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

Side by Side Diff: chrome/renderer/extensions/user_script_slave.cc

Issue 226663003: Allow content script insertion on about:-URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address reviewer's comments (matches->match) Created 6 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/user_script_slave.h" 5 #include "chrome/renderer/extensions/user_script_slave.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // the compose iframe's dataSource URL is about:blank, but the document URL 187 // the compose iframe's dataSource URL is about:blank, but the document URL
188 // changes to match the parent document after Gmail document.writes into 188 // changes to match the parent document after Gmail document.writes into
189 // it to create the editor. 189 // it to create the editor.
190 // http://code.google.com/p/chromium/issues/detail?id=86742 190 // http://code.google.com/p/chromium/issues/detail?id=86742
191 blink::WebDataSource* data_source = frame->provisionalDataSource() ? 191 blink::WebDataSource* data_source = frame->provisionalDataSource() ?
192 frame->provisionalDataSource() : frame->dataSource(); 192 frame->provisionalDataSource() : frame->dataSource();
193 CHECK(data_source); 193 CHECK(data_source);
194 return GURL(data_source->request().url()); 194 return GURL(data_source->request().url());
195 } 195 }
196 196
197 GURL UserScriptSlave::GetOriginURLForFrame(const WebFrame* frame) {
198 // All pages served with the about:-scheme inherit the security origin from
199 // their parent document (i.e. either the page that contains the document or
200 // the page that opened a new window containing this page).
201 // If this parent document is accessible by the extension, then access to
202 // the about:-frame is allowed if the extension has requested access to it.
203 GURL document_origin_url(frame->document().securityOrigin().toString());
204 if (document_origin_url.is_valid())
205 return document_origin_url;
206 return frame->document().url().GetOrigin();
207 }
208
197 void UserScriptSlave::InjectScripts(WebFrame* frame, 209 void UserScriptSlave::InjectScripts(WebFrame* frame,
198 UserScript::RunLocation location) { 210 UserScript::RunLocation location) {
199 GURL data_source_url = GetDataSourceURLForFrame(frame); 211 GURL data_source_url = GetDataSourceURLForFrame(frame);
200 if (data_source_url.is_empty()) 212 if (data_source_url.is_empty())
201 return; 213 return;
202 214
203 if (frame->isViewSourceModeEnabled()) 215 if (frame->isViewSourceModeEnabled())
204 data_source_url = GURL(content::kViewSourceScheme + std::string(":") + 216 data_source_url = GURL(content::kViewSourceScheme + std::string(":") +
205 data_source_url.spec()); 217 data_source_url.spec());
206 218
(...skipping 10 matching lines...) Expand all
217 if (frame->parent() && !script->match_all_frames()) 229 if (frame->parent() && !script->match_all_frames())
218 continue; // Only match subframes if the script declared it wanted to. 230 continue; // Only match subframes if the script declared it wanted to.
219 231
220 const Extension* extension = extensions_->GetByID(script->extension_id()); 232 const Extension* extension = extensions_->GetByID(script->extension_id());
221 233
222 // Since extension info is sent separately from user script info, they can 234 // Since extension info is sent separately from user script info, they can
223 // be out of sync. We just ignore this situation. 235 // be out of sync. We just ignore this situation.
224 if (!extension) 236 if (!extension)
225 continue; 237 continue;
226 238
239 const bool is_about_scheme =
240 data_source_url.SchemeIs(content::kAboutScheme);
241 if (is_about_scheme) {
242 if (!script->match_about_blank())
243 continue;
244 data_source_url = GetOriginURLForFrame(frame);
245 }
246
227 // Content scripts are not tab-specific. 247 // Content scripts are not tab-specific.
228 const int kNoTabId = -1; 248 const int kNoTabId = -1;
229 // We don't have a process id in this context. 249 // We don't have a process id in this context.
230 const int kNoProcessId = -1; 250 const int kNoProcessId = -1;
251 // If the page is about:blank, pass NULL instead of a UserScript. This
252 // ensures that the URL is checked against the extension's host permissions
253 // instead of the script's URL patterns.
254 const UserScript* script_or_null = is_about_scheme ? NULL : script;
not at google - send to devlin 2014/04/21 22:34:41 I see. a bit of a hack to assume that's what the i
robwu 2014/04/21 23:21:46 I disliked the alternative (adding yet another (bo
not at google - send to devlin 2014/04/21 23:37:39 We're in this code because we're running a declare
robwu 2014/04/22 13:29:52 Submitted patch to Blink so I can get rid of this
231 if (!PermissionsData::CanExecuteScriptOnPage(extension, 255 if (!PermissionsData::CanExecuteScriptOnPage(extension,
232 data_source_url, 256 data_source_url,
233 frame->top()->document().url(), 257 frame->top()->document().url(),
234 kNoTabId, 258 kNoTabId,
235 script, 259 script_or_null,
236 kNoProcessId, 260 kNoProcessId,
237 NULL)) { 261 NULL)) {
238 continue; 262 continue;
239 } 263 }
240 264
241 if (location == UserScript::DOCUMENT_START) { 265 if (location == UserScript::DOCUMENT_START) {
242 num_css += script->css_scripts().size(); 266 num_css += script->css_scripts().size();
243 for (UserScript::FileList::const_iterator iter = 267 for (UserScript::FileList::const_iterator iter =
244 script->css_scripts().begin(); 268 script->css_scripts().begin();
245 iter != script->css_scripts().end(); 269 iter != script->css_scripts().end();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } else if (location == UserScript::DOCUMENT_IDLE) { 342 } else if (location == UserScript::DOCUMENT_IDLE) {
319 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); 343 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts);
320 if (num_scripts) 344 if (num_scripts)
321 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); 345 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
322 } else { 346 } else {
323 NOTREACHED(); 347 NOTREACHED();
324 } 348 }
325 } 349 }
326 350
327 } // namespace extensions 351 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698