OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 #include "webkit/browser/fileapi/file_system_context.h" | 108 #include "webkit/browser/fileapi/file_system_context.h" |
109 #endif | 109 #endif |
110 | 110 |
111 using content::BrowserContext; | 111 using content::BrowserContext; |
112 using content::BrowserThread; | 112 using content::BrowserThread; |
113 using content::DevToolsAgentHost; | 113 using content::DevToolsAgentHost; |
114 using extensions::CrxInstaller; | 114 using extensions::CrxInstaller; |
115 using extensions::Extension; | 115 using extensions::Extension; |
116 using extensions::ExtensionIdSet; | 116 using extensions::ExtensionIdSet; |
117 using extensions::ExtensionInfo; | 117 using extensions::ExtensionInfo; |
| 118 using extensions::ExtensionRegistry; |
118 using extensions::ExtensionSet; | 119 using extensions::ExtensionSet; |
119 using extensions::FeatureSwitch; | 120 using extensions::FeatureSwitch; |
120 using extensions::InstallVerifier; | 121 using extensions::InstallVerifier; |
121 using extensions::ManagementPolicy; | 122 using extensions::ManagementPolicy; |
122 using extensions::Manifest; | 123 using extensions::Manifest; |
123 using extensions::PermissionMessage; | 124 using extensions::PermissionMessage; |
124 using extensions::PermissionMessages; | 125 using extensions::PermissionMessages; |
125 using extensions::PermissionSet; | 126 using extensions::PermissionSet; |
126 using extensions::SharedModuleInfo; | 127 using extensions::SharedModuleInfo; |
127 using extensions::UnloadedExtensionInfo; | 128 using extensions::UnloadedExtensionInfo; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 450 } |
450 } | 451 } |
451 | 452 |
452 void ExtensionService::Shutdown() { | 453 void ExtensionService::Shutdown() { |
453 system_->management_policy()->UnregisterProvider( | 454 system_->management_policy()->UnregisterProvider( |
454 shared_module_policy_provider_.get()); | 455 shared_module_policy_provider_.get()); |
455 } | 456 } |
456 | 457 |
457 const Extension* ExtensionService::GetExtensionById( | 458 const Extension* ExtensionService::GetExtensionById( |
458 const std::string& id, bool include_disabled) const { | 459 const std::string& id, bool include_disabled) const { |
459 int include_mask = INCLUDE_ENABLED; | 460 int include_mask = ExtensionRegistry::ENABLED; |
460 if (include_disabled) { | 461 if (include_disabled) { |
461 // Include blacklisted extensions here because there are hundreds of | 462 // Include blacklisted extensions here because there are hundreds of |
462 // callers of this function, and many might assume that this includes those | 463 // callers of this function, and many might assume that this includes those |
463 // that have been disabled due to blacklisting. | 464 // that have been disabled due to blacklisting. |
464 include_mask |= INCLUDE_DISABLED | INCLUDE_BLACKLISTED; | 465 include_mask |= ExtensionRegistry::DISABLED | |
| 466 ExtensionRegistry::BLACKLISTED; |
465 } | 467 } |
466 return GetExtensionById(id, include_mask); | 468 return registry_->GetExtensionById(id, include_mask); |
467 } | 469 } |
468 | 470 |
469 GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) { | 471 GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) { |
470 return content::SiteInstance::GetSiteForURL( | 472 return content::SiteInstance::GetSiteForURL( |
471 profile_, | 473 profile_, |
472 Extension::GetBaseURLFromExtensionId(extension_id)); | 474 Extension::GetBaseURLFromExtensionId(extension_id)); |
473 } | 475 } |
474 | 476 |
475 const Extension* ExtensionService::GetExtensionById( | |
476 const std::string& id, int include_mask) const { | |
477 std::string lowercase_id = StringToLowerASCII(id); | |
478 if (include_mask & INCLUDE_ENABLED) { | |
479 const Extension* extension = | |
480 registry_->enabled_extensions().GetByID(lowercase_id); | |
481 if (extension) | |
482 return extension; | |
483 } | |
484 if (include_mask & INCLUDE_DISABLED) { | |
485 const Extension* extension = | |
486 registry_->disabled_extensions().GetByID(lowercase_id); | |
487 if (extension) | |
488 return extension; | |
489 } | |
490 if (include_mask & INCLUDE_TERMINATED) { | |
491 const Extension* extension = | |
492 registry_->terminated_extensions().GetByID(lowercase_id); | |
493 if (extension) | |
494 return extension; | |
495 } | |
496 if (include_mask & INCLUDE_BLACKLISTED) { | |
497 const Extension* extension = | |
498 registry_->blacklisted_extensions().GetByID(lowercase_id); | |
499 if (extension) | |
500 return extension; | |
501 } | |
502 return NULL; | |
503 } | |
504 | |
505 void ExtensionService::Init() { | 477 void ExtensionService::Init() { |
506 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 478 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
507 | 479 |
508 base::Time begin_time = base::Time::Now(); | 480 base::Time begin_time = base::Time::Now(); |
509 | 481 |
510 DCHECK(!is_ready()); // Can't redo init. | 482 DCHECK(!is_ready()); // Can't redo init. |
511 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); | 483 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); |
512 | 484 |
513 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 485 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
514 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || | 486 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 // installed yet. | 982 // installed yet. |
1011 if (extension && | 983 if (extension && |
1012 disable_reason != Extension::DISABLE_RELOAD && | 984 disable_reason != Extension::DISABLE_RELOAD && |
1013 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { | 985 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { |
1014 return; | 986 return; |
1015 } | 987 } |
1016 | 988 |
1017 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 989 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
1018 extension_prefs_->AddDisableReason(extension_id, disable_reason); | 990 extension_prefs_->AddDisableReason(extension_id, disable_reason); |
1019 | 991 |
1020 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_DISABLED; | 992 int include_mask = |
1021 extension = GetExtensionById(extension_id, include_mask); | 993 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; |
| 994 extension = registry_->GetExtensionById(extension_id, include_mask); |
1022 if (!extension) | 995 if (!extension) |
1023 return; | 996 return; |
1024 | 997 |
1025 // Reset the background_page_ready flag | 998 // Reset the background_page_ready flag |
1026 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) | 999 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) |
1027 extension_runtime_data_[extension->id()].background_page_ready = false; | 1000 extension_runtime_data_[extension->id()].background_page_ready = false; |
1028 | 1001 |
1029 // Move it over to the disabled list. Don't send a second unload notification | 1002 // Move it over to the disabled list. Don't send a second unload notification |
1030 // for terminated extensions being disabled. | 1003 // for terminated extensions being disabled. |
1031 registry_->AddDisabled(make_scoped_refptr(extension)); | 1004 registry_->AddDisabled(make_scoped_refptr(extension)); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 } | 1195 } |
1223 #endif | 1196 #endif |
1224 | 1197 |
1225 UpdateActiveExtensionsInCrashReporter(); | 1198 UpdateActiveExtensionsInCrashReporter(); |
1226 } | 1199 } |
1227 | 1200 |
1228 Profile* ExtensionService::profile() { | 1201 Profile* ExtensionService::profile() { |
1229 return profile_; | 1202 return profile_; |
1230 } | 1203 } |
1231 | 1204 |
| 1205 content::BrowserContext* ExtensionService::GetBrowserContext() const { |
| 1206 // Implemented in the .cc file to avoid adding a profile.h dependency to |
| 1207 // extension_service.h. |
| 1208 return profile_; |
| 1209 } |
| 1210 |
1232 extensions::ExtensionPrefs* ExtensionService::extension_prefs() { | 1211 extensions::ExtensionPrefs* ExtensionService::extension_prefs() { |
1233 return extension_prefs_; | 1212 return extension_prefs_; |
1234 } | 1213 } |
1235 | 1214 |
1236 const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const { | 1215 const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const { |
1237 return extension_prefs_; | 1216 return extension_prefs_; |
1238 } | 1217 } |
1239 | 1218 |
1240 extensions::SettingsFrontend* ExtensionService::settings_frontend() { | 1219 extensions::SettingsFrontend* ExtensionService::settings_frontend() { |
1241 return settings_frontend_.get(); | 1220 return settings_frontend_.get(); |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 } | 1578 } |
1600 } else { | 1579 } else { |
1601 extensions::RemoveExternalInstallError(this); | 1580 extensions::RemoveExternalInstallError(this); |
1602 } | 1581 } |
1603 } | 1582 } |
1604 | 1583 |
1605 void ExtensionService::UnloadExtension( | 1584 void ExtensionService::UnloadExtension( |
1606 const std::string& extension_id, | 1585 const std::string& extension_id, |
1607 UnloadedExtensionInfo::Reason reason) { | 1586 UnloadedExtensionInfo::Reason reason) { |
1608 // Make sure the extension gets deleted after we return from this function. | 1587 // Make sure the extension gets deleted after we return from this function. |
1609 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_TERMINATED; | 1588 int include_mask = |
| 1589 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED; |
1610 scoped_refptr<const Extension> extension( | 1590 scoped_refptr<const Extension> extension( |
1611 GetExtensionById(extension_id, include_mask)); | 1591 registry_->GetExtensionById(extension_id, include_mask)); |
1612 | 1592 |
1613 // This method can be called via PostTask, so the extension may have been | 1593 // This method can be called via PostTask, so the extension may have been |
1614 // unloaded by the time this runs. | 1594 // unloaded by the time this runs. |
1615 if (!extension.get()) { | 1595 if (!extension.get()) { |
1616 // In case the extension may have crashed/uninstalled. Allow the profile to | 1596 // In case the extension may have crashed/uninstalled. Allow the profile to |
1617 // clean up its RequestContexts. | 1597 // clean up its RequestContexts. |
1618 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1598 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
1619 return; | 1599 return; |
1620 } | 1600 } |
1621 | 1601 |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 if (extension) { | 2336 if (extension) { |
2357 content::NotificationService::current()->Notify( | 2337 content::NotificationService::current()->Notify( |
2358 chrome::NOTIFICATION_EXTENSION_REMOVED, | 2338 chrome::NOTIFICATION_EXTENSION_REMOVED, |
2359 content::Source<Profile>(profile_), | 2339 content::Source<Profile>(profile_), |
2360 content::Details<const Extension>(extension)); | 2340 content::Details<const Extension>(extension)); |
2361 } | 2341 } |
2362 } | 2342 } |
2363 | 2343 |
2364 const Extension* ExtensionService::GetTerminatedExtension( | 2344 const Extension* ExtensionService::GetTerminatedExtension( |
2365 const std::string& id) const { | 2345 const std::string& id) const { |
2366 return GetExtensionById(id, INCLUDE_TERMINATED); | 2346 return registry_->GetExtensionById(id, ExtensionRegistry::TERMINATED); |
2367 } | 2347 } |
2368 | 2348 |
2369 const Extension* ExtensionService::GetInstalledExtension( | 2349 const Extension* ExtensionService::GetInstalledExtension( |
2370 const std::string& id) const { | 2350 const std::string& id) const { |
2371 int include_mask = INCLUDE_ENABLED | | 2351 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
2372 INCLUDE_DISABLED | | |
2373 INCLUDE_TERMINATED | | |
2374 INCLUDE_BLACKLISTED; | |
2375 return GetExtensionById(id, include_mask); | |
2376 } | 2352 } |
2377 | 2353 |
2378 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { | 2354 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
2379 // Allow bindings for all packaged extensions and component hosted apps. | 2355 // Allow bindings for all packaged extensions and component hosted apps. |
2380 const Extension* extension = | 2356 const Extension* extension = |
2381 registry_->enabled_extensions().GetExtensionOrAppByURL(url); | 2357 registry_->enabled_extensions().GetExtensionOrAppByURL(url); |
2382 return extension && (!extension->is_hosted_app() || | 2358 return extension && (!extension->is_hosted_app() || |
2383 extension->location() == Manifest::COMPONENT); | 2359 extension->location() == Manifest::COMPONENT); |
2384 } | 2360 } |
2385 | 2361 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2862 void ExtensionService::UnloadAllExtensionsInternal() { | 2838 void ExtensionService::UnloadAllExtensionsInternal() { |
2863 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2839 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
2864 | 2840 |
2865 registry_->ClearAll(); | 2841 registry_->ClearAll(); |
2866 extension_runtime_data_.clear(); | 2842 extension_runtime_data_.clear(); |
2867 | 2843 |
2868 // TODO(erikkay) should there be a notification for this? We can't use | 2844 // TODO(erikkay) should there be a notification for this? We can't use |
2869 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2845 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
2870 // or uninstalled. | 2846 // or uninstalled. |
2871 } | 2847 } |
OLD | NEW |