diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 16:00:34 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 16:00:34 +0000 |
commit | 699e1cd56df7b6f775601c80e99d26f83162a412 (patch) | |
tree | 22d80a14e0ddd552731daac0be3aa2e6dc8bd9ec /chrome/browser/extensions/extension_install_ui.cc | |
parent | bfae5e6625d0b3cd38d1b7481a12f6a177a2fbde (diff) | |
download | chromium_src-699e1cd56df7b6f775601c80e99d26f83162a412.zip chromium_src-699e1cd56df7b6f775601c80e99d26f83162a412.tar.gz chromium_src-699e1cd56df7b6f775601c80e99d26f83162a412.tar.bz2 |
Eliminate all UI thread decoding of extension images.
Except one, that is. We have one location we need to
take a look at (I've added a comment). This changelist
converts UI usage of DecodeImage on the UI thread to
a revamped and simplified ImageLoadingTracker class.
I plan on adding to GetFilePath a DCHECK for the File
thread but decided to do so in another changelist,
since it has a high likelyhood of flushing something
out and be backed out because of that. This started
out as issue 38521 (make infobar use cached icons)
but grew in scope to just eliminate all UI thread
access to DecodeImage and GetFilePath.
BUG=http://crbug.com/38521
TEST=None (extensions should work as before)
Review URL: http://codereview.chromium.org/1075006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_install_ui.cc')
-rw-r--r-- | chrome/browser/extensions/extension_install_ui.cc | 120 |
1 files changed, 76 insertions, 44 deletions
diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index e7a8406..f36f02b 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -127,16 +127,22 @@ static std::wstring GetInstallWarning(Extension* extension) { } // namespace ExtensionInstallUI::ExtensionInstallUI(Profile* profile) - : profile_(profile), ui_loop_(MessageLoop::current()) + : profile_(profile), + ui_loop_(MessageLoop::current()), + extension_(NULL), + delegate_(NULL), + prompt_type_(NUM_PROMPT_TYPES), + ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) #if defined(TOOLKIT_GTK) - ,previous_use_gtk_theme_(false) + , previous_use_gtk_theme_(false) #endif {} void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, - Extension* extension, - SkBitmap* install_icon) { + Extension* extension) { DCHECK(ui_loop_ == MessageLoop::current()); + extension_ = extension; + delegate_ = delegate; // We special-case themes to not show any confirm UI. Instead they are // immediately installed, and then we show an infobar (see OnInstallSuccess) @@ -148,7 +154,7 @@ void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, previous_theme_id_ = previous_theme->id(); #if defined(TOOLKIT_GTK) - // On linux, we also need to take the user's system settings into account + // On Linux, we also need to take the user's system settings into account // to undo theme installation. previous_use_gtk_theme_ = GtkThemeProvider::GetFrom(profile_)->UseGtkTheme(); @@ -158,53 +164,25 @@ void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, return; } - if (!install_icon) { - install_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_EXTENSION_DEFAULT_ICON); - } - icon_ = *install_icon; - - NotificationService* service = NotificationService::current(); - service->Notify(NotificationType::EXTENSION_WILL_SHOW_CONFIRM_DIALOG, - Source<ExtensionInstallUI>(this), - NotificationService::NoDetails()); - - ShowExtensionInstallUIPromptImpl( - profile_, delegate, extension, &icon_, - WideToUTF16Hack(GetInstallWarning(extension)), INSTALL_PROMPT); + ShowConfirmation(INSTALL_PROMPT); } void ExtensionInstallUI::ConfirmUninstall(Delegate* delegate, - Extension* extension, - SkBitmap* icon) { + Extension* extension) { DCHECK(ui_loop_ == MessageLoop::current()); + extension_ = extension; + delegate_ = delegate; - if (!icon) { - icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_EXTENSION_DEFAULT_ICON); - } - - string16 message = - l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_CONFIRMATION); - ShowExtensionInstallUIPromptImpl(profile_, delegate, extension, icon, - message, UNINSTALL_PROMPT); + ShowConfirmation(UNINSTALL_PROMPT); } void ExtensionInstallUI::ConfirmEnableIncognito(Delegate* delegate, - Extension* extension, - SkBitmap* icon) { + Extension* extension) { DCHECK(ui_loop_ == MessageLoop::current()); + extension_ = extension; + delegate_ = delegate; - if (!icon) { - icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_EXTENSION_DEFAULT_ICON); - } - - string16 message = - l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_INCOGNITO, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - ShowExtensionInstallUIPromptImpl(profile_, delegate, extension, icon, - message, ENABLE_INCOGNITO_PROMPT); + ShowConfirmation(ENABLE_INCOGNITO_PROMPT); } void ExtensionInstallUI::OnInstallSuccess(Extension* extension) { @@ -213,7 +191,7 @@ void ExtensionInstallUI::OnInstallSuccess(Extension* extension) { return; } - // GetLastActiveWithProfile will fail on the build bots. This needs to + // GetLastActiveWithProfile will fail on the build bots. This needs to be // implemented differently if any test is created which depends on // ExtensionInstalledBubble showing. #if defined(TOOLKIT_VIEWS) @@ -258,6 +236,50 @@ void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) { ShowThemeInfoBar(extension); } +void ExtensionInstallUI::OnImageLoaded( + SkBitmap* image, ExtensionResource resource, int index) { + if (image) + icon_ = *image; + else + icon_ = SkBitmap(); + if (icon_.empty()) { + icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_EXTENSION_DEFAULT_ICON); + } + + switch (prompt_type_) { + case INSTALL_PROMPT: { + NotificationService* service = NotificationService::current(); + service->Notify(NotificationType::EXTENSION_WILL_SHOW_CONFIRM_DIALOG, + Source<ExtensionInstallUI>(this), + NotificationService::NoDetails()); + + ShowExtensionInstallUIPromptImpl( + profile_, delegate_, extension_, &icon_, + WideToUTF16Hack(GetInstallWarning(extension_)), INSTALL_PROMPT); + break; + } + case UNINSTALL_PROMPT: { + string16 message = + l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_CONFIRMATION); + ShowExtensionInstallUIPromptImpl(profile_, delegate_, extension_, &icon_, + message, UNINSTALL_PROMPT); + break; + } + case ENABLE_INCOGNITO_PROMPT: { + string16 message = + l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_INCOGNITO, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); + ShowExtensionInstallUIPromptImpl(profile_, delegate_, extension_, &icon_, + message, ENABLE_INCOGNITO_PROMPT); + break; + } + default: + NOTREACHED() << "Unknown message"; + break; + } +} + void ExtensionInstallUI::ShowThemeInfoBar(Extension* new_theme) { if (!new_theme->IsTheme()) return; @@ -290,6 +312,16 @@ void ExtensionInstallUI::ShowThemeInfoBar(Extension* new_theme) { tab_contents->AddInfoBar(new_delegate); } +void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { + // Load the image asynchronously. For the response, check OnImageLoaded. + prompt_type_ = prompt_type; + ExtensionResource image = + extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE); + tracker_.LoadImage(image, + gfx::Size(Extension::EXTENSION_ICON_LARGE, + Extension::EXTENSION_ICON_LARGE)); +} + #if defined(OS_MACOSX) void ExtensionInstallUI::ShowGenericExtensionInstalledInfoBar( Extension* new_extension) { |