| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    46 #include "chrome/browser/extensions/extension_global_error.h" |    46 #include "chrome/browser/extensions/extension_global_error.h" | 
|    47 #include "chrome/browser/extensions/extension_host.h" |    47 #include "chrome/browser/extensions/extension_host.h" | 
|    48 #include "chrome/browser/extensions/extension_input_ime_api.h" |    48 #include "chrome/browser/extensions/extension_input_ime_api.h" | 
|    49 #include "chrome/browser/extensions/extension_management_api.h" |    49 #include "chrome/browser/extensions/extension_management_api.h" | 
|    50 #include "chrome/browser/extensions/extension_preference_api.h" |    50 #include "chrome/browser/extensions/extension_preference_api.h" | 
|    51 #include "chrome/browser/extensions/extension_process_manager.h" |    51 #include "chrome/browser/extensions/extension_process_manager.h" | 
|    52 #include "chrome/browser/extensions/extension_processes_api.h" |    52 #include "chrome/browser/extensions/extension_processes_api.h" | 
|    53 #include "chrome/browser/extensions/extension_sorting.h" |    53 #include "chrome/browser/extensions/extension_sorting.h" | 
|    54 #include "chrome/browser/extensions/extension_special_storage_policy.h" |    54 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 
|    55 #include "chrome/browser/extensions/extension_sync_data.h" |    55 #include "chrome/browser/extensions/extension_sync_data.h" | 
 |    56 #include "chrome/browser/extensions/extension_system.h" | 
 |    57 #include "chrome/browser/extensions/extension_system_factory.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" | 
|    65 #include "chrome/browser/extensions/updater/extension_updater.h" |    67 #include "chrome/browser/extensions/updater/extension_updater.h" | 
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   370   return true; |   372   return true; | 
|   371 } |   373 } | 
|   372  |   374  | 
|   373 ExtensionService::ExtensionService(Profile* profile, |   375 ExtensionService::ExtensionService(Profile* profile, | 
|   374                                    const CommandLine* command_line, |   376                                    const CommandLine* command_line, | 
|   375                                    const FilePath& install_directory, |   377                                    const FilePath& install_directory, | 
|   376                                    ExtensionPrefs* extension_prefs, |   378                                    ExtensionPrefs* extension_prefs, | 
|   377                                    bool autoupdate_enabled, |   379                                    bool autoupdate_enabled, | 
|   378                                    bool extensions_enabled) |   380                                    bool extensions_enabled) | 
|   379     : profile_(profile), |   381     : profile_(profile), | 
 |   382       system_(ExtensionSystemFactory::GetForProfile(profile)), | 
