summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions
diff options
context:
space:
mode:
authorcreis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 18:06:53 +0000
committercreis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 18:06:53 +0000
commit7b54ca0d914878f39e784bc4fd2046286817b319 (patch)
treeec2dd9a2d387b70105b676ccbff7588ce6b57db9 /chrome/common/extensions
parentc503402a1b3b3f0592e08281de6053f34147fd77 (diff)
downloadchromium_src-7b54ca0d914878f39e784bc4fd2046286817b319.zip
chromium_src-7b54ca0d914878f39e784bc4fd2046286817b319.tar.gz
chromium_src-7b54ca0d914878f39e784bc4fd2046286817b319.tar.bz2
Allow apps with background pages to request process-per-app-instance.
Requires setting background.allow_js_access to false in manifest. BUG=113444 TEST=Example hosted app has different processes in different tabs. Review URL: http://codereview.chromium.org/9508008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124684 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r--chrome/common/extensions/extension.cc25
-rw-r--r--chrome/common/extensions/extension.h12
-rw-r--r--chrome/common/extensions/extension_constants.cc8
-rw-r--r--chrome/common/extensions/extension_constants.h5
-rw-r--r--chrome/common/extensions/extension_manifests_unittest.cc8
5 files changed, 56 insertions, 2 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index dd9fb92..2c1cfc5 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1515,6 +1515,27 @@ bool Extension::LoadBackgroundPersistent(
return true;
}
+bool Extension::LoadBackgroundAllowJsAccess(
+ const ExtensionAPIPermissionSet& api_permissions,
+ string16* error) {
+ Value* allow_js_access = NULL;
+ if (!manifest_->Get(keys::kBackgroundAllowJsAccess, &allow_js_access))
+ return true;
+
+ if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) ||
+ !allow_js_access->GetAsBoolean(&allow_background_js_access_)) {
+ *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess);
+ return false;
+ }
+
+ if (!has_background_page()) {
+ *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccessNoPage);
+ return false;
+ }
+
+ return true;
+}
+
// static
bool Extension::IsTrustedId(const std::string& id) {
// See http://b/4946060 for more details.
@@ -1528,6 +1549,7 @@ Extension::Extension(const FilePath& path,
offline_enabled_(false),
converted_from_user_script_(false),
background_page_persists_(true),
+ allow_background_js_access_(true),
manifest_(manifest.release()),
is_storage_isolated_(false),
launch_container_(extension_misc::LAUNCH_TAB),
@@ -2325,6 +2347,9 @@ bool Extension::InitFromValue(int flags, string16* error) {
if (!LoadBackgroundPersistent(api_permissions, error))
return false;
+ if (!LoadBackgroundAllowJsAccess(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 0f789eb..9558d21 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -557,6 +557,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
bool has_background_page() const {
return background_url_.is_valid() || !background_scripts_.empty();
}
+ bool allow_background_js_access() const {
+ return allow_background_js_access_;
+ }
const std::vector<std::string>& background_scripts() const {
return background_scripts_;
}
@@ -704,6 +707,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
bool LoadBackgroundPersistent(
const ExtensionAPIPermissionSet& api_permissions,
string16* error);
+ bool LoadBackgroundAllowJsAccess(
+ const ExtensionAPIPermissionSet& api_permissions,
+ string16* error);
// Helper method that loads a UserScript object from a
// dictionary in the content_script list of the manifest.
@@ -857,6 +863,12 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// load on-demand (when it needs to handle an event). Defaults to true.
bool background_page_persists_;
+ // True if the background page can be scripted by pages of the app or
+ // extension, in which case all such pages must run in the same process.
+ // False if such pages are not permitted to script the background page,
+ // allowing them to run in different processes.
+ bool allow_background_js_access_;
+
// 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 c50c2e5..868dc3c 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -16,10 +16,11 @@ const char kAllFrames[] = "all_frames";
const char kAltKey[] = "altKey";
const char kApp[] = "app";
const char kBackground[] = "background";
+const char kBackgroundAllowJsAccess[] = "background.allow_js_access";
const char kBackgroundPage[] = "background.page";
const char kBackgroundPageLegacy[] = "background_page";
-const char kBackgroundScripts[] = "background.scripts";
const char kBackgroundPersistent[] = "background.persistent";
+const char kBackgroundScripts[] = "background.scripts";
const char kBrowserAction[] = "browser_action";
const char kChromeURLOverrides[] = "chrome_url_overrides";
const char kCommands[] = "commands";
@@ -179,6 +180,11 @@ const char kInvalidAllFrames[] =
"Invalid value for 'content_scripts[*].all_frames'.";
const char kInvalidBackground[] =
"Invalid value for 'background_page'.";
+const char kInvalidBackgroundAllowJsAccess[] =
+ "Invalid value for 'background.allow_js_access'.";
+const char kInvalidBackgroundAllowJsAccessNoPage[] =
+ "Must specify one of background.page or background.scripts to use"
+ " background.allow_js_access.";
const char kInvalidBackgroundCombination[] =
"The background.page and background.scripts properties cannot be used at "
"the same time.";
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index ca87caa..4ceb45e 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -17,10 +17,11 @@ namespace extension_manifest_keys {
extern const char kAltKey[];
extern const char kApp[];
extern const char kBackground[];
+ extern const char kBackgroundAllowJsAccess[];
extern const char kBackgroundPage[];
extern const char kBackgroundPageLegacy[];
- extern const char kBackgroundScripts[];
extern const char kBackgroundPersistent[];
+ extern const char kBackgroundScripts[];
extern const char kBrowserAction[];
extern const char kBrowseURLs[];
extern const char kChromeURLOverrides[];
@@ -162,6 +163,8 @@ namespace extension_manifest_errors {
extern const char kFeatureNotAllowed[];
extern const char kInvalidAllFrames[];
extern const char kInvalidBackground[];
+ extern const char kInvalidBackgroundAllowJsAccess[];
+ extern const char kInvalidBackgroundAllowJsAccessNoPage[];
extern const char kInvalidBackgroundCombination[];
extern const char kInvalidBackgroundScript[];
extern const char kInvalidBackgroundScripts[];
diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc
index e1d108f..23e3847 100644
--- a/chrome/common/extensions/extension_manifests_unittest.cc
+++ b/chrome/common/extensions/extension_manifests_unittest.cc
@@ -1037,6 +1037,7 @@ TEST_F(ExtensionManifestTest, BackgroundPage) {
LoadAndExpectSuccess("background_page.json"));
ASSERT_TRUE(extension);
EXPECT_EQ("/foo.html", extension->GetBackgroundURL().path());
+ EXPECT_TRUE(extension->allow_background_js_access());
std::string error;
scoped_ptr<DictionaryValue> manifest(
@@ -1077,6 +1078,13 @@ TEST_F(ExtensionManifestTest, BackgroundScripts) {
errors::kInvalidBackgroundCombination);
}
+TEST_F(ExtensionManifestTest, BackgroundAllowNoJsAccess) {
+ scoped_refptr<Extension> extension;
+ extension = LoadAndExpectSuccess("background_allow_no_js_access.json");
+ ASSERT_TRUE(extension);
+ EXPECT_FALSE(extension->allow_background_js_access());
+}
+
TEST_F(ExtensionManifestTest, PageActionManifestVersion2) {
scoped_refptr<Extension> extension(
LoadAndExpectSuccess("page_action_manifest_version_2.json"));