Index: extensions/renderer/script_context.cc |
diff --git a/extensions/renderer/script_context.cc b/extensions/renderer/script_context.cc |
index 587087bd1a5e05af173a28c3375f7c346ca4e205..514817a9c2d9f0316e133e4dc79baccc3b478b28 100644 |
--- a/extensions/renderer/script_context.cc |
+++ b/extensions/renderer/script_context.cc |
@@ -4,8 +4,6 @@ |
#include "extensions/renderer/script_context.h" |
-#include <memory> |
- |
#include "base/command_line.h" |
#include "base/logging.h" |
#include "base/macros.h" |
@@ -108,12 +106,13 @@ ScriptContext::ScriptContext(const v8::Local<v8::Context>& v8_context, |
effective_context_type_(effective_context_type), |
safe_builtins_(this), |
isolate_(v8_context->GetIsolate()), |
- url_(web_frame_ ? GetDataSourceURLForFrame(web_frame_) : GURL()), |
runner_(new Runner(this)) { |
VLOG(1) << "Created context:\n" << GetDebugString(); |
gin::PerContextData* gin_data = gin::PerContextData::From(v8_context); |
CHECK(gin_data); |
gin_data->set_runner(runner_.get()); |
+ if (web_frame_) |
+ url_ = GetAccessCheckedFrameURL(web_frame_); |
} |
ScriptContext::~ScriptContext() { |
@@ -281,6 +280,22 @@ GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { |
} |
// static |
+GURL ScriptContext::GetAccessCheckedFrameURL(const blink::WebFrame* frame) { |
+ const blink::WebURL& weburl = frame->document().url(); |
+ if (weburl.isEmpty()) { |
+ blink::WebDataSource* data_source = frame->provisionalDataSource() |
+ ? frame->provisionalDataSource() |
+ : frame->dataSource(); |
+ if (data_source && |
+ frame->getSecurityOrigin().canAccess( |
+ blink::WebSecurityOrigin::create(data_source->request().url()))) { |
+ return GURL(data_source->request().url()); |
+ } |
+ } |
+ return GURL(weburl); |
+} |
+ |
+// static |
GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebFrame* frame, |
const GURL& document_url, |
bool match_about_blank) { |