OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/platform_util.h" | 5 #include "chrome/browser/platform_util.h" |
6 | 6 |
7 #include <commdlg.h> | 7 #include <commdlg.h> |
8 #include <dwmapi.h> | 8 #include <dwmapi.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
11 | 11 |
| 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" |
12 #include "base/file_path.h" | 14 #include "base/file_path.h" |
13 #include "base/file_util.h" | 15 #include "base/file_util.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/string_util.h" | 17 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
17 #include "base/win/registry.h" | 19 #include "base/win/registry.h" |
18 #include "base/win/scoped_co_mem.h" | 20 #include "base/win/scoped_co_mem.h" |
19 #include "base/win/scoped_comptr.h" | 21 #include "base/win/scoped_comptr.h" |
| 22 #include "content/public/browser/browser_thread.h" |
20 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
21 #include "ui/base/win/shell.h" | 24 #include "ui/base/win/shell.h" |
22 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
23 | 26 |
24 namespace platform_util { | 27 using content::BrowserThread; |
25 | 28 |
26 void ShowItemInFolder(const FilePath& full_path) { | 29 namespace { |
| 30 |
| 31 void ShowItemInFolderOnFileThread(const FilePath& full_path) { |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
27 FilePath dir = full_path.DirName(); | 33 FilePath dir = full_path.DirName(); |
28 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". | 34 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". |
29 if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir)) | 35 if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir)) |
30 return; | 36 return; |
31 | 37 |
32 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( | 38 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( |
33 PCIDLIST_ABSOLUTE pidl_Folder, | 39 PCIDLIST_ABSOLUTE pidl_Folder, |
34 UINT cidl, | 40 UINT cidl, |
35 PCUITEMID_CHILD_ARRAY pidls, | 41 PCUITEMID_CHILD_ARRAY pidls, |
36 DWORD flags); | 42 DWORD flags); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 << "(): Can't open full_path = \"" | 106 << "(): Can't open full_path = \"" |
101 << full_path.value() << "\"" | 107 << full_path.value() << "\"" |
102 << " hr = " << hr | 108 << " hr = " << hr |
103 << " " << reinterpret_cast<LPTSTR>(&message); | 109 << " " << reinterpret_cast<LPTSTR>(&message); |
104 if (message) | 110 if (message) |
105 LocalFree(message); | 111 LocalFree(message); |
106 } | 112 } |
107 } | 113 } |
108 } | 114 } |
109 | 115 |
| 116 } // namespace |
| 117 |
| 118 namespace platform_util { |
| 119 |
| 120 void ShowItemInFolder(const FilePath& full_path) { |
| 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 122 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 123 base::Bind(&ShowItemInFolderOnFileThread, full_path)); |
| 124 } |
| 125 |
110 void OpenItem(const FilePath& full_path) { | 126 void OpenItem(const FilePath& full_path) { |
111 ui::win::OpenItemViaShell(full_path); | 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 128 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 129 base::IgnoreReturn<bool>(base::Bind(&ui::win::OpenItemViaShell, |
| 130 full_path))); |
112 } | 131 } |
113 | 132 |
114 void OpenExternal(const GURL& url) { | 133 void OpenExternal(const GURL& url) { |
115 // Quote the input scheme to be sure that the command does not have | 134 // Quote the input scheme to be sure that the command does not have |
116 // parameters unexpected by the external program. This url should already | 135 // parameters unexpected by the external program. This url should already |
117 // have been escaped. | 136 // have been escaped. |
118 std::string escaped_url = url.spec(); | 137 std::string escaped_url = url.spec(); |
119 escaped_url.insert(0, "\""); | 138 escaped_url.insert(0, "\""); |
120 escaped_url += "\""; | 139 escaped_url += "\""; |
121 | 140 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 void ActivateWindow(gfx::NativeWindow window) { | 189 void ActivateWindow(gfx::NativeWindow window) { |
171 ::SetForegroundWindow(window); | 190 ::SetForegroundWindow(window); |
172 } | 191 } |
173 | 192 |
174 bool IsVisible(gfx::NativeView view) { | 193 bool IsVisible(gfx::NativeView view) { |
175 // MSVC complains if we don't include != 0. | 194 // MSVC complains if we don't include != 0. |
176 return ::IsWindowVisible(view) != 0; | 195 return ::IsWindowVisible(view) != 0; |
177 } | 196 } |
178 | 197 |
179 } // namespace platform_util | 198 } // namespace platform_util |
OLD | NEW |