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 #ifndef EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
6 #define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 6 #define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/callback.h" | |
13 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
14 #include "extensions/common/features/feature.h" | 12 #include "extensions/common/features/feature.h" |
15 #include "extensions/common/permissions/api_permission_set.h" | 13 #include "extensions/common/permissions/api_permission_set.h" |
16 #include "extensions/renderer/module_system.h" | 14 #include "extensions/renderer/module_system.h" |
17 #include "extensions/renderer/request_sender.h" | 15 #include "extensions/renderer/request_sender.h" |
18 #include "extensions/renderer/safe_builtins.h" | 16 #include "extensions/renderer/safe_builtins.h" |
19 #include "gin/runner.h" | 17 #include "gin/runner.h" |
20 #include "url/gurl.h" | 18 #include "url/gurl.h" |
21 #include "v8/include/v8.h" | 19 #include "v8/include/v8.h" |
22 | 20 |
(...skipping 17 matching lines...) Expand all Loading... |
40 const Extension* extension, | 38 const Extension* extension, |
41 Feature::Context context_type, | 39 Feature::Context context_type, |
42 const Extension* effective_extension, | 40 const Extension* effective_extension, |
43 Feature::Context effective_context_type); | 41 Feature::Context effective_context_type); |
44 ~ScriptContext() override; | 42 ~ScriptContext() override; |
45 | 43 |
46 // Clears the WebFrame for this contexts and invalidates the associated | 44 // Clears the WebFrame for this contexts and invalidates the associated |
47 // ModuleSystem. | 45 // ModuleSystem. |
48 void Invalidate(); | 46 void Invalidate(); |
49 | 47 |
50 // Registers |observer| to be run when this context is invalidated. Closures | |
51 // are run immediately when Invalidate() is called, not in a message loop. | |
52 void AddInvalidationObserver(const base::Closure& observer); | |
53 | |
54 // Returns true if this context is still valid, false if it isn't. | 48 // Returns true if this context is still valid, false if it isn't. |
55 // A context becomes invalid via Invalidate(). | 49 // A context becomes invalid via Invalidate(). |
56 bool is_valid() const { return is_valid_; } | 50 bool is_valid() const { return !v8_context_.IsEmpty(); } |
57 | 51 |
58 v8::Handle<v8::Context> v8_context() const { | 52 v8::Handle<v8::Context> v8_context() const { |
59 return v8::Local<v8::Context>::New(isolate_, v8_context_); | 53 return v8::Local<v8::Context>::New(isolate_, v8_context_); |
60 } | 54 } |
61 | 55 |
62 const Extension* extension() const { return extension_.get(); } | 56 const Extension* extension() const { return extension_.get(); } |
63 | 57 |
64 const Extension* effective_extension() const { | 58 const Extension* effective_extension() const { |
65 return effective_extension_.get(); | 59 return effective_extension_.get(); |
66 } | 60 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 143 |
150 // Grants a set of content capabilities to this context. | 144 // Grants a set of content capabilities to this context. |
151 void SetContentCapabilities(const APIPermissionSet& permissions); | 145 void SetContentCapabilities(const APIPermissionSet& permissions); |
152 | 146 |
153 // Indicates if this context has an effective API permission either by being | 147 // Indicates if this context has an effective API permission either by being |
154 // a context for an extension which has that permission, or by being a web | 148 // a context for an extension which has that permission, or by being a web |
155 // context which has been granted the corresponding capability by an | 149 // context which has been granted the corresponding capability by an |
156 // extension. | 150 // extension. |
157 bool HasAPIPermission(APIPermission::ID permission) const; | 151 bool HasAPIPermission(APIPermission::ID permission) const; |
158 | 152 |
| 153 protected: |
| 154 // The v8 context the bindings are accessible to. |
| 155 v8::Global<v8::Context> v8_context_; |
| 156 |
159 private: | 157 private: |
160 class Runner; | 158 class Runner; |
161 | 159 |
162 // Whether this context is valid. | |
163 bool is_valid_; | |
164 | |
165 // The v8 context the bindings are accessible to. | |
166 v8::Global<v8::Context> v8_context_; | |
167 | |
168 // The WebFrame associated with this context. This can be NULL because this | 160 // The WebFrame associated with this context. This can be NULL because this |
169 // object can outlive is destroyed asynchronously. | 161 // object can outlive is destroyed asynchronously. |
170 blink::WebFrame* web_frame_; | 162 blink::WebFrame* web_frame_; |
171 | 163 |
172 // The extension associated with this context, or NULL if there is none. This | 164 // The extension associated with this context, or NULL if there is none. This |
173 // might be a hosted app in the case that this context is hosting a web URL. | 165 // might be a hosted app in the case that this context is hosting a web URL. |
174 scoped_refptr<const Extension> extension_; | 166 scoped_refptr<const Extension> extension_; |
175 | 167 |
176 // The type of context. | 168 // The type of context. |
177 Feature::Context context_type_; | 169 Feature::Context context_type_; |
178 | 170 |
179 // The effective extension associated with this context, or NULL if there is | 171 // The effective extension associated with this context, or NULL if there is |
180 // none. This is different from the above extension if this context is in an | 172 // none. This is different from the above extension if this context is in an |
181 // about:blank iframe for example. | 173 // about:blank iframe for example. |
182 scoped_refptr<const Extension> effective_extension_; | 174 scoped_refptr<const Extension> effective_extension_; |
183 | 175 |
184 // The type of context. | 176 // The type of context. |
185 Feature::Context effective_context_type_; | 177 Feature::Context effective_context_type_; |
186 | 178 |
187 // Owns and structures the JS that is injected to set up extension bindings. | 179 // Owns and structures the JS that is injected to set up extension bindings. |
188 scoped_ptr<ModuleSystem> module_system_; | 180 scoped_ptr<ModuleSystem> module_system_; |
189 | 181 |
190 // Contains safe copies of builtin objects like Function.prototype. | 182 // Contains safe copies of builtin objects like Function.prototype. |
191 SafeBuiltins safe_builtins_; | 183 SafeBuiltins safe_builtins_; |
192 | 184 |
193 // The set of capabilities granted to this context by extensions. | 185 // The set of capabilities granted to this context by extensions. |
194 APIPermissionSet content_capabilities_; | 186 APIPermissionSet content_capabilities_; |
195 | 187 |
196 // A list of base::Closure instances as an observer interface for | |
197 // invalidation. | |
198 std::vector<base::Closure> invalidate_observers_; | |
199 | |
200 v8::Isolate* isolate_; | 188 v8::Isolate* isolate_; |
201 | 189 |
202 GURL url_; | 190 GURL url_; |
203 | 191 |
204 scoped_ptr<Runner> runner_; | 192 scoped_ptr<Runner> runner_; |
205 | 193 |
206 DISALLOW_COPY_AND_ASSIGN(ScriptContext); | 194 DISALLOW_COPY_AND_ASSIGN(ScriptContext); |
207 }; | 195 }; |
208 | 196 |
209 } // namespace extensions | 197 } // namespace extensions |
210 | 198 |
211 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 199 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
OLD | NEW |