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/utility/shell_handler_win.h" | 5 #include "chrome/utility/shell_handler_win.h" |
6 | 6 |
7 #include <commdlg.h> | 7 #include <commdlg.h> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/common/chrome_utility_messages.h" | 11 #include "chrome/common/chrome_utility_messages.h" |
12 #include "content/public/utility/utility_thread.h" | 12 #include "content/public/utility/utility_thread.h" |
13 #include "ui/base/win/open_file_name_win.h" | 13 #include "ui/base/win/open_file_name_win.h" |
14 #include "ui/base/win/shell.h" | 14 #include "ui/base/win/shell.h" |
15 | 15 |
16 ShellHandler::ShellHandler() {} | 16 ShellHandler::ShellHandler() {} |
17 ShellHandler::~ShellHandler() {} | 17 ShellHandler::~ShellHandler() {} |
18 | 18 |
19 bool ShellHandler::OnMessageReceived(const IPC::Message& message) { | 19 bool ShellHandler::OnMessageReceived(const IPC::Message& message) { |
20 bool handled = true; | 20 bool handled = true; |
21 IPC_BEGIN_MESSAGE_MAP(ShellHandler, message) | 21 IPC_BEGIN_MESSAGE_MAP(ShellHandler, message) |
22 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_OpenItemViaShell, | 22 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_OpenItemViaShell, |
23 OnOpenItemViaShell) | 23 OnOpenItemViaShell) |
24 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetOpenFileName, | 24 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetOpenFileName, |
25 OnGetOpenFileName) | 25 OnGetOpenFileName) |
| 26 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetSaveFileName, |
| 27 OnGetSaveFileName) |
26 IPC_MESSAGE_UNHANDLED(handled = false) | 28 IPC_MESSAGE_UNHANDLED(handled = false) |
27 IPC_END_MESSAGE_MAP() | 29 IPC_END_MESSAGE_MAP() |
28 return handled; | 30 return handled; |
29 } | 31 } |
30 | 32 |
31 void ShellHandler::OnOpenItemViaShell(const base::FilePath& full_path) { | 33 void ShellHandler::OnOpenItemViaShell(const base::FilePath& full_path) { |
32 ui::win::OpenItemViaShell(full_path); | 34 ui::win::OpenItemViaShell(full_path); |
33 } | 35 } |
34 | 36 |
35 void ShellHandler::OnGetOpenFileName( | 37 void ShellHandler::OnGetOpenFileName( |
(...skipping 13 matching lines...) Expand all Loading... |
49 open_file_name.GetResult(&directory, &filenames); | 51 open_file_name.GetResult(&directory, &filenames); |
50 | 52 |
51 if (filenames.size()) { | 53 if (filenames.size()) { |
52 content::UtilityThread::Get()->Send( | 54 content::UtilityThread::Get()->Send( |
53 new ChromeUtilityHostMsg_GetOpenFileName_Result(directory, filenames)); | 55 new ChromeUtilityHostMsg_GetOpenFileName_Result(directory, filenames)); |
54 } else { | 56 } else { |
55 content::UtilityThread::Get()->Send( | 57 content::UtilityThread::Get()->Send( |
56 new ChromeUtilityHostMsg_GetOpenFileName_Failed()); | 58 new ChromeUtilityHostMsg_GetOpenFileName_Failed()); |
57 } | 59 } |
58 } | 60 } |
| 61 |
| 62 void ShellHandler::OnGetSaveFileName( |
| 63 const ChromeUtilityMsg_GetSaveFileName_Params& params) { |
| 64 ui::win::OpenFileName open_file_name(params.owner, params.flags); |
| 65 open_file_name.SetInitialSelection(params.initial_directory, |
| 66 params.suggested_filename); |
| 67 open_file_name.GetOPENFILENAME()->nFilterIndex = |
| 68 params.one_based_filter_index; |
| 69 open_file_name.GetOPENFILENAME()->lpstrDefExt = |
| 70 params.default_extension.c_str(); |
| 71 |
| 72 open_file_name.MaybeInstallWindowPositionHookForSaveAsOnXP(); |
| 73 |
| 74 if (::GetSaveFileName(open_file_name.GetOPENFILENAME())) { |
| 75 content::UtilityThread::Get()->Send( |
| 76 new ChromeUtilityHostMsg_GetSaveFileName_Result( |
| 77 base::FilePath(open_file_name.GetOPENFILENAME()->lpstrFile), |
| 78 open_file_name.GetOPENFILENAME()->nFilterIndex)); |
| 79 return; |
| 80 } |
| 81 |
| 82 // Zero means the dialog was closed, otherwise we had an error. |
| 83 DWORD error_code = ::CommDlgExtendedError(); |
| 84 if (error_code != 0) |
| 85 NOTREACHED() << "GetSaveFileName failed with code: " << error_code; |
| 86 |
| 87 content::UtilityThread::Get()->Send( |
| 88 new ChromeUtilityHostMsg_GetSaveFileName_Failed()); |
| 89 } |
OLD | NEW |