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 #include "chrome/browser/chromeos/extensions/file_browser_handler_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_handler_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chromeos/extensions/file_handler_util.h" | 14 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
15 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 15 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
16 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/chrome_select_file_policy.h" | 21 #include "chrome/browser/ui/chrome_select_file_policy.h" |
22 #include "chrome/browser/ui/select_file_dialog.h" | |
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
24 #include "chrome/common/extensions/api/file_browser_handler_internal.h" | 23 #include "chrome/common/extensions/api/file_browser_handler_internal.h" |
25 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/child_process_security_policy.h" | 25 #include "content/public/browser/child_process_security_policy.h" |
27 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
29 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
30 #include "webkit/fileapi/file_system_context.h" | 29 #include "webkit/fileapi/file_system_context.h" |
31 #include "webkit/fileapi/file_system_mount_point_provider.h" | 30 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 31 #include "ui/base/dialogs/select_file_dialog.h" |
32 | 32 |
33 using content::BrowserContext; | 33 using content::BrowserContext; |
34 using extensions::api::file_browser_handler_internal::FileEntryInfo; | 34 using extensions::api::file_browser_handler_internal::FileEntryInfo; |
35 using file_handler::FileSelector; | 35 using file_handler::FileSelector; |
36 | 36 |
37 namespace SelectFile = | 37 namespace SelectFile = |
38 extensions::api::file_browser_handler_internal::SelectFile; | 38 extensions::api::file_browser_handler_internal::SelectFile; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 const char kNoUserGestureError[] = | 42 const char kNoUserGestureError[] = |
43 "This method can only be called in response to user gesture, such as a " | 43 "This method can only be called in response to user gesture, such as a " |
44 "mouse click or key press."; | 44 "mouse click or key press."; |
45 | 45 |
46 // File selector implementation. It is bound to SelectFileFunction instance. | 46 // File selector implementation. It is bound to SelectFileFunction instance. |
47 // When |SelectFile| is invoked, it will show save as dialog and listen for user | 47 // When |SelectFile| is invoked, it will show save as dialog and listen for user |
48 // action. When user selects the file (or closes the dialog), the function's | 48 // action. When user selects the file (or closes the dialog), the function's |
49 // |OnFilePathSelected| method will be called with the result. | 49 // |OnFilePathSelected| method will be called with the result. |
50 // When |SelectFile| is called, the class instance takes ownership of itself. | 50 // When |SelectFile| is called, the class instance takes ownership of itself. |
51 class FileSelectorImpl : public FileSelector, | 51 class FileSelectorImpl : public FileSelector, |
52 public SelectFileDialog::Listener { | 52 public ui::SelectFileDialog::Listener { |
53 public: | 53 public: |
54 explicit FileSelectorImpl(FileHandlerSelectFileFunction* function); | 54 explicit FileSelectorImpl(FileHandlerSelectFileFunction* function); |
55 virtual ~FileSelectorImpl() OVERRIDE; | 55 virtual ~FileSelectorImpl() OVERRIDE; |
56 | 56 |
57 protected: | 57 protected: |
58 // file_handler::FileSelectr overrides. | 58 // file_handler::FileSelectr overrides. |
59 // Shows save as dialog with suggested name in window bound to |browser|. | 59 // Shows save as dialog with suggested name in window bound to |browser|. |
60 // After this method is called, the selector implementation should not be | 60 // After this method is called, the selector implementation should not be |
61 // deleted. It will delete itself after it receives response from | 61 // deleted. It will delete itself after it receives response from |
62 // SelectFielDialog. | 62 // SelectFielDialog. |
63 virtual void SelectFile(const FilePath& suggested_name, | 63 virtual void SelectFile(const FilePath& suggested_name, |
64 Browser* browser) OVERRIDE; | 64 Browser* browser) OVERRIDE; |
65 virtual void set_function_for_test( | 65 virtual void set_function_for_test( |
66 FileHandlerSelectFileFunction* function) OVERRIDE; | 66 FileHandlerSelectFileFunction* function) OVERRIDE; |
67 | 67 |
68 // SelectFileDialog::Listener overrides. | 68 // ui::SelectFileDialog::Listener overrides. |
69 virtual void FileSelected(const FilePath& path, | 69 virtual void FileSelected(const FilePath& path, |
70 int index, | 70 int index, |
71 void* params) OVERRIDE; | 71 void* params) OVERRIDE; |
72 virtual void MultiFilesSelected(const std::vector<FilePath>& files, | 72 virtual void MultiFilesSelected(const std::vector<FilePath>& files, |
73 void* params) OVERRIDE; | 73 void* params) OVERRIDE; |
74 virtual void FileSelectionCanceled(void* params) OVERRIDE; | 74 virtual void FileSelectionCanceled(void* params) OVERRIDE; |
75 | 75 |
76 private: | 76 private: |
77 bool DoSelectFile(const FilePath& suggeste_name, Browser* browser); | 77 bool DoSelectFile(const FilePath& suggeste_name, Browser* browser); |
78 void SendResponse(bool success, const FilePath& selected_path); | 78 void SendResponse(bool success, const FilePath& selected_path); |
79 | 79 |
80 // Dialog that is shown by selector. | 80 // Dialog that is shown by selector. |
81 scoped_refptr<SelectFileDialog> dialog_; | 81 scoped_refptr<ui::SelectFileDialog> dialog_; |
82 | 82 |
83 // Extension function that uses the selector. | 83 // Extension function that uses the selector. |
84 scoped_refptr<FileHandlerSelectFileFunction> function_; | 84 scoped_refptr<FileHandlerSelectFileFunction> function_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(FileSelectorImpl); | 86 DISALLOW_COPY_AND_ASSIGN(FileSelectorImpl); |
87 }; | 87 }; |
88 | 88 |
89 FileSelectorImpl::FileSelectorImpl(FileHandlerSelectFileFunction* function) | 89 FileSelectorImpl::FileSelectorImpl(FileHandlerSelectFileFunction* function) |
90 : function_(function) { | 90 : function_(function) { |
91 } | 91 } |
(...skipping 28 matching lines...) Expand all Loading... |
120 DCHECK(!dialog_.get()); | 120 DCHECK(!dialog_.get()); |
121 DCHECK(browser); | 121 DCHECK(browser); |
122 | 122 |
123 if (!browser->window()) | 123 if (!browser->window()) |
124 return false; | 124 return false; |
125 | 125 |
126 TabContents* tab_contents = chrome::GetActiveTabContents(browser); | 126 TabContents* tab_contents = chrome::GetActiveTabContents(browser); |
127 if (!tab_contents) | 127 if (!tab_contents) |
128 return false; | 128 return false; |
129 | 129 |
130 dialog_ = SelectFileDialog::Create( | 130 dialog_ = ui::SelectFileDialog::Create( |
131 this, new ChromeSelectFilePolicy(tab_contents->web_contents())); | 131 this, new ChromeSelectFilePolicy(tab_contents->web_contents())); |
132 | 132 |
133 dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | 133 dialog_->SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE, |
134 string16() /* dialog title*/, suggested_name, | 134 string16() /* dialog title*/, suggested_name, |
135 NULL /* allowed file types */, 0 /* file type index */, | 135 NULL /* allowed file types */, 0 /* file type index */, |
136 std::string() /* default file extension */, | 136 std::string() /* default file extension */, |
137 browser->window()->GetNativeWindow(), NULL /* params */); | 137 browser->window()->GetNativeWindow(), NULL /* params */); |
138 | 138 |
139 return dialog_->IsRunning(browser->window()->GetNativeWindow()); | 139 return dialog_->IsRunning(browser->window()->GetNativeWindow()); |
140 } | 140 } |
141 | 141 |
142 void FileSelectorImpl::FileSelected( | 142 void FileSelectorImpl::FileSelected( |
143 const FilePath& path, int index, void* params) { | 143 const FilePath& path, int index, void* params) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 result->set_function_for_test(this); | 322 result->set_function_for_test(this); |
323 return result; | 323 return result; |
324 } | 324 } |
325 return new FileSelectorImpl(this); | 325 return new FileSelectorImpl(this); |
326 } | 326 } |
327 | 327 |
328 FileSelector* FileHandlerSelectFileFunction::file_selector_for_test_ = NULL; | 328 FileSelector* FileHandlerSelectFileFunction::file_selector_for_test_ = NULL; |
329 | 329 |
330 bool FileHandlerSelectFileFunction::gesture_check_disabled_for_test_ = false; | 330 bool FileHandlerSelectFileFunction::gesture_check_disabled_for_test_ = false; |
331 | 331 |
OLD | NEW |