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 #include <stddef.h> | 11 #include <stddef.h> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
22 #include "base/win/scoped_co_mem.h" | 22 #include "base/win/scoped_co_mem.h" |
23 #include "base/win/scoped_comptr.h" | 23 #include "base/win/scoped_comptr.h" |
24 #include "base/win/windows_version.h" | |
25 #include "chrome/browser/lifetime/application_lifetime.h" | 24 #include "chrome/browser/lifetime/application_lifetime.h" |
26 #include "chrome/browser/platform_util_internal.h" | 25 #include "chrome/browser/platform_util_internal.h" |
27 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
28 #include "ui/base/win/shell.h" | 27 #include "ui/base/win/shell.h" |
29 #include "ui/gfx/native_widget_types.h" | 28 #include "ui/gfx/native_widget_types.h" |
30 #include "url/gurl.h" | 29 #include "url/gurl.h" |
31 | 30 |
32 using content::BrowserThread; | 31 using content::BrowserThread; |
33 | 32 |
34 namespace platform_util { | 33 namespace platform_util { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if (hr == ERROR_FILE_NOT_FOUND) { | 102 if (hr == ERROR_FILE_NOT_FOUND) { |
104 ShellExecute(NULL, L"open", dir.value().c_str(), NULL, NULL, SW_SHOW); | 103 ShellExecute(NULL, L"open", dir.value().c_str(), NULL, NULL, SW_SHOW); |
105 } else { | 104 } else { |
106 LOG(WARNING) << " " << __func__ << "(): Can't open full_path = \"" | 105 LOG(WARNING) << " " << __func__ << "(): Can't open full_path = \"" |
107 << full_path.value() << "\"" | 106 << full_path.value() << "\"" |
108 << " hr = " << logging::SystemErrorCodeToString(hr); | 107 << " hr = " << logging::SystemErrorCodeToString(hr); |
109 } | 108 } |
110 } | 109 } |
111 } | 110 } |
112 | 111 |
113 // Old ShellExecute crashes the process when the command for a given scheme | |
114 // is empty. This function tells if it is. | |
115 bool ValidateShellCommandForScheme(const std::string& scheme) { | |
116 base::win::RegKey key; | |
117 base::string16 registry_path = base::ASCIIToUTF16(scheme) + | |
118 L"\\shell\\open\\command"; | |
119 key.Open(HKEY_CLASSES_ROOT, registry_path.c_str(), KEY_READ); | |
120 if (!key.Valid()) | |
121 return false; | |
122 DWORD size = 0; | |
123 key.ReadValue(NULL, NULL, &size, NULL); | |
124 if (size <= 2) | |
125 return false; | |
126 return true; | |
127 } | |
128 | |
129 void OpenExternalOnFileThread(const GURL& url) { | 112 void OpenExternalOnFileThread(const GURL& url) { |
130 // Quote the input scheme to be sure that the command does not have | 113 // Quote the input scheme to be sure that the command does not have |
131 // parameters unexpected by the external program. This url should already | 114 // parameters unexpected by the external program. This url should already |
132 // have been escaped. | 115 // have been escaped. |
133 std::string escaped_url = url.spec(); | 116 std::string escaped_url = url.spec(); |
134 escaped_url.insert(0, "\""); | 117 escaped_url.insert(0, "\""); |
135 escaped_url += "\""; | 118 escaped_url += "\""; |
136 | 119 |
137 // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp: | 120 // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp: |
138 // "Some versions of windows (Win2k before SP3, Win XP before SP1) crash in | 121 // "Some versions of windows (Win2k before SP3, Win XP before SP1) crash in |
139 // ShellExecute on long URLs (bug 161357 on bugzilla.mozilla.org). IE 5 and 6 | 122 // ShellExecute on long URLs (bug 161357 on bugzilla.mozilla.org). IE 5 and 6 |
140 // support URLS of 2083 chars in length, 2K is safe." | 123 // support URLS of 2083 chars in length, 2K is safe." |
141 const size_t kMaxUrlLength = 2048; | 124 const size_t kMaxUrlLength = 2048; |
142 if (escaped_url.length() > kMaxUrlLength) { | 125 if (escaped_url.length() > kMaxUrlLength) { |
143 NOTREACHED(); | 126 NOTREACHED(); |
144 return; | 127 return; |
145 } | 128 } |
146 | 129 |
147 if (base::win::GetVersion() < base::win::VERSION_WIN7) { | |
148 if (!ValidateShellCommandForScheme(url.scheme())) | |
149 return; | |
150 } | |
151 | |
152 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", | 130 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", |
153 escaped_url.c_str(), NULL, NULL, | 131 escaped_url.c_str(), NULL, NULL, |
154 SW_SHOWNORMAL)) <= 32) { | 132 SW_SHOWNORMAL)) <= 32) { |
155 // We fail to execute the call. We could display a message to the user. | 133 // We fail to execute the call. We could display a message to the user. |
156 // TODO(nsylvain): we should also add a dialog to warn on errors. See | 134 // TODO(nsylvain): we should also add a dialog to warn on errors. See |
157 // bug 1136923. | 135 // bug 1136923. |
158 return; | 136 return; |
159 } | 137 } |
160 } | 138 } |
161 | 139 |
(...skipping 21 matching lines...) Expand all Loading... |
183 } // namespace internal | 161 } // namespace internal |
184 | 162 |
185 void OpenExternal(Profile* profile, const GURL& url) { | 163 void OpenExternal(Profile* profile, const GURL& url) { |
186 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 164 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
187 | 165 |
188 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 166 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
189 base::Bind(&OpenExternalOnFileThread, url)); | 167 base::Bind(&OpenExternalOnFileThread, url)); |
190 } | 168 } |
191 | 169 |
192 } // namespace platform_util | 170 } // namespace platform_util |
OLD | NEW |