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

Side by Side Diff: ppapi/proxy/ppb_file_chooser_proxy.cc

Issue 7844018: Revert 100748 - This patch tries to remove most of the manual registration for Pepper interfaces,... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_file_chooser_proxy.h ('k') | ppapi/proxy/ppb_file_ref_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "ppapi/proxy/ppb_file_chooser_proxy.h" 5 #include "ppapi/proxy/ppb_file_chooser_proxy.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "ppapi/c/dev/ppb_file_chooser_dev.h" 9 #include "ppapi/c/dev/ppb_file_chooser_dev.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/private/ppb_proxy_private.h" 11 #include "ppapi/c/private/ppb_proxy_private.h"
12 #include "ppapi/proxy/enter_proxy.h" 12 #include "ppapi/proxy/enter_proxy.h"
13 #include "ppapi/proxy/host_dispatcher.h" 13 #include "ppapi/proxy/host_dispatcher.h"
14 #include "ppapi/proxy/plugin_dispatcher.h" 14 #include "ppapi/proxy/plugin_dispatcher.h"
15 #include "ppapi/proxy/ppapi_messages.h" 15 #include "ppapi/proxy/ppapi_messages.h"
16 #include "ppapi/proxy/ppb_file_ref_proxy.h" 16 #include "ppapi/proxy/ppb_file_ref_proxy.h"
17 #include "ppapi/proxy/serialized_var.h" 17 #include "ppapi/proxy/serialized_var.h"
18 #include "ppapi/shared_impl/var.h" 18 #include "ppapi/shared_impl/var.h"
19 #include "ppapi/thunk/resource_creation_api.h"
20 #include "ppapi/thunk/thunk.h" 19 #include "ppapi/thunk/thunk.h"
21 20
22 using ppapi::thunk::PPB_FileChooser_API; 21 using ppapi::thunk::PPB_FileChooser_API;
23 22
24 namespace ppapi { 23 namespace ppapi {
25 namespace proxy { 24 namespace proxy {
26 25
27 class FileChooser : public Resource, 26 class FileChooser : public Resource,
28 public PPB_FileChooser_API { 27 public PPB_FileChooser_API {
29 public: 28 public:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // by the FileChooser object until they're passed to the plugin. 111 // by the FileChooser object until they're passed to the plugin.
113 DCHECK(file_queue_.empty()); 112 DCHECK(file_queue_.empty());
114 for (size_t i = 0; i < chosen_files.size(); i++) 113 for (size_t i = 0; i < chosen_files.size(); i++)
115 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); 114 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i]));
116 115
117 // Notify the plugin of the new data. 116 // Notify the plugin of the new data.
118 PP_RunAndClearCompletionCallback(&current_show_callback_, result_code); 117 PP_RunAndClearCompletionCallback(&current_show_callback_, result_code);
119 // DANGER: May delete |this|! 118 // DANGER: May delete |this|!
120 } 119 }
121 120
122 PPB_FileChooser_Proxy::PPB_FileChooser_Proxy(Dispatcher* dispatcher) 121 namespace {
123 : InterfaceProxy(dispatcher), 122
123 PP_Resource Create0_4(PP_Instance instance,
124 const PP_FileChooserOptions_0_4_Dev* options) {
125 PP_Var accept_var = PP_MakeUndefined();
126 if (options->accept_mime_types)
127 accept_var = StringVar::StringToPPVar(0, options->accept_mime_types);
128 PP_Resource result = thunk::GetPPB_FileChooser_Thunk()->Create(
129 instance, options->mode, accept_var);
130 if (accept_var.type == PP_VARTYPE_STRING)
131 PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(accept_var);
132 return result;
133 }
134
135 PP_Bool IsFileChooser0_4(PP_Resource resource) {
136 return thunk::GetPPB_FileChooser_Thunk()->IsFileChooser(resource);
137 }
138
139 int32_t Show0_4(PP_Resource chooser, PP_CompletionCallback callback) {
140 return thunk::GetPPB_FileChooser_Thunk()->Show(chooser, callback);
141 }
142
143 PP_Resource GetNextChosenFile0_4(PP_Resource chooser) {
144 return thunk::GetPPB_FileChooser_Thunk()->GetNextChosenFile(chooser);
145 }
146
147 PPB_FileChooser_0_4_Dev file_chooser_0_4_interface = {
148 &Create0_4,
149 &IsFileChooser0_4,
150 &Show0_4,
151 &GetNextChosenFile0_4
152 };
153
154 InterfaceProxy* CreateFileChooserProxy(Dispatcher* dispatcher,
155 const void* target_interface) {
156 return new PPB_FileChooser_Proxy(dispatcher, target_interface);
157 }
158
159 } // namespace
160
161 PPB_FileChooser_Proxy::PPB_FileChooser_Proxy(Dispatcher* dispatcher,
162 const void* target_interface)
163 : InterfaceProxy(dispatcher, target_interface),
124 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 164 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
125 } 165 }
126 166
127 PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() { 167 PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() {
128 } 168 }
129 169
170 const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo() {
171 static const Info info = {
172 thunk::GetPPB_FileChooser_Thunk(),
173 PPB_FILECHOOSER_DEV_INTERFACE,
174 INTERFACE_ID_PPB_FILE_CHOOSER,
175 false,
176 &CreateFileChooserProxy,
177 };
178 return &info;
179 }
180
181 const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo0_4() {
182 static const Info info = {
183 &file_chooser_0_4_interface,
184 PPB_FILECHOOSER_DEV_INTERFACE_0_4,
185 INTERFACE_ID_NONE,
186 false,
187 &CreateFileChooserProxy,
188 };
189 return &info;
190 }
191
130 // static 192 // static
131 PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( 193 PP_Resource PPB_FileChooser_Proxy::CreateProxyResource(
132 PP_Instance instance, 194 PP_Instance instance,
133 PP_FileChooserMode_Dev mode, 195 PP_FileChooserMode_Dev mode,
134 const PP_Var& accept_mime_types) { 196 const PP_Var& accept_mime_types) {
135 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 197 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
136 if (!dispatcher) 198 if (!dispatcher)
137 return 0; 199 return 0;
138 200
139 HostResource result; 201 HostResource result;
(...skipping 20 matching lines...) Expand all
160 IPC_MESSAGE_UNHANDLED(handled = false) 222 IPC_MESSAGE_UNHANDLED(handled = false)
161 IPC_END_MESSAGE_MAP() 223 IPC_END_MESSAGE_MAP()
162 return handled; 224 return handled;
163 } 225 }
164 226
165 void PPB_FileChooser_Proxy::OnMsgCreate( 227 void PPB_FileChooser_Proxy::OnMsgCreate(
166 PP_Instance instance, 228 PP_Instance instance,
167 int mode, 229 int mode,
168 SerializedVarReceiveInput accept_mime_types, 230 SerializedVarReceiveInput accept_mime_types,
169 HostResource* result) { 231 HostResource* result) {
170 thunk::EnterResourceCreation enter(instance); 232 result->SetHostResource(instance, ppb_file_chooser_target()->Create(
171 if (enter.succeeded()) { 233 instance, static_cast<PP_FileChooserMode_Dev>(mode),
172 result->SetHostResource(instance, enter.functions()->CreateFileChooser( 234 accept_mime_types.Get(dispatcher())));
173 instance, static_cast<PP_FileChooserMode_Dev>(mode),
174 accept_mime_types.Get(dispatcher())));
175 }
176 } 235 }
177 236
178 void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) { 237 void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) {
179 EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter( 238 EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter(
180 chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback, 239 chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback,
181 chooser); 240 chooser);
182 if (enter.succeeded()) 241 if (enter.succeeded())
183 enter.SetResult(enter.object()->Show(enter.callback())); 242 enter.SetResult(enter.object()->Show(enter.callback()));
184 } 243 }
185 244
186 void PPB_FileChooser_Proxy::OnMsgChooseComplete( 245 void PPB_FileChooser_Proxy::OnMsgChooseComplete(
187 const HostResource& chooser, 246 const HostResource& chooser,
188 int32_t result_code, 247 int32_t result_code,
189 const std::vector<PPB_FileRef_CreateInfo>& chosen_files) { 248 const std::vector<PPB_FileRef_CreateInfo>& chosen_files) {
190 EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser); 249 EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser);
191 if (enter.succeeded()) { 250 if (enter.succeeded()) {
192 static_cast<FileChooser*>(enter.object())->ChooseComplete( 251 static_cast<FileChooser*>(enter.object())->ChooseComplete(
193 result_code, chosen_files); 252 result_code, chosen_files);
194 } 253 }
195 } 254 }
196 255
197 void PPB_FileChooser_Proxy::OnShowCallback(int32_t result, 256 void PPB_FileChooser_Proxy::OnShowCallback(int32_t result,
198 const HostResource& chooser) { 257 const HostResource& chooser) {
199 EnterHostFromHostResource<PPB_FileChooser_API> enter(chooser);
200
201 std::vector<PPB_FileRef_CreateInfo> files; 258 std::vector<PPB_FileRef_CreateInfo> files;
202 if (enter.succeeded() && result == PP_OK) { 259 if (result == PP_OK) {
260 // Jump through some hoops to get the FileRef proxy. Since we know we're
261 // in the host at this point, we can ask the host dispatcher for it.
262 DCHECK(!dispatcher()->IsPlugin());
263 HostDispatcher* host_disp = static_cast<HostDispatcher*>(dispatcher());
203 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( 264 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>(
204 dispatcher()->GetInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); 265 host_disp->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_FILE_REF));
205 266
206 // Convert the returned files to the serialized info. 267 // Convert the returned files to the serialized info.
207 while (PP_Resource cur_file_resource = 268 while (PP_Resource cur_file_resource =
208 enter.object()->GetNextChosenFile()) { 269 ppb_file_chooser_target()->GetNextChosenFile(
270 chooser.host_resource())) {
209 PPB_FileRef_CreateInfo cur_create_info; 271 PPB_FileRef_CreateInfo cur_create_info;
210 file_ref_proxy->SerializeFileRef(cur_file_resource, &cur_create_info); 272 file_ref_proxy->SerializeFileRef(cur_file_resource, &cur_create_info);
211 files.push_back(cur_create_info); 273 files.push_back(cur_create_info);
212 } 274 }
213 } 275 }
214 276
215 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete( 277 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete(
216 INTERFACE_ID_PPB_FILE_CHOOSER, chooser, result, files)); 278 INTERFACE_ID_PPB_FILE_CHOOSER, chooser, result, files));
217 } 279 }
218 280
219 } // namespace proxy 281 } // namespace proxy
220 } // namespace ppapi 282 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_file_chooser_proxy.h ('k') | ppapi/proxy/ppb_file_ref_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698