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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 260 |
261 void ExtensionService::AddProviderForTesting( | 261 void ExtensionService::AddProviderForTesting( |
262 extensions::ExternalProviderInterface* test_provider) { | 262 extensions::ExternalProviderInterface* test_provider) { |
263 CHECK(test_provider); | 263 CHECK(test_provider); |
264 external_extension_providers_.push_back( | 264 external_extension_providers_.push_back( |
265 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); | 265 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); |
266 } | 266 } |
267 | 267 |
268 bool ExtensionService::OnExternalExtensionUpdateUrlFound( | 268 bool ExtensionService::OnExternalExtensionUpdateUrlFound( |
269 const std::string& id, | 269 const std::string& id, |
| 270 const std::string& install_parameter, |
270 const GURL& update_url, | 271 const GURL& update_url, |
271 Manifest::Location location, | 272 Manifest::Location location, |
272 int creation_flags, | 273 int creation_flags, |
273 bool mark_acknowledged) { | 274 bool mark_acknowledged) { |
274 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 275 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
275 CHECK(Extension::IdIsValid(id)); | 276 CHECK(Extension::IdIsValid(id)); |
276 | 277 |
277 if (Manifest::IsExternalLocation(location)) { | 278 if (Manifest::IsExternalLocation(location)) { |
278 // All extensions that are not user specific can be cached. | 279 // All extensions that are not user specific can be cached. |
279 extensions::ExtensionCache::GetInstance()->AllowCaching(id); | 280 extensions::ExtensionCache::GetInstance()->AllowCaching(id); |
280 } | 281 } |
281 | 282 |
282 const Extension* extension = GetExtensionById(id, true); | 283 const Extension* extension = GetExtensionById(id, true); |
283 if (extension) { | 284 if (extension) { |
284 // Already installed. Skip this install if the current location has | 285 // Already installed. Skip this install if the current location has |
285 // higher priority than |location|. | 286 // higher priority than |location|. |
286 Manifest::Location current = extension->location(); | 287 Manifest::Location current = extension->location(); |
287 if (current == Manifest::GetHigherPriorityLocation(current, location)) | 288 if (current == Manifest::GetHigherPriorityLocation(current, location)) |
288 return false; | 289 return false; |
289 // Otherwise, overwrite the current installation. | 290 // Otherwise, overwrite the current installation. |
290 } | 291 } |
291 | 292 |
292 // Add |id| to the set of pending extensions. If it can not be added, | 293 // Add |id| to the set of pending extensions. If it can not be added, |
293 // then there is already a pending record from a higher-priority install | 294 // then there is already a pending record from a higher-priority install |
294 // source. In this case, signal that this extension will not be | 295 // source. In this case, signal that this extension will not be |
295 // installed by returning false. | 296 // installed by returning false. |
296 if (!pending_extension_manager()->AddFromExternalUpdateUrl( | 297 if (!pending_extension_manager()->AddFromExternalUpdateUrl( |
297 id, update_url, location, creation_flags, mark_acknowledged)) { | 298 id, |
| 299 install_parameter, |
| 300 update_url, |
| 301 location, |
| 302 creation_flags, |
| 303 mark_acknowledged)) { |
298 return false; | 304 return false; |
299 } | 305 } |
300 | 306 |
301 update_once_all_providers_are_ready_ = true; | 307 update_once_all_providers_are_ready_ = true; |
302 return true; | 308 return true; |
303 } | 309 } |
304 | 310 |
305 const Extension* ExtensionService::GetInstalledExtensionByUrl( | 311 const Extension* ExtensionService::GetInstalledExtensionByUrl( |
306 const GURL& url) const { | 312 const GURL& url) const { |
307 return registry_->enabled_extensions().GetExtensionOrAppByURL(url); | 313 return registry_->enabled_extensions().GetExtensionOrAppByURL(url); |
(...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 | 1852 |
1847 VLOG(1) << "AddComponentExtension " << extension->name(); | 1853 VLOG(1) << "AddComponentExtension " << extension->name(); |
1848 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | 1854 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
1849 VLOG(1) << "Component extension " << extension->name() << " (" | 1855 VLOG(1) << "Component extension " << extension->name() << " (" |
1850 << extension->id() << ") installing/upgrading from '" | 1856 << extension->id() << ") installing/upgrading from '" |
1851 << old_version_string << "' to " << extension->version()->GetString(); | 1857 << old_version_string << "' to " << extension->version()->GetString(); |
1852 | 1858 |
1853 AddNewOrUpdatedExtension(extension, | 1859 AddNewOrUpdatedExtension(extension, |
1854 Extension::ENABLED_COMPONENT, | 1860 Extension::ENABLED_COMPONENT, |
1855 extensions::NOT_BLACKLISTED, | 1861 extensions::NOT_BLACKLISTED, |
1856 syncer::StringOrdinal()); | 1862 syncer::StringOrdinal(), |
| 1863 std::string()); |
1857 return; | 1864 return; |
1858 } | 1865 } |
1859 | 1866 |
1860 AddExtension(extension); | 1867 AddExtension(extension); |
1861 } | 1868 } |
1862 | 1869 |
1863 void ExtensionService::UpdateActivePermissions(const Extension* extension) { | 1870 void ExtensionService::UpdateActivePermissions(const Extension* extension) { |
1864 // If the extension has used the optional permissions API, it will have a | 1871 // If the extension has used the optional permissions API, it will have a |
1865 // custom set of active permissions defined in the extension prefs. Here, | 1872 // custom set of active permissions defined in the extension prefs. Here, |
1866 // we update the extension's active permissions based on the prefs. | 1873 // we update the extension's active permissions based on the prefs. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2106 void ExtensionService::OnExtensionInstalled( | 2113 void ExtensionService::OnExtensionInstalled( |
2107 const Extension* extension, | 2114 const Extension* extension, |
2108 const syncer::StringOrdinal& page_ordinal, | 2115 const syncer::StringOrdinal& page_ordinal, |
2109 bool has_requirement_errors, | 2116 bool has_requirement_errors, |
2110 extensions::BlacklistState blacklist_state, | 2117 extensions::BlacklistState blacklist_state, |
2111 bool wait_for_idle) { | 2118 bool wait_for_idle) { |
2112 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2119 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2113 | 2120 |
2114 const std::string& id = extension->id(); | 2121 const std::string& id = extension->id(); |
2115 bool initial_enable = ShouldEnableOnInstall(extension); | 2122 bool initial_enable = ShouldEnableOnInstall(extension); |
| 2123 std::string install_parameter; |
2116 const extensions::PendingExtensionInfo* pending_extension_info = NULL; | 2124 const extensions::PendingExtensionInfo* pending_extension_info = NULL; |
2117 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { | 2125 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { |
2118 if (!pending_extension_info->ShouldAllowInstall(extension)) { | 2126 if (!pending_extension_info->ShouldAllowInstall(extension)) { |
2119 pending_extension_manager()->Remove(id); | 2127 pending_extension_manager()->Remove(id); |
2120 | 2128 |
2121 LOG(WARNING) << "ShouldAllowInstall() returned false for " | 2129 LOG(WARNING) << "ShouldAllowInstall() returned false for " |
2122 << id << " of type " << extension->GetType() | 2130 << id << " of type " << extension->GetType() |
2123 << " and update URL " | 2131 << " and update URL " |
2124 << extensions::ManifestURL::GetUpdateURL(extension).spec() | 2132 << extensions::ManifestURL::GetUpdateURL(extension).spec() |
2125 << "; not installing"; | 2133 << "; not installing"; |
2126 | 2134 |
2127 // Delete the extension directory since we're not going to | 2135 // Delete the extension directory since we're not going to |
2128 // load it. | 2136 // load it. |
2129 if (!GetFileTaskRunner()->PostTask( | 2137 if (!GetFileTaskRunner()->PostTask( |
2130 FROM_HERE, | 2138 FROM_HERE, |
2131 base::Bind(&extension_file_util::DeleteFile, | 2139 base::Bind(&extension_file_util::DeleteFile, |
2132 extension->path(), true))) { | 2140 extension->path(), true))) { |
2133 NOTREACHED(); | 2141 NOTREACHED(); |
2134 } | 2142 } |
2135 return; | 2143 return; |
2136 } | 2144 } |
2137 | 2145 |
| 2146 install_parameter = pending_extension_info->install_parameter(); |
2138 pending_extension_manager()->Remove(id); | 2147 pending_extension_manager()->Remove(id); |
2139 } else { | 2148 } else { |
2140 // We explicitly want to re-enable an uninstalled external | 2149 // We explicitly want to re-enable an uninstalled external |
2141 // extension; if we're here, that means the user is manually | 2150 // extension; if we're here, that means the user is manually |
2142 // installing the extension. | 2151 // installing the extension. |
2143 if (IsExternalExtensionUninstalled(id)) { | 2152 if (IsExternalExtensionUninstalled(id)) { |
2144 initial_enable = true; | 2153 initial_enable = true; |
2145 } | 2154 } |
2146 } | 2155 } |
2147 | 2156 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 const Extension::State initial_state = | 2202 const Extension::State initial_state = |
2194 initial_enable ? Extension::ENABLED : Extension::DISABLED; | 2203 initial_enable ? Extension::ENABLED : Extension::DISABLED; |
2195 const bool blacklisted_for_malware = | 2204 const bool blacklisted_for_malware = |
2196 blacklist_state == extensions::BLACKLISTED_MALWARE; | 2205 blacklist_state == extensions::BLACKLISTED_MALWARE; |
2197 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) { | 2206 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) { |
2198 extension_prefs_->SetDelayedInstallInfo( | 2207 extension_prefs_->SetDelayedInstallInfo( |
2199 extension, | 2208 extension, |
2200 initial_state, | 2209 initial_state, |
2201 blacklisted_for_malware, | 2210 blacklisted_for_malware, |
2202 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, | 2211 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, |
2203 page_ordinal); | 2212 page_ordinal, |
| 2213 install_parameter); |
2204 | 2214 |
2205 // Transfer ownership of |extension|. | 2215 // Transfer ownership of |extension|. |
2206 delayed_installs_.Insert(extension); | 2216 delayed_installs_.Insert(extension); |
2207 | 2217 |
2208 // Notify observers that app update is available. | 2218 // Notify observers that app update is available. |
2209 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, | 2219 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
2210 OnAppUpdateAvailable(extension)); | 2220 OnAppUpdateAvailable(extension)); |
2211 return; | 2221 return; |
2212 } | 2222 } |
2213 | 2223 |
2214 ImportStatus status = SatisfyImports(extension); | 2224 ImportStatus status = SatisfyImports(extension); |
2215 if (installs_delayed_for_gc()) { | 2225 if (installs_delayed_for_gc()) { |
2216 extension_prefs_->SetDelayedInstallInfo( | 2226 extension_prefs_->SetDelayedInstallInfo( |
2217 extension, | 2227 extension, |
2218 initial_state, | 2228 initial_state, |
2219 blacklisted_for_malware, | 2229 blacklisted_for_malware, |
2220 extensions::ExtensionPrefs::DELAY_REASON_GC, | 2230 extensions::ExtensionPrefs::DELAY_REASON_GC, |
2221 page_ordinal); | 2231 page_ordinal, |
| 2232 install_parameter); |
2222 delayed_installs_.Insert(extension); | 2233 delayed_installs_.Insert(extension); |
2223 } else if (status != IMPORT_STATUS_OK) { | 2234 } else if (status != IMPORT_STATUS_OK) { |
2224 if (status == IMPORT_STATUS_UNSATISFIED) { | 2235 if (status == IMPORT_STATUS_UNSATISFIED) { |
2225 extension_prefs_->SetDelayedInstallInfo( | 2236 extension_prefs_->SetDelayedInstallInfo( |
2226 extension, | 2237 extension, |
2227 initial_state, | 2238 initial_state, |
2228 blacklisted_for_malware, | 2239 blacklisted_for_malware, |
2229 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, | 2240 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
2230 page_ordinal); | 2241 page_ordinal, |
| 2242 install_parameter); |
2231 delayed_installs_.Insert(extension); | 2243 delayed_installs_.Insert(extension); |
2232 } | 2244 } |
2233 } else { | 2245 } else { |
2234 AddNewOrUpdatedExtension(extension, | 2246 AddNewOrUpdatedExtension(extension, |
2235 initial_state, | 2247 initial_state, |
2236 blacklist_state, | 2248 blacklist_state, |
2237 page_ordinal); | 2249 page_ordinal, |
| 2250 install_parameter); |
2238 } | 2251 } |
2239 } | 2252 } |
2240 | 2253 |
2241 void ExtensionService::AddNewOrUpdatedExtension( | 2254 void ExtensionService::AddNewOrUpdatedExtension( |
2242 const Extension* extension, | 2255 const Extension* extension, |
2243 Extension::State initial_state, | 2256 Extension::State initial_state, |
2244 extensions::BlacklistState blacklist_state, | 2257 extensions::BlacklistState blacklist_state, |
2245 const syncer::StringOrdinal& page_ordinal) { | 2258 const syncer::StringOrdinal& page_ordinal, |
| 2259 const std::string& install_parameter) { |
2246 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2260 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2247 const bool blacklisted_for_malware = | 2261 const bool blacklisted_for_malware = |
2248 blacklist_state == extensions::BLACKLISTED_MALWARE; | 2262 blacklist_state == extensions::BLACKLISTED_MALWARE; |
2249 extension_prefs_->OnExtensionInstalled(extension, | 2263 extension_prefs_->OnExtensionInstalled(extension, |
2250 initial_state, | 2264 initial_state, |
2251 blacklisted_for_malware, | 2265 blacklisted_for_malware, |
2252 page_ordinal); | 2266 page_ordinal, |
| 2267 install_parameter); |
2253 delayed_installs_.Remove(extension->id()); | 2268 delayed_installs_.Remove(extension->id()); |
2254 if (InstallVerifier::NeedsVerification(*extension)) { | 2269 if (InstallVerifier::NeedsVerification(*extension)) { |
2255 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Add( | 2270 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Add( |
2256 extension->id(), base::Bind(LogAddVerifiedSuccess)); | 2271 extension->id(), base::Bind(LogAddVerifiedSuccess)); |
2257 } | 2272 } |
2258 FinishInstallation(extension); | 2273 FinishInstallation(extension); |
2259 } | 2274 } |
2260 | 2275 |
2261 void ExtensionService::MaybeFinishDelayedInstallation( | 2276 void ExtensionService::MaybeFinishDelayedInstallation( |
2262 const std::string& extension_id) { | 2277 const std::string& extension_id) { |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2887 void ExtensionService::UnloadAllExtensionsInternal() { | 2902 void ExtensionService::UnloadAllExtensionsInternal() { |
2888 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2903 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
2889 | 2904 |
2890 registry_->ClearAll(); | 2905 registry_->ClearAll(); |
2891 system_->runtime_data()->ClearAll(); | 2906 system_->runtime_data()->ClearAll(); |
2892 | 2907 |
2893 // TODO(erikkay) should there be a notification for this? We can't use | 2908 // TODO(erikkay) should there be a notification for this? We can't use |
2894 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2909 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
2895 // or uninstalled. | 2910 // or uninstalled. |
2896 } | 2911 } |
OLD | NEW |