| 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_util.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/win/registry.h" | 20 #include "base/win/registry.h" |
| 20 #include "base/win/scoped_co_mem.h" | 21 #include "base/win/scoped_co_mem.h" |
| 21 #include "base/win/scoped_comptr.h" | 22 #include "base/win/scoped_comptr.h" |
| 22 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 23 #include "chrome/browser/lifetime/application_lifetime.h" | 24 #include "chrome/browser/lifetime/application_lifetime.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 void OpenItemViaShellInUtilityProcess(const base::FilePath& full_path) { | 163 void OpenItemViaShellInUtilityProcess(const base::FilePath& full_path) { |
| 163 base::WeakPtr<content::UtilityProcessHost> utility_process_host( | 164 base::WeakPtr<content::UtilityProcessHost> utility_process_host( |
| 164 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr()); | 165 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr()); |
| 165 utility_process_host->DisableSandbox(); | 166 utility_process_host->DisableSandbox(); |
| 166 utility_process_host->Send(new ChromeUtilityMsg_OpenItemViaShell(full_path)); | 167 utility_process_host->Send(new ChromeUtilityMsg_OpenItemViaShell(full_path)); |
| 167 } | 168 } |
| 168 | 169 |
| 170 void OpenFileOnFileThread(const base::FilePath& path) { |
| 171 if (base::DirectoryExists(path) || !base::PathExists(path)) |
| 172 return; |
| 173 if (base::FieldTrialList::FindFullName("IsolateShellOperations") == |
| 174 "Enabled") { |
| 175 BrowserThread::PostTask( |
| 176 BrowserThread::IO, |
| 177 FROM_HERE, |
| 178 base::Bind(&OpenItemViaShellInUtilityProcess, path)); |
| 179 } else { |
| 180 ui::win::OpenItemViaShell(path); |
| 181 } |
| 182 } |
| 183 |
| 184 void OpenFolderOnFileThread(const base::FilePath& path) { |
| 185 if (!base::DirectoryExists(path)) |
| 186 return; |
| 187 ShellExecute(NULL, L"open", path.value().c_str(), NULL, NULL, SW_SHOW); |
| 188 } |
| 189 |
| 169 } // namespace | 190 } // namespace |
| 170 | 191 |
| 171 namespace platform_util { | 192 namespace platform_util { |
| 172 | 193 |
| 173 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { | 194 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { |
| 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 175 | 196 |
| 176 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) | 197 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
| 177 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); | 198 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); |
| 178 | 199 |
| 179 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 200 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 180 base::Bind(&ShowItemInFolderOnFileThread, full_path)); | 201 base::Bind(&ShowItemInFolderOnFileThread, full_path)); |
| 181 } | 202 } |
| 182 | 203 |
| 183 void OpenItem(Profile* profile, const base::FilePath& full_path) { | 204 void OpenFile(Profile* profile, const base::FilePath& full_path) { |
| 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 185 | 206 |
| 186 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) | 207 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
| 187 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); | 208 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); |
| 188 | 209 |
| 189 if (base::FieldTrialList::FindFullName("IsolateShellOperations") == | 210 BrowserThread::PostTask(BrowserThread::FILE, |
| 190 "Enabled") { | 211 FROM_HERE, |
| 191 BrowserThread::PostTask( | 212 base::Bind(&OpenFileOnFileThread, full_path)); |
| 192 BrowserThread::IO, | 213 } |
| 193 FROM_HERE, | 214 |
| 194 base::Bind(&OpenItemViaShellInUtilityProcess, full_path)); | 215 void OpenFolder(Profile* profile, const base::FilePath& full_path) { |
| 195 } else { | 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 196 BrowserThread::PostTask( | 217 |
| 197 BrowserThread::FILE, | 218 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
| 198 FROM_HERE, | 219 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); |
| 199 base::Bind(base::IgnoreResult(&ui::win::OpenItemViaShell), full_path)); | 220 |
| 200 } | 221 BrowserThread::PostTask(BrowserThread::FILE, |
| 222 FROM_HERE, |
| 223 base::Bind(&OpenFolderOnFileThread, full_path)); |
| 201 } | 224 } |
| 202 | 225 |
| 203 void OpenExternal(Profile* profile, const GURL& url) { | 226 void OpenExternal(Profile* profile, const GURL& url) { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 205 | 228 |
| 206 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH && | 229 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH && |
| 207 !url.SchemeIsHTTPOrHTTPS()) | 230 !url.SchemeIsHTTPOrHTTPS()) |
| 208 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); | 231 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); |
| 209 | 232 |
| 210 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 233 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 228 ::SetForegroundWindow(window); | 251 ::SetForegroundWindow(window); |
| 229 } | 252 } |
| 230 | 253 |
| 231 bool IsVisible(gfx::NativeView view) { | 254 bool IsVisible(gfx::NativeView view) { |
| 232 // MSVC complains if we don't include != 0. | 255 // MSVC complains if we don't include != 0. |
| 233 return ::IsWindowVisible(view) != 0; | 256 return ::IsWindowVisible(view) != 0; |
| 234 } | 257 } |
| 235 #endif | 258 #endif |
| 236 | 259 |
| 237 } // namespace platform_util | 260 } // namespace platform_util |
| OLD | NEW |