|   380       extension_prefs_(extension_prefs), |   383       extension_prefs_(extension_prefs), | 
|   381       settings_frontend_(extensions::SettingsFrontend::Create(profile)), |   384       settings_frontend_(extensions::SettingsFrontend::Create(profile)), | 
|   382       pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |   385       pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 
|   383       install_directory_(install_directory), |   386       install_directory_(install_directory), | 
|   384       extensions_enabled_(extensions_enabled), |   387       extensions_enabled_(extensions_enabled), | 
|   385       show_extensions_prompts_(true), |   388       show_extensions_prompts_(true), | 
|   386       ready_(false), |   389       ready_(false), | 
|   387       toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |   390       toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 
|   388       menu_manager_(profile), |   391       menu_manager_(profile), | 
|   389       app_notification_manager_(new AppNotificationManager(profile)), |   392       app_notification_manager_(new AppNotificationManager(profile)), | 
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   693 void ExtensionService::ReloadExtension(const std::string& extension_id) { |   696 void ExtensionService::ReloadExtension(const std::string& extension_id) { | 
|   694   CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |   697   CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|   695   FilePath path; |   698   FilePath path; | 
|   696   const Extension* current_extension = GetExtensionById(extension_id, false); |   699   const Extension* current_extension = GetExtensionById(extension_id, false); | 
|   697  |   700  | 
|   698   // Disable the extension if it's loaded. It might not be loaded if it crashed. |   701   // Disable the extension if it's loaded. It might not be loaded if it crashed. | 
|   699   if (current_extension) { |   702   if (current_extension) { | 
|   700     // If the extension has an inspector open for its background page, detach |   703     // If the extension has an inspector open for its background page, detach | 
|   701     // the inspector and hang onto a cookie for it, so that we can reattach |   704     // the inspector and hang onto a cookie for it, so that we can reattach | 
|   702     // later. |   705     // later. | 
|   703     ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |   706     // TODO(yoz): this is not incognito-safe! | 
 |   707     ExtensionProcessManager* manager = system_->process_manager(); | 
|   704     ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); |   708     ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); | 
|   705     if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( |   709     if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( | 
|   706             host->render_view_host())) { |   710             host->render_view_host())) { | 
|   707       // Look for an open inspector for the background page. |   711       // Look for an open inspector for the background page. | 
|   708       DevToolsAgentHost* agent = |   712       DevToolsAgentHost* agent = | 
|   709           DevToolsAgentHostRegistry::GetDevToolsAgentHost( |   713           DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 
|   710               host->render_view_host()); |   714               host->render_view_host()); | 
|   711       int devtools_cookie = |   715       int devtools_cookie = | 
|   712           content::DevToolsManager::GetInstance()->DetachClientHost(agent); |   716           content::DevToolsManager::GetInstance()->DetachClientHost(agent); | 
|   713       if (devtools_cookie >= 0) |   717       if (devtools_cookie >= 0) | 
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   983   } |   987   } | 
|   984 } |   988 } | 
|   985  |   989  | 
|   986 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |   990 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { | 
|   987   // The ChromeURLRequestContexts need to be first to know that the extension |   991   // The ChromeURLRequestContexts need to be first to know that the extension | 
|   988   // was loaded, otherwise a race can arise where a renderer that is created |   992   // was loaded, otherwise a race can arise where a renderer that is created | 
|   989   // for the extension may try to load an extension URL with an extension id |   993   // for the extension may try to load an extension URL with an extension id | 
|   990   // that the request context doesn't yet know about. The profile is responsible |   994   // that the request context doesn't yet know about. The profile is responsible | 
|   991   // for ensuring its URLRequestContexts appropriately discover the loaded |   995   // for ensuring its URLRequestContexts appropriately discover the loaded | 
|   992   // extension. |   996   // extension. | 
|   993   profile_->RegisterExtensionWithRequestContexts(extension); |   997   system_->RegisterExtensionWithRequestContexts(extension); | 
|   994  |   998  | 
|   995   // Tell renderers about the new extension, unless it's a theme (renderers |   999   // Tell renderers about the new extension, unless it's a theme (renderers | 
|   996   // don't need to know about themes). |  1000   // don't need to know about themes). | 
|   997   if (!extension->is_theme()) { |  1001   if (!extension->is_theme()) { | 
|   998     for (content::RenderProcessHost::iterator i( |  1002     for (content::RenderProcessHost::iterator i( | 
|   999             content::RenderProcessHost::AllHostsIterator()); |  1003             content::RenderProcessHost::AllHostsIterator()); | 
|  1000          !i.IsAtEnd(); i.Advance()) { |  1004          !i.IsAtEnd(); i.Advance()) { | 
|  1001       content::RenderProcessHost* host = i.GetCurrentValue(); |  1005       content::RenderProcessHost* host = i.GetCurrentValue(); | 
|  1002       Profile* host_profile = |  1006       Profile* host_profile = | 
|  1003           Profile::FromBrowserContext(host->GetBrowserContext()); |  1007           Profile::FromBrowserContext(host->GetBrowserContext()); | 
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1130   for (content::RenderProcessHost::iterator i( |  1134   for (content::RenderProcessHost::iterator i( | 
|  1131           content::RenderProcessHost::AllHostsIterator()); |  1135           content::RenderProcessHost::AllHostsIterator()); | 
|  1132        !i.IsAtEnd(); i.Advance()) { |  1136        !i.IsAtEnd(); i.Advance()) { | 
|  1133     content::RenderProcessHost* host = i.GetCurrentValue(); |  1137     content::RenderProcessHost* host = i.GetCurrentValue(); | 
|  1134     Profile* host_profile = |  1138     Profile* host_profile = | 
|  1135         Profile::FromBrowserContext(host->GetBrowserContext()); |  1139         Profile::FromBrowserContext(host->GetBrowserContext()); | 
|  1136     if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |  1140     if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) | 
|  1137       host->Send(new ExtensionMsg_Unloaded(extension->id())); |  1141       host->Send(new ExtensionMsg_Unloaded(extension->id())); | 
|  1138   } |  1142   } | 
|  1139  |  1143  | 
|  1140   profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |  1144   system_->UnregisterExtensionWithRequestContexts(extension->id(), reason); | 
|  1141   profile_->GetExtensionSpecialStoragePolicy()-> |  1145   profile_->GetExtensionSpecialStoragePolicy()-> | 
|  1142       RevokeRightsForExtension(extension); |  1146       RevokeRightsForExtension(extension); | 
|  1143  |  1147  | 
|  1144   ExtensionWebUI::UnregisterChromeURLOverrides( |  1148   ExtensionWebUI::UnregisterChromeURLOverrides( | 
|  1145       profile_, extension->GetChromeURLOverrides()); |  1149       profile_, extension->GetChromeURLOverrides()); | 
|  1146  |  1150  | 
|  1147 #if defined(OS_CHROMEOS) |  1151 #if defined(OS_CHROMEOS) | 
|  1148     // Revoke external file access to |  1152     // Revoke external file access to | 
|  1149   if (BrowserContext::GetFileSystemContext(profile_) && |  1153   if (BrowserContext::GetFileSystemContext(profile_) && | 
|  1150       BrowserContext::GetFileSystemContext(profile_)->external_provider()) { |  1154       BrowserContext::GetFileSystemContext(profile_)->external_provider()) { | 
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1873     extension_misc::UnloadedExtensionReason reason) { |  1877     extension_misc::UnloadedExtensionReason reason) { | 
|  1874   // Make sure the extension gets deleted after we return from this function. |  1878   // Make sure the extension gets deleted after we return from this function. | 
|  1875   scoped_refptr<const Extension> extension( |  1879   scoped_refptr<const Extension> extension( | 
|  1876       GetExtensionByIdInternal(extension_id, true, true, false)); |  1880       GetExtensionByIdInternal(extension_id, true, true, false)); | 
|  1877  |  1881  | 
|  1878   // This method can be called via PostTask, so the extension may have been |  1882   // This method can be called via PostTask, so the extension may have been | 
|  1879   // unloaded by the time this runs. |  1883   // unloaded by the time this runs. | 
|  1880   if (!extension) { |  1884   if (!extension) { | 
|  1881     // In case the extension may have crashed/uninstalled. Allow the profile to |  1885     // In case the extension may have crashed/uninstalled. Allow the profile to | 
|  1882     // clean up its RequestContexts. |  1886     // clean up its RequestContexts. | 
|  1883     profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |  1887     system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 
|  1884     return; |  1888     return; | 
|  1885   } |  1889   } | 
|  1886  |  1890  | 
|  1887   // Keep information about the extension so that we can reload it later |  1891   // Keep information about the extension so that we can reload it later | 
|  1888   // even if it's not permanently installed. |  1892   // even if it's not permanently installed. | 
|  1889   unloaded_extension_paths_[extension->id()] = extension->path(); |  1893   unloaded_extension_paths_[extension->id()] = extension->path(); | 
|  1890  |  1894  | 
|  1891   // Clean up if the extension is meant to be enabled after a reload. |  1895   // Clean up if the extension is meant to be enabled after a reload. | 
|  1892   disabled_extension_paths_.erase(extension->id()); |  1896   disabled_extension_paths_.erase(extension->id()); | 
|  1893  |  1897  | 
|  1894   // Clean up runtime data. |  1898   // Clean up runtime data. | 
|  1895   extension_runtime_data_.erase(extension_id); |  1899   extension_runtime_data_.erase(extension_id); | 
|  1896  |  1900  | 
|  1897 if (disabled_extensions_.Contains(extension->id())) { |  1901 if (disabled_extensions_.Contains(extension->id())) { | 
|  1898     UnloadedExtensionInfo details(extension, reason); |  1902     UnloadedExtensionInfo details(extension, reason); | 
|  1899     details.already_disabled = true; |  1903     details.already_disabled = true; | 
|  1900     disabled_extensions_.Remove(extension->id()); |  1904     disabled_extensions_.Remove(extension->id()); | 
|  1901     content::NotificationService::current()->Notify( |  1905     content::NotificationService::current()->Notify( | 
|  1902         chrome::NOTIFICATION_EXTENSION_UNLOADED, |  1906         chrome::NOTIFICATION_EXTENSION_UNLOADED, | 
|  1903         content::Source<Profile>(profile_), |  1907         content::Source<Profile>(profile_), | 
|  1904         content::Details<UnloadedExtensionInfo>(&details)); |  1908         content::Details<UnloadedExtensionInfo>(&details)); | 
|  1905     // Make sure the profile cleans up its RequestContexts when an already |  1909     // Make sure the profile cleans up its RequestContexts when an already | 
|  1906     // disabled extension is unloaded (since they are also tracking the disabled |  1910     // disabled extension is unloaded (since they are also tracking the disabled | 
|  1907     // extensions). |  1911     // extensions). | 
|  1908     profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |  1912     system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 
|  1909     return; |  1913     return; | 
|  1910   } |  1914   } | 
|  1911  |  1915  | 
|  1912 // Remove the extension from our list. |  1916 // Remove the extension from our list. | 
|  1913   extensions_.Remove(extension->id()); |  1917   extensions_.Remove(extension->id()); | 
|  1914  |  1918  | 
|  1915   NotifyExtensionUnloaded(extension.get(), reason); |  1919   NotifyExtensionUnloaded(extension.get(), reason); | 
|  1916 } |  1920 } | 
|  1917  |  1921  | 
|  1918 void ExtensionService::UnloadAllExtensions() { |  1922 void ExtensionService::UnloadAllExtensions() { | 
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2469           Profile::FromBrowserContext(process->GetBrowserContext()); |  2473           Profile::FromBrowserContext(process->GetBrowserContext()); | 
|  2470       if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |  2474       if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) | 
|  2471           break; |  2475           break; | 
|  2472  |  2476  | 
|  2473       installed_app_hosts_.erase(process->GetID()); |  2477       installed_app_hosts_.erase(process->GetID()); | 
|  2474  |  2478  | 
|  2475       process_map_.RemoveAllFromProcess(process->GetID()); |  2479       process_map_.RemoveAllFromProcess(process->GetID()); | 
|  2476       BrowserThread::PostTask( |  2480       BrowserThread::PostTask( | 
|  2477           BrowserThread::IO, FROM_HERE, |  2481           BrowserThread::IO, FROM_HERE, | 
|  2478           base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, |  2482           base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, | 
|  2479                      profile_->GetExtensionInfoMap(), |  2483                      system_->info_map(), | 
|  2480                      process->GetID())); |  2484                      process->GetID())); | 
|  2481       break; |  2485       break; | 
|  2482     } |  2486     } | 
|  2483     case chrome::NOTIFICATION_PREF_CHANGED: { |  2487     case chrome::NOTIFICATION_PREF_CHANGED: { | 
|  2484       std::string* pref_name = content::Details<std::string>(details).ptr(); |  2488       std::string* pref_name = content::Details<std::string>(details).ptr(); | 
|  2485       if (*pref_name == prefs::kExtensionInstallAllowList || |  2489       if (*pref_name == prefs::kExtensionInstallAllowList || | 
|  2486           *pref_name == prefs::kExtensionInstallDenyList) { |  2490           *pref_name == prefs::kExtensionInstallDenyList) { | 
|  2487         CheckAdminBlacklist(); |  2491         CheckAdminBlacklist(); | 
|  2488       } else { |  2492       } else { | 
|  2489         NOTREACHED() << "Unexpected preference name."; |  2493         NOTREACHED() << "Unexpected preference name."; | 
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2642   return api_resource_controller_; |  2646   return api_resource_controller_; | 
|  2643 } |  2647 } | 
|  2644  |  2648  | 
|  2645 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() { |  2649 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() { | 
|  2646   if (!rules_registry_service_.get()) { |  2650   if (!rules_registry_service_.get()) { | 
|  2647     rules_registry_service_.reset( |  2651     rules_registry_service_.reset( | 
|  2648         new extensions::RulesRegistryService(profile_)); |  2652         new extensions::RulesRegistryService(profile_)); | 
|  2649   } |  2653   } | 
|  2650   return rules_registry_service_.get(); |  2654   return rules_registry_service_.get(); | 
|  2651 } |  2655 } | 
| OLD | NEW |