summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-24 02:30:56 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-24 02:30:56 +0000
commit9e6720a53c11fc3d42c0959295d3b7f2c9765c93 (patch)
tree412b6e6b26b74494582c8f9eca1da9953570848b
parent0b39741d73734c2e5a211ee558ce12101dd5b5ab (diff)
downloadchromium_src-9e6720a53c11fc3d42c0959295d3b7f2c9765c93.zip
chromium_src-9e6720a53c11fc3d42c0959295d3b7f2c9765c93.tar.gz
chromium_src-9e6720a53c11fc3d42c0959295d3b7f2c9765c93.tar.bz2
Replace lazy-background switch with a manifest entry controlled by the
extension. BUG=81752 TEST=no Review URL: https://chromiumcodereview.appspot.com/9233016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118784 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_content_browser_client.cc1
-rw-r--r--chrome/browser/extensions/extension_event_router.cc27
-rw-r--r--chrome/browser/extensions/extension_event_router.h4
-rw-r--r--chrome/browser/extensions/extension_process_manager.cc9
-rw-r--r--chrome/browser/extensions/lazy_background_page_apitest.cc11
-rw-r--r--chrome/common/chrome_switches.cc4
-rw-r--r--chrome/common/chrome_switches.h1
-rw-r--r--chrome/common/extensions/extension.cc27
-rw-r--r--chrome/common/extensions/extension.h9
-rw-r--r--chrome/common/extensions/extension_constants.cc8
-rw-r--r--chrome/common/extensions/extension_constants.h3
-rw-r--r--chrome/renderer/extensions/extension_dispatcher.cc9
-rw-r--r--chrome/renderer/extensions/extension_helper.cc6
-rw-r--r--chrome/test/data/extensions/api_test/lazy_background_page/broadcast_event/manifest.json5
-rw-r--r--chrome/test/data/extensions/api_test/lazy_background_page/browser_action_create_tab/manifest.json25
-rw-r--r--chrome/test/data/extensions/api_test/lazy_background_page/browser_action_with_callback/manifest.json25
16 files changed, 98 insertions, 76 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 84dcf0d..5a852d0 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -652,7 +652,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
switches::kEnableExperimentalExtensionApis,
switches::kEnableInBrowserThumbnailing,
switches::kEnableIPCFuzzing,
- switches::kEnableLazyBackgroundPages,
switches::kEnableNaCl,
switches::kEnablePlatformApps,
switches::kEnableSearchProviderApiV2,
diff --git a/chrome/browser/extensions/extension_event_router.cc b/chrome/browser/extensions/extension_event_router.cc
index f18ec66..248fd38 100644
--- a/chrome/browser/extensions/extension_event_router.cc
+++ b/chrome/browser/extensions/extension_event_router.cc
@@ -213,18 +213,15 @@ void ExtensionEventRouter::DispatchEventsToRenderersAcrossIncognito(
bool ExtensionEventRouter::CanDispatchEventNow(
const std::string& extension_id) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages))
- return true;
-
if (extension_id.empty())
- // TODO(tessamac): Create all background pages. Wait for all to be loaded?
- // or dispatch event to each extension when it's ready?
+ // TODO(mpcomplete): We need to test this per-extension, rather than
+ // globally.
return true;
const Extension* extension = profile_->GetExtensionService()->
- GetExtensionById(extension_id, false); // exclude disabled extensions
- if (extension && extension->has_background_page()) {
+ GetExtensionById(extension_id, false);
+ if (extension && extension->has_background_page() &&
+ !extension->background_page_persists()) {
ExtensionProcessManager* pm = profile_->GetExtensionProcessManager();
if (!pm->GetBackgroundHostForExtension(extension_id)) {
pm->CreateBackgroundHost(extension, extension->GetBackgroundURL());
@@ -298,28 +295,24 @@ void ExtensionEventRouter::DispatchEventImpl(
DispatchEvent(listener->process, listener->extension_id,
event->event_name, event->cross_incognito_args,
event->event_url);
- IncrementInFlightEvents(listener->extension_id);
+ IncrementInFlightEvents(extension);
}
continue;
}
DispatchEvent(listener->process, listener->extension_id,
event->event_name, event->event_args, event->event_url);
- IncrementInFlightEvents(listener->extension_id);
+ IncrementInFlightEvents(extension);
}
}
-void ExtensionEventRouter::IncrementInFlightEvents(
- const std::string& extension_id) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages))
- in_flight_events_[extension_id]++;
+void ExtensionEventRouter::IncrementInFlightEvents(const Extension* extension) {
+ if (!extension->background_page_persists())
+ in_flight_events_[extension->id()]++;
}
void ExtensionEventRouter::OnExtensionEventAck(
const std::string& extension_id) {
- CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages));
CHECK(in_flight_events_[extension_id] > 0);
in_flight_events_[extension_id]--;
}
diff --git a/chrome/browser/extensions/extension_event_router.h b/chrome/browser/extensions/extension_event_router.h
index cc2608d..6624d98 100644
--- a/chrome/browser/extensions/extension_event_router.h
+++ b/chrome/browser/extensions/extension_event_router.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -144,7 +144,7 @@ class ExtensionEventRouter : public content::NotificationObserver {
// Track of the number of dispatched events that have not yet sent an
// ACK from the renderer.
- void IncrementInFlightEvents(const std::string& extension_id);
+ void IncrementInFlightEvents(const Extension* extension);
std::map<std::string, int> in_flight_events_;
DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter);
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index 977f47c..9271541 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -66,10 +66,8 @@ class IncognitoExtensionProcessManager : public ExtensionProcessManager {
static void CreateBackgroundHostForExtensionLoad(
ExtensionProcessManager* manager, const Extension* extension) {
- // Start the process for the master page, if it exists and we're not lazy.
- if (!CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages) &&
- extension->has_background_page()) {
+ if (extension->has_background_page() &&
+ extension->background_page_persists()) {
manager->CreateBackgroundHost(extension, extension->GetBackgroundURL());
}
}
@@ -481,9 +479,6 @@ void IncognitoExtensionProcessManager::Observe(
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages))
- break;
// We want to spawn our background hosts as soon as the user opens an
// incognito window. Watch for new browsers and create the hosts if
// it matches our profile.
diff --git a/chrome/browser/extensions/lazy_background_page_apitest.cc b/chrome/browser/extensions/lazy_background_page_apitest.cc
index 4df3996..9da56b8 100644
--- a/chrome/browser/extensions/lazy_background_page_apitest.cc
+++ b/chrome/browser/extensions/lazy_background_page_apitest.cc
@@ -23,14 +23,11 @@ class LazyBackgroundPageApiTest : public ExtensionApiTest {
public:
void SetUpCommandLine(CommandLine* command_line) {
ExtensionApiTest::SetUpCommandLine(command_line);
- command_line->AppendSwitch(switches::kEnableLazyBackgroundPages);
+ command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
}
};
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) {
- ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages));
-
FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
AppendASCII("browser_action_create_tab");
ASSERT_TRUE(LoadExtension(extdir));
@@ -62,9 +59,6 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) {
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
BrowserActionCreateTabAfterCallback) {
- ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages));
-
FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
AppendASCII("browser_action_with_callback");
ASSERT_TRUE(LoadExtension(extdir));
@@ -94,9 +88,6 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
BroadcastEvent) {
- ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages));
-
FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
AppendASCII("broadcast_event");
ASSERT_TRUE(LoadExtension(extdir));
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index c61f073..b5022f5 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -540,10 +540,6 @@ const char kEnableIPCFuzzing[] = "enable-ipc-fuzzing";
// attempt to use the existing connection.
const char kEnableIPPooling[] = "enable-ip-pooling";
-// Enables some extension background pages to be loaded when they are needed
-// rather than when the extensions are first loaded.
-const char kEnableLazyBackgroundPages[] = "enable-lazy-background-pages";
-
// Enables MAC cookies in the network stack. These cookies use HMAC to protect
// session state from passive network attackers.
// http://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index f061f02..f1cd801 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -153,7 +153,6 @@ extern const char kEnableInBrowserThumbnailing[];
extern const char kEnableIPv6[];
extern const char kEnableIPCFuzzing[];
extern const char kEnableIPPooling[];
-extern const char kEnableLazyBackgroundPages[];
extern const char kEnableMacCookies[];
extern const char kEnableMemoryInfo[];
extern const char kEnableNaCl[];
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index cafd853..8a4ec53 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1287,6 +1287,29 @@ bool Extension::LoadBackgroundPage(
return true;
}
+bool Extension::LoadBackgroundPersistent(
+ const extensions::Manifest* manifest,
+ const ExtensionAPIPermissionSet& api_permissions,
+ string16* error) {
+ Value* background_persistent = NULL;
+ if (!api_permissions.count(ExtensionAPIPermission::kExperimental) ||
+ !manifest->Get(keys::kBackgroundPersistent, &background_persistent))
+ return true;
+
+ if (!background_persistent->IsType(Value::TYPE_BOOLEAN) ||
+ !background_persistent->GetAsBoolean(&background_page_persists_)) {
+ *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent);
+ return false;
+ }
+
+ if (!has_background_page()) {
+ *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage);
+ return false;
+ }
+
+ return true;
+}
+
// static
bool Extension::IsTrustedId(const std::string& id) {
// See http://b/4946060 for more details.
@@ -1299,6 +1322,7 @@ Extension::Extension(const FilePath& path, Location location)
offline_enabled_(false),
location_(location),
converted_from_user_script_(false),
+ background_page_persists_(true),
is_storage_isolated_(false),
launch_container_(extension_misc::LAUNCH_TAB),
launch_width_(0),
@@ -2027,6 +2051,9 @@ bool Extension::InitFromValue(extensions::Manifest* manifest, int flags,
if (!LoadBackgroundPage(manifest, api_permissions, error))
return false;
+ if (!LoadBackgroundPersistent(manifest, api_permissions, error))
+ return false;
+
if (manifest->HasKey(keys::kDefaultLocale)) {
if (!manifest->GetString(keys::kDefaultLocale, &default_locale_) ||
!l10n_util::IsValidLocaleSyntax(default_locale_)) {
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 6c3ed47..97b7930 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -532,6 +532,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
const std::vector<std::string>& background_scripts() const {
return background_scripts_;
}
+ bool background_page_persists() const { return background_page_persists_; }
const GURL& options_url() const { return options_url_; }
const GURL& devtools_url() const { return devtools_url_; }
const ExtensionPermissionSet* optional_permission_set() const {
@@ -676,6 +677,10 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
bool LoadBackgroundPage(const extensions::Manifest* manifest,
const ExtensionAPIPermissionSet& api_permissions,
string16* error);
+ bool LoadBackgroundPersistent(
+ const extensions::Manifest* manifest,
+ const ExtensionAPIPermissionSet& api_permissions,
+ string16* error);
// Helper method to load an ExtensionAction from the page_action or
// browser_action entries in the manifest.
@@ -809,6 +814,10 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// present, background_url_ will be empty and generated by GetBackgroundURL().
std::vector<std::string> background_scripts_;
+ // True if the background page should stay loaded forever; false if it should
+ // load on-demand (when it needs to handle an event). Defaults to true.
+ bool background_page_persists_;
+
// Optional URL to a page for setting options/preferences.
GURL options_url_;
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index 463ab35..d216cd8d 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -19,6 +19,7 @@ const char kBackground[] = "background";
const char kBackgroundPage[] = "background.page";
const char kBackgroundPageLegacy[] = "background_page";
const char kBackgroundScripts[] = "background.scripts";
+const char kBackgroundPersistent[] = "background.persistent";
const char kBrowserAction[] = "browser_action";
const char kChromeURLOverrides[] = "chrome_url_overrides";
const char kContentScripts[] = "content_scripts";
@@ -169,7 +170,7 @@ const char kInvalidAllFrames[] =
const char kInvalidBackground[] =
"Invalid value for 'background_page'.";
const char kInvalidBackgroundCombination[] =
- "The background.page and background.scripts properties cannot be used at "
+ "The background.page and background.scripts properties cannot be used at "
"the same time.";
const char kInvalidBackgroundScript[] =
"Invalid value for 'background.scripts[*]'.";
@@ -178,6 +179,11 @@ const char kInvalidBackgroundScripts[] =
const char kInvalidBackgroundInHostedApp[] =
"Invalid value for 'background_page'. Hosted apps must specify an "
"absolute HTTPS URL for the background page.";
+const char kInvalidBackgroundPersistent[] =
+ "Invalid value for 'background.persistent'.";
+const char kInvalidBackgroundPersistentNoPage[] =
+ "Must specify one of background.page or background.scripts to use"
+ " background.persistent.";
const char kInvalidBrowserAction[] =
"Invalid value for 'browser_action'.";
const char kInvalidChromeURLOverrides[] =
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index b05c4ae..ad6981b 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -20,6 +20,7 @@ namespace extension_manifest_keys {
extern const char kBackgroundPage[];
extern const char kBackgroundPageLegacy[];
extern const char kBackgroundScripts[];
+ extern const char kBackgroundPersistent[];
extern const char kBrowserAction[];
extern const char kBrowseURLs[];
extern const char kChromeURLOverrides[];
@@ -156,6 +157,8 @@ namespace extension_manifest_errors {
extern const char kInvalidBackgroundScript[];
extern const char kInvalidBackgroundScripts[];
extern const char kInvalidBackgroundInHostedApp[];
+ extern const char kInvalidBackgroundPersistent[];
+ extern const char kInvalidBackgroundPersistentNoPage[];
extern const char kInvalidBrowserAction[];
extern const char kInvalidBrowseURL[];
extern const char kInvalidBrowseURLs[];
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc
index 754d265..1acc9af 100644
--- a/chrome/renderer/extensions/extension_dispatcher.cc
+++ b/chrome/renderer/extensions/extension_dispatcher.cc
@@ -168,9 +168,10 @@ void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id,
kInitialExtensionIdleHandlerDelayMs);
}
+ const Extension* extension = extensions_.GetByID(extension_id);
// Tell the browser process that the event is dispatched and we're idle.
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages) &&
+ // TODO(mpcomplete): differentiate between background page and other views.
+ if (extension && !extension->background_page_persists() &&
function_name == "Event.dispatchJSON") { // may always be true
RenderThread::Get()->Send(
new ExtensionHostMsg_ExtensionEventAck(extension_id));
@@ -179,7 +180,9 @@ void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id,
}
void ExtensionDispatcher::CheckIdleStatus(const std::string& extension_id) {
- if (!SchemaGeneratedBindings::HasPendingRequests(extension_id))
+ const Extension* extension = extensions_.GetByID(extension_id);
+ if (extension && !extension->background_page_persists() &&
+ !SchemaGeneratedBindings::HasPendingRequests(extension_id))
RenderThread::Get()->Send(new ExtensionHostMsg_ExtensionIdle(extension_id));
}
diff --git a/chrome/renderer/extensions/extension_helper.cc b/chrome/renderer/extensions/extension_helper.cc
index f0fb442..1d3d266 100644
--- a/chrome/renderer/extensions/extension_helper.cc
+++ b/chrome/renderer/extensions/extension_helper.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -208,9 +208,7 @@ void ExtensionHelper::OnExtensionResponse(int request_id,
extension_dispatcher_->v8_context_set(), request_id, success,
response, error, &extension_id);
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableLazyBackgroundPages))
- extension_dispatcher_->CheckIdleStatus(extension_id);
+ extension_dispatcher_->CheckIdleStatus(extension_id);
}
void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id,
diff --git a/chrome/test/data/extensions/api_test/lazy_background_page/broadcast_event/manifest.json b/chrome/test/data/extensions/api_test/lazy_background_page/broadcast_event/manifest.json
index ad642c8..aa69daf 100644
--- a/chrome/test/data/extensions/api_test/lazy_background_page/broadcast_event/manifest.json
+++ b/chrome/test/data/extensions/api_test/lazy_background_page/broadcast_event/manifest.json
@@ -3,9 +3,10 @@
"description": "Warn the user when a stegosaurus might be present.",
"version": "1",
"manifest_version": 2,
- "permissions": ["tabs"],
+ "permissions": ["tabs", "experimental"],
"background": {
- "scripts": ["background.js"]
+ "scripts": ["background.js"],
+ "persistent": false
},
"icons": {"48": "icon48.png"},
"page_action": {
diff --git a/chrome/test/data/extensions/api_test/lazy_background_page/browser_action_create_tab/manifest.json b/chrome/test/data/extensions/api_test/lazy_background_page/browser_action_create_tab/manifest.json
index 205ca23..ce1014f 100644
--- a/chrome/test/data/extensions/api_test/lazy_background_page/browser_action_create_tab/manifest.json
+++ b/chrome/test/data/extensions/api_test/lazy_background_page/browser_action_create_tab/manifest.json
@@ -1,14 +1,15 @@
{
- "name": "Extensions Button",
- "description": "Access the Extensions window directly from the toolbar",
- "version": "1",
- "manifest_version": 2,
- "permissions" : ["tabs"],
- "background": {
- "scripts": ["background.js"]
- },
- "browser_action": {
- "default_icon" : "ext_icon.png",
- "default_title": "Open Extensions window"
- }
+ "name": "Extensions Button",
+ "description": "Access the Extensions window directly from the toolbar",
+ "version": "1",
+ "manifest_version": 2,
+ "permissions": ["tabs", "experimental"],
+ "background": {
+ "scripts": ["background.js"],
+ "persistent": false
+ },
+ "browser_action": {
+ "default_icon" : "ext_icon.png",
+ "default_title": "Open Extensions window"
+ }
}
diff --git a/chrome/test/data/extensions/api_test/lazy_background_page/browser_action_with_callback/manifest.json b/chrome/test/data/extensions/api_test/lazy_background_page/browser_action_with_callback/manifest.json
index 96f03cd..b0817e6 100644
--- a/chrome/test/data/extensions/api_test/lazy_background_page/browser_action_with_callback/manifest.json
+++ b/chrome/test/data/extensions/api_test/lazy_background_page/browser_action_with_callback/manifest.json
@@ -1,14 +1,15 @@
{
- "name": "Extensions Button",
- "description": "Access the Extensions window directly from the toolbar. Will not open a duplicate extensions tab.",
- "version": "1.1",
- "manifest_version": 2,
- "permissions" : ["tabs"],
- "background": {
- "scripts": ["background.js"]
- },
- "browser_action": {
- "default_icon" : "ext_icon.png",
- "default_title": "Open Extensions window"
- }
+ "name": "Extensions Button",
+ "description": "Access the Extensions window directly from the toolbar. Will not open a duplicate extensions tab.",
+ "version": "1.1",
+ "manifest_version": 2,
+ "permissions": ["tabs", "experimental"],
+ "background": {
+ "scripts": ["background.js"],
+ "persistent": false
+ },
+ "browser_action": {
+ "default_icon" : "ext_icon.png",
+ "default_title": "Open Extensions window"
+ }
}