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 = context_type() == Feature::SERVICE_WORKER_CONTEXT |
| 260 ? url_ |
| 261 : GetDataSourceURLForFrame(web_frame()); |
258 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( | 262 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( |
259 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame())); | 263 api, extension(), context_type(), url); |
260 } | 264 } |
261 | 265 |
262 // static | 266 // static |
263 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { | 267 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { |
264 // Normally we would use frame->document().url() to determine the document's | 268 // 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 | 269 // 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 | 270 // the data source. This "quirk" helps prevents content scripts from |
267 // inadvertently adding DOM elements to the compose iframe in Gmail because | 271 // 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 | 272 // 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 | 273 // 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[]) { | 484 v8::Local<v8::Value> argv[]) { |
481 return context_->CallFunction(function, argc, argv); | 485 return context_->CallFunction(function, argc, argv); |
482 } | 486 } |
483 | 487 |
484 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { | 488 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { |
485 v8::HandleScope handle_scope(context_->isolate()); | 489 v8::HandleScope handle_scope(context_->isolate()); |
486 return gin::PerContextData::From(context_->v8_context())->context_holder(); | 490 return gin::PerContextData::From(context_->v8_context())->context_holder(); |
487 } | 491 } |
488 | 492 |
489 } // namespace extensions | 493 } // namespace extensions |
OLD | NEW |