Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: revert deprecated WebContents properties #24071

Merged
merged 1 commit into from Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 0 additions & 20 deletions docs/api/web-contents.md
Expand Up @@ -979,14 +979,10 @@ Returns `Boolean` - Whether the renderer process has crashed.

Overrides the user agent for this web page.

**[Deprecated](modernization/property-updates.md)**

#### `contents.getUserAgent()`

Returns `String` - The user agent for this web page.

**[Deprecated](modernization/property-updates.md)**

#### `contents.insertCSS(css[, options])`

* `css` String
Expand Down Expand Up @@ -1066,14 +1062,10 @@ Ignore application menu shortcuts while this web contents is focused.

Mute the audio on the current web page.

**[Deprecated](modernization/property-updates.md)**

#### `contents.isAudioMuted()`

Returns `Boolean` - Whether this page has been muted.

**[Deprecated](modernization/property-updates.md)**

#### `contents.isCurrentlyAudible()`

Returns `Boolean` - Whether audio is currently playing.
Expand All @@ -1087,14 +1079,10 @@ zoom percent divided by 100, so 300% = 3.0.

The factor must be greater than 0.0.

**[Deprecated](modernization/property-updates.md)**

#### `contents.getZoomFactor()`

Returns `Number` - the current zoom factor.

**[Deprecated](modernization/property-updates.md)**

#### `contents.setZoomLevel(level)`

* `level` Number - Zoom level.
Expand All @@ -1104,14 +1092,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
`scale := 1.2 ^ level`.

**[Deprecated](modernization/property-updates.md)**

#### `contents.getZoomLevel()`

Returns `Number` - the current zoom level.

**[Deprecated](modernization/property-updates.md)**

#### `contents.setVisualZoomLevelLimits(minimumLevel, maximumLevel)`

* `minimumLevel` Number
Expand Down Expand Up @@ -1714,14 +1698,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.
Only values between 1 and 60 are accepted.

**[Deprecated](modernization/property-updates.md)**

#### `contents.getFrameRate()`

Returns `Integer` - If *offscreen rendering* is enabled returns the current frame rate.

**[Deprecated](modernization/property-updates.md)**

#### `contents.invalidate()`

Schedules a full repaint of the window this web contents is in.
Expand Down
34 changes: 27 additions & 7 deletions lib/browser/api/web-contents.js
Expand Up @@ -442,14 +442,34 @@ WebContents.prototype._init = function () {

const event = process.electronBinding('event').createEmpty();
app.emit('web-contents-created', event, this);
};

// Deprecations
deprecate.fnToProperty(WebContents.prototype, 'audioMuted', '_isAudioMuted', '_setAudioMuted');
deprecate.fnToProperty(WebContents.prototype, 'userAgent', '_getUserAgent', '_setUserAgent');
deprecate.fnToProperty(WebContents.prototype, 'zoomLevel', '_getZoomLevel', '_setZoomLevel');
deprecate.fnToProperty(WebContents.prototype, 'zoomFactor', '_getZoomFactor', '_setZoomFactor');
deprecate.fnToProperty(WebContents.prototype, 'frameRate', '_getFrameRate', '_setFrameRate');
// Properties

