diff options
author | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-30 00:05:32 +0000 |
---|---|---|
committer | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-30 00:05:32 +0000 |
commit | f9a4c41a40dc781ea6bbbeeeb77ee3713dc168e2 (patch) | |
tree | 2f06565b8aaf35996d1ff3a553801f6d5aa29565 /ppapi | |
parent | 1e1184a4047adf5096a5597e4adf1ad07130445a (diff) | |
download | chromium_src-f9a4c41a40dc781ea6bbbeeeb77ee3713dc168e2.zip chromium_src-f9a4c41a40dc781ea6bbbeeeb77ee3713dc168e2.tar.gz chromium_src-f9a4c41a40dc781ea6bbbeeeb77ee3713dc168e2.tar.bz2 |
Modified the pepper file chooser API to support filtering files by extensions.
Previously you could filter only by MIME type. This adds support for filtering by specific extensions as well, e.g. .txt,.html. This change is aligned with the web platform which now allows filtering by file extension for <input> elements (http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#attr-input-accept).
This also changes the linux implementation of the file dialog (SelectFileDialogImplGTK). In the past, it would turn file extensions to filter into MIME types. However this is a bit silly because in FileSelectHelper we do the reverse (turn MIME types into a list of file extensions to filter by). It also prevents us from filtering by a specific extensions when this is really what is desired.
BUG=129251
TEST=
Review URL: https://chromiumcodereview.appspot.com/10414085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139434 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/api/dev/ppb_file_chooser_dev.idl | 16 | ||||
-rw-r--r-- | ppapi/c/dev/ppb_file_chooser_dev.h | 20 | ||||
-rw-r--r-- | ppapi/cpp/dev/file_chooser_dev.cc | 8 | ||||
-rw-r--r-- | ppapi/cpp/dev/file_chooser_dev.h | 21 | ||||
-rw-r--r-- | ppapi/cpp/trusted/file_chooser_trusted.cc | 4 | ||||
-rw-r--r-- | ppapi/cpp/trusted/file_chooser_trusted.h | 2 | ||||
-rw-r--r-- | ppapi/examples/file_chooser/file_chooser.cc | 6 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_chooser_proxy.cc | 8 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_chooser_proxy.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 4 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.h | 2 | ||||
-rw-r--r-- | ppapi/thunk/ppb_file_chooser_thunk.cc | 4 | ||||
-rw-r--r-- | ppapi/thunk/resource_creation_api.h | 2 |
14 files changed, 53 insertions, 50 deletions
diff --git a/ppapi/api/dev/ppb_file_chooser_dev.idl b/ppapi/api/dev/ppb_file_chooser_dev.idl index 425154b..cd5678c 100644 --- a/ppapi/api/dev/ppb_file_chooser_dev.idl +++ b/ppapi/api/dev/ppb_file_chooser_dev.idl @@ -39,12 +39,14 @@ interface PPB_FileChooser_Dev { * of a module. * @param[in] mode A <code>PP_FileChooserMode_Dev</code> value that controls * the behavior of the file chooser dialog. - * @param[in] 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. + * @param[in] accept_types A comma-separated list of MIME types and file + * extensions such as "audio/ *,text/plain,.html" (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 and file extensions. If a string in the comma-separated list begins + * with a period (.) then the string is interpreted as a file extension, + * otherwise it is interpreted as a MIME-type. An empty string or an undefined + * var may be given to indicate that all types should be accepted. * * @return A <code>PP_Resource</code> containing the file chooser if * successful or 0 if it could not be created. @@ -52,7 +54,7 @@ interface PPB_FileChooser_Dev { PP_Resource Create( [in] PP_Instance instance, [in] PP_FileChooserMode_Dev mode, - [in] PP_Var accept_mime_types); + [in] PP_Var accept_types); /** * Determines if the provided resource is a file chooser. diff --git a/ppapi/c/dev/ppb_file_chooser_dev.h b/ppapi/c/dev/ppb_file_chooser_dev.h index 81e8f52..469c712 100644 --- a/ppapi/c/dev/ppb_file_chooser_dev.h +++ b/ppapi/c/dev/ppb_file_chooser_dev.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From dev/ppb_file_chooser_dev.idl modified Thu Mar 15 09:29:39 2012. */ +/* From dev/ppb_file_chooser_dev.idl modified Thu May 17 09:04:27 2012. */ #ifndef PPAPI_C_DEV_PPB_FILE_CHOOSER_DEV_H_ #define PPAPI_C_DEV_PPB_FILE_CHOOSER_DEV_H_ @@ -64,19 +64,21 @@ struct PPB_FileChooser_Dev_0_6 { * of a module. * @param[in] mode A <code>PP_FileChooserMode_Dev</code> value that controls * the behavior of the file chooser dialog. - * @param[in] 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. + * @param[in] accept_types A comma-separated list of MIME types and file + * extensions such as "audio/ *,text/plain,.html" (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 and file extensions. If a string in the comma-separated list begins + * with a period (.) then the string is interpreted as a file extension, + * otherwise it is interpreted as a MIME-type. An empty string or an undefined + * var may be given to indicate that all types should be accepted. * * @return A <code>PP_Resource</code> containing the file chooser if * successful or 0 if it could not be created. */ PP_Resource (*Create)(PP_Instance instance, PP_FileChooserMode_Dev mode, - struct PP_Var accept_mime_types); + struct PP_Var accept_types); /** * Determines if the provided resource is a file chooser. * @@ -117,7 +119,7 @@ typedef struct PPB_FileChooser_Dev_0_6 PPB_FileChooser_Dev; struct PPB_FileChooser_Dev_0_5 { PP_Resource (*Create)(PP_Instance instance, PP_FileChooserMode_Dev mode, - struct PP_Var accept_mime_types); + struct PP_Var accept_types); 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 a773def..b7124a1 100644 --- a/ppapi/cpp/dev/file_chooser_dev.cc +++ b/ppapi/cpp/dev/file_chooser_dev.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -30,13 +30,13 @@ template <> const char* interface_name<PPB_FileChooser_Dev_0_6>() { FileChooser_Dev::FileChooser_Dev(const InstanceHandle& instance, PP_FileChooserMode_Dev mode, - const Var& accept_mime_types) { + const Var& accept_types) { if (has_interface<PPB_FileChooser_Dev_0_6>()) { PassRefFromConstructor(get_interface<PPB_FileChooser_Dev_0_6>()->Create( - instance.pp_instance(), mode, accept_mime_types.pp_var())); + instance.pp_instance(), mode, accept_types.pp_var())); } else if (has_interface<PPB_FileChooser_Dev_0_5>()) { PassRefFromConstructor(get_interface<PPB_FileChooser_Dev_0_5>()->Create( - instance.pp_instance(), mode, accept_mime_types.pp_var())); + instance.pp_instance(), mode, accept_types.pp_var())); } } diff --git a/ppapi/cpp/dev/file_chooser_dev.h b/ppapi/cpp/dev/file_chooser_dev.h index b588ac85..4feee6a 100644 --- a/ppapi/cpp/dev/file_chooser_dev.h +++ b/ppapi/cpp/dev/file_chooser_dev.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -36,19 +36,18 @@ class FileChooser_Dev : public Resource { /// 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 + /// @param accept_types A comma-separated list of MIME types and file + /// extensions such as "audio/ *,text/plain,.html" (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 and file extensions. If a string in the comma-separated list + /// begins with a period (.) then the string is interpreted as a file + /// extension, otherwise it is interpreted as a MIME-type. 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 InstanceHandle& instance, PP_FileChooserMode_Dev mode, - const Var& accept_mime_types); + const Var& accept_types); FileChooser_Dev(const FileChooser_Dev& other); diff --git a/ppapi/cpp/trusted/file_chooser_trusted.cc b/ppapi/cpp/trusted/file_chooser_trusted.cc index 92fec74..caa1b73 100644 --- a/ppapi/cpp/trusted/file_chooser_trusted.cc +++ b/ppapi/cpp/trusted/file_chooser_trusted.cc @@ -30,10 +30,10 @@ FileChooser_Trusted::FileChooser_Trusted() : save_as_(false) { FileChooser_Trusted::FileChooser_Trusted(const InstanceHandle& instance, PP_FileChooserMode_Dev mode, - const Var& accept_mime_types, + const Var& accept_types, bool save_as, const std::string& suggested_file_name) - : FileChooser_Dev(instance, mode, accept_mime_types), + : FileChooser_Dev(instance, mode, accept_types), save_as_(save_as), suggested_file_name_(suggested_file_name) { } diff --git a/ppapi/cpp/trusted/file_chooser_trusted.h b/ppapi/cpp/trusted/file_chooser_trusted.h index 6b3c1c1..cdb70b0 100644 --- a/ppapi/cpp/trusted/file_chooser_trusted.h +++ b/ppapi/cpp/trusted/file_chooser_trusted.h @@ -18,7 +18,7 @@ class FileChooser_Trusted : public FileChooser_Dev { FileChooser_Trusted(const InstanceHandle& instance, PP_FileChooserMode_Dev mode, - const Var& accept_mime_types, + const Var& accept_types, bool save_as, const std::string& suggested_file_name); diff --git a/ppapi/examples/file_chooser/file_chooser.cc b/ppapi/examples/file_chooser/file_chooser.cc index 959e649..fd207fe 100644 --- a/ppapi/examples/file_chooser/file_chooser.cc +++ b/ppapi/examples/file_chooser/file_chooser.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -46,9 +46,9 @@ class MyInstance : public pp::InstancePrivate { PP_FileChooserMode_Dev mode = (multi_select ? PP_FILECHOOSERMODE_OPENMULTIPLE : PP_FILECHOOSERMODE_OPEN); - std::string accept_mime_types = (multi_select ? "" : "plain/text"); + std::string accept_types = (multi_select ? "" : "plain/text"); - chooser_ = pp::FileChooser_Dev(this, mode, accept_mime_types); + chooser_ = pp::FileChooser_Dev(this, mode, accept_types); chooser_.Show(callback_factory_.NewCallbackWithOutput( &MyInstance::ShowSelectedFileNames)); } diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index fa0c71c..3eba62e 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1041,7 +1041,7 @@ IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBBuffer_Create, IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFileChooser_Create, PP_Instance /* instance */, int /* mode */, - std::string /* accept_mime_types */, + std::string /* accept_types */, ppapi::HostResource /* result */) IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFileChooser_Show, ppapi::HostResource /* file_chooser */, diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index 466d0e6..c7d7a74 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -204,7 +204,7 @@ PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() { PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( PP_Instance instance, PP_FileChooserMode_Dev mode, - const char* accept_mime_types) { + const char* accept_types) { Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); if (!dispatcher) return 0; @@ -213,7 +213,7 @@ PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Create( API_ID_PPB_FILE_CHOOSER, instance, mode, - accept_mime_types ? accept_mime_types : "", + accept_types ? accept_types : "", &result)); if (result.is_null()) @@ -239,14 +239,14 @@ bool PPB_FileChooser_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_FileChooser_Proxy::OnMsgCreate( PP_Instance instance, int mode, - std::string accept_mime_types, + std::string accept_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.c_str())); + accept_types.c_str())); } } diff --git a/ppapi/proxy/ppb_file_chooser_proxy.h b/ppapi/proxy/ppb_file_chooser_proxy.h index a0bfc0a..825d7c9 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.h +++ b/ppapi/proxy/ppb_file_chooser_proxy.h @@ -33,7 +33,7 @@ class PPB_FileChooser_Proxy : public InterfaceProxy { static PP_Resource CreateProxyResource( PP_Instance instance, PP_FileChooserMode_Dev mode, - const char* accept_mime_types); + const char* accept_types); // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -44,7 +44,7 @@ class PPB_FileChooser_Proxy : public InterfaceProxy { // Plugin -> host message handlers. void OnMsgCreate(PP_Instance instance, int mode, - std::string accept_mime_types, + std::string accept_types, ppapi::HostResource* result); void OnMsgShow(const ppapi::HostResource& chooser, PP_Bool save_as, diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 064410e..41a6c7c 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -223,9 +223,9 @@ PP_Resource ResourceCreationProxy::CreateDirectoryReader( PP_Resource ResourceCreationProxy::CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, - const char* accept_mime_types) { + const char* accept_types) { return PPB_FileChooser_Proxy::CreateProxyResource(instance, mode, - accept_mime_types); + accept_types); } PP_Resource ResourceCreationProxy::CreateFlashMenu( diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 25243ef..d6a2e76 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -110,7 +110,7 @@ class ResourceCreationProxy : public InterfaceProxy, virtual PP_Resource CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, - const char* accept_mime_types) OVERRIDE; + const char* accept_types) OVERRIDE; virtual PP_Resource CreateFlashMenu(PP_Instance instance, const PP_Flash_Menu* menu_data) OVERRIDE; virtual PP_Resource CreateFlashMessageLoop(PP_Instance instance) OVERRIDE; diff --git a/ppapi/thunk/ppb_file_chooser_thunk.cc b/ppapi/thunk/ppb_file_chooser_thunk.cc index 083ffb8..8db1b50 100644 --- a/ppapi/thunk/ppb_file_chooser_thunk.cc +++ b/ppapi/thunk/ppb_file_chooser_thunk.cc @@ -19,12 +19,12 @@ namespace { PP_Resource Create(PP_Instance instance, PP_FileChooserMode_Dev mode, - struct PP_Var accept_mime_types) { + struct PP_Var accept_types) { EnterResourceCreation enter(instance); if (enter.failed()) return 0; scoped_refptr<StringVar> string_var = - StringVar::FromPPVar(accept_mime_types); + StringVar::FromPPVar(accept_types); std::string str = string_var ? string_var->value() : std::string(); return enter.functions()->CreateFileChooser(instance, mode, str.c_str()); } diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index 3f18275..2f214e7 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -115,7 +115,7 @@ class ResourceCreationAPI { virtual PP_Resource CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, - const char* accept_mime_types) = 0; + const char* accept_types) = 0; virtual PP_Resource CreateFlashMenu(PP_Instance instance, const PP_Flash_Menu* menu_data) = 0; virtual PP_Resource CreateFlashMessageLoop(PP_Instance instance) = 0; |