diff options
Diffstat (limited to 'Source/WebCore/inspector/PageRuntimeAgent.cpp')
-rw-r--r-- | Source/WebCore/inspector/PageRuntimeAgent.cpp | 88 |
1 files changed, 36 insertions, 52 deletions
diff --git a/Source/WebCore/inspector/PageRuntimeAgent.cpp b/Source/WebCore/inspector/PageRuntimeAgent.cpp index 9e8427ba8..4f4fa25fe 100644 --- a/Source/WebCore/inspector/PageRuntimeAgent.cpp +++ b/Source/WebCore/inspector/PageRuntimeAgent.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 Google Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -31,8 +32,6 @@ #include "config.h" #include "PageRuntimeAgent.h" -#if ENABLE(INSPECTOR) - #include "Document.h" #include "Frame.h" #include "InspectorPageAgent.h" @@ -40,43 +39,41 @@ #include "JSDOMWindowBase.h" #include "MainFrame.h" #include "Page.h" -#include "PageConsole.h" +#include "PageConsoleClient.h" #include "ScriptController.h" #include "ScriptState.h" #include "SecurityOrigin.h" #include <inspector/InjectedScript.h> #include <inspector/InjectedScriptManager.h> -using Inspector::TypeBuilder::Runtime::ExecutionContextDescription; +using Inspector::Protocol::Runtime::ExecutionContextDescription; using namespace Inspector; namespace WebCore { -PageRuntimeAgent::PageRuntimeAgent(InjectedScriptManager* injectedScriptManager, Page* page, InspectorPageAgent* pageAgent) - : InspectorRuntimeAgent(injectedScriptManager) - , m_inspectedPage(page) +PageRuntimeAgent::PageRuntimeAgent(PageAgentContext& context, InspectorPageAgent* pageAgent) + : InspectorRuntimeAgent(context) + , m_frontendDispatcher(std::make_unique<Inspector::RuntimeFrontendDispatcher>(context.frontendRouter)) + , m_backendDispatcher(Inspector::RuntimeBackendDispatcher::create(context.backendDispatcher, this)) , m_pageAgent(pageAgent) - , m_mainWorldContextCreated(false) + , m_inspectedPage(context.inspectedPage) { } -void PageRuntimeAgent::didCreateFrontendAndBackend(Inspector::InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher) +void PageRuntimeAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) { - m_frontendDispatcher = std::make_unique<InspectorRuntimeFrontendDispatcher>(frontendChannel); - m_backendDispatcher = InspectorRuntimeBackendDispatcher::create(backendDispatcher, this); } -void PageRuntimeAgent::willDestroyFrontendAndBackend(InspectorDisconnectReason) +void PageRuntimeAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason reason) { - m_frontendDispatcher = nullptr; - m_backendDispatcher.clear(); + String unused; + disable(unused); - String errorString; - disable(&errorString); + InspectorRuntimeAgent::willDestroyFrontendAndBackend(reason); } -void PageRuntimeAgent::enable(ErrorString* errorString) +void PageRuntimeAgent::enable(ErrorString& errorString) { if (enabled()) return; @@ -90,7 +87,7 @@ void PageRuntimeAgent::enable(ErrorString* errorString) reportExecutionContextCreation(); } -void PageRuntimeAgent::disable(ErrorString* errorString) +void PageRuntimeAgent::disable(ErrorString& errorString) { if (!enabled()) return; @@ -98,64 +95,48 @@ void PageRuntimeAgent::disable(ErrorString* errorString) InspectorRuntimeAgent::disable(errorString); } -void PageRuntimeAgent::didCreateMainWorldContext(Frame* frame) +void PageRuntimeAgent::didCreateMainWorldContext(Frame& frame) { m_mainWorldContextCreated = true; if (!enabled()) return; - ASSERT(m_frontendDispatcher); - String frameId = m_pageAgent->frameId(frame); - JSC::ExecState* scriptState = mainWorldExecState(frame); + String frameId = m_pageAgent->frameId(&frame); + JSC::ExecState* scriptState = mainWorldExecState(&frame); notifyContextCreated(frameId, scriptState, nullptr, true); } -void PageRuntimeAgent::didCreateIsolatedContext(Frame* frame, JSC::ExecState* scriptState, SecurityOrigin* origin) -{ - if (!enabled()) - return; - - ASSERT(m_frontendDispatcher); - String frameId = m_pageAgent->frameId(frame); - notifyContextCreated(frameId, scriptState, origin, false); -} - -JSC::VM* PageRuntimeAgent::globalVM() -{ - return JSDOMWindowBase::commonVM(); -} - -InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId) +InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString& errorString, const int* executionContextId) { if (!executionContextId) { - JSC::ExecState* scriptState = mainWorldExecState(&m_inspectedPage->mainFrame()); - InjectedScript result = injectedScriptManager()->injectedScriptFor(scriptState); + JSC::ExecState* scriptState = mainWorldExecState(&m_inspectedPage.mainFrame()); + InjectedScript result = injectedScriptManager().injectedScriptFor(scriptState); if (result.hasNoValue()) - *errorString = ASCIILiteral("Internal error: main world execution context not found."); + errorString = ASCIILiteral("Internal error: main world execution context not found."); return result; } - InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId); + InjectedScript injectedScript = injectedScriptManager().injectedScriptForId(*executionContextId); if (injectedScript.hasNoValue()) - *errorString = ASCIILiteral("Execution context with given id not found."); + errorString = ASCIILiteral("Execution context with given id not found."); return injectedScript; } void PageRuntimeAgent::muteConsole() { - PageConsole::mute(); + PageConsoleClient::mute(); } void PageRuntimeAgent::unmuteConsole() { - PageConsole::unmute(); + PageConsoleClient::unmute(); } void PageRuntimeAgent::reportExecutionContextCreation() { Vector<std::pair<JSC::ExecState*, SecurityOrigin*>> isolatedContexts; - for (Frame* frame = &m_inspectedPage->mainFrame(); frame; frame = frame->tree().traverseNext()) { + for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) { if (!frame->script().canExecuteScripts(NotAboutToExecuteScript)) continue; String frameId = m_pageAgent->frameId(frame); @@ -165,8 +146,8 @@ void PageRuntimeAgent::reportExecutionContextCreation() frame->script().collectIsolatedContexts(isolatedContexts); if (isolatedContexts.isEmpty()) continue; - for (size_t i = 0; i< isolatedContexts.size(); i++) - notifyContextCreated(frameId, isolatedContexts[i].first, isolatedContexts[i].second, false); + for (auto& context : isolatedContexts) + notifyContextCreated(frameId, context.first, context.second, false); isolatedContexts.clear(); } } @@ -174,8 +155,13 @@ void PageRuntimeAgent::reportExecutionContextCreation() void PageRuntimeAgent::notifyContextCreated(const String& frameId, JSC::ExecState* scriptState, SecurityOrigin* securityOrigin, bool isPageContext) { ASSERT(securityOrigin || isPageContext); - int executionContextId = injectedScriptManager()->injectedScriptIdFor(scriptState); - String name = securityOrigin ? securityOrigin->toRawString() : ""; + + InjectedScript result = injectedScriptManager().injectedScriptFor(scriptState); + if (result.hasNoValue()) + return; + + int executionContextId = injectedScriptManager().injectedScriptIdFor(scriptState); + String name = securityOrigin ? securityOrigin->toRawString() : String(); m_frontendDispatcher->executionContextCreated(ExecutionContextDescription::create() .setId(executionContextId) .setIsPageContext(isPageContext) @@ -185,5 +171,3 @@ void PageRuntimeAgent::notifyContextCreated(const String& frameId, JSC::ExecStat } } // namespace WebCore - -#endif // ENABLE(INSPECTOR) |