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

Side by Side Diff: extensions/renderer/user_script_injector.cc

Issue 988633003: Refactoring: de-couple Extensions from "script injection System" [render side]:4 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 9 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
« no previous file with comments | « extensions/renderer/user_script_injector.h ('k') | extensions/renderer/user_script_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/user_script_injector.h" 5 #include "extensions/renderer/user_script_injector.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 blink::WebScriptSource GreasemonkeyApiJsString::GetSource() const { 50 blink::WebScriptSource GreasemonkeyApiJsString::GetSource() const {
51 return blink::WebScriptSource(blink::WebString::fromUTF8(source_)); 51 return blink::WebScriptSource(blink::WebString::fromUTF8(source_));
52 } 52 }
53 53
54 base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api = 54 base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api =
55 LAZY_INSTANCE_INITIALIZER; 55 LAZY_INSTANCE_INITIALIZER;
56 56
57 } // namespace 57 } // namespace
58 58
59 UserScriptInjector::UserScriptInjector( 59 UserScriptInjector::UserScriptInjector(const UserScript* script,
60 const UserScript* script, 60 UserScriptSet* script_list,
61 UserScriptSet* script_list, 61 bool is_declarative)
62 bool is_declarative)
63 : script_(script), 62 : script_(script),
64 script_id_(script_->id()), 63 script_id_(script_->id()),
65 extension_id_(script_->extension_id()), 64 host_id_(script_->host_id()),
66 is_declarative_(is_declarative), 65 is_declarative_(is_declarative),
67 user_script_set_observer_(this) { 66 user_script_set_observer_(this) {
68 user_script_set_observer_.Add(script_list); 67 user_script_set_observer_.Add(script_list);
69 } 68 }
70 69
71 UserScriptInjector::~UserScriptInjector() { 70 UserScriptInjector::~UserScriptInjector() {
72 } 71 }
73 72
74 void UserScriptInjector::OnUserScriptsUpdated( 73 void UserScriptInjector::OnUserScriptsUpdated(
75 const std::set<std::string>& changed_extensions, 74 const std::set<HostID>& changed_hosts,
76 const std::vector<UserScript*>& scripts) { 75 const std::vector<UserScript*>& scripts) {
77 // If the extension causing this injection changed, then this injection 76 // If the host causing this injection changed, then this injection
78 // will be removed, and there's no guarantee the backing script still exists. 77 // will be removed, and there's no guarantee the backing script still exists.
79 if (changed_extensions.count(extension_id_) > 0) 78 if (changed_hosts.count(host_id_) > 0)
80 return; 79 return;
81 80
82 for (std::vector<UserScript*>::const_iterator iter = scripts.begin(); 81 for (std::vector<UserScript*>::const_iterator iter = scripts.begin();
83 iter != scripts.end(); 82 iter != scripts.end();
84 ++iter) { 83 ++iter) {
85 // We need to compare to |script_id_| (and not to script_->id()) because the 84 // We need to compare to |script_id_| (and not to script_->id()) because the
86 // old |script_| may be deleted by now. 85 // old |script_| may be deleted by now.
87 if ((*iter)->id() == script_id_) { 86 if ((*iter)->id() == script_id_) {
88 script_ = *iter; 87 script_ = *iter;
89 break; 88 break;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 194
196 void UserScriptInjector::GetRunInfo( 195 void UserScriptInjector::GetRunInfo(
197 ScriptsRunInfo* scripts_run_info, 196 ScriptsRunInfo* scripts_run_info,
198 UserScript::RunLocation run_location) const { 197 UserScript::RunLocation run_location) const {
199 if (ShouldInjectJs(run_location)) { 198 if (ShouldInjectJs(run_location)) {
200 const UserScript::FileList& js_scripts = script_->js_scripts(); 199 const UserScript::FileList& js_scripts = script_->js_scripts();
201 scripts_run_info->num_js += js_scripts.size(); 200 scripts_run_info->num_js += js_scripts.size();
202 for (UserScript::FileList::const_iterator iter = js_scripts.begin(); 201 for (UserScript::FileList::const_iterator iter = js_scripts.begin();
203 iter != js_scripts.end(); 202 iter != js_scripts.end();
204 ++iter) { 203 ++iter) {
205 scripts_run_info->executing_scripts[extension_id_].insert( 204 scripts_run_info->executing_scripts[host_id_.id()].insert(
206 iter->url().path()); 205 iter->url().path());
207 } 206 }
208 } 207 }
209 208
210 if (ShouldInjectCss(run_location)) 209 if (ShouldInjectCss(run_location))
211 scripts_run_info->num_css += script_->css_scripts().size(); 210 scripts_run_info->num_css += script_->css_scripts().size();
212 } 211 }
213 212
214 void UserScriptInjector::OnInjectionComplete( 213 void UserScriptInjector::OnInjectionComplete(
215 scoped_ptr<base::ListValue> execution_results, 214 scoped_ptr<base::ListValue> execution_results,
216 UserScript::RunLocation run_location) { 215 UserScript::RunLocation run_location) {
217 } 216 }
218 217
219 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { 218 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) {
220 } 219 }
221 220
222 } // namespace extensions 221 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/user_script_injector.h ('k') | extensions/renderer/user_script_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698