Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / utility / shell_handler_win.cc
blob96cce541e07c40bd7771010426591efa8b9b8ae6
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.
5 #include "chrome/utility/shell_handler_win.h"
7 #include <commdlg.h>
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 #include "ui/base/win/shell.h"
16 ShellHandler::ShellHandler() {}
17 ShellHandler::~ShellHandler() {}
19 bool ShellHandler::OnMessageReceived(const IPC::Message& message) {
20 bool handled = true;
21 IPC_BEGIN_MESSAGE_MAP(ShellHandler, message)
22 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_OpenFileViaShell,
23 OnOpenFileViaShell)
24 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_OpenFolderViaShell,
25 OnOpenFolderViaShell)
26 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetOpenFileName,
27 OnGetOpenFileName)
28 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetSaveFileName,
29 OnGetSaveFileName)
30 IPC_MESSAGE_UNHANDLED(handled = false)
31 IPC_END_MESSAGE_MAP()
32 return handled;
35 void ShellHandler::OnOpenFileViaShell(const base::FilePath& full_path) {
36 ui::win::OpenFileViaShell(full_path);
39 void ShellHandler::OnOpenFolderViaShell(const base::FilePath& full_path) {
40 ui::win::OpenFolderViaShell(full_path);
43 void ShellHandler::OnGetOpenFileName(
44 HWND owner,
45 DWORD flags,
46 const GetOpenFileNameFilter& filter,
47 const base::FilePath& initial_directory,
48 const base::FilePath& filename) {
49 ui::win::OpenFileName open_file_name(owner, flags);
50 open_file_name.SetInitialSelection(initial_directory, filename);
51 open_file_name.SetFilters(filter);
53 base::FilePath directory;
54 std::vector<base::FilePath> filenames;
56 if (::GetOpenFileName(open_file_name.GetOPENFILENAME()))
57 open_file_name.GetResult(&directory, &filenames);
59 if (filenames.size()) {
60 content::UtilityThread::Get()->Send(
61 new ChromeUtilityHostMsg_GetOpenFileName_Result(directory, filenames));
62 } else {
63 content::UtilityThread::Get()->Send(
64 new ChromeUtilityHostMsg_GetOpenFileName_Failed());
68 void ShellHandler::OnGetSaveFileName(
69 const ChromeUtilityMsg_GetSaveFileName_Params& params) {
70 ui::win::OpenFileName open_file_name(params.owner, params.flags);
71 open_file_name.SetInitialSelection(params.initial_directory,
72 params.suggested_filename);
73 open_file_name.SetFilters(params.filters);
74 open_file_name.GetOPENFILENAME()->nFilterIndex =
75 params.one_based_filter_index;
76 open_file_name.GetOPENFILENAME()->lpstrDefExt =
77 params.default_extension.c_str();
79 open_file_name.MaybeInstallWindowPositionHookForSaveAsOnXP();
81 if (::GetSaveFileName(open_file_name.GetOPENFILENAME())) {
82 content::UtilityThread::Get()->Send(
83 new ChromeUtilityHostMsg_GetSaveFileName_Result(
84 base::FilePath(open_file_name.GetOPENFILENAME()->lpstrFile),
85 open_file_name.GetOPENFILENAME()->nFilterIndex));
86 return;
89 // Zero means the dialog was closed, otherwise we had an error.
90 DWORD error_code = ::CommDlgExtendedError();
91 if (error_code != 0)
92 NOTREACHED() << "GetSaveFileName failed with code: " << error_code;
94 content::UtilityThread::Get()->Send(
95 new ChromeUtilityHostMsg_GetSaveFileName_Failed());