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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 9150008: Introduce background.scripts feature for extension manifests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: picky Created 8 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 const std::string& relative_path) { 366 const std::string& relative_path) {
367 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); 367 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme));
368 DCHECK_EQ("/", extension_url.path()); 368 DCHECK_EQ("/", extension_url.path());
369 369
370 GURL ret_val = GURL(extension_url.spec() + relative_path); 370 GURL ret_val = GURL(extension_url.spec() + relative_path);
371 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); 371 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false));
372 372
373 return ret_val; 373 return ret_val;
374 } 374 }
375 375
376 GURL Extension::GetBackgroundURL() const {
377 if (!background_scripts_.empty()) {
378 return GetResourceURL(
379 extension_filenames::kGeneratedBackgroundPageFilename);
380 } else {
381 return background_url_;
382 }
383 }
384
376 bool Extension::IsResourceWebAccessible(const std::string& relative_path) 385 bool Extension::IsResourceWebAccessible(const std::string& relative_path)
377 const { 386 const {
378 // For old manifest versions which do not specify web_accessible_resources 387 // For old manifest versions which do not specify web_accessible_resources
379 // we always allow resource loads. 388 // we always allow resource loads.
380 if (manifest_version() < 2 && !HasWebAccessibleResources()) 389 if (manifest_version() < 2 && !HasWebAccessibleResources())
381 return true; 390 return true;
382 391
383 if (web_accessible_resources_.find(relative_path) != 392 if (web_accessible_resources_.find(relative_path) !=
384 web_accessible_resources_.end()) 393 web_accessible_resources_.end())
385 return true; 394 return true;
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 service.disposition = 1191 service.disposition =
1183 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; 1192 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW;
1184 } 1193 }
1185 } 1194 }
1186 1195
1187 intents_services_.push_back(service); 1196 intents_services_.push_back(service);
1188 } 1197 }
1189 return true; 1198 return true;
1190 } 1199 }
1191 1200
1201 bool Extension::LoadBackgroundScripts(const extensions::Manifest* manifest,
1202 string16* error) {
1203 Value* background_scripts_value = NULL;
1204 if (!manifest->Get(keys::kBackgroundScripts, &background_scripts_value))
1205 return true;
1206
1207 CHECK(background_scripts_value);
1208 if (background_scripts_value->GetType() != Value::TYPE_LIST) {
1209 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts);
1210 return false;
1211 }
1212
1213 ListValue* background_scripts =
1214 static_cast<ListValue*>(background_scripts_value);
1215 for (size_t i = 0; i < background_scripts->GetSize(); ++i) {
1216 std::string script;
1217 if (!background_scripts->GetString(i, &script)) {
1218 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1219 errors::kInvalidBackgroundScript, base::IntToString(i));
1220 return false;
1221 }
1222 background_scripts_.push_back(script);
Mihai Parparita -not on Chrome 2012/01/10 01:51:37 Drive by: Do you want to validate that these are r
1223 }
1224
1225 return true;
1226 }
1227
1192 bool Extension::LoadBackgroundPage( 1228 bool Extension::LoadBackgroundPage(
1193 const extensions::Manifest* manifest, 1229 const extensions::Manifest* manifest,
1194 const ExtensionAPIPermissionSet& api_permissions, 1230 const ExtensionAPIPermissionSet& api_permissions,
1195 string16* error) { 1231 string16* error) {
1196 base::Value* background_page_value = NULL; 1232 base::Value* background_page_value = NULL;
1197 if (!manifest->Get(keys::kBackgroundPage, &background_page_value)) { 1233 if (!manifest->Get(keys::kBackgroundPage, &background_page_value)) {
1198 if (manifest_version_ == 1) 1234 if (manifest_version_ == 1)
1199 manifest->Get(keys::kBackgroundPageLegacy, &background_page_value); 1235 manifest->Get(keys::kBackgroundPageLegacy, &background_page_value);
1200 } 1236 }
1201 1237
1202 if (!background_page_value) 1238 if (!background_page_value)
1203 return true; 1239 return true;
1204 1240
1205 std::string background_str; 1241 std::string background_str;
1206 if (!background_page_value->GetAsString(&background_str)) { 1242 if (!background_page_value->GetAsString(&background_str)) {
1207 *error = ASCIIToUTF16(errors::kInvalidBackground); 1243 *error = ASCIIToUTF16(errors::kInvalidBackground);
1208 return false; 1244 return false;
1209 } 1245 }
1210 1246
1247 if (!background_scripts_.empty()) {
1248 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
1249 return false;
1250 }
1251
1211 if (is_hosted_app()) { 1252 if (is_hosted_app()) {
1212 // Make sure "background" permission is set. 1253 // Make sure "background" permission is set.
1213 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { 1254 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) {
1214 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); 1255 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded);
1215 return false; 1256 return false;
1216 } 1257 }
1217 // Hosted apps require an absolute URL. 1258 // Hosted apps require an absolute URL.
1218 GURL bg_page(background_str); 1259 GURL bg_page(background_str);
1219 if (!bg_page.is_valid()) { 1260 if (!bg_page.is_valid()) {
1220 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); 1261 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 return false; 2004 return false;
1964 } 2005 }
1965 options_url_ = GetResourceURL(options_str); 2006 options_url_ = GetResourceURL(options_str);
1966 if (!options_url_.is_valid()) { 2007 if (!options_url_.is_valid()) {
1967 *error = ASCIIToUTF16(errors::kInvalidOptionsPage); 2008 *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
1968 return false; 2009 return false;
1969 } 2010 }
1970 } 2011 }
1971 } 2012 }
1972 2013
2014 if (!LoadBackgroundScripts(manifest, error))
2015 return false;
2016
1973 if (!LoadBackgroundPage(manifest, api_permissions, error)) 2017 if (!LoadBackgroundPage(manifest, api_permissions, error))
1974 return false; 2018 return false;
1975 2019
1976 if (manifest->HasKey(keys::kDefaultLocale)) { 2020 if (manifest->HasKey(keys::kDefaultLocale)) {
1977 if (!manifest->GetString(keys::kDefaultLocale, &default_locale_) || 2021 if (!manifest->GetString(keys::kDefaultLocale, &default_locale_) ||
1978 !l10n_util::IsValidLocaleSyntax(default_locale_)) { 2022 !l10n_util::IsValidLocaleSyntax(default_locale_)) {
1979 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale); 2023 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale);
1980 return false; 2024 return false;
1981 } 2025 }
1982 } 2026 }
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
2961 already_disabled(false), 3005 already_disabled(false),
2962 extension(extension) {} 3006 extension(extension) {}
2963 3007
2964 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3008 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
2965 const Extension* extension, 3009 const Extension* extension,
2966 const ExtensionPermissionSet* permissions, 3010 const ExtensionPermissionSet* permissions,
2967 Reason reason) 3011 Reason reason)
2968 : reason(reason), 3012 : reason(reason),
2969 extension(extension), 3013 extension(extension),
2970 permissions(permissions) {} 3014 permissions(permissions) {}
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698