From: deepak1556 Date: Tue, 19 May 2015 17:11:03 +0000 (+0530) Subject: navigation: adding clearHistory method X-Git-Tag: v0.26.1~5^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b0e8cafa0043d392a1cf189b5d254718e38bbcd9;p=electron.git navigation: adding clearHistory method --- diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index f7945e07..75e3affb 100644 --- a/atom/browser/api/lib/navigation-controller.coffee +++ b/atom/browser/api/lib/navigation-controller.coffee @@ -4,6 +4,9 @@ ipc = require 'ipc' ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) -> event.sender[method] args... +ipc.on 'ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', (event, method, args...) -> + event.returnValue = 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. @@ -11,10 +14,7 @@ ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) -> # process is restarted everytime. class NavigationController constructor: (@webContents) -> - @history = [] - @currentIndex = -1 - @pendingIndex = -1 - @inPageIndex = -1 + @clearHistory() @webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) => if @inPageIndex > -1 and not inPage @@ -71,6 +71,12 @@ class NavigationController canGoToOffset: (offset) -> @canGoToIndex @currentIndex + offset + clearHistory: -> + @history = [] + @currentIndex = -1 + @pendingIndex = -1 + @inPageIndex = -1 + goBack: -> return unless @canGoBack() @pendingIndex = @getActiveIndex() - 1 @@ -104,4 +110,7 @@ class NavigationController getActiveIndex: -> if @pendingIndex is -1 then @currentIndex else @pendingIndex + length: -> + @history.length + module.exports = NavigationController diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index 1ca6e692..ccc7882a 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -85,6 +85,13 @@ ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (message, targetOrigin) -> # Forward history operations to browser. sendHistoryOperation = (args...) -> ipc.send 'ATOM_SHELL_NAVIGATION_CONTROLLER', args... + +getHistoryOperation = (args...) -> + ipc.sendSync 'ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', args... + window.history.back = -> sendHistoryOperation 'goBack' window.history.forward = -> sendHistoryOperation 'goForward' window.history.go = (offset) -> sendHistoryOperation 'goToOffset', offset +Object.defineProperty window.history, 'length', + get: -> + getHistoryOperation 'length' diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index bf163c0c..b87131b9 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -244,6 +244,7 @@ registerWebViewElement = -> "canGoBack" "canGoForward" "canGoToOffset" + "clearHistory" "goBack" "goForward" "goToIndex" diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f8ff8e7b..748f5b3e 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -778,6 +778,10 @@ Returns whether the web page can go forward. Returns whether the web page can go to `offset`. +### WebContents.clearHistory() + +Clears the navigation history. + ### WebContents.goBack() Makes the web page go back. diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 89ae678b..6cb9718a 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -165,6 +165,10 @@ Returns whether guest page can go forward. Returns whether guest page can go to `offset`. +### ``.clearHistory() + +Clears the navigation history. + ### ``.goBack() Makes guest page go back.