Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <iterator> | 8 #include <iterator> | 
| 9 #include <set> | 9 #include <set> | 
| 10 | 10 | 
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { | 721 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { | 
| 722 // Look for an open inspector for the background page. | 722 // Look for an open inspector for the background page. | 
| 723 std::string devtools_cookie = DevToolsAgentHost::DisconnectRenderViewHost( | 723 std::string devtools_cookie = DevToolsAgentHost::DisconnectRenderViewHost( | 
| 724 host->render_view_host()); | 724 host->render_view_host()); | 
| 725 if (devtools_cookie != std::string()) | 725 if (devtools_cookie != std::string()) | 
| 726 orphaned_dev_tools_[extension_id] = devtools_cookie; | 726 orphaned_dev_tools_[extension_id] = devtools_cookie; | 
| 727 } | 727 } | 
| 728 | 728 | 
| 729 path = current_extension->path(); | 729 path = current_extension->path(); | 
| 730 DisableExtension(extension_id, Extension::DISABLE_RELOAD); | 730 DisableExtension(extension_id, Extension::DISABLE_RELOAD); | 
| 731 disabled_extension_paths_[extension_id] = path; | 731 reloading_extensions_.insert(extension_id); | 
| 732 } else { | 732 } else { | 
| 733 path = unloaded_extension_paths_[extension_id]; | 733 path = unloaded_extension_paths_[extension_id]; | 
| 734 } | 734 } | 
| 735 | 735 | 
| 736 on_load_events_[extension_id] = events; | 736 on_load_events_[extension_id] = events; | 
| 737 if (events & EVENT_RESTARTED) { | 737 if (events & EVENT_RESTARTED) { | 
| 738 extension_prefs_->GetSavedFileEntries( | 738 extension_prefs_->GetSavedFileEntries( | 
| 739 extension_id, &on_restart_file_entries_[extension_id]); | 739 extension_id, &on_restart_file_entries_[extension_id]); | 
| 740 } | 740 } | 
| 741 | 741 | 
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1515 // Honor user choice and skip installation/enabling. | 1515 // Honor user choice and skip installation/enabling. | 
| 1516 if (IsExternalExtensionUninstalled(id)) { | 1516 if (IsExternalExtensionUninstalled(id)) { | 
| 1517 LOG(WARNING) << "Extension with id " << id | 1517 LOG(WARNING) << "Extension with id " << id | 
| 1518 << " from sync was uninstalled as external extension"; | 1518 << " from sync was uninstalled as external extension"; | 
| 1519 return true; | 1519 return true; | 
| 1520 } | 1520 } | 
| 1521 | 1521 | 
| 1522 // Set user settings. | 1522 // Set user settings. | 
| 1523 // If the extension has been disabled from sync, it may not have | 1523 // If the extension has been disabled from sync, it may not have | 
| 1524 // been installed yet, so we don't know if the disable reason was a | 1524 // been installed yet, so we don't know if the disable reason was a | 
| 1525 // permissions increase. That will be updated once InitializePermissions | 1525 // permissions increase. That will be updated once CheckPermissionsIncrease | 
| 1526 // is called for it. | 1526 // is called for it. | 
| 1527 if (extension_sync_data.enabled()) | 1527 if (extension_sync_data.enabled()) | 
| 1528 EnableExtension(id); | 1528 EnableExtension(id); | 
| 1529 else | 1529 else | 
| 1530 DisableExtension(id, Extension::DISABLE_UNKNOWN_FROM_SYNC); | 1530 DisableExtension(id, Extension::DISABLE_UNKNOWN_FROM_SYNC); | 
| 1531 | 1531 | 
| 1532 // We need to cache some version information here because setting the | 1532 // We need to cache some version information here because setting the | 
| 1533 // incognito flag invalidates the |extension| pointer (it reloads the | 1533 // incognito flag invalidates the |extension| pointer (it reloads the | 
| 1534 // extension). | 1534 // extension). | 
| 1535 bool extension_installed = (extension != NULL); | 1535 bool extension_installed = (extension != NULL); | 
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1899 // clean up its RequestContexts. | 1899 // clean up its RequestContexts. | 
| 1900 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1900 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 
| 1901 return; | 1901 return; | 
| 1902 } | 1902 } | 
| 1903 | 1903 | 
| 1904 // Keep information about the extension so that we can reload it later | 1904 // Keep information about the extension so that we can reload it later | 
| 1905 // even if it's not permanently installed. | 1905 // even if it's not permanently installed. | 
| 1906 unloaded_extension_paths_[extension->id()] = extension->path(); | 1906 unloaded_extension_paths_[extension->id()] = extension->path(); | 
| 1907 | 1907 | 
| 1908 // Clean up if the extension is meant to be enabled after a reload. | 1908 // Clean up if the extension is meant to be enabled after a reload. | 
| 1909 disabled_extension_paths_.erase(extension->id()); | 1909 reloading_extensions_.erase(extension->id()); | 
| 1910 | 1910 | 
| 1911 // Clean up runtime data. | 1911 // Clean up runtime data. | 
| 1912 extension_runtime_data_.erase(extension_id); | 1912 extension_runtime_data_.erase(extension_id); | 
| 1913 | 1913 | 
| 1914 if (disabled_extensions_.Contains(extension->id())) { | 1914 if (disabled_extensions_.Contains(extension->id())) { | 
| 1915 UnloadedExtensionInfo details(extension, reason); | 1915 UnloadedExtensionInfo details(extension, reason); | 
| 1916 details.already_disabled = true; | 1916 details.already_disabled = true; | 
| 1917 disabled_extensions_.Remove(extension->id()); | 1917 disabled_extensions_.Remove(extension->id()); | 
| 1918 content::NotificationService::current()->Notify( | 1918 content::NotificationService::current()->Notify( | 
| 1919 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 1919 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2027 // TODO(jstritar): We may be able to get rid of this branch by overriding the | 2027 // TODO(jstritar): We may be able to get rid of this branch by overriding the | 
| 2028 // default extension state to DISABLED when the --disable-extensions flag | 2028 // default extension state to DISABLED when the --disable-extensions flag | 
| 2029 // is set (http://crbug.com/29067). | 2029 // is set (http://crbug.com/29067). | 
| 2030 if (!extensions_enabled() && | 2030 if (!extensions_enabled() && | 
| 2031 !extension->is_theme() && | 2031 !extension->is_theme() && | 
| 2032 extension->location() != Manifest::COMPONENT && | 2032 extension->location() != Manifest::COMPONENT && | 
| 2033 !Manifest::IsExternalLocation(extension->location())) { | 2033 !Manifest::IsExternalLocation(extension->location())) { | 
| 2034 return; | 2034 return; | 
| 2035 } | 2035 } | 
| 2036 | 2036 | 
| 2037 SetBeingUpgraded(extension, false); | 2037 bool is_extension_upgrade = false; | 
| 2038 if (const Extension* old = GetInstalledExtension(extension->id())) { | |
| 2039 is_extension_upgrade = true; | |
| 2040 DCHECK_NE(extension, old); | |
| 2041 // Other than for unpacked extensions, CrxInstaller should have guaranteed | |
| 2042 // that we aren't downgrading. | |
| 2043 if (!Manifest::IsUnpackedLocation(extension->location())) | |
| 2044 CHECK_GE(extension->version()->CompareTo(*(old->version())), 0); | |
| 2045 } | |
| 2046 SetBeingUpgraded(extension, is_extension_upgrade); | |
| 2038 | 2047 | 
| 2039 // The extension is now loaded, remove its data from unloaded extension map. | 2048 // The extension is now loaded, remove its data from unloaded extension map. | 
| 2040 unloaded_extension_paths_.erase(extension->id()); | 2049 unloaded_extension_paths_.erase(extension->id()); | 
| 2041 | 2050 | 
| 2042 // If a terminated extension is loaded, remove it from the terminated list. | 2051 // If a terminated extension is loaded, remove it from the terminated list. | 
| 2043 UntrackTerminatedExtension(extension->id()); | 2052 UntrackTerminatedExtension(extension->id()); | 
| 2044 | 2053 | 
| 2045 // If the extension was disabled for a reload, then enable it. | 2054 // If the extension was disabled for a reload, then enable it. | 
| 2046 if (disabled_extension_paths_.erase(extension->id()) > 0) | 2055 if (reloading_extensions_.erase(extension->id()) > 0) | 
| 2047 EnableExtension(extension->id()); | 2056 EnableExtension(extension->id()); | 
| 
 
Jeffrey Yasskin
2013/04/25 01:53:37
This Enable followed by Unload can cause an extra
 
Matt Perry
2013/04/25 19:03:46
Do you mean the Unload on line 2065? Can you just
 
Jeffrey Yasskin
2013/04/25 19:12:28
Not immediately, that breaks tests. :) I'm figurin
 
 | |
| 2048 | 2057 | 
| 2049 // Check if the extension's privileges have changed and disable the | 2058 // Check if the extension's privileges have changed and mark the | 
| 2050 // extension if necessary. | 2059 // extension disabled if necessary. | 
| 2051 InitializePermissions(extension); | 2060 CheckPermissionsIncrease(extension, is_extension_upgrade); | 
| 2061 | |
| 2062 if (is_extension_upgrade) { | |
| 2063 // To upgrade an extension in place, unload the old one and | |
| 2064 // then load the new one. | |
| 2065 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_UPDATE); | |
| 2066 } | |
| 2052 | 2067 | 
| 2053 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { | 2068 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { | 
| 2054 // Only prefs is checked for the blacklist. We rely on callers to check the | 2069 // Only prefs is checked for the blacklist. We rely on callers to check the | 
| 2055 // blacklist before calling into here, e.g. CrxInstaller checks before | 2070 // blacklist before calling into here, e.g. CrxInstaller checks before | 
| 2056 // installation, we check when loading installed extensions. | 2071 // installation, we check when loading installed extensions. | 
| 2057 blacklisted_extensions_.Insert(extension); | 2072 blacklisted_extensions_.Insert(extension); | 
| 2058 } else if (extension_prefs_->IsExtensionDisabled(extension->id())) { | 2073 } else if (extension_prefs_->IsExtensionDisabled(extension->id())) { | 
| 2059 disabled_extensions_.Insert(extension); | 2074 disabled_extensions_.Insert(extension); | 
| 2060 SyncExtensionChangeIfNeeded(*extension); | 2075 SyncExtensionChangeIfNeeded(*extension); | 
| 2061 content::NotificationService::current()->Notify( | 2076 content::NotificationService::current()->Notify( | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2079 } | 2094 } | 
| 2080 extension_prefs_->extension_sorting()->EnsureValidOrdinals( | 2095 extension_prefs_->extension_sorting()->EnsureValidOrdinals( | 
| 2081 extension->id(), syncer::StringOrdinal()); | 2096 extension->id(), syncer::StringOrdinal()); | 
| 2082 } | 2097 } | 
| 2083 | 2098 | 
| 2084 extensions_.Insert(extension); | 2099 extensions_.Insert(extension); | 
| 2085 SyncExtensionChangeIfNeeded(*extension); | 2100 SyncExtensionChangeIfNeeded(*extension); | 
| 2086 NotifyExtensionLoaded(extension); | 2101 NotifyExtensionLoaded(extension); | 
| 2087 DoPostLoadTasks(extension); | 2102 DoPostLoadTasks(extension); | 
| 2088 } | 2103 } | 
| 2104 SetBeingUpgraded(extension, false); | |
| 
 
