Merge pull request #6436 from electron/open-external-string16
win: Fix openExternal not working with non-ASCII characters
This commit is contained in:
commit
6164139167
4 changed files with 33 additions and 24 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include "atom/browser/login_handler.h"
|
#include "atom/browser/login_handler.h"
|
||||||
#include "atom/browser/web_contents_permission_helper.h"
|
#include "atom/browser/web_contents_permission_helper.h"
|
||||||
#include "atom/common/platform_util.h"
|
#include "atom/common/platform_util.h"
|
||||||
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "net/base/escape.h"
|
#include "net/base/escape.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
@ -20,7 +21,13 @@ namespace {
|
||||||
void OnOpenExternal(const GURL& escaped_url,
|
void OnOpenExternal(const GURL& escaped_url,
|
||||||
bool allowed) {
|
bool allowed) {
|
||||||
if (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(
|
void HandleExternalProtocolInUI(
|
||||||
|
|
|
@ -7,12 +7,19 @@
|
||||||
#include "atom/common/platform_util.h"
|
#include "atom/common/platform_util.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.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/gurl_converter.h"
|
||||||
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
|
||||||
namespace {
|
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;
|
bool activate = true;
|
||||||
if (args->Length() == 2) {
|
if (args->Length() == 2) {
|
||||||
mate::Dictionary options;
|
mate::Dictionary options;
|
||||||
|
|
|
@ -5,6 +5,12 @@
|
||||||
#ifndef ATOM_COMMON_PLATFORM_UTIL_H_
|
#ifndef ATOM_COMMON_PLATFORM_UTIL_H_
|
||||||
#define 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;
|
class GURL;
|
||||||
|
|
||||||
namespace base {
|
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.
|
// Open the given external protocol URL in the desktop's default manner.
|
||||||
// (For example, mailto: URLs in the default mail user agent.)
|
// (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.
|
// Move a file to trash.
|
||||||
bool MoveItemToTrash(const base::FilePath& full_path);
|
bool MoveItemToTrash(const base::FilePath& full_path);
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include "base/win/scoped_com_initializer.h"
|
#include "base/win/scoped_com_initializer.h"
|
||||||
#include "base/win/scoped_comptr.h"
|
#include "base/win/scoped_comptr.h"
|
||||||
#include "base/win/windows_version.h"
|
#include "base/win/windows_version.h"
|
||||||
#include "url/gurl.h"
|
|
||||||
#include "ui/base/win/shell.h"
|
#include "ui/base/win/shell.h"
|
||||||
|
#include "url/gurl.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -301,30 +301,13 @@ void OpenItem(const base::FilePath& full_path) {
|
||||||
ui::win::OpenFileViaShell(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
|
// Quote the input scheme to be sure that the command does not have
|
||||||
// parameters unexpected by the external program. This url should already
|
// parameters unexpected by the external program. This url should already
|
||||||
// have been escaped.
|
// have been escaped.
|
||||||
std::string escaped_url = url.spec();
|
base::string16 escaped_url = L"\"" + url + L"\"";
|
||||||
escaped_url.insert(0, "\"");
|
|
||||||
escaped_url += "\"";
|
|
||||||
|
|
||||||
// According to Mozilla in uriloader/exthandler/win/nsOSHelperAppService.cpp:
|
if (reinterpret_cast<ULONG_PTR>(ShellExecuteW(NULL, L"open",
|
||||||
// "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<ULONG_PTR>(ShellExecuteA(NULL, "open",
|
|
||||||
escaped_url.c_str(), NULL, NULL,
|
escaped_url.c_str(), NULL, NULL,
|
||||||
SW_SHOWNORMAL)) <= 32) {
|
SW_SHOWNORMAL)) <= 32) {
|
||||||
// We fail to execute the call. We could display a message to the user.
|
// We fail to execute the call. We could display a message to the user.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue