Preload doesn't load in sandboxed render if preload path contains special chars (#12037)
* Adding missing headers * adding ut * Removing the file path exists check * fixing test * exposing window.require in UT
This commit is contained in:
parent
69e7afee26
commit
2f4fd3324b
3 changed files with 28 additions and 4 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include "atom/renderer/api/atom_api_renderer_ipc.h"
|
#include "atom/renderer/api/atom_api_renderer_ipc.h"
|
||||||
#include "atom/renderer/atom_render_view_observer.h"
|
#include "atom/renderer/atom_render_view_observer.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
|
#include "base/files/file_path.h"
|
||||||
#include "chrome/renderer/printing/print_web_view_helper.h"
|
#include "chrome/renderer/printing/print_web_view_helper.h"
|
||||||
#include "content/public/renderer/render_frame.h"
|
#include "content/public/renderer/render_frame.h"
|
||||||
#include "content/public/renderer/render_view.h"
|
#include "content/public/renderer/render_view.h"
|
||||||
|
@ -163,9 +164,9 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
|
||||||
return;
|
return;
|
||||||
|
|
||||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
std::string preload_script = command_line->GetSwitchValueASCII(
|
base::FilePath preload_script_path = command_line->GetSwitchValuePath(
|
||||||
switches::kPreloadScript);
|
switches::kPreloadScript);
|
||||||
if (preload_script.empty())
|
if (preload_script_path.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto isolate = context->GetIsolate();
|
auto isolate = context->GetIsolate();
|
||||||
|
@ -191,7 +192,7 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
|
||||||
AddRenderBindings(isolate, binding);
|
AddRenderBindings(isolate, binding);
|
||||||
v8::Local<v8::Value> args[] = {
|
v8::Local<v8::Value> args[] = {
|
||||||
binding,
|
binding,
|
||||||
mate::ConvertToV8(isolate, preload_script)
|
mate::ConvertToV8(isolate, preload_script_path.value())
|
||||||
};
|
};
|
||||||
// Execute the function with proper arguments
|
// Execute the function with proper arguments
|
||||||
ignore_result(func->Call(context, v8::Null(isolate), 2, args));
|
ignore_result(func->Call(context, v8::Null(isolate), 2, args));
|
||||||
|
|
|
@ -1186,7 +1186,24 @@ describe('BrowserWindow module', () => {
|
||||||
w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html'))
|
w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('exposes "exit" event to preload script', (done) => {
|
it('exposes ipcRenderer to preload script (path has special chars)', function (done) {
|
||||||
|
const preloadSpecialChars = path.join(fixtures, 'module', 'preload-sandboxæø åü.js')
|
||||||
|
ipcMain.once('answer', function (event, test) {
|
||||||
|
assert.equal(test, 'preload')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.destroy()
|
||||||
|
w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
sandbox: true,
|
||||||
|
preload: preloadSpecialChars
|
||||||
|
}
|
||||||
|
})
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('exposes "exit" event to preload script', function (done) {
|
||||||
w.destroy()
|
w.destroy()
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
|
|
6
spec/fixtures/module/preload-sandboxæø åü.js
vendored
Normal file
6
spec/fixtures/module/preload-sandboxæø åü.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
(function () {
|
||||||
|
window.require = require
|
||||||
|
if (location.protocol === 'file:') {
|
||||||
|
window.test = 'preload'
|
||||||
|
}
|
||||||
|
})()
|
Loading…
Reference in a new issue