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

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: 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
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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 const std::string& relative_path) { 369 const std::string& relative_path) {
370 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); 370 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme));
371 DCHECK_EQ("/", extension_url.path()); 371 DCHECK_EQ("/", extension_url.path());
372 372
373 GURL ret_val = GURL(extension_url.spec() + relative_path); 373 GURL ret_val = GURL(extension_url.spec() + relative_path);
374 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); 374 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false));
375 375
376 return ret_val; 376 return ret_val;
377 } 377 }
378 378
379 GURL Extension::GetBackgroundURL() const {
380 if (!background_scripts_.empty())
381 return GetResourceURL(
382 extension_filenames::kGeneratedBackgroundPageFilename);
Matt Perry 2012/01/09 21:12:17 nit: braces around multi-line if/else
383 else
384 return background_url_;
385 }
386
379 bool Extension::IsResourceWebAccessible(const std::string& relative_path) 387 bool Extension::IsResourceWebAccessible(const std::string& relative_path)
380 const { 388 const {
381 // For old manifest versions which do not specify web_accessible_resources 389 // For old manifest versions which do not specify web_accessible_resources
382 // we always allow resource loads. 390 // we always allow resource loads.
383 if (manifest_version() < 2 && !HasWebAccessibleResources()) 391 if (manifest_version() < 2 && !HasWebAccessibleResources())
384 return true; 392 return true;
385 393
386 if (web_accessible_resources_.find(relative_path) != 394 if (web_accessible_resources_.find(relative_path) !=
387 web_accessible_resources_.end()) 395 web_accessible_resources_.end())
388 return true; 396 return true;
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 service.disposition = 1243 service.disposition =
1236 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; 1244 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW;
1237 } 1245 }
1238 } 1246 }
1239 1247
1240 intents_services_.push_back(service); 1248 intents_services_.push_back(service);
1241 } 1249 }
1242 return true; 1250 return true;
1243 } 1251 }
1244 1252
1253 bool Extension::LoadBackgroundScripts(const extensions::Manifest* manifest,
1254 string16* error) {
1255 Value* background_scripts_value = NULL;
1256 if (!manifest->Get(keys::kBackgroundScripts, &background_scripts_value))
1257 return true;
1258
1259 CHECK(background_scripts_value);
1260 if (background_scripts_value->GetType() != Value::TYPE_LIST) {
1261 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts);
1262 return false;
1263 }
1264
1265 ListValue* background_scripts =
1266 static_cast<ListValue*>(background_scripts_value);
1267 for (size_t i = 0; i < background_scripts->GetSize(); ++i) {
1268 std::string script;
1269 if (!background_scripts->GetString(i, &script)) {
1270 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1271 errors::kInvalidBackgroundScript, base::IntToString(i));
1272 return false;
1273 }
1274 background_scripts_.push_back(script);
1275 }
1276
1277 return true;
1278 }
1279
1245 bool Extension::LoadBackgroundPage( 1280 bool Extension::LoadBackgroundPage(
1246 const extensions::Manifest* manifest, 1281 const extensions::Manifest* manifest,
1247 const ExtensionAPIPermissionSet& api_permissions, 1282 const ExtensionAPIPermissionSet& api_permissions,
1248 string16* error) { 1283 string16* error) {
1284 if (!background_scripts_.empty())
Matt Perry 2012/01/09 21:12:17 Maybe it should be an error to have both a backgro
1285 return true;
1286
1249 base::Value* background_page_value = NULL; 1287 base::Value* background_page_value = NULL;
1250 if (!manifest->Get(keys::kBackgroundPage, &background_page_value)) { 1288 if (!manifest->Get(keys::kBackgroundPage, &background_page_value)) {
1251 if (manifest_version_ == 1) 1289 if (manifest_version_ == 1)
1252 manifest->Get(keys::kBackgroundPageLegacy, &background_page_value); 1290 manifest->Get(keys::kBackgroundPageLegacy, &background_page_value);
1253 } 1291 }
1254 1292
1255 if (!background_page_value) 1293 if (!background_page_value)
1256 return true; 1294 return true;
1257 1295
1258 std::string background_str; 1296 std::string background_str;
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 return false; 2054 return false;
2017 } 2055 }
2018 options_url_ = GetResourceURL(options_str); 2056 options_url_ = GetResourceURL(options_str);
2019 if (!options_url_.is_valid()) { 2057 if (!options_url_.is_valid()) {
2020 *error = ASCIIToUTF16(errors::kInvalidOptionsPage); 2058 *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
2021 return false; 2059 return false;
2022 } 2060 }
2023 } 2061 }
2024 } 2062 }
2025 2063
2064 if (!LoadBackgroundScripts(manifest, error))
2065 return false;
2066
2026 if (!LoadBackgroundPage(manifest, api_permissions, error)) 2067 if (!LoadBackgroundPage(manifest, api_permissions, error))
2027 return false; 2068 return false;
2028 2069
2029 if (manifest->HasKey(keys::kDefaultLocale)) { 2070 if (manifest->HasKey(keys::kDefaultLocale)) {
2030 if (!manifest->GetString(keys::kDefaultLocale, &default_locale_) || 2071 if (!manifest->GetString(keys::kDefaultLocale, &default_locale_) ||
2031 !l10n_util::IsValidLocaleSyntax(default_locale_)) { 2072 !l10n_util::IsValidLocaleSyntax(default_locale_)) {
2032 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale); 2073 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale);
2033 return false; 2074 return false;
2034 } 2075 }
2035 } 2076 }
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 already_disabled(false), 3071 already_disabled(false),
3031 extension(extension) {} 3072 extension(extension) {}
3032 3073
3033 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3074 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3034 const Extension* extension, 3075 const Extension* extension,
3035 const ExtensionPermissionSet* permissions, 3076 const ExtensionPermissionSet* permissions,
3036 Reason reason) 3077 Reason reason)
3037 : reason(reason), 3078 : reason(reason),
3038 extension(extension), 3079 extension(extension),
3039 permissions(permissions) {} 3080 permissions(permissions) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698