]> khamidou — GitHub mirrors - electron.git/commitdiff
Delay the did-fail-provisional-load event to next tick
authorCheng Zhao <zcbenz@gmail.com>
Tue, 1 Dec 2015 08:55:52 +0000 (16:55 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 1 Dec 2015 09:00:42 +0000 (17:00 +0800)
Chrome is doing some stuff after the DidFailProvisionalLoad event, if we
call LoadURL at this time crash would happen.

atom/browser/api/atom_api_web_contents.cc
atom/browser/api/lib/web-contents.coffee

index 066ca9cc7b65c6a8a7d6da7b46201f97b2107c39..339be85fe9bd2b403d71346a373204fb19eeab49 100644 (file)
@@ -460,14 +460,13 @@ void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
     Emit("did-finish-load");
 }
 
-// this error occurs when host could not be found
 void WebContents::DidFailProvisionalLoad(
     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) {
-  Emit("did-fail-load", error_code, error_description, validated_url);
+  Emit("did-fail-provisional-load", error_code, error_description, url);
 }
 
 void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
index 335928dcea81df80e26ce6358304fc5bedd00ab5..45545fe24874ae700e94bf342949386212873a19 100644 (file)
@@ -70,6 +70,12 @@ wrapWebContents = (webContents) ->
     menu = Menu.buildFromTemplate params.menu
     menu.popup params.x, params.y
 
+  # This error occurs when host could not be found.
+  webContents.on 'did-fail-provisional-load', (args...) ->
+    # Calling loadURL during this event might cause crash, so delay the event
+    # until next tick.
+    setImmediate => @emit 'did-fail-load', args...
+
   # Deprecated.
   deprecate.rename webContents, 'loadUrl', 'loadURL'
   deprecate.rename webContents, 'getUrl', 'getURL'