summaryrefslogtreecommitdiffstats
path: root/chrome/browser/file_select_helper.h
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-10 16:54:49 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-10 16:54:49 +0000
commitba70d082593f9e20ab059b7f09495d94c0856005 (patch)
treee56ce8065866ebde7de1ad8137b2fe2ccc7cf8c2 /chrome/browser/file_select_helper.h
parentba62fbd428232eee1815d4b4d63fc65cb3ead566 (diff)
downloadchromium_src-ba70d082593f9e20ab059b7f09495d94c0856005.zip
chromium_src-ba70d082593f9e20ab059b7f09495d94c0856005.tar.gz
chromium_src-ba70d082593f9e20ab059b7f09495d94c0856005.tar.bz2
Input file type now supported in extension popups.
To do this, this CL generalize the TabContentsFileSelectHelper (renamed FileSelectHelper) so it is associated with a RenderViewHost rather than a TabContents. This allows the extension popups which don't use a TabContents to use it. As part of that, I also moved GetTopLevelNativeWindow() from TabContentsView to TabContent, as it can be implemented in a non-platform specific way. BUG=28829 TEST=Make sure you can still open file on web pages (such as http://www.cs.tut.fi/~jkorpela/forms/file.html. Create an extension with a popup that contains an input file tag. Make sure it does open a file dialog and lets you choose a file. Review URL: http://codereview.chromium.org/3209002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59105 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/file_select_helper.h')
-rw-r--r--chrome/browser/file_select_helper.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/chrome/browser/file_select_helper.h b/chrome/browser/file_select_helper.h
new file mode 100644
index 0000000..ba8441b
--- /dev/null
+++ b/chrome/browser/file_select_helper.h
@@ -0,0 +1,85 @@
+// Copyright (c) 2010 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.
+
+#ifndef CHROME_BROWSER_FILE_SELECT_HELPER_H_
+#define CHROME_BROWSER_FILE_SELECT_HELPER_H_
+#pragma once
+
+#include <vector>
+
+#include "chrome/browser/shell_dialogs.h"
+#include "chrome/browser/renderer_host/render_view_host_delegate.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
+#include "net/base/directory_lister.h"
+
+class Profile;
+class RenderViewHost;
+struct ViewHostMsg_RunFileChooser_Params;
+
+class FileSelectHelper
+ : public SelectFileDialog::Listener,
+ public net::DirectoryLister::DirectoryListerDelegate,
+ public RenderViewHostDelegate::FileSelect,
+ public NotificationObserver {
+ public:
+ explicit FileSelectHelper(Profile* profile);
+ ~FileSelectHelper();
+
+ // SelectFileDialog::Listener
+ virtual void FileSelected(const FilePath& path, int index, void* params);
+ virtual void MultiFilesSelected(const std::vector<FilePath>& files,
+ void* params);
+ virtual void FileSelectionCanceled(void* params);
+
+ // net::DirectoryLister::DirectoryListerDelegate
+ virtual void OnListFile(
+ const net::DirectoryLister::DirectoryListerData& data);
+ virtual void OnListDone(int error);
+
+ // RenderViewHostDelegate::FileSelect
+ virtual void RunFileChooser(RenderViewHost* render_view_host,
+ const ViewHostMsg_RunFileChooser_Params& params);
+
+ private:
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ // Helper method for handling the SelectFileDialog::Listener callbacks.
+ void DirectorySelected(const FilePath& path);
+
+ // 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
+ SelectFileDialog::FileTypeInfo* GetFileTypesFromAcceptType(
+ const string16& accept_types);
+
+ // Profile used to set/retrieve the last used directory.
+ Profile* profile_;
+
+ // The RenderViewHost for the page we are associated with.
+ RenderViewHost* render_view_host_;
+
+ // Dialog box used for choosing files to upload from file form fields.
+ scoped_refptr<SelectFileDialog> select_file_dialog_;
+
+ // The type of file dialog last shown.
+ SelectFileDialog::Type dialog_type_;
+
+ // The current directory lister (runs on a separate thread).
+ scoped_refptr<net::DirectoryLister> directory_lister_;
+
+ // The current directory lister results, which may update incrementally
+ // as the listing proceeds.
+ std::vector<FilePath> directory_lister_results_;
+
+ // Registrar for notifications regarding our RenderViewHost.
+ NotificationRegistrar notification_registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileSelectHelper);
+};
+
+#endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_