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

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

Issue 8457004: platform_util::OpenItem fixes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: update comments Created 9 years, 1 month 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/file_path.h" 13 #include "base/file_path.h"
13 #include "base/file_util.h" 14 #include "base/file_util.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/string_util.h" 16 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
17 #include "base/win/registry.h" 18 #include "base/win/registry.h"
18 #include "base/win/scoped_co_mem.h" 19 #include "base/win/scoped_co_mem.h"
19 #include "base/win/scoped_comptr.h" 20 #include "base/win/scoped_comptr.h"
21 #include "content/public/browser/browser_thread.h"
20 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
21 #include "ui/base/win/shell.h" 23 #include "ui/base/win/shell.h"
22 #include "ui/gfx/native_widget_types.h" 24 #include "ui/gfx/native_widget_types.h"
23 25
24 namespace platform_util { 26 using content::BrowserThread;
25 27
26 void ShowItemInFolder(const FilePath& full_path) { 28 namespace {
29
30 void ShowItemInFolderOnFileThread(const FilePath& full_path) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
27 FilePath dir = full_path.DirName(); 32 FilePath dir = full_path.DirName();
28 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". 33 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\".
29 if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir)) 34 if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir))
30 return; 35 return;
31 36
32 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( 37 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)(
33 PCIDLIST_ABSOLUTE pidl_Folder, 38 PCIDLIST_ABSOLUTE pidl_Folder,
34 UINT cidl, 39 UINT cidl,
35 PCUITEMID_CHILD_ARRAY pidls, 40 PCUITEMID_CHILD_ARRAY pidls,
36 DWORD flags); 41 DWORD flags);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 << "(): Can't open full_path = \"" 105 << "(): Can't open full_path = \""
101 << full_path.value() << "\"" 106 << full_path.value() << "\""
102 << " hr = " << hr 107 << " hr = " << hr
103 << " " << reinterpret_cast<LPTSTR>(&message); 108 << " " << reinterpret_cast<LPTSTR>(&message);
104 if (message) 109 if (message)
105 LocalFree(message); 110 LocalFree(message);
106 } 111 }
107 } 112 }
108 } 113 }
109 114
115 } // namespace
116
117 namespace platform_util {
118
119 void ShowItemInFolder(const FilePath& full_path) {
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
121 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
122 base::Bind(&ShowItemInFolderOnFileThread, full_path));
123 }
124
110 void OpenItem(const FilePath& full_path) { 125 void OpenItem(const FilePath& full_path) {
111 ui::win::OpenItemViaShell(full_path); 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
127 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
128 base::Bind(&ui::win::OpenItemViaShell, full_path));
112 } 129 }
113 130
114 void OpenExternal(const GURL& url) { 131 void OpenExternal(const GURL& url) {
115 // Quote the input scheme to be sure that the command does not have 132 // Quote the input scheme to be sure that the command does not have
116 // parameters unexpected by the external program. This url should already 133 // parameters unexpected by the external program. This url should already
117 // have been escaped. 134 // have been escaped.
118 std::string escaped_url = url.spec(); 135 std::string escaped_url = url.spec();
119 escaped_url.insert(0, "\""); 136 escaped_url.insert(0, "\"");
120 escaped_url += "\""; 137 escaped_url += "\"";
121 138
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 void ActivateWindow(gfx::NativeWindow window) { 187 void ActivateWindow(gfx::NativeWindow window) {
171 ::SetForegroundWindow(window); 188 ::SetForegroundWindow(window);
172 } 189 }
173 190
174 bool IsVisible(gfx::NativeView view) { 191 bool IsVisible(gfx::NativeView view) {
175 // MSVC complains if we don't include != 0. 192 // MSVC complains if we don't include != 0.
176 return ::IsWindowVisible(view) != 0; 193 return ::IsWindowVisible(view) != 0;
177 } 194 }
178 195
179 } // namespace platform_util 196 } // namespace platform_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698