Object.defineProperty(this, 'audioMuted', {
get: () => this.isAudioMuted(),
set: (muted) => this.setAudioMuted(muted)
});

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.
const { Debugger } = process.electronBinding('debugger');
Expand Down
30 changes: 10 additions & 20 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -2659,10 +2659,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("_goForward", &WebContents::GoForward)
.SetMethod("_goToOffset", &WebContents::GoToOffset)
.SetMethod("isCrashed", &WebContents::IsCrashed)
.SetMethod("_setUserAgent", &WebContents::SetUserAgent)
.SetMethod("_getUserAgent", &WebContents::GetUserAgent)
.SetProperty("userAgent", &WebContents::GetUserAgent,
&WebContents::SetUserAgent)
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
.SetMethod("getUserAgent", &WebContents::GetUserAgent)
.SetMethod("savePage", &WebContents::SavePage)
.SetMethod("openDevTools", &WebContents::OpenDevTools)
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
Expand All @@ -2673,10 +2671,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
.SetMethod("inspectElement", &WebContents::InspectElement)
.SetMethod("setIgnoreMenuShortcuts", &WebContents::SetIgnoreMenuShortcuts)
.SetMethod("_setAudioMuted", &WebContents::SetAudioMuted)
.SetMethod("_isAudioMuted", &WebContents::IsAudioMuted)
.SetProperty("audioMuted", &WebContents::IsAudioMuted,
&WebContents::SetAudioMuted)
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
.SetMethod("isCurrentlyAudible", &WebContents::IsCurrentlyAudible)
.SetMethod("undo", &WebContents::Undo)
.SetMethod("redo", &WebContents::Redo)
Expand Down Expand Up @@ -2707,20 +2703,14 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("startPainting", &WebContents::StartPainting)
.SetMethod("stopPainting", &WebContents::StopPainting)
.SetMethod("isPainting", &WebContents::IsPainting)
.SetMethod("_setFrameRate", &WebContents::SetFrameRate)
.SetMethod("_getFrameRate", &WebContents::GetFrameRate)
.SetProperty("frameRate", &WebContents::GetFrameRate,
&WebContents::SetFrameRate)
.SetMethod("setFrameRate", &WebContents::SetFrameRate)
.SetMethod("getFrameRate", &WebContents::GetFrameRate)
#endif
.SetMethod("invalidate", &WebContents::Invalidate)
.SetMethod("_setZoomLevel", &WebContents::SetZoomLevel)
.SetMethod("_getZoomLevel", &WebContents::GetZoomLevel)
.SetProperty("zoomLevel", &WebContents::GetZoomLevel,
&WebContents::SetZoomLevel)
.SetMethod("_setZoomFactor", &WebContents::SetZoomFactor)
.SetMethod("_getZoomFactor", &WebContents::GetZoomFactor)
.SetProperty("zoomFactor", &WebContents::GetZoomFactor,
&WebContents::SetZoomFactor)
.SetMethod("setZoomLevel", &WebContents::SetZoomLevel)
.SetMethod("getZoomLevel", &WebContents::GetZoomLevel)
.SetMethod("setZoomFactor", &WebContents::SetZoomFactor)
.SetMethod("getZoomFactor", &WebContents::GetZoomFactor)
.SetMethod("getType", &WebContents::GetType)
.SetMethod("_getPreloadPaths", &WebContents::GetPreloadPaths)
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
Expand Down
30 changes: 12 additions & 18 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -3998,7 +3998,7 @@ describe('BrowserWindow module', () => {
})
})

const skip = features.isOffscreenRenderingEnabled() &&
const skip = features.isOffscreenRenderingEnabled() &&
(process.platform !== 'linux' || process.arch !== 'ia32')
ifdescribe(skip)('offscreen rendering', () => {
let w: BrowserWindow
Expand Down Expand Up @@ -4081,19 +4081,23 @@ describe('BrowserWindow module', () => {
})
})

// TODO(codebytere): remove in Electron v8.0.0
describe('window.webContents.getFrameRate()', () => {
it('has default frame rate', (done) => {
w.webContents.once('paint', function (event, rect, data) {
describe('frameRate APIs', () => {
it('has default frame rate (functions)', (done) => {
w.webContents.once('paint', function () {
expect(w.webContents.getFrameRate()).to.equal(60)
done()
})
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
})
})

// TODO(codebytere): remove in Electron v8.0.0
describe('window.webContents.setFrameRate(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) => {
w.webContents.on('dom-ready', () => {
w.webContents.setFrameRate(30)
Expand All @@ -4104,16 +4108,6 @@ describe('BrowserWindow module', () => {
})
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
})
})

describe('window.webContents.FrameRate', () => {
it('has default frame rate', (done) => {
w.webContents.once('paint', function (event, rect, data) {
expect(w.webContents.frameRate).to.equal(60)
done()
})
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
})

it('sets custom frame rate', (done) => {
w.webContents.on('dom-ready', () => {
Expand Down
78 changes: 77 additions & 1 deletion spec-main/api-web-contents-spec.ts
Expand Up @@ -763,6 +763,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', () => {
const scheme = (global as any).standardScheme
const hostZoomMap: Record<string, number> = {
Expand Down Expand Up @@ -820,7 +866,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 })
try {
await w.loadURL('about:blank')
Expand All @@ -834,6 +880,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) => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } })
let finalNavigation = false
Expand Down