Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/platform_util_win.cc

Issue 352393002: Be explicit about target type in platform_util::OpenItem() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/files/file_util.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"
25 #include "chrome/browser/platform_util_internal.h"
24 #include "chrome/browser/ui/host_desktop.h" 26 #include "chrome/browser/ui/host_desktop.h"
25 #include "chrome/common/chrome_utility_messages.h" 27 #include "chrome/common/chrome_utility_messages.h"
26 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/utility_process_host.h" 29 #include "content/public/browser/utility_process_host.h"
28 #include "content/public/browser/utility_process_host_client.h" 30 #include "content/public/browser/utility_process_host_client.h"
29 #include "ui/base/win/shell.h" 31 #include "ui/base/win/shell.h"
30 #include "ui/gfx/native_widget_types.h" 32 #include "ui/gfx/native_widget_types.h"
31 #include "url/gurl.h" 33 #include "url/gurl.h"
32 34
33 using content::BrowserThread; 35 using content::BrowserThread;
34 36
37 namespace platform_util {
38
35 namespace { 39 namespace {
36 40
37 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) { 41 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
39 base::FilePath dir = full_path.DirName().AsEndingWithSeparator(); 43 base::FilePath dir = full_path.DirName().AsEndingWithSeparator();
40 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". 44 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\".
41 if (dir.empty()) 45 if (dir.empty())
42 return; 46 return;
43 47
44 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( 48 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 163 }
160 } 164 }
161 165
162 void OpenItemViaShellInUtilityProcess(const base::FilePath& full_path) { 166 void OpenItemViaShellInUtilityProcess(const base::FilePath& full_path) {
163 base::WeakPtr<content::UtilityProcessHost> utility_process_host( 167 base::WeakPtr<content::UtilityProcessHost> utility_process_host(
164 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr()); 168 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr());
165 utility_process_host->DisableSandbox(); 169 utility_process_host->DisableSandbox();
166 utility_process_host->Send(new ChromeUtilityMsg_OpenItemViaShell(full_path)); 170 utility_process_host->Send(new ChromeUtilityMsg_OpenItemViaShell(full_path));
167 } 171 }
168 172
173 void OpenItemOnBlockingThread(const base::FilePath& path) {
174 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
175 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
176
177 if (base::FieldTrialList::FindFullName("IsolateShellOperations") ==
178 "Enabled") {
179 BrowserThread::PostTask(
180 BrowserThread::IO, FROM_HERE,
181 base::Bind(&OpenItemViaShellInUtilityProcess, path));
182 } else {
183 ui::win::OpenItemViaShell(path);
184 }
185 }
186
169 } // namespace 187 } // namespace
170 188
171 namespace platform_util {
172
173 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { 189 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
175 191
176 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) 192 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
177 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); 193 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
178 194
179 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 195 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
180 base::Bind(&ShowItemInFolderOnFileThread, full_path)); 196 base::Bind(&ShowItemInFolderOnFileThread, full_path));
181 } 197 }
182 198
183 void OpenItem(Profile* profile, const base::FilePath& full_path) { 199 namespace internal {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
185 200
186 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) 201 void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType) {
187 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); 202 OpenItemOnBlockingThread(path);
203 }
188 204
189 if (base::FieldTrialList::FindFullName("IsolateShellOperations") == 205 } // namespace internal
190 "Enabled") {
191 BrowserThread::PostTask(
192 BrowserThread::IO,
193 FROM_HERE,
194 base::Bind(&OpenItemViaShellInUtilityProcess, full_path));
195 } else {
196 BrowserThread::PostTask(
197 BrowserThread::FILE,
198 FROM_HERE,
199 base::Bind(base::IgnoreResult(&ui::win::OpenItemViaShell), full_path));
200 }
201 }
202 206
203 void OpenExternal(Profile* profile, const GURL& url) { 207 void OpenExternal(Profile* profile, const GURL& url) {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205 209
206 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH && 210 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH &&
207 !url.SchemeIsHTTPOrHTTPS()) 211 !url.SchemeIsHTTPOrHTTPS())
208 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING); 212 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
209 213
210 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 214 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
211 base::Bind(&OpenExternalOnFileThread, url)); 215 base::Bind(&OpenExternalOnFileThread, url));
(...skipping 16 matching lines...) Expand all
228 ::SetForegroundWindow(window); 232 ::SetForegroundWindow(window);
229 } 233 }
230 234
231 bool IsVisible(gfx::NativeView view) { 235 bool IsVisible(gfx::NativeView view) {
232 // MSVC complains if we don't include != 0. 236 // MSVC complains if we don't include != 0.
233 return ::IsWindowVisible(view) != 0; 237 return ::IsWindowVisible(view) != 0;
234 } 238 }
235 #endif 239 #endif
236 240
237 } // namespace platform_util 241 } // namespace platform_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698