Merge pull request #5932 from electron/fix-standard-scheme
Fix crash when using fetch in custom protocols
This commit is contained in:
commit
3cb5649f07
6 changed files with 51 additions and 1 deletions
|
@ -14,6 +14,10 @@
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/net_converter.h"
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
#include "atom/common/options_switches.h"
|
||||||
|
#include "base/command_line.h"
|
||||||
|
#include "base/strings/string_util.h"
|
||||||
|
#include "content/public/browser/child_process_security_policy.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "url/url_util.h"
|
#include "url/url_util.h"
|
||||||
|
|
||||||
|
@ -158,8 +162,15 @@ namespace {
|
||||||
|
|
||||||
void RegisterStandardSchemes(
|
void RegisterStandardSchemes(
|
||||||
const std::vector<std::string>& schemes) {
|
const std::vector<std::string>& schemes) {
|
||||||
for (const auto& scheme : schemes)
|
auto policy = content::ChildProcessSecurityPolicy::GetInstance();
|
||||||
|
for (const auto& scheme : schemes) {
|
||||||
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
|
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
|
||||||
|
policy->RegisterWebSafeScheme(scheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||||
|
command_line->AppendSwitchASCII(atom::switches::kStandardSchemes,
|
||||||
|
base::JoinString(schemes, ","));
|
||||||
}
|
}
|
||||||
|
|
||||||
mate::Handle<atom::api::Protocol> CreateProtocol(v8::Isolate* isolate) {
|
mate::Handle<atom::api::Protocol> CreateProtocol(v8::Isolate* isolate) {
|
||||||
|
|
|
@ -169,6 +169,14 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
if (process_type != "renderer")
|
if (process_type != "renderer")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Copy following switches to child process.
|
||||||
|
static const char* const kCommonSwitchNames[] = {
|
||||||
|
switches::kStandardSchemes,
|
||||||
|
};
|
||||||
|
command_line->CopySwitchesFrom(
|
||||||
|
*base::CommandLine::ForCurrentProcess(),
|
||||||
|
kCommonSwitchNames, arraysize(kCommonSwitchNames));
|
||||||
|
|
||||||
// The registered service worker schemes.
|
// The registered service worker schemes.
|
||||||
if (!g_custom_service_worker_schemes.empty())
|
if (!g_custom_service_worker_schemes.empty())
|
||||||
command_line->AppendSwitchASCII(switches::kRegisterServiceWorkerSchemes,
|
command_line->AppendSwitchASCII(switches::kRegisterServiceWorkerSchemes,
|
||||||
|
|
|
@ -129,6 +129,9 @@ const char kPpapiFlashVersion[] = "ppapi-flash-version";
|
||||||
// Disable HTTP cache.
|
// Disable HTTP cache.
|
||||||
const char kDisableHttpCache[] = "disable-http-cache";
|
const char kDisableHttpCache[] = "disable-http-cache";
|
||||||
|
|
||||||
|
// The list of standard schemes.
|
||||||
|
const char kStandardSchemes[] = "standard-schemes";
|
||||||
|
|
||||||
// Register schemes to handle service worker.
|
// Register schemes to handle service worker.
|
||||||
const char kRegisterServiceWorkerSchemes[] = "register-service-worker-schemes";
|
const char kRegisterServiceWorkerSchemes[] = "register-service-worker-schemes";
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ extern const char kEnablePlugins[];
|
||||||
extern const char kPpapiFlashPath[];
|
extern const char kPpapiFlashPath[];
|
||||||
extern const char kPpapiFlashVersion[];
|
extern const char kPpapiFlashVersion[];
|
||||||
extern const char kDisableHttpCache[];
|
extern const char kDisableHttpCache[];
|
||||||
|
extern const char kStandardSchemes[];
|
||||||
extern const char kRegisterServiceWorkerSchemes[];
|
extern const char kRegisterServiceWorkerSchemes[];
|
||||||
extern const char kSSLVersionFallbackMin[];
|
extern const char kSSLVersionFallbackMin[];
|
||||||
extern const char kCipherSuiteBlacklist[];
|
extern const char kCipherSuiteBlacklist[];
|
||||||
|
|
|
@ -122,6 +122,16 @@ bool IsDevToolsExtension(content::RenderFrame* render_frame) {
|
||||||
AtomRendererClient::AtomRendererClient()
|
AtomRendererClient::AtomRendererClient()
|
||||||
: node_bindings_(NodeBindings::Create(false)),
|
: node_bindings_(NodeBindings::Create(false)),
|
||||||
atom_bindings_(new AtomBindings) {
|
atom_bindings_(new AtomBindings) {
|
||||||
|
// Parse --standard-schemes=scheme1,scheme2
|
||||||
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
|
std::string custom_schemes = command_line->GetSwitchValueASCII(
|
||||||
|
switches::kStandardSchemes);
|
||||||
|
if (!custom_schemes.empty()) {
|
||||||
|
std::vector<std::string> schemes_list = base::SplitString(
|
||||||
|
custom_schemes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||||
|
for (const std::string& scheme : schemes_list)
|
||||||
|
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomRendererClient::~AtomRendererClient() {
|
AtomRendererClient::~AtomRendererClient() {
|
||||||
|
|
|
@ -919,6 +919,23 @@ describe('protocol module', function () {
|
||||||
})
|
})
|
||||||
w.loadURL(origin)
|
w.loadURL(origin)
|
||||||
})
|
})
|
||||||
|
}),
|
||||||
|
|
||||||
|
it('can have fetch working in it', function (done) {
|
||||||
|
const content = '<html><script>fetch("http://github.com")</script></html>'
|
||||||
|
const handler = function (request, callback) {
|
||||||
|
callback({data: content, mimeType: 'text/html'})
|
||||||
|
}
|
||||||
|
protocol.registerStringProtocol(standardScheme, handler, function (error) {
|
||||||
|
if (error) return done(error)
|
||||||
|
w.webContents.on('crashed', function () {
|
||||||
|
done('WebContents crashed')
|
||||||
|
})
|
||||||
|
w.webContents.on('did-finish-load', function () {
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.loadURL(origin)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue