diff options
-rw-r--r-- | chrome/browser/extensions/api/runtime/runtime_api.cc | 29 | ||||
-rw-r--r-- | chrome/browser/extensions/api/runtime/runtime_api.h | 11 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_function_registry.cc | 4 | ||||
-rw-r--r-- | chrome/chrome_renderer.gypi | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/experimental.runtime.json | 25 | ||||
-rw-r--r-- | chrome/common/extensions/docs/examples/api/omnibox/simple-example.zip | bin | 1383 -> 1381 bytes | |||
-rw-r--r-- | chrome/common/extensions/docs/experimental.runtime.html | 98 | ||||
-rw-r--r-- | chrome/common/extensions/docs/samples.json | 1 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_dispatcher.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/renderer_resources.grd | 1 | ||||
-rw-r--r-- | chrome/renderer/resources/extensions/experimental.runtime_custom_bindings.js | 23 |
11 files changed, 194 insertions, 1 deletions
diff --git a/chrome/browser/extensions/api/runtime/runtime_api.cc b/chrome/browser/extensions/api/runtime/runtime_api.cc index c2e541b..544e064 100644 --- a/chrome/browser/extensions/api/runtime/runtime_api.cc +++ b/chrome/browser/extensions/api/runtime/runtime_api.cc @@ -6,12 +6,17 @@ #include "chrome/common/extensions/extension.h" #include "chrome/browser/extensions/extension_event_router.h" +#include "chrome/browser/extensions/extension_host.h" +#include "chrome/browser/extensions/extension_process_manager.h" +#include "chrome/browser/extensions/extension_system.h" +#include "chrome/browser/extensions/lazy_background_task_queue.h" #include "chrome/browser/profiles/profile.h" #include "googleurl/src/gurl.h" namespace { const char kOnInstalledEvent[] = "experimental.runtime.onInstalled"; +const char kNoBackgroundPageError[] = "You do not have a background page."; } @@ -31,4 +36,28 @@ void RuntimeEventRouter::DispatchOnInstalledEvent( extension->id(), kOnInstalledEvent, "[]", NULL, GURL()); } +bool RuntimeGetBackgroundPageFunction::RunImpl() { + ExtensionHost* host = + ExtensionSystem::Get(profile())->process_manager()-> + GetBackgroundHostForExtension(extension_id()); + if (host) { + OnPageLoaded(host); + } else if (GetExtension()->has_lazy_background_page()) { + ExtensionSystem::Get(profile())->lazy_background_task_queue()-> + AddPendingTask( + profile(), extension_id(), + base::Bind(&RuntimeGetBackgroundPageFunction::OnPageLoaded, + this)); + } else { + error_ = kNoBackgroundPageError; + return false; + } + + return true; +} + +void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost*) { + SendResponse(true); +} + } // namespace extensions diff --git a/chrome/browser/extensions/api/runtime/runtime_api.h b/chrome/browser/extensions/api/runtime/runtime_api.h index 3db5764..3fdf088 100644 --- a/chrome/browser/extensions/api/runtime/runtime_api.h +++ b/chrome/browser/extensions/api/runtime/runtime_api.h @@ -6,7 +6,10 @@ #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ #pragma once +#include "chrome/browser/extensions/extension_function.h" + class Extension; +class ExtensionHost; class Profile; namespace extensions { @@ -18,6 +21,14 @@ class RuntimeEventRouter { const Extension* extension); }; +class RuntimeGetBackgroundPageFunction : public AsyncExtensionFunction { + protected: + virtual bool RunImpl() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("experimental.runtime.getBackgroundPage"); + private: + void OnPageLoaded(ExtensionHost*); +}; + } // namespace extensions #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ diff --git a/chrome/browser/extensions/extension_function_registry.cc b/chrome/browser/extensions/extension_function_registry.cc index dc84a93..63185c2 100644 --- a/chrome/browser/extensions/extension_function_registry.cc +++ b/chrome/browser/extensions/extension_function_registry.cc @@ -17,6 +17,7 @@ #include "chrome/browser/extensions/api/identity/identity_api.h" #include "chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.h" #include "chrome/browser/extensions/api/permissions/permissions_api.h" +#include "chrome/browser/extensions/api/runtime/runtime_api.h" #include "chrome/browser/extensions/api/serial/serial_api.h" #include "chrome/browser/extensions/api/socket/socket_api.h" #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" @@ -505,6 +506,9 @@ void ExtensionFunctionRegistry::ResetFunctions() { // Identity RegisterFunction<extensions::GetAuthTokenFunction>(); + // Runtime + RegisterFunction<extensions::RuntimeGetBackgroundPageFunction>(); + // Generated APIs extensions::api::GeneratedFunctionRegistry::RegisterAll(this); } diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 9148db4..07ff39f 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -141,6 +141,7 @@ 'renderer/resources/extensions/event.js', 'renderer/resources/extensions/experimental.declarative_custom_bindings.js', 'renderer/resources/extensions/experimental.offscreenTabs_custom_bindings.js', + 'renderer/resources/extensions/experimental.runtime_custom_bindings.js', 'renderer/resources/extensions/experimental.socket_custom_bindings.js', 'renderer/resources/extensions/experimental.webrequest_custom_bindings.js', 'renderer/resources/extensions/extension_custom_bindings.js', diff --git a/chrome/common/extensions/api/experimental.runtime.json b/chrome/common/extensions/api/experimental.runtime.json index fb6b2ed..ad37160 100644 --- a/chrome/common/extensions/api/experimental.runtime.json +++ b/chrome/common/extensions/api/experimental.runtime.json @@ -5,6 +5,31 @@ [ { "namespace": "experimental.runtime", + "functions": [ + { + "name": "getBackgroundPage", + "type": "function", + "description": "Retrieves the JavaScript 'window' object for the background page running inside the current extension. If the background page is transient, the system will ensure it is loaded before calling the callback. If there is no background page, an error is set.", + "parameters": [ + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "backgroundPage", + // Note: Only optional because we don't support validation + // for custom callbacks. + "optional": true, + "type": "object", + "isInstanceOf": "global", + "additionalProperties": { "type": "any" }, + "description": "The JavaScript 'window' object for the background page." + } + ] + } + ] + } + ], "events": [ { "name": "onInstalled", diff --git a/chrome/common/extensions/docs/examples/api/omnibox/simple-example.zip b/chrome/common/extensions/docs/examples/api/omnibox/simple-example.zip Binary files differindex 91e9d8e..6277c47 100644 --- a/chrome/common/extensions/docs/examples/api/omnibox/simple-example.zip +++ b/chrome/common/extensions/docs/examples/api/omnibox/simple-example.zip diff --git a/chrome/common/extensions/docs/experimental.runtime.html b/chrome/common/extensions/docs/experimental.runtime.html index 55aae88..0dcc761 100644 --- a/chrome/common/extensions/docs/experimental.runtime.html +++ b/chrome/common/extensions/docs/experimental.runtime.html @@ -195,6 +195,14 @@ <a href="#apiReference">API reference: chrome.experimental.runtime</a> <ol> <li> + <a href="#global-methods">Methods</a> + <ol> + <li> + <a href="#method-getBackgroundPage">getBackgroundPage</a> + </li> + </ol> + </li> + <li> <a href="#global-events">Events</a> <ol> <li> @@ -222,7 +230,95 @@ <!-- PROPERTIES --> <!-- /apiGroup --> <!-- METHODS --> - <!-- /apiGroup --> + <div id="methodsTemplate" class="apiGroup"> + <a name="global-methods"></a> + <h3>Methods</h3> + <!-- iterates over all functions --> + <div class="apiItem"> + <a name="method-getBackgroundPage"></a> <!-- method-anchor --> + <h4>getBackgroundPage</h4> + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.experimental.runtime.getBackgroundPage</span>(<span class="null"><span>function</span> + <var><span>callback</span></var></span>)</div> + <div class="description"> + <p>Retrieves the JavaScript 'window' object for the background page running inside the current extension. If the background page is transient, the system will ensure it is loaded before calling the callback. If there is no background page, an error is set.</p> + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>callback</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>function</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + <!-- RETURNS --> + <dl> + </dl> + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>global backgroundPage</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>backgroundPage</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional">optional</span> + <span id="typeTemplate"> + <span> + <span>global</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd>The JavaScript 'window' object for the background page.</dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </div> + </div> + <!-- MIN_VERSION --> + </div> <!-- /description --> + </div> <!-- /apiItem --> + </div> <!-- /apiGroup --> <!-- EVENTS --> <div id="eventsTemplate" class="apiGroup"> <a name="global-events"></a> diff --git a/chrome/common/extensions/docs/samples.json b/chrome/common/extensions/docs/samples.json index f74e0c4..a76a296 100644 --- a/chrome/common/extensions/docs/samples.json +++ b/chrome/common/extensions/docs/samples.json @@ -129,6 +129,7 @@ "chrome.experimental.offscreenTabs.sendMouseEvent": "experimental.offscreenTabs.html#method-sendMouseEvent", "chrome.experimental.offscreenTabs.toDataUrl": "experimental.offscreenTabs.html#method-toDataUrl", "chrome.experimental.offscreenTabs.update": "experimental.offscreenTabs.html#method-update", + "chrome.experimental.runtime.getBackgroundPage": "experimental.runtime.html#method-getBackgroundPage", "chrome.experimental.runtime.onBackgroundPageUnloadingSoon": "experimental.runtime.html#event-onBackgroundPageUnloadingSoon", "chrome.experimental.runtime.onInstalled": "experimental.runtime.html#event-onInstalled", "chrome.experimental.speechInput.isRecording": "experimental.speechInput.html#method-isRecording", diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc index ed3b2c1..4cf38fe 100644 --- a/chrome/renderer/extensions/extension_dispatcher.cc +++ b/chrome/renderer/extensions/extension_dispatcher.cc @@ -508,6 +508,8 @@ void ExtensionDispatcher::PopulateSourceMap() { IDR_EXPERIMENTAL_DECLARATIVE_CUSTOM_BINDINGS_JS); source_map_.RegisterSource("experimental.offscreen", IDR_EXPERIMENTAL_OFFSCREENTABS_CUSTOM_BINDINGS_JS); + source_map_.RegisterSource("experimental.runtime", + IDR_EXPERIMENTAL_RUNTIME_CUSTOM_BINDINGS_JS); source_map_.RegisterSource("experimental.socket", IDR_EXPERIMENTAL_SOCKET_CUSTOM_BINDINGS_JS); source_map_.RegisterSource("experimental.webRequest", diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index 599d2dd..07d23e6 100644 --- a/chrome/renderer/renderer_resources.grd +++ b/chrome/renderer/renderer_resources.grd @@ -38,6 +38,7 @@ without changes to the corresponding grd file. fb9 --> <include name="IDR_DEVTOOLS_CUSTOM_BINDINGS_JS" file="resources\extensions\devtools_custom_bindings.js" type="BINDATA" /> <include name="IDR_EXPERIMENTAL_DECLARATIVE_CUSTOM_BINDINGS_JS" file="resources\extensions\experimental.declarative_custom_bindings.js" type="BINDATA" /> <include name="IDR_EXPERIMENTAL_OFFSCREENTABS_CUSTOM_BINDINGS_JS" file="resources\extensions\experimental.offscreenTabs_custom_bindings.js" type="BINDATA" /> + <include name="IDR_EXPERIMENTAL_RUNTIME_CUSTOM_BINDINGS_JS" file="resources\extensions\experimental.runtime_custom_bindings.js" type="BINDATA" /> <include name="IDR_EXPERIMENTAL_SOCKET_CUSTOM_BINDINGS_JS" file="resources\extensions\experimental.socket_custom_bindings.js" type="BINDATA" /> <include name="IDR_EXPERIMENTAL_WEBREQUEST_CUSTOM_BINDINGS_JS" file="resources\extensions\experimental.webrequest_custom_bindings.js" type="BINDATA" /> <include name="IDR_EXTENSION_CUSTOM_BINDINGS_JS" file="resources\extensions\extension_custom_bindings.js" type="BINDATA" /> diff --git a/chrome/renderer/resources/extensions/experimental.runtime_custom_bindings.js b/chrome/renderer/resources/extensions/experimental.runtime_custom_bindings.js new file mode 100644 index 0000000..7d70ee2 --- /dev/null +++ b/chrome/renderer/resources/extensions/experimental.runtime_custom_bindings.js @@ -0,0 +1,23 @@ +// Copyright (c) 2012 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. + +// Custom bindings for the runtime API. + +var extensionNatives = requireNative('extension'); +var GetExtensionViews = extensionNatives.GetExtensionViews; +var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); +var sendRequest = require('sendRequest').sendRequest; + +chromeHidden.registerCustomHook('experimental.runtime', function(bindingsAPI) { + var apiFunctions = bindingsAPI.apiFunctions; + + apiFunctions.setCustomCallback('getBackgroundPage', + function(name, request, response) { + if (request.callback) { + var bg = GetExtensionViews(-1, 'BACKGROUND')[0] || null; + request.callback(bg); + } + request.callback = null; + }); +}); |