From 82ffa4d2b10d765e9fecb4030412f4ee051daf10 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 May 2015 16:03:25 +0800 Subject: [PATCH] Send history operations as asynchronous messages Sending as sync message will cause weird results for NavigationController --- atom/browser/api/lib/navigation-controller.coffee | 6 ++++++ atom/browser/api/lib/web-contents.coffee | 1 - atom/renderer/lib/override.coffee | 13 +++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index 675f34e8..9c3159ce 100644 --- a/atom/browser/api/lib/navigation-controller.coffee +++ b/atom/browser/api/lib/navigation-controller.coffee @@ -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. diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index e249ccfb..eb86c945 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -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 diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index 3ac5177e..1bc1e612 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -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' -- 2.43.0