OLD | NEW |
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 Loading... |
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 Loading... |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 AddRef(); // Balanced in Accepted() and Canceled() | 128 AddRef(); // Balanced in Accepted() and Canceled() |
144 extension_uninstall_dialog_.reset( | 129 extension_uninstall_dialog_.reset( |
145 ExtensionUninstallDialog::Create(profile_, this)); | 130 ExtensionUninstallDialog::Create(profile_, this)); |
146 extension_uninstall_dialog_->ConfirmUninstall(extension); | 131 extension_uninstall_dialog_->ConfirmUninstall(extension); |
147 break; | 132 break; |
148 } | 133 } |
149 case MANAGE: { | 134 case MANAGE: { |
150 browser_->ShowExtensionsTab(); | 135 browser_->ShowExtensionsTab(); |
151 break; | 136 break; |
152 } | 137 } |
153 case INSPECT_POPUP: { | |
154 delegate_->InspectPopup(extension_action_); | |
155 break; | |
156 } | |
157 default: | 138 default: |
158 NOTREACHED() << "Unknown option"; | 139 NOTREACHED() << "Unknown option"; |
159 break; | 140 break; |
160 } | 141 } |
161 } | 142 } |
162 | 143 |
163 void ExtensionContextMenuModel::ExtensionUninstallAccepted() { | 144 void ExtensionContextMenuModel::ExtensionUninstallAccepted() { |
164 if (GetExtension()) | 145 if (GetExtension()) |
165 profile_->GetExtensionService()->UninstallExtension(extension_id_, false, | 146 profile_->GetExtensionService()->UninstallExtension(extension_id_, false, |
166 NULL); | 147 NULL); |
167 | 148 |
168 Release(); | 149 Release(); |
169 } | 150 } |
170 | 151 |
171 void ExtensionContextMenuModel::ExtensionUninstallCanceled() { | 152 void ExtensionContextMenuModel::ExtensionUninstallCanceled() { |
172 Release(); | 153 Release(); |
173 } | 154 } |
174 | 155 |
175 const Extension* ExtensionContextMenuModel::GetExtension() const { | 156 const Extension* ExtensionContextMenuModel::GetExtension() const { |
176 ExtensionService* extension_service = profile_->GetExtensionService(); | 157 ExtensionService* extension_service = profile_->GetExtensionService(); |
177 return extension_service->GetExtensionById(extension_id_, false); | 158 return extension_service->GetExtensionById(extension_id_, false); |
178 } | 159 } |
OLD | NEW |