Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: extensions/browser/extension_function_dispatcher.h

Issue 1880933002: Begin to enable extension APIs in Extension Service Worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // - This object outlives any RenderFrameHost's passed to created 89 // - This object outlives any RenderFrameHost's passed to created
90 // ExtensionFunctions. 90 // ExtensionFunctions.
91 explicit ExtensionFunctionDispatcher( 91 explicit ExtensionFunctionDispatcher(
92 content::BrowserContext* browser_context); 92 content::BrowserContext* browser_context);
93 ~ExtensionFunctionDispatcher(); 93 ~ExtensionFunctionDispatcher();
94 94
95 // Message handlers. 95 // Message handlers.
96 // The response is sent to the corresponding render view in an 96 // The response is sent to the corresponding render view in an
97 // ExtensionMsg_Response message. 97 // ExtensionMsg_Response message.
98 void Dispatch(const ExtensionHostMsg_Request_Params& params, 98 void Dispatch(const ExtensionHostMsg_Request_Params& params,
99 content::RenderFrameHost* render_frame_host); 99 content::RenderFrameHost* render_frame_host,
100 int render_process_id);
100 101
101 // Called when an ExtensionFunction is done executing, after it has sent 102 // Called when an ExtensionFunction is done executing, after it has sent
102 // a response (if any) to the extension. 103 // a response (if any) to the extension.
103 void OnExtensionFunctionCompleted(const Extension* extension); 104 void OnExtensionFunctionCompleted(const Extension* extension);
104 105
105 // See the Delegate class for documentation on these methods. 106 // See the Delegate class for documentation on these methods.
106 // TODO(devlin): None of these belong here. We should kill 107 // TODO(devlin): None of these belong here. We should kill
107 // ExtensionFunctionDispatcher::Delegate. 108 // ExtensionFunctionDispatcher::Delegate.
108 WindowController* GetExtensionWindowController() const; 109 WindowController* GetExtensionWindowController() const;
109 content::WebContents* GetAssociatedWebContents() const; 110 content::WebContents* GetAssociatedWebContents() const;
110 content::WebContents* GetVisibleWebContents() const; 111 content::WebContents* GetVisibleWebContents() const;
111 112
112 // The BrowserContext that this dispatcher is associated with. 113 // The BrowserContext that this dispatcher is associated with.
113 content::BrowserContext* browser_context() { return browser_context_; } 114 content::BrowserContext* browser_context() { return browser_context_; }
114 115
115 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 116 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
116 117
117 private: 118 private:
118 // For a given RenderFrameHost instance, UIThreadResponseCallbackWrapper 119 // For a given RenderFrameHost instance, UIThreadResponseCallbackWrapper
119 // creates ExtensionFunction::ResponseCallback instances which send responses 120 // creates ExtensionFunction::ResponseCallback instances which send responses
120 // to the corresponding render view in ExtensionMsg_Response messages. 121 // to the corresponding render view in ExtensionMsg_Response messages.
121 // This class tracks the lifespan of the RenderFrameHost instance, and will be 122 // This class tracks the lifespan of the RenderFrameHost instance, and will be
122 // destroyed automatically when it goes away. 123 // destroyed automatically when it goes away.
123 class UIThreadResponseCallbackWrapper; 124 class UIThreadResponseCallbackWrapper;
124 125
126 // Same as UIThreadResponseCallbackWrapper above, but applies to an extension
127 // function from an extension Service Worker.
128 class UIThreadWorkerResponseCallbackWrapper;
129
130 // Key used to store UIThreadWorkerResponseCallbackWrapper in the map
131 // |ui_thread_response_callback_wrappers_for_worker_|.
132 struct WorkerResponseCallbackMapKey;
133
125 // Helper to check whether an ExtensionFunction has the required permissions. 134 // Helper to check whether an ExtensionFunction has the required permissions.
126 // This should be called after the function is fully initialized. 135 // This should be called after the function is fully initialized.
127 // If the check fails, |callback| is run with an access-denied error and false 136 // If the check fails, |callback| is run with an access-denied error and false
128 // is returned. |function| must not be run in that case. 137 // is returned. |function| must not be run in that case.
129 static bool CheckPermissions( 138 static bool CheckPermissions(
130 ExtensionFunction* function, 139 ExtensionFunction* function,
131 const ExtensionHostMsg_Request_Params& params, 140 const ExtensionHostMsg_Request_Params& params,
132 const ExtensionFunction::ResponseCallback& callback); 141 const ExtensionFunction::ResponseCallback& callback);
133 142
134 // Helper to create an ExtensionFunction to handle the function given by 143 // Helper to create an ExtensionFunction to handle the function given by
(...skipping 10 matching lines...) Expand all
145 154
146 // Helper to run the response callback with an access denied error. Can be 155 // Helper to run the response callback with an access denied error. Can be
147 // called on any thread. 156 // called on any thread.
148 static void SendAccessDenied( 157 static void SendAccessDenied(
149 const ExtensionFunction::ResponseCallback& callback, 158 const ExtensionFunction::ResponseCallback& callback,
150 functions::HistogramValue histogram_value); 159 functions::HistogramValue histogram_value);
151 160
152 void DispatchWithCallbackInternal( 161 void DispatchWithCallbackInternal(
153 const ExtensionHostMsg_Request_Params& params, 162 const ExtensionHostMsg_Request_Params& params,
154 content::RenderFrameHost* render_frame_host, 163 content::RenderFrameHost* render_frame_host,
164 int render_process_id,
155 const ExtensionFunction::ResponseCallback& callback); 165 const ExtensionFunction::ResponseCallback& callback);
156 166
167 void RemoveWorkerCallbacksForProcess(int render_process_id);
168
157 content::BrowserContext* browser_context_; 169 content::BrowserContext* browser_context_;
158 170
159 Delegate* delegate_; 171 Delegate* delegate_;
160 172
161 // This map doesn't own either the keys or the values. When a RenderFrameHost 173 // This map doesn't own either the keys or the values. When a RenderFrameHost
162 // instance goes away, the corresponding entry in this map (if exists) will be 174 // instance goes away, the corresponding entry in this map (if exists) will be
163 // removed. 175 // removed.
164 typedef std::map<content::RenderFrameHost*, UIThreadResponseCallbackWrapper*> 176 typedef std::map<content::RenderFrameHost*, UIThreadResponseCallbackWrapper*>
165 UIThreadResponseCallbackWrapperMap; 177 UIThreadResponseCallbackWrapperMap;
166 UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_; 178 UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_;
179
180 using UIThreadWorkerResponseCallbackWrapperMap =
181 std::map<WorkerResponseCallbackMapKey,
182 std::unique_ptr<UIThreadWorkerResponseCallbackWrapper>>;
183 // TODO(lazyboy): The map entries are cleared upon RenderProcessHost shutown,
184 // we should really be clearing it on service worker shutdown.
185 UIThreadWorkerResponseCallbackWrapperMap
186 ui_thread_response_callback_wrappers_for_worker_;
167 }; 187 };
168 188
169 } // namespace extensions 189 } // namespace extensions
170 190
171 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_ 191 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_
OLDNEW
« no previous file with comments | « extensions/browser/extension_function.cc ('k') | extensions/browser/extension_function_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698