Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1314)

Unified Diff: content/browser/service_worker/service_worker_internals_ui.cc

Issue 296463005: Push API: fire push event from chrome://serviceworker-internals/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
« no previous file with comments | « content/browser/service_worker/service_worker_internals_ui.h ('k') | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698