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

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: Replaced persisted permissions with granted permissions 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/browser/extensions/active_script_controller.h"
9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
10 #include "chrome/browser/extensions/extension_action.h" 11 #include "chrome/browser/extensions/extension_action.h"
11 #include "chrome/browser/extensions/extension_action_manager.h" 12 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 14 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/chrome_pages.h" 18 #include "chrome/browser/ui/chrome_pages.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
20 #include "chrome/common/extensions/manifest_url_handler.h" 21 #include "chrome/common/extensions/manifest_url_handler.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "extensions/browser/extension_prefs.h" 25 #include "extensions/browser/extension_prefs.h"
25 #include "extensions/browser/extension_system.h" 26 #include "extensions/browser/extension_system.h"
26 #include "extensions/browser/management_policy.h" 27 #include "extensions/browser/management_policy.h"
27 #include "extensions/browser/uninstall_reason.h" 28 #include "extensions/browser/uninstall_reason.h"
28 #include "extensions/common/extension.h" 29 #include "extensions/common/extension.h"
30 #include "extensions/common/manifest_constants.h"
29 #include "grit/chromium_strings.h" 31 #include "grit/chromium_strings.h"
30 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
31 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
32 34
33 using content::OpenURLParams; 35 using content::OpenURLParams;
34 using content::Referrer; 36 using content::Referrer;
35 using content::WebContents; 37 using content::WebContents;
36 using extensions::Extension; 38 using extensions::Extension;
37 39
38 ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension, 40 ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return; 108 return;
107 109
108 switch (command_id) { 110 switch (command_id) {
109 case NAME: { 111 case NAME: {
110 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), 112 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension),
111 Referrer(), NEW_FOREGROUND_TAB, 113 Referrer(), NEW_FOREGROUND_TAB,
112 content::PAGE_TRANSITION_LINK, false); 114 content::PAGE_TRANSITION_LINK, false);
113 browser_->OpenURL(params); 115 browser_->OpenURL(params);
114 break; 116 break;
115 } 117 }
118 case ALWAYS_ALLOW: {
not at google - send to devlin 2014/08/07 22:03:46 "run" is a better term than "allow" I think. more
gpdavis 2014/08/08 00:51:43 Done.
119 content::WebContents* web_contents =
120 browser_->tab_strip_model()->GetActiveWebContents();
121 extensions::ActiveScriptController::GetForWebContents(web_contents)
not at google - send to devlin 2014/08/07 22:03:45 elsewhere we seem to guard against a null web cont
gpdavis 2014/08/08 00:51:43 Done. Should we be caching the result of GetActiv
not at google - send to devlin 2014/08/08 14:31:28 not fussed... I guess the first one is idiomatic.
gpdavis 2014/08/08 18:07:35 Done.
122 ->AddPersistedPermission(extension);
123 break;
124 }
116 case CONFIGURE: 125 case CONFIGURE:
117 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); 126 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty());
118 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); 127 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_);
119 break; 128 break;
120 case HIDE: { 129 case HIDE: {
121 extensions::ExtensionActionAPI::SetBrowserActionVisibility( 130 extensions::ExtensionActionAPI::SetBrowserActionVisibility(
122 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); 131 extensions::ExtensionPrefs::Get(profile_), extension->id(), false);
123 break; 132 break;
124 } 133 }
125 case UNINSTALL: { 134 case UNINSTALL: {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 extension_action_ = extension_action_manager->GetBrowserAction(*extension); 179 extension_action_ = extension_action_manager->GetBrowserAction(*extension);
171 if (!extension_action_) 180 if (!extension_action_)
172 extension_action_ = extension_action_manager->GetPageAction(*extension); 181 extension_action_ = extension_action_manager->GetPageAction(*extension);
173 182
174 std::string extension_name = extension->name(); 183 std::string extension_name = extension->name();
175 // Ampersands need to be escaped to avoid being treated like 184 // Ampersands need to be escaped to avoid being treated like
176 // mnemonics in the menu. 185 // mnemonics in the menu.
177 base::ReplaceChars(extension_name, "&", "&&", &extension_name); 186 base::ReplaceChars(extension_name, "&", "&&", &extension_name);
178 AddItem(NAME, base::UTF8ToUTF16(extension_name)); 187 AddItem(NAME, base::UTF8ToUTF16(extension_name));
179 AddSeparator(ui::NORMAL_SEPARATOR); 188 AddSeparator(ui::NORMAL_SEPARATOR);
189
190 // Add the "Always Allow" item for adding persisted permissions for script
191 // injections if there is an active action for this extension (this action).
192 content::WebContents* web_contents =
193 browser_->tab_strip_model()->GetActiveWebContents();
194 if (extensions::ActiveScriptController::GetForWebContents(web_contents)
195 ->HasActiveScriptAction(extension)) {
196 AddItemWithStringId(ALWAYS_ALLOW, IDS_EXTENSIONS_ALWAYS_ALLOW);
197 }
198
180 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); 199 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
181 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); 200 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
182 if (extension_action_manager->GetBrowserAction(*extension)) 201 if (extension_action_manager->GetBrowserAction(*extension))
183 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); 202 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON);
184 AddSeparator(ui::NORMAL_SEPARATOR); 203 AddSeparator(ui::NORMAL_SEPARATOR);
185 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); 204 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION);
186 } 205 }
187 206
188 const Extension* ExtensionContextMenuModel::GetExtension() const { 207 const Extension* ExtensionContextMenuModel::GetExtension() const {
189 ExtensionService* extension_service = 208 ExtensionService* extension_service =
190 extensions::ExtensionSystem::Get(profile_)->extension_service(); 209 extensions::ExtensionSystem::Get(profile_)->extension_service();
191 return extension_service->GetExtensionById(extension_id_, false); 210 return extension_service->GetExtensionById(extension_id_, false);
192 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698