| Index: content/browser/service_worker/service_worker_internals_ui.cc
|
| diff --git a/content/browser/service_worker/service_worker_internals_ui.cc b/content/browser/service_worker/service_worker_internals_ui.cc
|
| index 14003b7a4f953d0c0117061bb68ea1202f40bee0..f69132f0fb8dbd913294803ec91eae6da4db803b 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<ServiceWorkerContextWrapper> context,
|
| const GURL& scope);
|
| + void InspectWorkerOnIOThread(
|
| + scoped_refptr<ServiceWorkerContextWrapper> context,
|
| + const GURL& scope);
|
|
|
| private:
|
| friend class base::RefCountedThreadSafe<OperationProxy>;
|
| @@ -78,6 +83,15 @@ class ServiceWorkerInternalsUI::OperationProxy
|
| ServiceWorkerStatusCode status,
|
| const scoped_refptr<ServiceWorkerRegistration>& registration);
|
|
|
| + void InspectActiveWorker(
|
| + const ServiceWorkerContextCore* const service_worker_context,
|
| + ServiceWorkerStatusCode status,
|
| + const scoped_refptr<ServiceWorkerRegistration>& registration);
|
| +
|
| + void InspectWorkerOnUIThread(
|
| + const ServiceWorkerContextCore* const service_worker_context,
|
| + int64 version_id);
|
| +
|
| WeakPtr<ServiceWorkerInternalsUI> internals_;
|
| scoped_ptr<ListValue> 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<ServiceWorkerContextWrapper> context;
|
| + if (!GetRegistrationInfo(args, &partition_path, &scope, &context))
|
| + return;
|
| + scoped_ptr<ListValue> 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<ServiceWorkerContextWrapper> 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<ServiceWorkerRegistration>& 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<DevToolsAgentHost> 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
|
|
|