Chromium Code Reviews| 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 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 714 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 715 host->render_view_host()); | 715 host->render_view_host()); |
| 716 int devtools_cookie = | 716 int devtools_cookie = |
| 717 content::DevToolsManager::GetInstance()->DetachClientHost(agent); | 717 content::DevToolsManager::GetInstance()->DetachClientHost(agent); |
| 718 if (devtools_cookie >= 0) | 718 if (devtools_cookie >= 0) |
| 719 orphaned_dev_tools_[extension_id] = devtools_cookie; | 719 orphaned_dev_tools_[extension_id] = devtools_cookie; |
| 720 } | 720 } |
| 721 | 721 |
| 722 path = current_extension->path(); | 722 path = current_extension->path(); |
| 723 DisableExtension(extension_id); | 723 DisableExtension(extension_id); |
| 724 extension_prefs_->SetDisableReason(extension_id, | |
| 725 ExtensionPrefs::DISABLE_RELOAD); | |
| 724 disabled_extension_paths_[extension_id] = path; | 726 disabled_extension_paths_[extension_id] = path; |
| 725 } else { | 727 } else { |
| 726 path = unloaded_extension_paths_[extension_id]; | 728 path = unloaded_extension_paths_[extension_id]; |
| 727 } | 729 } |
| 728 | 730 |
| 729 // If we're reloading a component extension, use the component extension | 731 // If we're reloading a component extension, use the component extension |
| 730 // loader's reloader. | 732 // loader's reloader. |
| 731 if (component_loader_->Exists(extension_id)) { | 733 if (component_loader_->Exists(extension_id)) { |
| 732 component_loader_->Reload(extension_id); | 734 component_loader_->Reload(extension_id); |
| 733 return; | 735 return; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 891 return extension_prefs_->IsExternalExtensionUninstalled(extension_id); | 893 return extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
| 892 } | 894 } |
| 893 | 895 |
| 894 void ExtensionService::EnableExtension(const std::string& extension_id) { | 896 void ExtensionService::EnableExtension(const std::string& extension_id) { |
| 895 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 897 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 896 | 898 |
| 897 if (IsExtensionEnabled(extension_id)) | 899 if (IsExtensionEnabled(extension_id)) |
| 898 return; | 900 return; |
| 899 | 901 |
| 900 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); | 902 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
| 903 extension_prefs_->SetDisableReason(extension_id, | |
| 904 ExtensionPrefs::DISABLE_UNKNOWN); | |
| 901 | 905 |
| 902 const Extension* extension = | 906 const Extension* extension = |
| 903 GetExtensionByIdInternal(extension_id, false, true, false); | 907 GetExtensionByIdInternal(extension_id, false, true, false); |
| 904 // This can happen if sync enables an extension that is not | 908 // This can happen if sync enables an extension that is not |
| 905 // installed yet. | 909 // installed yet. |
| 906 if (!extension) | 910 if (!extension) |
| 907 return; | 911 return; |
| 908 | 912 |
| 909 // Move it over to the enabled list. | 913 // Move it over to the enabled list. |
| 910 extensions_.Insert(make_scoped_refptr(extension)); | 914 extensions_.Insert(make_scoped_refptr(extension)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 925 if (!IsExtensionEnabled(extension_id)) | 929 if (!IsExtensionEnabled(extension_id)) |
| 926 return; | 930 return; |
| 927 | 931 |
| 928 const Extension* extension = GetInstalledExtension(extension_id); | 932 const Extension* extension = GetInstalledExtension(extension_id); |
| 929 // |extension| can be NULL if sync disables an extension that is not | 933 // |extension| can be NULL if sync disables an extension that is not |
| 930 // installed yet. | 934 // installed yet. |
| 931 if (extension && !Extension::UserMayDisable(extension->location())) | 935 if (extension && !Extension::UserMayDisable(extension->location())) |
| 932 return; | 936 return; |
| 933 | 937 |
| 934 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 938 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
| 939 extension_prefs_->SetDisableReason(extension_id, | |
| 940 ExtensionPrefs::DISABLE_USER_ACTION); | |
|
Aaron Boodman
2012/04/09 20:30:48
I am not sure this is always a good assumption. Co
Yoyo Zhou
2012/04/10 01:57:36
No, it's probably not, since it's used in RELOAD f
| |
| 935 | 941 |
| 936 extension = GetExtensionByIdInternal(extension_id, true, false, true); | 942 extension = GetExtensionByIdInternal(extension_id, true, false, true); |
| 937 if (!extension) | 943 if (!extension) |
| 938 return; | 944 return; |
| 939 | 945 |
| 940 // Move it over to the disabled list. | 946 // Move it over to the disabled list. |
| 941 disabled_extensions_.Insert(make_scoped_refptr(extension)); | 947 disabled_extensions_.Insert(make_scoped_refptr(extension)); |
| 942 if (extensions_.Contains(extension->id())) | 948 if (extensions_.Contains(extension->id())) |
| 943 extensions_.Remove(extension->id()); | 949 extensions_.Remove(extension->id()); |
| 944 else | 950 else |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2028 EnableExtension(extension->id()); | 2034 EnableExtension(extension->id()); |
| 2029 | 2035 |
| 2030 // Check if the extension's privileges have changed and disable the | 2036 // Check if the extension's privileges have changed and disable the |
| 2031 // extension if necessary. | 2037 // extension if necessary. |
| 2032 InitializePermissions(extension); | 2038 InitializePermissions(extension); |
| 2033 | 2039 |
| 2034 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); | 2040 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); |
| 2035 if (disabled) { | 2041 if (disabled) { |
| 2036 disabled_extensions_.Insert(scoped_extension); | 2042 disabled_extensions_.Insert(scoped_extension); |
| 2037 SyncExtensionChangeIfNeeded(*extension); | 2043 SyncExtensionChangeIfNeeded(*extension); |
| 2044 content::NotificationService::current()->Notify( | |
| 2045 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | |
| 2046 content::Source<Profile>(profile_), | |
| 2047 content::Details<const Extension>(extension)); | |
| 2038 | 2048 |
| 2039 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 2049 if (extension_prefs_->GetDisableReason(extension->id()) == |
| 2040 content::NotificationService::current()->Notify( | 2050 ExtensionPrefs::DISABLE_PERMISSIONS_INCREASE) { |
| 2041 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | |
| 2042 content::Source<Profile>(profile_), | |
| 2043 content::Details<const Extension>(extension)); | |
| 2044 extensions::AddExtensionDisabledError(this, extension); | 2051 extensions::AddExtensionDisabledError(this, extension); |
| 2045 } | 2052 } |
| 2046 // Although the extension is disabled, we technically did succeed in adding | 2053 // Although the extension is disabled, we technically did succeed in adding |
| 2047 // it to the list of installed extensions. | 2054 // it to the list of installed extensions. |
| 2048 return true; | 2055 return true; |
| 2049 } | 2056 } |
| 2050 | 2057 |
| 2051 // All apps that are displayed in the launcher are ordered by their ordinals | 2058 // All apps that are displayed in the launcher are ordered by their ordinals |
| 2052 // so we must ensure they have valid ordinals. | 2059 // so we must ensure they have valid ordinals. |
| 2053 if (extension->ShouldDisplayInLauncher()) | 2060 if (extension->ShouldDisplayInLauncher()) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2108 // will disable the extension and prompt the user to approve the increase | 2115 // will disable the extension and prompt the user to approve the increase |
| 2109 // in privileges. The extension could then release a new version that | 2116 // in privileges. The extension could then release a new version that |
| 2110 // removes the "omnibox" permission. When the user upgrades, Chrome will | 2117 // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 2111 // still remember that "omnibox" had been granted, so that if the | 2118 // still remember that "omnibox" had been granted, so that if the |
| 2112 // extension once again includes "omnibox" in an upgrade, the extension | 2119 // extension once again includes "omnibox" in an upgrade, the extension |
| 2113 // can upgrade without requiring this user's approval. | 2120 // can upgrade without requiring this user's approval. |
| 2114 const Extension* old = GetExtensionByIdInternal(extension->id(), | 2121 const Extension* old = GetExtensionByIdInternal(extension->id(), |
| 2115 true, true, false); | 2122 true, true, false); |
| 2116 bool is_extension_upgrade = old != NULL; | 2123 bool is_extension_upgrade = old != NULL; |
| 2117 bool is_privilege_increase = false; | 2124 bool is_privilege_increase = false; |
| 2125 bool previously_disabled = false; | |
| 2126 ExtensionPrefs::DisableReason disable_reason = | |
| 2127 extension_prefs_->GetDisableReason(extension->id()); | |
| 2118 | 2128 |
| 2119 // We only need to compare the granted permissions to the current permissions | 2129 // We only need to compare the granted permissions to the current permissions |
| 2120 // if the extension is not allowed to silently increase its permissions. | 2130 // if the extension is not allowed to silently increase its permissions. |
| 2121 if (!extension->CanSilentlyIncreasePermissions()) { | 2131 if (!extension->CanSilentlyIncreasePermissions()) { |
| 2122 // Add all the recognized permissions if the granted permissions list | 2132 // Add all the recognized permissions if the granted permissions list |
| 2123 // hasn't been initialized yet. | 2133 // hasn't been initialized yet. |
| 2124 scoped_refptr<ExtensionPermissionSet> granted_permissions = | 2134 scoped_refptr<ExtensionPermissionSet> granted_permissions = |
| 2125 extension_prefs_->GetGrantedPermissions(extension->id()); | 2135 extension_prefs_->GetGrantedPermissions(extension->id()); |
| 2126 CHECK(granted_permissions.get()); | 2136 CHECK(granted_permissions.get()); |
| 2127 | 2137 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2140 if (extension->location() != Extension::LOAD) | 2150 if (extension->location() != Extension::LOAD) |
| 2141 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); | 2151 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
| 2142 | 2152 |
| 2143 // Extensions get upgraded if the privileges are allowed to increase or | 2153 // Extensions get upgraded if the privileges are allowed to increase or |
| 2144 // the privileges haven't increased. | 2154 // the privileges haven't increased. |
| 2145 if (!is_privilege_increase) { | 2155 if (!is_privilege_increase) { |
| 2146 SetBeingUpgraded(old, true); | 2156 SetBeingUpgraded(old, true); |
| 2147 SetBeingUpgraded(extension, true); | 2157 SetBeingUpgraded(extension, true); |
| 2148 } | 2158 } |
| 2149 | 2159 |
| 2160 // If the extension was already disabled, suppress any alerts for becoming | |
| 2161 // disabled on permissions increase. | |
| 2162 previously_disabled = extension_prefs_->IsExtensionDisabled(old->id()); | |
| 2163 if (previously_disabled) { | |
| 2164 ExtensionPrefs::DisableReason reason = extension_prefs_->GetDisableReason( | |
| 2165 old->id()); | |
| 2166 if (reason == ExtensionPrefs::DISABLE_UNKNOWN) { | |
| 2167 // Initialize the reason for legacy disabled extensions from whether the | |
| 2168 // extension already exceeded granted permissions. | |
| 2169 if (extension_prefs_->DidExtensionEscalatePermissions(old->id())) | |
| 2170 disable_reason = ExtensionPrefs::DISABLE_PERMISSIONS_INCREASE; | |
| 2171 else | |
| 2172 disable_reason = ExtensionPrefs::DISABLE_USER_ACTION; | |
| 2173 } | |
| 2174 } else { | |
| 2175 disable_reason = ExtensionPrefs::DISABLE_PERMISSIONS_INCREASE; | |
| 2176 } | |
| 2177 | |
| 2150 // To upgrade an extension in place, unload the old one and | 2178 // To upgrade an extension in place, unload the old one and |
| 2151 // then load the new one. | 2179 // then load the new one. |
| 2152 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE); | 2180 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE); |
| 2153 old = NULL; | 2181 old = NULL; |
| 2154 } | 2182 } |
| 2155 | 2183 |
| 2156 // Extension has changed permissions significantly. Disable it. A | 2184 // Extension has changed permissions significantly. Disable it. A |
| 2157 // notification should be sent by the caller. | 2185 // notification should be sent by the caller. |
| 2158 if (is_privilege_increase) { | 2186 if (is_privilege_increase) { |
| 2159 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 2187 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
| 2160 RecordPermissionMessagesHistogram( | 2188 RecordPermissionMessagesHistogram( |
| 2161 extension, "Extensions.Permissions_AutoDisable"); | 2189 extension, "Extensions.Permissions_AutoDisable"); |
| 2162 } | 2190 } |
| 2163 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); | 2191 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
| 2164 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); | 2192 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 2193 extension_prefs_->SetDisableReason(extension->id(), disable_reason); | |
| 2165 } | 2194 } |
| 2166 } | 2195 } |
| 2167 | 2196 |
| 2168 void ExtensionService::UpdateActiveExtensionsInCrashReporter() { | 2197 void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
| 2169 std::set<std::string> extension_ids; | 2198 std::set<std::string> extension_ids; |
| 2170 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 2199 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 2171 iter != extensions_.end(); ++iter) { | 2200 iter != extensions_.end(); ++iter) { |
| 2172 const Extension* extension = *iter; | 2201 const Extension* extension = *iter; |
| 2173 if (!extension->is_theme() && extension->location() != Extension::COMPONENT) | 2202 if (!extension->is_theme() && extension->location() != Extension::COMPONENT) |
| 2174 extension_ids.insert(extension->id()); | 2203 extension_ids.insert(extension->id()); |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2639 // To coexist with certain unit tests that don't have an IO thread message | 2668 // To coexist with certain unit tests that don't have an IO thread message |
| 2640 // loop available at ExtensionService shutdown, we lazy-initialize this | 2669 // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2641 // object so that those cases neither create nor destroy an | 2670 // object so that those cases neither create nor destroy an |
| 2642 // APIResourceController. | 2671 // APIResourceController. |
| 2643 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2672 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2644 if (!api_resource_controller_) { | 2673 if (!api_resource_controller_) { |
| 2645 api_resource_controller_ = new extensions::APIResourceController(); | 2674 api_resource_controller_ = new extensions::APIResourceController(); |
| 2646 } | 2675 } |
| 2647 return api_resource_controller_; | 2676 return api_resource_controller_; |
| 2648 } | 2677 } |
| OLD | NEW |