Commit 42fc7c92 authored by horo@chromium.org's avatar horo@chromium.org

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
parent b54ef54a
...@@ -71,6 +71,8 @@ ...@@ -71,6 +71,8 @@
jsvalues=".scope:scope;.partition_path:$partition_path">Unregister</button> jsvalues=".scope:scope;.partition_path:$partition_path">Unregister</button>
<button href="#" class="sync" jsdisplay="$this.active.running_status == 'RUNNING'" <button href="#" class="sync" jsdisplay="$this.active.running_status == 'RUNNING'"
jsvalues=".scope:scope;.partition_path:$partition_path">Sync</button> jsvalues=".scope:scope;.partition_path:$partition_path">Sync</button>
<button href="#" class="inspect" jsdisplay="$this.active.running_status == 'RUNNING'"
jsvalues=".scope:scope;.partition_path:$partition_path">Inspect</button>
<span class="operation-status" style="display: none">Running...</span> <span class="operation-status" style="display: none">Running...</span>
</div> </div>
</div> </div>
......
...@@ -15,7 +15,7 @@ cr.define('serviceworker', function() { ...@@ -15,7 +15,7 @@ cr.define('serviceworker', function() {
// All commands are sent with the partition_path and scope, and // All commands are sent with the partition_path and scope, and
// are all completed with 'onOperationComplete'. // are all completed with 'onOperationComplete'.
var COMMANDS = ['unregister', 'start', 'stop', 'sync']; var COMMANDS = ['unregister', 'start', 'stop', 'sync', 'inspect'];
function commandHandler(command) { function commandHandler(command) {
return function(event) { return function(event) {
var link = event.target; var link = event.target;
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/values.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_observer.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h" #include "content/browser/service_worker/service_worker_registration.h"
...@@ -55,6 +57,9 @@ class ServiceWorkerInternalsUI::OperationProxy ...@@ -55,6 +57,9 @@ class ServiceWorkerInternalsUI::OperationProxy
void DispatchSyncEventToWorkerOnIOThread( void DispatchSyncEventToWorkerOnIOThread(
scoped_refptr<ServiceWorkerContextWrapper> context, scoped_refptr<ServiceWorkerContextWrapper> context,
const GURL& scope); const GURL& scope);
void InspectWorkerOnIOThread(
scoped_refptr<ServiceWorkerContextWrapper> context,
const GURL& scope);
private: private:
friend class base::RefCountedThreadSafe<OperationProxy>; friend class base::RefCountedThreadSafe<OperationProxy>;
...@@ -78,6 +83,15 @@ class ServiceWorkerInternalsUI::OperationProxy ...@@ -78,6 +83,15 @@ class ServiceWorkerInternalsUI::OperationProxy
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
const scoped_refptr<ServiceWorkerRegistration>& registration); 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_; WeakPtr<ServiceWorkerInternalsUI> internals_;
scoped_ptr<ListValue> original_args_; scoped_ptr<ListValue> original_args_;
}; };
...@@ -209,6 +223,10 @@ ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui) ...@@ -209,6 +223,10 @@ ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui)
"sync", "sync",
base::Bind(&ServiceWorkerInternalsUI::DispatchSyncEventToWorker, base::Bind(&ServiceWorkerInternalsUI::DispatchSyncEventToWorker,
base::Unretained(this))); base::Unretained(this)));
web_ui->RegisterMessageCallback(
"inspect",
base::Bind(&ServiceWorkerInternalsUI::InspectWorker,
base::Unretained(this)));
} }
ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() { ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() {
...@@ -337,6 +355,24 @@ void ServiceWorkerInternalsUI::DispatchSyncEventToWorker( ...@@ -337,6 +355,24 @@ void ServiceWorkerInternalsUI::DispatchSyncEventToWorker(
scope)); 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) { void ServiceWorkerInternalsUI::Unregister(const ListValue* args) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::FilePath partition_path; base::FilePath partition_path;
...@@ -453,6 +489,17 @@ ServiceWorkerInternalsUI::OperationProxy::DispatchSyncEventToWorkerOnIOThread( ...@@ -453,6 +489,17 @@ ServiceWorkerInternalsUI::OperationProxy::DispatchSyncEventToWorkerOnIOThread(
this)); 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 { namespace {
void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, void UpdateVersionInfo(const ServiceWorkerVersionInfo& version,
DictionaryValue* info) { DictionaryValue* info) {
...@@ -610,4 +657,42 @@ void ServiceWorkerInternalsUI::OperationProxy::DispatchSyncEventToActiveWorker( ...@@ -610,4 +657,42 @@ void ServiceWorkerInternalsUI::OperationProxy::DispatchSyncEventToActiveWorker(
OperationComplete(SERVICE_WORKER_ERROR_FAILED); 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 } // namespace content
...@@ -48,6 +48,7 @@ class ServiceWorkerInternalsUI ...@@ -48,6 +48,7 @@ class ServiceWorkerInternalsUI
void StartWorker(const base::ListValue* args); void StartWorker(const base::ListValue* args);
void StopWorker(const base::ListValue* args); void StopWorker(const base::ListValue* args);
void DispatchSyncEventToWorker(const base::ListValue* args); void DispatchSyncEventToWorker(const base::ListValue* args);
void InspectWorker(const base::ListValue* args);
void Unregister(const base::ListValue* args); void Unregister(const base::ListValue* args);
bool GetRegistrationInfo( bool GetRegistrationInfo(
......
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