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/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "base/win/registry.h" | 19 #include "base/win/registry.h" |
20 #include "base/win/scoped_co_mem.h" | 20 #include "base/win/scoped_co_mem.h" |
21 #include "base/win/scoped_comptr.h" | 21 #include "base/win/scoped_comptr.h" |
| 22 #include "base/win/windows_version.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
24 #include "ui/base/win/shell.h" | 25 #include "ui/base/win/shell.h" |
25 #include "ui/gfx/native_widget_types.h" | 26 #include "ui/gfx/native_widget_types.h" |
26 | 27 |
27 using content::BrowserThread; | 28 using content::BrowserThread; |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 void ShowItemInFolderOnFileThread(const FilePath& full_path) { | 32 void ShowItemInFolderOnFileThread(const FilePath& full_path) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 << "(): Can't open full_path = \"" | 107 << "(): Can't open full_path = \"" |
107 << full_path.value() << "\"" | 108 << full_path.value() << "\"" |
108 << " hr = " << hr | 109 << " hr = " << hr |
109 << " " << reinterpret_cast<LPTSTR>(&message); | 110 << " " << reinterpret_cast<LPTSTR>(&message); |
110 if (message) | 111 if (message) |
111 LocalFree(message); | 112 LocalFree(message); |
112 } | 113 } |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
| 117 // Old ShellExecute crashes the process when the command for a given scheme |
| 118 // is empty. This function tells if it is. |
| 119 bool ValidateShellCommandForScheme(const std::string& scheme) { |
| 120 base::win::RegKey key; |
| 121 std::wstring registry_path = ASCIIToWide(scheme) + |
| 122 L"\\shell\\open\\command"; |
| 123 key.Open(HKEY_CLASSES_ROOT, registry_path.c_str(), KEY_READ); |
| 124 if (!key.Valid()) |
| 125 return false; |
| 126 DWORD size = 0; |
| 127 key.ReadValue(NULL, NULL, &size, NULL); |
| 128 if (size <= 2) |
| 129 return false; |
| 130 return true; |
| 131 } |
| 132 |
116 } // namespace | 133 } // namespace |
117 | 134 |
118 namespace platform_util { | 135 namespace platform_util { |
119 | 136 |
120 void ShowItemInFolder(const FilePath& full_path) { | 137 void ShowItemInFolder(const FilePath& full_path) { |
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
122 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 139 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
123 base::Bind(&ShowItemInFolderOnFileThread, full_path)); | 140 base::Bind(&ShowItemInFolderOnFileThread, full_path)); |
124 } | 141 } |
125 | 142 |
(...skipping 15 matching lines...) Expand all Loading... |
141 // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp: | 158 // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp: |
142 // "Some versions of windows (Win2k before SP3, Win XP before SP1) crash in | 159 // "Some versions of windows (Win2k before SP3, Win XP before SP1) crash in |
143 // ShellExecute on long URLs (bug 161357 on bugzilla.mozilla.org). IE 5 and 6 | 160 // ShellExecute on long URLs (bug 161357 on bugzilla.mozilla.org). IE 5 and 6 |
144 // support URLS of 2083 chars in length, 2K is safe." | 161 // support URLS of 2083 chars in length, 2K is safe." |
145 const size_t kMaxUrlLength = 2048; | 162 const size_t kMaxUrlLength = 2048; |
146 if (escaped_url.length() > kMaxUrlLength) { | 163 if (escaped_url.length() > kMaxUrlLength) { |
147 NOTREACHED(); | 164 NOTREACHED(); |
148 return; | 165 return; |
149 } | 166 } |
150 | 167 |
151 base::win::RegKey key; | 168 if (base::win::GetVersion() < base::win::VERSION_WIN7) { |
152 std::wstring registry_path = ASCIIToWide(url.scheme()) + | 169 if (!ValidateShellCommandForScheme(url.scheme())) |
153 L"\\shell\\open\\command"; | |
154 key.Open(HKEY_CLASSES_ROOT, registry_path.c_str(), KEY_READ); | |
155 if (key.Valid()) { | |
156 DWORD size = 0; | |
157 key.ReadValue(NULL, NULL, &size, NULL); | |
158 if (size <= 2) { | |
159 // ShellExecute crashes the process when the command is empty. | |
160 // We check for "2" because it always returns the trailing NULL. | |
161 // TODO(nsylvain): we should also add a dialog to warn on errors. See | |
162 // bug 1136923. | |
163 return; | 170 return; |
164 } | |
165 } | 171 } |
166 | 172 |
167 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", | 173 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", |
168 escaped_url.c_str(), NULL, NULL, | 174 escaped_url.c_str(), NULL, NULL, |
169 SW_SHOWNORMAL)) <= 32) { | 175 SW_SHOWNORMAL)) <= 32) { |
170 // We fail to execute the call. We could display a message to the user. | 176 // We fail to execute the call. We could display a message to the user. |
171 // TODO(nsylvain): we should also add a dialog to warn on errors. See | 177 // TODO(nsylvain): we should also add a dialog to warn on errors. See |
172 // bug 1136923. | 178 // bug 1136923. |
173 return; | 179 return; |
174 } | 180 } |
(...skipping 16 matching lines...) Expand all Loading... |
191 ::SetForegroundWindow(window); | 197 ::SetForegroundWindow(window); |
192 } | 198 } |
193 | 199 |
194 bool IsVisible(gfx::NativeView view) { | 200 bool IsVisible(gfx::NativeView view) { |
195 // MSVC complains if we don't include != 0. | 201 // MSVC complains if we don't include != 0. |
196 return ::IsWindowVisible(view) != 0; | 202 return ::IsWindowVisible(view) != 0; |
197 } | 203 } |
198 #endif | 204 #endif |
199 | 205 |
200 } // namespace platform_util | 206 } // namespace platform_util |
OLD | NEW |