Use Chrome's navigation controller for in-page navigations
This commit is contained in:
parent
4d1cd7e15f
commit
40631edb70
3 changed files with 31 additions and 10 deletions
|
@ -443,6 +443,14 @@ void WebContents::ReloadIgnoringCache() {
|
||||||
web_contents()->GetController().ReloadIgnoringCache(false);
|
web_contents()->GetController().ReloadIgnoringCache(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::GoBack() {
|
||||||
|
web_contents()->GetController().GoBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebContents::GoForward() {
|
||||||
|
web_contents()->GetController().GoForward();
|
||||||
|
}
|
||||||
|
|
||||||
int WebContents::GetRoutingID() const {
|
int WebContents::GetRoutingID() const {
|
||||||
return web_contents()->GetRoutingID();
|
return web_contents()->GetRoutingID();
|
||||||
}
|
}
|
||||||
|
@ -611,6 +619,8 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
|
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
|
||||||
.SetMethod("_stop", &WebContents::Stop)
|
.SetMethod("_stop", &WebContents::Stop)
|
||||||
.SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
|
.SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
|
||||||
|
.SetMethod("_goBack", &WebContents::GoBack)
|
||||||
|
.SetMethod("_goForward", &WebContents::GoForward)
|
||||||
.SetMethod("getRoutingId", &WebContents::GetRoutingID)
|
.SetMethod("getRoutingId", &WebContents::GetRoutingID)
|
||||||
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
||||||
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
||||||
|
|
|
@ -53,6 +53,9 @@ class WebContents : public mate::EventEmitter,
|
||||||
bool IsWaitingForResponse() const;
|
bool IsWaitingForResponse() const;
|
||||||
void Stop();
|
void Stop();
|
||||||
void ReloadIgnoringCache();
|
void ReloadIgnoringCache();
|
||||||
|
void GoBack();
|
||||||
|
void GoForward();
|
||||||
|
void GoToIndex();
|
||||||
int GetRoutingID() const;
|
int GetRoutingID() const;
|
||||||
int GetProcessID() const;
|
int GetProcessID() const;
|
||||||
bool IsCrashed() const;
|
bool IsCrashed() const;
|
||||||
|
|
|
@ -10,20 +10,20 @@ class NavigationController
|
||||||
@pendingIndex = -1
|
@pendingIndex = -1
|
||||||
|
|
||||||
@webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) =>
|
@webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) =>
|
||||||
if replaceEntry
|
console.log 'navigation-entry-commited', url, inPage, replaceEntry
|
||||||
@history[@currentIndex] = {url, inPage}
|
|
||||||
return
|
|
||||||
|
|
||||||
if @pendingIndex is -1 # Normal navigation.
|
if @pendingIndex >= 0 # Go to index.
|
||||||
|
@currentIndex = @pendingIndex
|
||||||
|
@pendingIndex = -1
|
||||||
|
@history[@currentIndex] = {url, inPage}
|
||||||
|
else if replaceEntry # Non-user initialized navigation.
|
||||||
|
@history[@currentIndex] = {url, inPage}
|
||||||
|
else # Normal navigation.
|
||||||
@history = @history.slice 0, @currentIndex + 1 # Clear history.
|
@history = @history.slice 0, @currentIndex + 1 # Clear history.
|
||||||
currentEntry = @history[@currentIndex]
|
currentEntry = @history[@currentIndex]
|
||||||
if currentEntry?.url isnt url or currentEntry?.inPage isnt inPage
|
if currentEntry?.url isnt url or currentEntry?.inPage isnt inPage
|
||||||
@currentIndex++
|
@currentIndex++
|
||||||
@history.push {url, inPage}
|
@history.push {url, inPage}
|
||||||
else # Go to index.
|
|
||||||
@currentIndex = @pendingIndex
|
|
||||||
@pendingIndex = -1
|
|
||||||
@history[@currentIndex] = {url, inPage}
|
|
||||||
|
|
||||||
loadUrl: (url, options={}) ->
|
loadUrl: (url, options={}) ->
|
||||||
@pendingIndex = -1
|
@pendingIndex = -1
|
||||||
|
@ -62,12 +62,20 @@ class NavigationController
|
||||||
goBack: ->
|
goBack: ->
|
||||||
return unless @canGoBack()
|
return unless @canGoBack()
|
||||||
@pendingIndex = @getActiveIndex() - 1
|
@pendingIndex = @getActiveIndex() - 1
|
||||||
@webContents._loadUrl @history[@pendingIndex].url, {}
|
pendingEntry = @history[@pendingIndex]
|
||||||
|
if pendingEntry.inPage
|
||||||
|
@webContents._goBack()
|
||||||
|
else
|
||||||
|
@webContents._loadUrl pendingEntry.url, {}
|
||||||
|
|
||||||
goForward: ->
|
goForward: ->
|
||||||
return unless @canGoForward()
|
return unless @canGoForward()
|
||||||
@pendingIndex = @getActiveIndex() + 1
|
@pendingIndex = @getActiveIndex() + 1
|
||||||
@webContents._loadUrl @history[@pendingIndex].url, {}
|
pendingEntry = @history[@pendingIndex]
|
||||||
|
if pendingEntry.inPage
|
||||||
|
@webContents._goForward()
|
||||||
|
else
|
||||||
|
@webContents._loadUrl pendingEntry.url, {}
|
||||||
|
|
||||||
goToIndex: (index) ->
|
goToIndex: (index) ->
|
||||||
return unless @canGoToIndex index
|
return unless @canGoToIndex index
|
||||||
|
|
Loading…
Reference in a new issue