diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-22 22:36:20 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-22 22:36:20 +0000 |
commit | 7e9f4a8e17e918412cfba8337e55873abed112cb (patch) | |
tree | 49363f7f49844e68f858677aa5bef4e081b2e0df /chrome/browser/extensions | |
parent | 8c157cf900b7ae30185b4905ac51c39dfc2c90ad (diff) | |
download | chromium_src-7e9f4a8e17e918412cfba8337e55873abed112cb.zip chromium_src-7e9f4a8e17e918412cfba8337e55873abed112cb.tar.gz chromium_src-7e9f4a8e17e918412cfba8337e55873abed112cb.tar.bz2 |
Refactor ExtensionActionContextMenuModel.
- Simplify constructor
- Rename to ExtensionContextMenuModel.*
- Remove views/extension_action_context_menu.*
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1107007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_action_context_menu_model.h | 67 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_context_menu_model.cc (renamed from chrome/browser/extensions/extension_action_context_menu_model.cc) | 96 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_context_menu_model.h | 70 |
3 files changed, 116 insertions, 117 deletions
diff --git a/chrome/browser/extensions/extension_action_context_menu_model.h b/chrome/browser/extensions/extension_action_context_menu_model.h deleted file mode 100644 index a35d269..0000000 --- a/chrome/browser/extensions/extension_action_context_menu_model.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2009 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_ACTION_CONTEXT_MENU_MODEL_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_MODEL_H_ - -#include "app/menus/simple_menu_model.h" -#include "chrome/browser/extensions/extension_install_ui.h" - -class Extension; -class ExtensionAction; -class PrefService; - -// The menu model for the context menu for extension action icons (browser and -// page actions). -class ExtensionActionContextMenuModel - : public menus::SimpleMenuModel, - public menus::SimpleMenuModel::Delegate, - public ExtensionInstallUI::Delegate { - public: - // Delegate to handle menu commands. - class MenuDelegate { - public: - // Called when the user selects the menu item which requests that the - // popup be shown and inspected. - virtual void ShowPopupForDevToolsWindow(Extension* extension, - ExtensionAction* extension_action) { - } - }; - - // |extension_action|, |prefs|, & |delegate| call all be NULL. If valid - // values are provided for all three, and prefs::kExtensionsUIDeveloperMode - // is enabled in the PrefService, a menu item will be shown for "Inspect - // Popup" which, when selected, will cause ShowPopupForDevToolsWindow() to be - // called on |delegate|. - ExtensionActionContextMenuModel(Extension* extension, - ExtensionAction* extension_action, - PrefService* prefs, - MenuDelegate* delegate); - ~ExtensionActionContextMenuModel(); - - // SimpleMenuModel behavior overrides. - virtual bool IsCommandIdChecked(int command_id) const; - virtual bool IsCommandIdEnabled(int command_id) const; - virtual bool GetAcceleratorForCommandId(int command_id, - menus::Accelerator* accelerator); - virtual void ExecuteCommand(int command_id); - - // ExtensionInstallUI::Delegate overrides. - virtual void InstallUIProceed(bool create_app); - virtual void InstallUIAbort() {} - - private: - // The extension we are displaying the context menu for. - Extension* extension_; - - // The extension action we are displaying the context menu for. - ExtensionAction* extension_action_; - - // The delegate which handles the 'inspect popup' menu command. - MenuDelegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionActionContextMenuModel); -}; - -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_MODEL_H_ diff --git a/chrome/browser/extensions/extension_action_context_menu_model.cc b/chrome/browser/extensions/extension_context_menu_model.cc index fa49c4e..2c3be7d 100644 --- a/chrome/browser/extensions/extension_action_context_menu_model.cc +++ b/chrome/browser/extensions/extension_context_menu_model.cc @@ -1,11 +1,11 @@ -// 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. -#include "chrome/browser/extensions/extension_action_context_menu_model.h" +#include "chrome/browser/extensions/extension_context_menu_model.h" #include "app/l10n_util.h" -#include "chrome/browser/browser_list.h" +#include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extensions_service.h" @@ -27,36 +27,46 @@ enum MenuEntries { INSPECT_POPUP }; -ExtensionActionContextMenuModel::ExtensionActionContextMenuModel( - Extension* extension, ExtensionAction* extension_action, PrefService* prefs, - MenuDelegate* delegate) - : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), - extension_(extension), - extension_action_(extension_action), - delegate_(delegate) { - AddItem(NAME, UTF8ToUTF16(extension->name())); - AddSeparator(); - AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS); - AddItemWithStringId(DISABLE, IDS_EXTENSIONS_DISABLE); - AddItemWithStringId(UNINSTALL, IDS_EXTENSIONS_UNINSTALL); - AddSeparator(); - AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); +ExtensionContextMenuModel::ExtensionContextMenuModel( + Extension* extension, + Browser* browser, + PopupDelegate* delegate) + : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), + extension_(extension), + browser_(browser), + profile_(browser->profile()), + delegate_(delegate) { + extension_action_ = extension->browser_action(); + if (!extension_action_) + extension_action_ = extension->page_action(); + + InitCommonCommands(); - if (extension_ && delegate_ && prefs && - prefs->GetBoolean(prefs::kExtensionsUIDeveloperMode)) { + if (profile_->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode) && + delegate_) { AddSeparator(); AddItemWithStringId(INSPECT_POPUP, IDS_EXTENSION_ACTION_INSPECT_POPUP); } } -ExtensionActionContextMenuModel::~ExtensionActionContextMenuModel() { +ExtensionContextMenuModel::~ExtensionContextMenuModel() { +} + +void ExtensionContextMenuModel::InitCommonCommands() { + AddItem(NAME, UTF8ToUTF16(extension_->name())); + AddSeparator(); + AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS); + AddItemWithStringId(DISABLE, IDS_EXTENSIONS_DISABLE); + AddItemWithStringId(UNINSTALL, IDS_EXTENSIONS_UNINSTALL); + AddSeparator(); + AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); } -bool ExtensionActionContextMenuModel::IsCommandIdChecked(int command_id) const { +bool ExtensionContextMenuModel::IsCommandIdChecked(int command_id) const { return false; } -bool ExtensionActionContextMenuModel::IsCommandIdEnabled(int command_id) const { +bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const { if (command_id == CONFIGURE) { return extension_->options_url().spec().length() > 0; } else if (command_id == NAME) { @@ -66,46 +76,35 @@ bool ExtensionActionContextMenuModel::IsCommandIdEnabled(int command_id) const { // for now. return extension_->update_url().DomainIs("google.com"); } else if (command_id == INSPECT_POPUP) { - if (!delegate_ || !extension_) - return false; - Browser* browser = BrowserList::GetLastActive(); - if (!browser) - return false; - TabContents* contents = browser->GetSelectedTabContents(); + TabContents* contents = browser_->GetSelectedTabContents(); if (!contents) return false; - // Different tabs can have different popups set. We need to make sure we - // only enable the menu item if the current tab has a popup. - return (extension_action_->HasPopup(ExtensionTabUtil::GetTabId(contents))); + return extension_action_->HasPopup(ExtensionTabUtil::GetTabId(contents)); } return true; } -bool ExtensionActionContextMenuModel::GetAcceleratorForCommandId( +bool ExtensionContextMenuModel::GetAcceleratorForCommandId( int command_id, menus::Accelerator* accelerator) { return false; } -void ExtensionActionContextMenuModel::ExecuteCommand(int command_id) { - // TODO(finnur): GetLastActive returns NULL in unit tests. - Browser* browser = BrowserList::GetLastActive(); - Profile* profile = browser->profile(); - +void ExtensionContextMenuModel::ExecuteCommand(int command_id) { switch (command_id) { case NAME: { GURL url(std::string(extension_urls::kGalleryBrowsePrefix) + std::string("/detail/") + extension_->id()); - browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); + browser_->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); break; } case CONFIGURE: DCHECK(!extension_->options_url().is_empty()); - profile->GetExtensionProcessManager()->OpenOptionsPage(extension_, - browser); + profile_->GetExtensionProcessManager()->OpenOptionsPage(extension_, + browser_); break; case DISABLE: { - ExtensionsService* extension_service = profile->GetExtensionsService(); + ExtensionsService* extension_service = profile_->GetExtensionsService(); extension_service->DisableExtension(extension_->id()); break; } @@ -114,18 +113,17 @@ void ExtensionActionContextMenuModel::ExecuteCommand(int command_id) { Extension::DecodeIcon(extension_, Extension::EXTENSION_ICON_LARGE, &uninstall_icon); - ExtensionInstallUI client(profile); + ExtensionInstallUI client(profile_); client.ConfirmUninstall(this, extension_, uninstall_icon.get()); break; } case MANAGE: { - browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(), - SINGLETON_TAB, PageTransition::LINK); + browser_->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(), + SINGLETON_TAB, PageTransition::LINK); break; } case INSPECT_POPUP: { - if (delegate_) - delegate_->ShowPopupForDevToolsWindow(extension_, extension_action_); + delegate_->InspectPopup(extension_action_); break; } default: @@ -134,11 +132,9 @@ void ExtensionActionContextMenuModel::ExecuteCommand(int command_id) { } } -void ExtensionActionContextMenuModel::InstallUIProceed(bool create_app) { +void ExtensionContextMenuModel::InstallUIProceed(bool create_app) { DCHECK(!create_app); - // TODO(finnur): GetLastActive returns NULL in unit tests. - Browser* browser = BrowserList::GetLastActive(); std::string id = extension_->id(); - browser->profile()->GetExtensionsService()->UninstallExtension(id, false); + profile_->GetExtensionsService()->UninstallExtension(id, false); } diff --git a/chrome/browser/extensions/extension_context_menu_model.h b/chrome/browser/extensions/extension_context_menu_model.h new file mode 100644 index 0000000..21667ef --- /dev/null +++ b/chrome/browser/extensions/extension_context_menu_model.h @@ -0,0 +1,70 @@ +// 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. + +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ + +#include "app/menus/simple_menu_model.h" +#include "chrome/browser/extensions/extension_install_ui.h" + +class Browser; +class Extension; +class ExtensionAction; +class Profile; + +// The menu model for the context menu for extension action icons (browser and +// page actions). +class ExtensionContextMenuModel + : public menus::SimpleMenuModel, + public menus::SimpleMenuModel::Delegate, + public ExtensionInstallUI::Delegate { + public: + // Delegate to handle showing an ExtensionAction popup. + class PopupDelegate { + public: + // Called when the user selects the menu item which requests that the + // popup be shown and inspected. + virtual void InspectPopup(ExtensionAction* action) = 0; + }; + + // Creates a menu model for the given extension action. If + // prefs::kExtensionsUIDeveloperMode is enabled then a menu item + // will be shown for "Inspect Popup" which, when selected, will cause + // ShowPopupForDevToolsWindow() to be called on |delegate|. + ExtensionContextMenuModel(Extension* extension, + Browser* browser, + PopupDelegate* delegate); + virtual ~ExtensionContextMenuModel(); + + // SimpleMenuModel::Delegate overrides. + virtual bool IsCommandIdChecked(int command_id) const; + virtual bool IsCommandIdEnabled(int command_id) const; + virtual bool GetAcceleratorForCommandId(int command_id, + menus::Accelerator* accelerator); + virtual void ExecuteCommand(int command_id); + + // ExtensionInstallUI::Delegate overrides. + virtual void InstallUIProceed(bool create_app); + virtual void InstallUIAbort() {} + + private: + void InitCommonCommands(); + + // The extension we are displaying the menu for. + Extension* extension_; + + // The extension action we are displaying the menu for (or NULL). + ExtensionAction* extension_action_; + + Browser* browser_; + + Profile* profile_; + + // The delegate which handles the 'inspect popup' menu command (or NULL). + PopupDelegate* delegate_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel); +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |