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

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

Issue 396033002: Support "always allow" for runtime script execution (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ReloadExtension in unittest Created 6 years, 4 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/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/extensions/active_script_controller.h"
10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
11 #include "chrome/browser/extensions/context_menu_matcher.h" 12 #include "chrome/browser/extensions/context_menu_matcher.h"
12 #include "chrome/browser/extensions/extension_action.h" 13 #include "chrome/browser/extensions/extension_action.h"
13 #include "chrome/browser/extensions/extension_action_manager.h" 14 #include "chrome/browser/extensions/extension_action_manager.h"
14 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 16 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/extensions/menu_manager.h" 17 #include "chrome/browser/extensions/menu_manager.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/chrome_pages.h" 21 #include "chrome/browser/ui/chrome_pages.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/extensions/extension_constants.h" 23 #include "chrome/common/extensions/extension_constants.h"
23 #include "chrome/common/extensions/manifest_url_handler.h" 24 #include "chrome/common/extensions/manifest_url_handler.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/context_menu_params.h" 28 #include "content/public/common/context_menu_params.h"
28 #include "extensions/browser/extension_prefs.h" 29 #include "extensions/browser/extension_prefs.h"
29 #include "extensions/browser/extension_registry.h" 30 #include "extensions/browser/extension_registry.h"
30 #include "extensions/browser/extension_system.h" 31 #include "extensions/browser/extension_system.h"
31 #include "extensions/browser/management_policy.h" 32 #include "extensions/browser/management_policy.h"
32 #include "extensions/browser/uninstall_reason.h" 33 #include "extensions/browser/uninstall_reason.h"
33 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
35 #include "extensions/common/manifest_constants.h"
Devlin 2014/08/14 01:20:18 why??
gpdavis 2014/08/14 20:05:43 Oops, thought we still needed this for determining
34 #include "grit/chromium_strings.h" 36 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
36 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
37 39
38 using content::OpenURLParams; 40 using content::OpenURLParams;
39 using content::Referrer; 41 using content::Referrer;
40 using content::WebContents; 42 using content::WebContents;
41 using extensions::Extension; 43 using extensions::Extension;
42 using extensions::MenuItem; 44 using extensions::MenuItem;
43 using extensions::MenuManager; 45 using extensions::MenuManager;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { 115 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
114 return extension_items_->IsCommandIdEnabled(command_id); 116 return extension_items_->IsCommandIdEnabled(command_id);
115 } else if (command_id == CONFIGURE) { 117 } else if (command_id == CONFIGURE) {
116 return 118 return
117 extensions::ManifestURL::GetOptionsPage(extension).spec().length() > 0; 119 extensions::ManifestURL::GetOptionsPage(extension).spec().length() > 0;
118 } else if (command_id == NAME) { 120 } else if (command_id == NAME) {
119 // The NAME links to the Homepage URL. If the extension doesn't have a 121 // The NAME links to the Homepage URL. If the extension doesn't have a
120 // homepage, we just disable this menu item. 122 // homepage, we just disable this menu item.
121 return extensions::ManifestURL::GetHomepageURL(extension).is_valid(); 123 return extensions::ManifestURL::GetHomepageURL(extension).is_valid();
122 } else if (command_id == INSPECT_POPUP) { 124 } else if (command_id == INSPECT_POPUP) {
123 WebContents* web_contents = 125 WebContents* web_contents = GetActiveWebContents();
124 browser_->tab_strip_model()->GetActiveWebContents();
125 if (!web_contents) 126 if (!web_contents)
126 return false; 127 return false;
127 128
128 return extension_action_ && 129 return extension_action_ &&
129 extension_action_->HasPopup(SessionID::IdForTab(web_contents)); 130 extension_action_->HasPopup(SessionID::IdForTab(web_contents));
130 } else if (command_id == UNINSTALL) { 131 } else if (command_id == UNINSTALL) {
131 // Some extension types can not be uninstalled. 132 // Some extension types can not be uninstalled.
132 return extensions::ExtensionSystem::Get( 133 return extensions::ExtensionSystem::Get(
133 profile_)->management_policy()->UserMayModifySettings(extension, NULL); 134 profile_)->management_policy()->UserMayModifySettings(extension, NULL);
134 } 135 }
(...skipping 22 matching lines...) Expand all
157 } 158 }
158 159
159 switch (command_id) { 160 switch (command_id) {
160 case NAME: { 161 case NAME: {
161 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), 162 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension),
162 Referrer(), NEW_FOREGROUND_TAB, 163 Referrer(), NEW_FOREGROUND_TAB,
163 content::PAGE_TRANSITION_LINK, false); 164 content::PAGE_TRANSITION_LINK, false);
164 browser_->OpenURL(params); 165 browser_->OpenURL(params);
165 break; 166 break;
166 } 167 }
168 case ALWAYS_RUN: {
169 WebContents* web_contents = GetActiveWebContents();
170 if (web_contents) {
171 extensions::ActiveScriptController::GetForWebContents(web_contents)
172 ->AlwaysRunOnVisibleHost(extension);
173 }
174 break;
175 }
167 case CONFIGURE: 176 case CONFIGURE:
168 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); 177 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty());
169 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); 178 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_);
170 break; 179 break;
171 case HIDE: { 180 case HIDE: {
172 extensions::ExtensionActionAPI::SetBrowserActionVisibility( 181 extensions::ExtensionActionAPI::SetBrowserActionVisibility(
173 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); 182 extensions::ExtensionPrefs::Get(profile_), extension->id(), false);
174 break; 183 break;
175 } 184 }
176 case UNINSTALL: { 185 case UNINSTALL: {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 extension_items_.reset(new extensions::ContextMenuMatcher( 239 extension_items_.reset(new extensions::ContextMenuMatcher(
231 profile_, this, this, base::Bind(MenuItemMatchesAction, action_type_))); 240 profile_, this, this, base::Bind(MenuItemMatchesAction, action_type_)));
232 241
233 std::string extension_name = extension->name(); 242 std::string extension_name = extension->name();
234 // Ampersands need to be escaped to avoid being treated like 243 // Ampersands need to be escaped to avoid being treated like
235 // mnemonics in the menu. 244 // mnemonics in the menu.
236 base::ReplaceChars(extension_name, "&", "&&", &extension_name); 245 base::ReplaceChars(extension_name, "&", "&&", &extension_name);
237 AddItem(NAME, base::UTF8ToUTF16(extension_name)); 246 AddItem(NAME, base::UTF8ToUTF16(extension_name));
238 AppendExtensionItems(); 247 AppendExtensionItems();
239 AddSeparator(ui::NORMAL_SEPARATOR); 248 AddSeparator(ui::NORMAL_SEPARATOR);
249
250 // Add the "Always Allow" item for adding persisted permissions for script
251 // injections if there is an active action for this extension. Note that this
252 // will add it to *all* extension action context menus, not just the one
253 // attached to the script injection request icon, but that's okay.
254 WebContents* web_contents = GetActiveWebContents();
255 if (web_contents &&
256 extensions::ActiveScriptController::GetForWebContents(web_contents)
257 ->HasActiveScriptAction(extension)) {
258 AddItemWithStringId(ALWAYS_RUN, IDS_EXTENSIONS_ALWAYS_RUN);
259 }
260
240 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); 261 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
241 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); 262 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
242 if (extension_action_manager->GetBrowserAction(*extension)) 263 if (extension_action_manager->GetBrowserAction(*extension))
243 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); 264 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON);
244 AddSeparator(ui::NORMAL_SEPARATOR); 265 AddSeparator(ui::NORMAL_SEPARATOR);
245 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); 266 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION);
246 } 267 }
247 268
248 const Extension* ExtensionContextMenuModel::GetExtension() const { 269 const Extension* ExtensionContextMenuModel::GetExtension() const {
249 return extensions::ExtensionRegistry::Get(profile_) 270 return extensions::ExtensionRegistry::Get(profile_)
(...skipping 10 matching lines...) Expand all
260 return; 281 return;
261 282
262 AddSeparator(ui::NORMAL_SEPARATOR); 283 AddSeparator(ui::NORMAL_SEPARATOR);
263 284
264 extension_items_count_ = 0; 285 extension_items_count_ = 0;
265 extension_items_->AppendExtensionItems(MenuItem::ExtensionKey(extension_id_), 286 extension_items_->AppendExtensionItems(MenuItem::ExtensionKey(extension_id_),
266 base::string16(), 287 base::string16(),
267 &extension_items_count_, 288 &extension_items_count_,
268 true); // is_action_menu 289 true); // is_action_menu
269 } 290 }
291
292 content::WebContents* ExtensionContextMenuModel::GetActiveWebContents() const {
293 return browser_->tab_strip_model()->GetActiveWebContents();
294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698