feat: duplicate navigation related APIs to contents.navigationHistory (#41752)

* refactor: move navigation related api to navigationHistory

* docs: add deprecation messages to old web content methods

* fix: add deprecation warnings to webcontents

* fix: add deprecation warnings and make existing naviagation apis internal

* Update docs/api/web-contents.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* Update docs/api/web-contents.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* Update docs/api/web-contents.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* Update docs/api/web-contents.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* docs: fix links

* docs: add breaking change to 31

* docs: move breaking change to 32

* chore: re-run pipeline

---------

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>
This commit is contained in:
Alice Zhao 2024-06-05 09:34:47 -07:00 committed by GitHub
parent 5fb117a7d7
commit 406f644d26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 239 additions and 17 deletions

View file

@ -510,6 +510,54 @@ const environment = process._linkedBinding('electron_common_environment');
const loggingEnabled = () => {
return environment.hasVar('ELECTRON_ENABLE_LOGGING') || commandLine.hasSwitch('enable-logging');
};
// Deprecation warnings for navigation related APIs.
const canGoBackDeprecated = deprecate.warnOnce('webContents.canGoBack', 'webContents.navigationHistory.canGoBack');
WebContents.prototype.canGoBack = function () {
canGoBackDeprecated();
return this._canGoBack();
};
const canGoForwardDeprecated = deprecate.warnOnce('webContents.canGoForward', 'webContents.navigationHistory.canGoForward');
WebContents.prototype.canGoForward = function () {
canGoForwardDeprecated();
return this._canGoForward();
};
const canGoToOffsetDeprecated = deprecate.warnOnce('webContents.canGoToOffset', 'webContents.navigationHistory.canGoToOffset');
WebContents.prototype.canGoToOffset = function () {
canGoToOffsetDeprecated();
return this._canGoToOffset();
};
const clearHistoryDeprecated = deprecate.warnOnce('webContents.clearHistory', 'webContents.navigationHistory.clear');
WebContents.prototype.clearHistory = function () {
clearHistoryDeprecated();
return this._clearHistory();
};
const goBackDeprecated = deprecate.warnOnce('webContents.goBack', 'webContents.navigationHistory.goBack');
WebContents.prototype.goBack = function () {
goBackDeprecated();
return this._goBack();
};
const goForwardDeprecated = deprecate.warnOnce('webContents.goForward', 'webContents.navigationHistory.goForward');
WebContents.prototype.goForward = function () {
goForwardDeprecated();
return this._goForward();
};
const goToIndexDeprecated = deprecate.warnOnce('webContents.goToIndex', 'webContents.navigationHistory.goToIndex');
WebContents.prototype.goToIndex = function (index: number) {
goToIndexDeprecated();
return this._goToIndex(index);
};
const goToOffsetDeprecated = deprecate.warnOnce('webContents.goToOffset', 'webContents.navigationHistory.goToOffset');
WebContents.prototype.goToOffset = function (index: number) {
goToOffsetDeprecated();
return this._goToOffset(index);
};
// Add JavaScript wrappers for WebContents class.
WebContents.prototype._init = function () {
@ -537,6 +585,14 @@ WebContents.prototype._init = function () {
// maintaining a list of navigation entries for backward and forward navigation.
Object.defineProperty(this, 'navigationHistory', {
value: {
canGoBack: this._canGoBack.bind(this),
canGoForward: this._canGoForward.bind(this),
canGoToOffset: this._canGoToOffset.bind(this),
clear: this._clearHistory.bind(this),
goBack: this._goBack.bind(this),
goForward: this._goForward.bind(this),
goToIndex: this._goToIndex.bind(this),
goToOffset: this._goToOffset.bind(this),
getActiveIndex: this._getActiveIndex.bind(this),
length: this._historyLength.bind(this),
getEntryAtIndex: this._getNavigationEntryAtIndex.bind(this)