From fc2bc20572815b3953680bbed672a1c83a883903 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 May 2015 13:51:52 +0800 Subject: [PATCH] Determine wheter a navigation entry is in-page --- atom/browser/api/atom_api_web_contents.cc | 5 +++-- atom/browser/api/lib/navigation-controller.coffee | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index c998dec..2fedd10 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -348,8 +348,9 @@ void WebContents::WebContentsDestroyed() { } void WebContents::NavigationEntryCommitted( - const content::LoadCommittedDetails& load_details) { - Emit("navigation-entry-commited", load_details.entry->GetURL()); + const content::LoadCommittedDetails& details) { + Emit("navigation-entry-commited", details.entry->GetURL(), + details.is_in_page, details.did_replace_entry); } void WebContents::DidAttach(int guest_proxy_routing_id) { diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index 75f9dd2..28404b1 100644 --- a/atom/browser/api/lib/navigation-controller.coffee +++ b/atom/browser/api/lib/navigation-controller.coffee @@ -9,16 +9,21 @@ class NavigationController @currentIndex = -1 @pendingIndex = -1 - @webContents.on 'navigation-entry-commited', (event, url) => + @webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) => + if replaceEntry + @history[@currentIndex] = {url, inPage} + return + if @pendingIndex is -1 # Normal navigation. @history = @history.slice 0, @currentIndex + 1 # Clear history. - if @history[@currentIndex] isnt url + currentEntry = @history[@currentIndex] + if currentEntry?.url isnt url or currentEntry?.inPage isnt inPage @currentIndex++ - @history.push url + @history.push {url, inPage} else # Go to index. @currentIndex = @pendingIndex @pendingIndex = -1 - @history[@currentIndex] = url + @history[@currentIndex] = {url, inPage} loadUrl: (url, options={}) -> @pendingIndex = -1 @@ -28,7 +33,7 @@ class NavigationController if @currentIndex is -1 '' else - @history[@currentIndex] + @history[@currentIndex].url stop: -> @pendingIndex = -1 @@ -57,17 +62,17 @@ class NavigationController goBack: -> return unless @canGoBack() @pendingIndex = @getActiveIndex() - 1 - @webContents._loadUrl @history[@pendingIndex], {} + @webContents._loadUrl @history[@pendingIndex].url, {} goForward: -> return unless @canGoForward() @pendingIndex = @getActiveIndex() + 1 - @webContents._loadUrl @history[@pendingIndex], {} + @webContents._loadUrl @history[@pendingIndex].url, {} goToIndex: (index) -> return unless @canGoToIndex index @pendingIndex = index - @webContents._loadUrl @history[@pendingIndex], {} + @webContents._loadUrl @history[@pendingIndex].url, {} goToOffset: (offset) -> return unless @canGoToOffset offset -- 2.7.4