diff options
-rw-r--r-- | chrome/browser/file_select_helper.cc | 33 | ||||
-rw-r--r-- | chrome/browser/ui/views/shell_dialogs_win.cc | 4 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host.cc | 7 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host.h | 7 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 9 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_chooser_proxy.cc | 59 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_chooser_proxy.h | 10 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.h | 2 | ||||
-rw-r--r-- | ppapi/thunk/ppb_file_chooser_api.h | 6 | ||||
-rw-r--r-- | ppapi/thunk/ppb_file_chooser_thunk.cc | 31 | ||||
-rw-r--r-- | ppapi/thunk/resource_creation_api.h | 2 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_file_chooser_impl.cc | 24 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_file_chooser_impl.h | 9 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.h | 2 |
19 files changed, 177 insertions, 40 deletions
diff --git a/chrome/browser/file_select_helper.cc b/chrome/browser/file_select_helper.cc index f656e10..4de82d4 100644 --- a/chrome/browser/file_select_helper.cc +++ b/chrome/browser/file_select_helper.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/file_util.h" +#include "base/platform_file.h" #include "base/string_split.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -31,7 +32,28 @@ namespace { // There is only one file-selection happening at any given time, // so we allocate an enumeration ID for that purpose. All IDs from // the renderer must start at 0 and increase. -static const int kFileSelectEnumerationId = -1; +const int kFileSelectEnumerationId = -1; + +void NotifyRenderViewHost(RenderViewHost* render_view_host, + const std::vector<FilePath>& files, + SelectFileDialog::Type dialog_type) { + const int kReadFilePermissions = + base::PLATFORM_FILE_OPEN | + base::PLATFORM_FILE_READ | + base::PLATFORM_FILE_EXCLUSIVE_READ | + base::PLATFORM_FILE_ASYNC; + + const int kWriteFilePermissions = + base::PLATFORM_FILE_OPEN_ALWAYS | + base::PLATFORM_FILE_WRITE | + base::PLATFORM_FILE_WRITE_ATTRIBUTES | + base::PLATFORM_FILE_ASYNC; + + int permissions = kReadFilePermissions; + if (dialog_type == SelectFileDialog::SELECT_SAVEAS_FILE) + permissions = kWriteFilePermissions; + render_view_host->FilesSelectedInChooser(files, permissions); +} } struct FileSelectHelper::ActiveDirectoryEnumeration { @@ -83,7 +105,7 @@ void FileSelectHelper::FileSelected(const FilePath& path, std::vector<FilePath> files; files.push_back(path); - render_view_host_->FilesSelectedInChooser(files); + NotifyRenderViewHost(render_view_host_, files, dialog_type_); // No members should be accessed from here on. RunFileChooserEnd(); @@ -96,7 +118,7 @@ void FileSelectHelper::MultiFilesSelected(const std::vector<FilePath>& files, if (!render_view_host_) return; - render_view_host_->FilesSelectedInChooser(files); + NotifyRenderViewHost(render_view_host_, files, dialog_type_); // No members should be accessed from here on. RunFileChooserEnd(); @@ -108,7 +130,8 @@ void FileSelectHelper::FileSelectionCanceled(void* params) { // If the user cancels choosing a file to upload we pass back an // empty vector. - render_view_host_->FilesSelectedInChooser(std::vector<FilePath>()); + NotifyRenderViewHost( + render_view_host_, std::vector<FilePath>(), dialog_type_); // No members should be accessed from here on. RunFileChooserEnd(); @@ -160,7 +183,7 @@ void FileSelectHelper::OnListDone(int id, int error) { return; } if (id == kFileSelectEnumerationId) - entry->rvh_->FilesSelectedInChooser(entry->results_); + NotifyRenderViewHost(entry->rvh_, entry->results_, dialog_type_); else entry->rvh_->DirectoryEnumerationFinished(id, entry->results_); diff --git a/chrome/browser/ui/views/shell_dialogs_win.cc b/chrome/browser/ui/views/shell_dialogs_win.cc index 0ce04a0..3f09577 100644 --- a/chrome/browser/ui/views/shell_dialogs_win.cc +++ b/chrome/browser/ui/views/shell_dialogs_win.cc @@ -242,6 +242,10 @@ bool SaveFileAsWithFilter(HWND owner, // specify a filter when saving. DCHECK(!filter.empty()); std::wstring file_part = FilePath(suggested_name).BaseName().value(); + // If the suggested_name is a root directory, file_part will be '\', and the + // call to GetSaveFileName below will fail. + if (file_part.size() == 1 && file_part[0] == L'\\') + file_part.clear(); // The size of the in/out buffer in number of characters we pass to win32 // GetSaveFileName. From MSDN "The buffer must be large enough to store the diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index 5298315..81709ef 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -556,12 +556,13 @@ void RenderViewHost::SetInitialFocus(bool reverse) { } void RenderViewHost::FilesSelectedInChooser( - const std::vector<FilePath>& files) { + const std::vector<FilePath>& files, + int permissions) { // Grant the security access requested to the given files. for (std::vector<FilePath>::const_iterator file = files.begin(); file != files.end(); ++file) { - ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( - process()->id(), *file); + ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( + process()->id(), *file, permissions); } Send(new ViewMsg_RunFileChooserResponse(routing_id(), files)); } diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h index d29b8e4..fb55ee06 100644 --- a/content/browser/renderer_host/render_view_host.h +++ b/content/browser/renderer_host/render_view_host.h @@ -307,8 +307,11 @@ class CONTENT_EXPORT RenderViewHost : public RenderWidgetHost { const FilePath& local_directory_name); // Notifies the Listener that one or more files have been chosen by the user - // from an Open File dialog for the form. - void FilesSelectedInChooser(const std::vector<FilePath>& files); + // from a file chooser dialog for the form. |permissions| are flags from the + // base::PlatformFileFlags enum which specify which file permissions should + // be granted to the renderer. + void FilesSelectedInChooser(const std::vector<FilePath>& files, + int permissions); // Notifies the listener that a directory enumeration is complete. void DirectoryEnumerationFinished(int request_id, diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index fc2d729b..581e23d 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -1558,6 +1558,8 @@ bool RenderViewImpl::runFileChooser( ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder; else if (params.multiSelect) ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple; + else if (params.saveAs) + ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Save; else ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open; ipc_params.title = params.title; diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index a650577..3b61d1a 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -570,10 +570,13 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBCursorControl_CanLockCursor, IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFileChooser_Create, PP_Instance /* instance */, int /* mode */, - ppapi::proxy::SerializedVar /* accept_mime_types */, + std::string /* accept_mime_types */, ppapi::HostResource /* result */) -IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBFileChooser_Show, - ppapi::HostResource /* file_chooser */) +IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFileChooser_Show, + ppapi::HostResource /* file_chooser */, + bool /* save_as */, + std::string /* suggested_file_name */, + bool /* require_user_gesture */) // PPB_FileRef. diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index d6850a5..d128439 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -37,6 +37,10 @@ class FileChooser : public Resource, // PPB_FileChooser_API implementation. virtual int32_t Show(const PP_CompletionCallback& callback) OVERRIDE; virtual PP_Resource GetNextChosenFile() OVERRIDE; + virtual int32_t ShowWithoutUserGesture( + bool save_as, + const char* suggested_file_name, + const PP_CompletionCallback& callback) OVERRIDE; // Handles the choose complete notification from the host. void ChooseComplete( @@ -44,6 +48,11 @@ class FileChooser : public Resource, const std::vector<PPB_FileRef_CreateInfo>& chosen_files); private: + int32_t Show(bool require_user_gesture, + bool save_as, + const char* suggested_file_name, + const PP_CompletionCallback& callback); + PP_CompletionCallback current_show_callback_; // All files returned by the current show callback that haven't yet been @@ -84,6 +93,20 @@ PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { } int32_t FileChooser::Show(const PP_CompletionCallback& callback) { + return Show(true, false, NULL, callback); +} + +int32_t FileChooser::ShowWithoutUserGesture( + bool save_as, + const char* suggested_file_name, + const PP_CompletionCallback& callback) { + return Show(false, save_as, suggested_file_name, callback); +} + +int32_t FileChooser::Show(bool require_user_gesture, + bool save_as, + const char* suggested_file_name, + const PP_CompletionCallback& callback) { if (!callback.func) return PP_ERROR_BLOCKS_MAIN_THREAD; @@ -93,7 +116,11 @@ int32_t FileChooser::Show(const PP_CompletionCallback& callback) { current_show_callback_ = callback; PluginDispatcher::GetForResource(this)->Send( new PpapiHostMsg_PPBFileChooser_Show( - INTERFACE_ID_PPB_FILE_CHOOSER, host_resource())); + INTERFACE_ID_PPB_FILE_CHOOSER, + host_resource(), + save_as, + suggested_file_name, + require_user_gesture)); return PP_OK_COMPLETIONPENDING; } @@ -135,7 +162,7 @@ PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() { PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types) { + const char* accept_mime_types) { Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); if (!dispatcher) return 0; @@ -143,7 +170,8 @@ PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( HostResource result; dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Create( INTERFACE_ID_PPB_FILE_CHOOSER, instance, - mode, SerializedVarSendInput(dispatcher, accept_mime_types), + mode, + accept_mime_types, &result)); if (result.is_null()) @@ -169,22 +197,35 @@ bool PPB_FileChooser_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_FileChooser_Proxy::OnMsgCreate( PP_Instance instance, int mode, - SerializedVarReceiveInput accept_mime_types, + std::string accept_mime_types, HostResource* result) { thunk::EnterResourceCreation enter(instance); if (enter.succeeded()) { result->SetHostResource(instance, enter.functions()->CreateFileChooser( - instance, static_cast<PP_FileChooserMode_Dev>(mode), - accept_mime_types.Get(dispatcher()))); + instance, + static_cast<PP_FileChooserMode_Dev>(mode), + accept_mime_types.c_str())); } } -void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) { +void PPB_FileChooser_Proxy::OnMsgShow( + const HostResource& chooser, + bool save_as, + std::string suggested_file_name, + bool require_user_gesture) { EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter( chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback, chooser); - if (enter.succeeded()) - enter.SetResult(enter.object()->Show(enter.callback())); + if (enter.succeeded()) { + if (require_user_gesture) { + enter.SetResult(enter.object()->Show(enter.callback())); + } else { + enter.SetResult(enter.object()->ShowWithoutUserGesture( + save_as, + suggested_file_name.c_str(), + enter.callback())); + } + } } void PPB_FileChooser_Proxy::OnMsgChooseComplete( diff --git a/ppapi/proxy/ppb_file_chooser_proxy.h b/ppapi/proxy/ppb_file_chooser_proxy.h index f1dcd95..c7e2f48 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.h +++ b/ppapi/proxy/ppb_file_chooser_proxy.h @@ -20,6 +20,7 @@ struct PPB_FileChooser_Dev; namespace ppapi { class HostResource; +struct PPB_FileChooserTrusted; struct PPB_FileRef_CreateInfo; namespace proxy { @@ -34,7 +35,7 @@ class PPB_FileChooser_Proxy : public InterfaceProxy { static PP_Resource CreateProxyResource( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types); + const char* accept_mime_types); // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -45,9 +46,12 @@ class PPB_FileChooser_Proxy : public InterfaceProxy { // Plugin -> host message handlers. void OnMsgCreate(PP_Instance instance, int mode, - SerializedVarReceiveInput accept_mime_types, + std::string accept_mime_types, ppapi::HostResource* result); - void OnMsgShow(const ppapi::HostResource& chooser); + void OnMsgShow(const ppapi::HostResource& chooser, + bool save_as, + std::string suggested_file_name, + bool require_user_gesture); // Host -> plugin message handlers. void OnMsgChooseComplete( diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index a0b4b6a..b7d6c0c 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -120,7 +120,7 @@ PP_Resource ResourceCreationProxy::CreateDirectoryReader( PP_Resource ResourceCreationProxy::CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types) { + const char* accept_mime_types) { return PPB_FileChooser_Proxy::CreateProxyResource(instance, mode, accept_mime_types); } diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 1fdac1c..74812f4 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -61,7 +61,7 @@ class ResourceCreationProxy : public InterfaceProxy, virtual PP_Resource CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types) OVERRIDE; + const char* accept_mime_types) OVERRIDE; virtual PP_Resource CreateFileIO(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateFileRef(PP_Resource file_system, const char* path) OVERRIDE; diff --git a/ppapi/thunk/ppb_file_chooser_api.h b/ppapi/thunk/ppb_file_chooser_api.h index fba94c7..494f7bd 100644 --- a/ppapi/thunk/ppb_file_chooser_api.h +++ b/ppapi/thunk/ppb_file_chooser_api.h @@ -16,6 +16,12 @@ class PPB_FileChooser_API { virtual int32_t Show(const PP_CompletionCallback& callback) = 0; virtual PP_Resource GetNextChosenFile() = 0; + + // Trusted API. + virtual int32_t ShowWithoutUserGesture( + bool save_as, + const char* suggested_file_name, + const PP_CompletionCallback& callback) = 0; }; } // namespace thunk diff --git a/ppapi/thunk/ppb_file_chooser_thunk.cc b/ppapi/thunk/ppb_file_chooser_thunk.cc index 774ef03..e5cbc5d 100644 --- a/ppapi/thunk/ppb_file_chooser_thunk.cc +++ b/ppapi/thunk/ppb_file_chooser_thunk.cc @@ -5,6 +5,8 @@ #include "ppapi/c/dev/ppb_file_chooser_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/c/trusted/ppb_file_chooser_trusted.h" +#include "ppapi/shared_impl/var.h" #include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" @@ -22,8 +24,10 @@ PP_Resource Create(PP_Instance instance, EnterFunction<ResourceCreationAPI> enter(instance, true); if (enter.failed()) return 0; - return enter.functions()->CreateFileChooser(instance, mode, - accept_mime_types); + scoped_refptr<StringVar> string_var = + StringVar::FromPPVar(accept_mime_types); + std::string str = string_var ? string_var->value() : std::string(); + return enter.functions()->CreateFileChooser(instance, mode, str.c_str()); } PP_Bool IsFileChooser(PP_Resource resource) { @@ -46,6 +50,21 @@ PP_Resource GetNextChosenFile(PP_Resource chooser) { return enter.object()->GetNextChosenFile(); } +int32_t ShowWithoutUserGesture(PP_Resource chooser, + PP_Bool save_as, + PP_Var suggested_file_name, + PP_CompletionCallback callback) { + EnterResource<PPB_FileChooser_API> enter(chooser, true); + if (enter.failed()) + return MayForceCallback(callback, PP_ERROR_BADRESOURCE); + scoped_refptr<StringVar> string_var = + StringVar::FromPPVar(suggested_file_name); + std::string str = string_var ? string_var->value() : std::string(); + int32_t result = enter.object()->ShowWithoutUserGesture( + save_as == PP_TRUE, str.c_str(), callback); + return MayForceCallback(callback, result); +} + const PPB_FileChooser_Dev g_ppb_file_chooser_thunk = { &Create, &IsFileChooser, @@ -53,11 +72,19 @@ const PPB_FileChooser_Dev g_ppb_file_chooser_thunk = { &GetNextChosenFile }; +const PPB_FileChooserTrusted g_ppb_file_chooser_trusted_thunk = { + &ShowWithoutUserGesture +}; + } // namespace const PPB_FileChooser_Dev* GetPPB_FileChooser_Dev_Thunk() { return &g_ppb_file_chooser_thunk; } +const PPB_FileChooserTrusted* GetPPB_FileChooser_Trusted_Thunk() { + return &g_ppb_file_chooser_trusted_thunk; +} + } // namespace thunk } // namespace ppapi diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index 256c9e8..59cc1c2 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -62,7 +62,7 @@ class ResourceCreationAPI { virtual PP_Resource CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types) = 0; + const char* accept_mime_types) = 0; virtual PP_Resource CreateFileIO(PP_Instance instance) = 0; virtual PP_Resource CreateFileRef(PP_Resource file_system, const char* path) = 0; diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index fe90eff..bac3a63 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -31,6 +31,7 @@ struct PPB_AudioTrusted; struct PPB_BrokerTrusted; struct PPB_BufferTrusted; struct PPB_Context3DTrusted_Dev; +struct PPB_FileChooserTrusted; struct PPB_FileIOTrusted; struct PPB_Flash_Menu; struct PPB_Flash_NetConnector; @@ -56,6 +57,8 @@ PPAPI_THUNK_EXPORT const PPB_BrokerTrusted* GetPPB_Broker_Thunk(); PPAPI_THUNK_EXPORT const PPB_BufferTrusted* GetPPB_BufferTrusted_Thunk(); PPAPI_THUNK_EXPORT const PPB_Context3DTrusted_Dev* GetPPB_Context3DTrusted_Thunk(); +PPAPI_THUNK_EXPORT const PPB_FileChooserTrusted* + GetPPB_FileChooser_Trusted_Thunk(); PPAPI_THUNK_EXPORT const PPB_FileIOTrusted* GetPPB_FileIOTrusted_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_NetConnector* diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index b492c20..cb5f134 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -77,6 +77,7 @@ #include "ppapi/c/trusted/ppb_audio_trusted.h" #include "ppapi/c/trusted/ppb_broker_trusted.h" #include "ppapi/c/trusted/ppb_buffer_trusted.h" +#include "ppapi/c/trusted/ppb_file_chooser_trusted.h" #include "ppapi/c/trusted/ppb_file_io_trusted.h" #include "ppapi/c/trusted/ppb_graphics_3d_trusted.h" #include "ppapi/c/trusted/ppb_image_data_trusted.h" @@ -256,6 +257,8 @@ const void* GetInterface(const char* name) { return &core_interface; if (strcmp(name, PPB_FILEIOTRUSTED_INTERFACE) == 0) return ::ppapi::thunk::GetPPB_FileIOTrusted_Thunk(); + if (strcmp(name, PPB_FILECHOOSER_TRUSTED_INTERFACE) == 0) + return ::ppapi::thunk::GetPPB_FileChooser_Trusted_Thunk(); if (strcmp(name, PPB_FLASH_INTERFACE) == 0) return PPB_Flash_Impl::GetInterface(); if (strcmp(name, PPB_FLASH_CLIPBOARD_INTERFACE) == 0) diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc index f7904da..179cf04 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc @@ -65,13 +65,12 @@ class FileChooserCompletionImpl : public WebFileChooserCompletion { PPB_FileChooser_Impl::PPB_FileChooser_Impl( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types) + const char* accept_mime_types) : Resource(instance), mode_(mode), next_chosen_file_index_(0) { - scoped_refptr<StringVar> accept = StringVar::FromPPVar(accept_mime_types); - if (accept) - accept_mime_types_ = accept->value(); + if (accept_mime_types) + accept_mime_types_ = std::string(accept_mime_types); } PPB_FileChooser_Impl::~PPB_FileChooser_Impl() { @@ -81,7 +80,7 @@ PPB_FileChooser_Impl::~PPB_FileChooser_Impl() { PP_Resource PPB_FileChooser_Impl::Create( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types) { + const char* accept_mime_types) { if (mode != PP_FILECHOOSERMODE_OPEN && mode != PP_FILECHOOSERMODE_OPENMULTIPLE) return 0; @@ -148,6 +147,13 @@ void PPB_FileChooser_Impl::RunCallback(int32_t result) { } int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { + return ShowWithoutUserGesture(false, NULL, callback); +} + +int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture( + bool save_as, + const char* suggested_file_name, + const PP_CompletionCallback& callback) { int32_t rv = ValidateCallback(callback); if (rv != PP_OK) return rv; @@ -156,7 +162,13 @@ int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE)); WebFileChooserParams params; - params.multiSelect = (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE); + if (save_as) { + params.saveAs = true; + if (suggested_file_name) + params.initialValue = WebString::fromUTF8(suggested_file_name); + } else { + params.multiSelect = (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE); + } params.acceptTypes = WebString::fromUTF8(accept_mime_types_); params.directory = false; diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.h b/webkit/plugins/ppapi/ppb_file_chooser_impl.h index b8205b8..9157208 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.h +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.h @@ -27,12 +27,12 @@ class PPB_FileChooser_Impl : public ::ppapi::Resource, public: PPB_FileChooser_Impl(PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types); + const char* accept_mime_types); virtual ~PPB_FileChooser_Impl(); static PP_Resource Create(PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types); + const char* accept_mime_types); // Resource overrides. virtual PPB_FileChooser_Impl* AsPPB_FileChooser_Impl(); @@ -58,6 +58,11 @@ class PPB_FileChooser_Impl : public ::ppapi::Resource, virtual int32_t Show(const PP_CompletionCallback& callback) OVERRIDE; virtual PP_Resource GetNextChosenFile() OVERRIDE; + virtual int32_t ShowWithoutUserGesture( + bool save_as, + const char* suggested_file_name, + const PP_CompletionCallback& callback) OVERRIDE; + private: PP_FileChooserMode_Dev mode_; std::string accept_mime_types_; diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 216dabb..2a02112 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -108,7 +108,7 @@ PP_Resource ResourceCreationImpl::CreateDirectoryReader( PP_Resource ResourceCreationImpl::CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types) { + const char* accept_mime_types) { return PPB_FileChooser_Impl::Create(instance, mode, accept_mime_types); } diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index 27b17c5..2f9deff 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -48,7 +48,7 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, virtual PP_Resource CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, - const PP_Var& accept_mime_types) OVERRIDE; + const char* accept_mime_types) OVERRIDE; virtual PP_Resource CreateFileIO(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateFileRef(PP_Resource file_system, const char* path) OVERRIDE; |