Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7537)

Unified Diff: chrome/common/extensions/extension.cc

Issue 12253022: Manifest handler for all keys background-related. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 9b7eabfc39d6767b2c32714d5cd17001d03ce105..32deb6f440b9f711789e3c131dde5f7d2cb6b881 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -29,6 +29,8 @@
#include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/extensions/api/extension_action/page_action_handler.h"
#include "chrome/common/extensions/api/themes/theme_handler.h"
+// TODO(yoz): should not need this include.
+#include "chrome/common/extensions/background_info.h"
#include "chrome/common/extensions/csp_validator.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/extension_resource.h"
@@ -172,7 +174,7 @@ bool ReadLaunchDimension(const extensions::Manifest* manifest,
int* target,
bool is_valid_container,
string16* error) {
- Value* temp = NULL;
+ const Value* temp = NULL;
if (manifest->Get(key, &temp)) {
if (!is_valid_container) {
*error = ErrorUtils::FormatErrorMessageUTF16(
@@ -594,7 +596,7 @@ bool Extension::ParsePermissions(const char* key,
APIPermissionSet* api_permissions,
URLPatternSet* host_permissions) {
if (manifest_->HasKey(key)) {
- ListValue* permissions = NULL;
+ const ListValue* permissions = NULL;
if (!manifest_->GetList(key, &permissions)) {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidPermissions, "");
@@ -1194,12 +1196,6 @@ ExtensionResource Extension::GetContentPackSiteList() const {
return GetResource(content_pack_site_list_);
}
-GURL Extension::GetBackgroundURL() const {
- if (background_scripts_.empty())
- return background_url_;
- return GetResourceURL(extension_filenames::kGeneratedBackgroundPageFilename);
-}
-
Extension::RuntimeData::RuntimeData() {}
Extension::RuntimeData::RuntimeData(const PermissionSet* active)
: active_permissions_(active) {}
@@ -1302,7 +1298,7 @@ base::FilePath Extension::MaybeNormalizePath(const base::FilePath& path) {
bool Extension::LoadManagedModeFeatures(string16* error) {
if (!manifest_->HasKey(keys::kContentPack))
return true;
- DictionaryValue* content_pack_value = NULL;
+ const DictionaryValue* content_pack_value = NULL;
if (!manifest_->GetDictionary(keys::kContentPack, &content_pack_value)) {
*error = ASCIIToUTF16(errors::kInvalidContentPack);
return false;
@@ -1352,8 +1348,6 @@ Extension::Extension(const base::FilePath& path,
incognito_split_mode_(false),
offline_enabled_(false),
converted_from_user_script_(false),
- background_page_is_persistent_(true),
- allow_background_js_access_(true),
manifest_(manifest.release()),
finished_parsing_manifest_(false),
is_storage_isolated_(false),
@@ -1492,7 +1486,7 @@ bool Extension::LoadAppIsolation(string16* error) {
|| !is_app())
return true;
- Value* tmp_isolation = NULL;
+ const Value* tmp_isolation = NULL;
if (!manifest_->Get(keys::kIsolation, &tmp_isolation))
return true;
@@ -1501,7 +1495,8 @@ bool Extension::LoadAppIsolation(string16* error) {
return false;
}
- ListValue* isolation_list = static_cast<ListValue*>(tmp_isolation);
+ const ListValue* isolation_list = NULL;
+ tmp_isolation->GetAsList(&isolation_list);
Matt Perry 2013/02/15 20:15:02 As long as you using this method, combine it with
Yoyo Zhou 2013/02/16 00:54:04 Done.
for (size_t i = 0; i < isolation_list->GetSize(); ++i) {
std::string isolation_string;
if (!isolation_list->GetString(i, &isolation_string)) {
@@ -1584,7 +1579,7 @@ bool Extension::LoadExtent(const char* key,
const char* list_error,
const char* value_error,
string16* error) {
- Value* temp_pattern_value = NULL;
+ const Value* temp_pattern_value = NULL;
if (!manifest_->Get(key, &temp_pattern_value))
return true;
@@ -1593,7 +1588,8 @@ bool Extension::LoadExtent(const char* key,
return false;
}
- ListValue* pattern_list = static_cast<ListValue*>(temp_pattern_value);
+ const ListValue* pattern_list = NULL;
+ temp_pattern_value->GetAsList(&pattern_list);
for (size_t i = 0; i < pattern_list->GetSize(); ++i) {
std::string pattern_string;
if (!pattern_list->GetString(i, &pattern_string)) {
@@ -1654,7 +1650,7 @@ bool Extension::LoadExtent(const char* key,
}
bool Extension::LoadLaunchContainer(string16* error) {
- Value* tmp_launcher_container = NULL;
+ const Value* tmp_launcher_container = NULL;
if (!manifest_->Get(keys::kLaunchContainer, &tmp_launcher_container))
return true;
@@ -1699,7 +1695,7 @@ bool Extension::LoadLaunchContainer(string16* error) {
}
bool Extension::LoadLaunchURL(string16* error) {
- Value* temp = NULL;
+ const Value* temp = NULL;
// launch URL can be either local (to chrome-extension:// root) or an absolute
// web URL.
@@ -1818,12 +1814,7 @@ bool Extension::LoadSharedFeatures(string16* error) {
!LoadNaClModules(error) ||
!LoadSandboxedPages(error) ||
!LoadRequirements(error) ||
- !LoadOfflineEnabled(error) ||
- // LoadBackgroundScripts() must be called before LoadBackgroundPage().
- !LoadBackgroundScripts(error) ||
- !LoadBackgroundPage(error) ||
- !LoadBackgroundPersistent(error) ||
- !LoadBackgroundAllowJSAccess(error))
+ !LoadOfflineEnabled(error))
return false;
return true;
@@ -1867,7 +1858,7 @@ bool Extension::LoadManifestVersion(string16* error) {
bool Extension::LoadIcons(string16* error) {
if (!manifest_->HasKey(keys::kIcons))
return true;
- DictionaryValue* icons_value = NULL;
+ const DictionaryValue* icons_value = NULL;
if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) {
*error = ASCIIToUTF16(errors::kInvalidIcons);
return false;
@@ -1885,14 +1876,14 @@ bool Extension::LoadPlugins(string16* error) {
if (!manifest_->HasKey(keys::kPlugins))
return true;
- ListValue* list_value = NULL;
+ const ListValue* list_value = NULL;
if (!manifest_->GetList(keys::kPlugins, &list_value)) {
*error = ASCIIToUTF16(errors::kInvalidPlugins);
return false;
}
for (size_t i = 0; i < list_value->GetSize(); ++i) {
- DictionaryValue* plugin_value = NULL;
+ const DictionaryValue* plugin_value = NULL;
if (!list_value->GetDictionary(i, &plugin_value)) {
*error = ASCIIToUTF16(errors::kInvalidPlugins);
return false;
@@ -1937,14 +1928,14 @@ bool Extension::LoadPlugins(string16* error) {
bool Extension::LoadNaClModules(string16* error) {
if (!manifest_->HasKey(keys::kNaClModules))
return true;
- ListValue* list_value = NULL;
+ const ListValue* list_value = NULL;
if (!manifest_->GetList(keys::kNaClModules, &list_value)) {
*error = ASCIIToUTF16(errors::kInvalidNaClModules);
return false;
}
for (size_t i = 0; i < list_value->GetSize(); ++i) {
- DictionaryValue* module_value = NULL;
+ const DictionaryValue* module_value = NULL;
if (!list_value->GetDictionary(i, &module_value)) {
*error = ASCIIToUTF16(errors::kInvalidNaClModules);
return false;
@@ -1978,7 +1969,7 @@ bool Extension::LoadSandboxedPages(string16* error) {
if (!manifest_->HasPath(keys::kSandboxedPages))
return true;
- ListValue* list_value = NULL;
+ const ListValue* list_value = NULL;
if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) {
*error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList);
return false;
@@ -2029,14 +2020,14 @@ bool Extension::LoadSandboxedPages(string16* error) {
bool Extension::LoadRequirements(string16* error) {
// Before parsing requirements from the manifest, automatically default the
// NPAPI plugin requirement based on whether it includes NPAPI plugins.
- ListValue* list_value = NULL;
+ const ListValue* list_value = NULL;
requirements_.npapi =
manifest_->GetList(keys::kPlugins, &list_value) && !list_value->empty();
if (!manifest_->HasKey(keys::kRequirements))
return true;
- DictionaryValue* requirements_value = NULL;
+ const DictionaryValue* requirements_value = NULL;
if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) {
*error = ASCIIToUTF16(errors::kInvalidRequirements);
return false;
@@ -2115,134 +2106,6 @@ bool Extension::LoadOfflineEnabled(string16* error) {
return true;
}
-bool Extension::LoadBackgroundScripts(string16* error) {
- const std::string& key = is_platform_app() ?
- keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts;
- return LoadBackgroundScripts(key, error);
-}
-
-bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) {
- Value* background_scripts_value = NULL;
- if (!manifest_->Get(key, &background_scripts_value))
- return true;
-
- CHECK(background_scripts_value);
- if (background_scripts_value->GetType() != Value::TYPE_LIST) {
- *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts);
- return false;
- }
-
- ListValue* background_scripts =
- static_cast<ListValue*>(background_scripts_value);
- for (size_t i = 0; i < background_scripts->GetSize(); ++i) {
- std::string script;
- if (!background_scripts->GetString(i, &script)) {
- *error = ErrorUtils::FormatErrorMessageUTF16(
- errors::kInvalidBackgroundScript, base::IntToString(i));
- return false;
- }
- background_scripts_.push_back(script);
- }
-
- return true;
-}
-
-bool Extension::LoadBackgroundPage(string16* error) {
- if (is_platform_app()) {
- return LoadBackgroundPage(keys::kPlatformAppBackgroundPage, error);
- }
-
- if (!LoadBackgroundPage(keys::kBackgroundPage, error))
- return false;
- if (background_url_.is_empty()) {
- return LoadBackgroundPage(
- keys::kBackgroundPageLegacy, error);
- }
- return true;
-}
-
-bool Extension::LoadBackgroundPage(const std::string& key, string16* error) {
- base::Value* background_page_value = NULL;
- if (!manifest_->Get(key, &background_page_value))
- return true;
-
- if (!background_scripts_.empty()) {
- *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
- return false;
- }
-
-
- std::string background_str;
- if (!background_page_value->GetAsString(&background_str)) {
- *error = ASCIIToUTF16(errors::kInvalidBackground);
- return false;
- }
-
- if (is_hosted_app()) {
- background_url_ = GURL(background_str);
-
- // Make sure "background" permission is set.
- if (!initial_api_permissions()->count(APIPermission::kBackground)) {
- *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded);
- return false;
- }
- // Hosted apps require an absolute URL.
- if (!background_url_.is_valid()) {
- *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
- return false;
- }
-
- if (!(background_url_.SchemeIs("https") ||
- (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kAllowHTTPBackgroundPage) &&
- background_url_.SchemeIs("http")))) {
- *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
- return false;
- }
- } else {
- background_url_ = GetResourceURL(background_str);
- }
-
- return true;
-}
-
-bool Extension::LoadBackgroundPersistent(string16* error) {
- if (is_platform_app()) {
- background_page_is_persistent_ = false;
- return true;
- }
-
- Value* background_persistent = NULL;
- if (!manifest_->Get(keys::kBackgroundPersistent, &background_persistent))
- return true;
-
- if (!background_persistent->GetAsBoolean(&background_page_is_persistent_)) {
- *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent);
- return false;
- }
-
- if (!has_background_page()) {
- *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage);
- return false;
- }
-
- return true;
-}
-
-bool Extension::LoadBackgroundAllowJSAccess(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;
- }
-
- return true;
-}
-
bool Extension::LoadExtensionFeatures(string16* error) {
if (manifest_->HasKey(keys::kConvertedFromUserScript))
manifest_->GetBoolean(keys::kConvertedFromUserScript,
@@ -2260,14 +2123,14 @@ bool Extension::LoadExtensionFeatures(string16* error) {
bool Extension::LoadContentScripts(string16* error) {
if (!manifest_->HasKey(keys::kContentScripts))
return true;
- ListValue* list_value;
+ const ListValue* list_value;
if (!manifest_->GetList(keys::kContentScripts, &list_value)) {
*error = ASCIIToUTF16(errors::kInvalidContentScriptsList);
return false;
}
for (size_t i = 0; i < list_value->GetSize(); ++i) {
- DictionaryValue* content_script = NULL;
+ const DictionaryValue* content_script = NULL;
if (!list_value->GetDictionary(i, &content_script)) {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidContentScript, base::IntToString(i));
@@ -2293,7 +2156,7 @@ bool Extension::LoadSystemIndicator(string16* error) {
return true;
}
- DictionaryValue* system_indicator_value = NULL;
+ const DictionaryValue* system_indicator_value = NULL;
if (!manifest_->GetDictionary(keys::kSystemIndicator,
&system_indicator_value)) {
*error = ASCIIToUTF16(errors::kInvalidSystemIndicator);
@@ -2737,7 +2600,7 @@ bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const {
if (!is_platform_app())
return true;
- if (!has_background_page()) {
+ if (!BackgroundInfo::HasBackgroundPage(this)) {
*utf8_error = errors::kBackgroundRequiredForPlatformApps;
return false;
}
@@ -2751,7 +2614,7 @@ bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const {
}
bool Extension::CheckConflictingFeatures(std::string* utf8_error) const {
- if (has_lazy_background_page() &&
+ if (BackgroundInfo::HasLazyBackgroundPage(this) &&
HasAPIPermission(APIPermission::kWebRequest)) {
*utf8_error = errors::kWebRequestConflictsWithLazyBackground;
return false;

Powered by Google App Engine
This is Rietveld 408576698