Jeffrey Yasskin
2013/04/25 01:53:37
This should be late enough to cover the uses insid
 
 | |
| 2089 } | 2105 } | 
| 2090 | 2106 | 
| 2091 void ExtensionService::AddComponentExtension(const Extension* extension) { | 2107 void ExtensionService::AddComponentExtension(const Extension* extension) { | 
| 2092 const std::string old_version_string( | 2108 const std::string old_version_string( | 
| 2093 extension_prefs_->GetVersionString(extension->id())); | 2109 extension_prefs_->GetVersionString(extension->id())); | 
| 2094 const Version old_version(old_version_string); | 2110 const Version old_version(old_version_string); | 
| 2095 | 2111 | 
| 2096 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | 2112 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | 
| 2097 VLOG(1) << "Component extension " << extension->name() << " (" | 2113 VLOG(1) << "Component extension " << extension->name() << " (" | 
| 2098 << extension->id() << ") installing/upgrading from '" | 2114 << extension->id() << ") installing/upgrading from '" | 
| 2099 << old_version_string << "' to " << extension->version()->GetString(); | 2115 << old_version_string << "' to " << extension->version()->GetString(); | 
| 2100 | 2116 | 
| 2101 AddNewOrUpdatedExtension(extension, | 2117 AddNewOrUpdatedExtension(extension, | 
| 2102 Extension::ENABLED_COMPONENT, | 2118 Extension::ENABLED_COMPONENT, | 
| 2103 syncer::StringOrdinal()); | 2119 syncer::StringOrdinal()); | 
| 2104 return; | 2120 return; | 
| 2105 } | 2121 } | 
| 2106 | 2122 | 
| 2107 AddExtension(extension); | 2123 AddExtension(extension); | 
| 2108 } | 2124 } | 
| 2109 | 2125 | 
| 2110 void ExtensionService::InitializePermissions(const Extension* extension) { | 2126 void ExtensionService::UpdateActivePermissions(const Extension* extension) { | 
| 2111 // If the extension has used the optional permissions API, it will have a | 2127 // If the extension has used the optional permissions API, it will have a | 
| 2112 // custom set of active permissions defined in the extension prefs. Here, | 2128 // custom set of active permissions defined in the extension prefs. Here, | 
| 2113 // we update the extension's active permissions based on the prefs. | 2129 // we update the extension's active permissions based on the prefs. | 
| 2114 scoped_refptr<PermissionSet> active_permissions = | 2130 scoped_refptr<PermissionSet> active_permissions = | 
| 2115 extension_prefs()->GetActivePermissions(extension->id()); | 2131 extension_prefs()->GetActivePermissions(extension->id()); | 
| 2116 | 2132 | 
| 2117 if (active_permissions) { | 2133 if (active_permissions) { | 
| 2118 // We restrict the active permissions to be within the bounds defined in the | 2134 // We restrict the active permissions to be within the bounds defined in the | 
| 2119 // extension's manifest. | 2135 // extension's manifest. | 
| 2120 // a) active permissions must be a subset of optional + default permissions | 2136 // a) active permissions must be a subset of optional + default permissions | 
| 2121 // b) active permissions must contains all default permissions | 2137 // b) active permissions must contains all default permissions | 
| 2122 scoped_refptr<PermissionSet> total_permissions = | 2138 scoped_refptr<PermissionSet> total_permissions = | 
| 2123 PermissionSet::CreateUnion( | 2139 PermissionSet::CreateUnion( | 
| 2124 extension->required_permission_set(), | 2140 extension->required_permission_set(), | 
| 2125 extension->optional_permission_set()); | 2141 extension->optional_permission_set()); | 
| 2126 | 2142 | 
| 2127 // Make sure the active permissions contain no more than optional + default. | 2143 // Make sure the active permissions contain no more than optional + default. | 
| 2128 scoped_refptr<PermissionSet> adjusted_active = | 2144 scoped_refptr<PermissionSet> adjusted_active = | 
| 2129 PermissionSet::CreateIntersection( | 2145 PermissionSet::CreateIntersection( | 
| 2130 total_permissions.get(), active_permissions.get()); | 2146 total_permissions.get(), active_permissions.get()); | 
| 2131 | 2147 | 
| 2132 // Make sure the active permissions contain the default permissions. | 2148 // Make sure the active permissions contain the default permissions. | 
| 2133 adjusted_active = PermissionSet::CreateUnion( | 2149 adjusted_active = PermissionSet::CreateUnion( | 
| 2134 extension->required_permission_set(), adjusted_active.get()); | 2150 extension->required_permission_set(), adjusted_active.get()); | 
| 2135 | 2151 | 
| 2136 extensions::PermissionsUpdater perms_updater(profile()); | 2152 extensions::PermissionsUpdater perms_updater(profile()); | 
| 2137 perms_updater.UpdateActivePermissions(extension, adjusted_active); | 2153 perms_updater.UpdateActivePermissions(extension, adjusted_active); | 
| 2138 } | 2154 } | 
| 2155 } | |
| 2156 | |
| 2157 void ExtensionService::CheckPermissionsIncrease(const Extension* extension, | |
| 2158 bool is_extension_upgrade) { | |
| 2159 UpdateActivePermissions(extension); | |
| 2139 | 2160 | 
| 2140 // We keep track of all permissions the user has granted each extension. | 2161 // We keep track of all permissions the user has granted each extension. | 
| 2141 // This allows extensions to gracefully support backwards compatibility | 2162 // This allows extensions to gracefully support backwards compatibility | 
| 2142 // by including unknown permissions in their manifests. When the user | 2163 // by including unknown permissions in their manifests. When the user | 
| 2143 // installs the extension, only the recognized permissions are recorded. | 2164 // installs the extension, only the recognized permissions are recorded. | 
| 2144 // When the unknown permissions become recognized (e.g., through browser | 2165 // When the unknown permissions become recognized (e.g., through browser | 
| 2145 // upgrade), we can prompt the user to accept these new permissions. | 2166 // upgrade), we can prompt the user to accept these new permissions. | 
| 2146 // Extensions can also silently upgrade to less permissions, and then | 2167 // Extensions can also silently upgrade to less permissions, and then | 
| 2147 // silently upgrade to a version that adds these permissions back. | 2168 // silently upgrade to a version that adds these permissions back. | 
| 2148 // | 2169 // | 
| 2149 // For example, pretend that Chrome 10 includes a permission "omnibox" | 2170 // For example, pretend that Chrome 10 includes a permission "omnibox" | 
| 2150 // for an API that adds suggestions to the omnibox. An extension can | 2171 // for an API that adds suggestions to the omnibox. An extension can | 
| 2151 // maintain backwards compatibility while still having "omnibox" in the | 2172 // maintain backwards compatibility while still having "omnibox" in the | 
| 2152 // manifest. If a user installs the extension on Chrome 9, the browser | 2173 // manifest. If a user installs the extension on Chrome 9, the browser | 
| 2153 // will record the permissions it recognized, not including "omnibox." | 2174 // will record the permissions it recognized, not including "omnibox." | 
| 2154 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome | 2175 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome | 
| 2155 // will disable the extension and prompt the user to approve the increase | 2176 // will disable the extension and prompt the user to approve the increase | 
| 2156 // in privileges. The extension could then release a new version that | 2177 // in privileges. The extension could then release a new version that | 
| 2157 // removes the "omnibox" permission. When the user upgrades, Chrome will | 2178 // removes the "omnibox" permission. When the user upgrades, Chrome will | 
| 2158 // still remember that "omnibox" had been granted, so that if the | 2179 // still remember that "omnibox" had been granted, so that if the | 
| 2159 // extension once again includes "omnibox" in an upgrade, the extension | 2180 // extension once again includes "omnibox" in an upgrade, the extension | 
| 2160 // can upgrade without requiring this user's approval. | 2181 // can upgrade without requiring this user's approval. | 
| 2161 const Extension* old = GetInstalledExtension(extension->id()); | |
| 2162 bool is_extension_upgrade = old != NULL; | |
| 2163 bool is_privilege_increase = false; | |
| 2164 bool previously_disabled = false; | |
| 2165 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); | 2182 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); | 
| 2166 | 2183 | 
| 2184 bool is_default_app_install = | |
| 2185 (!is_extension_upgrade && extension->was_installed_by_default()); | |
| 2186 // Silently grant all active permissions to default apps only on install. | |
| 2187 // After install they should behave like other apps. | |
| 2188 if (is_default_app_install) | |
| 2189 GrantPermissions(extension); | |
| 2190 | |
| 2191 bool is_privilege_increase = false; | |
| 2167 // We only need to compare the granted permissions to the current permissions | 2192 // We only need to compare the granted permissions to the current permissions | 
| 2168 // if the extension is not allowed to silently increase its permissions. | 2193 // if the extension is not allowed to silently increase its permissions. | 
| 2169 bool is_default_app_install = | 2194 if (!(extension->CanSilentlyIncreasePermissions() || | 
| 2170 (!is_extension_upgrade && extension->was_installed_by_default()); | 2195 is_default_app_install)) { | 
| 2171 if (!(extension->CanSilentlyIncreasePermissions() | |
| 2172 || is_default_app_install)) { | |
| 2173 // Add all the recognized permissions if the granted permissions list | 2196 // Add all the recognized permissions if the granted permissions list | 
| 
 
Jeffrey Yasskin
2013/04/25 01:53:37
This isn't actually the effect of the next line, a
 
 | |
| 2174 // hasn't been initialized yet. | 2197 // hasn't been initialized yet. | 
| 2175 scoped_refptr<PermissionSet> granted_permissions = | 2198 scoped_refptr<PermissionSet> granted_permissions = | 
| 2176 extension_prefs_->GetGrantedPermissions(extension->id()); | 2199 extension_prefs_->GetGrantedPermissions(extension->id()); | 
| 2177 CHECK(granted_permissions.get()); | 2200 CHECK(granted_permissions.get()); | 
| 2178 | 2201 | 
| 2179 // Here, we check if an extension's privileges have increased in a manner | 2202 // Here, we check if an extension's privileges have increased in a manner | 
| 2180 // that requires the user's approval. This could occur because the browser | 2203 // that requires the user's approval. This could occur because the browser | 
| 2181 // upgraded and recognized additional privileges, or an extension upgrades | 2204 // upgraded and recognized additional privileges, or an extension upgrades | 
| 2182 // to a version that requires additional privileges. | 2205 // to a version that requires additional privileges. | 
| 2183 is_privilege_increase = | 2206 is_privilege_increase = | 
| 2184 granted_permissions->HasLessPrivilegesThan( | 2207 granted_permissions->HasLessPrivilegesThan( | 
| 2185 extension->GetActivePermissions()); | 2208 extension->GetActivePermissions()); | 
| 2186 } | 2209 } | 
| 2187 | 2210 | 
| 2188 // Silently grant all active permissions to default apps only on install. | |
| 2189 // After install they should behave like other apps. | |
| 2190 if (is_default_app_install) | |
| 2191 GrantPermissions(extension); | |
| 2192 | |
| 2193 if (is_extension_upgrade) { | 2211 if (is_extension_upgrade) { | 
| 2194 // Other than for unpacked extensions, CrxInstaller should have guaranteed | |
| 2195 // that we aren't downgrading. | |
| 2196 if (!Manifest::IsUnpackedLocation(extension->location())) | |
| 2197 CHECK_GE(extension->version()->CompareTo(*(old->version())), 0); | |
| 2198 | |
| 2199 // Extensions get upgraded if the privileges are allowed to increase or | |
| 2200 // the privileges haven't increased. | |
| 2201 if (!is_privilege_increase) { | |
| 2202 SetBeingUpgraded(old, true); | |
| 2203 SetBeingUpgraded(extension, true); | |
| 2204 } | |
| 2205 | |
| 2206 // If the extension was already disabled, suppress any alerts for becoming | 2212 // If the extension was already disabled, suppress any alerts for becoming | 
| 2207 // disabled on permissions increase. | 2213 // disabled on permissions increase. | 
| 2208 previously_disabled = extension_prefs_->IsExtensionDisabled(old->id()); | 2214 bool previously_disabled = | 
| 2215 extension_prefs_->IsExtensionDisabled(extension->id()); | |
| 2209 // Legacy disabled extensions do not have a disable reason. Infer that if | 2216 // Legacy disabled extensions do not have a disable reason. Infer that if | 
| 2210 // there was no permission increase, it was likely disabled by the user. | 2217 // there was no permission increase, it was likely disabled by the user. | 
| 2211 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && | 2218 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && | 
| 2212 !extension_prefs_->DidExtensionEscalatePermissions(old->id())) { | 2219 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 
| 2213 disable_reasons |= Extension::DISABLE_USER_ACTION; | 2220 disable_reasons |= Extension::DISABLE_USER_ACTION; | 
| 2214 } | 2221 } | 
| 2215 // Extensions that came to us disabled from sync need a similar inference, | 2222 // Extensions that came to us disabled from sync need a similar inference, | 
| 2216 // except based on the new version's permissions. | 2223 // except based on the new version's permissions. | 
| 2217 if (previously_disabled && | 2224 if (previously_disabled && | 
| 2218 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) { | 2225 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) { | 
| 2219 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason. | 2226 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason. | 
| 2220 extension_prefs_->ClearDisableReasons(extension->id()); | 2227 extension_prefs_->ClearDisableReasons(extension->id()); | 
| 
 
Jeffrey Yasskin
2013/04/25 01:53:37
If there's no privilege increase, this will drop a
 
Matt Perry
2013/04/25 19:03:46
Seems harmless here, though, because disable_reaso
 
Jeffrey Yasskin
2013/04/25 19:12:28
We want to clear that and add DISABLE_USER_ACTION.
 
Matt Perry
2013/04/25 19:22:43
We only add DISABLE_USER_ACTION if it's *not* a pr
 
Yoyo Zhou
2013/04/25 19:24:39
I think we (I, specifically) forgot to actually ad
 
Matt Perry
2013/04/25 19:29:55
Oh right, because we only AddDisableReason if it's
 
 | |
| 2221 if (!is_privilege_increase) | 2228 if (!is_privilege_increase) | 
| 2222 disable_reasons |= Extension::DISABLE_USER_ACTION; | 2229 disable_reasons |= Extension::DISABLE_USER_ACTION; | 
| 2223 } | 2230 } | 
| 2224 if (disable_reasons != Extension::DISABLE_NONE) | 2231 if (disable_reasons != Extension::DISABLE_NONE) | 
| 2225 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC; | 2232 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC; | 
| 
 
