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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 454 } |
454 } | 455 } |
455 | 456 |
456 void ExtensionService::Shutdown() { | 457 void ExtensionService::Shutdown() { |
457 system_->management_policy()->UnregisterProvider( | 458 system_->management_policy()->UnregisterProvider( |
458 shared_module_policy_provider_.get()); | 459 shared_module_policy_provider_.get()); |
459 } | 460 } |
460 | 461 |
461 const Extension* ExtensionService::GetExtensionById( | 462 const Extension* ExtensionService::GetExtensionById( |
462 const std::string& id, bool include_disabled) const { | 463 const std::string& id, bool include_disabled) const { |
463 int include_mask = INCLUDE_ENABLED; | 464 int include_mask = ExtensionRegistry::INCLUDE_ENABLED; |
464 if (include_disabled) { | 465 if (include_disabled) { |
465 // Include blacklisted extensions here because there are hundreds of | 466 // Include blacklisted extensions here because there are hundreds of |
466 // callers of this function, and many might assume that this includes those | 467 // callers of this function, and many might assume that this includes those |
467 // that have been disabled due to blacklisting. | 468 // that have been disabled due to blacklisting. |
468 include_mask |= INCLUDE_DISABLED | INCLUDE_BLACKLISTED; | 469 include_mask |= ExtensionRegistry::INCLUDE_DISABLED | |
| 470 ExtensionRegistry::INCLUDE_BLACKLISTED; |
469 } | 471 } |
470 return GetExtensionById(id, include_mask); | 472 return registry_->GetExtensionById(id, include_mask); |
471 } | 473 } |
472 | 474 |
473 GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) { | 475 GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) { |
474 return content::SiteInstance::GetSiteForURL( | 476 return content::SiteInstance::GetSiteForURL( |
475 profile_, | 477 profile_, |
476 Extension::GetBaseURLFromExtensionId(extension_id)); | 478 Extension::GetBaseURLFromExtensionId(extension_id)); |
477 } | 479 } |
478 | 480 |
479 const Extension* ExtensionService::GetExtensionById( | |
480 const std::string& id, int include_mask) const { | |
481 std::string lowercase_id = StringToLowerASCII(id); | |
482 if (include_mask & INCLUDE_ENABLED) { | |
483 const Extension* extension = | |
484 registry_->enabled_extensions().GetByID(lowercase_id); | |
485 if (extension) | |
486 return extension; | |
487 } | |
488 if (include_mask & INCLUDE_DISABLED) { | |
489 const Extension* extension = | |
490 registry_->disabled_extensions().GetByID(lowercase_id); | |
491 if (extension) | |
492 return extension; | |
493 } | |
494 if (include_mask & INCLUDE_TERMINATED) { | |
495 const Extension* extension = | |
496 registry_->terminated_extensions().GetByID(lowercase_id); | |
497 if (extension) | |
498 return extension; | |
499 } | |
500 if (include_mask & INCLUDE_BLACKLISTED) { | |
501 const Extension* extension = | |
502 registry_->blacklisted_extensions().GetByID(lowercase_id); | |
503 if (extension) | |
504 return extension; | |
505 } | |
506 return NULL; | |
507 } | |
508 | |
509 void ExtensionService::Init() { | 481 void ExtensionService::Init() { |
510 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 482 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
511 | 483 |
512 base::Time begin_time = base::Time::Now(); | 484 base::Time begin_time = base::Time::Now(); |
513 | 485 |
514 DCHECK(!is_ready()); // Can't redo init. | 486 DCHECK(!is_ready()); // Can't redo init. |
515 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); | 487 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); |
516 | 488 |
517 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 489 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
518 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || | 490 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 // installed yet. | 986 // installed yet. |
1015 if (extension && | 987 if (extension && |
1016 disable_reason != Extension::DISABLE_RELOAD && | 988 disable_reason != Extension::DISABLE_RELOAD && |
1017 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { | 989 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { |
1018 return; | 990 return; |
1019 } | 991 } |
1020 | 992 |
1021 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 993 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
1022 extension_prefs_->AddDisableReason(extension_id, disable_reason); | 994 extension_prefs_->AddDisableReason(extension_id, disable_reason); |
1023 | 995 |
1024 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_DISABLED; | 996 int include_mask = ExtensionRegistry::INCLUDE_EVERYTHING & |
1025 extension = GetExtensionById(extension_id, include_mask); | 997 ~ExtensionRegistry::INCLUDE_DISABLED; |
| 998 extension = registry_->GetExtensionById(extension_id, include_mask); |
1026 if (!extension) | 999 if (!extension) |
1027 return; | 1000 return; |
1028 | 1001 |
1029 // Reset the background_page_ready flag | 1002 // Reset the background_page_ready flag |
1030 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) | 1003 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) |
1031 extension_runtime_data_[extension->id()].background_page_ready = false; | 1004 extension_runtime_data_[extension->id()].background_page_ready = false; |
1032 | 1005 |
1033 // Move it over to the disabled list. Don't send a second unload notification | 1006 // Move it over to the disabled list. Don't send a second unload notification |
1034 // for terminated extensions being disabled. | 1007 // for terminated extensions being disabled. |
1035 registry_->AddDisabled(make_scoped_refptr(extension)); | 1008 registry_->AddDisabled(make_scoped_refptr(extension)); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 } | 1199 } |
1227 #endif | 1200 #endif |
1228 | 1201 |
1229 UpdateActiveExtensionsInCrashReporter(); | 1202 UpdateActiveExtensionsInCrashReporter(); |
1230 } | 1203 } |
1231 | 1204 |
1232 Profile* ExtensionService::profile() { | 1205 Profile* ExtensionService::profile() { |
1233 return profile_; | 1206 return profile_; |
1234 } | 1207 } |
1235 | 1208 |
| 1209 content::BrowserContext* ExtensionService::GetBrowserContext() const { |
| 1210 // Implemented in the .cc file to avoid adding a profile.h dependency to |
| 1211 // extension_service.h. |
| 1212 return profile_; |
| 1213 } |
| 1214 |
1236 extensions::ExtensionPrefs* ExtensionService::extension_prefs() { | 1215 extensions::ExtensionPrefs* ExtensionService::extension_prefs() { |
1237 return extension_prefs_; | 1216 return extension_prefs_; |
1238 } | 1217 } |
1239 | 1218 |
1240 const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const { | 1219 const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const { |
1241 return extension_prefs_; | 1220 return extension_prefs_; |
1242 } | 1221 } |
1243 | 1222 |
1244 extensions::SettingsFrontend* ExtensionService::settings_frontend() { | 1223 extensions::SettingsFrontend* ExtensionService::settings_frontend() { |
1245 return settings_frontend_.get(); | 1224 return settings_frontend_.get(); |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 } | 1582 } |
1604 } else { | 1583 } else { |
1605 extensions::RemoveExternalInstallError(this); | 1584 extensions::RemoveExternalInstallError(this); |
1606 } | 1585 } |
1607 } | 1586 } |
1608 | 1587 |
1609 void ExtensionService::UnloadExtension( | 1588 void ExtensionService::UnloadExtension( |
1610 const std::string& extension_id, | 1589 const std::string& extension_id, |
1611 UnloadedExtensionInfo::Reason reason) { | 1590 UnloadedExtensionInfo::Reason reason) { |
1612 // Make sure the extension gets deleted after we return from this function. | 1591 // Make sure the extension gets deleted after we return from this function. |
1613 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_TERMINATED; | 1592 int include_mask = ExtensionRegistry::INCLUDE_EVERYTHING & |
| 1593 ~ExtensionRegistry::INCLUDE_TERMINATED; |
1614 scoped_refptr<const Extension> extension( | 1594 scoped_refptr<const Extension> extension( |
1615 GetExtensionById(extension_id, include_mask)); | 1595 registry_->GetExtensionById(extension_id, include_mask)); |
1616 | 1596 |
1617 // This method can be called via PostTask, so the extension may have been | 1597 // This method can be called via PostTask, so the extension may have been |
1618 // unloaded by the time this runs. | 1598 // unloaded by the time this runs. |
1619 if (!extension.get()) { | 1599 if (!extension.get()) { |
1620 // In case the extension may have crashed/uninstalled. Allow the profile to | 1600 // In case the extension may have crashed/uninstalled. Allow the profile to |
1621 // clean up its RequestContexts. | 1601 // clean up its RequestContexts. |
1622 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1602 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
1623 return; | 1603 return; |
1624 } | 1604 } |
1625 | 1605 |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2360 if (extension) { | 2340 if (extension) { |
2361 content::NotificationService::current()->Notify( | 2341 content::NotificationService::current()->Notify( |
2362 chrome::NOTIFICATION_EXTENSION_REMOVED, | 2342 chrome::NOTIFICATION_EXTENSION_REMOVED, |
2363 content::Source<Profile>(profile_), | 2343 content::Source<Profile>(profile_), |
2364 content::Details<const Extension>(extension)); | 2344 content::Details<const Extension>(extension)); |
2365 } | 2345 } |
2366 } | 2346 } |
2367 | 2347 |
2368 const Extension* ExtensionService::GetTerminatedExtension( | 2348 const Extension* ExtensionService::GetTerminatedExtension( |
2369 const std::string& id) const { | 2349 const std::string& id) const { |
2370 return GetExtensionById(id, INCLUDE_TERMINATED); | 2350 return registry_->GetExtensionById(id, ExtensionRegistry::INCLUDE_TERMINATED); |
2371 } | 2351 } |
2372 | 2352 |
2373 const Extension* ExtensionService::GetInstalledExtension( | 2353 const Extension* ExtensionService::GetInstalledExtension( |
2374 const std::string& id) const { | 2354 const std::string& id) const { |
2375 int include_mask = INCLUDE_ENABLED | | 2355 return registry_->GetExtensionById(id, ExtensionRegistry::INCLUDE_EVERYTHING); |
2376 INCLUDE_DISABLED | | |
2377 INCLUDE_TERMINATED | | |
2378 INCLUDE_BLACKLISTED; | |
2379 return GetExtensionById(id, include_mask); | |
2380 } | 2356 } |
2381 | 2357 |
2382 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { | 2358 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
2383 // Allow bindings for all packaged extensions and component hosted apps. | 2359 // Allow bindings for all packaged extensions and component hosted apps. |
2384 const Extension* extension = | 2360 const Extension* extension = |
2385 registry_->enabled_extensions().GetExtensionOrAppByURL(url); | 2361 registry_->enabled_extensions().GetExtensionOrAppByURL(url); |
2386 return extension && (!extension->is_hosted_app() || | 2362 return extension && (!extension->is_hosted_app() || |
2387 extension->location() == Manifest::COMPONENT); | 2363 extension->location() == Manifest::COMPONENT); |
2388 } | 2364 } |
2389 | 2365 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2866 void ExtensionService::UnloadAllExtensionsInternal() { | 2842 void ExtensionService::UnloadAllExtensionsInternal() { |
2867 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2843 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
2868 | 2844 |
2869 registry_->ClearAll(); | 2845 registry_->ClearAll(); |
2870 extension_runtime_data_.clear(); | 2846 extension_runtime_data_.clear(); |
2871 | 2847 |
2872 // TODO(erikkay) should there be a notification for this? We can't use | 2848 // TODO(erikkay) should there be a notification for this? We can't use |
2873 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2849 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
2874 // or uninstalled. | 2850 // or uninstalled. |
2875 } | 2851 } |
OLD | NEW |