Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/file_select_helper.h

Issue 10414085: Modified the pepper file chooser API to support filtering files by extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/file_select_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_FILE_SELECT_HELPER_H_ 5 #ifndef CHROME_BROWSER_FILE_SELECT_HELPER_H_
6 #define CHROME_BROWSER_FILE_SELECT_HELPER_H_ 6 #define CHROME_BROWSER_FILE_SELECT_HELPER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
13 #include "chrome/browser/ui/select_file_dialog.h" 14 #include "chrome/browser/ui/select_file_dialog.h"
14 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
16 #include "net/base/directory_lister.h" 17 #include "net/base/directory_lister.h"
17 18
18 class Profile; 19 class Profile;
19 20
20 namespace content { 21 namespace content {
21 class RenderViewHost; 22 class RenderViewHost;
22 struct FileChooserParams; 23 struct FileChooserParams;
(...skipping 13 matching lines...) Expand all
36 static void RunFileChooser(content::WebContents* tab, 37 static void RunFileChooser(content::WebContents* tab,
37 const content::FileChooserParams& params); 38 const content::FileChooserParams& params);
38 39
39 // Enumerates all the files in directory. 40 // Enumerates all the files in directory.
40 static void EnumerateDirectory(content::WebContents* tab, 41 static void EnumerateDirectory(content::WebContents* tab,
41 int request_id, 42 int request_id,
42 const FilePath& path); 43 const FilePath& path);
43 44
44 private: 45 private:
45 friend class base::RefCountedThreadSafe<FileSelectHelper>; 46 friend class base::RefCountedThreadSafe<FileSelectHelper>;
47 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, IsAcceptTypeValid);
46 explicit FileSelectHelper(Profile* profile); 48 explicit FileSelectHelper(Profile* profile);
47 virtual ~FileSelectHelper(); 49 virtual ~FileSelectHelper();
48 50
49 // Utility class which can listen for directory lister events and relay 51 // Utility class which can listen for directory lister events and relay
50 // them to the main object with the correct tracking id. 52 // them to the main object with the correct tracking id.
51 class DirectoryListerDispatchDelegate 53 class DirectoryListerDispatchDelegate
52 : public net::DirectoryLister::DirectoryListerDelegate { 54 : public net::DirectoryLister::DirectoryListerDelegate {
53 public: 55 public:
54 DirectoryListerDispatchDelegate(FileSelectHelper* parent, int id) 56 DirectoryListerDispatchDelegate(FileSelectHelper* parent, int id)
55 : parent_(parent), 57 : parent_(parent),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 const net::DirectoryLister::DirectoryListerData& data); 118 const net::DirectoryLister::DirectoryListerData& data);
117 virtual void OnListDone(int id, int error); 119 virtual void OnListDone(int id, int error);
118 120
119 // Cleans up and releases this instance. This must be called after the last 121 // Cleans up and releases this instance. This must be called after the last
120 // callback is received from the enumeration code. 122 // callback is received from the enumeration code.
121 void EnumerateDirectoryEnd(); 123 void EnumerateDirectoryEnd();
122 124
123 // Helper method to get allowed extensions for select file dialog from 125 // Helper method to get allowed extensions for select file dialog from
124 // the specified accept types as defined in the spec: 126 // the specified accept types as defined in the spec:
125 // http://whatwg.org/html/number-state.html#attr-input-accept 127 // http://whatwg.org/html/number-state.html#attr-input-accept
126 // |accept_types| contains only valid lowercased MIME types. 128 // |accept_types| contains only valid lowercased MIME types or file extensions
129 // beginning with a period (.).
127 SelectFileDialog::FileTypeInfo* GetFileTypesFromAcceptType( 130 SelectFileDialog::FileTypeInfo* GetFileTypesFromAcceptType(
128 const std::vector<string16>& accept_types); 131 const std::vector<string16>& accept_types);
129 132
133 // Check the accept type is valid. It is expected to be all lower case with
134 // no whitespace.
135 static bool IsAcceptTypeValid(const std::string& accept_type);
136
130 // Profile used to set/retrieve the last used directory. 137 // Profile used to set/retrieve the last used directory.
131 Profile* profile_; 138 Profile* profile_;
132 139
133 // The RenderViewHost and WebContents for the page showing a file dialog 140 // The RenderViewHost and WebContents for the page showing a file dialog
134 // (may only be one such dialog). 141 // (may only be one such dialog).
135 content::RenderViewHost* render_view_host_; 142 content::RenderViewHost* render_view_host_;
136 content::WebContents* web_contents_; 143 content::WebContents* web_contents_;
137 144
138 // Dialog box used for choosing files to upload from file form fields. 145 // Dialog box used for choosing files to upload from file form fields.
139 scoped_refptr<SelectFileDialog> select_file_dialog_; 146 scoped_refptr<SelectFileDialog> select_file_dialog_;
140 scoped_ptr<SelectFileDialog::FileTypeInfo> select_file_types_; 147 scoped_ptr<SelectFileDialog::FileTypeInfo> select_file_types_;
141 148
142 // The type of file dialog last shown. 149 // The type of file dialog last shown.
143 SelectFileDialog::Type dialog_type_; 150 SelectFileDialog::Type dialog_type_;
144 151
145 // Maintain a list of active directory enumerations. These could come from 152 // Maintain a list of active directory enumerations. These could come from
146 // the file select dialog or from drag-and-drop of directories, so there could 153 // the file select dialog or from drag-and-drop of directories, so there could
147 // be more than one going on at a time. 154 // be more than one going on at a time.
148 struct ActiveDirectoryEnumeration; 155 struct ActiveDirectoryEnumeration;
149 std::map<int, ActiveDirectoryEnumeration*> directory_enumerations_; 156 std::map<int, ActiveDirectoryEnumeration*> directory_enumerations_;
150 157
151 // Registrar for notifications regarding our RenderViewHost. 158 // Registrar for notifications regarding our RenderViewHost.
152 content::NotificationRegistrar notification_registrar_; 159 content::NotificationRegistrar notification_registrar_;
153 160
154 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); 161 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper);
155 }; 162 };
156 163
157 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ 164 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/file_select_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698