Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/extensions/extension_action_context_menu_model.cc

Issue 1001002: Initial support for inspecting extension popups. (Closed)
Patch Set: pre submit Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_action_context_menu_model.h" 5 #include "chrome/browser/extensions/extension_action_context_menu_model.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "chrome/browser/browser_list.h" 8 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/extension_tabs_module.h"
10 #include "chrome/browser/extensions/extensions_service.h" 11 #include "chrome/browser/extensions/extensions_service.h"
12 #include "chrome/browser/pref_service.h"
11 #include "chrome/browser/profile.h" 13 #include "chrome/browser/profile.h"
12 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_action.h"
13 #include "chrome/common/extensions/extension_constants.h" 16 #include "chrome/common/extensions/extension_constants.h"
17 #include "chrome/common/pref_names.h"
14 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
15 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
16 20
17 enum MenuEntries { 21 enum MenuEntries {
18 NAME = 0, 22 NAME = 0,
19 CONFIGURE, 23 CONFIGURE,
20 DISABLE, 24 DISABLE,
21 UNINSTALL, 25 UNINSTALL,
22 MANAGE, 26 MANAGE,
27 INSPECT_POPUP
23 }; 28 };
24 29
25 ExtensionActionContextMenuModel::ExtensionActionContextMenuModel( 30 ExtensionActionContextMenuModel::ExtensionActionContextMenuModel(
26 Extension* extension) 31 Extension* extension, ExtensionAction* extension_action, PrefService* prefs,
32 MenuDelegate* delegate)
27 : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), 33 : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)),
28 extension_(extension) { 34 extension_(extension),
35 extension_action_(extension_action),
36 delegate_(delegate) {
29 AddItem(NAME, UTF8ToUTF16(extension->name())); 37 AddItem(NAME, UTF8ToUTF16(extension->name()));
30 AddSeparator(); 38 AddSeparator();
31 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS); 39 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS);
32 AddItemWithStringId(DISABLE, IDS_EXTENSIONS_DISABLE); 40 AddItemWithStringId(DISABLE, IDS_EXTENSIONS_DISABLE);
33 AddItemWithStringId(UNINSTALL, IDS_EXTENSIONS_UNINSTALL); 41 AddItemWithStringId(UNINSTALL, IDS_EXTENSIONS_UNINSTALL);
34 AddSeparator(); 42 AddSeparator();
43 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS);
35 44
36 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); 45 if (extension_ && delegate_ && prefs &&
46 prefs->GetBoolean(prefs::kExtensionsUIDeveloperMode)) {
47 AddSeparator();
48 AddItemWithStringId(INSPECT_POPUP, IDS_EXTENSION_ACTION_INSPECT_POPUP);
49 }
37 } 50 }
38 51
39 ExtensionActionContextMenuModel::~ExtensionActionContextMenuModel() { 52 ExtensionActionContextMenuModel::~ExtensionActionContextMenuModel() {
40 } 53 }
41 54
42 bool ExtensionActionContextMenuModel::IsCommandIdChecked(int command_id) const { 55 bool ExtensionActionContextMenuModel::IsCommandIdChecked(int command_id) const {
43 return false; 56 return false;
44 } 57 }
45 58
46 bool ExtensionActionContextMenuModel::IsCommandIdEnabled(int command_id) const { 59 bool ExtensionActionContextMenuModel::IsCommandIdEnabled(int command_id) const {
47 if (command_id == CONFIGURE) { 60 if (command_id == CONFIGURE) {
48 return extension_->options_url().spec().length() > 0; 61 return extension_->options_url().spec().length() > 0;
49 } else if (command_id == NAME) { 62 } else if (command_id == NAME) {
50 // The NAME links to the gallery page, which only makes sense if Google is 63 // The NAME links to the gallery page, which only makes sense if Google is
51 // hosting the extension. For other 3rd party extensions we don't have a 64 // hosting the extension. For other 3rd party extensions we don't have a
52 // homepage url, so we just disable this menu item on those cases, at least 65 // homepage url, so we just disable this menu item on those cases, at least
53 // for now. 66 // for now.
54 return extension_->update_url().DomainIs("google.com"); 67 return extension_->update_url().DomainIs("google.com");
68 } else if (command_id == INSPECT_POPUP) {
69 if (!delegate_ || !extension_)
70 return false;
71 Browser* browser = BrowserList::GetLastActive();
72 if (!browser)
73 return false;
74 TabContents* contents = browser->GetSelectedTabContents();
75 if (!contents)
76 return false;
77
78 // Different tabs can have different popups set. We need to make sure we
79 // only enable the menu item if the current tab has a popup.
80 return (extension_action_->HasPopup(ExtensionTabUtil::GetTabId(contents)));
55 } 81 }
56 return true; 82 return true;
57 } 83 }
58 84
59 bool ExtensionActionContextMenuModel::GetAcceleratorForCommandId( 85 bool ExtensionActionContextMenuModel::GetAcceleratorForCommandId(
60 int command_id, menus::Accelerator* accelerator) { 86 int command_id, menus::Accelerator* accelerator) {
61 return false; 87 return false;
62 } 88 }
63 89
64 void ExtensionActionContextMenuModel::ExecuteCommand(int command_id) { 90 void ExtensionActionContextMenuModel::ExecuteCommand(int command_id) {
(...skipping 25 matching lines...) Expand all
90 116
91 ExtensionInstallUI client(profile); 117 ExtensionInstallUI client(profile);
92 client.ConfirmUninstall(this, extension_, uninstall_icon.get()); 118 client.ConfirmUninstall(this, extension_, uninstall_icon.get());
93 break; 119 break;
94 } 120 }
95 case MANAGE: { 121 case MANAGE: {
96 browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(), 122 browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(),
97 SINGLETON_TAB, PageTransition::LINK); 123 SINGLETON_TAB, PageTransition::LINK);
98 break; 124 break;
99 } 125 }
126 case INSPECT_POPUP: {
127 if (delegate_)
128 delegate_->ShowPopupForDevToolsWindow(extension_, extension_action_);
129 break;
130 }
100 default: 131 default:
101 NOTREACHED() << "Unknown option"; 132 NOTREACHED() << "Unknown option";
102 break; 133 break;
103 } 134 }
104 } 135 }
105 136
106 void ExtensionActionContextMenuModel::InstallUIProceed(bool create_app) { 137 void ExtensionActionContextMenuModel::InstallUIProceed(bool create_app) {
107 DCHECK(!create_app); 138 DCHECK(!create_app);
108 139
109 // TODO(finnur): GetLastActive returns NULL in unit tests. 140 // TODO(finnur): GetLastActive returns NULL in unit tests.
110 Browser* browser = BrowserList::GetLastActive(); 141 Browser* browser = BrowserList::GetLastActive();
111 std::string id = extension_->id(); 142 std::string id = extension_->id();
112 browser->profile()->GetExtensionsService()->UninstallExtension(id, false); 143 browser->profile()->GetExtensionsService()->UninstallExtension(id, false);
113 } 144 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_action_context_menu_model.h ('k') | chrome/browser/extensions/extension_dom_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698