| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 425 |
| 426 // Figure out if extension installation should be enabled. | 426 // Figure out if extension installation should be enabled. |
| 427 if (command_line->HasSwitch(switches::kDisableExtensions)) { | 427 if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 428 extensions_enabled_ = false; | 428 extensions_enabled_ = false; |
| 429 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { | 429 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 430 extensions_enabled_ = false; | 430 extensions_enabled_ = false; |
| 431 } | 431 } |
| 432 | 432 |
| 433 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, | 433 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, |
| 434 NotificationService::AllSources()); | 434 NotificationService::AllSources()); |
| 435 |
| 436 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 437 NotificationService::AllSources()); |
| 438 |
| 435 pref_change_registrar_.Init(profile->GetPrefs()); | 439 pref_change_registrar_.Init(profile->GetPrefs()); |
| 436 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); | 440 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); |
| 437 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); | 441 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); |
| 438 | 442 |
| 439 // Set up the ExtensionUpdater | 443 // Set up the ExtensionUpdater |
| 440 if (autoupdate_enabled) { | 444 if (autoupdate_enabled) { |
| 441 int update_frequency = kDefaultUpdateFrequencySeconds; | 445 int update_frequency = kDefaultUpdateFrequencySeconds; |
| 442 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { | 446 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
| 443 base::StringToInt(command_line->GetSwitchValueASCII( | 447 base::StringToInt(command_line->GetSwitchValueASCII( |
| 444 switches::kExtensionsUpdateFrequency), | 448 switches::kExtensionsUpdateFrequency), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 if (event_routers_initialized_) | 501 if (event_routers_initialized_) |
| 498 return; | 502 return; |
| 499 | 503 |
| 500 ExtensionHistoryEventRouter::GetInstance()->ObserveProfile(profile_); | 504 ExtensionHistoryEventRouter::GetInstance()->ObserveProfile(profile_); |
| 501 ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_); | 505 ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_); |
| 502 browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_)); | 506 browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_)); |
| 503 browser_event_router_->Init(); | 507 browser_event_router_->Init(); |
| 504 ExtensionBookmarkEventRouter::GetInstance()->Observe( | 508 ExtensionBookmarkEventRouter::GetInstance()->Observe( |
| 505 profile_->GetBookmarkModel()); | 509 profile_->GetBookmarkModel()); |
| 506 ExtensionCookiesEventRouter::GetInstance()->Init(); | 510 ExtensionCookiesEventRouter::GetInstance()->Init(); |
| 507 ExtensionManagementEventRouter::GetInstance()->Init(); | 511 |
| 512 management_event_router_.reset(new ExtensionManagementEventRouter()); |
| 513 management_event_router_->Init(); |
| 514 |
| 508 ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_); | 515 ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_); |
| 509 ExtensionWebNavigationEventRouter::GetInstance()->Init(); | 516 ExtensionWebNavigationEventRouter::GetInstance()->Init(); |
| 510 event_routers_initialized_ = true; | 517 event_routers_initialized_ = true; |
| 511 } | 518 } |
| 512 | 519 |
| 513 const Extension* ExtensionService::GetExtensionById(const std::string& id, | 520 const Extension* ExtensionService::GetExtensionById(const std::string& id, |
| 514 bool include_disabled) { | 521 bool include_disabled) { |
| 515 return GetExtensionByIdInternal(id, true, include_disabled); | 522 return GetExtensionByIdInternal(id, true, include_disabled); |
| 516 } | 523 } |
| 517 | 524 |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 | 1252 |
| 1246 Profile* ExtensionService::profile() { | 1253 Profile* ExtensionService::profile() { |
| 1247 return profile_; | 1254 return profile_; |
| 1248 } | 1255 } |
| 1249 | 1256 |
| 1250 void ExtensionService::DestroyingProfile() { | 1257 void ExtensionService::DestroyingProfile() { |
| 1251 if (updater_.get()) { | 1258 if (updater_.get()) { |
| 1252 updater_->Stop(); | 1259 updater_->Stop(); |
| 1253 } | 1260 } |
| 1254 browser_event_router_.reset(); | 1261 browser_event_router_.reset(); |
| 1262 management_event_router_.reset(); |
| 1255 pref_change_registrar_.RemoveAll(); | 1263 pref_change_registrar_.RemoveAll(); |
| 1256 profile_ = NULL; | 1264 profile_ = NULL; |
| 1257 toolbar_model_.DestroyingProfile(); | 1265 toolbar_model_.DestroyingProfile(); |
| 1258 } | 1266 } |
| 1259 | 1267 |
| 1260 ExtensionPrefs* ExtensionService::extension_prefs() { | 1268 ExtensionPrefs* ExtensionService::extension_prefs() { |
| 1261 return extension_prefs_; | 1269 return extension_prefs_; |
| 1262 } | 1270 } |
| 1263 | 1271 |
| 1264 void ExtensionService::CheckAdminBlacklist() { | 1272 void ExtensionService::CheckAdminBlacklist() { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 initial_state = | 1706 initial_state = |
| 1699 pending_extension_info.enable_on_install ? | 1707 pending_extension_info.enable_on_install ? |
| 1700 Extension::ENABLED : Extension::DISABLED; | 1708 Extension::ENABLED : Extension::DISABLED; |
| 1701 initial_enable_incognito = | 1709 initial_enable_incognito = |
| 1702 pending_extension_info.enable_incognito_on_install; | 1710 pending_extension_info.enable_incognito_on_install; |
| 1703 } | 1711 } |
| 1704 } else { | 1712 } else { |
| 1705 // Make sure we preserve enabled/disabled states. | 1713 // Make sure we preserve enabled/disabled states. |
| 1706 Extension::State existing_state = | 1714 Extension::State existing_state = |
| 1707 extension_prefs_->GetExtensionState(extension->id()); | 1715 extension_prefs_->GetExtensionState(extension->id()); |
| 1708 initial_state = | 1716 initial_state = Extension::ENABLED; |
| 1709 (existing_state == Extension::DISABLED) ? | 1717 if (!extension->is_theme() && existing_state == Extension::DISABLED) |
| 1710 Extension::DISABLED : Extension::ENABLED; | 1718 initial_state = Extension::DISABLED; |
| 1711 initial_enable_incognito = | 1719 initial_enable_incognito = |
| 1712 extension_prefs_->IsIncognitoEnabled(extension->id()); | 1720 extension_prefs_->IsIncognitoEnabled(extension->id()); |
| 1713 } | 1721 } |
| 1714 | 1722 |
| 1715 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", | 1723 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 1716 extension->GetType(), 100); | 1724 extension->GetType(), 100); |
| 1717 ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); | 1725 ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); |
| 1718 extension_prefs_->OnExtensionInstalled( | 1726 extension_prefs_->OnExtensionInstalled( |
| 1719 extension, initial_state, initial_enable_incognito); | 1727 extension, initial_state, initial_enable_incognito); |
| 1720 | 1728 |
| 1721 // Unpacked extensions start off with file access since they are a developer | 1729 // Unpacked extensions start off with file access since they are a developer |
| 1722 // feature. | 1730 // feature. |
| 1723 if (extension->location() == Extension::LOAD) | 1731 if (extension->location() == Extension::LOAD) |
| 1724 extension_prefs_->SetAllowFileAccess(extension->id(), true); | 1732 extension_prefs_->SetAllowFileAccess(extension->id(), true); |
| 1725 | 1733 |
| 1726 // If the extension is a theme, tell the profile (and therefore ThemeProvider) | 1734 NotificationService::current()->Notify( |
| 1727 // to apply it. | 1735 NotificationType::EXTENSION_INSTALLED, |
| 1728 if (extension->is_theme()) { | 1736 Source<Profile>(profile_), |
| 1729 NotificationService::current()->Notify( | 1737 Details<const Extension>(extension)); |
| 1730 NotificationType::THEME_INSTALLED, | |
| 1731 Source<Profile>(profile_), | |
| 1732 Details<const Extension>(extension)); | |
| 1733 } else { | |
| 1734 NotificationService::current()->Notify( | |
| 1735 NotificationType::EXTENSION_INSTALLED, | |
| 1736 Source<Profile>(profile_), | |
| 1737 Details<const Extension>(extension)); | |
| 1738 } | |
| 1739 | 1738 |
| 1740 if (extension->is_app()) { | 1739 if (extension->is_app()) { |
| 1741 ExtensionIdSet installed_ids = GetAppIds(); | 1740 ExtensionIdSet installed_ids = GetAppIds(); |
| 1742 installed_ids.insert(extension->id()); | 1741 installed_ids.insert(extension->id()); |
| 1743 default_apps_.DidInstallApp(installed_ids); | 1742 default_apps_.DidInstallApp(installed_ids); |
| 1744 } | 1743 } |
| 1745 | 1744 |
| 1746 // Transfer ownership of |extension| to AddExtension. | 1745 // Transfer ownership of |extension| to AddExtension. |
| 1747 AddExtension(scoped_extension); | 1746 AddExtension(scoped_extension); |
| 1748 } | 1747 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 | 1911 |
| 1913 DevToolsManager::GetInstance()->AttachClientHost( | 1912 DevToolsManager::GetInstance()->AttachClientHost( |
| 1914 iter->second, host->render_view_host()); | 1913 iter->second, host->render_view_host()); |
| 1915 orphaned_dev_tools_.erase(iter); | 1914 orphaned_dev_tools_.erase(iter); |
| 1916 } | 1915 } |
| 1917 | 1916 |
| 1918 void ExtensionService::Observe(NotificationType type, | 1917 void ExtensionService::Observe(NotificationType type, |
| 1919 const NotificationSource& source, | 1918 const NotificationSource& source, |
| 1920 const NotificationDetails& details) { | 1919 const NotificationDetails& details) { |
| 1921 switch (type.value) { | 1920 switch (type.value) { |
| 1921 case NotificationType::BROWSER_THEME_CHANGED: { |
| 1922 // Disable any other enabled themes. |
| 1923 std::string new_theme_id; |
| 1924 const Extension* theme = Details<const Extension>(details).ptr(); |
| 1925 if (theme) |
| 1926 new_theme_id = theme->id(); |
| 1927 |
| 1928 std::set<std::string> disable_list; |
| 1929 for (ExtensionList::iterator i = extensions_.begin(); |
| 1930 i != extensions_.end(); ++i) { |
| 1931 const Extension* extension = i->get(); |
| 1932 if (extension->is_theme() && extension->id() != new_theme_id) |
| 1933 disable_list.insert(extension->id()); |
| 1934 } |
| 1935 |
| 1936 for (std::set<std::string>::iterator i = disable_list.begin(); |
| 1937 i != disable_list.end(); ++i) { |
| 1938 DisableExtension(*i); |
| 1939 } |
| 1940 |
| 1941 break; |
| 1942 } |
| 1943 |
| 1922 case NotificationType::EXTENSION_PROCESS_TERMINATED: { | 1944 case NotificationType::EXTENSION_PROCESS_TERMINATED: { |
| 1923 if (profile_ != Source<Profile>(source).ptr()->GetOriginalProfile()) | 1945 if (profile_ != Source<Profile>(source).ptr()->GetOriginalProfile()) |
| 1924 break; | 1946 break; |
| 1925 | 1947 |
| 1926 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); | 1948 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
| 1927 TrackTerminatedExtension(host->extension()); | 1949 TrackTerminatedExtension(host->extension()); |
| 1928 | 1950 |
| 1929 // Unload the entire extension. We want it to be in a consistent state: | 1951 // Unload the entire extension. We want it to be in a consistent state: |
| 1930 // either fully working or not loaded at all, but never half-crashed. | 1952 // either fully working or not loaded at all, but never half-crashed. |
| 1931 // We do it in a PostTask so that other handlers of this notification will | 1953 // We do it in a PostTask so that other handlers of this notification will |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 } | 2010 } |
| 1989 | 2011 |
| 1990 void ExtensionService::SetBeingUpgraded(const Extension* extension, | 2012 void ExtensionService::SetBeingUpgraded(const Extension* extension, |
| 1991 bool value) { | 2013 bool value) { |
| 1992 extension_runtime_data_[extension->id()].being_upgraded = value; | 2014 extension_runtime_data_[extension->id()].being_upgraded = value; |
| 1993 } | 2015 } |
| 1994 | 2016 |
| 1995 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { | 2017 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { |
| 1996 return &extension_runtime_data_[extension->id()].property_bag; | 2018 return &extension_runtime_data_[extension->id()].property_bag; |
| 1997 } | 2019 } |
| OLD | NEW |