Determine wheter a navigation entry is in-page

This commit is contained in:
Cheng Zhao 2015-05-11 13:51:52 +08:00
parent 4a195e6283
commit fc2bc20572
2 changed files with 16 additions and 10 deletions

View file

@ -348,8 +348,9 @@ void WebContents::WebContentsDestroyed() {
} }
void WebContents::NavigationEntryCommitted( void WebContents::NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) { const content::LoadCommittedDetails& details) {
Emit("navigation-entry-commited", load_details.entry->GetURL()); Emit("navigation-entry-commited", details.entry->GetURL(),
details.is_in_page, details.did_replace_entry);
} }
void WebContents::DidAttach(int guest_proxy_routing_id) { void WebContents::DidAttach(int guest_proxy_routing_id) {

View file

@ -9,16 +9,21 @@ class NavigationController
@currentIndex = -1 @currentIndex = -1
@pendingIndex = -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. if @pendingIndex is -1 # Normal navigation.
@history = @history.slice 0, @currentIndex + 1 # Clear history. @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++ @currentIndex++
@history.push url @history.push {url, inPage}
else # Go to index. else # Go to index.
@currentIndex = @pendingIndex @currentIndex = @pendingIndex
@pendingIndex = -1 @pendingIndex = -1
@history[@currentIndex] = url @history[@currentIndex] = {url, inPage}
loadUrl: (url, options={}) -> loadUrl: (url, options={}) ->
@pendingIndex = -1 @pendingIndex = -1
@ -28,7 +33,7 @@ class NavigationController
if @currentIndex is -1 if @currentIndex is -1
'' ''
else else
@history[@currentIndex] @history[@currentIndex].url
stop: -> stop: ->
@pendingIndex = -1 @pendingIndex = -1
@ -57,17 +62,17 @@ class NavigationController
goBack: -> goBack: ->
return unless @canGoBack() return unless @canGoBack()
@pendingIndex = @getActiveIndex() - 1 @pendingIndex = @getActiveIndex() - 1
@webContents._loadUrl @history[@pendingIndex], {} @webContents._loadUrl @history[@pendingIndex].url, {}
goForward: -> goForward: ->
return unless @canGoForward() return unless @canGoForward()
@pendingIndex = @getActiveIndex() + 1 @pendingIndex = @getActiveIndex() + 1
@webContents._loadUrl @history[@pendingIndex], {} @webContents._loadUrl @history[@pendingIndex].url, {}
goToIndex: (index) -> goToIndex: (index) ->
return unless @canGoToIndex index return unless @canGoToIndex index
@pendingIndex = index @pendingIndex = index
@webContents._loadUrl @history[@pendingIndex], {} @webContents._loadUrl @history[@pendingIndex].url, {}
goToOffset: (offset) -> goToOffset: (offset) ->
return unless @canGoToOffset offset return unless @canGoToOffset offset