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

Unified Diff: chrome/common/platform_util_win.cc

Issue 177040: Linux: handle external protocols, e.g. mailto: links. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/platform_util_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/platform_util_win.cc
===================================================================
--- chrome/common/platform_util_win.cc (revision 24928)
+++ chrome/common/platform_util_win.cc (working copy)
@@ -16,7 +16,9 @@
#include "base/file_util.h"
#include "base/gfx/native_widget_types.h"
#include "base/logging.h"
+#include "base/registry.h"
#include "base/string_util.h"
+#include "googleurl/src/gurl.h"
namespace platform_util {
@@ -86,6 +88,50 @@
win_util::OpenItemViaShell(full_path);
}
+void OpenExternal(const GURL& url) {
+ // Quote the input scheme to be sure that the command does not have
+ // parameters unexpected by the external program. This url should already
+ // have been escaped.
+ std::string escaped_url = url.spec();
+ escaped_url.insert(0, "\"");
+ escaped_url += "\"";
+
+ // According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp:
+ // "Some versions of windows (Win2k before SP3, Win XP before SP1) crash in
+ // ShellExecute on long URLs (bug 161357 on bugzilla.mozilla.org). IE 5 and 6
+ // support URLS of 2083 chars in length, 2K is safe."
+ const size_t kMaxUrlLength = 2048;
+ if (escaped_url.length() > kMaxUrlLength) {
+ NOTREACHED();
+ return;
+ }
+
+ RegKey key;
+ std::wstring registry_path = ASCIIToWide(url.scheme()) +
+ L"\\shell\\open\\command";
+ key.Open(HKEY_CLASSES_ROOT, registry_path.c_str());
+ if (key.Valid()) {
+ DWORD size = 0;
+ key.ReadValue(NULL, NULL, &size);
+ if (size <= 2) {
+ // ShellExecute crashes the process when the command is empty.
+ // We check for "2" because it always returns the trailing NULL.
+ // TODO(nsylvain): we should also add a dialog to warn on errors. See
+ // bug 1136923.
+ return;
+ }
+ }
+
+ if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open",
+ escaped_url.c_str(), NULL, NULL,
+ SW_SHOWNORMAL)) <= 32) {
+ // We fail to execute the call. We could display a message to the user.
+ // TODO(nsylvain): we should also add a dialog to warn on errors. See
+ // bug 1136923.
+ return;
+ }
+}
+
gfx::NativeWindow GetTopLevel(gfx::NativeView view) {
return GetAncestor(view, GA_ROOT);
}
Property changes on: chrome/common/platform_util_win.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/common/platform_util_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698