chore: revert deprecated WebContents properties (#22640)
* chore: revert deprecated WebContents properties * Fix failing zoomFactor test
This commit is contained in:
parent
0c02d794c9
commit
1b353d1ed3
5 changed files with 124 additions and 65 deletions
|
@ -967,14 +967,10 @@ Returns `Boolean` - Whether the renderer process has crashed.
|
||||||
|
|
||||||
Overrides the user agent for this web page.
|
Overrides the user agent for this web page.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.getUserAgent()`
|
#### `contents.getUserAgent()`
|
||||||
|
|
||||||
Returns `String` - The user agent for this web page.
|
Returns `String` - The user agent for this web page.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.insertCSS(css[, options])`
|
#### `contents.insertCSS(css[, options])`
|
||||||
|
|
||||||
* `css` String
|
* `css` String
|
||||||
|
@ -1054,14 +1050,10 @@ Ignore application menu shortcuts while this web contents is focused.
|
||||||
|
|
||||||
Mute the audio on the current web page.
|
Mute the audio on the current web page.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.isAudioMuted()`
|
#### `contents.isAudioMuted()`
|
||||||
|
|
||||||
Returns `Boolean` - Whether this page has been muted.
|
Returns `Boolean` - Whether this page has been muted.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.isCurrentlyAudible()`
|
#### `contents.isCurrentlyAudible()`
|
||||||
|
|
||||||
Returns `Boolean` - Whether audio is currently playing.
|
Returns `Boolean` - Whether audio is currently playing.
|
||||||
|
@ -1073,14 +1065,10 @@ Returns `Boolean` - Whether audio is currently playing.
|
||||||
Changes the zoom factor to the specified factor. Zoom factor is
|
Changes the zoom factor to the specified factor. Zoom factor is
|
||||||
zoom percent divided by 100, so 300% = 3.0.
|
zoom percent divided by 100, so 300% = 3.0.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.getZoomFactor()`
|
#### `contents.getZoomFactor()`
|
||||||
|
|
||||||
Returns `Number` - the current zoom factor.
|
Returns `Number` - the current zoom factor.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.setZoomLevel(level)`
|
#### `contents.setZoomLevel(level)`
|
||||||
|
|
||||||
* `level` Number - Zoom level.
|
* `level` Number - Zoom level.
|
||||||
|
@ -1090,14 +1078,10 @@ increment above or below represents zooming 20% larger or smaller to default
|
||||||
limits of 300% and 50% of original size, respectively. The formula for this is
|
limits of 300% and 50% of original size, respectively. The formula for this is
|
||||||
`scale := 1.2 ^ level`.
|
`scale := 1.2 ^ level`.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.getZoomLevel()`
|
#### `contents.getZoomLevel()`
|
||||||
|
|
||||||
Returns `Number` - the current zoom level.
|
Returns `Number` - the current zoom level.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.setVisualZoomLevelLimits(minimumLevel, maximumLevel)`
|
#### `contents.setVisualZoomLevelLimits(minimumLevel, maximumLevel)`
|
||||||
|
|
||||||
* `minimumLevel` Number
|
* `minimumLevel` Number
|
||||||
|
@ -1735,14 +1719,10 @@ Returns `Boolean` - If *offscreen rendering* is enabled returns whether it is cu
|
||||||
If *offscreen rendering* is enabled sets the frame rate to the specified number.
|
If *offscreen rendering* is enabled sets the frame rate to the specified number.
|
||||||
Only values between 1 and 60 are accepted.
|
Only values between 1 and 60 are accepted.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.getFrameRate()`
|
#### `contents.getFrameRate()`
|
||||||
|
|
||||||
Returns `Integer` - If *offscreen rendering* is enabled returns the current frame rate.
|
Returns `Integer` - If *offscreen rendering* is enabled returns the current frame rate.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `contents.invalidate()`
|
#### `contents.invalidate()`
|
||||||
|
|
||||||
Schedules a full repaint of the window this web contents is in.
|
Schedules a full repaint of the window this web contents is in.
|
||||||
|
|
|
@ -549,14 +549,34 @@ WebContents.prototype._init = function () {
|
||||||
|
|
||||||
const event = process.electronBinding('event').createEmpty()
|
const event = process.electronBinding('event').createEmpty()
|
||||||
app.emit('web-contents-created', event, this)
|
app.emit('web-contents-created', event, this)
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecations
|
// Properties
|
||||||
deprecate.fnToProperty(WebContents.prototype, 'audioMuted', '_isAudioMuted', '_setAudioMuted')
|
|
||||||
deprecate.fnToProperty(WebContents.prototype, 'userAgent', '_getUserAgent', '_setUserAgent')
|
Object.defineProperty(this, 'audioMuted', {
|
||||||
deprecate.fnToProperty(WebContents.prototype, 'zoomLevel', '_getZoomLevel', '_setZoomLevel')
|
get: () => this.isAudioMuted(),
|
||||||
deprecate.fnToProperty(WebContents.prototype, 'zoomFactor', '_getZoomFactor', '_setZoomFactor')
|
set: (muted) => this.setAudioMuted(muted)
|
||||||
deprecate.fnToProperty(WebContents.prototype, 'frameRate', '_getFrameRate', '_setFrameRate')
|
})
|
||||||
|
|
||||||
|
Object.defineProperty(this, 'userAgent', {
|
||||||
|
get: () => this.getUserAgent(),
|
||||||
|
set: (agent) => this.setUserAgent(agent)
|
||||||
|
})
|
||||||
|
|
||||||
|
Object.defineProperty(this, 'zoomLevel', {
|
||||||
|
get: () => this.getZoomLevel(),
|
||||||
|
set: (level) => this.setZoomLevel(level)
|
||||||
|
})
|
||||||
|
|
||||||
|
Object.defineProperty(this, 'zoomFactor', {
|
||||||
|
get: () => this.getZoomFactor(),
|
||||||
|
set: (factor) => this.setZoomFactor(factor)
|
||||||
|
})
|
||||||
|
|
||||||
|
Object.defineProperty(this, 'frameRate', {
|
||||||
|
get: () => this.getFrameRate(),
|
||||||
|
set: (rate) => this.setFrameRate(rate)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// JavaScript wrapper of Debugger.
|
// JavaScript wrapper of Debugger.
|
||||||
const { Debugger } = process.electronBinding('debugger')
|
const { Debugger } = process.electronBinding('debugger')
|
||||||
|
|
|
@ -2679,10 +2679,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("_goForward", &WebContents::GoForward)
|
.SetMethod("_goForward", &WebContents::GoForward)
|
||||||
.SetMethod("_goToOffset", &WebContents::GoToOffset)
|
.SetMethod("_goToOffset", &WebContents::GoToOffset)
|
||||||
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
||||||
.SetMethod("_setUserAgent", &WebContents::SetUserAgent)
|
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
|
||||||
.SetMethod("_getUserAgent", &WebContents::GetUserAgent)
|
.SetMethod("getUserAgent", &WebContents::GetUserAgent)
|
||||||
.SetProperty("userAgent", &WebContents::GetUserAgent,
|
|
||||||
&WebContents::SetUserAgent)
|
|
||||||
.SetMethod("savePage", &WebContents::SavePage)
|
.SetMethod("savePage", &WebContents::SavePage)
|
||||||
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
||||||
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
||||||
|
@ -2693,10 +2691,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
|
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
|
||||||
.SetMethod("inspectElement", &WebContents::InspectElement)
|
.SetMethod("inspectElement", &WebContents::InspectElement)
|
||||||
.SetMethod("setIgnoreMenuShortcuts", &WebContents::SetIgnoreMenuShortcuts)
|
.SetMethod("setIgnoreMenuShortcuts", &WebContents::SetIgnoreMenuShortcuts)
|
||||||
.SetMethod("_setAudioMuted", &WebContents::SetAudioMuted)
|
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
|
||||||
.SetMethod("_isAudioMuted", &WebContents::IsAudioMuted)
|
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
|
||||||
.SetProperty("audioMuted", &WebContents::IsAudioMuted,
|
|
||||||
&WebContents::SetAudioMuted)
|
|
||||||
.SetMethod("isCurrentlyAudible", &WebContents::IsCurrentlyAudible)
|
.SetMethod("isCurrentlyAudible", &WebContents::IsCurrentlyAudible)
|
||||||
.SetMethod("undo", &WebContents::Undo)
|
.SetMethod("undo", &WebContents::Undo)
|
||||||
.SetMethod("redo", &WebContents::Redo)
|
.SetMethod("redo", &WebContents::Redo)
|
||||||
|
@ -2728,20 +2724,14 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("startPainting", &WebContents::StartPainting)
|
.SetMethod("startPainting", &WebContents::StartPainting)
|
||||||
.SetMethod("stopPainting", &WebContents::StopPainting)
|
.SetMethod("stopPainting", &WebContents::StopPainting)
|
||||||
.SetMethod("isPainting", &WebContents::IsPainting)
|
.SetMethod("isPainting", &WebContents::IsPainting)
|
||||||
.SetMethod("_setFrameRate", &WebContents::SetFrameRate)
|
.SetMethod("setFrameRate", &WebContents::SetFrameRate)
|
||||||
.SetMethod("_getFrameRate", &WebContents::GetFrameRate)
|
.SetMethod("getFrameRate", &WebContents::GetFrameRate)
|
||||||
.SetProperty("frameRate", &WebContents::GetFrameRate,
|
|
||||||
&WebContents::SetFrameRate)
|
|
||||||
#endif
|
#endif
|
||||||
.SetMethod("invalidate", &WebContents::Invalidate)
|
.SetMethod("invalidate", &WebContents::Invalidate)
|
||||||
.SetMethod("_setZoomLevel", &WebContents::SetZoomLevel)
|
.SetMethod("setZoomLevel", &WebContents::SetZoomLevel)
|
||||||
.SetMethod("_getZoomLevel", &WebContents::GetZoomLevel)
|
.SetMethod("getZoomLevel", &WebContents::GetZoomLevel)
|
||||||
.SetProperty("zoomLevel", &WebContents::GetZoomLevel,
|
.SetMethod("setZoomFactor", &WebContents::SetZoomFactor)
|
||||||
&WebContents::SetZoomLevel)
|
.SetMethod("getZoomFactor", &WebContents::GetZoomFactor)
|
||||||
.SetMethod("_setZoomFactor", &WebContents::SetZoomFactor)
|
|
||||||
.SetMethod("_getZoomFactor", &WebContents::GetZoomFactor)
|
|
||||||
.SetProperty("zoomFactor", &WebContents::GetZoomFactor,
|
|
||||||
&WebContents::SetZoomFactor)
|
|
||||||
.SetMethod("getType", &WebContents::GetType)
|
.SetMethod("getType", &WebContents::GetType)
|
||||||
.SetMethod("_getPreloadPaths", &WebContents::GetPreloadPaths)
|
.SetMethod("_getPreloadPaths", &WebContents::GetPreloadPaths)
|
||||||
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
|
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
|
||||||
|
|
|
@ -3958,19 +3958,23 @@ describe('BrowserWindow module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO(codebytere): remove in Electron v8.0.0
|
describe('frameRate APIs', () => {
|
||||||
describe('window.webContents.getFrameRate()', () => {
|
it('has default frame rate (functions)', (done) => {
|
||||||
it('has default frame rate', (done) => {
|
|
||||||
w.webContents.once('paint', function () {
|
w.webContents.once('paint', function () {
|
||||||
expect(w.webContents.getFrameRate()).to.equal(60)
|
expect(w.webContents.getFrameRate()).to.equal(60)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
// TODO(codebytere): remove in Electron v8.0.0
|
it('has default frame rate', (done) => {
|
||||||
describe('window.webContents.setFrameRate(frameRate)', () => {
|
w.webContents.once('paint', function () {
|
||||||
|
expect(w.webContents.frameRate).to.equal(60)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
||||||
|
})
|
||||||
|
|
||||||
it('sets custom frame rate', (done) => {
|
it('sets custom frame rate', (done) => {
|
||||||
w.webContents.on('dom-ready', () => {
|
w.webContents.on('dom-ready', () => {
|
||||||
w.webContents.setFrameRate(30)
|
w.webContents.setFrameRate(30)
|
||||||
|
@ -3981,16 +3985,6 @@ describe('BrowserWindow module', () => {
|
||||||
})
|
})
|
||||||
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe('window.webContents.FrameRate', () => {
|
|
||||||
it('has default frame rate', (done) => {
|
|
||||||
w.webContents.once('paint', function () {
|
|
||||||
expect(w.webContents.frameRate).to.equal(60)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
|
||||||
})
|
|
||||||
|
|
||||||
it('sets custom frame rate', (done) => {
|
it('sets custom frame rate', (done) => {
|
||||||
w.webContents.on('dom-ready', () => {
|
w.webContents.on('dom-ready', () => {
|
||||||
|
|
|
@ -770,6 +770,52 @@ describe('webContents module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('userAgent APIs', () => {
|
||||||
|
it('can set the user agent (functions)', () => {
|
||||||
|
const w = new BrowserWindow({ show: false })
|
||||||
|
const userAgent = w.webContents.getUserAgent()
|
||||||
|
|
||||||
|
w.webContents.setUserAgent('my-user-agent')
|
||||||
|
expect(w.webContents.getUserAgent()).to.equal('my-user-agent')
|
||||||
|
|
||||||
|
w.webContents.setUserAgent(userAgent)
|
||||||
|
expect(w.webContents.getUserAgent()).to.equal(userAgent)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can set the user agent (properties)', () => {
|
||||||
|
const w = new BrowserWindow({ show: false })
|
||||||
|
const userAgent = w.webContents.userAgent
|
||||||
|
|
||||||
|
w.webContents.userAgent = 'my-user-agent'
|
||||||
|
expect(w.webContents.userAgent).to.equal('my-user-agent')
|
||||||
|
|
||||||
|
w.webContents.userAgent = userAgent
|
||||||
|
expect(w.webContents.userAgent).to.equal(userAgent)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('audioMuted APIs', () => {
|
||||||
|
it('can set the audio mute level (functions)', () => {
|
||||||
|
const w = new BrowserWindow({ show: false })
|
||||||
|
|
||||||
|
w.webContents.setAudioMuted(true)
|
||||||
|
expect(w.webContents.isAudioMuted()).to.be.true()
|
||||||
|
|
||||||
|
w.webContents.setAudioMuted(false)
|
||||||
|
expect(w.webContents.isAudioMuted()).to.be.false()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can set the audio mute level (functions)', () => {
|
||||||
|
const w = new BrowserWindow({ show: false })
|
||||||
|
|
||||||
|
w.webContents.audioMuted = true
|
||||||
|
expect(w.webContents.audioMuted).to.be.true()
|
||||||
|
|
||||||
|
w.webContents.audioMuted = false
|
||||||
|
expect(w.webContents.audioMuted).to.be.false()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('zoom api', () => {
|
describe('zoom api', () => {
|
||||||
const scheme = (global as any).standardScheme
|
const scheme = (global as any).standardScheme
|
||||||
const hostZoomMap: Record<string, number> = {
|
const hostZoomMap: Record<string, number> = {
|
||||||
|
@ -800,7 +846,6 @@ describe('webContents module', () => {
|
||||||
|
|
||||||
afterEach(closeAllWindows)
|
afterEach(closeAllWindows)
|
||||||
|
|
||||||
// TODO(codebytere): remove in Electron v8.0.0
|
|
||||||
it('can set the correct zoom level (functions)', async () => {
|
it('can set the correct zoom level (functions)', async () => {
|
||||||
const w = new BrowserWindow({ show: false })
|
const w = new BrowserWindow({ show: false })
|
||||||
try {
|
try {
|
||||||
|
@ -815,7 +860,7 @@ describe('webContents module', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can set the correct zoom level', async () => {
|
it('can set the correct zoom level (properties)', async () => {
|
||||||
const w = new BrowserWindow({ show: false })
|
const w = new BrowserWindow({ show: false })
|
||||||
try {
|
try {
|
||||||
await w.loadURL('about:blank')
|
await w.loadURL('about:blank')
|
||||||
|
@ -829,6 +874,36 @@ describe('webContents module', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can set the correct zoom factor (functions)', async () => {
|
||||||
|
const w = new BrowserWindow({ show: false })
|
||||||
|
try {
|
||||||
|
await w.loadURL('about:blank')
|
||||||
|
const zoomFactor = w.webContents.getZoomFactor()
|
||||||
|
expect(zoomFactor).to.eql(1.0)
|
||||||
|
|
||||||
|
w.webContents.setZoomFactor(0.5)
|
||||||
|
const newZoomFactor = w.webContents.getZoomFactor()
|
||||||
|
expect(newZoomFactor).to.eql(0.5)
|
||||||
|
} finally {
|
||||||
|
w.webContents.setZoomFactor(1.0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can set the correct zoom factor (properties)', async () => {
|
||||||
|
const w = new BrowserWindow({ show: false })
|
||||||
|
try {
|
||||||
|
await w.loadURL('about:blank')
|
||||||
|
const zoomFactor = w.webContents.zoomFactor
|
||||||
|
expect(zoomFactor).to.eql(1.0)
|
||||||
|
|
||||||
|
w.webContents.zoomFactor = 0.5
|
||||||
|
const newZoomFactor = w.webContents.zoomFactor
|
||||||
|
expect(newZoomFactor).to.eql(0.5)
|
||||||
|
} finally {
|
||||||
|
w.webContents.zoomFactor = 1.0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('can persist zoom level across navigation', (done) => {
|
it('can persist zoom level across navigation', (done) => {
|
||||||
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, enableRemoteModule: true } })
|
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, enableRemoteModule: true } })
|
||||||
let finalNavigation = false
|
let finalNavigation = false
|
||||||
|
|
Loading…
Reference in a new issue