OLD | NEW |
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/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "chrome/browser/extensions/extension_global_error.h" | 45 #include "chrome/browser/extensions/extension_global_error.h" |
46 #include "chrome/browser/extensions/extension_host.h" | 46 #include "chrome/browser/extensions/extension_host.h" |
47 #include "chrome/browser/extensions/extension_input_ime_api.h" | 47 #include "chrome/browser/extensions/extension_input_ime_api.h" |
48 #include "chrome/browser/extensions/extension_management_api.h" | 48 #include "chrome/browser/extensions/extension_management_api.h" |
49 #include "chrome/browser/extensions/extension_preference_api.h" | 49 #include "chrome/browser/extensions/extension_preference_api.h" |
50 #include "chrome/browser/extensions/extension_process_manager.h" | 50 #include "chrome/browser/extensions/extension_process_manager.h" |
51 #include "chrome/browser/extensions/extension_processes_api.h" | 51 #include "chrome/browser/extensions/extension_processes_api.h" |
52 #include "chrome/browser/extensions/extension_sorting.h" | 52 #include "chrome/browser/extensions/extension_sorting.h" |
53 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 53 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
54 #include "chrome/browser/extensions/extension_sync_data.h" | 54 #include "chrome/browser/extensions/extension_sync_data.h" |
| 55 #include "chrome/browser/extensions/extension_system.h" |
| 56 #include "chrome/browser/extensions/extension_system_factory.h" |
55 #include "chrome/browser/extensions/extension_updater.h" | 57 #include "chrome/browser/extensions/extension_updater.h" |
56 #include "chrome/browser/extensions/extension_web_ui.h" | 58 #include "chrome/browser/extensions/extension_web_ui.h" |
57 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 59 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
58 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 60 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
59 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 61 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
60 #include "chrome/browser/extensions/installed_loader.h" | 62 #include "chrome/browser/extensions/installed_loader.h" |
61 #include "chrome/browser/extensions/pending_extension_manager.h" | 63 #include "chrome/browser/extensions/pending_extension_manager.h" |
62 #include "chrome/browser/extensions/permissions_updater.h" | 64 #include "chrome/browser/extensions/permissions_updater.h" |
63 #include "chrome/browser/extensions/settings/settings_frontend.h" | 65 #include "chrome/browser/extensions/settings/settings_frontend.h" |
64 #include "chrome/browser/extensions/unpacked_installer.h" | 66 #include "chrome/browser/extensions/unpacked_installer.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 return true; | 370 return true; |
369 } | 371 } |
370 | 372 |
371 ExtensionService::ExtensionService(Profile* profile, | 373 ExtensionService::ExtensionService(Profile* profile, |
372 const CommandLine* command_line, | 374 const CommandLine* command_line, |
373 const FilePath& install_directory, | 375 const FilePath& install_directory, |
374 ExtensionPrefs* extension_prefs, | 376 ExtensionPrefs* extension_prefs, |
375 bool autoupdate_enabled, | 377 bool autoupdate_enabled, |
376 bool extensions_enabled) | 378 bool extensions_enabled) |
377 : profile_(profile), | 379 : profile_(profile), |
| 380 system_(ExtensionSystemFactory::GetForProfile(profile)), |
378 extension_prefs_(extension_prefs), | 381 extension_prefs_(extension_prefs), |
379 settings_frontend_(extensions::SettingsFrontend::Create(profile)), | 382 settings_frontend_(extensions::SettingsFrontend::Create(profile)), |
380 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 383 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
381 install_directory_(install_directory), | 384 install_directory_(install_directory), |
382 extensions_enabled_(extensions_enabled), | 385 extensions_enabled_(extensions_enabled), |
383 show_extensions_prompts_(true), | 386 show_extensions_prompts_(true), |
384 ready_(false), | 387 ready_(false), |
385 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 388 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
386 menu_manager_(profile), | 389 menu_manager_(profile), |
387 app_notification_manager_(new AppNotificationManager(profile)), | 390 app_notification_manager_(new AppNotificationManager(profile)), |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 void ExtensionService::ReloadExtension(const std::string& extension_id) { | 688 void ExtensionService::ReloadExtension(const std::string& extension_id) { |
686 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 689 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
687 FilePath path; | 690 FilePath path; |
688 const Extension* current_extension = GetExtensionById(extension_id, false); | 691 const Extension* current_extension = GetExtensionById(extension_id, false); |
689 | 692 |
690 // Disable the extension if it's loaded. It might not be loaded if it crashed. | 693 // Disable the extension if it's loaded. It might not be loaded if it crashed. |
691 if (current_extension) { | 694 if (current_extension) { |
692 // If the extension has an inspector open for its background page, detach | 695 // If the extension has an inspector open for its background page, detach |
693 // the inspector and hang onto a cookie for it, so that we can reattach | 696 // the inspector and hang onto a cookie for it, so that we can reattach |
694 // later. | 697 // later. |
695 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); | 698 // TODO(yoz): this is not incognito-safe! |
| 699 ExtensionProcessManager* manager = system_->process_manager(); |
696 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); | 700 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); |
697 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( | 701 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( |
698 host->render_view_host())) { | 702 host->render_view_host())) { |
699 // Look for an open inspector for the background page. | 703 // Look for an open inspector for the background page. |
700 DevToolsAgentHost* agent = | 704 DevToolsAgentHost* agent = |
701 DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 705 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
702 host->render_view_host()); | 706 host->render_view_host()); |
703 int devtools_cookie = | 707 int devtools_cookie = |
704 content::DevToolsManager::GetInstance()->DetachClientHost(agent); | 708 content::DevToolsManager::GetInstance()->DetachClientHost(agent); |
705 if (devtools_cookie >= 0) | 709 if (devtools_cookie >= 0) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 } | 978 } |
975 } | 979 } |
976 | 980 |
977 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { | 981 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
978 // The ChromeURLRequestContexts need to be first to know that the extension | 982 // The ChromeURLRequestContexts need to be first to know that the extension |
979 // was loaded, otherwise a race can arise where a renderer that is created | 983 // was loaded, otherwise a race can arise where a renderer that is created |
980 // for the extension may try to load an extension URL with an extension id | 984 // for the extension may try to load an extension URL with an extension id |
981 // that the request context doesn't yet know about. The profile is responsible | 985 // that the request context doesn't yet know about. The profile is responsible |
982 // for ensuring its URLRequestContexts appropriately discover the loaded | 986 // for ensuring its URLRequestContexts appropriately discover the loaded |
983 // extension. | 987 // extension. |
984 profile_->RegisterExtensionWithRequestContexts(extension); | 988 system_->RegisterExtensionWithRequestContexts(extension); |
985 | 989 |
986 // Tell renderers about the new extension, unless it's a theme (renderers | 990 // Tell renderers about the new extension, unless it's a theme (renderers |
987 // don't need to know about themes). | 991 // don't need to know about themes). |
988 if (!extension->is_theme()) { | 992 if (!extension->is_theme()) { |
989 for (content::RenderProcessHost::iterator i( | 993 for (content::RenderProcessHost::iterator i( |
990 content::RenderProcessHost::AllHostsIterator()); | 994 content::RenderProcessHost::AllHostsIterator()); |
991 !i.IsAtEnd(); i.Advance()) { | 995 !i.IsAtEnd(); i.Advance()) { |
992 content::RenderProcessHost* host = i.GetCurrentValue(); | 996 content::RenderProcessHost* host = i.GetCurrentValue(); |
993 Profile* host_profile = | 997 Profile* host_profile = |
994 Profile::FromBrowserContext(host->GetBrowserContext()); | 998 Profile::FromBrowserContext(host->GetBrowserContext()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 for (content::RenderProcessHost::iterator i( | 1125 for (content::RenderProcessHost::iterator i( |
1122 content::RenderProcessHost::AllHostsIterator()); | 1126 content::RenderProcessHost::AllHostsIterator()); |
1123 !i.IsAtEnd(); i.Advance()) { | 1127 !i.IsAtEnd(); i.Advance()) { |
1124 content::RenderProcessHost* host = i.GetCurrentValue(); | 1128 content::RenderProcessHost* host = i.GetCurrentValue(); |
1125 Profile* host_profile = | 1129 Profile* host_profile = |
1126 Profile::FromBrowserContext(host->GetBrowserContext()); | 1130 Profile::FromBrowserContext(host->GetBrowserContext()); |
1127 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) | 1131 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |
1128 host->Send(new ExtensionMsg_Unloaded(extension->id())); | 1132 host->Send(new ExtensionMsg_Unloaded(extension->id())); |
1129 } | 1133 } |
1130 | 1134 |
1131 profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason); | 1135 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
1132 profile_->GetExtensionSpecialStoragePolicy()-> | 1136 profile_->GetExtensionSpecialStoragePolicy()-> |
1133 RevokeRightsForExtension(extension); | 1137 RevokeRightsForExtension(extension); |
1134 | 1138 |
1135 ExtensionWebUI::UnregisterChromeURLOverrides( | 1139 ExtensionWebUI::UnregisterChromeURLOverrides( |
1136 profile_, extension->GetChromeURLOverrides()); | 1140 profile_, extension->GetChromeURLOverrides()); |
1137 | 1141 |
1138 #if defined(OS_CHROMEOS) | 1142 #if defined(OS_CHROMEOS) |
1139 // Revoke external file access to | 1143 // Revoke external file access to |
1140 if (BrowserContext::GetFileSystemContext(profile_) && | 1144 if (BrowserContext::GetFileSystemContext(profile_) && |
1141 BrowserContext::GetFileSystemContext(profile_)->external_provider()) { | 1145 BrowserContext::GetFileSystemContext(profile_)->external_provider()) { |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 extension_misc::UnloadedExtensionReason reason) { | 1919 extension_misc::UnloadedExtensionReason reason) { |
1916 // Make sure the extension gets deleted after we return from this function. | 1920 // Make sure the extension gets deleted after we return from this function. |
1917 scoped_refptr<const Extension> extension( | 1921 scoped_refptr<const Extension> extension( |
1918 GetExtensionByIdInternal(extension_id, true, true, false)); | 1922 GetExtensionByIdInternal(extension_id, true, true, false)); |
1919 | 1923 |
1920 // This method can be called via PostTask, so the extension may have been | 1924 // This method can be called via PostTask, so the extension may have been |
1921 // unloaded by the time this runs. | 1925 // unloaded by the time this runs. |
1922 if (!extension) { | 1926 if (!extension) { |
1923 // In case the extension may have crashed/uninstalled. Allow the profile to | 1927 // In case the extension may have crashed/uninstalled. Allow the profile to |
1924 // clean up its RequestContexts. | 1928 // clean up its RequestContexts. |
1925 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1929 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
1926 return; | 1930 return; |
1927 } | 1931 } |
1928 | 1932 |
1929 // Keep information about the extension so that we can reload it later | 1933 // Keep information about the extension so that we can reload it later |
1930 // even if it's not permanently installed. | 1934 // even if it's not permanently installed. |
1931 unloaded_extension_paths_[extension->id()] = extension->path(); | 1935 unloaded_extension_paths_[extension->id()] = extension->path(); |
1932 | 1936 |
1933 // Clean up if the extension is meant to be enabled after a reload. | 1937 // Clean up if the extension is meant to be enabled after a reload. |
1934 disabled_extension_paths_.erase(extension->id()); | 1938 disabled_extension_paths_.erase(extension->id()); |
1935 | 1939 |
1936 // Clean up runtime data. | 1940 // Clean up runtime data. |
1937 extension_runtime_data_.erase(extension_id); | 1941 extension_runtime_data_.erase(extension_id); |
1938 | 1942 |
1939 if (disabled_extensions_.Contains(extension->id())) { | 1943 if (disabled_extensions_.Contains(extension->id())) { |
1940 UnloadedExtensionInfo details(extension, reason); | 1944 UnloadedExtensionInfo details(extension, reason); |
1941 details.already_disabled = true; | 1945 details.already_disabled = true; |
1942 disabled_extensions_.Remove(extension->id()); | 1946 disabled_extensions_.Remove(extension->id()); |
1943 content::NotificationService::current()->Notify( | 1947 content::NotificationService::current()->Notify( |
1944 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 1948 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
1945 content::Source<Profile>(profile_), | 1949 content::Source<Profile>(profile_), |
1946 content::Details<UnloadedExtensionInfo>(&details)); | 1950 content::Details<UnloadedExtensionInfo>(&details)); |
1947 // Make sure the profile cleans up its RequestContexts when an already | 1951 // Make sure the profile cleans up its RequestContexts when an already |
1948 // disabled extension is unloaded (since they are also tracking the disabled | 1952 // disabled extension is unloaded (since they are also tracking the disabled |
1949 // extensions). | 1953 // extensions). |
1950 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1954 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
1951 return; | 1955 return; |
1952 } | 1956 } |
1953 | 1957 |
1954 // Remove the extension from our list. | 1958 // Remove the extension from our list. |
1955 extensions_.Remove(extension->id()); | 1959 extensions_.Remove(extension->id()); |
1956 | 1960 |
1957 NotifyExtensionUnloaded(extension.get(), reason); | 1961 NotifyExtensionUnloaded(extension.get(), reason); |
1958 } | 1962 } |
1959 | 1963 |
1960 void ExtensionService::UnloadAllExtensions() { | 1964 void ExtensionService::UnloadAllExtensions() { |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2487 Profile::FromBrowserContext(process->GetBrowserContext()); | 2491 Profile::FromBrowserContext(process->GetBrowserContext()); |
2488 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) | 2492 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
2489 break; | 2493 break; |
2490 | 2494 |
2491 installed_app_hosts_.erase(process->GetID()); | 2495 installed_app_hosts_.erase(process->GetID()); |
2492 | 2496 |
2493 process_map_.RemoveAllFromProcess(process->GetID()); | 2497 process_map_.RemoveAllFromProcess(process->GetID()); |
2494 BrowserThread::PostTask( | 2498 BrowserThread::PostTask( |
2495 BrowserThread::IO, FROM_HERE, | 2499 BrowserThread::IO, FROM_HERE, |
2496 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, | 2500 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, |
2497 profile_->GetExtensionInfoMap(), | 2501 system_->info_map(), |
2498 process->GetID())); | 2502 process->GetID())); |
2499 break; | 2503 break; |
2500 } | 2504 } |
2501 case chrome::NOTIFICATION_PREF_CHANGED: { | 2505 case chrome::NOTIFICATION_PREF_CHANGED: { |
2502 std::string* pref_name = content::Details<std::string>(details).ptr(); | 2506 std::string* pref_name = content::Details<std::string>(details).ptr(); |
2503 if (*pref_name == prefs::kExtensionInstallAllowList || | 2507 if (*pref_name == prefs::kExtensionInstallAllowList || |
2504 *pref_name == prefs::kExtensionInstallDenyList) { | 2508 *pref_name == prefs::kExtensionInstallDenyList) { |
2505 CheckAdminBlacklist(); | 2509 CheckAdminBlacklist(); |
2506 } else { | 2510 } else { |
2507 NOTREACHED() << "Unexpected preference name."; | 2511 NOTREACHED() << "Unexpected preference name."; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2660 return api_resource_controller_; | 2664 return api_resource_controller_; |
2661 } | 2665 } |
2662 | 2666 |
2663 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() { | 2667 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() { |
2664 if (!rules_registry_service_.get()) { | 2668 if (!rules_registry_service_.get()) { |
2665 rules_registry_service_.reset( | 2669 rules_registry_service_.reset( |
2666 new extensions::RulesRegistryService(profile_)); | 2670 new extensions::RulesRegistryService(profile_)); |
2667 } | 2671 } |
2668 return rules_registry_service_.get(); | 2672 return rules_registry_service_.get(); |
2669 } | 2673 } |
OLD | NEW |