]> khamidou — GitHub mirrors - electron.git/commitdiff
navigation: adding clearHistory method
authordeepak1556 <hop2deep@gmail.com>
Tue, 19 May 2015 17:11:03 +0000 (22:41 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Tue, 19 May 2015 17:11:03 +0000 (22:41 +0530)
atom/browser/api/lib/navigation-controller.coffee
atom/renderer/lib/override.coffee
atom/renderer/lib/web-view/web-view.coffee
docs/api/browser-window.md
docs/api/web-view-tag.md

index f7945e07bf401b26a24057ed98afd71b609278e5..75e3affbabd58a6297ceb6f4f25f647f4ca39c5d 100644 (file)
@@ -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
index 1ca6e692ba21148b35bef0dcd7eca9f9d1973356..ccc7882a37e8a65705312e95e37c4ee9d8f556db 100644 (file)
@@ -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'
index bf163c0cfb5c7e59302cae0e4bef531eda37002a..b87131b9141c7bf1ee854b5c459f88c99b3e23df 100644 (file)
@@ -244,6 +244,7 @@ registerWebViewElement = ->
     "canGoBack"
     "canGoForward"
     "canGoToOffset"
+    "clearHistory"
     "goBack"
     "goForward"
     "goToIndex"
index f8ff8e7b9e0cab2449f2ce73888456021fa7af25..748f5b3e4c9997a043e33bf7a9730b658d36213e 100644 (file)
@@ -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.
index 89ae678b3c4679a6bd802d502104b68f85ce6647..6cb9718a8d8ab96b0e9149a03acdb79d3143fb52 100644 (file)
@@ -165,6 +165,10 @@ Returns whether guest page can go forward.
 
 Returns whether guest page can go to `offset`.
 
+### `<webview>`.clearHistory()
+
+Clears the navigation history.
+
 ### `<webview>`.goBack()
 
 Makes guest page go back.