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

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

Issue 9968076: Remove Inspect Popup command from browser actions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moved includes to cc Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_context_menu_model.h" 5 #include "chrome/browser/extensions/extension_context_menu_model.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_tab_util.h" 9 #include "chrome/browser/extensions/extension_tab_util.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
(...skipping 12 matching lines...) Expand all
23 using content::OpenURLParams; 23 using content::OpenURLParams;
24 using content::Referrer; 24 using content::Referrer;
25 using content::WebContents; 25 using content::WebContents;
26 26
27 enum MenuEntries { 27 enum MenuEntries {
28 NAME = 0, 28 NAME = 0,
29 CONFIGURE, 29 CONFIGURE,
30 HIDE, 30 HIDE,
31 DISABLE, 31 DISABLE,
32 UNINSTALL, 32 UNINSTALL,
33 MANAGE, 33 MANAGE
34 INSPECT_POPUP
35 }; 34 };
36 35
37 ExtensionContextMenuModel::ExtensionContextMenuModel( 36 ExtensionContextMenuModel::ExtensionContextMenuModel(
38 const Extension* extension, 37 const Extension* extension,
39 Browser* browser, 38 Browser* browser)
40 PopupDelegate* delegate)
41 : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), 39 : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)),
42 extension_id_(extension->id()), 40 extension_id_(extension->id()),
43 browser_(browser), 41 browser_(browser),
44 profile_(browser->profile()), 42 profile_(browser->profile()) {
45 delegate_(delegate) {
46 extension_action_ = extension->browser_action(); 43 extension_action_ = extension->browser_action();
47 if (!extension_action_) 44 if (!extension_action_)
48 extension_action_ = extension->page_action(); 45 extension_action_ = extension->page_action();
49 46
50 InitCommonCommands(); 47 InitCommonCommands();
51
52 if (profile_->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode) &&
53 delegate_) {
54 AddSeparator();
55 AddItemWithStringId(INSPECT_POPUP, IDS_EXTENSION_ACTION_INSPECT_POPUP);
56 }
57 } 48 }
58 49
59 ExtensionContextMenuModel::~ExtensionContextMenuModel() { 50 ExtensionContextMenuModel::~ExtensionContextMenuModel() {
60 } 51 }
61 52
62 void ExtensionContextMenuModel::InitCommonCommands() { 53 void ExtensionContextMenuModel::InitCommonCommands() {
63 const Extension* extension = GetExtension(); 54 const Extension* extension = GetExtension();
64 55
65 // The extension pointer should only be null if the extension was uninstalled, 56 // The extension pointer should only be null if the extension was uninstalled,
66 // and since the menu just opened, it should still be installed. 57 // and since the menu just opened, it should still be installed.
(...skipping 18 matching lines...) Expand all
85 const Extension* extension = this->GetExtension(); 76 const Extension* extension = this->GetExtension();
86 if (!extension) 77 if (!extension)
87 return false; 78 return false;
88 79
89 if (command_id == CONFIGURE) { 80 if (command_id == CONFIGURE) {
90 return extension->options_url().spec().length() > 0; 81 return extension->options_url().spec().length() > 0;
91 } else if (command_id == NAME) { 82 } else if (command_id == NAME) {
92 // The NAME links to the Homepage URL. If the extension doesn't have a 83 // The NAME links to the Homepage URL. If the extension doesn't have a
93 // homepage, we just disable this menu item. 84 // homepage, we just disable this menu item.
94 return extension->GetHomepageURL().is_valid(); 85 return extension->GetHomepageURL().is_valid();
95 } else if (command_id == INSPECT_POPUP) {
96 WebContents* contents = browser_->GetSelectedWebContents();
97 if (!contents)
98 return false;
99
100 return extension_action_->HasPopup(ExtensionTabUtil::GetTabId(contents));
101 } else if (command_id == DISABLE || command_id == UNINSTALL) { 86 } else if (command_id == DISABLE || command_id == UNINSTALL) {
102 // Some extension types can not be disabled or uninstalled. 87 // Some extension types can not be disabled or uninstalled.
103 return Extension::UserMayDisable(extension->location()); 88 return Extension::UserMayDisable(extension->location());
104 } 89 }
105 return true; 90 return true;
106 } 91 }
107 92
108 bool ExtensionContextMenuModel::GetAcceleratorForCommandId( 93 bool ExtensionContextMenuModel::GetAcceleratorForCommandId(
109 int command_id, ui::Accelerator* accelerator) { 94 int command_id, ui::Accelerator* accelerator) {
110 return false; 95 return false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 AddRef(); // Balanced in Accepted() and Canceled() 127 AddRef(); // Balanced in Accepted() and Canceled()
143 extension_uninstall_dialog_.reset( 128 extension_uninstall_dialog_.reset(
144 ExtensionUninstallDialog::Create(profile_, this)); 129 ExtensionUninstallDialog::Create(profile_, this));
145 extension_uninstall_dialog_->ConfirmUninstall(extension); 130 extension_uninstall_dialog_->ConfirmUninstall(extension);
146 break; 131 break;
147 } 132 }
148 case MANAGE: { 133 case MANAGE: {
149 browser_->ShowExtensionsTab(); 134 browser_->ShowExtensionsTab();
150 break; 135 break;
151 } 136 }
152 case INSPECT_POPUP: {
153 delegate_->InspectPopup(extension_action_);
154 break;
155 }
156 default: 137 default:
157 NOTREACHED() << "Unknown option"; 138 NOTREACHED() << "Unknown option";
158 break; 139 break;
159 } 140 }
160 } 141 }
161 142
162 void ExtensionContextMenuModel::ExtensionUninstallAccepted() { 143 void ExtensionContextMenuModel::ExtensionUninstallAccepted() {
163 if (GetExtension()) 144 if (GetExtension())
164 profile_->GetExtensionService()->UninstallExtension(extension_id_, false, 145 profile_->GetExtensionService()->UninstallExtension(extension_id_, false,
165 NULL); 146 NULL);
166 147
167 Release(); 148 Release();
168 } 149 }
169 150
170 void ExtensionContextMenuModel::ExtensionUninstallCanceled() { 151 void ExtensionContextMenuModel::ExtensionUninstallCanceled() {
171 Release(); 152 Release();
172 } 153 }
173 154
174 const Extension* ExtensionContextMenuModel::GetExtension() const { 155 const Extension* ExtensionContextMenuModel::GetExtension() const {
175 ExtensionService* extension_service = profile_->GetExtensionService(); 156 ExtensionService* extension_service = profile_->GetExtensionService();
176 return extension_service->GetExtensionById(extension_id_, false); 157 return extension_service->GetExtensionById(extension_id_, false);
177 } 158 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698