Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 196663003: Introduce an extension parameter which is used to customize the extension. It's available for exter… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified test parameters Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 void ExtensionService::AddProviderForTesting( 259 void ExtensionService::AddProviderForTesting(
260 extensions::ExternalProviderInterface* test_provider) { 260 extensions::ExternalProviderInterface* test_provider) {
261 CHECK(test_provider); 261 CHECK(test_provider);
262 external_extension_providers_.push_back( 262 external_extension_providers_.push_back(
263 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); 263 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
264 } 264 }
265 265
266 bool ExtensionService::OnExternalExtensionUpdateUrlFound( 266 bool ExtensionService::OnExternalExtensionUpdateUrlFound(
267 const std::string& id, 267 const std::string& id,
268 const std::string& install_parameter,
268 const GURL& update_url, 269 const GURL& update_url,
269 Manifest::Location location, 270 Manifest::Location location,
270 int creation_flags, 271 int creation_flags,
271 bool mark_acknowledged) { 272 bool mark_acknowledged) {
272 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 273 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
273 CHECK(Extension::IdIsValid(id)); 274 CHECK(Extension::IdIsValid(id));
274 275
275 if (Manifest::IsExternalLocation(location)) { 276 if (Manifest::IsExternalLocation(location)) {
276 // All extensions that are not user specific can be cached. 277 // All extensions that are not user specific can be cached.
277 extensions::ExtensionCache::GetInstance()->AllowCaching(id); 278 extensions::ExtensionCache::GetInstance()->AllowCaching(id);
278 } 279 }
279 280
280 const Extension* extension = GetExtensionById(id, true); 281 const Extension* extension = GetExtensionById(id, true);
281 if (extension) { 282 if (extension) {
282 // Already installed. Skip this install if the current location has 283 // Already installed. Skip this install if the current location has
283 // higher priority than |location|. 284 // higher priority than |location|.
284 Manifest::Location current = extension->location(); 285 Manifest::Location current = extension->location();
285 if (current == Manifest::GetHigherPriorityLocation(current, location)) 286 if (current == Manifest::GetHigherPriorityLocation(current, location))
286 return false; 287 return false;
287 // Otherwise, overwrite the current installation. 288 // Otherwise, overwrite the current installation.
288 } 289 }
289 290
290 // Add |id| to the set of pending extensions. If it can not be added, 291 // Add |id| to the set of pending extensions. If it can not be added,
291 // then there is already a pending record from a higher-priority install 292 // then there is already a pending record from a higher-priority install
292 // source. In this case, signal that this extension will not be 293 // source. In this case, signal that this extension will not be
293 // installed by returning false. 294 // installed by returning false.
294 if (!pending_extension_manager()->AddFromExternalUpdateUrl( 295 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
295 id, update_url, location, creation_flags, mark_acknowledged)) { 296 id,
297 install_parameter,
298 update_url,
299 location,
300 creation_flags,
301 mark_acknowledged)) {
296 return false; 302 return false;
297 } 303 }
298 304
299 update_once_all_providers_are_ready_ = true; 305 update_once_all_providers_are_ready_ = true;
300 return true; 306 return true;
301 } 307 }
302 308
303 const Extension* ExtensionService::GetInstalledExtensionByUrl( 309 const Extension* ExtensionService::GetInstalledExtensionByUrl(
304 const GURL& url) const { 310 const GURL& url) const {
305 return registry_->enabled_extensions().GetExtensionOrAppByURL(url); 311 return registry_->enabled_extensions().GetExtensionOrAppByURL(url);
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 1822
1817 VLOG(1) << "AddComponentExtension " << extension->name(); 1823 VLOG(1) << "AddComponentExtension " << extension->name();
1818 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { 1824 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1819 VLOG(1) << "Component extension " << extension->name() << " (" 1825 VLOG(1) << "Component extension " << extension->name() << " ("
1820 << extension->id() << ") installing/upgrading from '" 1826 << extension->id() << ") installing/upgrading from '"
1821 << old_version_string << "' to " << extension->version()->GetString(); 1827 << old_version_string << "' to " << extension->version()->GetString();
1822 1828
1823 AddNewOrUpdatedExtension(extension, 1829 AddNewOrUpdatedExtension(extension,
1824 Extension::ENABLED_COMPONENT, 1830 Extension::ENABLED_COMPONENT,
1825 extensions::NOT_BLACKLISTED, 1831 extensions::NOT_BLACKLISTED,
1826 syncer::StringOrdinal()); 1832 syncer::StringOrdinal(),
1833 std::string());
1827 return; 1834 return;
1828 } 1835 }
1829 1836
1830 AddExtension(extension); 1837 AddExtension(extension);
1831 } 1838 }
1832 1839
1833 void ExtensionService::UpdateActivePermissions(const Extension* extension) { 1840 void ExtensionService::UpdateActivePermissions(const Extension* extension) {
1834 // If the extension has used the optional permissions API, it will have a 1841 // If the extension has used the optional permissions API, it will have a
1835 // custom set of active permissions defined in the extension prefs. Here, 1842 // custom set of active permissions defined in the extension prefs. Here,
1836 // we update the extension's active permissions based on the prefs. 1843 // we update the extension's active permissions based on the prefs.
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 void ExtensionService::OnExtensionInstalled( 2083 void ExtensionService::OnExtensionInstalled(
2077 const Extension* extension, 2084 const Extension* extension,
2078 const syncer::StringOrdinal& page_ordinal, 2085 const syncer::StringOrdinal& page_ordinal,
2079 bool has_requirement_errors, 2086 bool has_requirement_errors,
2080 extensions::BlacklistState blacklist_state, 2087 extensions::BlacklistState blacklist_state,
2081 bool wait_for_idle) { 2088 bool wait_for_idle) {
2082 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2089 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2083 2090
2084 const std::string& id = extension->id(); 2091 const std::string& id = extension->id();
2085 bool initial_enable = ShouldEnableOnInstall(extension); 2092 bool initial_enable = ShouldEnableOnInstall(extension);
2093 std::string install_parameter;
2086 const extensions::PendingExtensionInfo* pending_extension_info = NULL; 2094 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
2087 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { 2095 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
2088 if (!pending_extension_info->ShouldAllowInstall(extension)) { 2096 if (!pending_extension_info->ShouldAllowInstall(extension)) {
2089 pending_extension_manager()->Remove(id); 2097 pending_extension_manager()->Remove(id);
2090 2098
2091 LOG(WARNING) << "ShouldAllowInstall() returned false for " 2099 LOG(WARNING) << "ShouldAllowInstall() returned false for "
2092 << id << " of type " << extension->GetType() 2100 << id << " of type " << extension->GetType()
2093 << " and update URL " 2101 << " and update URL "
2094 << extensions::ManifestURL::GetUpdateURL(extension).spec() 2102 << extensions::ManifestURL::GetUpdateURL(extension).spec()
2095 << "; not installing"; 2103 << "; not installing";
2096 2104
2097 // Delete the extension directory since we're not going to 2105 // Delete the extension directory since we're not going to
2098 // load it. 2106 // load it.
2099 if (!GetFileTaskRunner()->PostTask( 2107 if (!GetFileTaskRunner()->PostTask(
2100 FROM_HERE, 2108 FROM_HERE,
2101 base::Bind(&extension_file_util::DeleteFile, 2109 base::Bind(&extension_file_util::DeleteFile,
2102 extension->path(), true))) { 2110 extension->path(), true))) {
2103 NOTREACHED(); 2111 NOTREACHED();
2104 } 2112 }
2105 return; 2113 return;
2106 } 2114 }
2107 2115
2116 install_parameter = pending_extension_info->install_parameter();
2108 pending_extension_manager()->Remove(id); 2117 pending_extension_manager()->Remove(id);
2109 } else { 2118 } else {
2110 // We explicitly want to re-enable an uninstalled external 2119 // We explicitly want to re-enable an uninstalled external
2111 // extension; if we're here, that means the user is manually 2120 // extension; if we're here, that means the user is manually
2112 // installing the extension. 2121 // installing the extension.
2113 if (IsExternalExtensionUninstalled(id)) { 2122 if (IsExternalExtensionUninstalled(id)) {
2114 initial_enable = true; 2123 initial_enable = true;
2115 } 2124 }
2116 } 2125 }
2117 2126
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 const Extension::State initial_state = 2172 const Extension::State initial_state =
2164 initial_enable ? Extension::ENABLED : Extension::DISABLED; 2173 initial_enable ? Extension::ENABLED : Extension::DISABLED;
2165 const bool blacklisted_for_malware = 2174 const bool blacklisted_for_malware =
2166 blacklist_state == extensions::BLACKLISTED_MALWARE; 2175 blacklist_state == extensions::BLACKLISTED_MALWARE;
2167 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) { 2176 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) {
2168 extension_prefs_->SetDelayedInstallInfo( 2177 extension_prefs_->SetDelayedInstallInfo(
2169 extension, 2178 extension,
2170 initial_state, 2179 initial_state,
2171 blacklisted_for_malware, 2180 blacklisted_for_malware,
2172 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, 2181 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
2173 page_ordinal); 2182 page_ordinal,
2183 install_parameter);
2174 2184
2175 // Transfer ownership of |extension|. 2185 // Transfer ownership of |extension|.
2176 delayed_installs_.Insert(extension); 2186 delayed_installs_.Insert(extension);
2177 2187
2178 // Notify observers that app update is available. 2188 // Notify observers that app update is available.
2179 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, 2189 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2180 OnAppUpdateAvailable(extension)); 2190 OnAppUpdateAvailable(extension));
2181 return; 2191 return;
2182 } 2192 }
2183 2193
2184 ImportStatus status = SatisfyImports(extension); 2194 ImportStatus status = SatisfyImports(extension);
2185 if (installs_delayed_for_gc()) { 2195 if (installs_delayed_for_gc()) {
2186 extension_prefs_->SetDelayedInstallInfo( 2196 extension_prefs_->SetDelayedInstallInfo(
2187 extension, 2197 extension,
2188 initial_state, 2198 initial_state,
2189 blacklisted_for_malware, 2199 blacklisted_for_malware,
2190 extensions::ExtensionPrefs::DELAY_REASON_GC, 2200 extensions::ExtensionPrefs::DELAY_REASON_GC,
2191 page_ordinal); 2201 page_ordinal,
2202 install_parameter);
2192 delayed_installs_.Insert(extension); 2203 delayed_installs_.Insert(extension);
2193 } else if (status != IMPORT_STATUS_OK) { 2204 } else if (status != IMPORT_STATUS_OK) {
2194 if (status == IMPORT_STATUS_UNSATISFIED) { 2205 if (status == IMPORT_STATUS_UNSATISFIED) {
2195 extension_prefs_->SetDelayedInstallInfo( 2206 extension_prefs_->SetDelayedInstallInfo(
2196 extension, 2207 extension,
2197 initial_state, 2208 initial_state,
2198 blacklisted_for_malware, 2209 blacklisted_for_malware,
2199 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, 2210 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
2200 page_ordinal); 2211 page_ordinal,
2212 install_parameter);
2201 delayed_installs_.Insert(extension); 2213 delayed_installs_.Insert(extension);
2202 } 2214 }
2203 } else { 2215 } else {
2204 AddNewOrUpdatedExtension(extension, 2216 AddNewOrUpdatedExtension(extension,
2205 initial_state, 2217 initial_state,
2206 blacklist_state, 2218 blacklist_state,
2207 page_ordinal); 2219 page_ordinal,
2220 install_parameter);
2208 } 2221 }
2209 } 2222 }
2210 2223
2211 void ExtensionService::AddNewOrUpdatedExtension( 2224 void ExtensionService::AddNewOrUpdatedExtension(
2212 const Extension* extension, 2225 const Extension* extension,
2213 Extension::State initial_state, 2226 Extension::State initial_state,
2214 extensions::BlacklistState blacklist_state, 2227 extensions::BlacklistState blacklist_state,
2215 const syncer::StringOrdinal& page_ordinal) { 2228 const syncer::StringOrdinal& page_ordinal,
2229 const std::string& install_parameter) {
2216 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2230 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2217 const bool blacklisted_for_malware = 2231 const bool blacklisted_for_malware =
2218 blacklist_state == extensions::BLACKLISTED_MALWARE; 2232 blacklist_state == extensions::BLACKLISTED_MALWARE;
2219 extension_prefs_->OnExtensionInstalled(extension, 2233 extension_prefs_->OnExtensionInstalled(extension,
2220 initial_state, 2234 initial_state,
2221 blacklisted_for_malware, 2235 blacklisted_for_malware,
2222 page_ordinal); 2236 page_ordinal,
2237 install_parameter);
2223 delayed_installs_.Remove(extension->id()); 2238 delayed_installs_.Remove(extension->id());
2224 if (InstallVerifier::NeedsVerification(*extension)) { 2239 if (InstallVerifier::NeedsVerification(*extension)) {
2225 system_->install_verifier()->Add(extension->id(), 2240 system_->install_verifier()->Add(extension->id(),
2226 base::Bind(LogAddVerifiedSuccess)); 2241 base::Bind(LogAddVerifiedSuccess));
2227 } 2242 }
2228 FinishInstallation(extension); 2243 FinishInstallation(extension);
2229 } 2244 }
2230 2245
2231 void ExtensionService::MaybeFinishDelayedInstallation( 2246 void ExtensionService::MaybeFinishDelayedInstallation(
2232 const std::string& extension_id) { 2247 const std::string& extension_id) {
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
2837 void ExtensionService::UnloadAllExtensionsInternal() { 2852 void ExtensionService::UnloadAllExtensionsInternal() {
2838 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2853 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2839 2854
2840 registry_->ClearAll(); 2855 registry_->ClearAll();
2841 system_->runtime_data()->ClearAll(); 2856 system_->runtime_data()->ClearAll();
2842 2857
2843 // TODO(erikkay) should there be a notification for this? We can't use 2858 // TODO(erikkay) should there be a notification for this? We can't use
2844 // EXTENSION_UNLOADED since that implies that the extension has been disabled 2859 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2845 // or uninstalled. 2860 // or uninstalled.
2846 } 2861 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698