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/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/field_trial.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "base/win/registry.h" | 19 #include "base/win/registry.h" |
19 #include "base/win/scoped_co_mem.h" | 20 #include "base/win/scoped_co_mem.h" |
20 #include "base/win/scoped_comptr.h" | 21 #include "base/win/scoped_comptr.h" |
21 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
22 #include "chrome/browser/lifetime/application_lifetime.h" | 23 #include "chrome/browser/lifetime/application_lifetime.h" |
23 #include "chrome/browser/ui/host_desktop.h" | 24 #include "chrome/browser/ui/host_desktop.h" |
| 25 #include "chrome/common/chrome_utility_messages.h" |
24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/utility_process_host.h" |
25 #include "ui/base/win/shell.h" | 28 #include "ui/base/win/shell.h" |
26 #include "ui/gfx/native_widget_types.h" | 29 #include "ui/gfx/native_widget_types.h" |
27 #include "url/gurl.h" | 30 #include "url/gurl.h" |
28 | 31 |
29 using content::BrowserThread; | 32 using content::BrowserThread; |
30 | 33 |
31 namespace { | 34 namespace { |
32 | 35 |
33 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) { | 36 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", | 151 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", |
149 escaped_url.c_str(), NULL, NULL, | 152 escaped_url.c_str(), NULL, NULL, |
150 SW_SHOWNORMAL)) <= 32) { | 153 SW_SHOWNORMAL)) <= 32) { |
151 // We fail to execute the call. We could display a message to the user. | 154 // We fail to execute the call. We could display a message to the user. |
152 // TODO(nsylvain): we should also add a dialog to warn on errors. See | 155 // TODO(nsylvain): we should also add a dialog to warn on errors. See |
153 // bug 1136923. | 156 // bug 1136923. |
154 return; | 157 return; |
155 } | 158 } |
156 } | 159 } |
157 | 160 |
| 161 void OpenItemViaShellInUtilityProcess(const base::FilePath& full_path) { |
| 162 base::WeakPtr<content::UtilityProcessHost> utility_process_host( |
| 163 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr()); |
| 164 utility_process_host->DisableSandbox(); |
| 165 utility_process_host->Send(new ChromeUtilityMsg_OpenItemViaShell(full_path)); |
| 166 } |
| 167 |
158 } // namespace | 168 } // namespace |
159 | 169 |
160 namespace platform_util { | 170 namespace platform_util { |
161 | 171 |
162 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { | 172 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
164 | 174 |
165 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) | 175 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
166 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); | 176 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); |
167 | 177 |
168 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 178 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
169 base::Bind(&ShowItemInFolderOnFileThread, full_path)); | 179 base::Bind(&ShowItemInFolderOnFileThread, full_path)); |
170 } | 180 } |
171 | 181 |
172 void OpenItem(Profile* profile, const base::FilePath& full_path) { | 182 void OpenItem(Profile* profile, const base::FilePath& full_path) { |
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
174 | 184 |
175 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) | 185 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
176 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); | 186 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); |
177 | 187 |
178 BrowserThread::PostTask( | 188 if (base::FieldTrialList::FindFullName("IsolateShellOperations") == |
179 BrowserThread::FILE, FROM_HERE, | 189 "Enabled") { |
180 base::Bind(base::IgnoreResult(&ui::win::OpenItemViaShell), full_path)); | 190 BrowserThread::PostTask( |
| 191 BrowserThread::IO, |
| 192 FROM_HERE, |
| 193 base::Bind(&OpenItemViaShellInUtilityProcess, full_path)); |
| 194 } else { |
| 195 BrowserThread::PostTask( |
| 196 BrowserThread::FILE, |
| 197 FROM_HERE, |
| 198 base::Bind(base::IgnoreResult(&ui::win::OpenItemViaShell), full_path)); |
| 199 } |
181 } | 200 } |
182 | 201 |
183 void OpenExternal(Profile* profile, const GURL& url) { | 202 void OpenExternal(Profile* profile, const GURL& url) { |
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
185 | 204 |
186 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH && | 205 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH && |
187 !url.SchemeIsHTTPOrHTTPS()) | 206 !url.SchemeIsHTTPOrHTTPS()) |
188 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); | 207 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); |
189 | 208 |
190 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 209 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
(...skipping 17 matching lines...) Expand all Loading... |
208 ::SetForegroundWindow(window); | 227 ::SetForegroundWindow(window); |
209 } | 228 } |
210 | 229 |
211 bool IsVisible(gfx::NativeView view) { | 230 bool IsVisible(gfx::NativeView view) { |
212 // MSVC complains if we don't include != 0. | 231 // MSVC complains if we don't include != 0. |
213 return ::IsWindowVisible(view) != 0; | 232 return ::IsWindowVisible(view) != 0; |
214 } | 233 } |
215 #endif | 234 #endif |
216 | 235 |
217 } // namespace platform_util | 236 } // namespace platform_util |
OLD | NEW |