| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/utility/ipc_shell_handler_win.h" | |
| 6 | |
| 7 #include <commdlg.h> | |
| 8 | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "chrome/common/chrome_utility_messages.h" | |
| 13 #include "content/public/utility/utility_thread.h" | |
| 14 #include "ui/base/win/open_file_name_win.h" | |
| 15 | |
| 16 IPCShellHandler::IPCShellHandler() {} | |
| 17 IPCShellHandler::~IPCShellHandler() {} | |
| 18 | |
| 19 bool IPCShellHandler::OnMessageReceived(const IPC::Message& message) { | |
| 20 bool handled = true; | |
| 21 IPC_BEGIN_MESSAGE_MAP(IPCShellHandler, message) | |
| 22 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetOpenFileName, OnGetOpenFileName) | |
| 23 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetSaveFileName, OnGetSaveFileName) | |
| 24 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 25 IPC_END_MESSAGE_MAP() | |
| 26 return handled; | |
| 27 } | |
| 28 | |
| 29 void IPCShellHandler::OnGetOpenFileName(HWND owner, | |
| 30 DWORD flags, | |
| 31 const GetOpenFileNameFilter& filter, | |
| 32 const base::FilePath& initial_directory, | |
| 33 const base::FilePath& filename) { | |
| 34 ui::win::OpenFileName open_file_name(owner, flags); | |
| 35 open_file_name.SetInitialSelection(initial_directory, filename); | |
| 36 open_file_name.SetFilters(filter); | |
| 37 | |
| 38 base::FilePath directory; | |
| 39 std::vector<base::FilePath> filenames; | |
| 40 | |
| 41 if (::GetOpenFileName(open_file_name.GetOPENFILENAME())) | |
| 42 open_file_name.GetResult(&directory, &filenames); | |
| 43 | |
| 44 if (filenames.size()) { | |
| 45 content::UtilityThread::Get()->Send( | |
| 46 new ChromeUtilityHostMsg_GetOpenFileName_Result(directory, filenames)); | |
| 47 } else { | |
| 48 content::UtilityThread::Get()->Send( | |
| 49 new ChromeUtilityHostMsg_GetOpenFileName_Failed()); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 void IPCShellHandler::OnGetSaveFileName( | |
| 54 const ChromeUtilityMsg_GetSaveFileName_Params& params) { | |
| 55 ui::win::OpenFileName open_file_name(params.owner, params.flags); | |
| 56 open_file_name.SetInitialSelection(params.initial_directory, | |
| 57 params.suggested_filename); | |
| 58 open_file_name.SetFilters(params.filters); | |
| 59 open_file_name.GetOPENFILENAME()->nFilterIndex = | |
| 60 params.one_based_filter_index; | |
| 61 open_file_name.GetOPENFILENAME()->lpstrDefExt = | |
| 62 params.default_extension.c_str(); | |
| 63 | |
| 64 open_file_name.MaybeInstallWindowPositionHookForSaveAsOnXP(); | |
| 65 | |
| 66 if (::GetSaveFileName(open_file_name.GetOPENFILENAME())) { | |
| 67 content::UtilityThread::Get()->Send( | |
| 68 new ChromeUtilityHostMsg_GetSaveFileName_Result( | |
| 69 base::FilePath(open_file_name.GetOPENFILENAME()->lpstrFile), | |
| 70 open_file_name.GetOPENFILENAME()->nFilterIndex)); | |
| 71 return; | |
| 72 } | |
| 73 | |
| 74 // Zero means the dialog was closed, otherwise we had an error. | |
| 75 DWORD error_code = ::CommDlgExtendedError(); | |
| 76 if (error_code != 0) | |
| 77 NOTREACHED() << "GetSaveFileName failed with code: " << error_code; | |
| 78 | |
| 79 content::UtilityThread::Get()->Send( | |
| 80 new ChromeUtilityHostMsg_GetSaveFileName_Failed()); | |
| 81 } | |
| OLD | NEW |