diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-20 04:53:22 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-20 04:53:22 +0000 |
commit | bab65ef72eb97612599d97a35c6da6f460b0cacc (patch) | |
tree | c3a3d01bf47a3c7f8e0a7969e5f59ff509963484 | |
parent | 84a7f535761e3bceeac188cd8cd499e2f8016661 (diff) | |
download | chromium_src-bab65ef72eb97612599d97a35c6da6f460b0cacc.zip chromium_src-bab65ef72eb97612599d97a35c6da6f460b0cacc.tar.gz chromium_src-bab65ef72eb97612599d97a35c6da6f460b0cacc.tar.bz2 |
Cleanup in the file chooser API.
This revs the file chooser interface to no longer pass a separate options structure. This structure was weird because it only had two members, and didn't have ownership of the string which is potentially dangerous. The new interface is a bit easier to call.
I changed the string to take a Var, and the C++ layer now takes an Instance*
rather than an Instance& which is consistent with the other interfaces. I
updated the example.
TEST=manual
BUG=
Review URL: http://codereview.chromium.org/7660017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97558 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 243 insertions, 116 deletions
diff --git a/ppapi/c/dev/ppb_file_chooser_dev.h b/ppapi/c/dev/ppb_file_chooser_dev.h index 27080fe..9199309 100644 --- a/ppapi/c/dev/ppb_file_chooser_dev.h +++ b/ppapi/c/dev/ppb_file_chooser_dev.h @@ -13,58 +13,88 @@ struct PP_CompletionCallback; typedef enum { - PP_FILECHOOSERMODE_OPEN, - PP_FILECHOOSERMODE_OPENMULTIPLE + PP_FILECHOOSERMODE_OPEN = 0, + PP_FILECHOOSERMODE_OPENMULTIPLE = 1 // TODO(darin): Should there be a way to choose a directory? } PP_FileChooserMode_Dev; PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FileChooserMode_Dev, 4); -struct PP_FileChooserOptions_Dev { - PP_FileChooserMode_Dev mode; - - // A comma-separated list of MIME types such as audio/*,text/plain. The - // dialog may restrict selectable files to the specified MIME types. Null may - // be given to indicate that all types should be accepted. - // TODO(darin): What if the mime type is unknown to the system? The plugin - // may wish to describe the mime type and provide a matching file extension. - // It is more webby to use mime types here instead of file extensions. - const char* accept_mime_types; -}; - -#define PPB_FILECHOOSER_DEV_INTERFACE_0_4 "PPB_FileChooser(Dev);0.4" -#define PPB_FILECHOOSER_DEV_INTERFACE PPB_FILECHOOSER_DEV_INTERFACE_0_4 +#define PPB_FILECHOOSER_DEV_INTERFACE_0_5 "PPB_FileChooser(Dev);0.5" +#define PPB_FILECHOOSER_DEV_INTERFACE PPB_FILECHOOSER_DEV_INTERFACE_0_5 struct PPB_FileChooser_Dev { - // Creates a file chooser dialog with the specified options. The chooser is - // associated with a particular instance, so that it may be positioned on the - // screen relative to the tab containing the instance. Returns 0 if passed - // an invalid instance. - // - // A PPB_FileChooser_Dev instance can be used to select a single file - // (PP_FILECHOOSERMODE_OPEN) or multiple files - // (PP_FILECHOOSERMODE_OPENMULTIPLE). Unlike the HTML5 <input type="file"> - // tag, a PPB_FileChooser_Dev instance cannot be used to select a directory. - // In order to get the list of files in a directory, the - // PPB_DirectoryReader_Dev interface must be used. + /** + * This function creates a file chooser dialog resource. The chooser is + * associated with a particular instance, so that it may be positioned on the + * screen relative to the tab containing the instance. Returns 0 if passed + * an invalid instance. + * + * @param mode A PPB_FileChooser_Dev instance can be used to select a single + * file (PP_FILECHOOSERMODE_OPEN) or multiple files + * (PP_FILECHOOSERMODE_OPENMULTIPLE). Unlike the HTML5 <input type="file"> + * tag, a PPB_FileChooser_Dev instance cannot be used to select a directory. + * In order to get the list of files in a directory, the + * PPB_DirectoryReader_Dev interface must be used. + * + * @param accept_mime_types A comma-separated list of MIME types such as + * "audio/ *,text/plain" (note there should be no space between the '/' and + * the '*', but one is added to avoid confusing C++ comments). The dialog + * may restrict selectable files to the specified MIME types. An empty string + * or an undefined var may be given to indicate that all types should be + * accepted. + * + * TODO(darin): What if the mime type is unknown to the system? The plugin + * may wish to describe the mime type and provide a matching file extension. + * It is more webby to use mime types here instead of file extensions. + */ PP_Resource (*Create)(PP_Instance instance, - const struct PP_FileChooserOptions_Dev* options); + PP_FileChooserMode_Dev mode, + struct PP_Var accept_mime_types); - // Returns PP_TRUE if the given resource is a FileChooser. Returns PP_FALSE - // if the resource is invalid or some type other than a FileChooser. + /** + * IsFileChooser returns PP_TRUE if the given resource is a FileChooser. + * It returns PP_FALSE if the resource is invalid or some type other than a + * FileChooser. + */ PP_Bool (*IsFileChooser)(PP_Resource resource); - // Prompts the user to choose a file or files. The callback is called with - // PP_OK on successful completion with a file (or files) selected or - // PP_ERROR_USERCANCEL if the user selected no file. + /** + * This function displays a previously created file chooser resource as a + * dialog box, prompting the user to choose a file or files. The callback is + * called with PP_OK on successful completion with a file (or files) selected + * or PP_ERROR_USERCANCEL if the user selected no file. + * + * @return PP_OK_COMPLETIONPENDING if request to show the dialog was + * successful, another error code from pp_errors.h on failure. + */ int32_t (*Show)(PP_Resource chooser, struct PP_CompletionCallback callback); - // After a successful call to Show, this method may be used to query the - // chosen files. It should be called in a loop until it returns 0. - // Depending on the PP_ChooseFileMode requested when the FileChooser was - // created, the file refs will either be readable or writable. Their file - // system type will be PP_FileSystemType_External. If the user chose no - // files or cancelled the dialog, then this method will simply return 0 - // the first time it is called. + /** + * After a successful completion callback call from Show, this method may be + * used to query the chosen files. It should be called in a loop until it + * returns 0. Depending on the PP_ChooseFileMode_Dev requested when the + * FileChooser was created, the file refs will either be readable or + * writable. Their file system type will be PP_FileSystemType_External. If + * the user chose no files or cancelled the dialog, then this method will + * simply return 0 the first time it is called. + */ + PP_Resource (*GetNextChosenFile)(PP_Resource chooser); +}; + +// Deprecated 0.4 version ------------------------------------------------------ + +#define PPB_FILECHOOSER_DEV_INTERFACE_0_4 "PPB_FileChooser(Dev);0.4" + +struct PP_FileChooserOptions_0_4_Dev { + PP_FileChooserMode_Dev mode; + const char* accept_mime_types; +}; + +struct PPB_FileChooser_0_4_Dev { + PP_Resource (*Create)(PP_Instance instance, + const struct PP_FileChooserOptions_0_4_Dev* options); + PP_Bool (*IsFileChooser)(PP_Resource resource); + int32_t (*Show)(PP_Resource chooser, struct PP_CompletionCallback callback); PP_Resource (*GetNextChosenFile)(PP_Resource chooser); }; diff --git a/ppapi/cpp/dev/file_chooser_dev.cc b/ppapi/cpp/dev/file_chooser_dev.cc index aa6535b..ef52b5b0 100644 --- a/ppapi/cpp/dev/file_chooser_dev.cc +++ b/ppapi/cpp/dev/file_chooser_dev.cc @@ -22,12 +22,13 @@ template <> const char* interface_name<PPB_FileChooser_Dev>() { } // namespace -FileChooser_Dev::FileChooser_Dev(const Instance& instance, - const PP_FileChooserOptions_Dev& options) { +FileChooser_Dev::FileChooser_Dev(const Instance* instance, + PP_FileChooserMode_Dev mode, + const Var& accept_mime_types) { if (!has_interface<PPB_FileChooser_Dev>()) return; PassRefFromConstructor(get_interface<PPB_FileChooser_Dev>()->Create( - instance.pp_instance(), &options)); + instance->pp_instance(), mode, accept_mime_types.pp_var())); } FileChooser_Dev::FileChooser_Dev(const FileChooser_Dev& other) diff --git a/ppapi/cpp/dev/file_chooser_dev.h b/ppapi/cpp/dev/file_chooser_dev.h index c2a40e1..6bbe0c5 100644 --- a/ppapi/cpp/dev/file_chooser_dev.h +++ b/ppapi/cpp/dev/file_chooser_dev.h @@ -5,28 +5,66 @@ #ifndef PPAPI_CPP_DEV_FILE_CHOOSER_DEV_H_ #define PPAPI_CPP_DEV_FILE_CHOOSER_DEV_H_ +#include "ppapi/c/dev/ppb_file_chooser_dev.h" #include "ppapi/cpp/resource.h" -struct PP_FileChooserOptions_Dev; - namespace pp { class CompletionCallback; class FileRef; class Instance; +class Var; class FileChooser_Dev : public Resource { public: - // Creates an is_null() FileChooser object. + /// Creates an is_null() FileChooser object. FileChooser_Dev() {} - FileChooser_Dev(const Instance& instance, - const PP_FileChooserOptions_Dev& options); + /// This function creates a file chooser dialog resource. The chooser is + /// associated with a particular instance, so that it may be positioned on the + /// screen relative to the tab containing the instance. Returns 0 if passed + /// an invalid instance. + /// + /// @param mode A PPB_FileChooser_Dev instance can be used to select a single + /// file (PP_FILECHOOSERMODE_OPEN) or multiple files + /// (PP_FILECHOOSERMODE_OPENMULTIPLE). Unlike the HTML5 <input type="file"> + /// tag, a PPB_FileChooser_Dev instance cannot be used to select a directory. + /// In order to get the list of files in a directory, the + /// PPB_DirectoryReader_Dev interface must be used. + /// + /// @param accept_mime_types A comma-separated list of MIME types such as + /// "audio/ *,text/plain" (note there should be no space between the '/' and + /// the '*', but one is added to avoid confusing C++ comments). The dialog + /// may restrict selectable files to the specified MIME types. An empty string + /// or an undefined var may be given to indicate that all types should be + /// accepted. + /// + /// TODO(darin): What if the mime type is unknown to the system? The plugin + /// may wish to describe the mime type and provide a matching file extension. + /// It is more webby to use mime types here instead of file extensions. + FileChooser_Dev(const Instance* instance, + PP_FileChooserMode_Dev mode, + const Var& accept_mime_types); FileChooser_Dev(const FileChooser_Dev& other); - // PPB_FileChooser methods: + /// This function displays a previously created file chooser resource as a + /// dialog box, prompting the user to choose a file or files. The callback is + /// called with PP_OK on successful completion with a file (or files) selected + /// or PP_ERROR_USERCANCEL if the user selected no file. + /// + /// @return PP_OK_COMPLETIONPENDING if request to show the dialog was + /// successful, another error code from pp_errors.h on failure. int32_t Show(const CompletionCallback& cc); + + /// After a successful completion callback call from Show, this method may be + /// used to query the chosen files. It should be called in a loop until it + /// returns an is_null() FileRef. Depending on the PP_ChooseFileMode + /// requested when the FileChooser was created, the file refs will either + /// be readable or writable. Their file system type will be + /// PP_FileSystemType_External. If the user chose no files or cancelled the + /// dialog, then this method will simply return an is_null() FileRef the + /// first time it is called. FileRef GetNextChosenFile() const; }; diff --git a/ppapi/examples/file_chooser/file_chooser.cc b/ppapi/examples/file_chooser/file_chooser.cc index dc12aa9..8c2e675 100644 --- a/ppapi/examples/file_chooser/file_chooser.cc +++ b/ppapi/examples/file_chooser/file_chooser.cc @@ -42,29 +42,25 @@ class MyInstance : public pp::InstancePrivate { void ShowFileChooser(bool multi_select) { RecreateConsole(); - PP_FileChooserOptions_Dev options; - options.mode = (multi_select ? PP_FILECHOOSERMODE_OPENMULTIPLE : - PP_FILECHOOSERMODE_OPEN); - options.accept_mime_types = (multi_select ? "" : "plain/text"); - - // Deleted in ShowSelectedFileNames(). - pp::FileChooser_Dev* file_chooser = new pp::FileChooser_Dev( - *this, options); - file_chooser->Show(callback_factory_.NewCallback( - &MyInstance::ShowSelectedFileNames, file_chooser)); + PP_FileChooserMode_Dev mode = + (multi_select ? PP_FILECHOOSERMODE_OPENMULTIPLE + : PP_FILECHOOSERMODE_OPEN); + std::string accept_mime_types = (multi_select ? "" : "plain/text"); + + chooser_ = pp::FileChooser_Dev(this, mode, accept_mime_types); + chooser_.Show(callback_factory_.NewCallback( + &MyInstance::ShowSelectedFileNames)); } - void ShowSelectedFileNames(int32_t, pp::FileChooser_Dev* file_chooser) { - if (!file_chooser) + void ShowSelectedFileNames(int32_t result) { + if (!result != PP_OK) return; - pp::FileRef file_ref = file_chooser->GetNextChosenFile(); + pp::FileRef file_ref = chooser_.GetNextChosenFile(); while (!file_ref.is_null()) { Log(file_ref.GetName()); - file_ref = file_chooser->GetNextChosenFile(); + file_ref = chooser_.GetNextChosenFile(); } - - delete file_chooser; } void RecreateConsole() { @@ -85,6 +81,8 @@ class MyInstance : public pp::InstancePrivate { console_.Call("appendChild", doc.Call("createTextNode", "\n")); } + pp::FileChooser_Dev chooser_; + pp::CompletionCallbackFactory<MyInstance> callback_factory_; pp::VarPrivate console_; }; diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc index 0432878..6229bc7 100644 --- a/ppapi/proxy/dispatcher.cc +++ b/ppapi/proxy/dispatcher.cc @@ -132,6 +132,7 @@ InterfaceList::InterfaceList() { AddPPB(PPB_Crypto_Proxy::GetInfo()); AddPPB(PPB_CursorControl_Proxy::GetInfo()); AddPPB(PPB_FileChooser_Proxy::GetInfo()); + AddPPB(PPB_FileChooser_Proxy::GetInfo0_4()); AddPPB(PPB_FileRef_Proxy::GetInfo()); AddPPB(PPB_FileSystem_Proxy::GetInfo()); AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 16e272f..cd1efe1 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -340,8 +340,9 @@ IPC_MESSAGE_ROUTED2(PpapiMsg_PPPMessaging_HandleMessage, // PPB_URLLoader // (Messages from browser to plugin to notify it of changes in state.) -IPC_MESSAGE_ROUTED1(PpapiMsg_PPBURLLoader_UpdateProgress, - ppapi::proxy::PPBURLLoader_UpdateProgress_Params /* params */) +IPC_MESSAGE_ROUTED1( + PpapiMsg_PPBURLLoader_UpdateProgress, + ppapi::proxy::PPBURLLoader_UpdateProgress_Params /* params */) IPC_MESSAGE_ROUTED3(PpapiMsg_PPBURLLoader_ReadResponseBody_Ack, ppapi::HostResource /* loader */, int32 /* result */, @@ -520,7 +521,7 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBCursorControl_CanLockCursor, IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFileChooser_Create, PP_Instance /* instance */, int /* mode */, - std::string /* accept_mime_types */, + ppapi::proxy::SerializedVar /* accept_mime_types */, ppapi::HostResource /* result */) IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBFileChooser_Show, ppapi::HostResource /* file_chooser */) @@ -566,9 +567,10 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop, PP_Bool /* on_top */) // This has to be synchronous becuase the caller may want to composite on // top of the resulting text after the call is complete. -IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFlash_DrawGlyphs, - ppapi::proxy::PPBFlash_DrawGlyphs_Params /* params */, - PP_Bool /* result */) +IPC_SYNC_MESSAGE_ROUTED1_1( + PpapiHostMsg_PPBFlash_DrawGlyphs, + ppapi::proxy::PPBFlash_DrawGlyphs_Params /* params */, + PP_Bool /* result */) IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_GetProxyForURL, PP_Instance /* instance */, std::string /* url */, diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index aa3c42e..139df10 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -178,8 +178,8 @@ PP_Resource PPB_Audio_Proxy::CreateProxyResource( if (result.is_null()) return 0; - return (new Audio(result, config_id, audio_callback, user_data))-> - GetReference(); + return (new Audio(result, config_id, + audio_callback, user_data))->GetReference(); } bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) { diff --git a/ppapi/proxy/ppb_context_3d_proxy.h b/ppapi/proxy/ppb_context_3d_proxy.h index e7ac81f..8a49efe 100644 --- a/ppapi/proxy/ppb_context_3d_proxy.h +++ b/ppapi/proxy/ppb_context_3d_proxy.h @@ -35,8 +35,7 @@ namespace proxy { class Surface3D; -class Context3D : public Resource, - public thunk::PPB_Context3D_API { +class Context3D : public Resource, public thunk::PPB_Context3D_API { public: explicit Context3D(const HostResource& resource); virtual ~Context3D(); diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index 385c7f8..10ed0d9 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -15,6 +15,7 @@ #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/var.h" #include "ppapi/thunk/thunk.h" using ppapi::thunk::PPB_FileChooser_API; @@ -32,7 +33,7 @@ class FileChooser : public Resource, virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; // PPB_FileChooser_API implementation. - virtual int32_t Show(PP_CompletionCallback callback) OVERRIDE; + virtual int32_t Show(const PP_CompletionCallback& callback) OVERRIDE; virtual PP_Resource GetNextChosenFile() OVERRIDE; // Handles the choose complete notification from the host. @@ -80,7 +81,7 @@ PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { return this; } -int32_t FileChooser::Show(PP_CompletionCallback callback) { +int32_t FileChooser::Show(const PP_CompletionCallback& callback) { if (current_show_callback_.func) return PP_ERROR_INPROGRESS; // Can't show more than once. @@ -119,6 +120,37 @@ void FileChooser::ChooseComplete( namespace { +PP_Resource Create0_4(PP_Instance instance, + const PP_FileChooserOptions_0_4_Dev* options) { + PP_Var accept_var = PP_MakeUndefined(); + if (options->accept_mime_types) + accept_var = StringVar::StringToPPVar(0, options->accept_mime_types); + PP_Resource result = thunk::GetPPB_FileChooser_Thunk()->Create( + instance, options->mode, accept_var); + if (accept_var.type == PP_VARTYPE_STRING) + PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(accept_var); + return result; +} + +PP_Bool IsFileChooser0_4(PP_Resource resource) { + return thunk::GetPPB_FileChooser_Thunk()->IsFileChooser(resource); +} + +int32_t Show0_4(PP_Resource chooser, PP_CompletionCallback callback) { + return thunk::GetPPB_FileChooser_Thunk()->Show(chooser, callback); +} + +PP_Resource GetNextChosenFile0_4(PP_Resource chooser) { + return thunk::GetPPB_FileChooser_Thunk()->GetNextChosenFile(chooser); +} + +PPB_FileChooser_0_4_Dev file_chooser_0_4_interface = { + &Create0_4, + &IsFileChooser0_4, + &Show0_4, + &GetNextChosenFile0_4 +}; + InterfaceProxy* CreateFileChooserProxy(Dispatcher* dispatcher, const void* target_interface) { return new PPB_FileChooser_Proxy(dispatcher, target_interface); @@ -146,10 +178,22 @@ const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo() { return &info; } +const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo0_4() { + static const Info info = { + &file_chooser_0_4_interface, + PPB_FILECHOOSER_DEV_INTERFACE_0_4, + INTERFACE_ID_NONE, + false, + &CreateFileChooserProxy, + }; + return &info; +} + // static PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( PP_Instance instance, - const PP_FileChooserOptions_Dev* options) { + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types) { Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); if (!dispatcher) return 0; @@ -157,8 +201,7 @@ PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( HostResource result; dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Create( INTERFACE_ID_PPB_FILE_CHOOSER, instance, - options->mode, - options->accept_mime_types ? options->accept_mime_types : std::string(), + mode, SerializedVarSendInput(dispatcher, accept_mime_types), &result)); if (result.is_null()) @@ -181,15 +224,14 @@ bool PPB_FileChooser_Proxy::OnMessageReceived(const IPC::Message& msg) { return handled; } -void PPB_FileChooser_Proxy::OnMsgCreate(PP_Instance instance, - int mode, - const std::string& accept_mime_types, - HostResource* result) { - PP_FileChooserOptions_Dev options; - options.mode = static_cast<PP_FileChooserMode_Dev>(mode); - options.accept_mime_types = accept_mime_types.c_str(); - result->SetHostResource( - instance, ppb_file_chooser_target()->Create(instance, &options)); +void PPB_FileChooser_Proxy::OnMsgCreate( + PP_Instance instance, + int mode, + SerializedVarReceiveInput accept_mime_types, + HostResource* result) { + result->SetHostResource(instance, ppb_file_chooser_target()->Create( + instance, static_cast<PP_FileChooserMode_Dev>(mode), + accept_mime_types.Get(dispatcher()))); } void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) { diff --git a/ppapi/proxy/ppb_file_chooser_proxy.h b/ppapi/proxy/ppb_file_chooser_proxy.h index 40a453f..322edc2 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.h +++ b/ppapi/proxy/ppb_file_chooser_proxy.h @@ -24,6 +24,7 @@ class HostResource; namespace proxy { struct PPBFileRef_CreateInfo; +class SerializedVarReceiveInput; class PPB_FileChooser_Proxy : public InterfaceProxy { public: @@ -31,10 +32,12 @@ class PPB_FileChooser_Proxy : public InterfaceProxy { virtual ~PPB_FileChooser_Proxy(); static const Info* GetInfo(); + static const Info* GetInfo0_4(); static PP_Resource CreateProxyResource( PP_Instance instance, - const PP_FileChooserOptions_Dev* options); + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types); const PPB_FileChooser_Dev* ppb_file_chooser_target() const { return static_cast<const PPB_FileChooser_Dev*>(target_interface()); @@ -47,7 +50,7 @@ class PPB_FileChooser_Proxy : public InterfaceProxy { // Plugin -> host message handlers. void OnMsgCreate(PP_Instance instance, int mode, - const std::string& accept_mime_types, + SerializedVarReceiveInput accept_mime_types, ppapi::HostResource* result); void OnMsgShow(const ppapi::HostResource& chooser); diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 25066f9..bc9d0e8 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -114,8 +114,10 @@ PP_Resource ResourceCreationProxy::CreateDirectoryReader( PP_Resource ResourceCreationProxy::CreateFileChooser( PP_Instance instance, - const PP_FileChooserOptions_Dev* options) { - return PPB_FileChooser_Proxy::CreateProxyResource(instance, options); + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types) { + return PPB_FileChooser_Proxy::CreateProxyResource(instance, mode, + accept_mime_types); } PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) { diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 88b0caa..0cbf230 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -58,7 +58,8 @@ class ResourceCreationProxy : public FunctionGroupBase, virtual PP_Resource CreateDirectoryReader(PP_Resource directory_ref) OVERRIDE; virtual PP_Resource CreateFileChooser( PP_Instance instance, - const PP_FileChooserOptions_Dev* options) OVERRIDE; + PP_FileChooserMode_Dev mode, + const PP_Var& 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/tests/arch_dependent_sizes_32.h b/ppapi/tests/arch_dependent_sizes_32.h index e207bc2..166df95 100644 --- a/ppapi/tests/arch_dependent_sizes_32.h +++ b/ppapi/tests/arch_dependent_sizes_32.h @@ -16,7 +16,6 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(GLsizeiptr, 4); PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_CompletionCallback_Func, 4); PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_URLLoaderTrusted_StatusCallback, 4); PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_CompletionCallback, 12); -PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_FileChooserOptions_Dev, 8); PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Picture_Dev, 8); PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoBitstreamBuffer_Dev, 12); PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PPB_VideoDecoder_Dev, 32); diff --git a/ppapi/tests/arch_dependent_sizes_64.h b/ppapi/tests/arch_dependent_sizes_64.h index 340456d..20ccb90 100644 --- a/ppapi/tests/arch_dependent_sizes_64.h +++ b/ppapi/tests/arch_dependent_sizes_64.h @@ -16,7 +16,6 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(GLsizeiptr, 8); PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_CompletionCallback_Func, 8); PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_URLLoaderTrusted_StatusCallback, 8); PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_CompletionCallback, 24); -PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_FileChooserOptions_Dev, 16); PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Picture_Dev, 8); PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoBitstreamBuffer_Dev, 12); PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PPB_VideoDecoder_Dev, 64); diff --git a/ppapi/thunk/ppb_file_chooser_api.h b/ppapi/thunk/ppb_file_chooser_api.h index 4119ae6..fba94c7 100644 --- a/ppapi/thunk/ppb_file_chooser_api.h +++ b/ppapi/thunk/ppb_file_chooser_api.h @@ -14,7 +14,7 @@ class PPB_FileChooser_API { public: virtual ~PPB_FileChooser_API() {} - virtual int32_t Show(PP_CompletionCallback callback) = 0; + virtual int32_t Show(const PP_CompletionCallback& callback) = 0; virtual PP_Resource GetNextChosenFile() = 0; }; diff --git a/ppapi/thunk/ppb_file_chooser_thunk.cc b/ppapi/thunk/ppb_file_chooser_thunk.cc index 224d248..c58f052 100644 --- a/ppapi/thunk/ppb_file_chooser_thunk.cc +++ b/ppapi/thunk/ppb_file_chooser_thunk.cc @@ -17,11 +17,13 @@ namespace thunk { namespace { PP_Resource Create(PP_Instance instance, - const PP_FileChooserOptions_Dev* options) { + PP_FileChooserMode_Dev mode, + struct PP_Var accept_mime_types) { EnterFunction<ResourceCreationAPI> enter(instance, true); if (enter.failed()) return 0; - return enter.functions()->CreateFileChooser(instance, options); + return enter.functions()->CreateFileChooser(instance, mode, + accept_mime_types); } PP_Bool IsFileChooser(PP_Resource resource) { diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index 589484d..948a1dd 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -56,7 +56,8 @@ class ResourceCreationAPI { virtual PP_Resource CreateDirectoryReader(PP_Resource directory_ref) = 0; virtual PP_Resource CreateFileChooser( PP_Instance instance, - const PP_FileChooserOptions_Dev* options) = 0; + PP_FileChooserMode_Dev mode, + const PP_Var& 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/webkit/plugins/ppapi/ppb_file_chooser_impl.cc b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc index 88ef8c4..14f4784 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc @@ -11,6 +11,7 @@ #include "base/sys_string_conversions.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/shared_impl/var.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserCompletion.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" @@ -25,6 +26,7 @@ #include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/glue/webkit_glue.h" +using ppapi::StringVar; using ppapi::thunk::PPB_FileChooser_API; using WebKit::WebCString; using WebKit::WebFileChooserCompletion; @@ -62,12 +64,14 @@ class FileChooserCompletionImpl : public WebFileChooserCompletion { PPB_FileChooser_Impl::PPB_FileChooser_Impl( PluginInstance* instance, - const PP_FileChooserOptions_Dev* options) + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types) : Resource(instance), - mode_(options->mode), - accept_mime_types_(options->accept_mime_types ? - options->accept_mime_types : ""), + mode_(mode), next_chosen_file_index_(0) { + scoped_refptr<StringVar> accept = StringVar::FromPPVar(accept_mime_types); + if (accept) + accept_mime_types_ = accept->value(); } PPB_FileChooser_Impl::~PPB_FileChooser_Impl() { @@ -76,11 +80,13 @@ PPB_FileChooser_Impl::~PPB_FileChooser_Impl() { // static PP_Resource PPB_FileChooser_Impl::Create( PluginInstance* instance, - const PP_FileChooserOptions_Dev* options) { - if ((options->mode != PP_FILECHOOSERMODE_OPEN) && - (options->mode != PP_FILECHOOSERMODE_OPENMULTIPLE)) + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types) { + if (mode != PP_FILECHOOSERMODE_OPEN && + mode != PP_FILECHOOSERMODE_OPENMULTIPLE) return 0; - return (new PPB_FileChooser_Impl(instance, options))->GetReference(); + return (new PPB_FileChooser_Impl(instance, mode, + accept_mime_types))->GetReference(); } PPB_FileChooser_Impl* PPB_FileChooser_Impl::AsPPB_FileChooser_Impl() { @@ -137,7 +143,7 @@ void PPB_FileChooser_Impl::RunCallback(int32_t result) { callback->Run(result); // Will complete abortively if necessary. } -int32_t PPB_FileChooser_Impl::Show(PP_CompletionCallback callback) { +int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { int32_t rv = ValidateCallback(callback); if (rv != PP_OK) return rv; diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.h b/webkit/plugins/ppapi/ppb_file_chooser_impl.h index 796ddd1..88813d8 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.h +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.h @@ -9,7 +9,6 @@ #include <vector> #include "base/memory/ref_counted.h" -#include "ppapi/c/dev/ppb_file_chooser_dev.h" #include "ppapi/thunk/ppb_file_chooser_api.h" #include "webkit/plugins/ppapi/resource.h" @@ -26,11 +25,13 @@ class PPB_FileChooser_Impl : public Resource, public ::ppapi::thunk::PPB_FileChooser_API { public: PPB_FileChooser_Impl(PluginInstance* instance, - const PP_FileChooserOptions_Dev* options); + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types); virtual ~PPB_FileChooser_Impl(); static PP_Resource Create(PluginInstance* instance, - const PP_FileChooserOptions_Dev* options); + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types); // Resource overrides. virtual PPB_FileChooser_Impl* AsPPB_FileChooser_Impl(); @@ -53,7 +54,7 @@ class PPB_FileChooser_Impl : public Resource, void RunCallback(int32_t result); // PPB_FileChooser_API implementation. - virtual int32_t Show(PP_CompletionCallback callback) OVERRIDE; + virtual int32_t Show(const PP_CompletionCallback& callback) OVERRIDE; virtual PP_Resource GetNextChosenFile() OVERRIDE; private: diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 720f8a4..0aafe50 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -107,8 +107,9 @@ PP_Resource ResourceCreationImpl::CreateDirectoryReader( PP_Resource ResourceCreationImpl::CreateFileChooser( PP_Instance instance, - const PP_FileChooserOptions_Dev* options) { - return PPB_FileChooser_Impl::Create(instance_, options); + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types) { + return PPB_FileChooser_Impl::Create(instance_, mode, accept_mime_types); } PP_Resource ResourceCreationImpl::CreateFileIO(PP_Instance instance) { diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index 417a949..1b29cb5 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -47,7 +47,8 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, virtual PP_Resource CreateDirectoryReader(PP_Resource directory_ref) OVERRIDE; virtual PP_Resource CreateFileChooser( PP_Instance instance, - const PP_FileChooserOptions_Dev* options) OVERRIDE; + PP_FileChooserMode_Dev mode, + const PP_Var& accept_mime_types) OVERRIDE; virtual PP_Resource CreateFileIO(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateFileRef(PP_Resource file_system, const char* path) OVERRIDE; |