| 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; | |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 27 class RenderFrame; | 26 class RenderFrame; |
| 28 class RenderView; | 27 class RenderView; |
| 29 } | 28 } |
| 30 | 29 |
| 31 namespace extensions { | 30 namespace extensions { |
| 32 class Extension; | 31 class Extension; |
| 33 class ExtensionSet; | |
| 34 | 32 |
| 35 // Extensions wrapper for a v8 context. | 33 // Extensions wrapper for a v8 context. |
| 36 class ScriptContext : public RequestSender::Source { | 34 class ScriptContext : public RequestSender::Source { |
| 37 public: | 35 public: |
| 38 ScriptContext(const v8::Handle<v8::Context>& context, | 36 ScriptContext(const v8::Handle<v8::Context>& context, |
| 39 blink::WebLocalFrame* frame, | 37 blink::WebFrame* frame, |
| 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 // 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 | |
| 54 // Clears the WebFrame for this contexts and invalidates the associated | 44 // Clears the WebFrame for this contexts and invalidates the associated |
| 55 // ModuleSystem. | 45 // ModuleSystem. |
| 56 void Invalidate(); | 46 void Invalidate(); |
| 57 | 47 |
| 58 // 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. |
| 59 // A context becomes invalid via Invalidate(). | 49 // A context becomes invalid via Invalidate(). |
| 60 bool is_valid() const { return !v8_context_.IsEmpty(); } | 50 bool is_valid() const { return !v8_context_.IsEmpty(); } |
| 61 | 51 |
| 62 v8::Handle<v8::Context> v8_context() const { | 52 v8::Handle<v8::Context> v8_context() const { |
| 63 return v8::Local<v8::Context>::New(isolate_, v8_context_); | 53 return v8::Local<v8::Context>::New(isolate_, v8_context_); |
| 64 } | 54 } |
| 65 | 55 |
| 66 const Extension* extension() const { return extension_.get(); } | 56 const Extension* extension() const { return extension_.get(); } |
| 67 | 57 |
| 68 const Extension* effective_extension() const { | 58 const Extension* effective_extension() const { |
| 69 return effective_extension_.get(); | 59 return effective_extension_.get(); |
| 70 } | 60 } |
| 71 | 61 |
| 72 blink::WebLocalFrame* web_frame() const { return web_frame_; } | 62 blink::WebFrame* web_frame() const { return web_frame_; } |
| 73 | 63 |
| 74 Feature::Context context_type() const { return context_type_; } | 64 Feature::Context context_type() const { return context_type_; } |
| 75 | 65 |
| 76 Feature::Context effective_context_type() const { | 66 Feature::Context effective_context_type() const { |
| 77 return effective_context_type_; | 67 return effective_context_type_; |
| 78 } | 68 } |
| 79 | 69 |
| 80 void set_module_system(scoped_ptr<ModuleSystem> module_system) { | 70 void set_module_system(scoped_ptr<ModuleSystem> module_system) { |
| 81 module_system_ = module_system.Pass(); | 71 module_system_ = module_system.Pass(); |
| 82 } | 72 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 107 |
| 118 // Returns a string description of the type of context this is. | 108 // Returns a string description of the type of context this is. |
| 119 std::string GetContextTypeDescription(); | 109 std::string GetContextTypeDescription(); |
| 120 | 110 |
| 121 // Returns a string description of the effective type of context this is. | 111 // Returns a string description of the effective type of context this is. |
| 122 std::string GetEffectiveContextTypeDescription(); | 112 std::string GetEffectiveContextTypeDescription(); |
| 123 | 113 |
| 124 v8::Isolate* isolate() const { return isolate_; } | 114 v8::Isolate* isolate() const { return isolate_; } |
| 125 | 115 |
| 126 // Get the URL of this context's web frame. | 116 // 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? | |
| 135 GURL GetURL() const; | 117 GURL GetURL() const; |
| 136 | 118 |
| 137 // Returns whether the API |api| or any part of the API could be | 119 // Returns whether the API |api| or any part of the API could be |
| 138 // available in this context without taking into account the context's | 120 // available in this context without taking into account the context's |
| 139 // extension. | 121 // extension. |
| 140 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api); | 122 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api); |
| 141 | 123 |
| 142 // Utility to get the URL we will match against for a frame. If the frame has | 124 // Utility to get the URL we will match against for a frame. If the frame has |
| 143 // committed, this is the commited URL. Otherwise it is the provisional URL. | 125 // committed, this is the commited URL. Otherwise it is the provisional URL. |
| 144 // The returned URL may be invalid. | 126 // The returned URL may be invalid. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 168 // extension. | 150 // extension. |
| 169 bool HasAPIPermission(APIPermission::ID permission) const; | 151 bool HasAPIPermission(APIPermission::ID permission) const; |
| 170 | 152 |
| 171 protected: | 153 protected: |
| 172 // The v8 context the bindings are accessible to. | 154 // The v8 context the bindings are accessible to. |
| 173 v8::Global<v8::Context> v8_context_; | 155 v8::Global<v8::Context> v8_context_; |
| 174 | 156 |
| 175 private: | 157 private: |
| 176 class Runner; | 158 class Runner; |
| 177 | 159 |
| 178 // The WebLocalFrame associated with this context. This can be NULL because | 160 // The WebFrame associated with this context. This can be NULL because this |
| 179 // this object can outlive is destroyed asynchronously. | 161 // object can outlive is destroyed asynchronously. |
| 180 blink::WebLocalFrame* web_frame_; | 162 blink::WebFrame* web_frame_; |
| 181 | 163 |
| 182 // 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 |
| 183 // 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. |
| 184 scoped_refptr<const Extension> extension_; | 166 scoped_refptr<const Extension> extension_; |
| 185 | 167 |
| 186 // The type of context. | 168 // The type of context. |
| 187 Feature::Context context_type_; | 169 Feature::Context context_type_; |
| 188 | 170 |
| 189 // 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 |
| 190 // 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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 208 GURL url_; | 190 GURL url_; |
| 209 | 191 |
| 210 scoped_ptr<Runner> runner_; | 192 scoped_ptr<Runner> runner_; |
| 211 | 193 |
| 212 DISALLOW_COPY_AND_ASSIGN(ScriptContext); | 194 DISALLOW_COPY_AND_ASSIGN(ScriptContext); |
| 213 }; | 195 }; |
| 214 | 196 |
| 215 } // namespace extensions | 197 } // namespace extensions |
| 216 | 198 |
| 217 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 199 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
| OLD | NEW |