OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "chrome/browser/ui/select_file_dialog.h" | 13 #include "chrome/browser/ui/select_file_dialog.h" |
14 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" | 14 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" |
15 #include "ui/gfx/native_widget_types.h" // gfx::NativeWindow | 15 #include "ui/gfx/native_widget_types.h" // gfx::NativeWindow |
16 | 16 |
17 class ExtensionDialog; | 17 class ExtensionDialog; |
18 class RenderViewHost; | 18 class RenderViewHost; |
19 | 19 |
20 // Shows a dialog box for selecting a file or a folder, using the | 20 // Shows a dialog box for selecting a file or a folder, using the |
21 // file manager extension implementation. | 21 // file manager extension implementation. |
22 class SelectFileDialogExtension | 22 class SelectFileDialogExtension |
23 : public SelectFileDialog, | 23 : public SelectFileDialog, |
24 public ExtensionDialogObserver { | 24 public ExtensionDialogObserver { |
25 public: | 25 public: |
26 static SelectFileDialogExtension* Create( | 26 static SelectFileDialogExtension* Create( |
27 SelectFileDialog::Listener* listener); | 27 SelectFileDialog::Listener* listener); |
28 | 28 |
29 // BaseShellDialog implementation. | 29 // BaseShellDialog implementation. |
30 virtual bool IsRunning(gfx::NativeWindow owner_window) const OVERRIDE; | 30 virtual bool IsRunning(gfx::NativeWindow owner_window) const OVERRIDE; |
31 virtual void ListenerDestroyed() OVERRIDE; | 31 virtual void ListenerDestroyed() OVERRIDE; |
32 | 32 |
33 // ExtensionDialog::Observer implementation. | 33 // ExtensionDialog::Observer implementation. |
34 virtual void ExtensionDialogIsClosing(ExtensionDialog* dialog) OVERRIDE; | 34 virtual void ExtensionDialogClosing(ExtensionDialog* dialog) OVERRIDE; |
35 | 35 |
36 // Routes callback to appropriate SelectFileDialog::Listener based on | 36 // Routes callback to appropriate SelectFileDialog::Listener based on |
37 // the owning |tab_id|, then closes the dialog. | 37 // the owning |tab_id|. |
38 static void OnFileSelected(int32 tab_id, const FilePath& path, int index); | 38 static void OnFileSelected(int32 tab_id, const FilePath& path, int index); |
39 static void OnMultiFilesSelected(int32 tab_id, | 39 static void OnMultiFilesSelected(int32 tab_id, |
40 const std::vector<FilePath>& files); | 40 const std::vector<FilePath>& files); |
41 static void OnFileSelectionCanceled(int32 tab_id); | 41 static void OnFileSelectionCanceled(int32 tab_id); |
42 | 42 |
43 // For testing, so we can inject JavaScript into the contained view. | 43 // For testing, so we can inject JavaScript into the contained view. |
44 RenderViewHost* GetRenderViewHost(); | 44 RenderViewHost* GetRenderViewHost(); |
45 | 45 |
46 protected: | 46 protected: |
47 // SelectFileDialog implementation. | 47 // SelectFileDialog implementation. |
48 virtual void SelectFileImpl(Type type, | 48 virtual void SelectFileImpl(Type type, |
49 const string16& title, | 49 const string16& title, |
50 const FilePath& default_path, | 50 const FilePath& default_path, |
51 const FileTypeInfo* file_types, | 51 const FileTypeInfo* file_types, |
52 int file_type_index, | 52 int file_type_index, |
53 const FilePath::StringType& default_extension, | 53 const FilePath::StringType& default_extension, |
54 gfx::NativeWindow owning_window, | 54 gfx::NativeWindow owning_window, |
55 void* params) OVERRIDE; | 55 void* params) OVERRIDE; |
56 | 56 |
57 | 57 |
58 private: | 58 private: |
59 friend class SelectFileDialogExtensionBrowserTest; | 59 friend class SelectFileDialogExtensionBrowserTest; |
60 friend class SelectFileDialogExtensionTest; | 60 friend class SelectFileDialogExtensionTest; |
61 | 61 |
62 // Object is ref-counted, use Create(). | 62 // Object is ref-counted, use Create(). |
63 explicit SelectFileDialogExtension(SelectFileDialog::Listener* listener); | 63 explicit SelectFileDialogExtension(SelectFileDialog::Listener* listener); |
64 virtual ~SelectFileDialogExtension(); | 64 virtual ~SelectFileDialogExtension(); |
65 | 65 |
66 // Closes the dialog and cleans up callbacks and listeners. | 66 // Invokes the appropriate file selection callback on our listener. |
67 void Close(); | 67 void NotifyListener(); |
68 | |
69 // Posts a task to close the dialog. | |
70 void PostTaskToClose(); | |
71 | 68 |
72 // Adds this to the list of pending dialogs, used for testing. | 69 // Adds this to the list of pending dialogs, used for testing. |
73 void AddPending(int32 tab_id); | 70 void AddPending(int32 tab_id); |
74 | 71 |
75 // Check if the list of pending dialogs contains dialog for |tab_id|. | 72 // Check if the list of pending dialogs contains dialog for |tab_id|. |
76 static bool PendingExists(int32 tab_id); | 73 static bool PendingExists(int32 tab_id); |
77 | 74 |
78 // Returns true if the dialog has multiple file type choices. | 75 // Returns true if the dialog has multiple file type choices. |
79 virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE; | 76 virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE; |
80 | 77 |
81 bool has_multiple_file_type_choices_; | 78 bool has_multiple_file_type_choices_; |
82 void* params_; | |
83 | 79 |
84 // Host for the extension that implements this dialog. | 80 // Host for the extension that implements this dialog. |
85 scoped_refptr<ExtensionDialog> extension_dialog_; | 81 scoped_refptr<ExtensionDialog> extension_dialog_; |
86 | 82 |
87 // ID of the tab that spawned this dialog, used to route callbacks. | 83 // ID of the tab that spawned this dialog, used to route callbacks. |
88 int32 tab_id_; | 84 int32 tab_id_; |
89 | 85 |
90 gfx::NativeWindow owner_window_; | 86 gfx::NativeWindow owner_window_; |
91 | 87 |
| 88 // We defer the callback into SelectFileDialog::Listener until the window |
| 89 // closes, to match the semantics of file selection on Windows and Mac. |
| 90 // These are the data passed to the listener. |
| 91 enum SelectionType { |
| 92 CANCEL = 0, |
| 93 SINGLE_FILE, |
| 94 MULTIPLE_FILES |
| 95 }; |
| 96 SelectionType selection_type_; |
| 97 std::vector<FilePath> selection_files_; |
| 98 int selection_index_; |
| 99 void* params_; |
| 100 |
92 DISALLOW_COPY_AND_ASSIGN(SelectFileDialogExtension); | 101 DISALLOW_COPY_AND_ASSIGN(SelectFileDialogExtension); |
93 }; | 102 }; |
94 | 103 |
95 #endif // CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ | 104 #endif // CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ |
OLD | NEW |