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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "extensions/common/features/feature.h" | 12 #include "extensions/common/features/feature.h" |
13 #include "extensions/common/permissions/api_permission_set.h" | 13 #include "extensions/common/permissions/api_permission_set.h" |
14 #include "extensions/renderer/module_system.h" | 14 #include "extensions/renderer/module_system.h" |
15 #include "extensions/renderer/request_sender.h" | 15 #include "extensions/renderer/request_sender.h" |
16 #include "extensions/renderer/safe_builtins.h" | 16 #include "extensions/renderer/safe_builtins.h" |
17 #include "gin/runner.h" | 17 #include "gin/runner.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 #include "v8/include/v8.h" | 19 #include "v8/include/v8.h" |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 class WebFrame; | 22 class WebFrame; |
| 23 class WebLocalFrame; |
23 } | 24 } |
24 | 25 |
25 namespace content { | 26 namespace content { |
26 class RenderFrame; | 27 class RenderFrame; |
27 class RenderView; | 28 class RenderView; |
28 } | 29 } |
29 | 30 |
30 namespace extensions { | 31 namespace extensions { |
31 class Extension; | 32 class Extension; |
| 33 class ExtensionSet; |
32 | 34 |
33 // Extensions wrapper for a v8 context. | 35 // Extensions wrapper for a v8 context. |
34 class ScriptContext : public RequestSender::Source { | 36 class ScriptContext : public RequestSender::Source { |
35 public: | 37 public: |
36 ScriptContext(const v8::Handle<v8::Context>& context, | 38 ScriptContext(const v8::Handle<v8::Context>& context, |
37 blink::WebFrame* frame, | 39 blink::WebLocalFrame* frame, |
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 |
| 46 // Returns whether |url| is sandboxed (as declared in any Extension in |
| 47 // |extension_set| as sandboxed). |
| 48 // |
| 49 // Declared in ScriptContext for lack of a better place, but this should |
| 50 // become unnecessary at some point as crbug.com/466373 is worked on. |
| 51 static bool IsSandboxedPage(const ExtensionSet& extension_set, |
| 52 const GURL& url); |
| 53 |
44 // Clears the WebFrame for this contexts and invalidates the associated | 54 // Clears the WebFrame for this contexts and invalidates the associated |
45 // ModuleSystem. | 55 // ModuleSystem. |
46 void Invalidate(); | 56 void Invalidate(); |
47 | 57 |
48 // Returns true if this context is still valid, false if it isn't. | 58 // Returns true if this context is still valid, false if it isn't. |
49 // A context becomes invalid via Invalidate(). | 59 // A context becomes invalid via Invalidate(). |
50 bool is_valid() const { return !v8_context_.IsEmpty(); } | 60 bool is_valid() const { return !v8_context_.IsEmpty(); } |
51 | 61 |
52 v8::Handle<v8::Context> v8_context() const { | 62 v8::Handle<v8::Context> v8_context() const { |
53 return v8::Local<v8::Context>::New(isolate_, v8_context_); | 63 return v8::Local<v8::Context>::New(isolate_, v8_context_); |
54 } | 64 } |
55 | 65 |
56 const Extension* extension() const { return extension_.get(); } | 66 const Extension* extension() const { return extension_.get(); } |
57 | 67 |
58 const Extension* effective_extension() const { | 68 const Extension* effective_extension() const { |
59 return effective_extension_.get(); | 69 return effective_extension_.get(); |
60 } | 70 } |
61 | 71 |
62 blink::WebFrame* web_frame() const { return web_frame_; } | 72 blink::WebLocalFrame* web_frame() const { return web_frame_; } |
63 | 73 |
64 Feature::Context context_type() const { return context_type_; } | 74 Feature::Context context_type() const { return context_type_; } |
65 | 75 |
66 Feature::Context effective_context_type() const { | 76 Feature::Context effective_context_type() const { |
67 return effective_context_type_; | 77 return effective_context_type_; |
68 } | 78 } |
69 | 79 |
70 void set_module_system(scoped_ptr<ModuleSystem> module_system) { | 80 void set_module_system(scoped_ptr<ModuleSystem> module_system) { |
71 module_system_ = module_system.Pass(); | 81 module_system_ = module_system.Pass(); |
72 } | 82 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 117 |
108 // Returns a string description of the type of context this is. | 118 // Returns a string description of the type of context this is. |
109 std::string GetContextTypeDescription(); | 119 std::string GetContextTypeDescription(); |
110 | 120 |
111 // Returns a string description of the effective type of context this is. | 121 // Returns a string description of the effective type of context this is. |
112 std::string GetEffectiveContextTypeDescription(); | 122 std::string GetEffectiveContextTypeDescription(); |
113 | 123 |
114 v8::Isolate* isolate() const { return isolate_; } | 124 v8::Isolate* isolate() const { return isolate_; } |
115 | 125 |
116 // Get the URL of this context's web frame. | 126 // Get the URL of this context's web frame. |
| 127 // |
| 128 // TODO(kalman): Remove this and replace with a GetOrigin() call which reads |
| 129 // of WebDocument::securityOrigin(): |
| 130 // - The URL can change (e.g. pushState) but the origin cannot. Luckily it |
| 131 // appears as though callers don't make security decisions based on the |
| 132 // result of GetURL() so it's not a problem... yet. |
| 133 // - Origin is the correct check to be making. |
| 134 // - It might let us remove the about:blank resolving? |
117 GURL GetURL() const; | 135 GURL GetURL() const; |
118 | 136 |
119 // Returns whether the API |api| or any part of the API could be | 137 // Returns whether the API |api| or any part of the API could be |
120 // available in this context without taking into account the context's | 138 // available in this context without taking into account the context's |
121 // extension. | 139 // extension. |
122 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api); | 140 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api); |
123 | 141 |
124 // Utility to get the URL we will match against for a frame. If the frame has | 142 // Utility to get the URL we will match against for a frame. If the frame has |
125 // committed, this is the commited URL. Otherwise it is the provisional URL. | 143 // committed, this is the commited URL. Otherwise it is the provisional URL. |
126 // The returned URL may be invalid. | 144 // The returned URL may be invalid. |
(...skipping 23 matching lines...) Expand all Loading... |
150 // extension. | 168 // extension. |
151 bool HasAPIPermission(APIPermission::ID permission) const; | 169 bool HasAPIPermission(APIPermission::ID permission) const; |
152 | 170 |
153 protected: | 171 protected: |
154 // The v8 context the bindings are accessible to. | 172 // The v8 context the bindings are accessible to. |
155 v8::Global<v8::Context> v8_context_; | 173 v8::Global<v8::Context> v8_context_; |
156 | 174 |
157 private: | 175 private: |
158 class Runner; | 176 class Runner; |
159 | 177 |
160 // The WebFrame associated with this context. This can be NULL because this | 178 // The WebLocalFrame associated with this context. This can be NULL because |
161 // object can outlive is destroyed asynchronously. | 179 // this object can outlive is destroyed asynchronously. |
162 blink::WebFrame* web_frame_; | 180 blink::WebLocalFrame* web_frame_; |
163 | 181 |
164 // The extension associated with this context, or NULL if there is none. This | 182 // 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. | 183 // might be a hosted app in the case that this context is hosting a web URL. |
166 scoped_refptr<const Extension> extension_; | 184 scoped_refptr<const Extension> extension_; |
167 | 185 |
168 // The type of context. | 186 // The type of context. |
169 Feature::Context context_type_; | 187 Feature::Context context_type_; |
170 | 188 |
171 // The effective extension associated with this context, or NULL if there is | 189 // 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 | 190 // none. This is different from the above extension if this context is in an |
(...skipping 17 matching lines...) Expand all Loading... |
190 GURL url_; | 208 GURL url_; |
191 | 209 |
192 scoped_ptr<Runner> runner_; | 210 scoped_ptr<Runner> runner_; |
193 | 211 |
194 DISALLOW_COPY_AND_ASSIGN(ScriptContext); | 212 DISALLOW_COPY_AND_ASSIGN(ScriptContext); |
195 }; | 213 }; |
196 | 214 |
197 } // namespace extensions | 215 } // namespace extensions |
198 | 216 |
199 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 217 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
OLD | NEW |