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:
Hari Juturu 2018-03-07 08:40:00 -08:00 коммит произвёл Shelley Vohr
Родитель 69e7afee26
Коммит 2f4fd3324b
3 изменённых файлов: 28 добавлений и 4 удалений

Просмотреть файл

@ -16,6 +16,7 @@
#include "atom/renderer/api/atom_api_renderer_ipc.h"
#include "atom/renderer/atom_render_view_observer.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "chrome/renderer/printing/print_web_view_helper.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
@ -163,9 +164,9 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
return;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
std::string preload_script = command_line->GetSwitchValueASCII(
base::FilePath preload_script_path = command_line->GetSwitchValuePath(
switches::kPreloadScript);
if (preload_script.empty())
if (preload_script_path.empty())
return;
auto isolate = context->GetIsolate();
@ -191,7 +192,7 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
AddRenderBindings(isolate, binding);
v8::Local<v8::Value> args[] = {
binding,
mate::ConvertToV8(isolate, preload_script)
mate::ConvertToV8(isolate, preload_script_path.value())
};
// Execute the function with proper arguments
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'))
})
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 = new BrowserWindow({
show: false,

6
spec/fixtures/module/preload-sandboxæø åü.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
(function () {
window.require = require
if (location.protocol === 'file:') {
window.test = 'preload'
}
})()