15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h" // gfx::NativeWindow 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/shell_dialogs/select_file_dialog.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ExtensionDialog; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderViewHost; 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WebContents; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct SelectedFileInfo; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SelectFilePolicy; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Shows a dialog box for selecting a file or a folder, using the 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// file manager extension implementation. 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SelectFileDialogExtension 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : public ui::SelectFileDialog, 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public ExtensionDialogObserver { 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Opaque ID type for identifying the tab spawned each dialog, unique for 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // every WebContents. 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) typedef const void* RoutingID; 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) static RoutingID GetRoutingIDFromWebContents( 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const content::WebContents* web_contents); 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static SelectFileDialogExtension* Create( 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SelectFileDialog::Listener* listener, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SelectFilePolicy* policy); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // BaseShellDialog implementation. 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsRunning(gfx::NativeWindow owner_window) const OVERRIDE; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ListenerDestroyed() OVERRIDE; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ExtensionDialog::Observer implementation. 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ExtensionDialogClosing(ExtensionDialog* dialog) OVERRIDE; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ExtensionTerminated(ExtensionDialog* dialog) OVERRIDE; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Routes callback to appropriate SelectFileDialog::Listener based on the 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // owning |web_contents|. 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) static void OnFileSelected(RoutingID routing_id, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ui::SelectedFileInfo& file, 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int index); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void OnMultiFilesSelected( 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RoutingID routing_id, 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::vector<ui::SelectedFileInfo>& files); 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) static void OnFileSelectionCanceled(RoutingID routing_id); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For testing, so we can inject JavaScript into the contained view. 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::RenderViewHost* GetRenderViewHost(); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SelectFileDialog implementation. 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SelectFileImpl( 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Type type, 70a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& title, 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& default_path, 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const FileTypeInfo* file_types, 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int file_type_index, 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath::StringType& default_extension, 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::NativeWindow owning_window, 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void* params) OVERRIDE; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class SelectFileDialogExtensionBrowserTest; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class SelectFileDialogExtensionTest; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Object is ref-counted, use Create(). 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit SelectFileDialogExtension(SelectFileDialog::Listener* listener, 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SelectFilePolicy* policy); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~SelectFileDialogExtension(); 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invokes the appropriate file selection callback on our listener. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyListener(); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds this to the list of pending dialogs, used for testing. 911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void AddPending(RoutingID routing_id); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Check if the list of pending dialogs contains dialog for |routing_id|. 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) static bool PendingExists(RoutingID routing_id); 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the dialog has multiple file type choices. 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE; 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool has_multiple_file_type_choices_; 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Host for the extension that implements this dialog. 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<ExtensionDialog> extension_dialog_; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ID of the tab that spawned this dialog, used to route callbacks. 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RoutingID routing_id_; 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Pointer to the profile the dialog is running in. 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile_; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The window that created the dialog. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeWindow owner_window_; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We defer the callback into SelectFileDialog::Listener until the window 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // closes, to match the semantics of file selection on Windows and Mac. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These are the data passed to the listener. 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum SelectionType { 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CANCEL = 0, 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SINGLE_FILE, 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MULTIPLE_FILES 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SelectionType selection_type_; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<ui::SelectedFileInfo> selection_files_; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int selection_index_; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void* params_; 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SelectFileDialogExtension); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_UI_VIEWS_SELECT_FILE_DIALOG_EXTENSION_H_ 130