Chromium Code Reviews| 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; | |
|
darin (slow to review)
2013/01/08 06:00:14
nit: 2 space indent
cpu_(ooo_6.6-7.5)
2013/01/08 19:01:16
Done.
| |
| 130 return true; | |
| 131 } | |
| 116 } // namespace | 132 } // namespace |
|
darin (slow to review)
2013/01/08 06:00:14
nit: new line before close of namespace
cpu_(ooo_6.6-7.5)
2013/01/08 19:01:16
Done.
| |
| 117 | 133 |
| 118 namespace platform_util { | 134 namespace platform_util { |
| 119 | 135 |
| 120 void ShowItemInFolder(const FilePath& full_path) { | 136 void ShowItemInFolder(const FilePath& full_path) { |
| 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 122 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 138 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 123 base::Bind(&ShowItemInFolderOnFileThread, full_path)); | 139 base::Bind(&ShowItemInFolderOnFileThread, full_path)); |
| 124 } | 140 } |
| 125 | 141 |
| 126 void OpenItem(const FilePath& full_path) { | 142 void OpenItem(const FilePath& full_path) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 141 // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp: | 157 // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp: |
| 142 // "Some versions of windows (Win2k before SP3, Win XP before SP1) crash in | 158 // "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 | 159 // 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." | 160 // support URLS of 2083 chars in length, 2K is safe." |
| 145 const size_t kMaxUrlLength = 2048; | 161 const size_t kMaxUrlLength = 2048; |
| 146 if (escaped_url.length() > kMaxUrlLength) { | 162 if (escaped_url.length() > kMaxUrlLength) { |
| 147 NOTREACHED(); | 163 NOTREACHED(); |
| 148 return; | 164 return; |
| 149 } | 165 } |
| 150 | 166 |
| 151 base::win::RegKey key; | 167 if (base::win::GetVersion() < base::win::VERSION_WIN7) { |
|
darin (slow to review)
2013/01/08 06:00:14
Why less than Win7 and not less than Win8? Win7 a
cpu_(ooo_6.6-7.5)
2013/01/08 19:01:16
Yes.
| |
| 152 std::wstring registry_path = ASCIIToWide(url.scheme()) + | 168 if (!ValidateShellCommandForScheme(url.scheme())) |
|
jschuh
2013/01/08 04:06:00
I feel like Nicolas should sign off on this one gi
cpu_(ooo_6.6-7.5)
2013/01/08 19:01:16
Ok, I'll ping him.
jschuh
2013/01/08 19:22:37
I'm pretty sure I typed that after you handed me a
| |
| 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; | 169 return; |
| 164 } | |
| 165 } | 170 } |
| 166 | 171 |
| 167 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", | 172 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", |
| 168 escaped_url.c_str(), NULL, NULL, | 173 escaped_url.c_str(), NULL, NULL, |
| 169 SW_SHOWNORMAL)) <= 32) { | 174 SW_SHOWNORMAL)) <= 32) { |
| 170 // We fail to execute the call. We could display a message to the user. | 175 // 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 | 176 // TODO(nsylvain): we should also add a dialog to warn on errors. See |
| 172 // bug 1136923. | 177 // bug 1136923. |
| 173 return; | 178 return; |
| 174 } | 179 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 191 ::SetForegroundWindow(window); | 196 ::SetForegroundWindow(window); |
| 192 } | 197 } |
| 193 | 198 |
| 194 bool IsVisible(gfx::NativeView view) { | 199 bool IsVisible(gfx::NativeView view) { |
| 195 // MSVC complains if we don't include != 0. | 200 // MSVC complains if we don't include != 0. |
| 196 return ::IsWindowVisible(view) != 0; | 201 return ::IsWindowVisible(view) != 0; |
| 197 } | 202 } |
| 198 #endif | 203 #endif |
| 199 | 204 |
| 200 } // namespace platform_util | 205 } // namespace platform_util |
| OLD | NEW |