summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/resources
diff options
context:
space:
mode:
authorannekao <annekao@google.com>2015-08-21 16:23:53 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-21 23:24:40 +0000
commit53348222214fa3b5cf008f70566d1b3bc7d94d64 (patch)
tree19543da773b578596bd898a6161d8d70c88d877a /extensions/renderer/resources
parentde00d08970e7ef2a95b231d605bb6a0c2c7716f4 (diff)
downloadchromium_src-53348222214fa3b5cf008f70566d1b3bc7d94d64.zip
chromium_src-53348222214fa3b5cf008f70566d1b3bc7d94d64.tar.gz
chromium_src-53348222214fa3b5cf008f70566d1b3bc7d94d64.tar.bz2
[Extension ServiceWorkers] Adding getBackgroundClient
After the v8::Context for a service worker is passed up, a script is injected in order for the service worker to have access to the background page of the extension. BUG=501569 Review URL: https://codereview.chromium.org/1304663003 Cr-Commit-Position: refs/heads/master@{#344900}
Diffstat (limited to 'extensions/renderer/resources')
-rw-r--r--extensions/renderer/resources/extensions_renderer_resources.grd1
-rw-r--r--extensions/renderer/resources/service_worker_bindings.js26
2 files changed, 27 insertions, 0 deletions
diff --git a/extensions/renderer/resources/extensions_renderer_resources.grd b/extensions/renderer/resources/extensions_renderer_resources.grd
index 5d20a15..d3fcb7d 100644
--- a/extensions/renderer/resources/extensions_renderer_resources.grd
+++ b/extensions/renderer/resources/extensions_renderer_resources.grd
@@ -80,6 +80,7 @@
<include name="IDR_PERMISSIONS_CUSTOM_BINDINGS_JS" file="permissions_custom_bindings.js" type="BINDATA" />
<include name="IDR_PRINTER_PROVIDER_CUSTOM_BINDINGS_JS" file="printer_provider_custom_bindings.js" type="BINDATA" />
<include name="IDR_RUNTIME_CUSTOM_BINDINGS_JS" file="runtime_custom_bindings.js" type="BINDATA" />
+ <include name="IDR_SERVICE_WORKER_BINDINGS_JS" file="service_worker_bindings.js" type="BINDATA" />
<include name="IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS" file="web_request_custom_bindings.js" type="BINDATA" />
<include name="IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS" file="web_request_internal_custom_bindings.js" type="BINDATA" />
<include name="IDR_WINDOW_CONTROLS_JS" file="window_controls.js" type="BINDATA" />
diff --git a/extensions/renderer/resources/service_worker_bindings.js b/extensions/renderer/resources/service_worker_bindings.js
new file mode 100644
index 0000000..bc8cfd6b
--- /dev/null
+++ b/extensions/renderer/resources/service_worker_bindings.js
@@ -0,0 +1,26 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+(function(backgroundUrl) {
+ 'use strict';
+
+ self.chrome = self.chrome || {};
+
+ self.chrome.getBackgroundClient = function() { return new Promise(
+ function(resolve, reject) {
+ self.clients.matchAll({
+ includeUncontrolled: true,
+ type: 'window'
+ }).then(function(clients) {
+ for (let client of clients) {
+ if (client.url == backgroundUrl) {
+ resolve(client);
+ return;
+ }
+ }
+ reject("BackgroundClient ('" + backgroundUrl + "') does not exist.")
+ })
+ });
+ }
+});