OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 // Return the chromeHidden object associated with this context, or an empty | 79 // Return the chromeHidden object associated with this context, or an empty |
80 // handle if no chrome hidden has been created (by GetOrCreateChromeHidden) | 80 // handle if no chrome hidden has been created (by GetOrCreateChromeHidden) |
81 // yet for this context. | 81 // yet for this context. |
82 v8::Handle<v8::Value> GetChromeHidden() const; | 82 v8::Handle<v8::Value> GetChromeHidden() const; |
83 | 83 |
84 // Returns the RenderView associated with this context. Can return NULL if the | 84 // Returns the RenderView associated with this context. Can return NULL if the |
85 // context is in the process of being destroyed. | 85 // context is in the process of being destroyed. |
86 content::RenderView* GetRenderView() const; | 86 content::RenderView* GetRenderView() const; |
87 | 87 |
| 88 // Runs |function| with appropriate scopes. Doesn't catch exceptions, callers |
| 89 // must do that if they want. |
| 90 // |
| 91 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE. |
| 92 v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function, |
| 93 int argc, |
| 94 v8::Handle<v8::Value> argv[]) const; |
| 95 |
88 // Fires the onunload event on the chromeHidden object. | 96 // Fires the onunload event on the chromeHidden object. |
89 void DispatchOnUnloadEvent(); | 97 void DispatchOnUnloadEvent(); |
90 | 98 |
91 // Call the named method of the chromeHidden object in this context. | |
92 // The function can be a sub-property like "Port.dispatchOnMessage". Returns | |
93 // the result of the function call in |result| if |result| is non-NULL. If the | |
94 // named method does not exist, returns false. | |
95 bool CallChromeHiddenMethod( | |
96 const std::string& function_name, | |
97 int argc, | |
98 v8::Handle<v8::Value>* argv, | |
99 v8::Handle<v8::Value>* result) const; | |
100 | |
101 // Returns the availability of the API |api_name|. | 99 // Returns the availability of the API |api_name|. |
102 Feature::Availability GetAvailability(const std::string& api_name); | 100 Feature::Availability GetAvailability(const std::string& api_name); |
103 | 101 |
104 // Returns whether the API |api_name| or any part of the API could be | 102 // Returns whether the API |api_name| or any part of the API could be |
105 // available in this context without taking into account the context's | 103 // available in this context without taking into account the context's |
106 // extension. | 104 // extension. |
107 bool IsAnyFeatureAvailableToContext(const std::string& api_name); | 105 bool IsAnyFeatureAvailableToContext(const std::string& api_name); |
108 | 106 |
109 // Returns a string description of the type of context this is. | 107 // Returns a string description of the type of context this is. |
110 std::string GetContextTypeDescription(); | 108 std::string GetContextTypeDescription(); |
111 | 109 |
112 // RequestSender::Source implementation. | 110 // RequestSender::Source implementation. |
113 virtual ChromeV8Context* GetContext() OVERRIDE; | 111 virtual ChromeV8Context* GetContext() OVERRIDE; |
114 virtual void OnResponseReceived(const std::string& name, | 112 virtual void OnResponseReceived(const std::string& name, |
115 int request_id, | 113 int request_id, |
116 bool success, | 114 bool success, |
117 const base::ListValue& response, | 115 const base::ListValue& response, |
118 const std::string& error) OVERRIDE; | 116 const std::string& error) OVERRIDE; |
119 | 117 |
120 private: | 118 private: |
| 119 bool is_valid() const; |
| 120 |
121 // The v8 context the bindings are accessible to. | 121 // The v8 context the bindings are accessible to. |
122 ScopedPersistent<v8::Context> v8_context_; | 122 ScopedPersistent<v8::Context> v8_context_; |
123 | 123 |
124 // The WebFrame associated with this context. This can be NULL because this | 124 // The WebFrame associated with this context. This can be NULL because this |
125 // object can outlive is destroyed asynchronously. | 125 // object can outlive is destroyed asynchronously. |
126 WebKit::WebFrame* web_frame_; | 126 WebKit::WebFrame* web_frame_; |
127 | 127 |
128 // The extension associated with this context, or NULL if there is none. This | 128 // The extension associated with this context, or NULL if there is none. This |
129 // might be a hosted app in the case that this context is hosting a web URL. | 129 // might be a hosted app in the case that this context is hosting a web URL. |
130 scoped_refptr<const Extension> extension_; | 130 scoped_refptr<const Extension> extension_; |
131 | 131 |
132 // The type of context. | 132 // The type of context. |
133 Feature::Context context_type_; | 133 Feature::Context context_type_; |
134 | 134 |
135 // Owns and structures the JS that is injected to set up extension bindings. | 135 // Owns and structures the JS that is injected to set up extension bindings. |
136 scoped_ptr<ModuleSystem> module_system_; | 136 scoped_ptr<ModuleSystem> module_system_; |
137 | 137 |
138 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 138 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
139 }; | 139 }; |
140 | 140 |
141 } // namespace extensions | 141 } // namespace extensions |
142 | 142 |
143 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 143 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
OLD | NEW |