From 5efa075aca6237814667cf78fc04d68b77953f5b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Apr 2016 14:57:40 +0900 Subject: [PATCH 1/3] spec: preload attribute should work without script tag in page --- spec/webview-spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 64b73d9d220..c9f44747bef 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -155,6 +155,18 @@ describe(' tag', function () { webview.src = 'file://' + fixtures + '/pages/e.html' document.body.appendChild(webview) }) + + it('works without script tag in page', function (done) { + var listener = function (e) { + assert.equal(e.message, 'function object object') + webview.removeEventListener('console-message', listener) + done() + } + webview.addEventListener('console-message', listener) + webview.setAttribute('preload', fixtures + '/module/preload.js') + webview.src = 'file://' + fixtures + '/pages/base-page.html' + document.body.appendChild(webview) + }) }) describe('httpreferrer attribute', function () { From bb70defcb8236aebaa23032d52c575ae8bd00c3c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Apr 2016 15:10:26 +0900 Subject: [PATCH 2/3] spec: webview should work without script tag in page --- spec/fixtures/pages/ping.html | 7 +++++++ spec/fixtures/pages/webview-no-script.html | 5 +++++ spec/webview-spec.js | 11 ++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/pages/ping.html create mode 100644 spec/fixtures/pages/webview-no-script.html diff --git a/spec/fixtures/pages/ping.html b/spec/fixtures/pages/ping.html new file mode 100644 index 00000000000..5bd6a8772a9 --- /dev/null +++ b/spec/fixtures/pages/ping.html @@ -0,0 +1,7 @@ + + + + + diff --git a/spec/fixtures/pages/webview-no-script.html b/spec/fixtures/pages/webview-no-script.html new file mode 100644 index 00000000000..00b8f21bde7 --- /dev/null +++ b/spec/fixtures/pages/webview-no-script.html @@ -0,0 +1,5 @@ + + + + + diff --git a/spec/webview-spec.js b/spec/webview-spec.js index c9f44747bef..10758a0a436 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -2,7 +2,7 @@ const assert = require('assert') const path = require('path') const http = require('http') const url = require('url') -const {app, session} = require('electron').remote +const {app, session, ipcMain, BrowserWindow} = require('electron').remote describe(' tag', function () { this.timeout(10000) @@ -20,6 +20,15 @@ describe(' tag', function () { } }) + it('works without script tag in page', function (done) { + let w = new BrowserWindow({show: false}) + ipcMain.once('pong', function () { + w.destroy() + done() + }) + w.loadURL('file://' + fixtures + '/pages/webview-no-script.html') + }) + describe('src attribute', function () { it('specifies the page to load', function (done) { webview.addEventListener('console-message', function (e) { From 17446f42848d2215cbe96d8381eada07d8dfe93e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Apr 2016 15:11:10 +0900 Subject: [PATCH 3/3] Make sure every page will get a script context created --- atom/renderer/atom_render_view_observer.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/atom/renderer/atom_render_view_observer.cc b/atom/renderer/atom_render_view_observer.cc index bbaea351378..96dffbd512a 100644 --- a/atom/renderer/atom_render_view_observer.cc +++ b/atom/renderer/atom_render_view_observer.cc @@ -27,6 +27,7 @@ #include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebKit.h" +#include "third_party/WebKit/public/web/WebScriptSource.h" #include "third_party/WebKit/public/web/WebView.h" #include "ui/base/resource/resource_bundle.h" #include "native_mate/dictionary.h" @@ -88,6 +89,9 @@ void AtomRenderViewObserver::DidCreateDocumentElement( blink::WebLocalFrame* frame) { document_created_ = true; + // Make sure every page will get a script context created. + frame->executeScript(blink::WebScriptSource("void 0")); + // Read --zoom-factor from command line. std::string zoom_factor_str = base::CommandLine::ForCurrentProcess()-> GetSwitchValueASCII(switches::kZoomFactor);