| 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 v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function, |
| 91 int argc, |
| 92 v8::Handle<v8::Value> argv[]) const; |
| 93 |
| 88 // Fires the onunload event on the chromeHidden object. | 94 // Fires the onunload event on the chromeHidden object. |
| 89 void DispatchOnUnloadEvent(); | 95 void DispatchOnUnloadEvent(); |
| 90 | 96 |
| 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|. | 97 // Returns the availability of the API |api_name|. |
| 102 Feature::Availability GetAvailability(const std::string& api_name); | 98 Feature::Availability GetAvailability(const std::string& api_name); |
| 103 | 99 |
| 104 // Returns whether the API |api_name| or any part of the API could be | 100 // 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 | 101 // available in this context without taking into account the context's |
| 106 // extension. | 102 // extension. |
| 107 bool IsAnyFeatureAvailableToContext(const std::string& api_name); | 103 bool IsAnyFeatureAvailableToContext(const std::string& api_name); |
| 108 | 104 |
| 109 // Returns a string description of the type of context this is. | 105 // Returns a string description of the type of context this is. |
| 110 std::string GetContextTypeDescription(); | 106 std::string GetContextTypeDescription(); |
| 111 | 107 |
| 112 // RequestSender::Source implementation. | 108 // RequestSender::Source implementation. |
| 113 virtual ChromeV8Context* GetContext() OVERRIDE; | 109 virtual ChromeV8Context* GetContext() OVERRIDE; |
| 114 virtual void OnResponseReceived(const std::string& name, | 110 virtual void OnResponseReceived(const std::string& name, |
| 115 int request_id, | 111 int request_id, |
| 116 bool success, | 112 bool success, |
| 117 const base::ListValue& response, | 113 const base::ListValue& response, |
| 118 const std::string& error) OVERRIDE; | 114 const std::string& error) OVERRIDE; |
| 119 | 115 |
| 120 private: | 116 private: |
| 117 bool is_valid() const; |
| 118 |
| 121 // The v8 context the bindings are accessible to. | 119 // The v8 context the bindings are accessible to. |
| 122 ScopedPersistent<v8::Context> v8_context_; | 120 ScopedPersistent<v8::Context> v8_context_; |
| 123 | 121 |
| 124 // The WebFrame associated with this context. This can be NULL because this | 122 // The WebFrame associated with this context. This can be NULL because this |
| 125 // object can outlive is destroyed asynchronously. | 123 // object can outlive is destroyed asynchronously. |
| 126 WebKit::WebFrame* web_frame_; | 124 WebKit::WebFrame* web_frame_; |
| 127 | 125 |
| 128 // The extension associated with this context, or NULL if there is none. This | 126 // 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. | 127 // might be a hosted app in the case that this context is hosting a web URL. |
| 130 scoped_refptr<const Extension> extension_; | 128 scoped_refptr<const Extension> extension_; |
| 131 | 129 |
| 132 // The type of context. | 130 // The type of context. |
| 133 Feature::Context context_type_; | 131 Feature::Context context_type_; |
| 134 | 132 |
| 135 // Owns and structures the JS that is injected to set up extension bindings. | 133 // Owns and structures the JS that is injected to set up extension bindings. |
| 136 scoped_ptr<ModuleSystem> module_system_; | 134 scoped_ptr<ModuleSystem> module_system_; |
| 137 | 135 |
| 138 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 136 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
| 139 }; | 137 }; |
| 140 | 138 |
| 141 } // namespace extensions | 139 } // namespace extensions |
| 142 | 140 |
| 143 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 141 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
| OLD | NEW |