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