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

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

Issue 2241203003: Pass user session type to extension feature checks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: split out some stuff 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
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 gin::ContextHolder* GetContextHolder() override; 89 gin::ContextHolder* GetContextHolder() override;
90 90
91 private: 91 private:
92 ScriptContext* context_; 92 ScriptContext* context_;
93 }; 93 };
94 94
95 ScriptContext::ScriptContext(const v8::Local<v8::Context>& v8_context, 95 ScriptContext::ScriptContext(const v8::Local<v8::Context>& v8_context,
96 blink::WebLocalFrame* web_frame, 96 blink::WebLocalFrame* web_frame,
97 const Extension* extension, 97 const Extension* extension,
98 Feature::Context context_type, 98 Feature::Context context_type,
99 Feature::SessionType session_type,
99 const Extension* effective_extension, 100 const Extension* effective_extension,
100 Feature::Context effective_context_type) 101 Feature::Context effective_context_type)
101 : is_valid_(true), 102 : is_valid_(true),
102 v8_context_(v8_context->GetIsolate(), v8_context), 103 v8_context_(v8_context->GetIsolate(), v8_context),
103 web_frame_(web_frame), 104 web_frame_(web_frame),
104 extension_(extension), 105 extension_(extension),
105 context_type_(context_type), 106 context_type_(context_type),
107 session_type_(session_type),
106 effective_extension_(effective_extension), 108 effective_extension_(effective_extension),
107 effective_context_type_(effective_context_type), 109 effective_context_type_(effective_context_type),
108 safe_builtins_(this), 110 safe_builtins_(this),
109 isolate_(v8_context->GetIsolate()), 111 isolate_(v8_context->GetIsolate()),
110 runner_(new Runner(this)) { 112 runner_(new Runner(this)) {
111 VLOG(1) << "Created context:\n" << GetDebugString(); 113 VLOG(1) << "Created context:\n" << GetDebugString();
112 gin::PerContextData* gin_data = gin::PerContextData::From(v8_context); 114 gin::PerContextData* gin_data = gin::PerContextData::From(v8_context);
113 CHECK(gin_data); 115 CHECK(gin_data);
114 gin_data->set_runner(runner_.get()); 116 gin_data->set_runner(runner_.get());
115 if (web_frame_) 117 if (web_frame_)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 223 }
222 // Hack: Hosted apps should have the availability of messaging APIs based on 224 // Hack: Hosted apps should have the availability of messaging APIs based on
223 // the URL of the page (which might have access depending on some extension 225 // the URL of the page (which might have access depending on some extension
224 // with externally_connectable), not whether the app has access to messaging 226 // with externally_connectable), not whether the app has access to messaging
225 // (which it won't). 227 // (which it won't).
226 const Extension* extension = extension_.get(); 228 const Extension* extension = extension_.get();
227 if (extension && extension->is_hosted_app() && 229 if (extension && extension->is_hosted_app() &&
228 (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) { 230 (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) {
229 extension = NULL; 231 extension = NULL;
230 } 232 }
231 return ExtensionAPI::GetSharedInstance()->IsAvailable(api_name, extension, 233 return ExtensionAPI::GetSharedInstance()->IsAvailable(
232 context_type_, url()); 234 api_name, extension, context_type_, session_type_, url());
233 } 235 }
234 236
235 void ScriptContext::DispatchEvent(const char* event_name, 237 void ScriptContext::DispatchEvent(const char* event_name,
236 v8::Local<v8::Array> args) const { 238 v8::Local<v8::Array> args) const {
237 DCHECK(thread_checker_.CalledOnValidThread()); 239 DCHECK(thread_checker_.CalledOnValidThread());
238 v8::HandleScope handle_scope(isolate()); 240 v8::HandleScope handle_scope(isolate());
239 v8::Context::Scope context_scope(v8_context()); 241 v8::Context::Scope context_scope(v8_context());
240 242
241 v8::Local<v8::Value> argv[] = {v8::String::NewFromUtf8(isolate(), event_name), 243 v8::Local<v8::Value> argv[] = {v8::String::NewFromUtf8(isolate(), event_name),
242 args}; 244 args};
(...skipping 11 matching lines...) Expand all
254 return GetContextTypeDescriptionString(effective_context_type_); 256 return GetContextTypeDescriptionString(effective_context_type_);
255 } 257 }
256 258
257 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { 259 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) {
258 DCHECK(thread_checker_.CalledOnValidThread()); 260 DCHECK(thread_checker_.CalledOnValidThread());
259 // TODO(lazyboy): Decide what we should do for SERVICE_WORKER_CONTEXT. 261 // TODO(lazyboy): Decide what we should do for SERVICE_WORKER_CONTEXT.
260 GURL url = context_type() == Feature::SERVICE_WORKER_CONTEXT 262 GURL url = context_type() == Feature::SERVICE_WORKER_CONTEXT
261 ? url_ 263 ? url_
262 : GetDataSourceURLForFrame(web_frame()); 264 : GetDataSourceURLForFrame(web_frame());
263 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( 265 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext(
264 api, extension(), context_type(), url); 266 api, extension(), context_type(), session_type_, url);
265 } 267 }
266 268
267 // static 269 // static
268 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { 270 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) {
269 // Normally we would use frame->document().url() to determine the document's 271 // Normally we would use frame->document().url() to determine the document's
270 // URL, but to decide whether to inject a content script, we use the URL from 272 // URL, but to decide whether to inject a content script, we use the URL from
271 // the data source. This "quirk" helps prevents content scripts from 273 // the data source. This "quirk" helps prevents content scripts from
272 // inadvertently adding DOM elements to the compose iframe in Gmail because 274 // inadvertently adding DOM elements to the compose iframe in Gmail because
273 // the compose iframe's dataSource URL is about:blank, but the document URL 275 // the compose iframe's dataSource URL is about:blank, but the document URL
274 // changes to match the parent document after Gmail document.writes into 276 // changes to match the parent document after Gmail document.writes into
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 v8::Local<v8::Value> argv[]) { 503 v8::Local<v8::Value> argv[]) {
502 return context_->CallFunction(function, argc, argv); 504 return context_->CallFunction(function, argc, argv);
503 } 505 }
504 506
505 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 507 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
506 v8::HandleScope handle_scope(context_->isolate()); 508 v8::HandleScope handle_scope(context_->isolate());
507 return gin::PerContextData::From(context_->v8_context())->context_holder(); 509 return gin::PerContextData::From(context_->v8_context())->context_holder();
508 } 510 }
509 511
510 } // namespace extensions 512 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698