Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / win8 / metro_driver / file_picker_ash.h
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #ifndef CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_
5 #define CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_
6
7 #include <vector>
8
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "base/strings/string16.h"
13
14 class ChromeAppViewAsh;
15 struct MetroViewerHostMsg_SaveAsDialogParams;
16
17 namespace base {
18 class FilePath;
19 }
20
21 // Base class for the file pickers.
22 class FilePickerSessionBase {
23  public:
24   // Creates a file picker for open_file_name.
25   explicit FilePickerSessionBase(ChromeAppViewAsh* app_view,
26                                  const base::string16& title,
27                                  const base::string16& filter,
28                                  const base::FilePath& default_path);
29
30   virtual ~FilePickerSessionBase() {
31   }
32
33   // Runs the picker, returns true on success.
34   bool Run();
35
36   const base::string16& result() const {
37     return result_;
38   }
39
40   bool success() const {
41     return success_;
42   }
43
44  protected:
45   // Creates, configures and starts a file picker.
46   // If the HRESULT returned is a failure code the file picker has not started,
47   // so no callbacks should be expected.
48   virtual HRESULT StartFilePicker() = 0;
49
50   // True iff a file picker has successfully finished.
51   bool success_;
52
53   // The title of the file picker.
54   base::string16 title_;
55
56   // The file type filter.
57   base::string16 filter_;
58
59   // The starting directory/file name.
60   base::FilePath default_path_;
61
62   // Pointer to the ChromeAppViewAsh instance. We notify the ChromeAppViewAsh
63   // instance when the file open/save operations complete.
64   ChromeAppViewAsh* app_view_;
65
66   base::string16 result_;
67
68  private:
69   // Initiate a file picker, must be called on the main metro thread.
70   // Returns true on success.
71   bool DoFilePicker();
72
73   DISALLOW_COPY_AND_ASSIGN(FilePickerSessionBase);
74 };
75
76 // Provides functionality to display the open file/multiple open file pickers
77 // metro dialog.
78 class OpenFilePickerSession : public FilePickerSessionBase {
79  public:
80   explicit OpenFilePickerSession(ChromeAppViewAsh* app_view,
81                                  const base::string16& title,
82                                  const base::string16& filter,
83                                  const base::FilePath& default_path,
84                                  bool allow_multi_select);
85
86   const std::vector<base::FilePath>& filenames() const {
87     return filenames_;
88   }
89
90   const bool allow_multi_select() const {
91     return allow_multi_select_;
92   }
93
94  private:
95   virtual HRESULT StartFilePicker() override;
96
97   typedef winfoundtn::IAsyncOperation<winstorage::StorageFile*>
98       SingleFileAsyncOp;
99   typedef winfoundtn::Collections::IVectorView<
100       winstorage::StorageFile*> StorageFileVectorCollection;
101   typedef winfoundtn::IAsyncOperation<StorageFileVectorCollection*>
102       MultiFileAsyncOp;
103
104   // Called asynchronously when a single file picker is done.
105   HRESULT SinglePickerDone(SingleFileAsyncOp* async, AsyncStatus status);
106
107   // Called asynchronously when a multi file picker is done.
108   HRESULT MultiPickerDone(MultiFileAsyncOp* async, AsyncStatus status);
109
110   // Composes a multi-file result string suitable for returning to a
111   // from a storage file collection.
112   static HRESULT ComposeMultiFileResult(StorageFileVectorCollection* files,
113                                         base::string16* result);
114
115  private:
116   // True if the multi file picker is to be displayed.
117   bool allow_multi_select_;
118   // If multi select is true then this member contains the list of filenames
119   // to be returned back.
120   std::vector<base::FilePath> filenames_;
121
122   DISALLOW_COPY_AND_ASSIGN(OpenFilePickerSession);
123 };
124
125 // Provides functionality to display the save file picker.
126 class SaveFilePickerSession : public FilePickerSessionBase {
127  public:
128   explicit SaveFilePickerSession(
129       ChromeAppViewAsh* app_view,
130       const MetroViewerHostMsg_SaveAsDialogParams& params);
131
132   int SaveFilePickerSession::filter_index() const;
133
134  private:
135   virtual HRESULT StartFilePicker() override;
136
137   typedef winfoundtn::IAsyncOperation<winstorage::StorageFile*>
138       SaveFileAsyncOp;
139
140   // Called asynchronously when the save file picker is done.
141   HRESULT FilePickerDone(SaveFileAsyncOp* async, AsyncStatus status);
142
143   int filter_index_;
144
145   DISALLOW_COPY_AND_ASSIGN(SaveFilePickerSession);
146 };
147
148 // Provides functionality to display the folder picker.
149 class FolderPickerSession : public FilePickerSessionBase {
150  public:
151   explicit FolderPickerSession(ChromeAppViewAsh* app_view,
152                                const base::string16& title);
153
154  private:
155   virtual HRESULT StartFilePicker() override;
156
157   typedef winfoundtn::IAsyncOperation<winstorage::StorageFolder*>
158       FolderPickerAsyncOp;
159
160   // Called asynchronously when the folder picker is done.
161   HRESULT FolderPickerDone(FolderPickerAsyncOp* async, AsyncStatus status);
162
163   DISALLOW_COPY_AND_ASSIGN(FolderPickerSession);
164 };
165
166 #endif  // CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_
167