| 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 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 32 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 33 base::Bind(&ShowItemInFolder, full_path)); |
| 34 return; |
| 35 } |
| 36 |
| 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 27 FilePath dir = full_path.DirName(); | 38 FilePath dir = full_path.DirName(); |
| 28 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". | 39 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". |
| 29 if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir)) | 40 if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir)) |
| 30 return; | 41 return; |
| 31 | 42 |
| 32 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( | 43 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( |
| 33 PCIDLIST_ABSOLUTE pidl_Folder, | 44 PCIDLIST_ABSOLUTE pidl_Folder, |
| 34 UINT cidl, | 45 UINT cidl, |
| 35 PCUITEMID_CHILD_ARRAY pidls, | 46 PCUITEMID_CHILD_ARRAY pidls, |
| 36 DWORD flags); | 47 DWORD flags); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 << full_path.value() << "\"" | 112 << full_path.value() << "\"" |
| 102 << " hr = " << hr | 113 << " hr = " << hr |
| 103 << " " << reinterpret_cast<LPTSTR>(&message); | 114 << " " << reinterpret_cast<LPTSTR>(&message); |
| 104 if (message) | 115 if (message) |
| 105 LocalFree(message); | 116 LocalFree(message); |
| 106 } | 117 } |
| 107 } | 118 } |
| 108 } | 119 } |
| 109 | 120 |
| 110 void OpenItem(const FilePath& full_path) { | 121 void OpenItem(const FilePath& full_path) { |
| 111 ui::win::OpenItemViaShell(full_path); | 122 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 123 ui::win::OpenItemViaShell(full_path); |
| 124 } else { |
| 125 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 126 base::Bind(&OpenItem, full_path)); |
| 127 } |
| 112 } | 128 } |
| 113 | 129 |
| 114 void OpenExternal(const GURL& url) { | 130 void OpenExternal(const GURL& url) { |
| 115 // Quote the input scheme to be sure that the command does not have | 131 // Quote the input scheme to be sure that the command does not have |
| 116 // parameters unexpected by the external program. This url should already | 132 // parameters unexpected by the external program. This url should already |
| 117 // have been escaped. | 133 // have been escaped. |
| 118 std::string escaped_url = url.spec(); | 134 std::string escaped_url = url.spec(); |
| 119 escaped_url.insert(0, "\""); | 135 escaped_url.insert(0, "\""); |
| 120 escaped_url += "\""; | 136 escaped_url += "\""; |
| 121 | 137 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 void ActivateWindow(gfx::NativeWindow window) { | 186 void ActivateWindow(gfx::NativeWindow window) { |
| 171 ::SetForegroundWindow(window); | 187 ::SetForegroundWindow(window); |
| 172 } | 188 } |
| 173 | 189 |
| 174 bool IsVisible(gfx::NativeView view) { | 190 bool IsVisible(gfx::NativeView view) { |
| 175 // MSVC complains if we don't include != 0. | 191 // MSVC complains if we don't include != 0. |
| 176 return ::IsWindowVisible(view) != 0; | 192 return ::IsWindowVisible(view) != 0; |
| 177 } | 193 } |
| 178 | 194 |
| 179 } // namespace platform_util | 195 } // namespace platform_util |
| OLD | NEW |