| 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_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "extensions/browser/extension_function.h" | 13 #include "extensions/browser/extension_function.h" |
| 14 #include "ipc/ipc_sender.h" | 14 #include "ipc/ipc_sender.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 class ChromeRenderMessageFilter; | 17 class ChromeRenderMessageFilter; |
| 18 class Profile; | |
| 19 struct ExtensionHostMsg_Request_Params; | 18 struct ExtensionHostMsg_Request_Params; |
| 20 | 19 |
| 21 namespace content { | 20 namespace content { |
| 22 class BrowserContext; | 21 class BrowserContext; |
| 23 class RenderViewHost; | 22 class RenderViewHost; |
| 24 class WebContents; | 23 class WebContents; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace extensions { | 26 namespace extensions { |
| 28 class Extension; | 27 class Extension; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // |callback| is called when the function execution completes. | 111 // |callback| is called when the function execution completes. |
| 113 void DispatchWithCallback( | 112 void DispatchWithCallback( |
| 114 const ExtensionHostMsg_Request_Params& params, | 113 const ExtensionHostMsg_Request_Params& params, |
| 115 content::RenderViewHost* render_view_host, | 114 content::RenderViewHost* render_view_host, |
| 116 const ExtensionFunction::ResponseCallback& callback); | 115 const ExtensionFunction::ResponseCallback& callback); |
| 117 | 116 |
| 118 // Called when an ExtensionFunction is done executing, after it has sent | 117 // Called when an ExtensionFunction is done executing, after it has sent |
| 119 // a response (if any) to the extension. | 118 // a response (if any) to the extension. |
| 120 void OnExtensionFunctionCompleted(const extensions::Extension* extension); | 119 void OnExtensionFunctionCompleted(const extensions::Extension* extension); |
| 121 | 120 |
| 122 // The profile that this dispatcher is associated with. | 121 // The BrowserContext that this dispatcher is associated with. |
| 123 Profile* profile() { return profile_; } | 122 content::BrowserContext* browser_context() { return browser_context_; } |
| 124 | 123 |
| 125 private: | 124 private: |
| 126 // For a given RenderViewHost instance, UIThreadResponseCallbackWrapper | 125 // For a given RenderViewHost instance, UIThreadResponseCallbackWrapper |
| 127 // creates ExtensionFunction::ResponseCallback instances which send responses | 126 // creates ExtensionFunction::ResponseCallback instances which send responses |
| 128 // to the corresponding render view in ExtensionMsg_Response messages. | 127 // to the corresponding render view in ExtensionMsg_Response messages. |
| 129 // This class tracks the lifespan of the RenderViewHost instance, and will be | 128 // This class tracks the lifespan of the RenderViewHost instance, and will be |
| 130 // destroyed automatically when it goes away. | 129 // destroyed automatically when it goes away. |
| 131 class UIThreadResponseCallbackWrapper; | 130 class UIThreadResponseCallbackWrapper; |
| 132 | 131 |
| 133 // Helper to check whether an ExtensionFunction has the required permissions. | 132 // Helper to check whether an ExtensionFunction has the required permissions. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 150 const extensions::ProcessMap& process_map, | 149 const extensions::ProcessMap& process_map, |
| 151 extensions::ExtensionAPI* api, | 150 extensions::ExtensionAPI* api, |
| 152 void* profile, | 151 void* profile, |
| 153 const ExtensionFunction::ResponseCallback& callback); | 152 const ExtensionFunction::ResponseCallback& callback); |
| 154 | 153 |
| 155 // Helper to run the response callback with an access denied error. Can be | 154 // Helper to run the response callback with an access denied error. Can be |
| 156 // called on any thread. | 155 // called on any thread. |
| 157 static void SendAccessDenied( | 156 static void SendAccessDenied( |
| 158 const ExtensionFunction::ResponseCallback& callback); | 157 const ExtensionFunction::ResponseCallback& callback); |
| 159 | 158 |
| 160 Profile* profile_; | 159 content::BrowserContext* browser_context_; |
| 161 | 160 |
| 162 Delegate* delegate_; | 161 Delegate* delegate_; |
| 163 | 162 |
| 164 // This map doesn't own either the keys or the values. When a RenderViewHost | 163 // This map doesn't own either the keys or the values. When a RenderViewHost |
| 165 // instance goes away, the corresponding entry in this map (if exists) will be | 164 // instance goes away, the corresponding entry in this map (if exists) will be |
| 166 // removed. | 165 // removed. |
| 167 typedef std::map<content::RenderViewHost*, UIThreadResponseCallbackWrapper*> | 166 typedef std::map<content::RenderViewHost*, UIThreadResponseCallbackWrapper*> |
| 168 UIThreadResponseCallbackWrapperMap; | 167 UIThreadResponseCallbackWrapperMap; |
| 169 UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_; | 168 UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_; |
| 170 }; | 169 }; |
| 171 | 170 |
| 172 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ | 171 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ |
| OLD | NEW |