| 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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 ExtensionInstallUI* client = | 740 ExtensionInstallUI* client = |
| 741 (!is_pending_extension || pending_extension_info.install_silently()) ? | 741 (!is_pending_extension || pending_extension_info.install_silently()) ? |
| 742 NULL : new ExtensionInstallUI(profile_); | 742 NULL : new ExtensionInstallUI(profile_); |
| 743 | 743 |
| 744 scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(client)); | 744 scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(client)); |
| 745 installer->set_expected_id(id); | 745 installer->set_expected_id(id); |
| 746 if (is_pending_extension) | 746 if (is_pending_extension) |
| 747 installer->set_install_source(pending_extension_info.install_source()); | 747 installer->set_install_source(pending_extension_info.install_source()); |
| 748 else if (extension) | 748 else if (extension) |
| 749 installer->set_install_source(extension->location()); | 749 installer->set_install_source(extension->location()); |
| 750 if (pending_extension_info.install_silently()) |
| 751 installer->set_allow_silent_install(true); |
| 750 installer->set_delete_source(true); | 752 installer->set_delete_source(true); |
| 751 installer->set_original_url(download_url); | 753 installer->set_original_url(download_url); |
| 752 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); | 754 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
| 753 installer->InstallCrx(extension_path); | 755 installer->InstallCrx(extension_path); |
| 754 | 756 |
| 755 if (out_crx_installer) | 757 if (out_crx_installer) |
| 756 *out_crx_installer = installer; | 758 *out_crx_installer = installer; |
| 757 | 759 |
| 758 return true; | 760 return true; |
| 759 } | 761 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 | 960 |
| 959 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE); | 961 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE); |
| 960 } | 962 } |
| 961 | 963 |
| 962 void ExtensionService::GrantPermissions(const Extension* extension) { | 964 void ExtensionService::GrantPermissions(const Extension* extension) { |
| 963 CHECK(extension); | 965 CHECK(extension); |
| 964 | 966 |
| 965 // We only maintain the granted permissions prefs for INTERNAL extensions. | 967 // We only maintain the granted permissions prefs for INTERNAL extensions. |
| 966 CHECK_EQ(Extension::INTERNAL, extension->location()); | 968 CHECK_EQ(Extension::INTERNAL, extension->location()); |
| 967 | 969 |
| 968 URLPatternSet effective_hosts = extension->GetEffectiveHostPermissions(); | |
| 969 extension_prefs_->AddGrantedPermissions(extension->id(), | 970 extension_prefs_->AddGrantedPermissions(extension->id(), |
| 970 extension->HasFullPermissions(), | 971 extension->permission_set()); |
| 971 extension->api_permissions(), | |
| 972 effective_hosts); | |
| 973 } | 972 } |
| 974 | 973 |
| 975 void ExtensionService::GrantPermissionsAndEnableExtension( | 974 void ExtensionService::GrantPermissionsAndEnableExtension( |
| 976 const Extension* extension) { | 975 const Extension* extension) { |
| 977 CHECK(extension); | 976 CHECK(extension); |
| 978 RecordPermissionMessagesHistogram( | 977 RecordPermissionMessagesHistogram( |
| 979 extension, "Extensions.Permissions_ReEnable"); | 978 extension, "Extensions.Permissions_ReEnable"); |
| 980 GrantPermissions(extension); | 979 GrantPermissions(extension); |
| 981 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); | 980 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 982 EnableExtension(extension->id()); | 981 EnableExtension(extension->id()); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1201 } | 1200 } |
| 1202 | 1201 |
| 1203 // static | 1202 // static |
| 1204 void ExtensionService::RecordPermissionMessagesHistogram( | 1203 void ExtensionService::RecordPermissionMessagesHistogram( |
| 1205 const Extension* e, const char* histogram) { | 1204 const Extension* e, const char* histogram) { |
| 1206 // Since this is called from multiple sources, and since the Histogram macros | 1205 // Since this is called from multiple sources, and since the Histogram macros |
| 1207 // use statics, we need to manually lookup the Histogram ourselves. | 1206 // use statics, we need to manually lookup the Histogram ourselves. |
| 1208 base::Histogram* counter = base::LinearHistogram::FactoryGet( | 1207 base::Histogram* counter = base::LinearHistogram::FactoryGet( |
| 1209 histogram, | 1208 histogram, |
| 1210 1, | 1209 1, |
| 1211 Extension::PermissionMessage::ID_ENUM_BOUNDARY, | 1210 ExtensionPermissionMessage::kEnumBoundary, |
| 1212 Extension::PermissionMessage::ID_ENUM_BOUNDARY + 1, | 1211 ExtensionPermissionMessage::kEnumBoundary + 1, |
| 1213 base::Histogram::kUmaTargetedHistogramFlag); | 1212 base::Histogram::kUmaTargetedHistogramFlag); |
| 1214 | 1213 |
| 1215 std::vector<Extension::PermissionMessage> permissions = | 1214 ExtensionPermissionMessages permissions = e->GetPermissionMessages(); |
| 1216 e->GetPermissionMessages(); | |
| 1217 if (permissions.empty()) { | 1215 if (permissions.empty()) { |
| 1218 counter->Add(Extension::PermissionMessage::ID_NONE); | 1216 counter->Add(ExtensionPermissionMessage::kNone); |
| 1219 } else { | 1217 } else { |
| 1220 std::vector<Extension::PermissionMessage>::iterator it; | 1218 for (ExtensionPermissionMessages::iterator it = permissions.begin(); |
| 1221 for (it = permissions.begin(); it != permissions.end(); ++it) | 1219 it != permissions.end(); ++it) |
| 1222 counter->Add(it->message_id()); | 1220 counter->Add(it->id()); |
| 1223 } | 1221 } |
| 1224 } | 1222 } |
| 1225 | 1223 |
| 1226 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, | 1224 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, |
| 1227 bool write_to_prefs) { | 1225 bool write_to_prefs) { |
| 1228 std::string error; | 1226 std::string error; |
| 1229 scoped_refptr<const Extension> extension(NULL); | 1227 scoped_refptr<const Extension> extension(NULL); |
| 1230 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { | 1228 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { |
| 1231 error = errors::kDisabledByPolicy; | 1229 error = errors::kDisabledByPolicy; |
| 1232 } else if (info.extension_manifest.get()) { | 1230 } else if (info.extension_manifest.get()) { |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 // will record the permissions it recognized, not including "omnibox." | 1929 // will record the permissions it recognized, not including "omnibox." |
| 1932 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome | 1930 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 1933 // will disable the extension and prompt the user to approve the increase | 1931 // will disable the extension and prompt the user to approve the increase |
| 1934 // in privileges. The extension could then release a new version that | 1932 // in privileges. The extension could then release a new version that |
| 1935 // removes the "omnibox" permission. When the user upgrades, Chrome will | 1933 // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 1936 // still remember that "omnibox" had been granted, so that if the | 1934 // still remember that "omnibox" had been granted, so that if the |
| 1937 // extension once again includes "omnibox" in an upgrade, the extension | 1935 // extension once again includes "omnibox" in an upgrade, the extension |
| 1938 // can upgrade without requiring this user's approval. | 1936 // can upgrade without requiring this user's approval. |
| 1939 const Extension* old = GetExtensionByIdInternal(extension->id(), | 1937 const Extension* old = GetExtensionByIdInternal(extension->id(), |
| 1940 true, true, false); | 1938 true, true, false); |
| 1941 bool granted_full_access; | |
| 1942 std::set<std::string> granted_apis; | |
| 1943 URLPatternSet granted_extent; | |
| 1944 | |
| 1945 bool is_extension_upgrade = old != NULL; | 1939 bool is_extension_upgrade = old != NULL; |
| 1946 bool is_privilege_increase = false; | 1940 bool is_privilege_increase = false; |
| 1947 | 1941 |
| 1948 // We only record the granted permissions for INTERNAL extensions, since | 1942 // We only record the granted permissions for INTERNAL extensions, since |
| 1949 // they can't silently increase privileges. | 1943 // they can't silently increase privileges. |
| 1950 if (extension->location() == Extension::INTERNAL) { | 1944 if (extension->location() == Extension::INTERNAL) { |
| 1951 // Add all the recognized permissions if the granted permissions list | 1945 // Add all the recognized permissions if the granted permissions list |
| 1952 // hasn't been initialized yet. | 1946 // hasn't been initialized yet. |
| 1953 if (!extension_prefs_->GetGrantedPermissions(extension->id(), | 1947 scoped_ptr<ExtensionPermissionSet> granted_permissions( |
| 1954 &granted_full_access, | 1948 extension_prefs_->GetGrantedPermissions(extension->id())); |
| 1955 &granted_apis, | 1949 CHECK(granted_permissions.get()); |
| 1956 &granted_extent)) { | |
| 1957 GrantPermissions(extension); | |
| 1958 CHECK(extension_prefs_->GetGrantedPermissions(extension->id(), | |
| 1959 &granted_full_access, | |
| 1960 &granted_apis, | |
| 1961 &granted_extent)); | |
| 1962 } | |
| 1963 | 1950 |
| 1964 // Here, we check if an extension's privileges have increased in a manner | 1951 // Here, we check if an extension's privileges have increased in a manner |
| 1965 // that requires the user's approval. This could occur because the browser | 1952 // that requires the user's approval. This could occur because the browser |
| 1966 // upgraded and recognized additional privileges, or an extension upgrades | 1953 // upgraded and recognized additional privileges, or an extension upgrades |
| 1967 // to a version that requires additional privileges. | 1954 // to a version that requires additional privileges. |
| 1968 is_privilege_increase = Extension::IsPrivilegeIncrease( | 1955 is_privilege_increase = |
| 1969 granted_full_access, granted_apis, granted_extent, extension); | 1956 granted_permissions->HasLessPrivilegesThan(extension->permission_set()); |
| 1970 } | 1957 } |
| 1971 | 1958 |
| 1972 if (is_extension_upgrade) { | 1959 if (is_extension_upgrade) { |
| 1973 // Other than for unpacked extensions, CrxInstaller should have guaranteed | 1960 // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 1974 // that we aren't downgrading. | 1961 // that we aren't downgrading. |
| 1975 if (extension->location() != Extension::LOAD) | 1962 if (extension->location() != Extension::LOAD) |
| 1976 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); | 1963 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
| 1977 | 1964 |
| 1978 // Extensions get upgraded if the privileges are allowed to increase or | 1965 // Extensions get upgraded if the privileges are allowed to increase or |
| 1979 // the privileges haven't increased. | 1966 // the privileges haven't increased. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2016 // first. | 2003 // first. |
| 2017 if (show_extensions_prompts_ && | 2004 if (show_extensions_prompts_ && |
| 2018 !extension->plugins().empty() && | 2005 !extension->plugins().empty() && |
| 2019 disabled_extension_paths_.find(extension->id()) == | 2006 disabled_extension_paths_.find(extension->id()) == |
| 2020 disabled_extension_paths_.end()) { | 2007 disabled_extension_paths_.end()) { |
| 2021 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( | 2008 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( |
| 2022 profile_, weak_ptr_factory_.GetWeakPtr(), extension); | 2009 profile_, weak_ptr_factory_.GetWeakPtr(), extension); |
| 2023 prompt->ShowPrompt(); | 2010 prompt->ShowPrompt(); |
| 2024 return; // continues in SimpleExtensionLoadPrompt::InstallUI* | 2011 return; // continues in SimpleExtensionLoadPrompt::InstallUI* |
| 2025 } | 2012 } |
| 2026 | |
| 2027 OnExtensionInstalled(extension); | 2013 OnExtensionInstalled(extension); |
| 2028 } | 2014 } |
| 2029 | 2015 |
| 2030 void ExtensionService::OnExtensionInstalled(const Extension* extension) { | 2016 void ExtensionService::OnExtensionInstalled(const Extension* extension) { |
| 2031 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2017 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2032 | 2018 |
| 2033 // Ensure extension is deleted unless we transfer ownership. | 2019 // Ensure extension is deleted unless we transfer ownership. |
| 2034 scoped_refptr<const Extension> scoped_extension(extension); | 2020 scoped_refptr<const Extension> scoped_extension(extension); |
| 2035 const std::string& id = extension->id(); | 2021 const std::string& id = extension->id(); |
| 2036 bool initial_enable = IsExtensionEnabled(id); | 2022 bool initial_enable = IsExtensionEnabled(id); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 | 2416 |
| 2431 ExtensionService::NaClModuleInfoList::iterator | 2417 ExtensionService::NaClModuleInfoList::iterator |
| 2432 ExtensionService::FindNaClModule(const GURL& url) { | 2418 ExtensionService::FindNaClModule(const GURL& url) { |
| 2433 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2419 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2434 iter != nacl_module_list_.end(); ++iter) { | 2420 iter != nacl_module_list_.end(); ++iter) { |
| 2435 if (iter->url == url) | 2421 if (iter->url == url) |
| 2436 return iter; | 2422 return iter; |
| 2437 } | 2423 } |
| 2438 return nacl_module_list_.end(); | 2424 return nacl_module_list_.end(); |
| 2439 } | 2425 } |
| OLD | NEW |