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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 return GetContextTypeDescriptionString(context_type_); | 249 return GetContextTypeDescriptionString(context_type_); |
250 } | 250 } |
251 | 251 |
252 std::string ScriptContext::GetEffectiveContextTypeDescription() const { | 252 std::string ScriptContext::GetEffectiveContextTypeDescription() const { |
253 DCHECK(thread_checker_.CalledOnValidThread()); | 253 DCHECK(thread_checker_.CalledOnValidThread()); |
254 return GetContextTypeDescriptionString(effective_context_type_); | 254 return GetContextTypeDescriptionString(effective_context_type_); |
255 } | 255 } |
256 | 256 |
257 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { | 257 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { |
258 DCHECK(thread_checker_.CalledOnValidThread()); | 258 DCHECK(thread_checker_.CalledOnValidThread()); |
| 259 // TODO(lazyboy): Decide what we should do for SERVICE_WORKER_CONTEXT. |
| 260 GURL url = context_type() == Feature::SERVICE_WORKER_CONTEXT |
| 261 ? url_ |
| 262 : GetDataSourceURLForFrame(web_frame()); |
259 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( | 263 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( |
260 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame())); | 264 api, extension(), context_type(), url); |
261 } | 265 } |
262 | 266 |
263 // static | 267 // static |
264 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { | 268 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { |
265 // 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 |
266 // 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 |
267 // the data source. This "quirk" helps prevents content scripts from | 271 // the data source. This "quirk" helps prevents content scripts from |
268 // inadvertently adding DOM elements to the compose iframe in Gmail because | 272 // inadvertently adding DOM elements to the compose iframe in Gmail because |
269 // 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 |
270 // 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... |
481 v8::Local<v8::Value> argv[]) { | 485 v8::Local<v8::Value> argv[]) { |
482 return context_->CallFunction(function, argc, argv); | 486 return context_->CallFunction(function, argc, argv); |
483 } | 487 } |
484 | 488 |
485 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { | 489 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { |
486 v8::HandleScope handle_scope(context_->isolate()); | 490 v8::HandleScope handle_scope(context_->isolate()); |
487 return gin::PerContextData::From(context_->v8_context())->context_holder(); | 491 return gin::PerContextData::From(context_->v8_context())->context_holder(); |
488 } | 492 } |
489 | 493 |
490 } // namespace extensions | 494 } // namespace extensions |
OLD | NEW |