From 92882c358a0cdf091059a8cec98a00762f368c17 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Apr 2016 19:33:59 +0900 Subject: [PATCH 1/3] No more need to delay did-fail-load event --- atom/browser/api/atom_api_web_contents.cc | 19 ++++++------------- lib/browser/api/web-contents.js | 9 --------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 985c541a15a9..81e2423a3519 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -547,28 +547,21 @@ void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host, void WebContents::DidFailProvisionalLoad( content::RenderFrameHost* render_frame_host, const GURL& url, - int error_code, - const base::string16& error_description, + int code, + const base::string16& description, bool was_ignored_by_handler) { bool is_main_frame = !render_frame_host->GetParent(); - Emit("did-fail-provisional-load", - error_code, - error_description, - url, - is_main_frame); + Emit("did-fail-provisional-load", code, description, url, is_main_frame); + Emit("did-fail-load", code, description, url, is_main_frame); } void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host, - const GURL& validated_url, + const GURL& url, int error_code, const base::string16& error_description, bool was_ignored_by_handler) { bool is_main_frame = !render_frame_host->GetParent(); - Emit("did-fail-load", - error_code, - error_description, - validated_url, - is_main_frame); + Emit("did-fail-load", error_code, error_description, url, is_main_frame); } void WebContents::DidStartLoading() { diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index bc32161e77e7..40efa77cda02 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -146,15 +146,6 @@ let wrapWebContents = function (webContents) { return menu.popup(params.x, params.y) }) - // This error occurs when host could not be found. - webContents.on('did-fail-provisional-load', function (...args) { - // Calling loadURL during this event might cause crash, so delay the event - // until next tick. - setImmediate(() => { - this.emit.apply(this, ['did-fail-load'].concat(args)) - }) - }) - // The devtools requests the webContents to reload. webContents.on('devtools-reload-page', function () { webContents.reload() From 0a39449694cf874c92a04d0b634d2dfe0627ac48 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Apr 2016 19:39:11 +0900 Subject: [PATCH 2/3] spec: loadUrl should not crash in did-fail-provisional-load handler --- spec/api-browser-window-spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 5775a89e2948..f1dd24345ded 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -153,6 +153,14 @@ describe('browser-window module', function () { }) w.loadURL('file://' + path.join(fixtures, 'api', 'did-fail-load-iframe.html')) }) + + it('does not crash in did-fail-provisional-load handler', function (done) { + w.webContents.once('did-fail-provisional-load', function () { + w.loadURL('http://somewhere-that-does-not.exist/') + done() + }) + w.loadURL('http://somewhere-that-does-not.exist/') + }) }) describe('BrowserWindow.show()', function () { From 65c612a66dc3af0ada41756777e4cb2348d5a875 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Apr 2016 19:55:59 +0900 Subject: [PATCH 3/3] Avoid external URLs --- spec/api-browser-window-spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index f1dd24345ded..2a8d1295c7fd 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -156,10 +156,10 @@ describe('browser-window module', function () { it('does not crash in did-fail-provisional-load handler', function (done) { w.webContents.once('did-fail-provisional-load', function () { - w.loadURL('http://somewhere-that-does-not.exist/') + w.loadURL('http://localhost:11111') done() }) - w.loadURL('http://somewhere-that-does-not.exist/') + w.loadURL('http://localhost:11111') }) })