| 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_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_ |
| 6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 ~ExtensionFunctionDispatcher(); | 99 ~ExtensionFunctionDispatcher(); |
| 100 | 100 |
| 101 Delegate* delegate() { return delegate_; } | 101 Delegate* delegate() { return delegate_; } |
| 102 | 102 |
| 103 // Message handlers. | 103 // Message handlers. |
| 104 // The response is sent to the corresponding render view in an | 104 // The response is sent to the corresponding render view in an |
| 105 // ExtensionMsg_Response message. | 105 // ExtensionMsg_Response message. |
| 106 // TODO (jam): convert all callers to use RenderFrameHost. | 106 // TODO (jam): convert all callers to use RenderFrameHost. |
| 107 void Dispatch(const ExtensionHostMsg_Request_Params& params, | 107 void Dispatch(const ExtensionHostMsg_Request_Params& params, |
| 108 content::RenderViewHost* render_view_host); | 108 content::RenderViewHost* render_view_host); |
| 109 // Dispatch an extension function and calls |callback| when the execution | |
| 110 // completes. | |
| 111 void DispatchWithCallback( | |
| 112 const ExtensionHostMsg_Request_Params& params, | |
| 113 content::RenderFrameHost* render_frame_host, | |
| 114 const ExtensionFunction::ResponseCallback& callback); | |
| 115 | 109 |
| 116 // Called when an ExtensionFunction is done executing, after it has sent | 110 // Called when an ExtensionFunction is done executing, after it has sent |
| 117 // a response (if any) to the extension. | 111 // a response (if any) to the extension. |
| 118 void OnExtensionFunctionCompleted(const Extension* extension); | 112 void OnExtensionFunctionCompleted(const Extension* extension); |
| 119 | 113 |
| 120 // The BrowserContext that this dispatcher is associated with. | 114 // The BrowserContext that this dispatcher is associated with. |
| 121 content::BrowserContext* browser_context() { return browser_context_; } | 115 content::BrowserContext* browser_context() { return browser_context_; } |
| 122 | 116 |
| 123 private: | 117 private: |
| 124 // For a given RenderViewHost instance, UIThreadResponseCallbackWrapper | 118 // For a given RenderViewHost instance, UIThreadResponseCallbackWrapper |
| 125 // creates ExtensionFunction::ResponseCallback instances which send responses | 119 // creates ExtensionFunction::ResponseCallback instances which send responses |
| 126 // to the corresponding render view in ExtensionMsg_Response messages. | 120 // to the corresponding render view in ExtensionMsg_Response messages. |
| 127 // This class tracks the lifespan of the RenderViewHost instance, and will be | 121 // This class tracks the lifespan of the RenderViewHost instance, and will be |
| 128 // destroyed automatically when it goes away. | 122 // destroyed automatically when it goes away. |
| 129 class UIThreadResponseCallbackWrapper; | 123 class UIThreadResponseCallbackWrapper; |
| 130 | 124 |
| 131 // Helper to check whether an ExtensionFunction has the required permissions. | 125 // Helper to check whether an ExtensionFunction has the required permissions. |
| 132 // This should be called after the function is fully initialized. | 126 // This should be called after the function is fully initialized. |
| 133 // If the check fails, |callback| is run with an access-denied error and false | 127 // If the check fails, |callback| is run with an access-denied error and false |
| 134 // is returned. |function| must not be run in that case. | 128 // is returned. |function| must not be run in that case. |
| 135 static bool CheckPermissions( | 129 static bool CheckPermissions( |
| 136 ExtensionFunction* function, | 130 ExtensionFunction* function, |
| 137 const Extension* extension, | |
| 138 const ExtensionHostMsg_Request_Params& params, | 131 const ExtensionHostMsg_Request_Params& params, |
| 139 const ExtensionFunction::ResponseCallback& callback); | 132 const ExtensionFunction::ResponseCallback& callback); |
| 140 | 133 |
| 141 // Helper to create an ExtensionFunction to handle the function given by | 134 // Helper to create an ExtensionFunction to handle the function given by |
| 142 // |params|. Can be called on any thread. | 135 // |params|. Can be called on any thread. |
| 143 // Does not set subclass properties, or include_incognito. | 136 // Does not set subclass properties, or include_incognito. |
| 144 static ExtensionFunction* CreateExtensionFunction( | 137 static ExtensionFunction* CreateExtensionFunction( |
| 145 const ExtensionHostMsg_Request_Params& params, | 138 const ExtensionHostMsg_Request_Params& params, |
| 146 const Extension* extension, | 139 const Extension* extension, |
| 147 int requesting_process_id, | 140 int requesting_process_id, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 169 // instance goes away, the corresponding entry in this map (if exists) will be | 162 // instance goes away, the corresponding entry in this map (if exists) will be |
| 170 // removed. | 163 // removed. |
| 171 typedef std::map<content::RenderViewHost*, UIThreadResponseCallbackWrapper*> | 164 typedef std::map<content::RenderViewHost*, UIThreadResponseCallbackWrapper*> |
| 172 UIThreadResponseCallbackWrapperMap; | 165 UIThreadResponseCallbackWrapperMap; |
| 173 UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_; | 166 UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_; |
| 174 }; | 167 }; |
| 175 | 168 |
| 176 } // namespace extensions | 169 } // namespace extensions |
| 177 | 170 |
| 178 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_ | 171 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_ |
| OLD | NEW |