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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 8313006: Allow webstore extensions to use experimental permissions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 2 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/browser/extensions/extension_service.h ('k') | chrome/common/extensions/extension.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser/extensions/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 1250
1251 if (reload_reason != NOT_NEEDED) { 1251 if (reload_reason != NOT_NEEDED) {
1252 // Reloading and extension reads files from disk. We do this on the 1252 // Reloading and extension reads files from disk. We do this on the
1253 // UI thread because reloads should be very rare, and the complexity 1253 // UI thread because reloads should be very rare, and the complexity
1254 // added by delaying the time when the extensions service knows about 1254 // added by delaying the time when the extensions service knows about
1255 // all extensions is significant. See crbug.com/37548 for details. 1255 // all extensions is significant. See crbug.com/37548 for details.
1256 // |allow_io| disables tests that file operations run on the file 1256 // |allow_io| disables tests that file operations run on the file
1257 // thread. 1257 // thread.
1258 base::ThreadRestrictions::ScopedAllowIO allow_io; 1258 base::ThreadRestrictions::ScopedAllowIO allow_io;
1259 1259
1260 int flags = Extension::NO_FLAGS;
1261 if (Extension::ShouldDoStrictErrorChecking(info->extension_location))
1262 flags |= Extension::STRICT_ERROR_CHECKS;
1263 if (extension_prefs_->AllowFileAccess(info->extension_id))
1264 flags |= Extension::ALLOW_FILE_ACCESS;
1265 if (extension_prefs_->IsFromWebStore(info->extension_id))
1266 flags |= Extension::FROM_WEBSTORE;
1267 if (extension_prefs_->IsFromBookmark(info->extension_id))
1268 flags |= Extension::FROM_BOOKMARK;
1269 std::string error; 1260 std::string error;
1270 scoped_refptr<const Extension> extension( 1261 scoped_refptr<const Extension> extension(
1271 extension_file_util::LoadExtension( 1262 extension_file_util::LoadExtension(
1272 info->extension_path, 1263 info->extension_path,
1273 info->extension_location, 1264 info->extension_location,
1274 flags, 1265 GetExtensionCreateFlagsForInstalledExtension(info),
1275 &error)); 1266 &error));
1276 1267
1277 if (extension.get()) { 1268 if (extension.get()) {
1278 extensions_info->at(i)->extension_manifest.reset( 1269 extensions_info->at(i)->extension_manifest.reset(
1279 static_cast<DictionaryValue*>( 1270 static_cast<DictionaryValue*>(
1280 extension->manifest_value()->DeepCopy())); 1271 extension->manifest_value()->DeepCopy()));
1281 should_write_prefs = true; 1272 should_write_prefs = true;
1282 } 1273 }
1283 } 1274 }
1284 } 1275 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 } 1412 }
1422 } 1413 }
1423 1414
1424 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, 1415 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info,
1425 bool write_to_prefs) { 1416 bool write_to_prefs) {
1426 std::string error; 1417 std::string error;
1427 scoped_refptr<const Extension> extension(NULL); 1418 scoped_refptr<const Extension> extension(NULL);
1428 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { 1419 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) {
1429 error = errors::kDisabledByPolicy; 1420 error = errors::kDisabledByPolicy;
1430 } else if (info.extension_manifest.get()) { 1421 } else if (info.extension_manifest.get()) {
1431 int flags = Extension::NO_FLAGS;
1432 if (info.extension_location != Extension::LOAD)
1433 flags |= Extension::REQUIRE_KEY;
1434 if (Extension::ShouldDoStrictErrorChecking(info.extension_location))
1435 flags |= Extension::STRICT_ERROR_CHECKS;
1436 if (extension_prefs_->AllowFileAccess(info.extension_id))
1437 flags |= Extension::ALLOW_FILE_ACCESS;
1438 if (extension_prefs_->IsFromWebStore(info.extension_id))
1439 flags |= Extension::FROM_WEBSTORE;
1440 if (extension_prefs_->IsFromBookmark(info.extension_id))
1441 flags |= Extension::FROM_BOOKMARK;
1442 extension = Extension::Create( 1422 extension = Extension::Create(
1443 info.extension_path, 1423 info.extension_path,
1444 info.extension_location, 1424 info.extension_location,
1445 *info.extension_manifest, 1425 *info.extension_manifest,
1446 flags, 1426 GetExtensionCreateFlagsForInstalledExtension(&info),
1447 &error); 1427 &error);
1448 } else { 1428 } else {
1449 error = errors::kManifestUnreadable; 1429 error = errors::kManifestUnreadable;
1450 } 1430 }
1451 1431
1452 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by 1432 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by
1453 // updating the 'key' field in their manifest). 1433 // updating the 'key' field in their manifest).
1454 if (extension && 1434 if (extension &&
1455 extension->location() != Extension::LOAD && 1435 extension->location() != Extension::LOAD &&
1456 info.extension_id != extension->id()) { 1436 info.extension_id != extension->id()) {
1457 error = errors::kCannotChangeExtensionID; 1437 error = errors::kCannotChangeExtensionID;
1458 extension = NULL; 1438 extension = NULL;
1459 UserMetrics::RecordAction(UserMetricsAction("Extensions.IDChangedError")); 1439 UserMetrics::RecordAction(UserMetricsAction("Extensions.IDChangedError"));
1460 } 1440 }
1461 1441
1462 if (!extension) { 1442 if (!extension) {
1463 ReportExtensionLoadError(info.extension_path, error, false); 1443 ReportExtensionLoadError(info.extension_path, error, false);
1464 return; 1444 return;
1465 } 1445 }
1466 1446
1467 if (write_to_prefs) 1447 if (write_to_prefs)
1468 extension_prefs_->UpdateManifest(extension); 1448 extension_prefs_->UpdateManifest(extension);
1469 1449
1470 AddExtension(extension); 1450 AddExtension(extension);
1471 } 1451 }
1472 1452
1453 int ExtensionService::GetExtensionCreateFlagsForInstalledExtension(
Mihai Parparita -not on Chrome 2011/10/16 22:41:46 Seems like this could be a static/in an unnamed na
1454 const ExtensionInfo* info) {
1455 int flags = Extension::NO_FLAGS;
1456 if (info->extension_location != Extension::LOAD)
Mihai Parparita -not on Chrome 2011/10/16 22:41:46 Body is indented one too many times.
1457 flags |= Extension::REQUIRE_KEY;
1458 if (Extension::ShouldDoStrictErrorChecking(info->extension_location))
1459 flags |= Extension::STRICT_ERROR_CHECKS;
1460 if (extension_prefs_->AllowFileAccess(info->extension_id))
1461 flags |= Extension::ALLOW_FILE_ACCESS;
1462 if (extension_prefs_->IsFromWebStore(info->extension_id))
1463 flags |= Extension::FROM_WEBSTORE;
1464 if (extension_prefs_->IsFromBookmark(info->extension_id))
1465 flags |= Extension::FROM_BOOKMARK;
1466 return flags;
1467 }
1468
1473 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { 1469 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
1474 // The ChromeURLRequestContexts need to be first to know that the extension 1470 // The ChromeURLRequestContexts need to be first to know that the extension
1475 // was loaded, otherwise a race can arise where a renderer that is created 1471 // was loaded, otherwise a race can arise where a renderer that is created
1476 // for the extension may try to load an extension URL with an extension id 1472 // for the extension may try to load an extension URL with an extension id
1477 // that the request context doesn't yet know about. The profile is responsible 1473 // that the request context doesn't yet know about. The profile is responsible
1478 // for ensuring its URLRequestContexts appropriately discover the loaded 1474 // for ensuring its URLRequestContexts appropriately discover the loaded
1479 // extension. 1475 // extension.
1480 profile_->RegisterExtensionWithRequestContexts(extension); 1476 profile_->RegisterExtensionWithRequestContexts(extension);
1481 1477
1482 // Tell subsystems that use the EXTENSION_LOADED notification about the new 1478 // Tell subsystems that use the EXTENSION_LOADED notification about the new
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 3004
3009 ExtensionService::NaClModuleInfoList::iterator 3005 ExtensionService::NaClModuleInfoList::iterator
3010 ExtensionService::FindNaClModule(const GURL& url) { 3006 ExtensionService::FindNaClModule(const GURL& url) {
3011 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); 3007 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
3012 iter != nacl_module_list_.end(); ++iter) { 3008 iter != nacl_module_list_.end(); ++iter) {
3013 if (iter->url == url) 3009 if (iter->url == url)
3014 return iter; 3010 return iter;
3015 } 3011 }
3016 return nacl_module_list_.end(); 3012 return nacl_module_list_.end();
3017 } 3013 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/common/extensions/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698