From 42fc7c92be36296a195fb08d3bb3d11441b7bf4a Mon Sep 17 00:00:00 2001 From: "horo@chromium.org" Date: Sat, 17 May 2014 18:36:33 +0000 Subject: [PATCH] Add "inspect" button to chrome://serviceworker-internals. This cl depends on https://codereview.chromium.org/261753008 BUG=358657 Review URL: https://codereview.chromium.org/274743003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271254 0039d316-1c4b-4281-b951-d872f2087c98 --- .../service_worker/serviceworker_internals.html | 2 + .../service_worker/serviceworker_internals.js | 2 +- .../service_worker/service_worker_internals_ui.cc | 85 ++++++++++++++++++++++ .../service_worker/service_worker_internals_ui.h | 1 + 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/content/browser/resources/service_worker/serviceworker_internals.html b/content/browser/resources/service_worker/serviceworker_internals.html index ae854680e5af..867b89774124 100644 --- a/content/browser/resources/service_worker/serviceworker_internals.html +++ b/content/browser/resources/service_worker/serviceworker_internals.html @@ -71,6 +71,8 @@ jsvalues=".scope:scope;.partition_path:$partition_path">Unregister + diff --git a/content/browser/resources/service_worker/serviceworker_internals.js b/content/browser/resources/service_worker/serviceworker_internals.js index ec2132c985ec..1be184cf6fcc 100644 --- a/content/browser/resources/service_worker/serviceworker_internals.js +++ b/content/browser/resources/service_worker/serviceworker_internals.js @@ -15,7 +15,7 @@ cr.define('serviceworker', function() { // All commands are sent with the partition_path and scope, and // are all completed with 'onOperationComplete'. - var COMMANDS = ['unregister', 'start', 'stop', 'sync']; + var COMMANDS = ['unregister', 'start', 'stop', 'sync', 'inspect']; function commandHandler(command) { return function(event) { var link = event.target; diff --git a/content/browser/service_worker/service_worker_internals_ui.cc b/content/browser/service_worker/service_worker_internals_ui.cc index 14003b7a4f95..f69132f0fb8d 100644 --- a/content/browser/service_worker/service_worker_internals_ui.cc +++ b/content/browser/service_worker/service_worker_internals_ui.cc @@ -11,6 +11,8 @@ #include "base/memory/scoped_vector.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" +#include "content/browser/devtools/devtools_manager_impl.h" +#include "content/browser/devtools/embedded_worker_devtools_manager.h" #include "content/browser/service_worker/service_worker_context_observer.h" #include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_registration.h" @@ -55,6 +57,9 @@ class ServiceWorkerInternalsUI::OperationProxy void DispatchSyncEventToWorkerOnIOThread( scoped_refptr context, const GURL& scope); + void InspectWorkerOnIOThread( + scoped_refptr context, + const GURL& scope); private: friend class base::RefCountedThreadSafe; @@ -78,6 +83,15 @@ class ServiceWorkerInternalsUI::OperationProxy ServiceWorkerStatusCode status, const scoped_refptr& registration); + void InspectActiveWorker( + const ServiceWorkerContextCore* const service_worker_context, + ServiceWorkerStatusCode status, + const scoped_refptr& registration); + + void InspectWorkerOnUIThread( + const ServiceWorkerContextCore* const service_worker_context, + int64 version_id); + WeakPtr internals_; scoped_ptr original_args_; }; @@ -209,6 +223,10 @@ ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui) "sync", base::Bind(&ServiceWorkerInternalsUI::DispatchSyncEventToWorker, base::Unretained(this))); + web_ui->RegisterMessageCallback( + "inspect", + base::Bind(&ServiceWorkerInternalsUI::InspectWorker, + base::Unretained(this))); } ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() { @@ -337,6 +355,24 @@ void ServiceWorkerInternalsUI::DispatchSyncEventToWorker( scope)); } +void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + base::FilePath partition_path; + GURL scope; + scoped_refptr context; + if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) + return; + scoped_ptr args_copy(args->DeepCopy()); + BrowserThread::PostTask( + BrowserThread::IO, + FROM_HERE, + base::Bind( + &ServiceWorkerInternalsUI::OperationProxy::InspectWorkerOnIOThread, + new OperationProxy(AsWeakPtr(), args_copy.Pass()), + context, + scope)); +} + void ServiceWorkerInternalsUI::Unregister(const ListValue* args) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); base::FilePath partition_path; @@ -453,6 +489,17 @@ ServiceWorkerInternalsUI::OperationProxy::DispatchSyncEventToWorkerOnIOThread( this)); } +void ServiceWorkerInternalsUI::OperationProxy::InspectWorkerOnIOThread( + scoped_refptr context, + const GURL& scope) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + context->context()->storage()->FindRegistrationForPattern( + scope, + base::Bind(&ServiceWorkerInternalsUI::OperationProxy::InspectActiveWorker, + this, + context->context())); +} + namespace { void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, DictionaryValue* info) { @@ -610,4 +657,42 @@ void ServiceWorkerInternalsUI::OperationProxy::DispatchSyncEventToActiveWorker( OperationComplete(SERVICE_WORKER_ERROR_FAILED); } +void ServiceWorkerInternalsUI::OperationProxy::InspectActiveWorker( + const ServiceWorkerContextCore* const service_worker_context, + ServiceWorkerStatusCode status, + const scoped_refptr& registration) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + if (status == SERVICE_WORKER_OK) { + BrowserThread::PostTask( + BrowserThread::UI, + FROM_HERE, + base::Bind(&OperationProxy::InspectWorkerOnUIThread, + this, + service_worker_context, + registration->active_version()->version_id())); + return; + } + + OperationComplete(status); +} + +void ServiceWorkerInternalsUI::OperationProxy::InspectWorkerOnUIThread( + const ServiceWorkerContextCore* const service_worker_context, + int64 version_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + scoped_refptr agent_host( + EmbeddedWorkerDevToolsManager::GetInstance() + ->GetDevToolsAgentHostForServiceWorker( + EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier( + service_worker_context, version_id))); + if (agent_host) { + DevToolsManagerImpl::GetInstance()->Inspect( + internals_->web_ui()->GetWebContents()->GetBrowserContext(), + agent_host.get()); + OperationComplete(SERVICE_WORKER_OK); + return; + } + OperationComplete(SERVICE_WORKER_ERROR_NOT_FOUND); +} + } // namespace content diff --git a/content/browser/service_worker/service_worker_internals_ui.h b/content/browser/service_worker/service_worker_internals_ui.h index 715fe70bd019..c3f806dc768d 100644 --- a/content/browser/service_worker/service_worker_internals_ui.h +++ b/content/browser/service_worker/service_worker_internals_ui.h @@ -48,6 +48,7 @@ class ServiceWorkerInternalsUI void StartWorker(const base::ListValue* args); void StopWorker(const base::ListValue* args); void DispatchSyncEventToWorker(const base::ListValue* args); + void InspectWorker(const base::ListValue* args); void Unregister(const base::ListValue* args); bool GetRegistrationInfo( -- 2.11.4.GIT