OLD | NEW |
---|---|
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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 return GetContextTypeDescriptionString(context_type_); | 248 return GetContextTypeDescriptionString(context_type_); |
249 } | 249 } |
250 | 250 |
251 std::string ScriptContext::GetEffectiveContextTypeDescription() const { | 251 std::string ScriptContext::GetEffectiveContextTypeDescription() const { |
252 DCHECK(thread_checker_.CalledOnValidThread()); | 252 DCHECK(thread_checker_.CalledOnValidThread()); |
253 return GetContextTypeDescriptionString(effective_context_type_); | 253 return GetContextTypeDescriptionString(effective_context_type_); |
254 } | 254 } |
255 | 255 |
256 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { | 256 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { |
257 DCHECK(thread_checker_.CalledOnValidThread()); | 257 DCHECK(thread_checker_.CalledOnValidThread()); |
258 // TODO(lazyboy): Decide what we should do for SERVICE_WORKER_CONTEXT. | |
259 GURL url = url_; | |
Devlin
2016/04/13 19:46:32
ternary?
lazyboy
2016/04/14 02:07:53
Done.
| |
260 if (context_type() != Feature::SERVICE_WORKER_CONTEXT) | |
261 url = GetDataSourceURLForFrame(web_frame()); | |
262 | |
258 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( | 263 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( |
259 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame())); | 264 api, extension(), context_type(), url); |
260 } | 265 } |
261 | 266 |
262 // static | 267 // static |
263 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { | 268 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { |
264 // Normally we would use frame->document().url() to determine the document's | 269 // Normally we would use frame->document().url() to determine the document's |
265 // URL, but to decide whether to inject a content script, we use the URL from | 270 // URL, but to decide whether to inject a content script, we use the URL from |
266 // the data source. This "quirk" helps prevents content scripts from | 271 // the data source. This "quirk" helps prevents content scripts from |
267 // inadvertently adding DOM elements to the compose iframe in Gmail because | 272 // inadvertently adding DOM elements to the compose iframe in Gmail because |
268 // the compose iframe's dataSource URL is about:blank, but the document URL | 273 // the compose iframe's dataSource URL is about:blank, but the document URL |
269 // changes to match the parent document after Gmail document.writes into | 274 // changes to match the parent document after Gmail document.writes into |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 v8::Local<v8::Value> argv[]) { | 485 v8::Local<v8::Value> argv[]) { |
481 return context_->CallFunction(function, argc, argv); | 486 return context_->CallFunction(function, argc, argv); |
482 } | 487 } |
483 | 488 |
484 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { | 489 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { |
485 v8::HandleScope handle_scope(context_->isolate()); | 490 v8::HandleScope handle_scope(context_->isolate()); |
486 return gin::PerContextData::From(context_->v8_context())->context_holder(); | 491 return gin::PerContextData::From(context_->v8_context())->context_holder(); |
487 } | 492 } |
488 | 493 |
489 } // namespace extensions | 494 } // namespace extensions |
OLD | NEW |