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