]> khamidou — GitHub mirrors - electron.git/commitdiff
Send history operations as asynchronous messages
authorCheng Zhao <zcbenz@gmail.com>
Mon, 11 May 2015 08:03:25 +0000 (16:03 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 11 May 2015 08:03:25 +0000 (16:03 +0800)
Sending as sync message will cause weird results for
NavigationController

atom/browser/api/lib/navigation-controller.coffee
atom/browser/api/lib/web-contents.coffee
atom/renderer/lib/override.coffee

index 675f34e85f85a08e414ae41e8004d71896d2bbec..9c3159ce407ea17e7774060b57a15bc2bfdc4d04 100644 (file)
@@ -1,3 +1,9 @@
+ipc = require 'ipc'
+
+# The history operation in renderer is redirected to browser.
+ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) ->
+  event.sender[method] args...
+
 # JavaScript implementation of Chromium's NavigationController.
 # Instead of relying on Chromium for history control, we compeletely do history
 # control on user land, and only rely on WebContents.loadUrl for navigation.
index e249ccfb808dcc96fb78c7703d692b8d19d3aa22..eb86c94500ce873e11edc9a661040bef1181722b 100644 (file)
@@ -29,7 +29,6 @@ module.exports.wrap = (webContents) ->
 
   # The navigation controller.
   controller = new NavigationController(webContents)
-  webContents.controller = controller
   for name, method of NavigationController.prototype when method instanceof Function
     do (name, method) ->
       webContents[name] = -> method.apply controller, arguments
index 3ac5177e809db8b023f67fb7acafeaa53a9518b7..1bc1e612c5c297447b2fb50a09a4db80847a6c03 100644 (file)
@@ -74,15 +74,16 @@ window.confirm = (message, title='') ->
 window.prompt = ->
   throw new Error('prompt() is and will not be supported.')
 
-# Forward history operations to browser.
-window.history.back = ->
-  remote.getCurrentWebContents().goBack()
-window.history.forward = ->
-  remote.getCurrentWebContents().goForward()
-
+# Simple implementation of postMessage.
 window.opener =
   postMessage: (message, targetOrigin='*') ->
     ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', message, targetOrigin
 
 ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (message, targetOrigin) ->
   window.postMessage message, targetOrigin
+
+# Forward history operations to browser.
+sendHistoryOperation = (args...) ->
+  ipc.send 'ATOM_SHELL_NAVIGATION_CONTROLLER', args...
+window.history.back = -> sendHistoryOperation 'goBack'
+window.history.forward = -> sendHistoryOperation 'goForward'