diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-22 00:58:03 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-22 00:58:03 +0000 |
commit | edb6e773afb3a46322ea64eaf4bb0f0f4eb7e726 (patch) | |
tree | 6badee320045177f58468a5d3b1159d036d75b4e | |
parent | e99683d890ef5a52c87bd91aa896a1e1daad9789 (diff) | |
download | chromium_src-edb6e773afb3a46322ea64eaf4bb0f0f4eb7e726.zip chromium_src-edb6e773afb3a46322ea64eaf4bb0f0f4eb7e726.tar.gz chromium_src-edb6e773afb3a46322ea64eaf4bb0f0f4eb7e726.tar.bz2 |
Revert 127903 - Revert 127887 - Replace extension disabled infobar with a global error.
Move disabled-extension interface to namespace extensions.
It looks like this:
http://dl.dropbox.com/u/27111995/Mocks/disable-dialog.png
http://dl.dropbox.com/u/27111995/Mocks/disable-menu.png
BUG=108202
TEST=install extension, update to version that requires additional permissions. Accept upgrade. Uninstall manually from chrome://extensions. Don't crash.
Review URL: http://codereview.chromium.org/9718008
TBR=yoz@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9802007
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9812033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128124 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chrome_command_ids.h | 2 | ||||
-rw-r--r-- | chrome/app/generated_resources.grd | 11 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_disabled_infobar_delegate.cc | 195 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_disabled_ui.cc | 291 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_disabled_ui.h (renamed from chrome/browser/extensions/extension_disabled_infobar_delegate.h) | 12 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_disabled_ui_browsertest.cc | 81 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_management_browsertest.cc | 79 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/extension_settings_handler.cc | 6 | ||||
-rw-r--r-- | chrome/chrome_browser_extensions.gypi | 4 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 |
11 files changed, 397 insertions, 289 deletions
diff --git a/chrome/app/chrome_command_ids.h b/chrome/app/chrome_command_ids.h index 9153113..5726389 100644 --- a/chrome/app/chrome_command_ids.h +++ b/chrome/app/chrome_command_ids.h @@ -176,6 +176,8 @@ #define IDC_SHOW_SETTINGS_CHANGE_FIRST 40033 #define IDC_SHOW_SETTINGS_CHANGE_LAST 40133 #define IDC_SHOW_AVATAR_MENU 40134 +#define IDC_EXTENSION_DISABLED_FIRST 40135 +#define IDC_EXTENSION_DISABLED_LAST 40235 // Spell-check // Insert any additional suggestions before _LAST; these have to be consecutive. diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 7b4b82d..cb1ff33 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -3919,16 +3919,19 @@ Public Exponent (<ph name="PUBLIC_EXPONENT_NUM_BITS">$3<ex>24</ex></ph> bits): Undo </message> - <!-- Extension/App disabled info bar --> - <message name="IDS_EXTENSION_DISABLED_INFOBAR_LABEL" desc="Text displayed on an infobar when an extension was disabled due to a new upgrade requiring an explicit permission check from the user."> + <!-- Extension/App disabled notification --> + <message name="IDS_EXTENSION_DISABLED_ERROR_LABEL" desc="Text displayed when an extension was disabled due to a new upgrade requiring an explicit permission check from the user."> The newest version of the extension "<ph name="EXTENSION_NAME">$1<ex>Flashblock</ex></ph>" requires more permissions, so it has been disabled. </message> - <message name="IDS_APP_DISABLED_INFOBAR_LABEL" desc="Text displayed on an infobar when an app was disabled due to a new upgrade requiring an explicit permission check from the user."> + <message name="IDS_APP_DISABLED_ERROR_LABEL" desc="Text displayed when an app was disabled due to a new upgrade requiring an explicit permission check from the user."> The newest version of the app "<ph name="APP_NAME">$1<ex>Pandora</ex></ph>" requires more permissions, so it has been disabled. </message> - <message name="IDS_EXTENSION_DISABLED_INFOBAR_ENABLE_BUTTON" desc="Text displayed on the button to re-enable the disabled extension or app."> + <message name="IDS_EXTENSION_DISABLED_ERROR_ENABLE_BUTTON" desc="Text displayed on the button to re-enable the disabled extension or app."> Re-enable </message> + <message name="IDS_EXTENSION_DISABLED_ERROR_TITLE" desc="Title of the notification that an extension or app was disabled due to a new upgrade requiring an explicit permission check from the user."> + <ph name="EXTENSION_NAME">$1<ex>Adblock</ex></ph> requires new permissions + </message> <!-- Extension/App install prompt --> <message name="IDS_EXTENSION_INSTALL_PROMPT_TITLE" desc="Titlebar of the extension or app installation prompt window"> diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc deleted file mode 100644 index a090e95..0000000 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2011 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. - -#include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" - -#include <string> - -#include "base/compiler_specific.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/extensions/extension_install_ui.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/infobars/infobar_tab_helper.h" -#include "chrome/browser/tab_contents/confirm_infobar_delegate.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/chrome_notification_types.h" -#include "chrome/common/extensions/extension_file_util.h" -#include "chrome/common/extensions/extension_resource.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/web_contents.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -// ExtensionDisabledDialogDelegate -------------------------------------------- - -class ExtensionDisabledDialogDelegate - : public ExtensionInstallUI::Delegate, - public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { - public: - ExtensionDisabledDialogDelegate(Profile* profile, - ExtensionService* service, - const Extension* extension); - - private: - friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>; - - virtual ~ExtensionDisabledDialogDelegate(); - - // ExtensionInstallUI::Delegate: - virtual void InstallUIProceed() OVERRIDE; - virtual void InstallUIAbort(bool user_initiated) OVERRIDE; - - // The UI for showing the install dialog when enabling. - scoped_ptr<ExtensionInstallUI> install_ui_; - - ExtensionService* service_; - const Extension* extension_; -}; - -ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate( - Profile* profile, - ExtensionService* service, - const Extension* extension) - : service_(service), extension_(extension) { - AddRef(); // Balanced in Proceed or Abort. - - install_ui_.reset(new ExtensionInstallUI(profile)); - install_ui_->ConfirmReEnable(this, extension_); -} - -ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() { -} - -void ExtensionDisabledDialogDelegate::InstallUIProceed() { - service_->GrantPermissionsAndEnableExtension(extension_); - Release(); -} - -void ExtensionDisabledDialogDelegate::InstallUIAbort(bool user_initiated) { - std::string histogram_name = user_initiated ? - "Extensions.Permissions_ReEnableCancel" : - "Extensions.Permissions_ReEnableAbort"; - ExtensionService::RecordPermissionMessagesHistogram( - extension_, histogram_name.c_str()); - - // Do nothing. The extension will remain disabled. - Release(); -} - - -// ExtensionDisabledInfobarDelegate ------------------------------------------- - -class ExtensionDisabledInfobarDelegate : public ConfirmInfoBarDelegate, - public content::NotificationObserver { - public: - ExtensionDisabledInfobarDelegate(InfoBarTabHelper* infobar_helper, - ExtensionService* service, - const Extension* extension); - - private: - virtual ~ExtensionDisabledInfobarDelegate(); - - // ConfirmInfoBarDelegate: - virtual string16 GetMessageText() const OVERRIDE; - virtual int GetButtons() const OVERRIDE; - virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; - virtual bool Accept() OVERRIDE; - - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - content::NotificationRegistrar registrar_; - ExtensionService* service_; - const Extension* extension_; -}; - -ExtensionDisabledInfobarDelegate::ExtensionDisabledInfobarDelegate( - InfoBarTabHelper* infobar_helper, - ExtensionService* service, - const Extension* extension) - : ConfirmInfoBarDelegate(infobar_helper), - service_(service), - extension_(extension) { - // The user might re-enable the extension in other ways, so watch for that. - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, - content::Source<Profile>(service->profile())); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, - content::Source<Profile>(service->profile())); -} - -ExtensionDisabledInfobarDelegate::~ExtensionDisabledInfobarDelegate() { -} - -string16 ExtensionDisabledInfobarDelegate::GetMessageText() const { - return l10n_util::GetStringFUTF16(extension_->is_app() ? - IDS_APP_DISABLED_INFOBAR_LABEL : IDS_EXTENSION_DISABLED_INFOBAR_LABEL, - UTF8ToUTF16(extension_->name())); -} - -int ExtensionDisabledInfobarDelegate::GetButtons() const { - return BUTTON_OK; -} - -string16 ExtensionDisabledInfobarDelegate::GetButtonLabel( - InfoBarButton button) const { - DCHECK_EQ(BUTTON_OK, button); - return l10n_util::GetStringUTF16( - IDS_EXTENSION_DISABLED_INFOBAR_ENABLE_BUTTON); -} - -bool ExtensionDisabledInfobarDelegate::Accept() { - // This object manages its own lifetime. - new ExtensionDisabledDialogDelegate(service_->profile(), service_, - extension_); - return true; -} - -void ExtensionDisabledInfobarDelegate::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - // TODO(mpcomplete): RemoveInfoBar doesn't seem to always result in us getting - // deleted. - const Extension* extension = NULL; - if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { - extension = content::Details<const Extension>(details).ptr(); - } else { - DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); - UnloadedExtensionInfo* info = - content::Details<UnloadedExtensionInfo>(details).ptr(); - extension = info->extension; - } - if (extension == extension_) - RemoveSelf(); -} - - -// Globals -------------------------------------------------------------------- - -void ShowExtensionDisabledUI(ExtensionService* service, - Profile* profile, - const Extension* extension) { - Browser* browser = BrowserList::GetLastActiveWithProfile(profile); - if (!browser) - return; - - TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper(); - if (!tab_contents) - return; - - InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); - infobar_helper->AddInfoBar( - new ExtensionDisabledInfobarDelegate(infobar_helper, service, extension)); -} - -void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile, - const Extension* extension) { - // This object manages its own lifetime. - new ExtensionDisabledDialogDelegate(profile, service, extension); -} diff --git a/chrome/browser/extensions/extension_disabled_ui.cc b/chrome/browser/extensions/extension_disabled_ui.cc new file mode 100644 index 0000000..86afcbb --- /dev/null +++ b/chrome/browser/extensions/extension_disabled_ui.cc @@ -0,0 +1,291 @@ +// Copyright (c) 2012 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. + +#include "chrome/browser/extensions/extension_disabled_ui.h" + +#include <string> + +#include "base/bind.h" +#include "base/lazy_instance.h" +#include "base/message_loop.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/utf_string_conversions.h" +#include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/extensions/extension_install_ui.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_uninstall_dialog.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/global_error.h" +#include "chrome/browser/ui/global_error_service.h" +#include "chrome/browser/ui/global_error_service_factory.h" +#include "chrome/common/chrome_notification_types.h" +#include "chrome/common/extensions/extension.h" +#include "content/public/browser/notification_details.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" +#include "content/public/browser/notification_source.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" + +namespace { + +static base::LazyInstance< + std::bitset<IDC_EXTENSION_DISABLED_LAST - + IDC_EXTENSION_DISABLED_FIRST + 1> > + menu_command_ids = LAZY_INSTANCE_INITIALIZER; + +// Get an available menu ID. +int GetMenuCommandID() { + int id; + for (id = IDC_EXTENSION_DISABLED_FIRST; + id <= IDC_EXTENSION_DISABLED_LAST; ++id) { + if (!menu_command_ids.Get()[id - IDC_EXTENSION_DISABLED_FIRST]) { + menu_command_ids.Get().set(id - IDC_EXTENSION_DISABLED_FIRST); + return id; + } + } + // This should not happen. + DCHECK(id <= IDC_EXTENSION_DISABLED_LAST) << + "No available menu command IDs for ExtensionDisabledGlobalError"; + return IDC_EXTENSION_DISABLED_LAST; +} + +// Make a menu ID available when it is no longer used. +void ReleaseMenuCommandID(int id) { + menu_command_ids.Get().reset(id - IDC_EXTENSION_DISABLED_FIRST); +} + +} // namespace + +// ExtensionDisabledDialogDelegate -------------------------------------------- + +class ExtensionDisabledDialogDelegate + : public ExtensionInstallUI::Delegate, + public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { + public: + ExtensionDisabledDialogDelegate(Profile* profile, + ExtensionService* service, + const Extension* extension); + + private: + friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>; + + virtual ~ExtensionDisabledDialogDelegate(); + + // ExtensionInstallUI::Delegate: + virtual void InstallUIProceed() OVERRIDE; + virtual void InstallUIAbort(bool user_initiated) OVERRIDE; + + // The UI for showing the install dialog when enabling. + scoped_ptr<ExtensionInstallUI> install_ui_; + + ExtensionService* service_; + const Extension* extension_; +}; + +ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate( + Profile* profile, + ExtensionService* service, + const Extension* extension) + : service_(service), extension_(extension) { + AddRef(); // Balanced in Proceed or Abort. + + install_ui_.reset(new ExtensionInstallUI(profile)); + install_ui_->ConfirmReEnable(this, extension_); +} + +ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() { +} + +void ExtensionDisabledDialogDelegate::InstallUIProceed() { + service_->GrantPermissionsAndEnableExtension(extension_); + Release(); +} + +void ExtensionDisabledDialogDelegate::InstallUIAbort(bool user_initiated) { + std::string histogram_name = user_initiated ? + "Extensions.Permissions_ReEnableCancel" : + "Extensions.Permissions_ReEnableAbort"; + ExtensionService::RecordPermissionMessagesHistogram( + extension_, histogram_name.c_str()); + + // Do nothing. The extension will remain disabled. + Release(); +} + +// ExtensionDisabledGlobalError ----------------------------------------------- + +class ExtensionDisabledGlobalError : public GlobalError, + public content::NotificationObserver, + public ExtensionUninstallDialog::Delegate { + public: + ExtensionDisabledGlobalError(ExtensionService* service, + const Extension* extension); + virtual ~ExtensionDisabledGlobalError(); + + // GlobalError implementation. + virtual bool HasBadge() OVERRIDE; + virtual bool HasMenuItem() OVERRIDE; + virtual int MenuItemCommandID() OVERRIDE; + virtual string16 MenuItemLabel() OVERRIDE; + virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; + virtual bool HasBubbleView() OVERRIDE; + virtual string16 GetBubbleViewTitle() OVERRIDE; + virtual string16 GetBubbleViewMessage() OVERRIDE; + virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; + virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; + virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; + virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; + virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; + + // ExtensionUninstallDialog::Delegate implementation. + virtual void ExtensionUninstallAccepted() OVERRIDE; + virtual void ExtensionUninstallCanceled() OVERRIDE; + + // content::NotificationObserver implementation. + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + private: + ExtensionService* service_; + const Extension* extension_; + + scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_; + + // Menu command ID assigned for this extension's error. + int menu_command_id_; + + content::NotificationRegistrar registrar_; +}; + +// TODO(yoz): create error at startup for disabled extensions. +ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( + ExtensionService* service, + const Extension* extension) + : service_(service), + extension_(extension), + menu_command_id_(GetMenuCommandID()) { + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, + content::Source<Profile>(service->profile())); + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, + content::Source<Profile>(service->profile())); +} + +ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() { +} + +bool ExtensionDisabledGlobalError::HasBadge() { + return true; +} + +bool ExtensionDisabledGlobalError::HasMenuItem() { + return true; +} + +int ExtensionDisabledGlobalError::MenuItemCommandID() { + return menu_command_id_; +} + +string16 ExtensionDisabledGlobalError::MenuItemLabel() { + return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, + UTF8ToUTF16(extension_->name())); +} + +void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) { + ShowBubbleView(browser); +} + +bool ExtensionDisabledGlobalError::HasBubbleView() { + return true; +} + +string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() { + return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, + UTF8ToUTF16(extension_->name())); +} + +string16 ExtensionDisabledGlobalError::GetBubbleViewMessage() { + return l10n_util::GetStringFUTF16(extension_->is_app() ? + IDS_APP_DISABLED_ERROR_LABEL : IDS_EXTENSION_DISABLED_ERROR_LABEL, + UTF8ToUTF16(extension_->name())); +} + +string16 ExtensionDisabledGlobalError::GetBubbleViewAcceptButtonLabel() { + return l10n_util::GetStringUTF16( + IDS_EXTENSION_DISABLED_ERROR_ENABLE_BUTTON); +} + +string16 ExtensionDisabledGlobalError::GetBubbleViewCancelButtonLabel() { + return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL); +} + +void ExtensionDisabledGlobalError::OnBubbleViewDidClose(Browser* browser) { +} + +void ExtensionDisabledGlobalError::BubbleViewAcceptButtonPressed( + Browser* browser) { + new ExtensionDisabledDialogDelegate(service_->profile(), service_, + extension_); +} + +void ExtensionDisabledGlobalError::BubbleViewCancelButtonPressed( + Browser* browser) { + uninstall_dialog_.reset( + ExtensionUninstallDialog::Create(service_->profile(), this)); + uninstall_dialog_->ConfirmUninstall(extension_); +} + +void ExtensionDisabledGlobalError::ExtensionUninstallAccepted() { + service_->UninstallExtension(extension_->id(), false, NULL); +} + +void ExtensionDisabledGlobalError::ExtensionUninstallCanceled() { + // Nothing happens, and the error is still there. +} + +void ExtensionDisabledGlobalError::Observe( + int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + const Extension* extension = NULL; + // The error is invalidated if the extension has been reloaded + // or unloaded. + if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { + extension = content::Details<const Extension>(details).ptr(); + } else { + DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); + UnloadedExtensionInfo* info = + content::Details<UnloadedExtensionInfo>(details).ptr(); + extension = info->extension; + } + if (extension == extension_) { + GlobalErrorServiceFactory::GetForProfile(service_->profile())-> + RemoveGlobalError(this); + ReleaseMenuCommandID(menu_command_id_); + delete this; + } +} + +// Globals -------------------------------------------------------------------- + +namespace extensions { + +void ShowExtensionDisabledUI(ExtensionService* service, + Profile* profile, + const Extension* extension) { + GlobalErrorServiceFactory::GetForProfile(service->profile())-> + AddGlobalError(new ExtensionDisabledGlobalError(service, extension)); +} + +void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile, + const Extension* extension) { + // This object manages its own lifetime. + new ExtensionDisabledDialogDelegate(profile, service, extension); +} + +} // namespace extensions diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.h b/chrome/browser/extensions/extension_disabled_ui.h index 665b0eb..f851805 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.h +++ b/chrome/browser/extensions/extension_disabled_ui.h @@ -1,15 +1,17 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DISABLED_INFOBAR_DELEGATE_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DISABLED_INFOBAR_DELEGATE_H_ +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DISABLED_UI_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DISABLED_UI_H_ #pragma once class Extension; class ExtensionService; class Profile; +namespace extensions { + // Shows UI to inform the user that an extension was disabled after upgrading // to higher permissions. void ShowExtensionDisabledUI(ExtensionService* service, Profile* profile, @@ -19,4 +21,6 @@ void ShowExtensionDisabledUI(ExtensionService* service, Profile* profile, void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile, const Extension* extension); -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DISABLED_INFOBAR_DELEGATE_H_ +} // namespace extensions + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DISABLED_UI_H_ diff --git a/chrome/browser/extensions/extension_disabled_ui_browsertest.cc b/chrome/browser/extensions/extension_disabled_ui_browsertest.cc new file mode 100644 index 0000000..d908fa0 --- /dev/null +++ b/chrome/browser/extensions/extension_disabled_ui_browsertest.cc @@ -0,0 +1,81 @@ +// Copyright (c) 2012 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. + +#include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/extensions/extension_browsertest.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/global_error_service.h" +#include "chrome/browser/ui/global_error_service_factory.h" +#include "chrome/common/extensions/extension.h" + +class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest { + protected: + void SetUpOnMainThread() { + service_ = browser()->profile()->GetExtensionService(); + } + + // Returns the ExtensionDisabledGlobalError, if present. + // Caution: currently only supports one error at a time. + GlobalError* GetExtensionDisabledGlobalError() { + return GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> + GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_DISABLED_FIRST); + } + + // Helper function to install an extension and upgrade it to a version + // requiring additional permissions. Returns the new disabled Extension. + const Extension* InstallAndUpdateIncreasingPermissionsExtension() { + size_t size_before = service_->extensions()->size(); + + // Install the initial version, which should happen just fine. + const Extension* extension = InstallExtension( + test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1); + if (!extension) + return NULL; + if (service_->extensions()->size() != size_before + 1) + return NULL; + + // Upgrade to a version that wants more permissions. We should disable the + // extension and prompt the user to reenable. + if (UpdateExtension( + extension->id(), + test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) + return NULL; + EXPECT_EQ(size_before, service_->extensions()->size()); + if (service_->disabled_extensions()->size() != 1u) + return NULL; + + return *service_->disabled_extensions()->begin(); + } + + ExtensionService* service_; +}; + +// Tests the process of updating an extension to one that requires higher +// permissions, and accepting the permissions. +IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, AcceptPermissions) { + const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); + ASSERT_TRUE(extension); + ASSERT_TRUE(GetExtensionDisabledGlobalError()); + const size_t size_before = service_->extensions()->size(); + + service_->GrantPermissionsAndEnableExtension(extension); + EXPECT_EQ(size_before + 1, service_->extensions()->size()); + EXPECT_EQ(0u, service_->disabled_extensions()->size()); + ASSERT_FALSE(GetExtensionDisabledGlobalError()); +} + +// Tests uninstalling an extension that was disabled due to higher permissions. +IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, Uninstall) { + const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); + ASSERT_TRUE(extension); + ASSERT_TRUE(GetExtensionDisabledGlobalError()); + const size_t size_before = service_->extensions()->size(); + + UninstallExtension(extension->id()); + EXPECT_EQ(size_before, service_->extensions()->size()); + EXPECT_EQ(0u, service_->disabled_extensions()->size()); + ASSERT_FALSE(GetExtensionDisabledGlobalError()); +} diff --git a/chrome/browser/extensions/extension_management_browsertest.cc b/chrome/browser/extensions/extension_management_browsertest.cc index 5777708..672d26e 100644 --- a/chrome/browser/extensions/extension_management_browsertest.cc +++ b/chrome/browser/extensions/extension_management_browsertest.cc @@ -59,33 +59,6 @@ class ExtensionManagementTest : public ExtensionBrowserTest { return false; return true; } - - // Helper method that installs a low permission extension then updates - // to the second version requiring increased permissions. Returns whether - // the operation was completed successfully. - bool InstallAndUpdateIncreasingPermissionsExtension() { - ExtensionService* service = browser()->profile()->GetExtensionService(); - size_t size_before = service->extensions()->size(); - - // Install the initial version, which should happen just fine. - const Extension* extension = InstallExtension( - test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1); - if (!extension) - return false; - if (service->extensions()->size() != size_before + 1) - return false; - - // Upgrade to a version that wants more permissions. We should disable the - // extension and prompt the user to reenable. - if (UpdateExtension( - extension->id(), - test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) - return false; - EXPECT_EQ(size_before, service->extensions()->size()); - if (service->disabled_extensions()->size() != 1u) - return false; - return true; - } }; #if defined(OS_LINUX) @@ -148,58 +121,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallRequiresConfirm) { UninstallExtension(id); } -// Tests the process of updating an extension to one that requires higher -// permissions. -IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissions) { - ExtensionService* service = browser()->profile()->GetExtensionService(); - ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); - const size_t size_before = service->extensions()->size(); - - // Now try reenabling it. - const std::string id = (*service->disabled_extensions()->begin())->id(); - service->EnableExtension(id); - EXPECT_EQ(size_before + 1, service->extensions()->size()); - EXPECT_EQ(0u, service->disabled_extensions()->size()); -} - -// Tests uninstalling an extension that was disabled due to higher permissions. -IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissionsAndUninstall) { - ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); - - // Make sure the "disable extension" infobar is present. - ASSERT_EQ(0, browser()->active_index()); - InfoBarTabHelper* infobar_helper = browser()->GetTabContentsWrapperAt(0)-> - infobar_tab_helper(); - ASSERT_EQ(1U, infobar_helper->infobar_count()); - - // Uninstall, and check that the infobar went away. - ExtensionService* service = browser()->profile()->GetExtensionService(); - std::string id = (*service->disabled_extensions()->begin())->id(); - UninstallExtension(id); - ASSERT_EQ(0U, infobar_helper->infobar_count()); - - // Now select a new tab, and switch back to the first tab which had the - // infobar. We should not crash. - ASSERT_EQ(1, browser()->tab_count()); - ASSERT_EQ(0, browser()->active_index()); - browser()->NewTab(); - ASSERT_EQ(2, browser()->tab_count()); - ASSERT_EQ(1, browser()->active_index()); - browser()->ActivateTabAt(0, true); -} - -// Tests that we can uninstall a disabled extension. -IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UninstallDisabled) { - ExtensionService* service = browser()->profile()->GetExtensionService(); - ASSERT_TRUE(InstallAndUpdateIncreasingPermissionsExtension()); - const size_t size_before = service->extensions()->size(); - - // Now try uninstalling it. - UninstallExtension((*service->disabled_extensions()->begin())->id()); - EXPECT_EQ(size_before, service->extensions()->size()); - EXPECT_EQ(0u, service->disabled_extensions()->size()); -} - // Tests that disabling and re-enabling an extension works. IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, DisableEnable) { ExtensionProcessManager* manager = browser()->profile()-> diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index b0dd944..50699fe 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -51,7 +51,7 @@ #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/default_apps_trial.h" #include "chrome/browser/extensions/extension_browser_event_router.h" -#include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" +#include "chrome/browser/extensions/extension_disabled_ui.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_helper.h" @@ -4427,7 +4427,7 @@ void Browser::Observe(int type, content::Details<const Extension>(details).ptr(); if (service->extension_prefs()->DidExtensionEscalatePermissions( extension->id())) - ShowExtensionDisabledUI(service, profile_, extension); + extensions::ShowExtensionDisabledUI(service, profile_, extension); } break; } diff --git a/chrome/browser/ui/webui/options/extension_settings_handler.cc b/chrome/browser/ui/webui/options/extension_settings_handler.cc index f04b6a5..bf6aa99 100644 --- a/chrome/browser/ui/webui/options/extension_settings_handler.cc +++ b/chrome/browser/ui/webui/options/extension_settings_handler.cc @@ -16,7 +16,7 @@ #include "base/version.h" #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/extensions/crx_installer.h" -#include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" +#include "chrome/browser/extensions/extension_disabled_ui.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_warning_set.h" #include "chrome/browser/extensions/unpacked_installer.h" @@ -313,8 +313,8 @@ void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { if (enable_str == "true") { ExtensionPrefs* prefs = extension_service_->extension_prefs(); if (prefs->DidExtensionEscalatePermissions(extension_id)) { - ShowExtensionDisabledDialog(extension_service_, - Profile::FromWebUI(web_ui()), extension); + extensions::ShowExtensionDisabledDialog( + extension_service_, Profile::FromWebUI(web_ui()), extension); } else { extension_service_->EnableExtension(extension_id); } diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 2d7351d..2926ff5 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -207,8 +207,8 @@ 'browser/extensions/extension_devtools_events.h', 'browser/extensions/extension_devtools_manager.cc', 'browser/extensions/extension_devtools_manager.h', - 'browser/extensions/extension_disabled_infobar_delegate.cc', - 'browser/extensions/extension_disabled_infobar_delegate.h', + 'browser/extensions/extension_disabled_ui.cc', + 'browser/extensions/extension_disabled_ui.h', 'browser/extensions/extension_error_reporter.cc', 'browser/extensions/extension_error_reporter.h', 'browser/extensions/extension_event_names.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 765114c..1596223 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2686,6 +2686,7 @@ 'browser/extensions/extension_devtools_browsertest.cc', 'browser/extensions/extension_devtools_browsertest.h', 'browser/extensions/extension_devtools_browsertests.cc', + 'browser/extensions/extension_disabled_ui_browsertest.cc', 'browser/extensions/extension_dom_clipboard_apitest.cc', 'browser/extensions/extension_fileapi_apitest.cc', 'browser/extensions/extension_font_settings_apitest.cc', |