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 #include <vector> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 class RenderView; | 30 class RenderView; |
31 } | 31 } |
32 | 32 |
33 namespace extensions { | 33 namespace extensions { |
34 class Extension; | 34 class Extension; |
35 class ExtensionSet; | 35 class ExtensionSet; |
36 | 36 |
37 // Extensions wrapper for a v8 context. | 37 // Extensions wrapper for a v8 context. |
38 class ScriptContext : public RequestSender::Source { | 38 class ScriptContext : public RequestSender::Source { |
39 public: | 39 public: |
40 ScriptContext(const v8::Handle<v8::Context>& context, | 40 ScriptContext(const v8::Local<v8::Context>& context, |
41 blink::WebLocalFrame* frame, | 41 blink::WebLocalFrame* frame, |
42 const Extension* extension, | 42 const Extension* extension, |
43 Feature::Context context_type, | 43 Feature::Context context_type, |
44 const Extension* effective_extension, | 44 const Extension* effective_extension, |
45 Feature::Context effective_context_type); | 45 Feature::Context effective_context_type); |
46 ~ScriptContext() override; | 46 ~ScriptContext() override; |
47 | 47 |
48 // Returns whether |url| from any Extension in |extension_set| is sandboxed, | 48 // Returns whether |url| from any Extension in |extension_set| is sandboxed, |
49 // as declared in each Extension's manifest. | 49 // as declared in each Extension's manifest. |
50 // TODO(kalman): Delete this when crbug.com/466373 is fixed. | 50 // TODO(kalman): Delete this when crbug.com/466373 is fixed. |
51 // See comment in HasAccessOrThrowError. | 51 // See comment in HasAccessOrThrowError. |
52 static bool IsSandboxedPage(const ExtensionSet& extension_set, | 52 static bool IsSandboxedPage(const ExtensionSet& extension_set, |
53 const GURL& url); | 53 const GURL& url); |
54 | 54 |
55 // Clears the WebFrame for this contexts and invalidates the associated | 55 // Clears the WebFrame for this contexts and invalidates the associated |
56 // ModuleSystem. | 56 // ModuleSystem. |
57 void Invalidate(); | 57 void Invalidate(); |
58 | 58 |
59 // Registers |observer| to be run when this context is invalidated. Closures | 59 // Registers |observer| to be run when this context is invalidated. Closures |
60 // are run immediately when Invalidate() is called, not in a message loop. | 60 // are run immediately when Invalidate() is called, not in a message loop. |
61 void AddInvalidationObserver(const base::Closure& observer); | 61 void AddInvalidationObserver(const base::Closure& observer); |
62 | 62 |
63 // Returns true if this context is still valid, false if it isn't. | 63 // Returns true if this context is still valid, false if it isn't. |
64 // A context becomes invalid via Invalidate(). | 64 // A context becomes invalid via Invalidate(). |
65 bool is_valid() const { return is_valid_; } | 65 bool is_valid() const { return is_valid_; } |
66 | 66 |
67 v8::Handle<v8::Context> v8_context() const { | 67 v8::Local<v8::Context> v8_context() const { |
68 return v8::Local<v8::Context>::New(isolate_, v8_context_); | 68 return v8::Local<v8::Context>::New(isolate_, v8_context_); |
69 } | 69 } |
70 | 70 |
71 const Extension* extension() const { return extension_.get(); } | 71 const Extension* extension() const { return extension_.get(); } |
72 | 72 |
73 const Extension* effective_extension() const { | 73 const Extension* effective_extension() const { |
74 return effective_extension_.get(); | 74 return effective_extension_.get(); |
75 } | 75 } |
76 | 76 |
77 blink::WebLocalFrame* web_frame() const { return web_frame_; } | 77 blink::WebLocalFrame* web_frame() const { return web_frame_; } |
(...skipping 23 matching lines...) Expand all Loading... |
101 content::RenderView* GetRenderView() const; | 101 content::RenderView* GetRenderView() const; |
102 | 102 |
103 // Returns the RenderFrame associated with this context. Can return NULL if | 103 // Returns the RenderFrame associated with this context. Can return NULL if |
104 // the context is in the process of being destroyed. | 104 // the context is in the process of being destroyed. |
105 content::RenderFrame* GetRenderFrame() const; | 105 content::RenderFrame* GetRenderFrame() const; |
106 | 106 |
107 // Runs |function| with appropriate scopes. Doesn't catch exceptions, callers | 107 // Runs |function| with appropriate scopes. Doesn't catch exceptions, callers |
108 // must do that if they want. | 108 // must do that if they want. |
109 // | 109 // |
110 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE. | 110 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE. |
111 v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function, | 111 v8::Local<v8::Value> CallFunction(v8::Local<v8::Function> function, |
112 int argc, | 112 int argc, |
113 v8::Handle<v8::Value> argv[]) const; | 113 v8::Local<v8::Value> argv[]) const; |
114 | 114 |
115 void DispatchEvent(const char* event_name, v8::Handle<v8::Array> args) const; | 115 void DispatchEvent(const char* event_name, v8::Local<v8::Array> args) const; |
116 | 116 |
117 // Fires the onunload event on the unload_event module. | 117 // Fires the onunload event on the unload_event module. |
118 void DispatchOnUnloadEvent(); | 118 void DispatchOnUnloadEvent(); |
119 | 119 |
120 // Returns the availability of the API |api_name|. | 120 // Returns the availability of the API |api_name|. |
121 Feature::Availability GetAvailability(const std::string& api_name); | 121 Feature::Availability GetAvailability(const std::string& api_name); |
122 | 122 |
123 // Returns a string description of the type of context this is. | 123 // Returns a string description of the type of context this is. |
124 std::string GetContextTypeDescription(); | 124 std::string GetContextTypeDescription(); |
125 | 125 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 GURL url_; | 224 GURL url_; |
225 | 225 |
226 scoped_ptr<Runner> runner_; | 226 scoped_ptr<Runner> runner_; |
227 | 227 |
228 DISALLOW_COPY_AND_ASSIGN(ScriptContext); | 228 DISALLOW_COPY_AND_ASSIGN(ScriptContext); |
229 }; | 229 }; |
230 | 230 |
231 } // namespace extensions | 231 } // namespace extensions |
232 | 232 |
233 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 233 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
OLD | NEW |