Commit 286d478f authored by vsevik@chromium.org's avatar vsevik@chromium.org

DevTools: Switch shared workers inspection on to the main thread.

BUG=404355

Review URL: https://codereview.chromium.org/534293003

git-svn-id: svn://svn.chromium.org/blink/trunk@181674 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 66f187eb
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include "public/platform/WebString.h" #include "public/platform/WebString.h"
#include "public/platform/WebURL.h" #include "public/platform/WebURL.h"
#include "public/platform/WebURLRequest.h" #include "public/platform/WebURLRequest.h"
#include "public/web/WebDevToolsAgent.h"
#include "public/web/WebFrame.h" #include "public/web/WebFrame.h"
#include "public/web/WebSettings.h" #include "public/web/WebSettings.h"
#include "public/web/WebView.h" #include "public/web/WebView.h"
...@@ -159,7 +160,7 @@ WebSharedWorkerImpl::WebSharedWorkerImpl(WebSharedWorkerClient* client) ...@@ -159,7 +160,7 @@ WebSharedWorkerImpl::WebSharedWorkerImpl(WebSharedWorkerClient* client)
, m_client(WeakReference<WebSharedWorkerClient>::create(client)) , m_client(WeakReference<WebSharedWorkerClient>::create(client))
, m_clientWeakPtr(WeakPtr<WebSharedWorkerClient>(m_client)) , m_clientWeakPtr(WeakPtr<WebSharedWorkerClient>(m_client))
, m_pauseWorkerContextOnStart(false) , m_pauseWorkerContextOnStart(false)
, m_attachDevToolsOnStart(false) , m_isPausedOnStart(false)
{ {
initializeWebKitStaticValues(); initializeWebKitStaticValues();
} }
...@@ -207,6 +208,7 @@ void WebSharedWorkerImpl::initializeLoader(const WebURL& url) ...@@ -207,6 +208,7 @@ void WebSharedWorkerImpl::initializeLoader(const WebURL& url)
// is created (similar to RenderThread::OnCreateNewView). // is created (similar to RenderThread::OnCreateNewView).
m_mainFrame = WebLocalFrame::create(this); m_mainFrame = WebLocalFrame::create(this);
m_webView->setMainFrame(m_mainFrame); m_webView->setMainFrame(m_mainFrame);
m_webView->setDevToolsAgentClient(this);
WebLocalFrameImpl* webFrame = toWebLocalFrameImpl(m_webView->mainFrame()); WebLocalFrameImpl* webFrame = toWebLocalFrameImpl(m_webView->mainFrame());
...@@ -226,6 +228,35 @@ WebApplicationCacheHost* WebSharedWorkerImpl::createApplicationCacheHost(WebLoca ...@@ -226,6 +228,35 @@ WebApplicationCacheHost* WebSharedWorkerImpl::createApplicationCacheHost(WebLoca
} }
void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame)
{
// If we were asked to pause worker context on start and wait for debugger then it is the good time to do that.
client()->workerReadyForInspection();
if (m_pauseWorkerContextOnStart) {
m_isPausedOnStart = true;
return;
}
startScriptLoader(frame);
}
void WebSharedWorkerImpl::sendMessageToInspectorFrontend(const WebString& message)
{
client()->dispatchDevToolsMessage(message);
}
void WebSharedWorkerImpl::resumeStartup()
{
bool isPausedOnStart = m_isPausedOnStart;
m_isPausedOnStart = false;
if (isPausedOnStart)
startScriptLoader(toWebLocalFrameImpl(m_mainFrame));
}
void WebSharedWorkerImpl::saveAgentRuntimeState(const WebString& inspectorState)
{
client()->saveDevToolsAgentState(inspectorState);
}
void WebSharedWorkerImpl::startScriptLoader(WebLocalFrame* frame)
{ {
ASSERT(!m_loadingDocument); ASSERT(!m_loadingDocument);
ASSERT(!m_mainScriptLoader); ASSERT(!m_mainScriptLoader);
...@@ -252,11 +283,6 @@ void WebSharedWorkerImpl::reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMes ...@@ -252,11 +283,6 @@ void WebSharedWorkerImpl::reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMes
void WebSharedWorkerImpl::postMessageToPageInspector(const String& message) void WebSharedWorkerImpl::postMessageToPageInspector(const String& message)
{ {
// Note that we need to keep the closure creation on a separate line so
// that the temporary created by isolatedCopy() will always be destroyed
// before the copy in the closure is used on the main thread.
const Closure& boundFunction = bind(&WebSharedWorkerClient::dispatchDevToolsMessage, m_clientWeakPtr, message.isolatedCopy());
callOnMainThread(boundFunction);
toWebLocalFrameImpl(m_mainFrame)->frame()->document()->postInspectorTask(createCrossThreadTask(&WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread, this, message)); toWebLocalFrameImpl(m_mainFrame)->frame()->document()->postInspectorTask(createCrossThreadTask(&WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread, this, message));
} }
...@@ -271,11 +297,6 @@ void WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread(const String& m ...@@ -271,11 +297,6 @@ void WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread(const String& m
void WebSharedWorkerImpl::updateInspectorStateCookie(const String& cookie) void WebSharedWorkerImpl::updateInspectorStateCookie(const String& cookie)
{ {
// Note that we need to keep the closure creation on a separate line so
// that the temporary created by isolatedCopy() will always be destroyed
// before the copy in the closure is used on the main thread.
const Closure& boundFunction = bind(&WebSharedWorkerClient::saveDevToolsAgentState, m_clientWeakPtr, cookie.isolatedCopy());
callOnMainThread(boundFunction);
} }
void WebSharedWorkerImpl::workerGlobalScopeClosed() void WebSharedWorkerImpl::workerGlobalScopeClosed()
...@@ -353,11 +374,6 @@ void WebSharedWorkerImpl::didReceiveScriptLoaderResponse() ...@@ -353,11 +374,6 @@ void WebSharedWorkerImpl::didReceiveScriptLoaderResponse()
client()->selectAppCacheID(m_mainScriptLoader->appCacheID()); client()->selectAppCacheID(m_mainScriptLoader->appCacheID());
} }
static void connectToWorkerContextInspectorTask(ExecutionContext* context, bool)
{
toWorkerGlobalScope(context)->workerInspectorController()->connectFrontend();
}
void WebSharedWorkerImpl::onScriptLoaderFinished() void WebSharedWorkerImpl::onScriptLoaderFinished()
{ {
ASSERT(m_loadingDocument); ASSERT(m_loadingDocument);
...@@ -374,7 +390,12 @@ void WebSharedWorkerImpl::onScriptLoaderFinished() ...@@ -374,7 +390,12 @@ void WebSharedWorkerImpl::onScriptLoaderFinished()
delete this; delete this;
return; return;
} }
WorkerThreadStartMode startMode = m_pauseWorkerContextOnStart ? PauseWorkerGlobalScopeOnStart : DontPauseWorkerGlobalScopeOnStart;
Document* document = toWebLocalFrameImpl(m_mainFrame)->frame()->document();
WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart;
if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document))
startMode = PauseWorkerGlobalScopeOnStart;
OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create(); OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create();
provideLocalFileSystemToWorker(workerClients.get(), LocalFileSystemClient::create()); provideLocalFileSystemToWorker(workerClients.get(), LocalFileSystemClient::create());
provideDatabaseClientToWorker(workerClients.get(), DatabaseClientImpl::create()); provideDatabaseClientToWorker(workerClients.get(), DatabaseClientImpl::create());
...@@ -385,15 +406,10 @@ void WebSharedWorkerImpl::onScriptLoaderFinished() ...@@ -385,15 +406,10 @@ void WebSharedWorkerImpl::onScriptLoaderFinished()
InspectorInstrumentation::scriptImported(m_loadingDocument.get(), m_mainScriptLoader->identifier(), m_mainScriptLoader->script()); InspectorInstrumentation::scriptImported(m_loadingDocument.get(), m_mainScriptLoader->identifier(), m_mainScriptLoader->script());
m_mainScriptLoader.clear(); m_mainScriptLoader.clear();
if (m_attachDevToolsOnStart)
workerThread()->postDebuggerTask(createCrossThreadTask(connectToWorkerContextInspectorTask, true));
workerThread()->start(); workerThread()->start();
m_workerInspectorProxy->workerThreadCreated(m_loadingDocument.get(), workerThread(), m_url); m_workerInspectorProxy->workerThreadCreated(m_loadingDocument.get(), workerThread(), m_url);
if (client()) { if (client())
client()->workerScriptLoaded(); client()->workerScriptLoaded();
client()->workerReadyForInspection();
}
} }
void WebSharedWorkerImpl::terminateWorkerContext() void WebSharedWorkerImpl::terminateWorkerContext()
...@@ -411,70 +427,38 @@ void WebSharedWorkerImpl::pauseWorkerContextOnStart() ...@@ -411,70 +427,38 @@ void WebSharedWorkerImpl::pauseWorkerContextOnStart()
m_pauseWorkerContextOnStart = true; m_pauseWorkerContextOnStart = true;
} }
static void resumeWorkerContextTask(ExecutionContext* context, bool)
{
toWorkerGlobalScope(context)->workerInspectorController()->resume();
}
void WebSharedWorkerImpl::resumeWorkerContext() void WebSharedWorkerImpl::resumeWorkerContext()
{ {
m_pauseWorkerContextOnStart = false;
if (workerThread())
workerThread()->postDebuggerTask(createCrossThreadTask(resumeWorkerContextTask, true));
}
void WebSharedWorkerImpl::attachDevTools()
{
if (workerThread())
workerThread()->postDebuggerTask(createCrossThreadTask(connectToWorkerContextInspectorTask, true));
else
m_attachDevToolsOnStart = true;
} }
void WebSharedWorkerImpl::attachDevTools(const WebString& hostId) void WebSharedWorkerImpl::attachDevTools(const WebString& hostId)
{ {
attachDevTools(); WebDevToolsAgent* devtoolsAgent = m_webView->devToolsAgent();
} if (devtoolsAgent)
devtoolsAgent->attach(hostId);
static void reconnectToWorkerContextInspectorTask(ExecutionContext* context, const String& savedState)
{
WorkerInspectorController* ic = toWorkerGlobalScope(context)->workerInspectorController();
ic->restoreInspectorStateFromCookie(savedState);
ic->resume();
}
void WebSharedWorkerImpl::reattachDevTools(const WebString& savedState)
{
workerThread()->postDebuggerTask(createCrossThreadTask(reconnectToWorkerContextInspectorTask, String(savedState)));
} }
void WebSharedWorkerImpl::reattachDevTools(const WebString& hostId, const WebString& savedState) void WebSharedWorkerImpl::reattachDevTools(const WebString& hostId, const WebString& savedState)
{ {
reattachDevTools(savedState); WebDevToolsAgent* devtoolsAgent = m_webView->devToolsAgent();
} if (devtoolsAgent)
devtoolsAgent->reattach(hostId, savedState);
static void disconnectFromWorkerContextInspectorTask(ExecutionContext* context, bool)
{
toWorkerGlobalScope(context)->workerInspectorController()->disconnectFrontend();
} }
void WebSharedWorkerImpl::detachDevTools() void WebSharedWorkerImpl::detachDevTools()
{ {
m_attachDevToolsOnStart = false; WebDevToolsAgent* devtoolsAgent = m_webView->devToolsAgent();
workerThread()->postDebuggerTask(createCrossThreadTask(disconnectFromWorkerContextInspectorTask, true)); if (devtoolsAgent)
} devtoolsAgent->detach();
static void dispatchOnInspectorBackendTask(ExecutionContext* context, const String& message)
{
toWorkerGlobalScope(context)->workerInspectorController()->dispatchMessageFromFrontend(message);
} }
void WebSharedWorkerImpl::dispatchDevToolsMessage(const WebString& message) void WebSharedWorkerImpl::dispatchDevToolsMessage(const WebString& message)
{ {
if (m_askedToTerminate) if (m_askedToTerminate)
return; return;
workerThread()->postDebuggerTask(createCrossThreadTask(dispatchOnInspectorBackendTask, String(message))); WebDevToolsAgent* devtoolsAgent = m_webView->devToolsAgent();
workerThread()->interruptAndDispatchInspectorCommands(); if (devtoolsAgent)
devtoolsAgent->dispatchOnInspectorBackend(message);
} }
WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client)
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "core/workers/WorkerScriptLoaderClient.h" #include "core/workers/WorkerScriptLoaderClient.h"
#include "core/workers/WorkerThread.h" #include "core/workers/WorkerThread.h"
#include "public/web/WebContentSecurityPolicy.h" #include "public/web/WebContentSecurityPolicy.h"
#include "public/web/WebDevToolsAgentClient.h"
#include "public/web/WebFrameClient.h" #include "public/web/WebFrameClient.h"
#include "public/web/WebSharedWorkerClient.h" #include "public/web/WebSharedWorkerClient.h"
#include "wtf/PassOwnPtr.h" #include "wtf/PassOwnPtr.h"
...@@ -68,7 +69,8 @@ class WebSharedWorkerImpl FINAL ...@@ -68,7 +69,8 @@ class WebSharedWorkerImpl FINAL
: public WorkerReportingProxy : public WorkerReportingProxy
, public WorkerLoaderProxy , public WorkerLoaderProxy
, public WebFrameClient , public WebFrameClient
, public WebSharedWorker { , public WebSharedWorker
, public WebDevToolsAgentClient {
public: public:
explicit WebSharedWorkerImpl(WebSharedWorkerClient*); explicit WebSharedWorkerImpl(WebSharedWorkerClient*);
...@@ -91,6 +93,11 @@ public: ...@@ -91,6 +93,11 @@ public:
virtual WebApplicationCacheHost* createApplicationCacheHost(WebLocalFrame*, WebApplicationCacheHostClient*) OVERRIDE; virtual WebApplicationCacheHost* createApplicationCacheHost(WebLocalFrame*, WebApplicationCacheHostClient*) OVERRIDE;
virtual void didFinishDocumentLoad(WebLocalFrame*) OVERRIDE; virtual void didFinishDocumentLoad(WebLocalFrame*) OVERRIDE;
// WebDevToolsAgentClient overrides.
virtual void sendMessageToInspectorFrontend(const WebString&) OVERRIDE;
virtual void saveAgentRuntimeState(const WebString&) OVERRIDE;
virtual void resumeStartup() OVERRIDE;
// WebSharedWorker methods: // WebSharedWorker methods:
virtual void startWorkerContext(const WebURL&, const WebString& name, const WebString& contentSecurityPolicy, WebContentSecurityPolicyType) OVERRIDE; virtual void startWorkerContext(const WebURL&, const WebString& name, const WebString& contentSecurityPolicy, WebContentSecurityPolicyType) OVERRIDE;
virtual void connect(WebMessagePortChannel*) OVERRIDE; virtual void connect(WebMessagePortChannel*) OVERRIDE;
...@@ -99,11 +106,7 @@ public: ...@@ -99,11 +106,7 @@ public:
virtual void pauseWorkerContextOnStart() OVERRIDE; virtual void pauseWorkerContextOnStart() OVERRIDE;
virtual void resumeWorkerContext() OVERRIDE; virtual void resumeWorkerContext() OVERRIDE;
// FIXME: Remove this once chromium uses the one that receives hostId as a parameter.
virtual void attachDevTools() OVERRIDE;
virtual void attachDevTools(const WebString& hostId) OVERRIDE; virtual void attachDevTools(const WebString& hostId) OVERRIDE;
// FIXME: Remove this once chromium uses the one that receives hostId as a parameter.
virtual void reattachDevTools(const WebString& savedState) OVERRIDE;
virtual void reattachDevTools(const WebString& hostId, const WebString& savedState) OVERRIDE; virtual void reattachDevTools(const WebString& hostId, const WebString& savedState) OVERRIDE;
virtual void detachDevTools() OVERRIDE; virtual void detachDevTools() OVERRIDE;
virtual void dispatchDevToolsMessage(const WebString&) OVERRIDE; virtual void dispatchDevToolsMessage(const WebString&) OVERRIDE;
...@@ -124,6 +127,7 @@ private: ...@@ -124,6 +127,7 @@ private:
// Creates the shadow loader used for worker network requests. // Creates the shadow loader used for worker network requests.
void initializeLoader(const WebURL&); void initializeLoader(const WebURL&);
void startScriptLoader(WebLocalFrame*);
void didReceiveScriptLoaderResponse(); void didReceiveScriptLoaderResponse();
void onScriptLoaderFinished(); void onScriptLoaderFinished();
...@@ -153,7 +157,7 @@ private: ...@@ -153,7 +157,7 @@ private:
WeakPtr<WebSharedWorkerClient> m_clientWeakPtr; WeakPtr<WebSharedWorkerClient> m_clientWeakPtr;
bool m_pauseWorkerContextOnStart; bool m_pauseWorkerContextOnStart;
bool m_attachDevToolsOnStart; bool m_isPausedOnStart;
// Kept around only while main script loading is ongoing. // Kept around only while main script loading is ongoing.
OwnPtr<Loader> m_mainScriptLoader; OwnPtr<Loader> m_mainScriptLoader;
......
...@@ -64,11 +64,7 @@ public: ...@@ -64,11 +64,7 @@ public:
virtual void pauseWorkerContextOnStart() = 0; virtual void pauseWorkerContextOnStart() = 0;
virtual void resumeWorkerContext() = 0; virtual void resumeWorkerContext() = 0;
virtual void attachDevTools() = 0;
// FIXME: Remove this once chromium uses the one that receives hostId as a parameter.
virtual void attachDevTools(const WebString& hostId) = 0; virtual void attachDevTools(const WebString& hostId) = 0;
virtual void reattachDevTools(const WebString& savedState) = 0;
// FIXME: Remove this once chromium uses the one that receives hostId as a parameter.
virtual void reattachDevTools(const WebString& hostId, const WebString& savedState) = 0; virtual void reattachDevTools(const WebString& hostId, const WebString& savedState) = 0;
virtual void detachDevTools() = 0; virtual void detachDevTools() = 0;
virtual void dispatchDevToolsMessage(const WebString&) = 0; virtual void dispatchDevToolsMessage(const WebString&) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment