Index: chrome/browser/extensions/extension_context_menu_model.cc |
=================================================================== |
--- chrome/browser/extensions/extension_context_menu_model.cc (revision 41960) |
+++ chrome/browser/extensions/extension_context_menu_model.cc (working copy) |
@@ -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 @@ |
INSPECT_POPUP |
}; |
-ExtensionActionContextMenuModel::ExtensionActionContextMenuModel( |
- Extension* extension, ExtensionAction* extension_action, PrefService* prefs, |
- MenuDelegate* delegate) |
+ExtensionContextMenuModel::ExtensionContextMenuModel( |
+ Extension* extension, |
+ Browser* browser, |
+ PopupDelegate* delegate) |
: ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), |
Finnur
2010/03/22 21:10:09
nit: I believe you need 4 cols before the colon in
|
extension_(extension), |
- extension_action_(extension_action), |
+ browser_(browser), |
+ profile_(browser->profile()), |
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); |
+ extension_action_ = extension->browser_action(); |
+ if (!extension_action_) |
+ extension_action_ = extension->page_action(); |
- if (extension_ && delegate_ && prefs && |
- prefs->GetBoolean(prefs::kExtensionsUIDeveloperMode)) { |
+ InitCommonCommands(); |
+ |
+ if (profile_->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode) && |
+ delegate_) { |
AddSeparator(); |
AddItemWithStringId(INSPECT_POPUP, IDS_EXTENSION_ACTION_INSPECT_POPUP); |
} |
} |
-ExtensionActionContextMenuModel::~ExtensionActionContextMenuModel() { |
+ExtensionContextMenuModel::~ExtensionContextMenuModel() { |
} |
-bool ExtensionActionContextMenuModel::IsCommandIdChecked(int command_id) const { |
+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 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 @@ |
// 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 @@ |
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::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); |
} |
Property changes on: chrome/browser/extensions/extension_context_menu_model.cc |
___________________________________________________________________ |
Added: svn:mergeinfo |