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

Unified Diff: extensions/renderer/user_script_injector.cc

Issue 2116613002: Prevent duplicate content script injection defined in manifest.json (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed code review on patch 8 Created 4 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
« no previous file with comments | « extensions/renderer/user_script_injector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/user_script_injector.cc
diff --git a/extensions/renderer/user_script_injector.cc b/extensions/renderer/user_script_injector.cc
index 1910548ba24b340d720cd7eb4ea16d8af38e6416..f653cf4b792327763d2609181802f725bad47bcb 100644
--- a/extensions/renderer/user_script_injector.cc
+++ b/extensions/renderer/user_script_injector.cc
@@ -197,7 +197,8 @@ PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame(
}
std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
- UserScript::RunLocation run_location) const {
+ UserScript::RunLocation run_location,
+ ScriptsRunInfo* scripts_run_info) const {
std::vector<blink::WebScriptSource> sources;
if (!script_)
return sources;
@@ -209,6 +210,11 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
for (UserScript::FileList::const_iterator iter = js_scripts.begin();
iter != js_scripts.end();
++iter) {
+ const GURL& script_url = iter->url();
+ // Check if the script is already injected.
+ if (scripts_run_info->injected_scripts.count(script_url) != 0)
+ continue;
+
std::string content = iter->GetContent().as_string();
// We add this dumb function wrapper for user scripts to emulate what
@@ -218,7 +224,9 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
content += kUserScriptTail;
}
sources.push_back(blink::WebScriptSource(
- blink::WebString::fromUTF8(content), iter->url()));
+ blink::WebString::fromUTF8(content), script_url));
+
+ scripts_run_info->injected_scripts.insert(script_url);
}
// Emulate Greasemonkey API for scripts that were converted to extension
@@ -230,7 +238,8 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
}
std::vector<std::string> UserScriptInjector::GetCssSources(
- UserScript::RunLocation run_location) const {
+ UserScript::RunLocation run_location,
+ ScriptsRunInfo* scripts_run_info) const {
DCHECK_EQ(UserScript::DOCUMENT_START, run_location);
std::vector<std::string> sources;
@@ -238,10 +247,18 @@ std::vector<std::string> UserScriptInjector::GetCssSources(
return sources;
const UserScript::FileList& css_scripts = script_->css_scripts();
+
for (UserScript::FileList::const_iterator iter = css_scripts.begin();
iter != css_scripts.end();
++iter) {
- sources.push_back(iter->GetContent().as_string());
+ const GURL& script_url = iter->url();
+ // Check if the stylesheet is already injected.
+ if (scripts_run_info->injected_scripts.find(script_url) ==
+ scripts_run_info->injected_scripts.end()) {
+ sources.push_back(iter->GetContent().as_string());
+
+ scripts_run_info->injected_scripts.insert(script_url);
+ }
}
return sources;
}
« no previous file with comments | « extensions/renderer/user_script_injector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698