blob: ba8441b638c7343033a3c448903181b48a17640f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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_
|