OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_VIEWS_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_VIEWS_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/browser/ui/select_file_dialog.h" |
| 13 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" |
| 14 #include "ui/gfx/native_widget_types.h" // gfx::NativeWindow |
| 15 |
| 16 class ExtensionDialog; |
| 17 class Profile; |
| 18 |
| 19 namespace content { |
| 20 class RenderViewHost; |
| 21 } |
| 22 |
| 23 namespace ui { |
| 24 struct SelectedFileInfo; |
| 25 class SelectFilePolicy; |
| 26 } |
| 27 |
| 28 // Shows a dialog box for selecting a file or a folder, using the |
| 29 // file manager extension implementation. |
| 30 class SelectFileDialogExtensionViews : public SelectFileDialog, |
| 31 public ExtensionDialogObserver { |
| 32 public: |
| 33 static SelectFileDialogExtensionViews* Create( |
| 34 SelectFileDialog::Listener* listener, |
| 35 ui::SelectFilePolicy* policy); |
| 36 |
| 37 // To implement the cross-platform API. |
| 38 static void OnFileSelected(int32 tab_id, |
| 39 const ui::SelectedFileInfo& file, |
| 40 int index); |
| 41 static void OnMultiFilesSelected( |
| 42 int32 tab_id, |
| 43 const std::vector<ui::SelectedFileInfo>& files); |
| 44 static void OnFileSelectionCanceled(int32 tab_id); |
| 45 |
| 46 // Overridden from ui::BaseShellDialog: |
| 47 virtual bool IsRunning(gfx::NativeWindow owner_window) const OVERRIDE; |
| 48 virtual void ListenerDestroyed() OVERRIDE; |
| 49 |
| 50 // Overridden from ExtensionDialogObserver: |
| 51 virtual void ExtensionDialogClosing(ExtensionDialog* dialog) OVERRIDE; |
| 52 virtual void ExtensionTerminated(ExtensionDialog* dialog) OVERRIDE; |
| 53 |
| 54 // For testing, so we can inject JavaScript into the contained view. |
| 55 content::RenderViewHost* GetRenderViewHost(); |
| 56 |
| 57 protected: |
| 58 // Overriddden from SelectFileDialog: |
| 59 virtual void SelectFileImpl(Type type, |
| 60 const string16& title, |
| 61 const FilePath& default_path, |
| 62 const FileTypeInfo* file_types, |
| 63 int file_type_index, |
| 64 const FilePath::StringType& default_extension, |
| 65 gfx::NativeWindow owning_window, |
| 66 void* params) OVERRIDE; |
| 67 |
| 68 |
| 69 private: |
| 70 friend class SelectFileDialogExtensionBrowserTest; |
| 71 friend class SelectFileDialogExtensionTest; |
| 72 |
| 73 // Object is ref-counted, use Create(). |
| 74 explicit SelectFileDialogExtensionViews(SelectFileDialog::Listener* listener, |
| 75 ui::SelectFilePolicy* policy); |
| 76 virtual ~SelectFileDialogExtensionViews(); |
| 77 |
| 78 // Invokes the appropriate file selection callback on our listener. |
| 79 void NotifyListener(); |
| 80 |
| 81 // Adds this to the list of pending dialogs, used for testing. |
| 82 void AddPending(int32 tab_id); |
| 83 |
| 84 // Check if the list of pending dialogs contains dialog for |tab_id|. |
| 85 static bool PendingExists(int32 tab_id); |
| 86 |
| 87 // Returns true if the dialog has multiple file type choices. |
| 88 virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE; |
| 89 |
| 90 bool has_multiple_file_type_choices_; |
| 91 |
| 92 // Host for the extension that implements this dialog. |
| 93 scoped_refptr<ExtensionDialog> extension_dialog_; |
| 94 |
| 95 // ID of the tab that spawned this dialog, used to route callbacks. |
| 96 int32 tab_id_; |
| 97 |
| 98 // Pointer to the profile the dialog is running in. |
| 99 Profile* profile_; |
| 100 |
| 101 // The window that created the dialog. |
| 102 gfx::NativeWindow owner_window_; |
| 103 |
| 104 // We defer the callback into SelectFileDialog::Listener until the window |
| 105 // closes, to match the semantics of file selection on Windows and Mac. |
| 106 // These are the data passed to the listener. |
| 107 enum SelectionType { |
| 108 CANCEL = 0, |
| 109 SINGLE_FILE, |
| 110 MULTIPLE_FILES |
| 111 }; |
| 112 SelectionType selection_type_; |
| 113 std::vector<ui::SelectedFileInfo> selection_files_; |
| 114 int selection_index_; |
| 115 void* params_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(SelectFileDialogExtensionViews); |
| 118 }; |
| 119 |
| 120 #endif // CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_VIEWS_H_ |
OLD | NEW |