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

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

Issue 2208483002: Fix extension bindings injection for iframes (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments, fixed lint Created 4 years, 4 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_set.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 <memory>
8
9 #include "base/command_line.h" 7 #include "base/command_line.h"
10 #include "base/logging.h" 8 #include "base/logging.h"
11 #include "base/macros.h" 9 #include "base/macros.h"
12 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 13 #include "base/values.h"
16 #include "content/public/child/v8_value_converter.h" 14 #include "content/public/child/v8_value_converter.h"
17 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
18 #include "content/public/common/url_constants.h" 16 #include "content/public/common/url_constants.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 Feature::Context effective_context_type) 100 Feature::Context effective_context_type)
103 : is_valid_(true), 101 : is_valid_(true),
104 v8_context_(v8_context->GetIsolate(), v8_context), 102 v8_context_(v8_context->GetIsolate(), v8_context),
105 web_frame_(web_frame), 103 web_frame_(web_frame),
106 extension_(extension), 104 extension_(extension),
107 context_type_(context_type), 105 context_type_(context_type),
108 effective_extension_(effective_extension), 106 effective_extension_(effective_extension),
109 effective_context_type_(effective_context_type), 107 effective_context_type_(effective_context_type),
110 safe_builtins_(this), 108 safe_builtins_(this),
111 isolate_(v8_context->GetIsolate()), 109 isolate_(v8_context->GetIsolate()),
112 url_(web_frame_ ? GetDataSourceURLForFrame(web_frame_) : GURL()),
113 runner_(new Runner(this)) { 110 runner_(new Runner(this)) {
114 VLOG(1) << "Created context:\n" << GetDebugString(); 111 VLOG(1) << "Created context:\n" << GetDebugString();
115 gin::PerContextData* gin_data = gin::PerContextData::From(v8_context); 112 gin::PerContextData* gin_data = gin::PerContextData::From(v8_context);
116 CHECK(gin_data); 113 CHECK(gin_data);
117 gin_data->set_runner(runner_.get()); 114 gin_data->set_runner(runner_.get());
115 if (web_frame_)
116 url_ = GetAccessCheckedFrameURL(web_frame_);
118 } 117 }
119 118
120 ScriptContext::~ScriptContext() { 119 ScriptContext::~ScriptContext() {
121 VLOG(1) << "Destroyed context for extension\n" 120 VLOG(1) << "Destroyed context for extension\n"
122 << " extension id: " << GetExtensionID() << "\n" 121 << " extension id: " << GetExtensionID() << "\n"
123 << " effective extension id: " 122 << " effective extension id: "
124 << (effective_extension_.get() ? effective_extension_->id() : ""); 123 << (effective_extension_.get() ? effective_extension_->id() : "");
125 CHECK(!is_valid_) << "ScriptContexts must be invalidated before destruction"; 124 CHECK(!is_valid_) << "ScriptContexts must be invalidated before destruction";
126 } 125 }
127 126
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // changes to match the parent document after Gmail document.writes into 274 // changes to match the parent document after Gmail document.writes into
276 // it to create the editor. 275 // it to create the editor.
277 // http://code.google.com/p/chromium/issues/detail?id=86742 276 // http://code.google.com/p/chromium/issues/detail?id=86742
278 blink::WebDataSource* data_source = frame->provisionalDataSource() 277 blink::WebDataSource* data_source = frame->provisionalDataSource()
279 ? frame->provisionalDataSource() 278 ? frame->provisionalDataSource()
280 : frame->dataSource(); 279 : frame->dataSource();
281 return data_source ? GURL(data_source->request().url()) : GURL(); 280 return data_source ? GURL(data_source->request().url()) : GURL();
282 } 281 }
283 282
284 // static 283 // static
284 GURL ScriptContext::GetAccessCheckedFrameURL(const blink::WebFrame* frame) {
285 const blink::WebURL& weburl = frame->document().url();
286 if (weburl.isEmpty()) {
287 blink::WebDataSource* data_source = frame->provisionalDataSource()
288 ? frame->provisionalDataSource()
289 : frame->dataSource();
290 if (data_source &&
291 frame->getSecurityOrigin().canAccess(
292 blink::WebSecurityOrigin::create(data_source->request().url()))) {
293 return GURL(data_source->request().url());
294 }
295 }
296 return GURL(weburl);
297 }
298
299 // static
285 GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebFrame* frame, 300 GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebFrame* frame,
286 const GURL& document_url, 301 const GURL& document_url,
287 bool match_about_blank) { 302 bool match_about_blank) {
288 // Common scenario. If |match_about_blank| is false (as is the case in most 303 // Common scenario. If |match_about_blank| is false (as is the case in most
289 // extensions), or if the frame is not an about:-page, just return 304 // extensions), or if the frame is not an about:-page, just return
290 // |document_url| (supposedly the URL of the frame). 305 // |document_url| (supposedly the URL of the frame).
291 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme)) 306 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme))
292 return document_url; 307 return document_url;
293 308
294 // Non-sandboxed about:blank and about:srcdoc pages inherit their security 309 // Non-sandboxed about:blank and about:srcdoc pages inherit their security
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 v8::Local<v8::Value> argv[]) { 501 v8::Local<v8::Value> argv[]) {
487 return context_->CallFunction(function, argc, argv); 502 return context_->CallFunction(function, argc, argv);
488 } 503 }
489 504
490 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 505 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
491 v8::HandleScope handle_scope(context_->isolate()); 506 v8::HandleScope handle_scope(context_->isolate());
492 return gin::PerContextData::From(context_->v8_context())->context_holder(); 507 return gin::PerContextData::From(context_->v8_context())->context_holder();
493 } 508 }
494 509
495 } // namespace extensions 510 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context.h ('k') | extensions/renderer/script_context_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698