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

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 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
125 // Helper to check whether an ExtensionFunction has the required permissions. 130 // Helper to check whether an ExtensionFunction has the required permissions.
126 // This should be called after the function is fully initialized. 131 // 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 132 // 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. 133 // is returned. |function| must not be run in that case.
129 static bool CheckPermissions( 134 static bool CheckPermissions(
130 ExtensionFunction* function, 135 ExtensionFunction* function,
131 const ExtensionHostMsg_Request_Params& params, 136 const ExtensionHostMsg_Request_Params& params,
132 const ExtensionFunction::ResponseCallback& callback); 137 const ExtensionFunction::ResponseCallback& callback);
133 138
134 // Helper to create an ExtensionFunction to handle the function given by 139 // Helper to create an ExtensionFunction to handle the function given by
(...skipping 10 matching lines...) Expand all
145 150
146 // Helper to run the response callback with an access denied error. Can be 151 // Helper to run the response callback with an access denied error. Can be
147 // called on any thread. 152 // called on any thread.
148 static void SendAccessDenied( 153 static void SendAccessDenied(
149 const ExtensionFunction::ResponseCallback& callback, 154 const ExtensionFunction::ResponseCallback& callback,
150 functions::HistogramValue histogram_value); 155 functions::HistogramValue histogram_value);
151 156
152 void DispatchWithCallbackInternal( 157 void DispatchWithCallbackInternal(
153 const ExtensionHostMsg_Request_Params& params, 158 const ExtensionHostMsg_Request_Params& params,
154 content::RenderFrameHost* render_frame_host, 159 content::RenderFrameHost* render_frame_host,
160 int render_process_id,
155 const ExtensionFunction::ResponseCallback& callback); 161 const ExtensionFunction::ResponseCallback& callback);
156 162
163 void RemoveWorkerCallbacksForProcess(int render_process_id);
164
157 content::BrowserContext* browser_context_; 165 content::BrowserContext* browser_context_;
158 166
159 Delegate* delegate_; 167 Delegate* delegate_;
160 168
161 // This map doesn't own either the keys or the values. When a RenderFrameHost 169 // 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 170 // instance goes away, the corresponding entry in this map (if exists) will be
163 // removed. 171 // removed.
164 typedef std::map<content::RenderFrameHost*, UIThreadResponseCallbackWrapper*> 172 typedef std::map<content::RenderFrameHost*, UIThreadResponseCallbackWrapper*>
165 UIThreadResponseCallbackWrapperMap; 173 UIThreadResponseCallbackWrapperMap;
166 UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_; 174 UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_;
175
176 // The key is <render process id, embedded worker id>.
177 using UIThreadWorkerResponseCallbackWrapperMapKey = std::pair<int, int>;
dcheng 2016/05/11 23:41:18 This should just be a simple struct. The typedef i
lazyboy 2016/05/12 00:21:22 Done.
178 using UIThreadWorkerResponseCallbackWrapperMap =
179 std::map<UIThreadWorkerResponseCallbackWrapperMapKey,
180 std::unique_ptr<UIThreadWorkerResponseCallbackWrapper>>;
181 // TODO(lazyboy): The map entries are cleared upon RenderProcessHost shutown,
182 // we should really be clearing it on service worker shutdown.
183 UIThreadWorkerResponseCallbackWrapperMap
184 ui_thread_response_callback_wrappers_for_worker_;
167 }; 185 };
168 186
169 } // namespace extensions 187 } // namespace extensions
170 188
171 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_ 189 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698