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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/script_context.cc
diff --git a/extensions/renderer/script_context.cc b/extensions/renderer/script_context.cc
index 197e6c0c764c6ee96c514d876b832a2dea46894d..9a60177ad76ebe841bc8da9c7331b4081b9d14e4 100644
--- a/extensions/renderer/script_context.cc
+++ b/extensions/renderer/script_context.cc
@@ -300,7 +300,7 @@ GURL ScriptContext::GetAccessCheckedFrameURL(
}
// static
-GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebLocalFrame* frame,
+GURL ScriptContext::GetEffectiveDocumentURL(blink::WebLocalFrame* frame,
const GURL& document_url,
bool match_about_blank) {
// Common scenario. If |match_about_blank| is false (as is the case in most
@@ -312,7 +312,8 @@ GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebLocalFrame* frame,
// Non-sandboxed about:blank and about:srcdoc pages inherit their security
// origin from their parent frame/window. So, traverse the frame/window
// hierarchy to find the closest non-about:-page and return its URL.
- const blink::WebFrame* parent = frame;
+ blink::WebFrame* parent = frame;
+ blink::WebDocument parent_document;
do {
if (parent->Parent())
parent = parent->Parent();
@@ -320,12 +321,15 @@ GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebLocalFrame* frame,
parent = parent->Opener();
else
parent = nullptr;
- } while (parent && !parent->GetDocument().IsNull() &&
- GURL(parent->GetDocument().Url()).SchemeIs(url::kAboutScheme));
- if (parent && !parent->GetDocument().IsNull()) {
+ parent_document = parent && parent->IsWebLocalFrame()
+ ? parent->ToWebLocalFrame()->GetDocument()
+ : blink::WebDocument();
+ } while (!parent_document.IsNull() &&
+ GURL(parent_document.Url()).SchemeIs(url::kAboutScheme));
+
+ if (!parent_document.IsNull()) {
// Only return the parent URL if the frame can access it.
- const blink::WebDocument& parent_document = parent->GetDocument();
if (frame->GetDocument().GetSecurityOrigin().CanAccess(
parent_document.GetSecurityOrigin())) {
return parent_document.Url();
« 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