diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 19:52:47 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 19:52:47 +0000 |
commit | cdaf8d04617e815d8e8fb0fe1c707a23cc583904 (patch) | |
tree | b323d372b6e01fe6d13e37b8a50016386bd6142e /chrome/renderer/webplugin_delegate_pepper.cc | |
parent | 39c4e1a8b2343b3883a098a8e0d21fb8bd3204cf (diff) | |
download | chromium_src-cdaf8d04617e815d8e8fb0fe1c707a23cc583904.zip chromium_src-cdaf8d04617e815d8e8fb0fe1c707a23cc583904.tar.gz chromium_src-cdaf8d04617e815d8e8fb0fe1c707a23cc583904.tar.bz2 |
Extend the file browser/chooser to support more modes of operation, and plumb
it through to the pepper API. This pepper API just supports adding the filename
to the "upload files" whitelist and returning it to the plugin, but it does not
actually give any ability for a sandboxed plugin to read the file (this will
come in a separate changelist).
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/1094004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43123 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/webplugin_delegate_pepper.cc')
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc index 37b169d..9c4db6c 100644 --- a/chrome/renderer/webplugin_delegate_pepper.cc +++ b/chrome/renderer/webplugin_delegate_pepper.cc @@ -146,6 +146,30 @@ WebPluginDelegatePepper* WebPluginDelegatePepper::Create( instance.get()); } +void WebPluginDelegatePepper::didChooseFile( + const WebKit::WebVector<WebKit::WebString>& file_names) { + if (file_names.isEmpty()) { + current_choose_file_callback_(NULL, 0, current_choose_file_user_data_); + } else { + // Construct a bunch of 8-bit strings for the callback. + std::vector<std::string> file_strings; + file_strings.resize(file_names.size()); + for (size_t i = 0; i < file_names.size(); i++) + file_strings[i] = file_names[0].utf8(); + + // Construct an array of pointers to each of the strings. + std::vector<const char*> pointers_to_strings; + pointers_to_strings.resize(file_strings.size()); + for (size_t i = 0; i < file_strings.size(); i++) + pointers_to_strings[i] = file_strings[i].c_str(); + + current_choose_file_callback_( + &pointers_to_strings[0], + static_cast<int>(pointers_to_strings.size()), + current_choose_file_user_data_); + } +} + bool WebPluginDelegatePepper::Initialize( const GURL& url, const std::vector<std::string>& arg_names, @@ -368,6 +392,38 @@ void WebPluginDelegatePepper::Zoom(int factor) { extensions->zoom(instance()->npp(), factor); } +bool WebPluginDelegatePepper::ChooseFile(const char* mime_types, + int mode, + NPChooseFileCallback callback, + void* user_data) { + if (!render_view_ || !callback) + return false; + + if (current_choose_file_callback_) + return false; // Reentrant call to browse, only one can be outstanding + // per plugin. + + // TODO(brettw) do something with the mime types! + current_choose_file_callback_ = callback; + current_choose_file_user_data_ = user_data; + + ViewHostMsg_RunFileChooser_Params ipc_params; + switch (mode) { + case NPChooseFile_Open: + ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open; + break; + case NPChooseFile_OpenMultiple: + ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple; + break; + case NPChooseFile_Save: + ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Save; + break; + default: + return false; + } + return render_view_->ScheduleFileChooser(ipc_params, this); +} + NPError WebPluginDelegatePepper::Device2DQueryCapability(int32 capability, int32* value) { return NPERR_GENERIC_ERROR; @@ -1045,7 +1101,9 @@ WebPluginDelegatePepper::WebPluginDelegatePepper( command_buffer_(NULL), #endif find_identifier_(-1), - method_factory3d_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { + method_factory3d_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + current_choose_file_callback_(NULL), + current_choose_file_user_data_(NULL) { // For now we keep a window struct, although it isn't used. memset(&window_, 0, sizeof(window_)); // All Pepper plugins are windowless and transparent. |