Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: chrome/utility/shell_handler_impl_win.cc

Issue 2122303002: Revive experiment to isolate shell operations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
20 21
21 namespace { 22 namespace {
22 23
24 HWND Uint32ToHWND(uint32_t value) {
25 return reinterpret_cast<HWND>(value);
26 }
27
23 // This class checks if the current executable is pinned to the taskbar. It also 28 // This class checks if the current executable is pinned to the taskbar. It also
24 // keeps track of the errors that occurs that prevents it from getting a result. 29 // keeps track of the errors that occurs that prevents it from getting a result.
25 class IsPinnedToTaskbarHelper { 30 class IsPinnedToTaskbarHelper {
26 public: 31 public:
27 IsPinnedToTaskbarHelper() = default; 32 IsPinnedToTaskbarHelper() = default;
28 33
29 // Returns true if the current executable is pinned to the taskbar. 34 // Returns true if the current executable is pinned to the taskbar.
30 bool GetResult(); 35 bool GetResult();
31 36
32 bool error_occured() { return error_occured_; } 37 bool error_occured() { return error_occured_; }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 : binding_(this, std::move(request)) {} 220 : binding_(this, std::move(request)) {}
216 221
217 ShellHandlerImpl::~ShellHandlerImpl() = default; 222 ShellHandlerImpl::~ShellHandlerImpl() = default;
218 223
219 void ShellHandlerImpl::IsPinnedToTaskbar( 224 void ShellHandlerImpl::IsPinnedToTaskbar(
220 const IsPinnedToTaskbarCallback& callback) { 225 const IsPinnedToTaskbarCallback& callback) {
221 IsPinnedToTaskbarHelper helper; 226 IsPinnedToTaskbarHelper helper;
222 bool is_pinned_to_taskbar = helper.GetResult(); 227 bool is_pinned_to_taskbar = helper.GetResult();
223 callback.Run(!helper.error_occured(), is_pinned_to_taskbar); 228 callback.Run(!helper.error_occured(), is_pinned_to_taskbar);
224 } 229 }
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 }
OLDNEW
« no previous file with comments | « chrome/utility/shell_handler_impl_win.h ('k') | mojo/public/tools/bindings/chromium_bindings_configuration.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698