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

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: Test attempt Created 6 years, 5 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 1890a0ec9e1186626eb5f0a234c74e6e470328a2..d9f02b32c395917803a13402549d209d602fa24b 100644
--- a/chrome/browser/extensions/extension_context_menu_model.cc
+++ b/chrome/browser/extensions/extension_context_menu_model.cc
@@ -6,6 +6,7 @@
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/extensions/active_script_controller.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h"
@@ -16,6 +17,7 @@
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
#include "chrome/common/extensions/manifest_url_handler.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
@@ -25,6 +27,7 @@
#include "extensions/browser/management_policy.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/extension.h"
+#include "extensions/common/manifest_constants.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -112,6 +115,13 @@ void ExtensionContextMenuModel::ExecuteCommand(int command_id,
browser_->OpenURL(params);
break;
}
+ case ALWAYS_ALLOW: {
+ content::WebContents* web_contents =
+ browser_->tab_strip_model()->GetActiveWebContents();
+ extensions::ActiveScriptController::GetForWebContents(web_contents)
+ ->AddPersistedPermission(extension);
+ break;
+ }
case CONFIGURE:
DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty());
extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_);
@@ -174,6 +184,15 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension) {
base::ReplaceChars(extension_name, "&", "&&", &extension_name);
AddItem(NAME, base::UTF8ToUTF16(extension_name));
AddSeparator(ui::NORMAL_SEPARATOR);
+
+ // Add the "Always Allow" item for adding persisted permissions for script
+ // injections.
+ // TODO: Only add this item if the current page does not match any
+ // persisted permissions.
+ if (!extension_action_manager->GetBrowserAction(*extension) &&
+ extension->GetManifestData(extensions::manifest_keys::kContentScripts))
+ AddItemWithStringId(ALWAYS_ALLOW, IDS_EXTENSIONS_ALWAYS_ALLOW);
+
AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
if (extension_action_manager->GetBrowserAction(*extension))

Powered by Google App Engine
This is Rietveld 408576698