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 #include "content/renderer/pepper/pepper_file_chooser_host.h" | 5 #include "content/renderer/pepper/pepper_file_chooser_host.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/renderer/renderer_ppapi_host.h" | 9 #include "content/public/renderer/renderer_ppapi_host.h" |
10 #include "content/renderer/pepper/ppb_file_ref_impl.h" | |
11 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
12 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/host/dispatch_host_message.h" | 12 #include "ppapi/host/dispatch_host_message.h" |
14 #include "ppapi/host/ppapi_host.h" | 13 #include "ppapi/host/ppapi_host.h" |
15 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
16 #include "ppapi/proxy/ppb_file_ref_proxy.h" | |
17 #include "third_party/WebKit/public/platform/WebCString.h" | 15 #include "third_party/WebKit/public/platform/WebCString.h" |
18 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 17 #include "third_party/WebKit/public/platform/WebVector.h" |
20 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" | 18 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" |
21 #include "third_party/WebKit/public/web/WebFileChooserParams.h" | 19 #include "third_party/WebKit/public/web/WebFileChooserParams.h" |
22 | 20 |
23 namespace content { | 21 namespace content { |
24 | 22 |
25 class PepperFileChooserHost::CompletionHandler | 23 class PepperFileChooserHost::CompletionHandler |
26 : public WebKit::WebFileChooserCompletion { | 24 : public WebKit::WebFileChooserCompletion { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 display_name(display_name) { | 72 display_name(display_name) { |
75 } | 73 } |
76 | 74 |
77 | 75 |
78 PepperFileChooserHost::PepperFileChooserHost( | 76 PepperFileChooserHost::PepperFileChooserHost( |
79 RendererPpapiHost* host, | 77 RendererPpapiHost* host, |
80 PP_Instance instance, | 78 PP_Instance instance, |
81 PP_Resource resource) | 79 PP_Resource resource) |
82 : ResourceHost(host->GetPpapiHost(), instance, resource), | 80 : ResourceHost(host->GetPpapiHost(), instance, resource), |
83 renderer_ppapi_host_(host), | 81 renderer_ppapi_host_(host), |
84 handler_(NULL) { | 82 handler_(NULL), |
83 weak_factory_(this) { | |
85 } | 84 } |
86 | 85 |
87 PepperFileChooserHost::~PepperFileChooserHost() { | 86 PepperFileChooserHost::~PepperFileChooserHost() { |
88 } | 87 } |
89 | 88 |
90 int32_t PepperFileChooserHost::OnResourceMessageReceived( | 89 int32_t PepperFileChooserHost::OnResourceMessageReceived( |
91 const IPC::Message& msg, | 90 const IPC::Message& msg, |
92 ppapi::host::HostMessageContext* context) { | 91 ppapi::host::HostMessageContext* context) { |
93 IPC_BEGIN_MESSAGE_MAP(PepperFileChooserHost, msg) | 92 IPC_BEGIN_MESSAGE_MAP(PepperFileChooserHost, msg) |
94 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileChooser_Show, OnShow) | 93 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileChooser_Show, OnShow) |
95 IPC_END_MESSAGE_MAP() | 94 IPC_END_MESSAGE_MAP() |
96 return PP_ERROR_FAILED; | 95 return PP_ERROR_FAILED; |
97 } | 96 } |
98 | 97 |
99 void PepperFileChooserHost::StoreChosenFiles( | 98 void PepperFileChooserHost::StoreChosenFiles( |
100 const std::vector<ChosenFileInfo>& files) { | 99 const std::vector<ChosenFileInfo>& files) { |
101 std::vector<ppapi::PPB_FileRef_CreateInfo> chosen_files; | 100 num_pending_file_resources_ = files.size(); |
102 for (size_t i = 0; i < files.size(); i++) { | 101 for (size_t i = 0; i < files.size(); i++) { |
103 #if defined(OS_WIN) | 102 #if defined(OS_WIN) |
104 base::FilePath file_path(UTF8ToWide(files[i].path)); | 103 base::FilePath file_path(UTF8ToWide(files[i].path)); |
105 #else | 104 #else |
106 base::FilePath file_path(files[i].path); | 105 base::FilePath file_path(files[i].path); |
107 #endif | 106 #endif |
108 | 107 IPC::Message create_msg = |
109 PPB_FileRef_Impl* ref = PPB_FileRef_Impl::CreateExternal( | 108 PpapiHostMsg_FileRef_CreateExternal(file_path); |
dmichael (off chromium)
2013/08/07 22:19:13
Is there any slicing problem with doing this? It s
teravest
2013/08/08 00:50:06
What do you mean? I don't understand.
dmichael (off chromium)
2013/08/08 01:58:41
"Slicing" is when you assign an object to a type t
| |
110 pp_instance(), file_path, files[i].display_name); | 109 RendererPpapiHost::GetForPPInstance(pp_instance())-> |
111 ppapi::PPB_FileRef_CreateInfo create_info; | 110 CreateBrowserResourceHost( |
112 ppapi::proxy::PPB_FileRef_Proxy::SerializeFileRef(ref->GetReference(), | 111 pp_instance(), |
113 &create_info); | 112 create_msg, |
114 chosen_files.push_back(create_info); | 113 base::Bind(&PepperFileChooserHost::DidCreateResourceHost, |
114 weak_factory_.GetWeakPtr(), | |
115 file_path, | |
116 files[i].display_name)); | |
115 } | 117 } |
116 | 118 |
117 reply_context_.params.set_result( | 119 if (files.size() == 0) { |
118 (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL); | 120 std::vector<ppapi::FileRef_CreateInfo> chosen_files; |
119 host()->SendReply(reply_context_, | 121 reply_context_.params.set_result(PP_ERROR_USERCANCEL); |
120 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); | 122 host()->SendReply(reply_context_, |
121 | 123 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); |
122 reply_context_ = ppapi::host::ReplyMessageContext(); | 124 reply_context_ = ppapi::host::ReplyMessageContext(); |
123 handler_ = NULL; // Handler deletes itself. | 125 handler_ = NULL; // Handler deletes itself. |
126 } | |
124 } | 127 } |
125 | 128 |
126 int32_t PepperFileChooserHost::OnShow( | 129 int32_t PepperFileChooserHost::OnShow( |
127 ppapi::host::HostMessageContext* context, | 130 ppapi::host::HostMessageContext* context, |
128 bool save_as, | 131 bool save_as, |
129 bool open_multiple, | 132 bool open_multiple, |
130 const std::string& suggested_file_name, | 133 const std::string& suggested_file_name, |
131 const std::vector<std::string>& accept_mime_types) { | 134 const std::vector<std::string>& accept_mime_types) { |
132 if (handler_) | 135 if (handler_) |
133 return PP_ERROR_INPROGRESS; // Already pending. | 136 return PP_ERROR_INPROGRESS; // Already pending. |
(...skipping 26 matching lines...) Expand all Loading... | |
160 if (!render_view || !render_view->runFileChooser(params, handler_)) { | 163 if (!render_view || !render_view->runFileChooser(params, handler_)) { |
161 delete handler_; | 164 delete handler_; |
162 handler_ = NULL; | 165 handler_ = NULL; |
163 return PP_ERROR_NOACCESS; | 166 return PP_ERROR_NOACCESS; |
164 } | 167 } |
165 | 168 |
166 reply_context_ = context->MakeReplyMessageContext(); | 169 reply_context_ = context->MakeReplyMessageContext(); |
167 return PP_OK_COMPLETIONPENDING; | 170 return PP_OK_COMPLETIONPENDING; |
168 } | 171 } |
169 | 172 |
173 void PepperFileChooserHost::DidCreateResourceHost( | |
174 const base::FilePath& file_path, | |
175 const std::string& display_name, | |
176 int32_t id) { | |
177 num_pending_file_resources_--; | |
178 ppapi::FileRef_CreateInfo info; | |
179 info.file_system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
180 info.internal_path = std::string(); | |
181 info.display_name = display_name; | |
182 info.pending_host_resource_id = id; | |
dmichael (off chromium)
2013/08/07 22:19:13
Suggestion: What do you think of adding a couple o
teravest
2013/08/08 00:50:06
Done. (I had a function that was pretty close alre
dmichael (off chromium)
2013/08/08 21:24:03
Any reason you aren't using it here?
| |
183 chosen_files_.push_back(info); | |
184 if (num_pending_file_resources_ == 0) { | |
185 reply_context_.params.set_result(PP_OK); | |
186 host()->SendReply(reply_context_, | |
187 PpapiPluginMsg_FileChooser_ShowReply(chosen_files_)); | |
188 reply_context_ = ppapi::host::ReplyMessageContext(); | |
189 handler_ = NULL; // Handler deletes itself. | |
190 } | |
191 } | |
192 | |
170 } // namespace content | 193 } // namespace content |
171 | 194 |
OLD | NEW |