| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // File contains the fileBrowserHandlerInternal.selectFile extension function. | 5 // File contains the fileBrowserHandlerInternal.selectFile extension function. |
| 6 // The function prompts user to select a file path to be used by the caller. It | 6 // The function prompts user to select a file path to be used by the caller. It |
| 7 // will fail if it isn't invoked by a user gesture (e.g. a mouse click or a | 7 // will fail if it isn't invoked by a user gesture (e.g. a mouse click or a |
| 8 // keyboard key press). | 8 // keyboard key press). |
| 9 // Note that the target file is never actually created by this function, even | 9 // Note that the target file is never actually created by this function, even |
| 10 // if the selected path doesn't exist. | 10 // if the selected path doesn't exist. |
| 11 | 11 |
| 12 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_API_H_ | 12 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_API_H_ |
| 13 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_API_H_ | 13 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_API_H_ |
| 14 | 14 |
| 15 #include <string> | 15 #include <string> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/file_path.h" | 18 #include "base/file_path.h" |
| 19 #include "chrome/browser/extensions/extension_function.h" | 19 #include "chrome/browser/extensions/extension_function.h" |
| 20 | 20 |
| 21 class Browser; | 21 class Browser; |
| 22 class FileHandlerSelectFileFunction; | 22 class FileBrowserHandlerInternalSelectFileFunction; |
| 23 | 23 |
| 24 namespace file_handler { | 24 namespace file_handler { |
| 25 | 25 |
| 26 // Interface that is used by FileHandlerSelectFileFunction to select the file | 26 // Interface that is used by FileBrowserHandlerInternalSelectFileFunction to |
| 27 // path that should be reported back to the extension function caller. | 27 // select the file path that should be reported back to the extension function |
| 28 // Nobody will take the ownership of the interface implementation, so it should | 28 // caller. Nobody will take the ownership of the interface implementation, so |
| 29 // delete itself once it's done. | 29 // it should delete itself once it's done. |
| 30 class FileSelector { | 30 class FileSelector { |
| 31 public: | 31 public: |
| 32 virtual ~FileSelector() {} | 32 virtual ~FileSelector() {} |
| 33 | 33 |
| 34 // Starts the file selection. It should prompt user to select a file path. | 34 // Starts the file selection. It should prompt user to select a file path. |
| 35 // Once the selection is made it should asynchronously call | 35 // Once the selection is made it should asynchronously call |
| 36 // |function_->OnFilePathSelected| with the selection information. | 36 // |function_->OnFilePathSelected| with the selection information. |
| 37 // User should be initially suggested to select file named |suggested_name|. | 37 // User should be initially suggested to select file named |suggested_name|. |
| 38 // |allowed_extensions| specifies the file extensions allowed to be shown, | 38 // |allowed_extensions| specifies the file extensions allowed to be shown, |
| 39 // and selected. Extensions should not include '.'. This spec comes from | 39 // and selected. Extensions should not include '.'. This spec comes from |
| 40 // ui::SelectFileDialog() which takes extensions without '.'. | 40 // ui::SelectFileDialog() which takes extensions without '.'. |
| 41 // | 41 // |
| 42 // Selection UI should be displayed using |browser|. |browser| should outlive | 42 // Selection UI should be displayed using |browser|. |browser| should outlive |
| 43 // the interface implementation. | 43 // the interface implementation. |
| 44 // |function| if the extension function that called the method and needs to | 44 // |function| if the extension function that called the method and needs to |
| 45 // be notified of user action. The interface implementation should keep a | 45 // be notified of user action. The interface implementation should keep a |
| 46 // reference to the function until it is notified (extension function | 46 // reference to the function until it is notified (extension function |
| 47 // implementations are ref counted). | 47 // implementations are ref counted). |
| 48 // |SelectFile| will be called at most once by a single extension function. | 48 // |SelectFile| will be called at most once by a single extension function. |
| 49 // The interface implementation should delete itself after the extension | 49 // The interface implementation should delete itself after the extension |
| 50 // function is notified of file selection result. | 50 // function is notified of file selection result. |
| 51 virtual void SelectFile(const FilePath& suggested_name, | 51 virtual void SelectFile( |
| 52 const std::vector<std::string>& allowed_extensions, | 52 const FilePath& suggested_name, |
| 53 Browser* browser, | 53 const std::vector<std::string>& allowed_extensions, |
| 54 FileHandlerSelectFileFunction* function) = 0; | 54 Browser* browser, |
| 55 FileBrowserHandlerInternalSelectFileFunction* function) = 0; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 // Interface that is used by FileHandlerSelectFileFunction to create a | 58 // Interface that is used by FileBrowserHandlerInternalSelectFileFunction to |
| 58 // FileSelector it can use to select a file path. | 59 // create a FileSelector it can use to select a file path. |
| 59 class FileSelectorFactory { | 60 class FileSelectorFactory { |
| 60 public: | 61 public: |
| 61 virtual ~FileSelectorFactory() {} | 62 virtual ~FileSelectorFactory() {} |
| 62 | 63 |
| 63 // Creates a FileSelector instance for the FileHandlerSelectFileFunction. | 64 // Creates a FileSelector instance for the |
| 65 // FileBrowserHandlerInternalSelectFileFunction. |
| 64 virtual FileSelector* CreateFileSelector() const = 0; | 66 virtual FileSelector* CreateFileSelector() const = 0; |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 } // namespace file_handler | 69 } // namespace file_handler |
| 68 | 70 |
| 69 // The fileBrowserHandlerInternal.selectFile extension function implementation. | 71 // The fileBrowserHandlerInternal.selectFile extension function implementation. |
| 70 // See the file description for more info. | 72 // See the file description for more info. |
| 71 class FileHandlerSelectFileFunction : public AsyncExtensionFunction { | 73 class FileBrowserHandlerInternalSelectFileFunction |
| 74 : public AsyncExtensionFunction { |
| 72 public: | 75 public: |
| 73 // Default constructor used in production code. | 76 // Default constructor used in production code. |
| 74 // It will create its own FileSelectorFactory implementation, and set the | 77 // It will create its own FileSelectorFactory implementation, and set the |
| 75 // value of |user_gesture_check_enabled| to true. | 78 // value of |user_gesture_check_enabled| to true. |
| 76 FileHandlerSelectFileFunction(); | 79 FileBrowserHandlerInternalSelectFileFunction(); |
| 77 | 80 |
| 78 // This constructor should be used only in tests to inject test file selector | 81 // This constructor should be used only in tests to inject test file selector |
| 79 // factory and to allow extension function to run even if it hasn't been | 82 // factory and to allow extension function to run even if it hasn't been |
| 80 // invoked by user gesture. | 83 // invoked by user gesture. |
| 81 // Created object will take the ownership of the |file_selector_factory|. | 84 // Created object will take the ownership of the |file_selector_factory|. |
| 82 FileHandlerSelectFileFunction( | 85 FileBrowserHandlerInternalSelectFileFunction( |
| 83 file_handler::FileSelectorFactory* file_selector_factory, | 86 file_handler::FileSelectorFactory* file_selector_factory, |
| 84 bool enable_user_gesture_check); | 87 bool enable_user_gesture_check); |
| 85 | 88 |
| 86 // Called by FileSelector implementation when the user selects the file's | 89 // Called by FileSelector implementation when the user selects the file's |
| 87 // file path. File access permissions for the selected file are granted and | 90 // file path. File access permissions for the selected file are granted and |
| 88 // caller is notified of the selection result after this method is called. | 91 // caller is notified of the selection result after this method is called. |
| 89 // |success| Whether the path was selected. | 92 // |success| Whether the path was selected. |
| 90 // |full_path| The selected file path if one was selected. It is ignored if | 93 // |full_path| The selected file path if one was selected. It is ignored if |
| 91 // the selection did not succeed. | 94 // the selection did not succeed. |
| 92 void OnFilePathSelected(bool success, const FilePath& full_path); | 95 void OnFilePathSelected(bool success, const FilePath& full_path); |
| 93 | 96 |
| 94 protected: | 97 protected: |
| 95 // The class is ref counted, so destructor should not be public. | 98 // The class is ref counted, so destructor should not be public. |
| 96 virtual ~FileHandlerSelectFileFunction() OVERRIDE; | 99 virtual ~FileBrowserHandlerInternalSelectFileFunction(); |
| 97 | 100 |
| 98 // AsyncExtensionFunction implementation. | 101 // AsyncExtensionFunction implementation. |
| 99 // Runs the extension function implementation. | 102 // Runs the extension function implementation. |
| 100 virtual bool RunImpl() OVERRIDE; | 103 virtual bool RunImpl() OVERRIDE; |
| 101 | 104 |
| 102 private: | 105 private: |
| 103 // Called when the external file system is opened for the extension function | 106 // Called when the external file system is opened for the extension function |
| 104 // caller in the browser context. It saves opened file system's parameters. | 107 // caller in the browser context. It saves opened file system's parameters. |
| 105 // The file system is needed to create FileEntry object for the selection | 108 // The file system is needed to create FileEntry object for the selection |
| 106 // result. | 109 // result. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 GURL file_system_root_; | 155 GURL file_system_root_; |
| 153 | 156 |
| 154 // List of permissions and paths that have to be granted for the selected | 157 // List of permissions and paths that have to be granted for the selected |
| 155 // files. | 158 // files. |
| 156 std::vector<std::pair<FilePath, int> > permissions_to_grant_; | 159 std::vector<std::pair<FilePath, int> > permissions_to_grant_; |
| 157 | 160 |
| 158 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserHandlerInternal.selectFile"); | 161 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserHandlerInternal.selectFile"); |
| 159 }; | 162 }; |
| 160 | 163 |
| 161 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_API_H_ | 164 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_API_H_ |
| OLD | NEW |