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

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

Issue 2928033002: Move GetDocument method from WebFrame to WebLocalFrame. (Closed)
Patch Set: Split a DCHECK in two as suggested by boliu@. Created 3 years, 6 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/script_context.h ('k') | extensions/renderer/script_context_browsertest.cc » ('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/script_context.h" 5 #include "extensions/renderer/script_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (data_source && 293 if (data_source &&
294 frame->GetSecurityOrigin().CanAccess(blink::WebSecurityOrigin::Create( 294 frame->GetSecurityOrigin().CanAccess(blink::WebSecurityOrigin::Create(
295 data_source->GetRequest().Url()))) { 295 data_source->GetRequest().Url()))) {
296 return GURL(data_source->GetRequest().Url()); 296 return GURL(data_source->GetRequest().Url());
297 } 297 }
298 } 298 }
299 return GURL(weburl); 299 return GURL(weburl);
300 } 300 }
301 301
302 // static 302 // static
303 GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebLocalFrame* frame, 303 GURL ScriptContext::GetEffectiveDocumentURL(blink::WebLocalFrame* frame,
304 const GURL& document_url, 304 const GURL& document_url,
305 bool match_about_blank) { 305 bool match_about_blank) {
306 // Common scenario. If |match_about_blank| is false (as is the case in most 306 // Common scenario. If |match_about_blank| is false (as is the case in most
307 // extensions), or if the frame is not an about:-page, just return 307 // extensions), or if the frame is not an about:-page, just return
308 // |document_url| (supposedly the URL of the frame). 308 // |document_url| (supposedly the URL of the frame).
309 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme)) 309 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme))
310 return document_url; 310 return document_url;
311 311
312 // Non-sandboxed about:blank and about:srcdoc pages inherit their security 312 // Non-sandboxed about:blank and about:srcdoc pages inherit their security
313 // origin from their parent frame/window. So, traverse the frame/window 313 // origin from their parent frame/window. So, traverse the frame/window
314 // hierarchy to find the closest non-about:-page and return its URL. 314 // hierarchy to find the closest non-about:-page and return its URL.
315 const blink::WebFrame* parent = frame; 315 blink::WebFrame* parent = frame;
316 blink::WebDocument parent_document;
316 do { 317 do {
317 if (parent->Parent()) 318 if (parent->Parent())
318 parent = parent->Parent(); 319 parent = parent->Parent();
319 else if (parent->Opener() != parent) 320 else if (parent->Opener() != parent)
320 parent = parent->Opener(); 321 parent = parent->Opener();
321 else 322 else
322 parent = nullptr; 323 parent = nullptr;
323 } while (parent && !parent->GetDocument().IsNull() &&
324 GURL(parent->GetDocument().Url()).SchemeIs(url::kAboutScheme));
325 324
326 if (parent && !parent->GetDocument().IsNull()) { 325 parent_document = parent && parent->IsWebLocalFrame()
326 ? parent->ToWebLocalFrame()->GetDocument()
327 : blink::WebDocument();
328 } while (!parent_document.IsNull() &&
329 GURL(parent_document.Url()).SchemeIs(url::kAboutScheme));
330
331 if (!parent_document.IsNull()) {
327 // Only return the parent URL if the frame can access it. 332 // Only return the parent URL if the frame can access it.
328 const blink::WebDocument& parent_document = parent->GetDocument();
329 if (frame->GetDocument().GetSecurityOrigin().CanAccess( 333 if (frame->GetDocument().GetSecurityOrigin().CanAccess(
330 parent_document.GetSecurityOrigin())) { 334 parent_document.GetSecurityOrigin())) {
331 return parent_document.Url(); 335 return parent_document.Url();
332 } 336 }
333 } 337 }
334 return document_url; 338 return document_url;
335 } 339 }
336 340
337 ScriptContext* ScriptContext::GetContext() { 341 ScriptContext* ScriptContext::GetContext() {
338 DCHECK(thread_checker_.CalledOnValidThread()); 342 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 525
522 v8::Local<v8::Object> global = v8_context()->Global(); 526 v8::Local<v8::Object> global = v8_context()->Global();
523 if (!web_frame_) 527 if (!web_frame_)
524 return handle_scope.Escape(function->Call(global, argc, argv)); 528 return handle_scope.Escape(function->Call(global, argc, argv));
525 return handle_scope.Escape( 529 return handle_scope.Escape(
526 v8::Local<v8::Value>(web_frame_->CallFunctionEvenIfScriptDisabled( 530 v8::Local<v8::Value>(web_frame_->CallFunctionEvenIfScriptDisabled(
527 function, global, argc, argv))); 531 function, global, argc, argv)));
528 } 532 }
529 533
530 } // namespace extensions 534 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context.h ('k') | extensions/renderer/script_context_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698