Jeffrey Yasskin
2013/04/25 01:53:37
This has no effect unless the ClearDisableReasons
 
Yoyo Zhou
2013/04/25 19:21:58
This logic is quite complicated to compensate for
 
Jeffrey Yasskin
2013/04/26 00:52:44
Moving SetExtensionState broke a ManagementPolicy
 
 | |
| 2226 | |
| 2227 // To upgrade an extension in place, unload the old one and | |
| 2228 // then load the new one. | |
| 2229 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE); | |
| 2230 old = NULL; | |
| 2231 } | 2233 } | 
| 2232 | 2234 | 
| 2233 // Extension has changed permissions significantly. Disable it. A | 2235 // Extension has changed permissions significantly. Disable it. A | 
| 2234 // notification should be sent by the caller. | 2236 // notification should be sent by the caller. | 
| 2235 if (is_privilege_increase) { | 2237 if (is_privilege_increase) { | 
| 2236 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; | 2238 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; | 
| 2237 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 2239 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 
| 2238 RecordPermissionMessagesHistogram( | 2240 RecordPermissionMessagesHistogram( | 
| 2239 extension, "Extensions.Permissions_AutoDisable"); | 2241 extension, "Extensions.Permissions_AutoDisable"); | 
| 2240 } | 2242 } | 
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2774 } | 2776 } | 
| 2775 | 2777 | 
| 2776 bool ExtensionService::IsBeingUpgraded(const Extension* extension) const { | 2778 bool ExtensionService::IsBeingUpgraded(const Extension* extension) const { | 
| 2777 ExtensionRuntimeDataMap::const_iterator it = | 2779 ExtensionRuntimeDataMap::const_iterator it = | 
| 2778 extension_runtime_data_.find(extension->id()); | 2780 extension_runtime_data_.find(extension->id()); | 
| 2779 return it == extension_runtime_data_.end() ? false : | 2781 return it == extension_runtime_data_.end() ? false : | 
| 2780 it->second.being_upgraded; | 2782 it->second.being_upgraded; | 
| 2781 } | 2783 } | 
| 2782 | 2784 | 
| 2783 void ExtensionService::SetBeingUpgraded(const Extension* extension, | 2785 void ExtensionService::SetBeingUpgraded(const Extension* extension, | 
| 2784 bool value) { | 2786 bool value) { | 
| 2785 extension_runtime_data_[extension->id()].being_upgraded = value; | 2787 extension_runtime_data_[extension->id()].being_upgraded = value; | 
| 2786 } | 2788 } | 
| 2787 | 2789 | 
| 2788 bool ExtensionService::HasUsedWebRequest(const Extension* extension) const { | 2790 bool ExtensionService::HasUsedWebRequest(const Extension* extension) const { | 
| 2789 ExtensionRuntimeDataMap::const_iterator it = | 2791 ExtensionRuntimeDataMap::const_iterator it = | 
| 2790 extension_runtime_data_.find(extension->id()); | 2792 extension_runtime_data_.find(extension->id()); | 
| 2791 return it == extension_runtime_data_.end() ? false : | 2793 return it == extension_runtime_data_.end() ? false : | 
| 2792 it->second.has_used_webrequest; | 2794 it->second.has_used_webrequest; | 
| 2793 } | 2795 } | 
| 2794 | 2796 | 
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3090 } | 3092 } | 
| 3091 | 3093 | 
| 3092 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 3094 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 
| 3093 update_observers_.AddObserver(observer); | 3095 update_observers_.AddObserver(observer); | 
| 3094 } | 3096 } | 
| 3095 | 3097 | 
| 3096 void ExtensionService::RemoveUpdateObserver( | 3098 void ExtensionService::RemoveUpdateObserver( | 
| 3097 extensions::UpdateObserver* observer) { | 3099 extensions::UpdateObserver* observer) { | 
| 3098 update_observers_.RemoveObserver(observer); | 3100 update_observers_.RemoveObserver(observer); | 
| 3099 } | 3101 } | 
| OLD | NEW |