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> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 static bool initialize_open_folder_proc = true; | 55 static bool initialize_open_folder_proc = true; |
56 if (initialize_open_folder_proc) { | 56 if (initialize_open_folder_proc) { |
57 initialize_open_folder_proc = false; | 57 initialize_open_folder_proc = false; |
58 // The SHOpenFolderAndSelectItems API is exposed by shell32 version 6 | 58 // The SHOpenFolderAndSelectItems API is exposed by shell32 version 6 |
59 // and does not exist in Win2K. We attempt to retrieve this function export | 59 // and does not exist in Win2K. We attempt to retrieve this function export |
60 // from shell32 and if it does not exist, we just invoke ShellExecute to | 60 // from shell32 and if it does not exist, we just invoke ShellExecute to |
61 // open the folder thus losing the functionality to select the item in | 61 // open the folder thus losing the functionality to select the item in |
62 // the process. | 62 // the process. |
63 HMODULE shell32_base = GetModuleHandle(L"shell32.dll"); | 63 HMODULE shell32_base = GetModuleHandle(L"shell32.dll"); |
64 if (!shell32_base) { | 64 if (!shell32_base) { |
65 NOTREACHED() << " " << __FUNCTION__ << "(): Can't open shell32.dll"; | 65 NOTREACHED() << " " << __func__ << "(): Can't open shell32.dll"; |
66 return; | 66 return; |
67 } | 67 } |
68 open_folder_and_select_itemsPtr = | 68 open_folder_and_select_itemsPtr = |
69 reinterpret_cast<SHOpenFolderAndSelectItemsFuncPtr> | 69 reinterpret_cast<SHOpenFolderAndSelectItemsFuncPtr> |
70 (GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems")); | 70 (GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems")); |
71 } | 71 } |
72 if (!open_folder_and_select_itemsPtr) { | 72 if (!open_folder_and_select_itemsPtr) { |
73 ShellExecute(NULL, L"open", dir.value().c_str(), NULL, NULL, SW_SHOW); | 73 ShellExecute(NULL, L"open", dir.value().c_str(), NULL, NULL, SW_SHOW); |
74 return; | 74 return; |
75 } | 75 } |
(...skipping 22 matching lines...) Expand all Loading... |
98 hr = (*open_folder_and_select_itemsPtr)(dir_item, arraysize(highlight), | 98 hr = (*open_folder_and_select_itemsPtr)(dir_item, arraysize(highlight), |
99 highlight, NULL); | 99 highlight, NULL); |
100 | 100 |
101 if (FAILED(hr)) { | 101 if (FAILED(hr)) { |
102 // On some systems, the above call mysteriously fails with "file not | 102 // On some systems, the above call mysteriously fails with "file not |
103 // found" even though the file is there. In these cases, ShellExecute() | 103 // found" even though the file is there. In these cases, ShellExecute() |
104 // seems to work as a fallback (although it won't select the file). | 104 // seems to work as a fallback (although it won't select the file). |
105 if (hr == ERROR_FILE_NOT_FOUND) { | 105 if (hr == ERROR_FILE_NOT_FOUND) { |
106 ShellExecute(NULL, L"open", dir.value().c_str(), NULL, NULL, SW_SHOW); | 106 ShellExecute(NULL, L"open", dir.value().c_str(), NULL, NULL, SW_SHOW); |
107 } else { | 107 } else { |
108 LOG(WARNING) << " " << __FUNCTION__ << "(): Can't open full_path = \"" | 108 LOG(WARNING) << " " << __func__ << "(): Can't open full_path = \"" |
109 << full_path.value() << "\"" | 109 << full_path.value() << "\"" |
110 << " hr = " << logging::SystemErrorCodeToString(hr); | 110 << " hr = " << logging::SystemErrorCodeToString(hr); |
111 } | 111 } |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 // Old ShellExecute crashes the process when the command for a given scheme | 115 // Old ShellExecute crashes the process when the command for a given scheme |
116 // is empty. This function tells if it is. | 116 // is empty. This function tells if it is. |
117 bool ValidateShellCommandForScheme(const std::string& scheme) { | 117 bool ValidateShellCommandForScheme(const std::string& scheme) { |
118 base::win::RegKey key; | 118 base::win::RegKey key; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } // namespace internal | 185 } // namespace internal |
186 | 186 |
187 void OpenExternal(Profile* profile, const GURL& url) { | 187 void OpenExternal(Profile* profile, const GURL& url) { |
188 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 188 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
189 | 189 |
190 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 190 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
191 base::Bind(&OpenExternalOnFileThread, url)); | 191 base::Bind(&OpenExternalOnFileThread, url)); |
192 } | 192 } |
193 | 193 |
194 } // namespace platform_util | 194 } // namespace platform_util |
OLD | NEW |