OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/extensions/crx_installer.h" | 11 #include "chrome/browser/extensions/crx_installer.h" |
12 #include "chrome/browser/extensions/extension_browser_event_router.h" | 12 #include "chrome/browser/extensions/extension_browser_event_router.h" |
13 #include "chrome/browser/extensions/extension_file_util.h" | 13 #include "chrome/browser/extensions/extension_file_util.h" |
14 #include "chrome/browser/extensions/extension_updater.h" | 14 #include "chrome/browser/extensions/extension_updater.h" |
15 #include "chrome/browser/extensions/external_extension_provider.h" | 15 #include "chrome/browser/extensions/external_extension_provider.h" |
16 #include "chrome/browser/extensions/external_pref_extension_provider.h" | 16 #include "chrome/browser/extensions/external_pref_extension_provider.h" |
17 #include "chrome/browser/extensions/theme_preview_infobar_delegate.h" | |
18 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
19 #include "chrome/browser/tab_contents/tab_contents.h" | |
20 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
22 #include "chrome/common/extensions/extension_error_reporter.h" | 20 #include "chrome/common/extensions/extension_error_reporter.h" |
23 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
24 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
25 #include "chrome/common/pref_service.h" | 23 #include "chrome/common/pref_service.h" |
26 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
27 | 25 |
28 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
29 #include "chrome/browser/extensions/external_registry_extension_provider_win.h" | 27 #include "chrome/browser/extensions/external_registry_extension_provider_win.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 99 |
102 // TODO(erikkay) this should probably be deferred to a future point | 100 // TODO(erikkay) this should probably be deferred to a future point |
103 // rather than running immediately at startup. | 101 // rather than running immediately at startup. |
104 CheckForExternalUpdates(); | 102 CheckForExternalUpdates(); |
105 | 103 |
106 // TODO(erikkay) this should probably be deferred as well. | 104 // TODO(erikkay) this should probably be deferred as well. |
107 GarbageCollectExtensions(); | 105 GarbageCollectExtensions(); |
108 } | 106 } |
109 | 107 |
110 void ExtensionsService::InstallExtension(const FilePath& extension_path) { | 108 void ExtensionsService::InstallExtension(const FilePath& extension_path) { |
111 InstallExtension(extension_path, GURL(), GURL()); | 109 CrxInstaller::Start(extension_path, install_directory_, Extension::INTERNAL, |
112 } | 110 "", // no expected id |
113 | 111 false, // don't delete crx when complete |
114 void ExtensionsService::InstallExtension(const FilePath& extension_path, | 112 backend_loop_, |
115 const GURL& download_url, | 113 this, |
116 const GURL& referrer_url) { | 114 NULL); // no client (silent install) |
117 new CrxInstaller(extension_path, install_directory_, Extension::INTERNAL, | |
118 "", // no expected id | |
119 extensions_enabled_, | |
120 IsDownloadFromGallery(download_url, referrer_url), | |
121 show_extensions_prompts(), | |
122 false, // don't delete crx when complete | |
123 backend_loop_, | |
124 this); | |
125 } | 115 } |
126 | 116 |
127 void ExtensionsService::UpdateExtension(const std::string& id, | 117 void ExtensionsService::UpdateExtension(const std::string& id, |
128 const FilePath& extension_path) { | 118 const FilePath& extension_path) { |
129 | 119 |
130 if (!GetExtensionById(id)) { | 120 if (!GetExtensionById(id)) { |
131 LOG(WARNING) << "Will not update extension " << id << " because it is not " | 121 LOG(WARNING) << "Will not update extension " << id << " because it is not " |
132 << "installed"; | 122 << "installed"; |
133 return; | 123 return; |
134 } | 124 } |
135 | 125 |
136 new CrxInstaller(extension_path, install_directory_, Extension::INTERNAL, | 126 CrxInstaller::Start(extension_path, install_directory_, Extension::INTERNAL, |
137 id, extensions_enabled_, | 127 id, |
138 false, // not from gallery | 128 true, // delete crx when complete |
139 show_extensions_prompts(), | 129 backend_loop_, |
140 true, // delete crx when complete | 130 this, |
141 backend_loop_, | 131 NULL); // no client (silent install) |
142 this); | |
143 } | 132 } |
144 | 133 |
145 void ExtensionsService::ReloadExtension(const std::string& extension_id) { | 134 void ExtensionsService::ReloadExtension(const std::string& extension_id) { |
146 Extension* extension = GetExtensionById(extension_id); | 135 Extension* extension = GetExtensionById(extension_id); |
147 FilePath extension_path = extension->path(); | 136 FilePath extension_path = extension->path(); |
148 | 137 |
149 UnloadExtension(extension_id); | 138 UnloadExtension(extension_id); |
150 LoadExtension(extension_path); | 139 LoadExtension(extension_path); |
151 } | 140 } |
152 | 141 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 294 } |
306 } | 295 } |
307 } | 296 } |
308 | 297 |
309 void ExtensionsService::OnExtensionInstalled(Extension* extension) { | 298 void ExtensionsService::OnExtensionInstalled(Extension* extension) { |
310 extension_prefs_->OnExtensionInstalled(extension); | 299 extension_prefs_->OnExtensionInstalled(extension); |
311 | 300 |
312 // If the extension is a theme, tell the profile (and therefore ThemeProvider) | 301 // If the extension is a theme, tell the profile (and therefore ThemeProvider) |
313 // to apply it. | 302 // to apply it. |
314 if (extension->IsTheme()) { | 303 if (extension->IsTheme()) { |
315 ShowThemePreviewInfobar(extension); | |
316 NotificationService::current()->Notify( | 304 NotificationService::current()->Notify( |
317 NotificationType::THEME_INSTALLED, | 305 NotificationType::THEME_INSTALLED, |
318 Source<ExtensionsService>(this), | 306 Source<ExtensionsService>(this), |
319 Details<Extension>(extension)); | 307 Details<Extension>(extension)); |
320 } else { | 308 } else { |
321 NotificationService::current()->Notify( | 309 NotificationService::current()->Notify( |
322 NotificationType::EXTENSION_INSTALLED, | 310 NotificationType::EXTENSION_INSTALLED, |
323 Source<ExtensionsService>(this), | 311 Source<ExtensionsService>(this), |
324 Details<Extension>(extension)); | 312 Details<Extension>(extension)); |
325 } | 313 } |
326 | 314 |
327 // Also load the extension. | 315 // Also load the extension. |
328 ExtensionList* list = new ExtensionList; | 316 ExtensionList* list = new ExtensionList; |
329 list->push_back(extension); | 317 list->push_back(extension); |
330 OnExtensionsLoaded(list); | 318 OnExtensionsLoaded(list); |
331 } | 319 } |
332 | 320 |
333 | 321 |
334 void ExtensionsService::OnExtensionOverinstallAttempted(const std::string& id) { | 322 void ExtensionsService::OnExtensionOverinstallAttempted(const std::string& id) { |
335 Extension* extension = GetExtensionById(id); | 323 Extension* extension = GetExtensionById(id); |
336 if (extension && extension->IsTheme()) { | 324 if (extension && extension->IsTheme()) { |
337 ShowThemePreviewInfobar(extension); | |
338 NotificationService::current()->Notify( | 325 NotificationService::current()->Notify( |
339 NotificationType::THEME_INSTALLED, | 326 NotificationType::THEME_INSTALLED, |
340 Source<ExtensionsService>(this), | 327 Source<ExtensionsService>(this), |
341 Details<Extension>(extension)); | 328 Details<Extension>(extension)); |
342 } | 329 } |
343 } | 330 } |
344 | 331 |
345 Extension* ExtensionsService::GetExtensionById(const std::string& id) { | 332 Extension* ExtensionsService::GetExtensionById(const std::string& id) { |
346 std::string lowercase_id = StringToLowerASCII(id); | 333 std::string lowercase_id = StringToLowerASCII(id); |
347 for (ExtensionList::const_iterator iter = extensions_.begin(); | 334 for (ExtensionList::const_iterator iter = extensions_.begin(); |
(...skipping 14 matching lines...) Expand all Loading... |
362 &ExtensionsServiceBackend::ClearProvidersForTesting)); | 349 &ExtensionsServiceBackend::ClearProvidersForTesting)); |
363 } | 350 } |
364 | 351 |
365 void ExtensionsService::SetProviderForTesting( | 352 void ExtensionsService::SetProviderForTesting( |
366 Extension::Location location, ExternalExtensionProvider* test_provider) { | 353 Extension::Location location, ExternalExtensionProvider* test_provider) { |
367 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), | 354 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), |
368 &ExtensionsServiceBackend::SetProviderForTesting, | 355 &ExtensionsServiceBackend::SetProviderForTesting, |
369 location, test_provider)); | 356 location, test_provider)); |
370 } | 357 } |
371 | 358 |
372 bool ExtensionsService::ShowThemePreviewInfobar(Extension* extension) { | |
373 if (!profile_) | |
374 return false; | |
375 | |
376 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | |
377 if (!browser) | |
378 return false; | |
379 | |
380 TabContents* tab_contents = browser->GetSelectedTabContents(); | |
381 if (!tab_contents) | |
382 return false; | |
383 | |
384 tab_contents->AddInfoBar(new ThemePreviewInfobarDelegate(tab_contents, | |
385 extension->name())); | |
386 return true; | |
387 } | |
388 | |
389 void ExtensionsService::OnExternalExtensionFound(const std::string& id, | 359 void ExtensionsService::OnExternalExtensionFound(const std::string& id, |
390 const std::string& version, | 360 const std::string& version, |
391 const FilePath& path, | 361 const FilePath& path, |
392 Extension::Location location) { | 362 Extension::Location location) { |
393 // Before even bothering to unpack, check and see if we already have this | 363 // Before even bothering to unpack, check and see if we already have this |
394 // version. This is important because these extensions are going to get | 364 // version. This is important because these extensions are going to get |
395 // installed on every startup. | 365 // installed on every startup. |
396 Extension* existing = GetExtensionById(id); | 366 Extension* existing = GetExtensionById(id); |
397 if (existing) { | 367 if (existing) { |
398 switch (existing->version()->CompareTo( | 368 switch (existing->version()->CompareTo( |
399 *Version::GetVersionFromString(version))) { | 369 *Version::GetVersionFromString(version))) { |
400 case -1: // existing version is older, we should upgrade | 370 case -1: // existing version is older, we should upgrade |
401 break; | 371 break; |
402 case 0: // existing version is same, do nothing | 372 case 0: // existing version is same, do nothing |
403 return; | 373 return; |
404 case 1: // existing version is newer, uh-oh | 374 case 1: // existing version is newer, uh-oh |
405 LOG(WARNING) << "Found external version of extension " << id | 375 LOG(WARNING) << "Found external version of extension " << id |
406 << "that is older than current version. Current version " | 376 << "that is older than current version. Current version " |
407 << "is: " << existing->VersionString() << ". New version " | 377 << "is: " << existing->VersionString() << ". New version " |
408 << "is: " << version << ". Keeping current version."; | 378 << "is: " << version << ". Keeping current version."; |
409 return; | 379 return; |
410 } | 380 } |
411 } | 381 } |
412 | 382 |
413 new CrxInstaller(path, install_directory_, location, id, extensions_enabled_, | 383 CrxInstaller::Start(path, install_directory_, location, id, |
414 false, // not from gallery | 384 false, // don't delete crx when complete |
415 show_extensions_prompts(), | 385 backend_loop_, |
416 false, // don't delete crx when complete | 386 this, |
417 backend_loop_, | 387 NULL); // no client (silent install) |
418 this); | |
419 } | 388 } |
420 | 389 |
421 | 390 |
422 // ExtensionsServicesBackend | 391 // ExtensionsServicesBackend |
423 | 392 |
424 ExtensionsServiceBackend::ExtensionsServiceBackend( | 393 ExtensionsServiceBackend::ExtensionsServiceBackend( |
425 const FilePath& install_directory, MessageLoop* frontend_loop) | 394 const FilePath& install_directory, MessageLoop* frontend_loop) |
426 : frontend_(NULL), | 395 : frontend_(NULL), |
427 install_directory_(install_directory), | 396 install_directory_(install_directory), |
428 alert_on_error_(false), | 397 alert_on_error_(false), |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 linked_ptr<ExternalExtensionProvider>(test_provider); | 576 linked_ptr<ExternalExtensionProvider>(test_provider); |
608 } | 577 } |
609 | 578 |
610 void ExtensionsServiceBackend::OnExternalExtensionFound( | 579 void ExtensionsServiceBackend::OnExternalExtensionFound( |
611 const std::string& id, const Version* version, const FilePath& path, | 580 const std::string& id, const Version* version, const FilePath& path, |
612 Extension::Location location) { | 581 Extension::Location location) { |
613 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_, | 582 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_, |
614 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(), | 583 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(), |
615 path, location)); | 584 path, location)); |
616 } | 585 } |
OLD | NEW |