From 86338290fb41f4993c2859d920e581b49c75723d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 Jul 2016 17:11:05 +0900 Subject: [PATCH 1/2] win: Fix openExternal not working with non-ASCII characters --- .../atom_resource_dispatcher_host_delegate.cc | 9 ++++++- atom/common/api/atom_api_shell.cc | 9 ++++++- atom/common/platform_util.h | 14 +++++++++- atom/common/platform_util_win.cc | 26 ++++--------------- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc index 1115aa049d69..c64a21d26dd8 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.cc +++ b/atom/browser/atom_resource_dispatcher_host_delegate.cc @@ -7,6 +7,7 @@ #include "atom/browser/login_handler.h" #include "atom/browser/web_contents_permission_helper.h" #include "atom/common/platform_util.h" +#include "base/strings/utf_string_conversions.h" #include "content/public/browser/browser_thread.h" #include "net/base/escape.h" #include "url/gurl.h" @@ -20,7 +21,13 @@ namespace { void OnOpenExternal(const GURL& escaped_url, bool allowed) { if (allowed) - platform_util::OpenExternal(escaped_url, true); + platform_util::OpenExternal( +#if defined(OS_WIN) + base::UTF8ToUTF16(escaped_url.spec()), +#else + escaped_url, +#endif + true); } void HandleExternalProtocolInUI( diff --git a/atom/common/api/atom_api_shell.cc b/atom/common/api/atom_api_shell.cc index f99e2ba1854e..860787f17c8f 100644 --- a/atom/common/api/atom_api_shell.cc +++ b/atom/common/api/atom_api_shell.cc @@ -7,12 +7,19 @@ #include "atom/common/platform_util.h" #include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/gurl_converter.h" +#include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/node_includes.h" #include "native_mate/dictionary.h" namespace { -bool OpenExternal(const GURL& url, mate::Arguments* args) { +bool OpenExternal( +#if defined(OS_WIN) + const base::string16& url, +#else + const GURL& url, +#endif + mate::Arguments* args) { bool activate = true; if (args->Length() == 2) { mate::Dictionary options; diff --git a/atom/common/platform_util.h b/atom/common/platform_util.h index 4565221e9d84..262f0a2e6e49 100644 --- a/atom/common/platform_util.h +++ b/atom/common/platform_util.h @@ -5,6 +5,12 @@ #ifndef ATOM_COMMON_PLATFORM_UTIL_H_ #define ATOM_COMMON_PLATFORM_UTIL_H_ +#include "build/build_config.h" + +#if defined(OS_WIN) +#include "base/strings/string16.h" +#endif + class GURL; namespace base { @@ -23,7 +29,13 @@ void OpenItem(const base::FilePath& full_path); // Open the given external protocol URL in the desktop's default manner. // (For example, mailto: URLs in the default mail user agent.) -bool OpenExternal(const GURL& url, bool activate); +bool OpenExternal( +#if defined(OS_WIN) + const base::string16& url, +#else + const GURL& url, +#endif + bool activate); // Move a file to trash. bool MoveItemToTrash(const base::FilePath& full_path); diff --git a/atom/common/platform_util_win.cc b/atom/common/platform_util_win.cc index 12591a94d569..db3f81ab2769 100644 --- a/atom/common/platform_util_win.cc +++ b/atom/common/platform_util_win.cc @@ -24,8 +24,9 @@ #include "base/win/scoped_com_initializer.h" #include "base/win/scoped_comptr.h" #include "base/win/windows_version.h" -#include "url/gurl.h" +#include "net/base/escape.h" #include "ui/base/win/shell.h" +#include "url/gurl.h" namespace { @@ -301,30 +302,13 @@ void OpenItem(const base::FilePath& full_path) { ui::win::OpenFileViaShell(full_path); } -bool OpenExternal(const GURL& url, bool activate) { +bool OpenExternal(const base::string16& url, bool activate) { // 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 += "\""; + base::string16 escaped_url = L"\"" + url + L"\""; - // 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 false; - } - - if (base::win::GetVersion() < base::win::VERSION_WIN7) { - if (!ValidateShellCommandForScheme(url.scheme())) - return false; - } - - if (reinterpret_cast(ShellExecuteA(NULL, "open", + if (reinterpret_cast(ShellExecuteW(NULL, L"open", escaped_url.c_str(), NULL, NULL, SW_SHOWNORMAL)) <= 32) { // We fail to execute the call. We could display a message to the user. From 5208bbd2e8452bda91a6d7c100dd0b2fd31ffd86 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 Jul 2016 17:13:21 +0900 Subject: [PATCH 2/2] Remove unneeded include --- atom/common/platform_util_win.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/atom/common/platform_util_win.cc b/atom/common/platform_util_win.cc index db3f81ab2769..0795fcb72bff 100644 --- a/atom/common/platform_util_win.cc +++ b/atom/common/platform_util_win.cc @@ -24,7 +24,6 @@ #include "base/win/scoped_com_initializer.h" #include "base/win/scoped_comptr.h" #include "base/win/windows_version.h" -#include "net/base/escape.h" #include "ui/base/win/shell.h" #include "url/gurl.h"