| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chrome_select_file_dialog_factory_win.h" | 5 #include "chrome/browser/chrome_select_file_dialog_factory_win.h" |
| 6 | 6 |
| 7 #include <Windows.h> | 7 #include <Windows.h> |
| 8 #include <commdlg.h> | 8 #include <commdlg.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/win/metro.h" | 18 #include "base/win/metro.h" |
| 19 #include "chrome/common/chrome_utility_messages.h" | 19 #include "chrome/common/chrome_utility_messages.h" |
| 20 #include "chrome/grit/generated_resources.h" |
| 20 #include "content/public/browser/utility_process_host.h" | 21 #include "content/public/browser/utility_process_host.h" |
| 21 #include "content/public/browser/utility_process_host_client.h" | 22 #include "content/public/browser/utility_process_host_client.h" |
| 22 #include "ipc/ipc_message_macros.h" | 23 #include "ipc/ipc_message_macros.h" |
| 24 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/win/open_file_name_win.h" | 25 #include "ui/base/win/open_file_name_win.h" |
| 24 #include "ui/shell_dialogs/select_file_dialog_win.h" | 26 #include "ui/shell_dialogs/select_file_dialog_win.h" |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 bool CallMetroOPENFILENAMEMethod(const char* method_name, OPENFILENAME* ofn) { | 30 bool CallMetroOPENFILENAMEMethod(const char* method_name, OPENFILENAME* ofn) { |
| 29 typedef BOOL (*MetroOPENFILENAMEMethod)(OPENFILENAME*); | 31 typedef BOOL (*MetroOPENFILENAMEMethod)(OPENFILENAME*); |
| 30 MetroOPENFILENAMEMethod metro_method = NULL; | 32 MetroOPENFILENAMEMethod metro_method = NULL; |
| 31 HMODULE metro_module = base::win::GetMetroModule(); | 33 HMODULE metro_module = base::win::GetMetroModule(); |
| 32 | 34 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 58 void WaitForCompletion(); | 60 void WaitForCompletion(); |
| 59 | 61 |
| 60 // Returns the selected directory. | 62 // Returns the selected directory. |
| 61 const base::FilePath& directory() const { return directory_; } | 63 const base::FilePath& directory() const { return directory_; } |
| 62 | 64 |
| 63 // Returns the list of selected filenames. Each should be interpreted as a | 65 // Returns the list of selected filenames. Each should be interpreted as a |
| 64 // child of directory(). | 66 // child of directory(). |
| 65 const std::vector<base::FilePath>& filenames() const { return filenames_; } | 67 const std::vector<base::FilePath>& filenames() const { return filenames_; } |
| 66 | 68 |
| 67 // UtilityProcessHostClient implementation | 69 // UtilityProcessHostClient implementation |
| 68 virtual void OnProcessCrashed(int exit_code) override; | 70 void OnProcessCrashed(int exit_code) override; |
| 69 virtual void OnProcessLaunchFailed() override; | 71 void OnProcessLaunchFailed() override; |
| 70 virtual bool OnMessageReceived(const IPC::Message& message) override; | 72 bool OnMessageReceived(const IPC::Message& message) override; |
| 71 | 73 |
| 72 protected: | 74 protected: |
| 73 virtual ~GetOpenFileNameClient(); | 75 virtual ~GetOpenFileNameClient(); |
| 74 | 76 |
| 75 private: | 77 private: |
| 76 void OnResult(const base::FilePath& directory, | 78 void OnResult(const base::FilePath& directory, |
| 77 const std::vector<base::FilePath>& filenames); | 79 const std::vector<base::FilePath>& filenames); |
| 78 void OnFailure(); | 80 void OnFailure(); |
| 79 | 81 |
| 80 base::FilePath directory_; | 82 base::FilePath directory_; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // must be the currently executing task runner. | 132 // must be the currently executing task runner. |
| 131 void DoInvokeGetOpenFileName( | 133 void DoInvokeGetOpenFileName( |
| 132 OPENFILENAME* ofn, | 134 OPENFILENAME* ofn, |
| 133 scoped_refptr<GetOpenFileNameClient> client, | 135 scoped_refptr<GetOpenFileNameClient> client, |
| 134 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner) { | 136 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner) { |
| 135 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); | 137 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); |
| 136 | 138 |
| 137 base::WeakPtr<content::UtilityProcessHost> utility_process_host( | 139 base::WeakPtr<content::UtilityProcessHost> utility_process_host( |
| 138 content::UtilityProcessHost::Create(client, current_task_runner) | 140 content::UtilityProcessHost::Create(client, current_task_runner) |
| 139 ->AsWeakPtr()); | 141 ->AsWeakPtr()); |
| 142 utility_process_host->SetName(l10n_util::GetStringUTF16( |
| 143 IDS_UTILITY_PROCESS_FILE_DIALOG_NAME)); |
| 140 utility_process_host->DisableSandbox(); | 144 utility_process_host->DisableSandbox(); |
| 141 utility_process_host->Send(new ChromeUtilityMsg_GetOpenFileName( | 145 utility_process_host->Send(new ChromeUtilityMsg_GetOpenFileName( |
| 142 ofn->hwndOwner, | 146 ofn->hwndOwner, |
| 143 ofn->Flags & ~OFN_ENABLEHOOK, // We can't send a hook function over IPC. | 147 ofn->Flags & ~OFN_ENABLEHOOK, // We can't send a hook function over IPC. |
| 144 ui::win::OpenFileName::GetFilters(ofn), | 148 ui::win::OpenFileName::GetFilters(ofn), |
| 145 base::FilePath(ofn->lpstrInitialDir ? ofn->lpstrInitialDir | 149 base::FilePath(ofn->lpstrInitialDir ? ofn->lpstrInitialDir |
| 146 : base::string16()), | 150 : base::string16()), |
| 147 base::FilePath(ofn->lpstrFile))); | 151 base::FilePath(ofn->lpstrFile))); |
| 148 } | 152 } |
| 149 | 153 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // launch or a crash of the utility process). | 193 // launch or a crash of the utility process). |
| 190 void WaitForCompletion(); | 194 void WaitForCompletion(); |
| 191 | 195 |
| 192 // Returns the selected path. | 196 // Returns the selected path. |
| 193 const base::FilePath& path() const { return path_; } | 197 const base::FilePath& path() const { return path_; } |
| 194 | 198 |
| 195 // Returns the index of the user-selected filter. | 199 // Returns the index of the user-selected filter. |
| 196 int one_based_filter_index() const { return one_based_filter_index_; } | 200 int one_based_filter_index() const { return one_based_filter_index_; } |
| 197 | 201 |
| 198 // UtilityProcessHostClient implementation | 202 // UtilityProcessHostClient implementation |
| 199 virtual void OnProcessCrashed(int exit_code) override; | 203 void OnProcessCrashed(int exit_code) override; |
| 200 virtual void OnProcessLaunchFailed() override; | 204 void OnProcessLaunchFailed() override; |
| 201 virtual bool OnMessageReceived(const IPC::Message& message) override; | 205 bool OnMessageReceived(const IPC::Message& message) override; |
| 202 | 206 |
| 203 protected: | 207 protected: |
| 204 virtual ~GetSaveFileNameClient(); | 208 virtual ~GetSaveFileNameClient(); |
| 205 | 209 |
| 206 private: | 210 private: |
| 207 void OnResult(const base::FilePath& path, int one_based_filter_index); | 211 void OnResult(const base::FilePath& path, int one_based_filter_index); |
| 208 void OnFailure(); | 212 void OnFailure(); |
| 209 | 213 |
| 210 base::FilePath path_; | 214 base::FilePath path_; |
| 211 int one_based_filter_index_; | 215 int one_based_filter_index_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // must be the currently executing task runner. | 264 // must be the currently executing task runner. |
| 261 void DoInvokeGetSaveFileName( | 265 void DoInvokeGetSaveFileName( |
| 262 OPENFILENAME* ofn, | 266 OPENFILENAME* ofn, |
| 263 scoped_refptr<GetSaveFileNameClient> client, | 267 scoped_refptr<GetSaveFileNameClient> client, |
| 264 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner) { | 268 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner) { |
| 265 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); | 269 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); |
| 266 | 270 |
| 267 base::WeakPtr<content::UtilityProcessHost> utility_process_host( | 271 base::WeakPtr<content::UtilityProcessHost> utility_process_host( |
| 268 content::UtilityProcessHost::Create(client, current_task_runner) | 272 content::UtilityProcessHost::Create(client, current_task_runner) |
| 269 ->AsWeakPtr()); | 273 ->AsWeakPtr()); |
| 274 utility_process_host->SetName(l10n_util::GetStringUTF16( |
| 275 IDS_UTILITY_PROCESS_FILE_DIALOG_NAME)); |
| 270 utility_process_host->DisableSandbox(); | 276 utility_process_host->DisableSandbox(); |
| 271 ChromeUtilityMsg_GetSaveFileName_Params params; | 277 ChromeUtilityMsg_GetSaveFileName_Params params; |
| 272 params.owner = ofn->hwndOwner; | 278 params.owner = ofn->hwndOwner; |
| 273 // We can't pass the hook function over IPC. | 279 // We can't pass the hook function over IPC. |
| 274 params.flags = ofn->Flags & ~OFN_ENABLEHOOK; | 280 params.flags = ofn->Flags & ~OFN_ENABLEHOOK; |
| 275 params.filters = ui::win::OpenFileName::GetFilters(ofn); | 281 params.filters = ui::win::OpenFileName::GetFilters(ofn); |
| 276 params.one_based_filter_index = ofn->nFilterIndex; | 282 params.one_based_filter_index = ofn->nFilterIndex; |
| 277 params.suggested_filename = base::FilePath(ofn->lpstrFile); | 283 params.suggested_filename = base::FilePath(ofn->lpstrFile); |
| 278 params.initial_directory = base::FilePath( | 284 params.initial_directory = base::FilePath( |
| 279 ofn->lpstrInitialDir ? ofn->lpstrInitialDir : base::string16()); | 285 ofn->lpstrInitialDir ? ofn->lpstrInitialDir : base::string16()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 335 |
| 330 ui::SelectFileDialog* ChromeSelectFileDialogFactory::Create( | 336 ui::SelectFileDialog* ChromeSelectFileDialogFactory::Create( |
| 331 ui::SelectFileDialog::Listener* listener, | 337 ui::SelectFileDialog::Listener* listener, |
| 332 ui::SelectFilePolicy* policy) { | 338 ui::SelectFilePolicy* policy) { |
| 333 return ui::CreateWinSelectFileDialog( | 339 return ui::CreateWinSelectFileDialog( |
| 334 listener, | 340 listener, |
| 335 policy, | 341 policy, |
| 336 base::Bind(GetOpenFileNameImpl, blocking_task_runner_), | 342 base::Bind(GetOpenFileNameImpl, blocking_task_runner_), |
| 337 base::Bind(GetSaveFileNameImpl, blocking_task_runner_)); | 343 base::Bind(GetSaveFileNameImpl, blocking_task_runner_)); |
| 338 } | 344 } |
| OLD | NEW |