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

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: Final fixes 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"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { 114 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
114 return extension_items_->IsCommandIdEnabled(command_id); 115 return extension_items_->IsCommandIdEnabled(command_id);
115 } else if (command_id == CONFIGURE) { 116 } else if (command_id == CONFIGURE) {
116 return 117 return
117 extensions::ManifestURL::GetOptionsPage(extension).spec().length() > 0; 118 extensions::ManifestURL::GetOptionsPage(extension).spec().length() > 0;
118 } else if (command_id == NAME) { 119 } else if (command_id == NAME) {
119 // The NAME links to the Homepage URL. If the extension doesn't have a 120 // The NAME links to the Homepage URL. If the extension doesn't have a
120 // homepage, we just disable this menu item. 121 // homepage, we just disable this menu item.
121 return extensions::ManifestURL::GetHomepageURL(extension).is_valid(); 122 return extensions::ManifestURL::GetHomepageURL(extension).is_valid();
122 } else if (command_id == INSPECT_POPUP) { 123 } else if (command_id == INSPECT_POPUP) {
123 WebContents* web_contents = 124 WebContents* web_contents = GetActiveWebContents();
124 browser_->tab_strip_model()->GetActiveWebContents();
125 if (!web_contents) 125 if (!web_contents)
126 return false; 126 return false;
127 127
128 return extension_action_ && 128 return extension_action_ &&
129 extension_action_->HasPopup(SessionID::IdForTab(web_contents)); 129 extension_action_->HasPopup(SessionID::IdForTab(web_contents));
130 } else if (command_id == UNINSTALL) { 130 } else if (command_id == UNINSTALL) {
131 // Some extension types can not be uninstalled. 131 // Some extension types can not be uninstalled.
132 return extensions::ExtensionSystem::Get( 132 return extensions::ExtensionSystem::Get(
133 profile_)->management_policy()->UserMayModifySettings(extension, NULL); 133 profile_)->management_policy()->UserMayModifySettings(extension, NULL);
134 } 134 }
(...skipping 22 matching lines...) Expand all
157 } 157 }
158 158
159 switch (command_id) { 159 switch (command_id) {
160 case NAME: { 160 case NAME: {
161 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), 161 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension),
162 Referrer(), NEW_FOREGROUND_TAB, 162 Referrer(), NEW_FOREGROUND_TAB,
163 content::PAGE_TRANSITION_LINK, false); 163 content::PAGE_TRANSITION_LINK, false);
164 browser_->OpenURL(params); 164 browser_->OpenURL(params);
165 break; 165 break;
166 } 166 }
167 case ALWAYS_RUN: {
168 WebContents* web_contents = GetActiveWebContents();
169 if (web_contents) {
170 extensions::ActiveScriptController::GetForWebContents(web_contents)
171 ->AlwaysRunOnVisibleOrigin(extension);
172 }
173 break;
174 }
167 case CONFIGURE: 175 case CONFIGURE:
168 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); 176 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty());
169 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); 177 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_);
170 break; 178 break;
171 case HIDE: { 179 case HIDE: {
172 extensions::ExtensionActionAPI::SetBrowserActionVisibility( 180 extensions::ExtensionActionAPI::SetBrowserActionVisibility(
173 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); 181 extensions::ExtensionPrefs::Get(profile_), extension->id(), false);
174 break; 182 break;
175 } 183 }
176 case UNINSTALL: { 184 case UNINSTALL: {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 extension_items_.reset(new extensions::ContextMenuMatcher( 238 extension_items_.reset(new extensions::ContextMenuMatcher(
231 profile_, this, this, base::Bind(MenuItemMatchesAction, action_type_))); 239 profile_, this, this, base::Bind(MenuItemMatchesAction, action_type_)));
232 240
233 std::string extension_name = extension->name(); 241 std::string extension_name = extension->name();
234 // Ampersands need to be escaped to avoid being treated like 242 // Ampersands need to be escaped to avoid being treated like
235 // mnemonics in the menu. 243 // mnemonics in the menu.
236 base::ReplaceChars(extension_name, "&", "&&", &extension_name); 244 base::ReplaceChars(extension_name, "&", "&&", &extension_name);
237 AddItem(NAME, base::UTF8ToUTF16(extension_name)); 245 AddItem(NAME, base::UTF8ToUTF16(extension_name));
238 AppendExtensionItems(); 246 AppendExtensionItems();
239 AddSeparator(ui::NORMAL_SEPARATOR); 247 AddSeparator(ui::NORMAL_SEPARATOR);
248
249 // Add the "Always Allow" item for adding persisted permissions for script
250 // injections if there is an active action for this extension. Note that this
251 // will add it to *all* extension action context menus, not just the one
252 // attached to the script injection request icon, but that's okay.
253 WebContents* web_contents = GetActiveWebContents();
254 if (web_contents &&
255 extensions::ActiveScriptController::GetForWebContents(web_contents)
256 ->HasActiveScriptAction(extension)) {
257 AddItemWithStringId(ALWAYS_RUN, IDS_EXTENSIONS_ALWAYS_RUN);
258 }
259
240 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); 260 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
241 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); 261 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
242 if (extension_action_manager->GetBrowserAction(*extension)) 262 if (extension_action_manager->GetBrowserAction(*extension))
243 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); 263 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON);
244 AddSeparator(ui::NORMAL_SEPARATOR); 264 AddSeparator(ui::NORMAL_SEPARATOR);
245 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); 265 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION);
246 } 266 }
247 267
248 const Extension* ExtensionContextMenuModel::GetExtension() const { 268 const Extension* ExtensionContextMenuModel::GetExtension() const {
249 return extensions::ExtensionRegistry::Get(profile_) 269 return extensions::ExtensionRegistry::Get(profile_)
(...skipping 10 matching lines...) Expand all
260 return; 280 return;
261 281
262 AddSeparator(ui::NORMAL_SEPARATOR); 282 AddSeparator(ui::NORMAL_SEPARATOR);
263 283
264 extension_items_count_ = 0; 284 extension_items_count_ = 0;
265 extension_items_->AppendExtensionItems(MenuItem::ExtensionKey(extension_id_), 285 extension_items_->AppendExtensionItems(MenuItem::ExtensionKey(extension_id_),
266 base::string16(), 286 base::string16(),
267 &extension_items_count_, 287 &extension_items_count_,
268 true); // is_action_menu 288 true); // is_action_menu
269 } 289 }
290
291 content::WebContents* ExtensionContextMenuModel::GetActiveWebContents() const {
292 return browser_->tab_strip_model()->GetActiveWebContents();
293 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_context_menu_model.h ('k') | chrome/browser/extensions/permissions_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698