diff options
Diffstat (limited to 'chrome/browser')
5 files changed, 81 insertions, 56 deletions
diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index 144ea78f..1023a5a 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -26,6 +26,59 @@ #include <CoreFoundation/CFUserNotification.h> #endif +namespace { + +#if defined(OS_WIN) || defined(TOOLKIT_GTK) + +static std::wstring GetInstallWarning(Extension* extension) { + // If the extension has a plugin, it's easy: the plugin has the most severe + // warning. + if (!extension->plugins().empty()) + return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_FULL_ACCESS); + + // Otherwise, we go in descending order of severity: all hosts, several hosts, + // a single host, no hosts. For each of these, we also have a variation of the + // message for when api permissions are also requested. + if (extension->HasAccessToAllHosts()) { + if (extension->api_permissions().empty()) + return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_ALL_HOSTS); + else + return l10n_util::GetString( + IDS_EXTENSION_PROMPT_WARNING_NEW_ALL_HOSTS_AND_BROWSER); + } + + const std::set<std::string> hosts = extension->GetEffectiveHostPermissions(); + if (hosts.size() > 1) { + if (extension->api_permissions().empty()) + return l10n_util::GetString( + IDS_EXTENSION_PROMPT_WARNING_NEW_MULTIPLE_HOSTS); + else + return l10n_util::GetString( + IDS_EXTENSION_PROMPT_WARNING_NEW_MULTIPLE_HOSTS_AND_BROWSER); + } + + if (hosts.size() == 1) { + if (extension->api_permissions().empty()) + return l10n_util::GetStringF( + IDS_EXTENSION_PROMPT_WARNING_NEW_SINGLE_HOST, + UTF8ToWide(*hosts.begin())); + else + return l10n_util::GetStringF( + IDS_EXTENSION_PROMPT_WARNING_NEW_SINGLE_HOST_AND_BROWSER, + UTF8ToWide(*hosts.begin())); + } + + DCHECK(hosts.size() == 0); + if (extension->api_permissions().empty()) + return L""; + else + return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_BROWSER); +} + +#endif + +} + ExtensionInstallUI::ExtensionInstallUI(Profile* profile) : profile_(profile), ui_loop_(MessageLoop::current()) { } @@ -49,7 +102,8 @@ void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, } #if defined(OS_WIN) || defined(TOOLKIT_GTK) - ShowExtensionInstallPrompt(profile_, delegate, extension, install_icon); + ShowExtensionInstallPrompt(profile_, delegate, extension, install_icon, + GetInstallWarning(extension)); #elif defined(OS_MACOSX) // TODO(port): Implement nicer UI. diff --git a/chrome/browser/extensions/extension_install_ui.h b/chrome/browser/extensions/extension_install_ui.h index 1914989..0147d9c 100644 --- a/chrome/browser/extensions/extension_install_ui.h +++ b/chrome/browser/extensions/extension_install_ui.h @@ -9,6 +9,8 @@ #include "base/gfx/native_widget_types.h" #include "base/ref_counted.h" +#include <string> + class Extension; class ExtensionsService; class MessageLoop; @@ -34,7 +36,8 @@ class ExtensionInstallUI { static void ShowExtensionInstallPrompt(Profile* profile, Delegate* delegate, Extension* extension, - SkBitmap* install_icon); + SkBitmap* install_icon, + const std::wstring& warning_text); ExtensionInstallUI(Profile* profile); diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 9b19ba9..d389aa6 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -381,16 +381,16 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension) { Extension* old = GetExtensionByIdInternal(extension->id(), true, true); if (old) { if (extension->version()->CompareTo(*(old->version())) > 0) { - bool higher_permissions = - (extension->GetPermissionClass() > old->GetPermissionClass()); + bool allow_silent_upgrade = Extension::AllowSilentUpgrade( + old, extension); // To upgrade an extension in place, unload the old one and // then load the new one. UnloadExtension(old->id()); old = NULL; - if (higher_permissions) { - // Extension was upgraded to a high permission class. Disable it and + if (!allow_silent_upgrade) { + // Extension has changed permissions significantly. Disable it and // notify the user. extension_prefs_->SetExtensionState(extension, Extension::DISABLED); NotificationService::current()->Notify( diff --git a/chrome/browser/gtk/extension_install_prompt_gtk.cc b/chrome/browser/gtk/extension_install_prompt_gtk.cc index a195cff..c49102e 100644 --- a/chrome/browser/gtk/extension_install_prompt_gtk.cc +++ b/chrome/browser/gtk/extension_install_prompt_gtk.cc @@ -126,10 +126,9 @@ void ShowInstallPromptDialog(GtkWindow* parent, SkBitmap* skia_icon, } // namespace -void ExtensionInstallUI::ShowExtensionInstallPrompt(Profile* profile, - Delegate* delegate, - Extension* extension, - SkBitmap* icon) { +void ExtensionInstallUI::ShowExtensionInstallPrompt( + Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon, + const std::wstring& warning_text) { Browser* browser = BrowserList::GetLastActiveWithProfile(profile); if (!browser) { delegate->ContinueInstall(); diff --git a/chrome/browser/views/extensions/extension_install_prompt.cc b/chrome/browser/views/extensions/extension_install_prompt.cc index 6c58914..cc7d41c 100644 --- a/chrome/browser/views/extensions/extension_install_prompt.cc +++ b/chrome/browser/views/extensions/extension_install_prompt.cc @@ -23,24 +23,18 @@ class Profile; namespace { -const int kRightColumnWidth = 290; +const int kRightColumnWidth = 270; +const int kIconSize = 85; // Implements the extension installation prompt for Windows. -// TODO(aa): It would be cool to add an "extensions threat level" when we have -// granular permissions implemented: -// - red: npapi -// - orange: access to any domains -// - yellow: access to browser data -// - green: nothing -// We could have a collection of funny descriptions for each color. class InstallDialogContent : public views::View, public views::DialogDelegate { public: InstallDialogContent(ExtensionInstallUI::Delegate* delegate, - Extension* extension, - SkBitmap* icon) - : delegate_(delegate), icon_(NULL) { + Extension* extension, SkBitmap* icon, const std::wstring& warning_text) + : delegate_(delegate), icon_(NULL) { if (icon) { icon_ = new views::ImageView(); + icon_->SetImageSize(gfx::Size(kIconSize, kIconSize)); icon_->SetImage(*icon); AddChildView(icon_); } @@ -53,25 +47,10 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(heading_); - // Pick a random warning. - std::wstring warnings[] = { - l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_1), - l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_2), - l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_3) - }; - warning_ = new views::Label( - warnings[base::RandInt(0, arraysize(warnings) - 1)]); + warning_ = new views::Label(warning_text); warning_->SetMultiLine(true); warning_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(warning_); - - severe_ = new views::Label( - l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_SEVERE)); - severe_->SetMultiLine(true); - severe_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - severe_->SetFont(heading_->GetFont().DeriveFont(0, gfx::Font::BOLD)); - severe_->SetColor(SK_ColorRED); - AddChildView(severe_); } private: @@ -116,7 +95,7 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { int width = kRightColumnWidth + kPanelHorizMargin + kPanelHorizMargin; if (icon_) { - width += Extension::EXTENSION_ICON_LARGE; + width += kIconSize; width += kPanelHorizMargin; } @@ -125,11 +104,8 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { height += kPanelVertMargin; height += warning_->GetHeightForWidth(kRightColumnWidth); height += kPanelVertMargin; - height += severe_->GetHeightForWidth(kRightColumnWidth); - height += kPanelVertMargin; - return gfx::Size(width, std::max(height, - static_cast<int>(Extension::EXTENSION_ICON_LARGE))); + return gfx::Size(width, std::max(height, kIconSize)); } virtual void Layout() { @@ -137,9 +113,8 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { int y = kPanelVertMargin; if (icon_) { - icon_->SetBounds(x, y, Extension::EXTENSION_ICON_LARGE, - Extension::EXTENSION_ICON_LARGE); - x += Extension::EXTENSION_ICON_LARGE; + icon_->SetBounds(x, y, kIconSize, kIconSize); + x += kIconSize; x += kPanelHorizMargin; } @@ -156,28 +131,21 @@ class InstallDialogContent : public views::View, public views::DialogDelegate { y += warning_->height(); y += kPanelVertMargin; - - severe_->SizeToFit(kRightColumnWidth); - severe_->SetX(x); - severe_->SetY(y); - y += severe_->height(); } ExtensionInstallUI::Delegate* delegate_; views::ImageView* icon_; views::Label* heading_; views::Label* warning_; - views::Label* severe_; DISALLOW_COPY_AND_ASSIGN(InstallDialogContent); }; } // namespace -void ExtensionInstallUI::ShowExtensionInstallPrompt(Profile* profile, - Delegate* delegate, - Extension* extension, - SkBitmap* icon) { +void ExtensionInstallUI::ShowExtensionInstallPrompt( + Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon, + const std::wstring& warning_text) { Browser* browser = BrowserList::GetLastActiveWithProfile(profile); if (!browser) { delegate->ContinueInstall(); @@ -191,5 +159,6 @@ void ExtensionInstallUI::ShowExtensionInstallPrompt(Profile* profile, } views::Window::CreateChromeWindow(window->GetNativeHandle(), gfx::Rect(), - new InstallDialogContent(delegate, extension, icon))->Show(); + new InstallDialogContent(delegate, extension, icon, + warning_text))->Show(); } |