diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 21:15:10 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 21:15:10 +0000 |
commit | f1bab9c91785bb381347026848c21a3212ebe043 (patch) | |
tree | f92310afe61262535f887c39a1747f5add65944a | |
parent | bdceafac0b64fe49b0c14af00727117e1555f13f (diff) | |
download | chromium_src-f1bab9c91785bb381347026848c21a3212ebe043.zip chromium_src-f1bab9c91785bb381347026848c21a3212ebe043.tar.gz chromium_src-f1bab9c91785bb381347026848c21a3212ebe043.tar.bz2 |
Disallow the webRequest API with an event page.
BUG=119613
TEST=no
Review URL: https://chromiumcodereview.appspot.com/10381076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136665 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 43 insertions, 3 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 13f5665..7b836d3 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -299,7 +299,8 @@ scoped_refptr<Extension> Extension::Create(const FilePath& path, return NULL; } - if (!extension->CheckPlatformAppFeatures(utf8_error)) + if (!extension->CheckPlatformAppFeatures(utf8_error) || + !extension->CheckConflictingFeatures(utf8_error)) return NULL; return extension; @@ -3519,6 +3520,16 @@ bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) { return true; } +bool Extension::CheckConflictingFeatures(std::string* utf8_error) { + if (has_lazy_background_page() && + HasAPIPermission(ExtensionAPIPermission::kWebRequest)) { + *utf8_error = errors::kWebRequestConflictsWithLazyBackground; + return false; + } + + return true; +} + ExtensionInfo::~ExtensionInfo() {} Extension::RuntimeData::RuntimeData() {} diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index b45268d..b1665c6 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -845,6 +845,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> { // Check that platform app features are valid. Called after InitFromValue. bool CheckPlatformAppFeatures(std::string* utf8_error); + // Check that features don't conflict. Called after InitFromValue. + bool CheckConflictingFeatures(std::string* utf8_error); + // Cached images for this extension. This should only be touched on the UI // thread. mutable ImageCache image_cache_; diff --git a/chrome/common/extensions/extension_manifest_constants.cc b/chrome/common/extensions/extension_manifest_constants.cc index c728f3a..7ebfb05 100644 --- a/chrome/common/extensions/extension_manifest_constants.cc +++ b/chrome/common/extensions/extension_manifest_constants.cc @@ -471,6 +471,8 @@ const char kPlatformAppNeedsManifestVersion2[] = "Platform apps need manifest_version set to >= 2"; const char kReservedMessageFound[] = "Reserved key * found in message catalog."; +const char kWebRequestConflictsWithLazyBackground[] = + "The 'webRequest' API cannot be used with event pages."; #if defined(OS_CHROMEOS) const char kIllegalPlugins[] = "Extensions cannot install plugins on Chrome OS"; diff --git a/chrome/common/extensions/extension_manifest_constants.h b/chrome/common/extensions/extension_manifest_constants.h index 870f949..fa39857 100644 --- a/chrome/common/extensions/extension_manifest_constants.h +++ b/chrome/common/extensions/extension_manifest_constants.h @@ -312,7 +312,7 @@ namespace extension_manifest_errors { extern const char kPlatformAppNeedsManifestVersion2[]; extern const char kOneUISurfaceOnly[]; extern const char kReservedMessageFound[]; - extern const char kWebContentMustBeEnabled[]; + extern const char kWebRequestConflictsWithLazyBackground[]; #if defined(OS_CHROMEOS) extern const char kIllegalPlugins[]; #endif diff --git a/chrome/common/extensions/manifest_tests/extension_manifests_background_unittest.cc b/chrome/common/extensions/manifest_tests/extension_manifests_background_unittest.cc index 5dd777a..7bd211d 100644 --- a/chrome/common/extensions/manifest_tests/extension_manifests_background_unittest.cc +++ b/chrome/common/extensions/manifest_tests/extension_manifests_background_unittest.cc @@ -4,8 +4,10 @@ #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" -#include "base/values.h" +#include "base/command_line.h" #include "base/memory/scoped_ptr.h" +#include "base/values.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_error_utils.h" #include "chrome/common/extensions/extension_manifest_constants.h" @@ -84,4 +86,26 @@ TEST_F(ExtensionManifestTest, BackgroundAllowNoJsAccess) { EXPECT_FALSE(extension->allow_background_js_access()); } +TEST_F(ExtensionManifestTest, BackgroundPageWebRequest) { + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + + std::string error; + scoped_ptr<DictionaryValue> manifest( + LoadManifestFile("background_page.json", &error)); + ASSERT_TRUE(manifest.get()); + manifest->SetBoolean(keys::kBackgroundPersistent, false); + manifest->SetInteger(keys::kManifestVersion, 2); + scoped_refptr<Extension> extension( + LoadAndExpectSuccess(Manifest(manifest.get(), ""))); + ASSERT_TRUE(extension); + EXPECT_TRUE(extension->has_lazy_background_page()); + + ListValue* permissions = new ListValue(); + permissions->Append(Value::CreateStringValue("webRequest")); + manifest->Set(keys::kPermissions, permissions); + LoadAndExpectError(Manifest(manifest.get(), ""), + errors::kWebRequestConflictsWithLazyBackground); +} + } // namespace extensions |