diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-13 18:00:25 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-13 18:00:25 +0000 |
commit | 7492275526897a62fe04400aa536dde5c51278d7 (patch) | |
tree | 187d8e83d349b975adf00c1f31d1c6e2630f4e7a /chrome/common | |
parent | 0fc357452454dbcf342314dfa828bdcb2dd560be (diff) | |
download | chromium_src-7492275526897a62fe04400aa536dde5c51278d7.zip chromium_src-7492275526897a62fe04400aa536dde5c51278d7.tar.gz chromium_src-7492275526897a62fe04400aa536dde5c51278d7.tar.bz2 |
apps: Add 'background_page' support for hosted apps.
A hosted app can have a 'background_page' if it has 'background' 'permission'.
The 'background_page' will launch immediately after the app is installed.
BUG=77718
TEST=AppBackgroundPageApiTest.ManifestBackgroundPage, and existing tests.
Review URL: http://codereview.chromium.org/6708100
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81438 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/chrome_switches.cc | 3 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 52 | ||||
-rw-r--r-- | chrome/common/extensions/extension_constants.cc | 8 | ||||
-rw-r--r-- | chrome/common/extensions/extension_constants.h | 2 | ||||
-rw-r--r-- | chrome/common/extensions/extension_file_util.cc | 6 | ||||
-rw-r--r-- | chrome/common/extensions/extension_manifests_unittest.cc | 6 |
7 files changed, 60 insertions, 18 deletions
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 82a4ab9..44aa7cd 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -21,6 +21,9 @@ const char kActivateOnLaunch[] = "activate-on-launch"; // directories. This switch re-enables file:// for testing. const char kAllowFileAccess[] = "allow-file-access"; +// Allow non-https URL for background_page for hosted apps. +const char kAllowHTTPBackgroundPage[] = "allow-http-background-page"; + // Don't block outdated plugins. const char kAllowOutdatedPlugins[] = "allow-outdated-plugins"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 582c41d..640e764 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -26,6 +26,7 @@ namespace switches { extern const char kActivateOnLaunch[]; extern const char kAllowFileAccess[]; extern const char kAllowOutdatedPlugins[]; +extern const char kAllowHTTPBackgroundPage[]; extern const char kAllowScriptingGallery[]; extern const char kAlwaysAuthorizePlugins[]; extern const char kAlwaysEnableDevTools[]; diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 3fc7be1..471dd11 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -1284,8 +1284,10 @@ bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest, if (!IsBaseCrxKey(*key) && *key != keys::kApp && *key != keys::kPermissions && - *key != keys::kOptionsPage) { - *error = errors::kHostedAppsCannotIncludeExtensionFeatures; + *key != keys::kOptionsPage && + *key != keys::kBackground) { + *error = ExtensionErrorUtils::FormatErrorMessage( + errors::kHostedAppsCannotIncludeExtensionFeatures, *key); return false; } } @@ -1854,16 +1856,6 @@ bool Extension::InitFromValue(const DictionaryValue& source, int flags, } } - // Initialize background url (optional). - if (source.HasKey(keys::kBackground)) { - std::string background_str; - if (!source.GetString(keys::kBackground, &background_str)) { - *error = errors::kInvalidBackground; - return false; - } - background_url_ = GetResourceURL(background_str); - } - // Initialize toolstrips. This is deprecated for public use. // NOTE(erikkay) Although deprecated, we intend to preserve this parsing // code indefinitely. Please contact me or Joi for details as to why. @@ -2012,7 +2004,6 @@ bool Extension::InitFromValue(const DictionaryValue& source, int flags, return false; } options_url_ = options_url; - } else { GURL absolute(options_str); if (absolute.is_valid()) { @@ -2118,6 +2109,41 @@ bool Extension::InitFromValue(const DictionaryValue& source, int flags, } } + // Initialize background url (optional). + if (source.HasKey(keys::kBackground)) { + std::string background_str; + if (!source.GetString(keys::kBackground, &background_str)) { + *error = errors::kInvalidBackground; + return false; + } + + if (is_hosted_app()) { + // Make sure "background" permission is set. + if (api_permissions_.find(kBackgroundPermission) == + api_permissions_.end()) { + *error = errors::kBackgroundPermissionNeeded; + return false; + } + // Hosted apps require an absolute URL. + GURL bg_page(background_str); + if (!bg_page.is_valid()) { + *error = errors::kInvalidBackgroundInHostedApp; + return false; + } + + if (!(bg_page.SchemeIs("https") || + (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kAllowHTTPBackgroundPage) && + bg_page.SchemeIs("http")))) { + *error = errors::kInvalidBackgroundInHostedApp; + return false; + } + background_url_ = bg_page; + } else { + background_url_ = GetResourceURL(background_str); + } + } + if (source.HasKey(keys::kDefaultLocale)) { if (!source.GetString(keys::kDefaultLocale, &default_locale_) || !l10n_util::IsValidLocaleSyntax(default_locale_)) { diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc index 97243e5..27324ef 100644 --- a/chrome/common/extensions/extension_constants.cc +++ b/chrome/common/extensions/extension_constants.cc @@ -102,6 +102,9 @@ const char* kLaunchContainerWindow = "window"; namespace extension_manifest_errors { const char* kAppsNotEnabled = "Apps are not enabled."; +const char* kBackgroundPermissionNeeded = + "Hosted apps that use 'background_page' must have the 'background' " + "permission."; const char* kCannotAccessPage = "Cannot access contents of url \"*\". " "Extension manifest must request permission to access this host."; @@ -128,11 +131,14 @@ const char *kExperimentalFeature = "This feature requires 'experimental' permissions and" " --enable-experimental-extension-apis command line flag."; const char* kHostedAppsCannotIncludeExtensionFeatures = - "Hosted apps cannot use extension features."; + "Hosted apps cannot use the extension feature '*'."; const char* kInvalidAllFrames = "Invalid value for 'content_scripts[*].all_frames'."; const char* kInvalidBackground = "Invalid value for 'background_page'."; +const char* kInvalidBackgroundInHostedApp = + "Invalid value for 'background_page'. Hosted apps must specify an " + "absolute HTTPS URL for the background page."; 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 daa2156..f05c947 100644 --- a/chrome/common/extensions/extension_constants.h +++ b/chrome/common/extensions/extension_constants.h @@ -104,6 +104,7 @@ namespace extension_manifest_values { // Error messages returned from Extension::InitFromValue(). namespace extension_manifest_errors { extern const char* kAppsNotEnabled; + extern const char* kBackgroundPermissionNeeded; extern const char* kCannotAccessPage; extern const char* kCannotClaimAllHostsInExtent; extern const char* kCannotClaimAllURLsInExtent; @@ -118,6 +119,7 @@ namespace extension_manifest_errors { extern const char* kHostedAppsCannotIncludeExtensionFeatures; extern const char* kInvalidAllFrames; extern const char* kInvalidBackground; + extern const char* kInvalidBackgroundInHostedApp; extern const char* kInvalidBrowserAction; extern const char* kInvalidBrowseURL; extern const char* kInvalidBrowseURLs; diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc index 1c4ec8c..be34cfb 100644 --- a/chrome/common/extensions/extension_file_util.cc +++ b/chrome/common/extensions/extension_file_util.cc @@ -245,8 +245,10 @@ bool ValidateExtension(Extension* extension, std::string* error) { } } - // Validate background page location. - if (!extension->background_url().is_empty()) { + // Validate background page location, except for hosted apps, which should use + // an external URL. Background page for hosted apps are verified when the + // extension is created (in Extension::InitFromValue) + if (!extension->background_url().is_empty() && !extension->is_hosted_app()) { FilePath page_path = ExtensionURLToRelativeFilePath( extension->background_url()); const FilePath path = extension->GetResource(page_path).GetFilePath(); diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc index 5deef17..e49ec0a 100644 --- a/chrome/common/extensions/extension_manifests_unittest.cc +++ b/chrome/common/extensions/extension_manifests_unittest.cc @@ -405,9 +405,11 @@ TEST_F(ExtensionManifestTest, Sidebar) { TEST_F(ExtensionManifestTest, DisallowHybridApps) { LoadAndExpectError("disallow_hybrid_1.json", - errors::kHostedAppsCannotIncludeExtensionFeatures); + ExtensionErrorUtils::FormatErrorMessage( + errors::kHostedAppsCannotIncludeExtensionFeatures, + keys::kBrowserAction)); LoadAndExpectError("disallow_hybrid_2.json", - errors::kHostedAppsCannotIncludeExtensionFeatures); + errors::kBackgroundPermissionNeeded); } TEST_F(ExtensionManifestTest, OptionsPageInApps) { |