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

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

Issue 107033003: Stop using GetDefaultProfile() in Chrome OS implementation of platform_util::OpenExternal() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove is_valid check Created 7 years 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>
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 key.Open(HKEY_CLASSES_ROOT, registry_path.c_str(), KEY_READ); 122 key.Open(HKEY_CLASSES_ROOT, registry_path.c_str(), KEY_READ);
123 if (!key.Valid()) 123 if (!key.Valid())
124 return false; 124 return false;
125 DWORD size = 0; 125 DWORD size = 0;
126 key.ReadValue(NULL, NULL, &size, NULL); 126 key.ReadValue(NULL, NULL, &size, NULL);
127 if (size <= 2) 127 if (size <= 2)
128 return false; 128 return false;
129 return true; 129 return true;
130 } 130 }
131 131
132 } // namespace 132 void OpenExternalOnFileThread(const GURL& url) {
133
134 namespace platform_util {
135
136 void ShowItemInFolder(const base::FilePath& full_path) {
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
138
139 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
140 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
141
142 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
143 base::Bind(&ShowItemInFolderOnFileThread, full_path));
144 }
145
146 void OpenItem(const base::FilePath& full_path) {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
148
149 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
150 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
151
152 BrowserThread::PostTask(
153 BrowserThread::FILE, FROM_HERE,
154 base::Bind(base::IgnoreResult(&ui::win::OpenItemViaShell), full_path));
155 }
156
157 void OpenExternal(const GURL& url) {
158 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
159 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
160
161 // Quote the input scheme to be sure that the command does not have 133 // Quote the input scheme to be sure that the command does not have
162 // parameters unexpected by the external program. This url should already 134 // parameters unexpected by the external program. This url should already
163 // have been escaped. 135 // have been escaped.
164 std::string escaped_url = url.spec(); 136 std::string escaped_url = url.spec();
165 escaped_url.insert(0, "\""); 137 escaped_url.insert(0, "\"");
166 escaped_url += "\""; 138 escaped_url += "\"";
167 139
168 // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp: 140 // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp:
169 // "Some versions of windows (Win2k before SP3, Win XP before SP1) crash in 141 // "Some versions of windows (Win2k before SP3, Win XP before SP1) crash in
170 // ShellExecute on long URLs (bug 161357 on bugzilla.mozilla.org). IE 5 and 6 142 // ShellExecute on long URLs (bug 161357 on bugzilla.mozilla.org). IE 5 and 6
(...skipping 12 matching lines...) Expand all
183 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", 155 if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open",
184 escaped_url.c_str(), NULL, NULL, 156 escaped_url.c_str(), NULL, NULL,
185 SW_SHOWNORMAL)) <= 32) { 157 SW_SHOWNORMAL)) <= 32) {
186 // We fail to execute the call. We could display a message to the user. 158 // We fail to execute the call. We could display a message to the user.
187 // TODO(nsylvain): we should also add a dialog to warn on errors. See 159 // TODO(nsylvain): we should also add a dialog to warn on errors. See
188 // bug 1136923. 160 // bug 1136923.
189 return; 161 return;
190 } 162 }
191 } 163 }
192 164
165 } // namespace
166
167 namespace platform_util {
168
169 void ShowItemInFolder(const base::FilePath& full_path) {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
171
172 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
173 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
174
175 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
176 base::Bind(&ShowItemInFolderOnFileThread, full_path));
177 }
178
179 void OpenItem(const base::FilePath& full_path) {
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
181
182 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
183 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
184
185 BrowserThread::PostTask(
186 BrowserThread::FILE, FROM_HERE,
187 base::Bind(base::IgnoreResult(&ui::win::OpenItemViaShell), full_path));
188 }
189
190 void OpenExternal(Profile* profile, const GURL& url) {
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
192
193 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
194 chrome::ActivateDesktopHelper(chrome::ASH_KEEP_RUNNING);
195
196 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
197 base::Bind(&OpenExternalOnFileThread, url));
198 }
199
193 #if !defined(USE_AURA) 200 #if !defined(USE_AURA)
194 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { 201 gfx::NativeWindow GetTopLevel(gfx::NativeView view) {
195 return ::GetAncestor(view, GA_ROOT); 202 return ::GetAncestor(view, GA_ROOT);
196 } 203 }
197 204
198 gfx::NativeView GetParent(gfx::NativeView view) { 205 gfx::NativeView GetParent(gfx::NativeView view) {
199 return ::GetParent(view); 206 return ::GetParent(view);
200 } 207 }
201 208
202 bool IsWindowActive(gfx::NativeWindow window) { 209 bool IsWindowActive(gfx::NativeWindow window) {
203 return ::GetForegroundWindow() == window; 210 return ::GetForegroundWindow() == window;
204 } 211 }
205 212
206 void ActivateWindow(gfx::NativeWindow window) { 213 void ActivateWindow(gfx::NativeWindow window) {
207 ::SetForegroundWindow(window); 214 ::SetForegroundWindow(window);
208 } 215 }
209 216
210 bool IsVisible(gfx::NativeView view) { 217 bool IsVisible(gfx::NativeView view) {
211 // MSVC complains if we don't include != 0. 218 // MSVC complains if we don't include != 0.
212 return ::IsWindowVisible(view) != 0; 219 return ::IsWindowVisible(view) != 0;
213 } 220 }
214 #endif 221 #endif
215 222
216 } // namespace platform_util 223 } // namespace platform_util
OLDNEW
« no previous file with comments | « chrome/browser/platform_util_mac.mm ('k') | chrome/browser/ui/apps/chrome_shell_window_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698