summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 00:05:32 +0000
committerraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 00:05:32 +0000
commitf9a4c41a40dc781ea6bbbeeeb77ee3713dc168e2 (patch)
tree2f06565b8aaf35996d1ff3a553801f6d5aa29565
parent1e1184a4047adf5096a5597e4adf1ad07130445a (diff)
downloadchromium_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
-rw-r--r--chrome/browser/file_select_helper.cc39
-rw-r--r--chrome/browser/file_select_helper.h9
-rw-r--r--chrome/browser/file_select_helper_unittest.cc19
-rw-r--r--chrome/browser/ui/gtk/select_file_dialog_impl_gtk.cc25
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--content/public/common/file_chooser_params.h6
-rw-r--r--content/renderer/render_view_impl.cc6
-rw-r--r--ppapi/api/dev/ppb_file_chooser_dev.idl16
-rw-r--r--ppapi/c/dev/ppb_file_chooser_dev.h20
-rw-r--r--ppapi/cpp/dev/file_chooser_dev.cc8
-rw-r--r--ppapi/cpp/dev/file_chooser_dev.h21
-rw-r--r--ppapi/cpp/trusted/file_chooser_trusted.cc4
-rw-r--r--ppapi/cpp/trusted/file_chooser_trusted.h2
-rw-r--r--ppapi/examples/file_chooser/file_chooser.cc6
-rw-r--r--ppapi/proxy/ppapi_messages.h2
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.cc8
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.h4
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc4
-rw-r--r--ppapi/proxy/resource_creation_proxy.h2
-rw-r--r--ppapi/thunk/ppb_file_chooser_thunk.cc4
-rw-r--r--ppapi/thunk/resource_creation_api.h2
-rw-r--r--webkit/plugins/ppapi/ppb_file_chooser_impl.cc46
-rw-r--r--webkit/plugins/ppapi/ppb_file_chooser_impl.h12
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.cc4
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.h2
25 files changed, 152 insertions, 120 deletions
diff --git a/chrome/browser/file_select_helper.cc b/chrome/browser/file_select_helper.cc
index 4b328fc..591f725f 100644
--- a/chrome/browser/file_select_helper.cc
+++ b/chrome/browser/file_select_helper.cc
@@ -249,30 +249,31 @@ SelectFileDialog::FileTypeInfo* FileSelectHelper::GetFileTypesFromAcceptType(
file_type->extensions.resize(1);
std::vector<FilePath::StringType>* extensions = &file_type->extensions.back();
- // Find the correspondinge extensions.
+ // Find the corresponding extensions.
int valid_type_count = 0;
int description_id = 0;
for (size_t i = 0; i < accept_types.size(); ++i) {
- std::string ascii_mime_type = UTF16ToASCII(accept_types[i]);
- // WebKit normalizes MIME types. See HTMLInputElement::acceptMIMETypes().
- DCHECK(StringToLowerASCII(ascii_mime_type) == ascii_mime_type)
- << "A MIME type contains uppercase letter: " << ascii_mime_type;
- DCHECK(TrimWhitespaceASCII(ascii_mime_type, TRIM_ALL, &ascii_mime_type)
- == TRIM_NONE)
- << "A MIME type contains whitespace: '" << ascii_mime_type << "'";
+ std::string ascii_type = UTF16ToASCII(accept_types[i]);
+ if (!IsAcceptTypeValid(ascii_type))
+ continue;
size_t old_extension_size = extensions->size();
- if (ascii_mime_type == "image/*") {
+ if (ascii_type[0] == '.') {
+ // If the type starts with a period it is assumed to be a file extension
+ // so we just have to add it to the list.
+ FilePath::StringType ext(ascii_type.begin(), ascii_type.end());
+ extensions->push_back(ext.substr(1));
+ } else if (ascii_type == "image/*") {
description_id = IDS_IMAGE_FILES;
net::GetImageExtensions(extensions);
- } else if (ascii_mime_type == "audio/*") {
+ } else if (ascii_type == "audio/*") {
description_id = IDS_AUDIO_FILES;
net::GetAudioExtensions(extensions);
- } else if (ascii_mime_type == "video/*") {
+ } else if (ascii_type == "video/*") {
description_id = IDS_VIDEO_FILES;
net::GetVideoExtensions(extensions);
} else {
- net::GetExtensionsForMimeType(ascii_mime_type, extensions);
+ net::GetExtensionsForMimeType(ascii_type, extensions);
}
if (extensions->size() > old_extension_size)
@@ -461,3 +462,17 @@ void FileSelectHelper::Observe(int type,
NOTREACHED();
}
}
+
+// static
+bool FileSelectHelper::IsAcceptTypeValid(const std::string& accept_type) {
+ // TODO(raymes): This only does some basic checks, extend to test more cases.
+ // A 1 character accept type will always be invalid (either a "." in the case
+ // of an extension or a "/" in the case of a MIME type).
+ std::string unused;
+ if (accept_type.length() <= 1 ||
+ StringToLowerASCII(accept_type) != accept_type ||
+ TrimWhitespaceASCII(accept_type, TRIM_ALL, &unused) != TRIM_NONE) {
+ return false;
+ }
+ return true;
+}
diff --git a/chrome/browser/file_select_helper.h b/chrome/browser/file_select_helper.h
index 7f544a4..87c8ec6 100644
--- a/chrome/browser/file_select_helper.h
+++ b/chrome/browser/file_select_helper.h
@@ -10,6 +10,7 @@
#include <vector>
#include "base/compiler_specific.h"
+#include "base/gtest_prod_util.h"
#include "chrome/browser/ui/select_file_dialog.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -43,6 +44,7 @@ class FileSelectHelper
private:
friend class base::RefCountedThreadSafe<FileSelectHelper>;
+ FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, IsAcceptTypeValid);
explicit FileSelectHelper(Profile* profile);
virtual ~FileSelectHelper();
@@ -123,10 +125,15 @@ class FileSelectHelper
// Helper method to get allowed extensions for select file dialog from
// the specified accept types as defined in the spec:
// http://whatwg.org/html/number-state.html#attr-input-accept
- // |accept_types| contains only valid lowercased MIME types.
+ // |accept_types| contains only valid lowercased MIME types or file extensions
+ // beginning with a period (.).
SelectFileDialog::FileTypeInfo* GetFileTypesFromAcceptType(
const std::vector<string16>& accept_types);
+ // Check the accept type is valid. It is expected to be all lower case with
+ // no whitespace.
+ static bool IsAcceptTypeValid(const std::string& accept_type);
+
// Profile used to set/retrieve the last used directory.
Profile* profile_;
diff --git a/chrome/browser/file_select_helper_unittest.cc b/chrome/browser/file_select_helper_unittest.cc
new file mode 100644
index 0000000..5eb0436
--- /dev/null
+++ b/chrome/browser/file_select_helper_unittest.cc
@@ -0,0 +1,19 @@
+// 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.
+
+#include "chrome/browser/file_select_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(FileSelectHelperTest, IsAcceptTypeValid) {
+ EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("a/b"));
+ EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/def"));
+ EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/*"));
+ EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".a"));
+ EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".abc"));
+
+ EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("."));
+ EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("/"));
+ EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("ABC/*"));
+ EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("abc/def "));
+}
diff --git a/chrome/browser/ui/gtk/select_file_dialog_impl_gtk.cc b/chrome/browser/ui/gtk/select_file_dialog_impl_gtk.cc
index 3544eb3..b657f7f 100644
--- a/chrome/browser/ui/gtk/select_file_dialog_impl_gtk.cc
+++ b/chrome/browser/ui/gtk/select_file_dialog_impl_gtk.cc
@@ -19,7 +19,6 @@
#include "chrome/browser/ui/select_file_dialog.h"
#include "content/public/browser/browser_thread.h"
#include "grit/generated_resources.h"
-#include "net/base/mime_util.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/base/l10n/l10n_util.h"
@@ -228,27 +227,11 @@ void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) {
const std::string& current_extension = file_types_.extensions[i][j];
if (!current_extension.empty()) {
- std::string mime_type;
- bool found_valid_mime_type;
- {
- // Allow IO in the file dialog. (http://crbug.com/72637)
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- found_valid_mime_type = net::GetMimeTypeFromExtension(
- current_extension, &mime_type);
- }
if (!filter)
filter = gtk_file_filter_new();
-
- // Try to add a mime-type filter instead of an extension filter if
- // possible. (http://crbug.com/12347)
- if (found_valid_mime_type) {
- gtk_file_filter_add_mime_type(filter, mime_type.c_str());
- fallback_labels.insert(mime_type);
- } else {
- std::string pattern = "*." + current_extension;
- gtk_file_filter_add_pattern(filter, pattern.c_str());
- fallback_labels.insert(pattern);
- }
+ std::string pattern = "*." + current_extension;
+ gtk_file_filter_add_pattern(filter, pattern.c_str());
+ fallback_labels.insert(pattern);
}
}
// We didn't find any non-empty extensions to filter on.
@@ -262,7 +245,7 @@ void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
file_types_.extension_description_overrides[i]).c_str());
} else {
// There is no system default filter description so we use
- // the MIME types themselves if the description is blank.
+ // the extensions themselves if the description is blank.
std::vector<std::string> fallback_labels_vector(fallback_labels.begin(),
fallback_labels.end());
std::string fallback_label = JoinString(fallback_labels_vector, ',');
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index f9cf498..dfcc806 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1237,6 +1237,7 @@
'browser/extensions/webstore_inline_installer_unittest.cc',
'browser/external_protocol/external_protocol_handler_unittest.cc',
'browser/favicon/favicon_handler_unittest.cc',
+ 'browser/file_select_helper_unittest.cc',
'browser/first_run/first_run_unittest.cc',
'browser/geolocation/chrome_geolocation_permission_context_unittest.cc',
'browser/geolocation/geolocation_settings_state_unittest.cc',
diff --git a/content/public/common/file_chooser_params.h b/content/public/common/file_chooser_params.h
index 7807cbd..acc7fad 100644
--- a/content/public/common/file_chooser_params.h
+++ b/content/public/common/file_chooser_params.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.
@@ -43,8 +43,8 @@ struct CONTENT_EXPORT FileChooserParams {
// Default file name to select in the dialog.
FilePath default_file_name;
- // A list of valid lower-cased MIME types specified in an input element. It is
- // used to restrict selectable files to such types.
+ // A list of valid lower-cased MIME types or file extensions specified in an
+ // input element. It is used to restrict selectable files to such types.
std::vector<string16> accept_types;
};
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index e26b07a..1b4a943 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -1910,9 +1910,9 @@ bool RenderViewImpl::runFileChooser(
ipc_params.title = params.title;
ipc_params.default_file_name =
webkit_glue::WebStringToFilePath(params.initialValue);
- ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
- for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
- ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
+ ipc_params.accept_types.reserve(params.acceptTypes.size());
+ for (size_t i = 0; i < params.acceptTypes.size(); ++i)
+ ipc_params.accept_types.push_back(params.acceptTypes[i]);
return ScheduleFileChooser(ipc_params, chooser_completion);
}
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;
diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc
index 95a97a2..7eedd59 100644
--- a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc
@@ -81,12 +81,12 @@ class FileChooserCompletionImpl : public WebFileChooserCompletion {
PPB_FileChooser_Impl::PPB_FileChooser_Impl(
PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const char* accept_mime_types)
+ const char* accept_types)
: Resource(::ppapi::OBJECT_IS_IMPL, instance),
mode_(mode),
next_chosen_file_index_(0) {
- if (accept_mime_types)
- accept_mime_types_ = std::string(accept_mime_types);
+ if (accept_types)
+ accept_types_ = std::string(accept_types);
}
PPB_FileChooser_Impl::~PPB_FileChooser_Impl() {
@@ -96,12 +96,12 @@ PPB_FileChooser_Impl::~PPB_FileChooser_Impl() {
PP_Resource PPB_FileChooser_Impl::Create(
PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const char* accept_mime_types) {
+ const char* accept_types) {
if (mode != PP_FILECHOOSERMODE_OPEN &&
mode != PP_FILECHOOSERMODE_OPENMULTIPLE)
return 0;
return (new PPB_FileChooser_Impl(instance, mode,
- accept_mime_types))->GetReference();
+ accept_types))->GetReference();
}
PPB_FileChooser_Impl* PPB_FileChooser_Impl::AsPPB_FileChooser_Impl() {
@@ -225,7 +225,7 @@ int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5(
} else {
params.multiSelect = (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE);
}
- params.acceptMIMETypes = ParseAcceptValue(accept_mime_types_);
+ params.acceptTypes = ParseAcceptValue(accept_types_);
params.directory = false;
PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
@@ -248,25 +248,29 @@ PP_Resource PPB_FileChooser_Impl::GetNextChosenFile() {
}
std::vector<WebString> PPB_FileChooser_Impl::ParseAcceptValue(
- const std::string& accept_mime_types) {
- if (accept_mime_types.empty())
+ const std::string& accept_types) {
+ if (accept_types.empty())
return std::vector<WebString>();
- std::vector<std::string> mime_type_list;
- base::SplitString(accept_mime_types, ',', &mime_type_list);
- std::vector<WebString> normalized_mime_type_list;
- normalized_mime_type_list.reserve(mime_type_list.size());
- for (size_t i = 0; i < mime_type_list.size(); ++i) {
- std::string mime_type = mime_type_list[i];
- TrimWhitespaceASCII(mime_type, TRIM_ALL, &mime_type);
- if (mime_type.empty())
+ std::vector<std::string> type_list;
+ base::SplitString(accept_types, ',', &type_list);
+ std::vector<WebString> normalized_type_list;
+ normalized_type_list.reserve(type_list.size());
+ for (size_t i = 0; i < type_list.size(); ++i) {
+ std::string type = type_list[i];
+ TrimWhitespaceASCII(type, TRIM_ALL, &type);
+
+ // If the type is a single character, it definitely cannot be valid. In the
+ // case of a file extension it would be a single ".". In the case of a MIME
+ // type it would just be a "/".
+ if (type.length() < 2)
continue;
- if (mime_type.find_first_of('/') == std::string::npos)
+ if (type.find_first_of('/') == std::string::npos && type[0] != '.')
continue;
- StringToLowerASCII(&mime_type);
- normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(),
- mime_type.size()));
+ StringToLowerASCII(&type);
+ normalized_type_list.push_back(WebString::fromUTF8(type.data(),
+ type.size()));
}
- return normalized_mime_type_list;
+ return normalized_type_list;
}
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.h b/webkit/plugins/ppapi/ppb_file_chooser_impl.h
index d5afc2d..dc34509 100644
--- a/webkit/plugins/ppapi/ppb_file_chooser_impl.h
+++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.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,12 +36,12 @@ class PPB_FileChooser_Impl : public ::ppapi::Resource,
public:
PPB_FileChooser_Impl(PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const char* accept_mime_types);
+ const char* accept_types);
virtual ~PPB_FileChooser_Impl();
static PP_Resource Create(PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const char* accept_mime_types);
+ const char* accept_types);
// Resource overrides.
virtual PPB_FileChooser_Impl* AsPPB_FileChooser_Impl();
@@ -78,15 +78,15 @@ class PPB_FileChooser_Impl : public ::ppapi::Resource,
PP_Var suggested_file_name,
const PP_CompletionCallback& callback) OVERRIDE;
- // Splits a comma-separated MIME type list |accept_mime_types|, trims the
+ // Splits a comma-separated MIME type/extension list |accept_types|, trims the
// resultant split types, makes them lowercase, and returns them.
// Though this should be private, this is public for testing.
WEBKIT_PLUGINS_EXPORT static std::vector<WebKit::WebString> ParseAcceptValue(
- const std::string& accept_mime_types);
+ const std::string& accept_types);
private:
PP_FileChooserMode_Dev mode_;
- std::string accept_mime_types_;
+ std::string accept_types_;
scoped_refptr< ::ppapi::TrackedCallback> callback_;
// When using the v0.6 of the API, this will contain the output for the
diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc
index 077e247..e14030f 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.cc
+++ b/webkit/plugins/ppapi/resource_creation_impl.cc
@@ -119,8 +119,8 @@ PP_Resource ResourceCreationImpl::CreateDirectoryReader(
PP_Resource ResourceCreationImpl::CreateFileChooser(
PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const char* accept_mime_types) {
- return PPB_FileChooser_Impl::Create(instance, mode, accept_mime_types);
+ const char* accept_types) {
+ return PPB_FileChooser_Impl::Create(instance, mode, accept_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 ca8bb54..84f9b2e 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.h
+++ b/webkit/plugins/ppapi/resource_creation_impl.h
@@ -44,7 +44,7 @@ class ResourceCreationImpl : public ::ppapi::thunk::ResourceCreationAPI {
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 CreateFileIO(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateFileRef(PP_Resource file_system,
const char* path) OVERRIDE;