OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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/shell_handler_win.h" |
| 6 |
| 7 #include <commdlg.h> |
| 8 |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/common/chrome_utility_messages.h" |
| 12 #include "content/public/utility/utility_thread.h" |
| 13 #include "ui/base/win/open_file_name_win.h" |
| 14 |
| 15 ShellHandler::ShellHandler() {} |
| 16 ShellHandler::~ShellHandler() {} |
| 17 |
| 18 bool ShellHandler::OnMessageReceived(const IPC::Message& message) { |
| 19 bool handled = true; |
| 20 IPC_BEGIN_MESSAGE_MAP(ShellHandler, message) |
| 21 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetOpenFileName, |
| 22 OnGetOpenFileName) |
| 23 IPC_MESSAGE_UNHANDLED(handled = false) |
| 24 IPC_END_MESSAGE_MAP() |
| 25 return handled; |
| 26 } |
| 27 |
| 28 void ShellHandler::OnGetOpenFileName( |
| 29 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.Get())) |
| 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 } |
OLD | NEW |