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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 | 518 |
519 ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_); | 519 ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_); |
520 extensions::InputImeEventRouter::GetInstance()->Init(); | 520 extensions::InputImeEventRouter::GetInstance()->Init(); |
521 #endif | 521 #endif |
522 #endif // defined(ENABLE_EXTENSIONS) | 522 #endif // defined(ENABLE_EXTENSIONS) |
523 event_routers_initialized_ = true; | 523 event_routers_initialized_ = true; |
524 } | 524 } |
525 | 525 |
526 const Extension* ExtensionService::GetExtensionById( | 526 const Extension* ExtensionService::GetExtensionById( |
527 const std::string& id, bool include_disabled) const { | 527 const std::string& id, bool include_disabled) const { |
528 return GetExtensionByIdInternal(id, true, include_disabled, false); | 528 int include_mask = ExtensionService::INCLUDE_ENABLED; |
529 if (include_disabled) { | |
530 include_mask |= ExtensionService::INCLUDE_DISABLED; | |
531 } | |
532 return GetExtensionByIdInternal(id, include_mask); | |
529 } | 533 } |
530 | 534 |
531 void ExtensionService::Init() { | 535 void ExtensionService::Init() { |
532 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 536 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
533 | 537 |
534 DCHECK(!ready_); // Can't redo init. | 538 DCHECK(!ready_); // Can't redo init. |
535 DCHECK_EQ(extensions_.size(), 0u); | 539 DCHECK_EQ(extensions_.size(), 0u); |
536 | 540 |
537 component_loader_->LoadAll(); | 541 component_loader_->LoadAll(); |
538 extensions::InstalledLoader(this).LoadAllExtensions(); | 542 extensions::InstalledLoader(this).LoadAllExtensions(); |
(...skipping 22 matching lines...) Expand all Loading... | |
561 bool ExtensionService::UpdateExtension( | 565 bool ExtensionService::UpdateExtension( |
562 const std::string& id, | 566 const std::string& id, |
563 const FilePath& extension_path, | 567 const FilePath& extension_path, |
564 const GURL& download_url, | 568 const GURL& download_url, |
565 CrxInstaller** out_crx_installer) { | 569 CrxInstaller** out_crx_installer) { |
566 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 570 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
567 | 571 |
568 const extensions::PendingExtensionInfo* pending_extension_info = | 572 const extensions::PendingExtensionInfo* pending_extension_info = |
569 pending_extension_manager()->GetById(id); | 573 pending_extension_manager()->GetById(id); |
570 | 574 |
575 int include_mask = ExtensionService::INCLUDE_ENABLED; | |
576 include_mask |= ExtensionService::INCLUDE_DISABLED; | |
571 const Extension* extension = | 577 const Extension* extension = |
572 GetExtensionByIdInternal(id, true, true, false); | 578 GetExtensionByIdInternal(id, include_mask); |
573 if (!pending_extension_info && !extension) { | 579 if (!pending_extension_info && !extension) { |
574 LOG(WARNING) << "Will not update extension " << id | 580 LOG(WARNING) << "Will not update extension " << id |
575 << " because it is not installed or pending"; | 581 << " because it is not installed or pending"; |
576 // Delete extension_path since we're not creating a CrxInstaller | 582 // Delete extension_path since we're not creating a CrxInstaller |
577 // that would do it for us. | 583 // that would do it for us. |
578 if (!BrowserThread::PostTask( | 584 if (!BrowserThread::PostTask( |
579 BrowserThread::FILE, FROM_HERE, | 585 BrowserThread::FILE, FROM_HERE, |
580 base::Bind( | 586 base::Bind( |
581 &extension_file_util::DeleteFile, extension_path, false))) | 587 &extension_file_util::DeleteFile, extension_path, false))) |
582 NOTREACHED(); | 588 NOTREACHED(); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
822 | 828 |
823 void ExtensionService::EnableExtension(const std::string& extension_id) { | 829 void ExtensionService::EnableExtension(const std::string& extension_id) { |
824 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 830 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
825 | 831 |
826 if (IsExtensionEnabled(extension_id)) | 832 if (IsExtensionEnabled(extension_id)) |
827 return; | 833 return; |
828 | 834 |
829 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); | 835 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
830 extension_prefs_->RemoveDisableReason(extension_id); | 836 extension_prefs_->RemoveDisableReason(extension_id); |
831 | 837 |
832 const Extension* extension = | 838 const Extension* extension = GetExtensionByIdInternal(extension_id, |
833 GetExtensionByIdInternal(extension_id, false, true, false); | 839 ExtensionService::INCLUDE_DISABLED); |
834 // This can happen if sync enables an extension that is not | 840 // This can happen if sync enables an extension that is not |
835 // installed yet. | 841 // installed yet. |
836 if (!extension) | 842 if (!extension) |
837 return; | 843 return; |
838 | 844 |
839 // Move it over to the enabled list. | 845 // Move it over to the enabled list. |
840 extensions_.Insert(make_scoped_refptr(extension)); | 846 extensions_.Insert(make_scoped_refptr(extension)); |
841 disabled_extensions_.Remove(extension->id()); | 847 disabled_extensions_.Remove(extension->id()); |
842 | 848 |
843 // Make sure any browser action contained within it is not hidden. | 849 // Make sure any browser action contained within it is not hidden. |
(...skipping 23 matching lines...) Expand all Loading... | |
867 // |extension| can be NULL if sync disables an extension that is not | 873 // |extension| can be NULL if sync disables an extension that is not |
868 // installed yet. | 874 // installed yet. |
869 if (extension && | 875 if (extension && |
870 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { | 876 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { |
871 return; | 877 return; |
872 } | 878 } |
873 | 879 |
874 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 880 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
875 extension_prefs_->SetDisableReason(extension_id, disable_reason); | 881 extension_prefs_->SetDisableReason(extension_id, disable_reason); |
876 | 882 |
877 extension = GetExtensionByIdInternal(extension_id, true, false, true); | 883 int include_mask = ExtensionService::INCLUDE_ENABLED; |
884 include_mask |= ExtensionService::INCLUDE_TERMINATED; | |
885 extension = GetExtensionByIdInternal(extension_id, include_mask); | |
878 if (!extension) | 886 if (!extension) |
879 return; | 887 return; |
880 | 888 |
881 // Move it over to the disabled list. | 889 // Move it over to the disabled list. |
882 disabled_extensions_.Insert(make_scoped_refptr(extension)); | 890 disabled_extensions_.Insert(make_scoped_refptr(extension)); |
883 if (extensions_.Contains(extension->id())) | 891 if (extensions_.Contains(extension->id())) |
884 extensions_.Remove(extension->id()); | 892 extensions_.Remove(extension->id()); |
885 else | 893 else |
886 terminated_extensions_.Remove(extension->id()); | 894 terminated_extensions_.Remove(extension->id()); |
887 | 895 |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1788 } | 1796 } |
1789 | 1797 |
1790 void ExtensionService::HandleExtensionAlertDetails() { | 1798 void ExtensionService::HandleExtensionAlertDetails() { |
1791 extension_error_ui_->ShowExtensions(); | 1799 extension_error_ui_->ShowExtensions(); |
1792 } | 1800 } |
1793 | 1801 |
1794 void ExtensionService::UnloadExtension( | 1802 void ExtensionService::UnloadExtension( |
1795 const std::string& extension_id, | 1803 const std::string& extension_id, |
1796 extension_misc::UnloadedExtensionReason reason) { | 1804 extension_misc::UnloadedExtensionReason reason) { |
1797 // Make sure the extension gets deleted after we return from this function. | 1805 // Make sure the extension gets deleted after we return from this function. |
1806 int include_mask = ExtensionService::INCLUDE_ENABLED; | |
1807 include_mask |= ExtensionService::INCLUDE_DISABLED; | |
1798 scoped_refptr<const Extension> extension( | 1808 scoped_refptr<const Extension> extension( |
1799 GetExtensionByIdInternal(extension_id, true, true, false)); | 1809 GetExtensionByIdInternal(extension_id, include_mask)); |
1800 | 1810 |
1801 // This method can be called via PostTask, so the extension may have been | 1811 // This method can be called via PostTask, so the extension may have been |
1802 // unloaded by the time this runs. | 1812 // unloaded by the time this runs. |
1803 if (!extension) { | 1813 if (!extension) { |
1804 // In case the extension may have crashed/uninstalled. Allow the profile to | 1814 // In case the extension may have crashed/uninstalled. Allow the profile to |
1805 // clean up its RequestContexts. | 1815 // clean up its RequestContexts. |
1806 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1816 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
1807 return; | 1817 return; |
1808 } | 1818 } |
1809 | 1819 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2006 // maintain backwards compatibility while still having "omnibox" in the | 2016 // maintain backwards compatibility while still having "omnibox" in the |
2007 // manifest. If a user installs the extension on Chrome 9, the browser | 2017 // manifest. If a user installs the extension on Chrome 9, the browser |
2008 // will record the permissions it recognized, not including "omnibox." | 2018 // will record the permissions it recognized, not including "omnibox." |
2009 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome | 2019 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
2010 // will disable the extension and prompt the user to approve the increase | 2020 // will disable the extension and prompt the user to approve the increase |
2011 // in privileges. The extension could then release a new version that | 2021 // in privileges. The extension could then release a new version that |
2012 // removes the "omnibox" permission. When the user upgrades, Chrome will | 2022 // removes the "omnibox" permission. When the user upgrades, Chrome will |
2013 // still remember that "omnibox" had been granted, so that if the | 2023 // still remember that "omnibox" had been granted, so that if the |
2014 // extension once again includes "omnibox" in an upgrade, the extension | 2024 // extension once again includes "omnibox" in an upgrade, the extension |
2015 // can upgrade without requiring this user's approval. | 2025 // can upgrade without requiring this user's approval. |
2016 const Extension* old = GetExtensionByIdInternal(extension->id(), | 2026 int include_mask = ExtensionService::INCLUDE_ENABLED; |
2017 true, true, false); | 2027 include_mask |= ExtensionService::INCLUDE_DISABLED; |
2028 const Extension* old = | |
2029 GetExtensionByIdInternal(extension->id(), include_mask); | |
2018 bool is_extension_upgrade = old != NULL; | 2030 bool is_extension_upgrade = old != NULL; |
2019 bool is_privilege_increase = false; | 2031 bool is_privilege_increase = false; |
2020 bool previously_disabled = false; | 2032 bool previously_disabled = false; |
2021 Extension::DisableReason disable_reason = | 2033 Extension::DisableReason disable_reason = |
2022 extension_prefs_->GetDisableReason(extension->id()); | 2034 extension_prefs_->GetDisableReason(extension->id()); |
2023 | 2035 |
2024 // We only need to compare the granted permissions to the current permissions | 2036 // We only need to compare the granted permissions to the current permissions |
2025 // if the extension is not allowed to silently increase its permissions. | 2037 // if the extension is not allowed to silently increase its permissions. |
2026 if (!extension->CanSilentlyIncreasePermissions()) { | 2038 if (!extension->CanSilentlyIncreasePermissions()) { |
2027 // Add all the recognized permissions if the granted permissions list | 2039 // Add all the recognized permissions if the granted permissions list |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2144 pending_extension_manager()->Remove(id); | 2156 pending_extension_manager()->Remove(id); |
2145 } else { | 2157 } else { |
2146 // We explicitly want to re-enable an uninstalled external | 2158 // We explicitly want to re-enable an uninstalled external |
2147 // extension; if we're here, that means the user is manually | 2159 // extension; if we're here, that means the user is manually |
2148 // installing the extension. | 2160 // installing the extension. |
2149 if (IsExternalExtensionUninstalled(id)) { | 2161 if (IsExternalExtensionUninstalled(id)) { |
2150 initial_enable = true; | 2162 initial_enable = true; |
2151 } | 2163 } |
2152 } | 2164 } |
2153 | 2165 |
2166 int include_mask = ExtensionService::INCLUDE_ENABLED; | |
2167 include_mask |= ExtensionService::INCLUDE_DISABLED; | |
2154 // Do not record the install histograms for upgrades. | 2168 // Do not record the install histograms for upgrades. |
2155 if (!GetExtensionByIdInternal(extension->id(), true, true, false)) { | 2169 if (!GetExtensionByIdInternal(extension->id(), include_mask)) { |
2156 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", | 2170 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
2157 extension->GetType(), 100); | 2171 extension->GetType(), 100); |
2158 RecordPermissionMessagesHistogram( | 2172 RecordPermissionMessagesHistogram( |
2159 extension, "Extensions.Permissions_Install"); | 2173 extension, "Extensions.Permissions_Install"); |
2160 } | 2174 } |
2161 | 2175 |
2162 // Certain extension locations are specific enough that we can | 2176 // Certain extension locations are specific enough that we can |
2163 // auto-acknowledge any extension that came from one of them. | 2177 // auto-acknowledge any extension that came from one of them. |
2164 if (extension->location() == Extension::EXTERNAL_POLICY_DOWNLOAD) { | 2178 if (extension->location() == Extension::EXTERNAL_POLICY_DOWNLOAD) { |
2165 AcknowledgeExternalExtension(extension->id()); | 2179 AcknowledgeExternalExtension(extension->id()); |
(...skipping 15 matching lines...) Expand all Loading... | |
2181 content::NotificationService::current()->Notify( | 2195 content::NotificationService::current()->Notify( |
2182 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 2196 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
2183 content::Source<Profile>(profile_), | 2197 content::Source<Profile>(profile_), |
2184 content::Details<const Extension>(extension)); | 2198 content::Details<const Extension>(extension)); |
2185 | 2199 |
2186 // Transfer ownership of |extension| to AddExtension. | 2200 // Transfer ownership of |extension| to AddExtension. |
2187 AddExtension(scoped_extension); | 2201 AddExtension(scoped_extension); |
2188 } | 2202 } |
2189 | 2203 |
2190 const Extension* ExtensionService::GetExtensionByIdInternal( | 2204 const Extension* ExtensionService::GetExtensionByIdInternal( |
2191 const std::string& id, bool include_enabled, bool include_disabled, | 2205 const std::string& id, const int include_mask) const { |
2192 bool include_terminated) const { | |
2193 std::string lowercase_id = StringToLowerASCII(id); | 2206 std::string lowercase_id = StringToLowerASCII(id); |
2194 if (include_enabled) { | 2207 if (include_mask & ExtensionService::INCLUDE_ENABLED) { |
Mihai Parparita -not on Chrome
2012/08/15 00:10:07
Nit: since you're in ExtensionService already, you
| |
2195 const Extension* extension = extensions_.GetByID(lowercase_id); | 2208 const Extension* extension = extensions_.GetByID(lowercase_id); |
2196 if (extension) | 2209 if (extension) |
2197 return extension; | 2210 return extension; |
2198 } | 2211 } |
2199 if (include_disabled) { | 2212 if (include_mask & ExtensionService::INCLUDE_DISABLED) { |
2200 const Extension* extension = disabled_extensions_.GetByID(lowercase_id); | 2213 const Extension* extension = disabled_extensions_.GetByID(lowercase_id); |
2201 if (extension) | 2214 if (extension) |
2202 return extension; | 2215 return extension; |
2203 } | 2216 } |
2204 if (include_terminated) { | 2217 if (include_mask & ExtensionService::INCLUDE_TERMINATED) { |
2205 const Extension* extension = terminated_extensions_.GetByID(lowercase_id); | 2218 const Extension* extension = terminated_extensions_.GetByID(lowercase_id); |
2206 if (extension) | 2219 if (extension) |
2207 return extension; | 2220 return extension; |
2208 } | 2221 } |
2209 return NULL; | 2222 return NULL; |
2210 } | 2223 } |
2211 | 2224 |
2212 void ExtensionService::TrackTerminatedExtension(const Extension* extension) { | 2225 void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
2213 if (!terminated_extensions_.Contains(extension->id())) | 2226 if (!terminated_extensions_.Contains(extension->id())) |
2214 terminated_extensions_.Insert(make_scoped_refptr(extension)); | 2227 terminated_extensions_.Insert(make_scoped_refptr(extension)); |
2215 | 2228 |
2216 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE); | 2229 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE); |
2217 } | 2230 } |
2218 | 2231 |
2219 void ExtensionService::UntrackTerminatedExtension(const std::string& id) { | 2232 void ExtensionService::UntrackTerminatedExtension(const std::string& id) { |
2220 std::string lowercase_id = StringToLowerASCII(id); | 2233 std::string lowercase_id = StringToLowerASCII(id); |
2221 terminated_extensions_.Remove(lowercase_id); | 2234 terminated_extensions_.Remove(lowercase_id); |
2222 } | 2235 } |
2223 | 2236 |
2224 const Extension* ExtensionService::GetTerminatedExtension( | 2237 const Extension* ExtensionService::GetTerminatedExtension( |
2225 const std::string& id) const { | 2238 const std::string& id) const { |
2226 return GetExtensionByIdInternal(id, false, false, true); | 2239 return GetExtensionByIdInternal(id, ExtensionService::INCLUDE_TERMINATED); |
2227 } | 2240 } |
2228 | 2241 |
2229 const Extension* ExtensionService::GetInstalledExtension( | 2242 const Extension* ExtensionService::GetInstalledExtension( |
2230 const std::string& id) const { | 2243 const std::string& id) const { |
2231 return GetExtensionByIdInternal(id, true, true, true); | 2244 int include_mask = ExtensionService::INCLUDE_ENABLED; |
2245 include_mask |= ExtensionService::INCLUDE_DISABLED; | |
2246 include_mask |= ExtensionService::INCLUDE_TERMINATED; | |
2247 return GetExtensionByIdInternal(id, include_mask); | |
2232 } | 2248 } |
2233 | 2249 |
2234 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { | 2250 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
2235 // Allow bindings for all packaged extensions and component hosted apps. | 2251 // Allow bindings for all packaged extensions and component hosted apps. |
2236 const Extension* extension = extensions_.GetExtensionOrAppByURL( | 2252 const Extension* extension = extensions_.GetExtensionOrAppByURL( |
2237 ExtensionURLInfo(url)); | 2253 ExtensionURLInfo(url)); |
2238 return extension && (!extension->is_hosted_app() || | 2254 return extension && (!extension->is_hosted_app() || |
2239 extension->location() == Extension::COMPONENT); | 2255 extension->location() == Extension::COMPONENT); |
2240 } | 2256 } |
2241 | 2257 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2552 | 2568 |
2553 ExtensionService::NaClModuleInfoList::iterator | 2569 ExtensionService::NaClModuleInfoList::iterator |
2554 ExtensionService::FindNaClModule(const GURL& url) { | 2570 ExtensionService::FindNaClModule(const GURL& url) { |
2555 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2571 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
2556 iter != nacl_module_list_.end(); ++iter) { | 2572 iter != nacl_module_list_.end(); ++iter) { |
2557 if (iter->url == url) | 2573 if (iter->url == url) |
2558 return iter; | 2574 return iter; |
2559 } | 2575 } |
2560 return nacl_module_list_.end(); | 2576 return nacl_module_list_.end(); |
2561 } | 2577 } |
OLD | NEW |