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

Unified 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: String param reference 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_context_menu_model.cc
diff --git a/chrome/browser/extensions/extension_context_menu_model.cc b/chrome/browser/extensions/extension_context_menu_model.cc
index 2edc1ac95b05846252fe157e92d98de4fb5c8e23..c79384595fe195cf3de783970ec6d20f6e99be95 100644
--- a/chrome/browser/extensions/extension_context_menu_model.cc
+++ b/chrome/browser/extensions/extension_context_menu_model.cc
@@ -7,6 +7,7 @@
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/extensions/active_script_controller.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/context_menu_matcher.h"
#include "chrome/browser/extensions/extension_action.h"
@@ -120,8 +121,7 @@ bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const {
// homepage, we just disable this menu item.
return extensions::ManifestURL::GetHomepageURL(extension).is_valid();
} else if (command_id == INSPECT_POPUP) {
- WebContents* web_contents =
- browser_->tab_strip_model()->GetActiveWebContents();
+ WebContents* web_contents = GetActiveWebContents();
if (!web_contents)
return false;
@@ -164,6 +164,14 @@ void ExtensionContextMenuModel::ExecuteCommand(int command_id,
browser_->OpenURL(params);
break;
}
+ case ALWAYS_RUN: {
+ WebContents* web_contents = GetActiveWebContents();
+ if (web_contents) {
+ extensions::ActiveScriptController::GetForWebContents(web_contents)
+ ->AlwaysRunOnVisibleHost(extension);
+ }
+ break;
+ }
case CONFIGURE:
DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty());
extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_);
@@ -237,6 +245,18 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension) {
AddItem(NAME, base::UTF8ToUTF16(extension_name));
AppendExtensionItems();
AddSeparator(ui::NORMAL_SEPARATOR);
+
+ // Add the "Always Allow" item for adding persisted permissions for script
+ // injections if there is an active action for this extension. Note that this
+ // will add it to *all* extension action context menus, not just the one
+ // attached to the script injection request icon, but that's okay.
+ WebContents* web_contents = GetActiveWebContents();
+ if (web_contents &&
+ extensions::ActiveScriptController::GetForWebContents(web_contents)
+ ->HasActiveScriptAction(extension)) {
+ AddItemWithStringId(ALWAYS_RUN, IDS_EXTENSIONS_ALWAYS_RUN);
+ }
+
AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
if (extension_action_manager->GetBrowserAction(*extension))
@@ -267,3 +287,7 @@ void ExtensionContextMenuModel::AppendExtensionItems() {
&extension_items_count_,
true); // is_action_menu
}
+
+content::WebContents* ExtensionContextMenuModel::GetActiveWebContents() const {
+ return browser_->tab_strip_model()->GetActiveWebContents();
+}

Powered by Google App Engine
This is Rietveld 408576698