summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins/pepper_file_chooser.cc
diff options
context:
space:
mode:
authorIain Merrick <husky@google.com>2010-10-19 14:37:37 +0100
committerIain Merrick <husky@google.com>2010-10-19 14:37:37 +0100
commit3345a6884c488ff3a535c2c9acdd33d74b37e311 (patch)
tree7784b988ef1698cb6967ea1bdf07616237716c6c /webkit/glue/plugins/pepper_file_chooser.cc
parentefc8475837ec58186051f23bb03542620424f6ce (diff)
downloadexternal_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.zip
external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.tar.gz
external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.tar.bz2
Merge Chromium at 7.0.540.0 : Initial merge by git
Not including third_party/icu as it contains huge data files that break Gerrit, and aren't actually used. Change-Id: I428a386e70f3b58cacd28677b8cfda282e891e15
Diffstat (limited to 'webkit/glue/plugins/pepper_file_chooser.cc')
-rw-r--r--webkit/glue/plugins/pepper_file_chooser.cc85
1 files changed, 76 insertions, 9 deletions
diff --git a/webkit/glue/plugins/pepper_file_chooser.cc b/webkit/glue/plugins/pepper_file_chooser.cc
index 5e45600..138efd7 100644
--- a/webkit/glue/plugins/pepper_file_chooser.cc
+++ b/webkit/glue/plugins/pepper_file_chooser.cc
@@ -4,19 +4,35 @@
#include "webkit/glue/plugins/pepper_file_chooser.h"
+#include <string>
+#include <vector>
+
#include "base/logging.h"
#include "third_party/ppapi/c/pp_completion_callback.h"
#include "third_party/ppapi/c/pp_errors.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
#include "webkit/glue/plugins/pepper_file_ref.h"
+#include "webkit/glue/plugins/pepper_plugin_delegate.h"
#include "webkit/glue/plugins/pepper_plugin_instance.h"
#include "webkit/glue/plugins/pepper_resource_tracker.h"
+#include "webkit/glue/webkit_glue.h"
+
+using WebKit::WebCString;
+using WebKit::WebFileChooserCompletion;
+using WebKit::WebFileChooserParams;
+using WebKit::WebString;
+using WebKit::WebVector;
namespace pepper {
namespace {
PP_Resource Create(PP_Instance instance_id,
- const PP_FileChooserOptions* options) {
+ const PP_FileChooserOptions_Dev* options) {
PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
if (!instance)
return 0;
@@ -51,38 +67,89 @@ PP_Resource GetNextChosenFile(PP_Resource chooser_id) {
return file_ref->GetReference();
}
-const PPB_FileChooser ppb_filechooser = {
+const PPB_FileChooser_Dev ppb_filechooser = {
&Create,
&IsFileChooser,
&Show,
&GetNextChosenFile
};
+class FileChooserCompletionImpl : public WebFileChooserCompletion {
+ public:
+ FileChooserCompletionImpl(pepper::FileChooser* file_chooser)
+ : file_chooser_(file_chooser) {
+ DCHECK(file_chooser_);
+ }
+
+ virtual ~FileChooserCompletionImpl() {}
+
+ virtual void didChooseFile(const WebVector<WebString>& file_names) {
+ std::vector<std::string> files;
+ for (size_t i = 0; i < file_names.size(); i++)
+ files.push_back(file_names[i].utf8().data());
+
+ file_chooser_->StoreChosenFiles(files);
+ }
+
+ private:
+ FileChooser* file_chooser_;
+};
+
} // namespace
FileChooser::FileChooser(PluginInstance* instance,
- const PP_FileChooserOptions* options)
+ const PP_FileChooserOptions_Dev* options)
: Resource(instance->module()),
+ delegate_(instance->delegate()),
mode_(options->mode),
- accept_mime_types_(options->accept_mime_types) {
+ accept_mime_types_(options->accept_mime_types),
+ completion_callback_() {
}
FileChooser::~FileChooser() {
}
// static
-const PPB_FileChooser* FileChooser::GetInterface() {
+const PPB_FileChooser_Dev* FileChooser::GetInterface() {
return &ppb_filechooser;
}
+void FileChooser::StoreChosenFiles(const std::vector<std::string>& files) {
+ next_chosen_file_index_ = 0;
+ std::vector<std::string>::const_iterator end_it = files.end();
+ for (std::vector<std::string>::const_iterator it = files.begin();
+ it != end_it; it++)
+ chosen_files_.push_back(
+ new FileRef(module(), PP_FILESYSTEMTYPE_LOCALPERSISTENT, *it, ""));
+
+ if (!completion_callback_.func)
+ return;
+
+ PP_CompletionCallback callback = {0};
+ std::swap(callback, completion_callback_);
+ PP_RunCompletionCallback(&callback, 0);
+}
+
int32_t FileChooser::Show(PP_CompletionCallback callback) {
- NOTIMPLEMENTED(); // TODO(darin): Implement me!
- return PP_ERROR_FAILED;
+ DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) ||
+ (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE));
+ DCHECK(!completion_callback_.func);
+ completion_callback_ = callback;
+
+ WebFileChooserParams params;
+ params.multiSelect = (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE);
+ params.acceptTypes = WebString::fromUTF8(accept_mime_types_);
+ params.directory = false;
+
+ return delegate_->RunFileChooser(
+ params, new FileChooserCompletionImpl(this));
}
scoped_refptr<FileRef> FileChooser::GetNextChosenFile() {
- NOTIMPLEMENTED(); // TODO(darin): Implement me!
- return NULL;
+ if (next_chosen_file_index_ >= chosen_files_.size())
+ return NULL;
+
+ return chosen_files_[next_chosen_file_index_++];
}
} // namespace pepper