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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/public/child/v8_value_converter.h" | 12 #include "content/public/child/v8_value_converter.h" |
13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
14 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
16 #include "extensions/common/constants.h" | |
17 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
18 #include "extensions/common/extension_api.h" | 17 #include "extensions/common/extension_api.h" |
19 #include "extensions/common/extension_set.h" | |
20 #include "extensions/common/extension_urls.h" | 18 #include "extensions/common/extension_urls.h" |
21 #include "extensions/common/features/base_feature_provider.h" | 19 #include "extensions/common/features/base_feature_provider.h" |
22 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" | |
23 #include "extensions/common/permissions/permissions_data.h" | 20 #include "extensions/common/permissions/permissions_data.h" |
24 #include "gin/per_context_data.h" | 21 #include "gin/per_context_data.h" |
25 #include "third_party/WebKit/public/web/WebDataSource.h" | 22 #include "third_party/WebKit/public/web/WebDataSource.h" |
26 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
27 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
28 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
29 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 25 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
30 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 26 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
31 #include "third_party/WebKit/public/web/WebView.h" | 27 #include "third_party/WebKit/public/web/WebView.h" |
32 #include "v8/include/v8.h" | 28 #include "v8/include/v8.h" |
33 | 29 |
34 using content::V8ValueConverter; | 30 using content::V8ValueConverter; |
35 | 31 |
36 namespace extensions { | 32 namespace extensions { |
37 | 33 |
38 namespace { | 34 namespace { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 v8::Handle<v8::Value> receiver, | 68 v8::Handle<v8::Value> receiver, |
73 int argc, | 69 int argc, |
74 v8::Handle<v8::Value> argv[]) override; | 70 v8::Handle<v8::Value> argv[]) override; |
75 gin::ContextHolder* GetContextHolder() override; | 71 gin::ContextHolder* GetContextHolder() override; |
76 | 72 |
77 private: | 73 private: |
78 ScriptContext* context_; | 74 ScriptContext* context_; |
79 }; | 75 }; |
80 | 76 |
81 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, | 77 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, |
82 blink::WebLocalFrame* web_frame, | 78 blink::WebFrame* web_frame, |
83 const Extension* extension, | 79 const Extension* extension, |
84 Feature::Context context_type, | 80 Feature::Context context_type, |
85 const Extension* effective_extension, | 81 const Extension* effective_extension, |
86 Feature::Context effective_context_type) | 82 Feature::Context effective_context_type) |
87 : v8_context_(v8_context->GetIsolate(), v8_context), | 83 : v8_context_(v8_context->GetIsolate(), v8_context), |
88 web_frame_(web_frame), | 84 web_frame_(web_frame), |
89 extension_(extension), | 85 extension_(extension), |
90 context_type_(context_type), | 86 context_type_(context_type), |
91 effective_extension_(effective_extension), | 87 effective_extension_(effective_extension), |
92 effective_context_type_(effective_context_type), | 88 effective_context_type_(effective_context_type), |
(...skipping 14 matching lines...) Expand all Loading... |
107 } | 103 } |
108 | 104 |
109 ScriptContext::~ScriptContext() { | 105 ScriptContext::~ScriptContext() { |
110 VLOG(1) << "Destroyed context for extension\n" | 106 VLOG(1) << "Destroyed context for extension\n" |
111 << " extension id: " << GetExtensionID() << "\n" | 107 << " extension id: " << GetExtensionID() << "\n" |
112 << " effective extension id: " | 108 << " effective extension id: " |
113 << (effective_extension_.get() ? effective_extension_->id() : ""); | 109 << (effective_extension_.get() ? effective_extension_->id() : ""); |
114 Invalidate(); | 110 Invalidate(); |
115 } | 111 } |
116 | 112 |
117 // static | |
118 bool ScriptContext::IsSandboxedPage(const ExtensionSet& extensions, | |
119 const GURL& url) { | |
120 // TODO(kalman): This is checking for the wrong thing, it should be checking | |
121 // if the frame's security origin is unique. The extension sandbox directive | |
122 // is checked for in extensions/common/manifest_handlers/csp_info.cc. | |
123 if (url.SchemeIs(kExtensionScheme)) { | |
124 const Extension* extension = extensions.GetByID(url.host()); | |
125 if (extension) { | |
126 return SandboxedPageInfo::IsSandboxedPage(extension, url.path()); | |
127 } | |
128 } | |
129 return false; | |
130 } | |
131 | |
132 void ScriptContext::Invalidate() { | 113 void ScriptContext::Invalidate() { |
133 if (!is_valid()) | 114 if (!is_valid()) |
134 return; | 115 return; |
135 if (module_system_) | 116 if (module_system_) |
136 module_system_->Invalidate(); | 117 module_system_->Invalidate(); |
137 web_frame_ = NULL; | 118 web_frame_ = NULL; |
138 v8_context_.Reset(); | 119 v8_context_.Reset(); |
139 runner_.reset(); | 120 runner_.reset(); |
140 } | 121 } |
141 | 122 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 v8::Handle<v8::Value> argv[]) { | 311 v8::Handle<v8::Value> argv[]) { |
331 return context_->CallFunction(function, argc, argv); | 312 return context_->CallFunction(function, argc, argv); |
332 } | 313 } |
333 | 314 |
334 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { | 315 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { |
335 v8::HandleScope handle_scope(context_->isolate()); | 316 v8::HandleScope handle_scope(context_->isolate()); |
336 return gin::PerContextData::From(context_->v8_context())->context_holder(); | 317 return gin::PerContextData::From(context_->v8_context())->context_holder(); |
337 } | 318 } |
338 | 319 |
339 } // namespace extensions | 320 } // namespace extensions |
OLD | NEW |