Parametrize PageScriptDebugServer with v8::Context -> InspectorHost resolver

ScriptDebugServer needs a way to find ScriptDebugListener for the paused v8::Context. The listeners are added per InspectorHost. Now we have to mapping v8::Context -> InspectorHost, InspectorHost -> ScriptDebugListener which allow to map v8::Context -> ScriptDebugListener. This allows to avoid storing InspectorHost on Page.

BUG=435243
R=abarth@chromium.org

Review URL: https://codereview.chromium.org/764573002
This commit is contained in:
Yury Semikhatsky 2014-11-27 11:18:09 +03:00
parent 9837d78956
commit e645181fec
5 changed files with 34 additions and 19 deletions

View File

@ -79,7 +79,6 @@ Page::Page(PageClients& pageClients, ServiceProvider& services)
, m_isPainting(false)
#endif
, m_frameHost(FrameHost::create(*this, services))
, m_inspectorHost(0)
{
ASSERT(m_editorClient);

View File

@ -36,11 +36,6 @@
#include "sky/engine/wtf/Noncopyable.h"
#include "sky/engine/wtf/text/WTFString.h"
// FIXME: Page should not need to know anything about InspectorHost.
namespace inspector {
class InspectorHost;
}
namespace blink {
class AutoscrollController;
@ -90,11 +85,6 @@ public:
FrameHost& frameHost() const { return *m_frameHost; }
// FIXME(sky): This is only needed by PageDebuggerAgent to be able to look
// up the InspectorHost from the frame associated with a v8 context.
inspector::InspectorHost* inspectorHost() const { return m_inspectorHost; }
void setInspectorHost(inspector::InspectorHost* host) { m_inspectorHost = host; }
void setNeedsRecalcStyleInAllFrames();
EditorClient& editorClient() const { return *m_editorClient; }
@ -216,7 +206,6 @@ private:
// A pointer to all the interfaces provided to in-process Frames for this Page.
// FIXME: Most of the members of Page should move onto FrameHost.
OwnPtr<FrameHost> m_frameHost;
inspector::InspectorHost* m_inspectorHost;
};
} // namespace blink

View File

@ -161,6 +161,11 @@ void PageScriptDebugServer::setClientMessageLoop(PassOwnPtr<ClientMessageLoop> c
m_clientMessageLoop = clientMessageLoop;
}
void PageScriptDebugServer::setInspectorHostResolver(PassOwnPtr<InspectorHostResolver> resolver)
{
m_inspectorHostResolver = resolver;
}
void PageScriptDebugServer::compileScript(ScriptState* scriptState, const String& expression, const String& sourceURL, String* scriptId, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace)
{
ExecutionContext* executionContext = scriptState->executionContext();
@ -193,18 +198,16 @@ void PageScriptDebugServer::runScript(ScriptState* scriptState, const String& sc
ScriptDebugListener* PageScriptDebugServer::getDebugListenerForContext(v8::Handle<v8::Context> context)
{
v8::HandleScope scope(m_isolate);
LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context);
if (!frame)
inspector::InspectorHost* inspectorHost = m_inspectorHostResolver->inspectorHostFor(context);
if (!inspectorHost)
return 0;
return m_listenersMap.get(frame->page()->inspectorHost());
return m_listenersMap.get(inspectorHost);
}
void PageScriptDebugServer::runMessageLoopOnPause(v8::Handle<v8::Context> context)
{
v8::HandleScope scope(m_isolate);
LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context);
m_pausedHost = frame->page()->inspectorHost();
m_pausedHost = m_inspectorHostResolver->inspectorHostFor(context);
ASSERT(m_pausedHost);
// Wait for continue or step command.
m_clientMessageLoop->run(m_pausedHost);

View File

@ -68,6 +68,13 @@ public:
};
void setClientMessageLoop(PassOwnPtr<ClientMessageLoop>);
class InspectorHostResolver {
public:
virtual ~InspectorHostResolver() { }
virtual inspector::InspectorHost* inspectorHostFor(v8::Handle<v8::Context>) = 0;
};
void setInspectorHostResolver(PassOwnPtr<InspectorHostResolver>);
virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace) override;
virtual void clearCompiledScripts() override;
virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace) override;
@ -91,6 +98,7 @@ private:
typedef HashMap<inspector::InspectorHost*, ScriptDebugListener*> ListenersMap;
ListenersMap m_listenersMap;
OwnPtr<ClientMessageLoop> m_clientMessageLoop;
OwnPtr<InspectorHostResolver> m_inspectorHostResolver;
inspector::InspectorHost* m_pausedHost;
HashMap<String, String> m_compiledScriptURLs;

View File

@ -72,6 +72,19 @@ class MessageLoopAdaptor : public PageScriptDebugServer::ClientMessageLoop {
scoped_ptr<base::RunLoop> run_loop_;
};
class InspectorHostResolverImpl : public PageScriptDebugServer::InspectorHostResolver {
public:
explicit InspectorHostResolverImpl(inspector::InspectorHost* host) : host_(host) { }
~InspectorHostResolverImpl() override { }
inspector::InspectorHost* inspectorHostFor(v8::Handle<v8::Context> context) override {
if (context == host_->GetContext())
return host_;
return nullptr;
}
private:
inspector::InspectorHost* host_;
};
InspectorBackendMojoImpl::InspectorBackendMojoImpl(
inspector::InspectorHost* host)
: host_(host) {
@ -96,6 +109,9 @@ void InspectorBackendMojoImpl::Connect() {
PageScriptDebugServer::setMainThreadIsolate(host_->GetIsolate());
OwnPtr<MessageLoopAdaptor> message_loop = adoptPtr(new MessageLoopAdaptor);
PageScriptDebugServer::shared().setClientMessageLoop(message_loop.release());
OwnPtr<InspectorHostResolverImpl> host_resolver =
adoptPtr(new InspectorHostResolverImpl(host_));
PageScriptDebugServer::shared().setInspectorHostResolver(host_resolver.release());
// AgentRegistry used to do this, but we don't need it for one agent.
script_manager_ = InjectedScriptManager::createForPage();