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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "chrome/browser/extensions/extension_global_error.h" | 44 #include "chrome/browser/extensions/extension_global_error.h" |
45 #include "chrome/browser/extensions/extension_host.h" | 45 #include "chrome/browser/extensions/extension_host.h" |
46 #include "chrome/browser/extensions/extension_input_ime_api.h" | 46 #include "chrome/browser/extensions/extension_input_ime_api.h" |
47 #include "chrome/browser/extensions/extension_management_api.h" | 47 #include "chrome/browser/extensions/extension_management_api.h" |
48 #include "chrome/browser/extensions/extension_preference_api.h" | 48 #include "chrome/browser/extensions/extension_preference_api.h" |
49 #include "chrome/browser/extensions/extension_process_manager.h" | 49 #include "chrome/browser/extensions/extension_process_manager.h" |
50 #include "chrome/browser/extensions/extension_processes_api.h" | 50 #include "chrome/browser/extensions/extension_processes_api.h" |
51 #include "chrome/browser/extensions/extension_sorting.h" | 51 #include "chrome/browser/extensions/extension_sorting.h" |
52 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 52 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
53 #include "chrome/browser/extensions/extension_sync_data.h" | 53 #include "chrome/browser/extensions/extension_sync_data.h" |
| 54 #include "chrome/browser/extensions/extension_system.h" |
| 55 #include "chrome/browser/extensions/extension_system_factory.h" |
54 #include "chrome/browser/extensions/extension_updater.h" | 56 #include "chrome/browser/extensions/extension_updater.h" |
55 #include "chrome/browser/extensions/extension_web_ui.h" | 57 #include "chrome/browser/extensions/extension_web_ui.h" |
56 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 58 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
57 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 59 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
58 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 60 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
59 #include "chrome/browser/extensions/installed_loader.h" | 61 #include "chrome/browser/extensions/installed_loader.h" |
60 #include "chrome/browser/extensions/pending_extension_manager.h" | 62 #include "chrome/browser/extensions/pending_extension_manager.h" |
61 #include "chrome/browser/extensions/permissions_updater.h" | 63 #include "chrome/browser/extensions/permissions_updater.h" |
62 #include "chrome/browser/extensions/settings/settings_frontend.h" | 64 #include "chrome/browser/extensions/settings/settings_frontend.h" |
63 #include "chrome/browser/extensions/unpacked_installer.h" | 65 #include "chrome/browser/extensions/unpacked_installer.h" |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 return true; | 371 return true; |
370 } | 372 } |
371 | 373 |
372 ExtensionService::ExtensionService(Profile* profile, | 374 ExtensionService::ExtensionService(Profile* profile, |
373 const CommandLine* command_line, | 375 const CommandLine* command_line, |
374 const FilePath& install_directory, | 376 const FilePath& install_directory, |
375 ExtensionPrefs* extension_prefs, | 377 ExtensionPrefs* extension_prefs, |
376 bool autoupdate_enabled, | 378 bool autoupdate_enabled, |
377 bool extensions_enabled) | 379 bool extensions_enabled) |
378 : profile_(profile), | 380 : profile_(profile), |
| 381 system_(ExtensionSystemFactory::GetForProfile(profile)), |
379 extension_prefs_(extension_prefs), | 382 extension_prefs_(extension_prefs), |
380 settings_frontend_(extensions::SettingsFrontend::Create(profile)), | 383 settings_frontend_(extensions::SettingsFrontend::Create(profile)), |
381 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 384 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
382 install_directory_(install_directory), | 385 install_directory_(install_directory), |
383 extensions_enabled_(extensions_enabled), | 386 extensions_enabled_(extensions_enabled), |
384 show_extensions_prompts_(true), | 387 show_extensions_prompts_(true), |
385 ready_(false), | 388 ready_(false), |
386 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 389 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
387 menu_manager_(profile), | 390 menu_manager_(profile), |
388 app_notification_manager_(new AppNotificationManager(profile)), | 391 app_notification_manager_(new AppNotificationManager(profile)), |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 void ExtensionService::ReloadExtension(const std::string& extension_id) { | 691 void ExtensionService::ReloadExtension(const std::string& extension_id) { |
689 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 692 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
690 FilePath path; | 693 FilePath path; |
691 const Extension* current_extension = GetExtensionById(extension_id, false); | 694 const Extension* current_extension = GetExtensionById(extension_id, false); |
692 | 695 |
693 // Disable the extension if it's loaded. It might not be loaded if it crashed. | 696 // Disable the extension if it's loaded. It might not be loaded if it crashed. |
694 if (current_extension) { | 697 if (current_extension) { |
695 // If the extension has an inspector open for its background page, detach | 698 // If the extension has an inspector open for its background page, detach |
696 // the inspector and hang onto a cookie for it, so that we can reattach | 699 // the inspector and hang onto a cookie for it, so that we can reattach |
697 // later. | 700 // later. |
698 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); | 701 // TODO(yoz): this is not incognito-safe! |
| 702 ExtensionProcessManager* manager = system_->process_manager(); |
699 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); | 703 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); |
700 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( | 704 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( |
701 host->render_view_host())) { | 705 host->render_view_host())) { |
702 // Look for an open inspector for the background page. | 706 // Look for an open inspector for the background page. |
703 DevToolsAgentHost* agent = | 707 DevToolsAgentHost* agent = |
704 DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 708 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
705 host->render_view_host()); | 709 host->render_view_host()); |
706 int devtools_cookie = | 710 int devtools_cookie = |
707 content::DevToolsManager::GetInstance()->DetachClientHost(agent); | 711 content::DevToolsManager::GetInstance()->DetachClientHost(agent); |
708 if (devtools_cookie >= 0) | 712 if (devtools_cookie >= 0) |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 } | 974 } |
971 } | 975 } |
972 | 976 |
973 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { | 977 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
974 // The ChromeURLRequestContexts need to be first to know that the extension | 978 // The ChromeURLRequestContexts need to be first to know that the extension |
975 // was loaded, otherwise a race can arise where a renderer that is created | 979 // was loaded, otherwise a race can arise where a renderer that is created |
976 // for the extension may try to load an extension URL with an extension id | 980 // for the extension may try to load an extension URL with an extension id |
977 // that the request context doesn't yet know about. The profile is responsible | 981 // that the request context doesn't yet know about. The profile is responsible |
978 // for ensuring its URLRequestContexts appropriately discover the loaded | 982 // for ensuring its URLRequestContexts appropriately discover the loaded |
979 // extension. | 983 // extension. |
980 profile_->RegisterExtensionWithRequestContexts(extension); | 984 system_->RegisterExtensionWithRequestContexts(extension); |
981 | 985 |
982 // Tell renderers about the new extension, unless it's a theme (renderers | 986 // Tell renderers about the new extension, unless it's a theme (renderers |
983 // don't need to know about themes). | 987 // don't need to know about themes). |
984 if (!extension->is_theme()) { | 988 if (!extension->is_theme()) { |
985 for (content::RenderProcessHost::iterator i( | 989 for (content::RenderProcessHost::iterator i( |
986 content::RenderProcessHost::AllHostsIterator()); | 990 content::RenderProcessHost::AllHostsIterator()); |
987 !i.IsAtEnd(); i.Advance()) { | 991 !i.IsAtEnd(); i.Advance()) { |
988 content::RenderProcessHost* host = i.GetCurrentValue(); | 992 content::RenderProcessHost* host = i.GetCurrentValue(); |
989 Profile* host_profile = | 993 Profile* host_profile = |
990 Profile::FromBrowserContext(host->GetBrowserContext()); | 994 Profile::FromBrowserContext(host->GetBrowserContext()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 for (content::RenderProcessHost::iterator i( | 1121 for (content::RenderProcessHost::iterator i( |
1118 content::RenderProcessHost::AllHostsIterator()); | 1122 content::RenderProcessHost::AllHostsIterator()); |
1119 !i.IsAtEnd(); i.Advance()) { | 1123 !i.IsAtEnd(); i.Advance()) { |
1120 content::RenderProcessHost* host = i.GetCurrentValue(); | 1124 content::RenderProcessHost* host = i.GetCurrentValue(); |
1121 Profile* host_profile = | 1125 Profile* host_profile = |
1122 Profile::FromBrowserContext(host->GetBrowserContext()); | 1126 Profile::FromBrowserContext(host->GetBrowserContext()); |
1123 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) | 1127 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |
1124 host->Send(new ExtensionMsg_Unloaded(extension->id())); | 1128 host->Send(new ExtensionMsg_Unloaded(extension->id())); |
1125 } | 1129 } |
1126 | 1130 |
1127 profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason); | 1131 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
1128 profile_->GetExtensionSpecialStoragePolicy()-> | 1132 profile_->GetExtensionSpecialStoragePolicy()-> |
1129 RevokeRightsForExtension(extension); | 1133 RevokeRightsForExtension(extension); |
1130 | 1134 |
1131 ExtensionWebUI::UnregisterChromeURLOverrides( | 1135 ExtensionWebUI::UnregisterChromeURLOverrides( |
1132 profile_, extension->GetChromeURLOverrides()); | 1136 profile_, extension->GetChromeURLOverrides()); |
1133 | 1137 |
1134 #if defined(OS_CHROMEOS) | 1138 #if defined(OS_CHROMEOS) |
1135 // Revoke external file access to | 1139 // Revoke external file access to |
1136 if (profile_->GetFileSystemContext() && | 1140 if (profile_->GetFileSystemContext() && |
1137 profile_->GetFileSystemContext()->external_provider()) { | 1141 profile_->GetFileSystemContext()->external_provider()) { |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1906 extension_misc::UnloadedExtensionReason reason) { | 1910 extension_misc::UnloadedExtensionReason reason) { |
1907 // Make sure the extension gets deleted after we return from this function. | 1911 // Make sure the extension gets deleted after we return from this function. |
1908 scoped_refptr<const Extension> extension( | 1912 scoped_refptr<const Extension> extension( |
1909 GetExtensionByIdInternal(extension_id, true, true, false)); | 1913 GetExtensionByIdInternal(extension_id, true, true, false)); |
1910 | 1914 |
1911 // This method can be called via PostTask, so the extension may have been | 1915 // This method can be called via PostTask, so the extension may have been |
1912 // unloaded by the time this runs. | 1916 // unloaded by the time this runs. |
1913 if (!extension) { | 1917 if (!extension) { |
1914 // In case the extension may have crashed/uninstalled. Allow the profile to | 1918 // In case the extension may have crashed/uninstalled. Allow the profile to |
1915 // clean up its RequestContexts. | 1919 // clean up its RequestContexts. |
1916 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1920 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
1917 return; | 1921 return; |
1918 } | 1922 } |
1919 | 1923 |
1920 // Keep information about the extension so that we can reload it later | 1924 // Keep information about the extension so that we can reload it later |
1921 // even if it's not permanently installed. | 1925 // even if it's not permanently installed. |
1922 unloaded_extension_paths_[extension->id()] = extension->path(); | 1926 unloaded_extension_paths_[extension->id()] = extension->path(); |
1923 | 1927 |
1924 // Clean up if the extension is meant to be enabled after a reload. | 1928 // Clean up if the extension is meant to be enabled after a reload. |
1925 disabled_extension_paths_.erase(extension->id()); | 1929 disabled_extension_paths_.erase(extension->id()); |
1926 | 1930 |
1927 // Clean up runtime data. | 1931 // Clean up runtime data. |
1928 extension_runtime_data_.erase(extension_id); | 1932 extension_runtime_data_.erase(extension_id); |
1929 | 1933 |
1930 if (disabled_extensions_.Contains(extension->id())) { | 1934 if (disabled_extensions_.Contains(extension->id())) { |
1931 UnloadedExtensionInfo details(extension, reason); | 1935 UnloadedExtensionInfo details(extension, reason); |
1932 details.already_disabled = true; | 1936 details.already_disabled = true; |
1933 disabled_extensions_.Remove(extension->id()); | 1937 disabled_extensions_.Remove(extension->id()); |
1934 content::NotificationService::current()->Notify( | 1938 content::NotificationService::current()->Notify( |
1935 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 1939 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
1936 content::Source<Profile>(profile_), | 1940 content::Source<Profile>(profile_), |
1937 content::Details<UnloadedExtensionInfo>(&details)); | 1941 content::Details<UnloadedExtensionInfo>(&details)); |
1938 // Make sure the profile cleans up its RequestContexts when an already | 1942 // Make sure the profile cleans up its RequestContexts when an already |
1939 // disabled extension is unloaded (since they are also tracking the disabled | 1943 // disabled extension is unloaded (since they are also tracking the disabled |
1940 // extensions). | 1944 // extensions). |
1941 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1945 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
1942 return; | 1946 return; |
1943 } | 1947 } |
1944 | 1948 |
1945 // Remove the extension from our list. | 1949 // Remove the extension from our list. |
1946 extensions_.Remove(extension->id()); | 1950 extensions_.Remove(extension->id()); |
1947 | 1951 |
1948 NotifyExtensionUnloaded(extension.get(), reason); | 1952 NotifyExtensionUnloaded(extension.get(), reason); |
1949 } | 1953 } |
1950 | 1954 |
1951 void ExtensionService::UnloadAllExtensions() { | 1955 void ExtensionService::UnloadAllExtensions() { |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2476 Profile::FromBrowserContext(process->GetBrowserContext()); | 2480 Profile::FromBrowserContext(process->GetBrowserContext()); |
2477 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) | 2481 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
2478 break; | 2482 break; |
2479 | 2483 |
2480 installed_app_hosts_.erase(process->GetID()); | 2484 installed_app_hosts_.erase(process->GetID()); |
2481 | 2485 |
2482 process_map_.RemoveAllFromProcess(process->GetID()); | 2486 process_map_.RemoveAllFromProcess(process->GetID()); |
2483 BrowserThread::PostTask( | 2487 BrowserThread::PostTask( |
2484 BrowserThread::IO, FROM_HERE, | 2488 BrowserThread::IO, FROM_HERE, |
2485 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, | 2489 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, |
2486 profile_->GetExtensionInfoMap(), | 2490 system_->info_map(), |
2487 process->GetID())); | 2491 process->GetID())); |
2488 break; | 2492 break; |
2489 } | 2493 } |
2490 case chrome::NOTIFICATION_PREF_CHANGED: { | 2494 case chrome::NOTIFICATION_PREF_CHANGED: { |
2491 std::string* pref_name = content::Details<std::string>(details).ptr(); | 2495 std::string* pref_name = content::Details<std::string>(details).ptr(); |
2492 if (*pref_name == prefs::kExtensionInstallAllowList || | 2496 if (*pref_name == prefs::kExtensionInstallAllowList || |
2493 *pref_name == prefs::kExtensionInstallDenyList) { | 2497 *pref_name == prefs::kExtensionInstallDenyList) { |
2494 CheckAdminBlacklist(); | 2498 CheckAdminBlacklist(); |
2495 } else { | 2499 } else { |
2496 NOTREACHED() << "Unexpected preference name."; | 2500 NOTREACHED() << "Unexpected preference name."; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2692 // | 2696 // |
2693 // To coexist with certain unit tests that don't have an IO thread message | 2697 // To coexist with certain unit tests that don't have an IO thread message |
2694 // loop available at ExtensionService shutdown, we lazy-initialize this | 2698 // loop available at ExtensionService shutdown, we lazy-initialize this |
2695 // object so that those cases neither create nor destroy a SocketController. | 2699 // object so that those cases neither create nor destroy a SocketController. |
2696 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2700 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2697 if (!socket_controller_) { | 2701 if (!socket_controller_) { |
2698 socket_controller_ = new extensions::SocketController(); | 2702 socket_controller_ = new extensions::SocketController(); |
2699 } | 2703 } |
2700 return socket_controller_; | 2704 return socket_controller_; |
2701 } | 2705 } |
OLD | NEW |