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

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

Issue 492133002: Renderer changes for wiring up shared memory with declarative injection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests, revert mistaken changes, address nits Created 6 years, 3 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 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_set.h" 5 #include "extensions/renderer/user_script_set.h"
6 6
7 #include "content/public/common/url_constants.h" 7 #include "content/public/common/url_constants.h"
8 #include "content/public/renderer/render_thread.h" 8 #include "content/public/renderer/render_thread.h"
9 #include "extensions/common/extension.h" 9 #include "extensions/common/extension.h"
10 #include "extensions/common/extension_messages.h" 10 #include "extensions/common/extension_messages.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 int tab_id, 65 int tab_id,
66 UserScript::RunLocation run_location) { 66 UserScript::RunLocation run_location) {
67 GURL document_url = GetDocumentUrlForFrame(web_frame); 67 GURL document_url = GetDocumentUrlForFrame(web_frame);
68 for (ScopedVector<UserScript>::const_iterator iter = scripts_.begin(); 68 for (ScopedVector<UserScript>::const_iterator iter = scripts_.begin();
69 iter != scripts_.end(); 69 iter != scripts_.end();
70 ++iter) { 70 ++iter) {
71 const Extension* extension = extensions_->GetByID((*iter)->extension_id()); 71 const Extension* extension = extensions_->GetByID((*iter)->extension_id());
72 if (!extension) 72 if (!extension)
73 continue; 73 continue;
74 scoped_ptr<ScriptInjection> injection = GetInjectionForScript( 74 scoped_ptr<ScriptInjection> injection = GetInjectionForScript(
75 *iter, web_frame, tab_id, run_location, document_url, extension); 75 *iter,
76 web_frame,
77 tab_id,
78 run_location,
79 document_url,
80 extension,
81 false /* is_declarative */);
76 if (injection.get()) 82 if (injection.get())
77 injections->push_back(injection.release()); 83 injections->push_back(injection.release());
78 } 84 }
79 } 85 }
80 86
81 bool UserScriptSet::UpdateUserScripts( 87 bool UserScriptSet::UpdateUserScripts(
82 base::SharedMemoryHandle shared_memory, 88 base::SharedMemoryHandle shared_memory,
83 const std::set<std::string>& changed_extensions) { 89 const std::set<std::string>& changed_extensions) {
84 bool only_inject_incognito = 90 bool only_inject_incognito =
85 ExtensionsRendererClient::Get()->IsIncognitoProcess(); 91 ExtensionsRendererClient::Get()->IsIncognitoProcess();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 142
137 scripts_.push_back(script.release()); 143 scripts_.push_back(script.release());
138 } 144 }
139 145
140 FOR_EACH_OBSERVER(Observer, 146 FOR_EACH_OBSERVER(Observer,
141 observers_, 147 observers_,
142 OnUserScriptsUpdated(changed_extensions, scripts_.get())); 148 OnUserScriptsUpdated(changed_extensions, scripts_.get()));
143 return true; 149 return true;
144 } 150 }
145 151
152 scoped_ptr<ScriptInjection> UserScriptSet::GetInjectionByScriptID(
153 int script_id,
154 blink::WebFrame* web_frame,
155 int tab_id,
156 UserScript::RunLocation run_location,
157 const GURL& document_url,
158 const Extension* extension) {
159 for (ScopedVector<UserScript>::const_iterator it = scripts_.begin();
160 it != scripts_.end();
161 ++it) {
162 if ((*it)->id() == script_id) {
163 return GetInjectionForScript(*it,
164 web_frame,
165 tab_id,
166 run_location,
167 document_url,
168 extension,
169 true /* is_declarative */);
170 }
171 }
172 return scoped_ptr<ScriptInjection>();
173 }
174
146 scoped_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript( 175 scoped_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript(
147 UserScript* script, 176 UserScript* script,
148 blink::WebFrame* web_frame, 177 blink::WebFrame* web_frame,
149 int tab_id, 178 int tab_id,
150 UserScript::RunLocation run_location, 179 UserScript::RunLocation run_location,
151 const GURL& document_url, 180 const GURL& document_url,
152 const Extension* extension) { 181 const Extension* extension,
182 bool is_declarative) {
153 scoped_ptr<ScriptInjection> injection; 183 scoped_ptr<ScriptInjection> injection;
154 if (web_frame->parent() && !script->match_all_frames()) 184 if (web_frame->parent() && !script->match_all_frames())
155 return injection.Pass(); // Only match subframes if the script declared it. 185 return injection.Pass(); // Only match subframes if the script declared it.
156 186
157 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 187 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
158 web_frame, document_url, script->match_about_blank()); 188 web_frame, document_url, script->match_about_blank());
159 189
160 if (!script->MatchesURL(effective_document_url)) 190 if (!script->MatchesURL(effective_document_url))
161 return injection.Pass(); 191 return injection.Pass();
162 192
163 if (extension->permissions_data()->GetContentScriptAccess( 193 scoped_ptr<ScriptInjector> injector(new UserScriptInjector(script,
194 this,
195 is_declarative));
196 if (injector->CanExecuteOnFrame(
164 extension, 197 extension,
165 effective_document_url, 198 web_frame,
166 web_frame->top()->document().url(),
167 -1, // Content scripts are not tab-specific. 199 -1, // Content scripts are not tab-specific.
168 -1, // We don't have a process id in this context. 200 web_frame->top()->document().url()) ==
169 NULL /* ignore error */) == PermissionsData::ACCESS_DENIED) { 201 PermissionsData::ACCESS_DENIED) {
170 return injection.Pass(); 202 return injection.Pass();
171 } 203 }
172 204
173 bool inject_css = !script->css_scripts().empty() && 205 bool inject_css = !script->css_scripts().empty() &&
174 run_location == UserScript::DOCUMENT_START; 206 run_location == UserScript::DOCUMENT_START;
175 bool inject_js = 207 bool inject_js =
176 !script->js_scripts().empty() && script->run_location() == run_location; 208 !script->js_scripts().empty() && script->run_location() == run_location;
177 if (inject_css || inject_js) { 209 if (inject_css || inject_js) {
178 injection.reset(new ScriptInjection( 210 injection.reset(new ScriptInjection(
179 scoped_ptr<ScriptInjector>(new UserScriptInjector(script, this)), 211 injector.Pass(),
180 web_frame, 212 web_frame,
181 extension->id(), 213 extension->id(),
182 run_location, 214 run_location,
183 tab_id)); 215 tab_id));
184 } 216 }
185 return injection.Pass(); 217 return injection.Pass();
186 } 218 }
187 219
188 } // namespace extensions 220 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698