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 e0f39a7aff3d7a955a46297c13f1bc8fe87c49f7..e976ad82884e6dffa992bca1608458371fad1dda 100644 |
--- a/content/browser/service_worker/service_worker_internals_ui.cc |
+++ b/content/browser/service_worker/service_worker_internals_ui.cc |
@@ -82,6 +82,31 @@ void CallServiceWorkerVersionMethodWithVersionID( |
(*version.*method)(callback); |
} |
+void DispatchPushEventWithVersionID( |
+ scoped_refptr<ServiceWorkerContextWrapper> context, |
+ int64 version_id, |
+ const ServiceWorkerInternalsUI::StatusCallback& callback) { |
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(DispatchPushEventWithVersionID, |
+ context, |
+ version_id, |
+ callback)); |
+ return; |
+ } |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ scoped_refptr<ServiceWorkerVersion> version = |
+ context->context()->GetLiveVersion(version_id); |
+ if (!version) { |
+ callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
+ return; |
+ } |
+ std::string data = "Test push message from ServiceWorkerInternals."; |
+ version->DispatchPushEvent(callback, data); |
+} |
+ |
void UnregisterWithScope( |
scoped_refptr<ServiceWorkerContextWrapper> context, |
const GURL& scope, |
@@ -400,6 +425,10 @@ ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui) |
base::Unretained(this), |
&ServiceWorkerVersion::DispatchSyncEvent)); |
web_ui->RegisterMessageCallback( |
+ "push", |
+ base::Bind(&ServiceWorkerInternalsUI::DispatchPushEvent, |
+ base::Unretained(this))); |
+ web_ui->RegisterMessageCallback( |
"inspect", |
base::Bind(&ServiceWorkerInternalsUI::InspectWorker, |
base::Unretained(this))); |
@@ -551,6 +580,29 @@ void ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod( |
method, context, version_id, callback); |
} |
+void ServiceWorkerInternalsUI::DispatchPushEvent( |
+ const ListValue* args) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ int callback_id; |
+ int partition_id; |
+ int64 version_id; |
+ std::string version_id_string; |
+ const DictionaryValue* cmd_args = NULL; |
+ scoped_refptr<ServiceWorkerContextWrapper> context; |
+ if (!args->GetInteger(0, &callback_id) || |
+ !args->GetDictionary(1, &cmd_args) || |
+ !cmd_args->GetInteger("partition_id", &partition_id) || |
+ !GetServiceWorkerContext(partition_id, &context) || |
+ !cmd_args->GetString("version_id", &version_id_string) || |
+ !base::StringToInt64(version_id_string, &version_id)) { |
+ return; |
+ } |
+ |
+ base::Callback<void(ServiceWorkerStatusCode)> callback = |
+ base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
+ DispatchPushEventWithVersionID(context, version_id, callback); |
+} |
+ |
void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
int callback_id; |