| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_impl_win.h" | 5 #include "chrome/utility/shell_handler_impl_win.h" |
| 6 | 6 |
| 7 #include <shldisp.h> | 7 #include <shldisp.h> |
| 8 | 8 |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/scoped_native_library.h" | 12 #include "base/scoped_native_library.h" |
| 13 #include "base/win/scoped_bstr.h" | 13 #include "base/win/scoped_bstr.h" |
| 14 #include "base/win/scoped_com_initializer.h" | 14 #include "base/win/scoped_com_initializer.h" |
| 15 #include "base/win/scoped_comptr.h" | 15 #include "base/win/scoped_comptr.h" |
| 16 #include "base/win/scoped_variant.h" | 16 #include "base/win/scoped_variant.h" |
| 17 #include "base/win/shortcut.h" | 17 #include "base/win/shortcut.h" |
| 18 #include "chrome/installer/util/install_util.h" | 18 #include "chrome/installer/util/install_util.h" |
| 19 #include "content/public/utility/utility_thread.h" | 19 #include "content/public/utility/utility_thread.h" |
| 20 #include "ui/base/win/open_file_name_win.h" | |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 HWND Uint32ToHWND(uint32_t value) { | |
| 25 return reinterpret_cast<HWND>(value); | |
| 26 } | |
| 27 | |
| 28 // This class checks if the current executable is pinned to the taskbar. It also | 23 // This class checks if the current executable is pinned to the taskbar. It also |
| 29 // keeps track of the errors that occurs that prevents it from getting a result. | 24 // keeps track of the errors that occurs that prevents it from getting a result. |
| 30 class IsPinnedToTaskbarHelper { | 25 class IsPinnedToTaskbarHelper { |
| 31 public: | 26 public: |
| 32 IsPinnedToTaskbarHelper() = default; | 27 IsPinnedToTaskbarHelper() = default; |
| 33 | 28 |
| 34 // Returns true if the current executable is pinned to the taskbar. | 29 // Returns true if the current executable is pinned to the taskbar. |
| 35 bool GetResult(); | 30 bool GetResult(); |
| 36 | 31 |
| 37 bool error_occured() { return error_occured_; } | 32 bool error_occured() { return error_occured_; } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 : binding_(this, std::move(request)) {} | 215 : binding_(this, std::move(request)) {} |
| 221 | 216 |
| 222 ShellHandlerImpl::~ShellHandlerImpl() = default; | 217 ShellHandlerImpl::~ShellHandlerImpl() = default; |
| 223 | 218 |
| 224 void ShellHandlerImpl::IsPinnedToTaskbar( | 219 void ShellHandlerImpl::IsPinnedToTaskbar( |
| 225 const IsPinnedToTaskbarCallback& callback) { | 220 const IsPinnedToTaskbarCallback& callback) { |
| 226 IsPinnedToTaskbarHelper helper; | 221 IsPinnedToTaskbarHelper helper; |
| 227 bool is_pinned_to_taskbar = helper.GetResult(); | 222 bool is_pinned_to_taskbar = helper.GetResult(); |
| 228 callback.Run(!helper.error_occured(), is_pinned_to_taskbar); | 223 callback.Run(!helper.error_occured(), is_pinned_to_taskbar); |
| 229 } | 224 } |
| 230 | |
| 231 void ShellHandlerImpl::DoGetOpenFileName( | |
| 232 uint32_t owner, | |
| 233 uint32_t flags, | |
| 234 const std::vector<std::tuple<base::string16, base::string16>>& filters, | |
| 235 const base::FilePath& initial_directory, | |
| 236 const base::FilePath& filename, | |
| 237 const DoGetOpenFileNameCallback& callback) { | |
| 238 ui::win::OpenFileName open_file_name(Uint32ToHWND(owner), flags); | |
| 239 open_file_name.SetInitialSelection(initial_directory, filename); | |
| 240 open_file_name.SetFilters(filters); | |
| 241 | |
| 242 base::FilePath directory; | |
| 243 std::vector<base::FilePath> filenames; | |
| 244 | |
| 245 if (::GetOpenFileName(open_file_name.GetOPENFILENAME())) | |
| 246 open_file_name.GetResult(&directory, &filenames); | |
| 247 | |
| 248 if (!filenames.empty()) | |
| 249 callback.Run(directory, filenames); | |
| 250 else | |
| 251 callback.Run(base::FilePath(), std::vector<base::FilePath>()); | |
| 252 } | |
| 253 | |
| 254 void ShellHandlerImpl::DoGetSaveFileName( | |
| 255 uint32_t owner, | |
| 256 uint32_t flags, | |
| 257 const std::vector<std::tuple<base::string16, base::string16>>& filters, | |
| 258 uint32_t one_based_filter_index, | |
| 259 const base::FilePath& initial_directory, | |
| 260 const base::FilePath& suggested_filename, | |
| 261 const base::FilePath& default_extension, | |
| 262 const DoGetSaveFileNameCallback& callback) { | |
| 263 ui::win::OpenFileName open_file_name(reinterpret_cast<HWND>(owner), flags); | |
| 264 open_file_name.SetInitialSelection(initial_directory, suggested_filename); | |
| 265 open_file_name.SetFilters(filters); | |
| 266 open_file_name.GetOPENFILENAME()->nFilterIndex = one_based_filter_index; | |
| 267 open_file_name.GetOPENFILENAME()->lpstrDefExt = | |
| 268 default_extension.value().c_str(); | |
| 269 | |
| 270 if (::GetSaveFileName(open_file_name.GetOPENFILENAME())) { | |
| 271 callback.Run(base::FilePath(open_file_name.GetOPENFILENAME()->lpstrFile), | |
| 272 open_file_name.GetOPENFILENAME()->nFilterIndex); | |
| 273 return; | |
| 274 } | |
| 275 | |
| 276 // Zero means the dialog was closed, otherwise we had an error. | |
| 277 DWORD error_code = ::CommDlgExtendedError(); | |
| 278 if (error_code != 0) | |
| 279 NOTREACHED() << "GetSaveFileName failed with code: " << error_code; | |
| 280 | |
| 281 callback.Run(base::FilePath(), 0); | |
| 282 } | |
| OLD | NEW |