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

Unified Diff: content/renderer/pepper/pepper_file_chooser_host.cc

Issue 21966004: Pepper: Move FileRef to the "new" resource proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CreateInfo/DetailedInfo rename Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/pepper/pepper_file_chooser_host.cc
diff --git a/content/renderer/pepper/pepper_file_chooser_host.cc b/content/renderer/pepper/pepper_file_chooser_host.cc
index 1229d17f610af7a1f69a3ff1e061e54c15e1cf7a..c825b38a03ae94bf5f2523a753de2609a4df4761 100644
--- a/content/renderer/pepper/pepper_file_chooser_host.cc
+++ b/content/renderer/pepper/pepper_file_chooser_host.cc
@@ -7,13 +7,11 @@
#include "base/files/file_path.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/renderer/renderer_ppapi_host.h"
-#include "content/renderer/pepper/ppb_file_ref_impl.h"
#include "content/renderer/render_view_impl.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/host/dispatch_host_message.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/proxy/ppapi_messages.h"
-#include "ppapi/proxy/ppb_file_ref_proxy.h"
#include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebVector.h"
@@ -81,7 +79,8 @@ PepperFileChooserHost::PepperFileChooserHost(
PP_Resource resource)
: ResourceHost(host->GetPpapiHost(), instance, resource),
renderer_ppapi_host_(host),
- handler_(NULL) {
+ handler_(NULL),
+ weak_factory_(this) {
yzshen1 2013/08/08 23:16:21 please init num_pending_file_resources_.
teravest 2013/08/09 02:00:08 Done.
}
PepperFileChooserHost::~PepperFileChooserHost() {
@@ -98,29 +97,30 @@ int32_t PepperFileChooserHost::OnResourceMessageReceived(
void PepperFileChooserHost::StoreChosenFiles(
const std::vector<ChosenFileInfo>& files) {
- std::vector<ppapi::PPB_FileRef_CreateInfo> chosen_files;
+ num_pending_file_resources_ = files.size();
for (size_t i = 0; i < files.size(); i++) {
#if defined(OS_WIN)
base::FilePath file_path(UTF8ToWide(files[i].path));
#else
base::FilePath file_path(files[i].path);
#endif
-
- PPB_FileRef_Impl* ref = PPB_FileRef_Impl::CreateExternal(
- pp_instance(), file_path, files[i].display_name);
- ppapi::PPB_FileRef_CreateInfo create_info;
- ppapi::proxy::PPB_FileRef_Proxy::SerializeFileRef(ref->GetReference(),
- &create_info);
- chosen_files.push_back(create_info);
+ renderer_ppapi_host_->CreateBrowserResourceHost(
+ pp_instance(),
+ PpapiHostMsg_FileRef_CreateExternal(file_path),
+ base::Bind(&PepperFileChooserHost::DidCreateResourceHost,
+ weak_factory_.GetWeakPtr(),
+ file_path,
+ files[i].display_name));
}
- reply_context_.params.set_result(
- (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL);
- host()->SendReply(reply_context_,
- PpapiPluginMsg_FileChooser_ShowReply(chosen_files));
-
- reply_context_ = ppapi::host::ReplyMessageContext();
- handler_ = NULL; // Handler deletes itself.
+ if (files.size() == 0) {
yzshen1 2013/08/08 23:16:21 - Please use files.empty(). - Does it make sense t
teravest 2013/08/09 02:00:08 Done. There are a few differences in the similar c
+ std::vector<ppapi::FileRefCreateInfo> chosen_files;
+ reply_context_.params.set_result(PP_ERROR_USERCANCEL);
+ host()->SendReply(reply_context_,
+ PpapiPluginMsg_FileChooser_ShowReply(chosen_files));
+ reply_context_ = ppapi::host::ReplyMessageContext();
+ handler_ = NULL; // Handler deletes itself.
+ }
}
int32_t PepperFileChooserHost::OnShow(
@@ -167,5 +167,25 @@ int32_t PepperFileChooserHost::OnShow(
return PP_OK_COMPLETIONPENDING;
}
+void PepperFileChooserHost::DidCreateResourceHost(
+ const base::FilePath& file_path,
+ const std::string& display_name,
+ int32_t id) {
+ num_pending_file_resources_--;
+ ppapi::FileRefCreateInfo info;
+ info.file_system_type = PP_FILESYSTEMTYPE_EXTERNAL;
+ info.internal_path = std::string();
+ info.display_name = display_name;
+ info.pending_host_resource_id = id;
+ chosen_files_.push_back(info);
+ if (num_pending_file_resources_ == 0) {
+ reply_context_.params.set_result(PP_OK);
+ host()->SendReply(reply_context_,
+ PpapiPluginMsg_FileChooser_ShowReply(chosen_files_));
+ reply_context_ = ppapi::host::ReplyMessageContext();
+ handler_ = NULL; // Handler deletes itself.
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698