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/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "chrome/common/extensions/extension_file_util.h" | 40 #include "chrome/common/extensions/extension_file_util.h" |
41 #include "chrome/common/extensions/extension_icon_set.h" | 41 #include "chrome/common/extensions/extension_icon_set.h" |
42 #include "chrome/common/extensions/extension_switch_utils.h" | 42 #include "chrome/common/extensions/extension_switch_utils.h" |
43 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
44 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/resource_dispatcher_host.h" | 45 #include "content/public/browser/resource_dispatcher_host.h" |
46 #include "content/public/browser/user_metrics.h" | 46 #include "content/public/browser/user_metrics.h" |
47 #include "grit/chromium_strings.h" | 47 #include "grit/chromium_strings.h" |
48 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
49 #include "grit/theme_resources.h" | 49 #include "grit/theme_resources.h" |
| 50 #include "skia/ext/image_operations.h" |
50 #include "third_party/skia/include/core/SkBitmap.h" | 51 #include "third_party/skia/include/core/SkBitmap.h" |
51 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
52 #include "ui/base/resource/resource_bundle.h" | 53 #include "ui/base/resource/resource_bundle.h" |
53 | 54 |
54 using content::BrowserThread; | 55 using content::BrowserThread; |
55 using content::UserMetricsAction; | 56 using content::UserMetricsAction; |
56 | 57 |
57 namespace extensions { | 58 namespace extensions { |
58 | 59 |
59 namespace { | 60 namespace { |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return; | 386 return; |
386 } | 387 } |
387 | 388 |
388 if (client_) { | 389 if (client_) { |
389 Extension::DecodeIcon(extension_.get(), | 390 Extension::DecodeIcon(extension_.get(), |
390 extension_misc::EXTENSION_ICON_LARGE, | 391 extension_misc::EXTENSION_ICON_LARGE, |
391 ExtensionIconSet::MATCH_BIGGER, | 392 ExtensionIconSet::MATCH_BIGGER, |
392 &install_icon_); | 393 &install_icon_); |
393 } | 394 } |
394 | 395 |
| 396 PreloadIcons(); |
| 397 |
395 if (!BrowserThread::PostTask( | 398 if (!BrowserThread::PostTask( |
396 BrowserThread::UI, FROM_HERE, | 399 BrowserThread::UI, FROM_HERE, |
397 base::Bind(&CrxInstaller::CheckRequirements, this))) | 400 base::Bind(&CrxInstaller::CheckRequirements, this))) |
398 NOTREACHED(); | 401 NOTREACHED(); |
399 } | 402 } |
400 | 403 |
401 void CrxInstaller::CheckRequirements() { | 404 void CrxInstaller::CheckRequirements() { |
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
403 AddRef(); // Balanced in OnRequirementsChecked(). | 406 AddRef(); // Balanced in OnRequirementsChecked(). |
404 requirements_checker_->Check(extension_, | 407 requirements_checker_->Check(extension_, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 record_oauth2_grant_ = client_->record_oauth2_grant(); | 626 record_oauth2_grant_ = client_->record_oauth2_grant(); |
624 | 627 |
625 // We update the extension's granted permissions if the user already approved | 628 // We update the extension's granted permissions if the user already approved |
626 // the install (client_ is non NULL), or we are allowed to install this | 629 // the install (client_ is non NULL), or we are allowed to install this |
627 // silently. | 630 // silently. |
628 if (client_ || allow_silent_install_) { | 631 if (client_ || allow_silent_install_) { |
629 PermissionsUpdater perms_updater(profile()); | 632 PermissionsUpdater perms_updater(profile()); |
630 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); | 633 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); |
631 } | 634 } |
632 | 635 |
| 636 CachePreloadedIcons(); |
| 637 |
633 // Tell the frontend about the installation and hand off ownership of | 638 // Tell the frontend about the installation and hand off ownership of |
634 // extension_ to it. | 639 // extension_ to it. |
635 frontend_weak_->OnExtensionInstalled(extension_, | 640 frontend_weak_->OnExtensionInstalled(extension_, |
636 is_gallery_install(), | 641 is_gallery_install(), |
637 page_ordinal_, | 642 page_ordinal_, |
638 has_requirement_errors_); | 643 has_requirement_errors_); |
639 | 644 |
640 NotifyCrxInstallComplete(extension_.get()); | 645 NotifyCrxInstallComplete(extension_.get()); |
641 | 646 |
642 extension_ = NULL; | 647 extension_ = NULL; |
643 | 648 |
644 // We're done. We don't post any more tasks to ourselves so we are deleted | 649 // We're done. We don't post any more tasks to ourselves so we are deleted |
645 // soon. | 650 // soon. |
646 } | 651 } |
647 | 652 |
648 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { | 653 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { |
649 // Some users (such as the download shelf) need to know when a | 654 // Some users (such as the download shelf) need to know when a |
650 // CRXInstaller is done. Listening for the EXTENSION_* events | 655 // CRXInstaller is done. Listening for the EXTENSION_* events |
651 // is problematic because they don't know anything about the | 656 // is problematic because they don't know anything about the |
652 // extension before it is unpacked, so they cannot filter based | 657 // extension before it is unpacked, so they cannot filter based |
653 // on the extension. | 658 // on the extension. |
654 content::NotificationService::current()->Notify( | 659 content::NotificationService::current()->Notify( |
655 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 660 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
656 content::Source<CrxInstaller>(this), | 661 content::Source<CrxInstaller>(this), |
657 content::Details<const Extension>(extension)); | 662 content::Details<const Extension>(extension)); |
658 } | 663 } |
659 | 664 |
| 665 void CrxInstaller::PreloadIcons() { |
| 666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 667 |
| 668 for (std::set<int>::const_iterator it = preload_sizes_.begin(); |
| 669 it != preload_sizes_.end(); ++it) { |
| 670 scoped_ptr<SkBitmap> icon(new SkBitmap()); |
| 671 |
| 672 const int requested_size = *it; |
| 673 Extension::DecodeIcon(extension_.get(), |
| 674 requested_size, |
| 675 ExtensionIconSet::MATCH_BIGGER, |
| 676 &icon); |
| 677 if (icon->empty()) |
| 678 continue; |
| 679 |
| 680 if (icon->width() != requested_size || |
| 681 icon->height() != requested_size) { |
| 682 *icon = skia::ImageOperations::Resize( |
| 683 *icon, skia::ImageOperations::RESIZE_LANCZOS3, |
| 684 requested_size, requested_size); |
| 685 } |
| 686 |
| 687 preload_map_[*it] = *icon.get(); |
| 688 } |
| 689 } |
| 690 |
| 691 void CrxInstaller::CachePreloadedIcons() { |
| 692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 693 |
| 694 for (std::map<int, SkBitmap>::const_iterator it = preload_map_.begin(); |
| 695 it != preload_map_.end(); ++it) { |
| 696 const std::string icon_path = extension_->icons().Get( |
| 697 it->first, ExtensionIconSet::MATCH_BIGGER); |
| 698 ExtensionResource icon_resource = extension_->GetResource(icon_path); |
| 699 if (icon_resource.empty()) { |
| 700 NOTREACHED(); |
| 701 continue; |
| 702 } |
| 703 |
| 704 extension_->SetCachedImage(icon_resource, |
| 705 it->second, |
| 706 gfx::Size(it->first, it->first)); |
| 707 } |
| 708 } |
| 709 |
660 } // namespace extensions | 710 } // namespace extensions |
OLD | NEW |