diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-19 07:18:45 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-19 07:18:45 +0000 |
commit | 21217cab5b687af94175570fc301b6e33dc4e085 (patch) | |
tree | 6d9f74816baeb04301b44d88ad17afa2dabb74eb /chrome | |
parent | f1c42aa16ff81a4983d17b717513e231e1850ab2 (diff) | |
download | chromium_src-21217cab5b687af94175570fc301b6e33dc4e085.zip chromium_src-21217cab5b687af94175570fc301b6e33dc4e085.tar.gz chromium_src-21217cab5b687af94175570fc301b6e33dc4e085.tar.bz2 |
Only create a desktop shortcut for apps if the user requests.
BUG=32361
Review URL: http://codereview.chromium.org/551052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36513 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
14 files changed, 103 insertions, 37 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 5361c23..d8f349f 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -2793,7 +2793,10 @@ each locale. --> Confirm Uninstallation </message> <message name="IDS_EXTENSION_INSTALL_PROMPT_HEADING" desc="First bold line in the content area of the extension installation prompt. Asks the user if they want to install a particular extension."> - Install "<ph name="EXTENSION_NAME">$1<ex>Gmail Checker</ex></ph>"? + Install <ph name="EXTENSION_NAME">$1<ex>Gmail Checker</ex></ph>? + </message> + <message name="IDS_EXTENSION_PROMPT_CREATE_SHORTCUT" desc="Label for checkbox that asks the user if they want to create a desktop shortcut for an app install."> + Create desktop shortcut </message> <message name="IDS_EXTENSION_UNINSTALL_PROMPT_HEADING" desc="First bold line in the content area of the extension uninstallation prompt. Asks the user if they want to uninstall a particular extension."> Uninstall "<ph name="EXTENSION_NAME">$1<ex>Gmail Checker</ex></ph>"? diff --git a/chrome/browser/cocoa/extension_install_prompt.mm b/chrome/browser/cocoa/extension_install_prompt.mm index 059bd7d..d53fc19 100644 --- a/chrome/browser/cocoa/extension_install_prompt.mm +++ b/chrome/browser/cocoa/extension_install_prompt.mm @@ -43,7 +43,7 @@ void ExtensionInstallUI::ShowExtensionInstallUIPromptImpl( [alert setIcon:gfx::SkBitmapToNSImage(*icon)]; if ([alert runModal] == NSAlertFirstButtonReturn) { - delegate->InstallUIProceed(); + delegate->InstallUIProceed(false); } else { delegate->InstallUIAbort(); } diff --git a/chrome/browser/cocoa/extensions/extension_action_context_menu.mm b/chrome/browser/cocoa/extensions/extension_action_context_menu.mm index ee3c6ae..ff7cd40 100644 --- a/chrome/browser/cocoa/extensions/extension_action_context_menu.mm +++ b/chrome/browser/cocoa/extensions/extension_action_context_menu.mm @@ -37,7 +37,8 @@ class AsyncUninstaller : public base::RefCountedThreadSafe<AsyncUninstaller>, } // Overridden by ExtensionInstallUI::Delegate. - virtual void InstallUIProceed() { + virtual void InstallUIProceed(bool create_shortcut) { + DCHECK(!create_shortcut); Browser* browser = BrowserList::GetLastActive(); // GetLastActive() returns NULL during testing. if (!browser) diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index defeff4..675fc02 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -87,6 +87,7 @@ CrxInstaller::CrxInstaller(const FilePath& source_file, install_source_(Extension::INTERNAL), delete_source_(delete_source), allow_privilege_increase_(false), + create_app_shortcut_(false), frontend_(frontend), client_(client) { extensions_enabled_ = frontend_->extensions_enabled(); @@ -190,7 +191,12 @@ void CrxInstaller::ConfirmInstall() { return; } -void CrxInstaller::InstallUIProceed() { +void CrxInstaller::InstallUIProceed(bool create_app_shortcut) { + if (create_app_shortcut) { + DCHECK(extension_->IsApp()); + create_app_shortcut_ = true; + } + ChromeThread::PostTask( ChromeThread::FILE, FROM_HERE, NewRunnableMethod(this, &CrxInstaller::CompleteInstall)); @@ -237,7 +243,7 @@ void CrxInstaller::CompleteInstall() { return; } - if (extension_->IsApp()) { + if (create_app_shortcut_) { SkBitmap icon = install_icon_.get() ? *install_icon_ : *ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_EXTENSION_DEFAULT_ICON); diff --git a/chrome/browser/extensions/crx_installer.h b/chrome/browser/extensions/crx_installer.h index 30f0cd5..0b19fef 100644 --- a/chrome/browser/extensions/crx_installer.h +++ b/chrome/browser/extensions/crx_installer.h @@ -72,7 +72,7 @@ class CrxInstaller ExtensionInstallUI* client); // ExtensionInstallUI::Delegate - virtual void InstallUIProceed(); + virtual void InstallUIProceed(bool create_app_shortcut); virtual void InstallUIAbort(); private: @@ -138,6 +138,11 @@ class CrxInstaller // previously installed version of the extension. bool allow_privilege_increase_; + // Whether to create an app shortcut after successful installation. This is + // set based on the user's selection in the UI and can only ever be true for + // apps. + bool create_app_shortcut_; + // The extension we're installing. We own this and either pass it off to // ExtensionsService on success, or delete it on failure. scoped_ptr<Extension> extension_; diff --git a/chrome/browser/extensions/extension_action_context_menu_model.cc b/chrome/browser/extensions/extension_action_context_menu_model.cc index 1a0409a..ec87bbe 100644 --- a/chrome/browser/extensions/extension_action_context_menu_model.cc +++ b/chrome/browser/extensions/extension_action_context_menu_model.cc @@ -96,7 +96,9 @@ void ExtensionActionContextMenuModel::ExecuteCommand(int command_id) { } } -void ExtensionActionContextMenuModel::InstallUIProceed() { +void ExtensionActionContextMenuModel::InstallUIProceed(bool create_app) { + DCHECK(!create_app); + // TODO(finnur): GetLastActive returns NULL in unit tests. Browser* browser = BrowserList::GetLastActive(); std::string id = extension_->id(); diff --git a/chrome/browser/extensions/extension_action_context_menu_model.h b/chrome/browser/extensions/extension_action_context_menu_model.h index 3dbf8bf..1a8e664 100644 --- a/chrome/browser/extensions/extension_action_context_menu_model.h +++ b/chrome/browser/extensions/extension_action_context_menu_model.h @@ -28,7 +28,7 @@ class ExtensionActionContextMenuModel virtual void ExecuteCommand(int command_id); // ExtensionInstallUI::Delegate overrides. - virtual void InstallUIProceed(); + virtual void InstallUIProceed(bool create_app); virtual void InstallUIAbort() {} private: diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc index c95c2bb..dd12915 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc @@ -37,7 +37,7 @@ class ExtensionDisabledDialogDelegate } // ExtensionInstallUI::Delegate - virtual void InstallUIProceed() { + virtual void InstallUIProceed(bool create_app_shortcut) { ExtensionPrefs* prefs = service_->extension_prefs(); prefs->SetShowInstallWarningOnEnable(extension_, false); service_->EnableExtension(extension_->id()); diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index d1b85f6..70347ff 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -147,7 +147,7 @@ void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, GtkThemeProvider::GetFrom(profile_)->UseGtkTheme(); #endif - delegate->InstallUIProceed(); + delegate->InstallUIProceed(false); return; } diff --git a/chrome/browser/extensions/extension_install_ui.h b/chrome/browser/extensions/extension_install_ui.h index b1f9c80..cda2076 100644 --- a/chrome/browser/extensions/extension_install_ui.h +++ b/chrome/browser/extensions/extension_install_ui.h @@ -28,7 +28,7 @@ class ExtensionInstallUI { public: // We call this method after ConfirmInstall()/ConfirmUninstall() to signal // that the installation/uninstallation should continue. - virtual void InstallUIProceed() = 0; + virtual void InstallUIProceed(bool create_app_shortcut) = 0; // We call this method after ConfirmInstall()/ConfirmUninstall() to signal // that the installation/uninstallation should stop. diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index eadeafe..63c40a3 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -422,7 +422,10 @@ void ExtensionsDOMHandler::HandleUninstallMessage(const Value* value) { client.ConfirmUninstall(this, extension, uninstall_icon.get()); } -void ExtensionsDOMHandler::InstallUIProceed() { +void ExtensionsDOMHandler::InstallUIProceed(bool create_app_shortcut) { + // We only ever use ExtensionInstallUI for uninstalling, which should never + // result in it telling us to create a shortcut. + DCHECK(!create_app_shortcut); extensions_service_->UninstallExtension(extension_id_uninstalling_, false); extension_id_uninstalling_ = ""; } diff --git a/chrome/browser/extensions/extensions_ui.h b/chrome/browser/extensions/extensions_ui.h index 21715ba..cabc5be 100644 --- a/chrome/browser/extensions/extensions_ui.h +++ b/chrome/browser/extensions/extensions_ui.h @@ -124,7 +124,7 @@ class ExtensionsDOMHandler // ExtensionInstallUI::Delegate implementation, used for receiving // notification about uninstall confirmation dialog selections. - virtual void InstallUIProceed(); + virtual void InstallUIProceed(bool create_app_shortcut); virtual void InstallUIAbort(); private: diff --git a/chrome/browser/gtk/extension_install_prompt_gtk.cc b/chrome/browser/gtk/extension_install_prompt_gtk.cc index 9e81375..26a8b90 100644 --- a/chrome/browser/gtk/extension_install_prompt_gtk.cc +++ b/chrome/browser/gtk/extension_install_prompt_gtk.cc @@ -40,7 +40,7 @@ GtkWidget* MakeMarkupLabel(const char* format, const std::string& str) { void OnDialogResponse(GtkDialog* dialog, int response_id, ExtensionInstallUI::Delegate* delegate) { if (response_id == GTK_RESPONSE_ACCEPT) { - delegate->InstallUIProceed(); + delegate->InstallUIProceed(false); } else { delegate->InstallUIAbort(); } diff --git a/chrome/browser/views/extensions/extension_install_prompt.cc b/chrome/browser/views/extensions/extension_install_prompt.cc index 80618ee..6a65291 100644 --- a/chrome/browser/views/extensions/extension_install_prompt.cc +++ b/chrome/browser/views/extensions/extension_install_prompt.cc @@ -11,6 +11,7 @@ #include "chrome/browser/extensions/extension_install_ui.h" #include "chrome/common/extensions/extension.h" #include "grit/generated_resources.h" +#include "views/controls/button/checkbox.h" #include "views/controls/image_view.h" #include "views/controls/label.h" #include "views/controls/link.h" @@ -27,8 +28,13 @@ class Profile; namespace { -const int kRightColumnWidth = 270; -const int kIconSize = 85; +// Since apps don't (currently) have any privilege disclosure text, the dialog +// looks a bit empty if it is sized the same as extensions. So we scale +// everything down a bit for apps for the time being. +const int kRightColumnWidthApp = 210; +const int kRightColumnWidthExtension = 270; +const int kIconSizeApp = 69; +const int kIconSizeExtension = 85; // Implements the extension installation prompt for Windows. class InstallDialogContent : public views::View, public views::DialogDelegate { @@ -36,11 +42,20 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { InstallDialogContent(ExtensionInstallUI::Delegate* delegate, Extension* extension, SkBitmap* icon, const std::wstring& warning_text, bool is_uninstall) - : delegate_(delegate), icon_(NULL), is_uninstall_(is_uninstall) { - // Scale down to 85x85, but allow smaller icons (don't scale up). + : delegate_(delegate), icon_(NULL), warning_(NULL), + is_uninstall_(NULL), create_shortcut_(NULL) { + if (extension->IsApp()) { + icon_size_ = kIconSizeApp; + right_column_width_ = kRightColumnWidthApp; + } else { + icon_size_ = kIconSizeExtension; + right_column_width_ = kRightColumnWidthExtension; + } + + // Scale down to icon size, but allow smaller icons (don't scale up). gfx::Size size(icon->width(), icon->height()); - if (size.width() > kIconSize || size.height() > kIconSize) - size = gfx::Size(kIconSize, kIconSize); + if (size.width() > icon_size_ || size.height() > icon_size_) + size = gfx::Size(icon_size_, icon_size_); icon_ = new views::ImageView(); icon_->SetImageSize(size); icon_->SetImage(*icon); @@ -56,10 +71,18 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(heading_); - warning_ = new views::Label(warning_text); - warning_->SetMultiLine(true); - warning_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - AddChildView(warning_); + if (!is_uninstall && extension->IsApp()) { + create_shortcut_ = new views::Checkbox( + l10n_util::GetString(IDS_EXTENSION_PROMPT_CREATE_SHORTCUT)); + create_shortcut_->SetChecked(true); + create_shortcut_->SetMultiLine(true); + AddChildView(create_shortcut_); + } else { + warning_ = new views::Label(warning_text); + warning_->SetMultiLine(true); + warning_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + AddChildView(warning_); + } } private: @@ -85,7 +108,8 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { } virtual bool Accept() { - delegate_->InstallUIProceed(); + delegate_->InstallUIProceed( + create_shortcut_ && create_shortcut_->checked()); return true; } @@ -107,38 +131,57 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { // View virtual gfx::Size GetPreferredSize() { - int width = kRightColumnWidth + kPanelHorizMargin + kPanelHorizMargin; - width += kIconSize; + int width = right_column_width_ + kPanelHorizMargin + kPanelHorizMargin; + width += icon_size_; width += kPanelHorizMargin; int height = kPanelVertMargin * 2; - height += heading_->GetHeightForWidth(kRightColumnWidth); + height += heading_->GetHeightForWidth(right_column_width_); height += kPanelVertMargin; - height += warning_->GetHeightForWidth(kRightColumnWidth); + + if (warning_) + height += warning_->GetHeightForWidth(right_column_width_); + else + height += create_shortcut_->GetPreferredSize().height(); + height += kPanelVertMargin; - return gfx::Size(width, std::max(height, kIconSize + kPanelVertMargin * 2)); + return gfx::Size(width, std::max(height, icon_size_ + kPanelVertMargin * 2)); } virtual void Layout() { int x = kPanelHorizMargin; int y = kPanelVertMargin; - icon_->SetBounds(x, y, kIconSize, kIconSize); - x += kIconSize; + icon_->SetBounds(x, y, icon_size_, icon_size_); + x += icon_size_; x += kPanelHorizMargin; - heading_->SizeToFit(kRightColumnWidth); + heading_->SizeToFit(right_column_width_); heading_->SetX(x); heading_->SetY(y); y += heading_->height(); y += kPanelVertMargin; - warning_->SizeToFit(kRightColumnWidth); - warning_->SetX(x); - warning_->SetY(y); - y += warning_->height(); + if (create_shortcut_) { + create_shortcut_->SetBounds(x, y, right_column_width_, 0); + create_shortcut_->SetBounds(x, y, right_column_width_, + create_shortcut_->GetPreferredSize().height()); + + int bottom_aligned = icon_->y() + icon_->height() - + create_shortcut_->height(); + if (bottom_aligned > y) { + create_shortcut_->SetY(bottom_aligned); + y = bottom_aligned; + } + y += create_shortcut_->height(); + } else { + warning_->SizeToFit(right_column_width_); + warning_->SetX(x); + warning_->SetY(y); + y += warning_->height(); + } y += kPanelVertMargin; } @@ -147,7 +190,10 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { views::ImageView* icon_; views::Label* heading_; views::Label* warning_; + views::Checkbox* create_shortcut_; bool is_uninstall_; + int right_column_width_; + int icon_size_; DISALLOW_COPY_AND_ASSIGN(InstallDialogContent); }; |