diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 3a12d49ca9..bdcdc90e86 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1516,7 +1516,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, &WebContents::ShowDefinitionForSelection) .SetMethod("capturePage", &WebContents::CapturePage) .SetMethod("isFocused", &WebContents::IsFocused) - .SetMethod("isOffScreen", &WebContents::IsOffScreen) + .SetMethod("isOffscreen", &WebContents::IsOffScreen) .SetMethod("startPainting", &WebContents::StartPainting) .SetMethod("stopPainting", &WebContents::StopPainting) .SetMethod("isPainting", &WebContents::IsPainting) diff --git a/atom/browser/osr_output_device.cc b/atom/browser/osr_output_device.cc index 21b7991d9c..2a41963a82 100644 --- a/atom/browser/osr_output_device.cc +++ b/atom/browser/osr_output_device.cc @@ -17,7 +17,8 @@ OffScreenOutputDevice::OffScreenOutputDevice(bool transparent, DCHECK(!callback_.is_null()); } -OffScreenOutputDevice::~OffScreenOutputDevice() { } +OffScreenOutputDevice::~OffScreenOutputDevice() { +} void OffScreenOutputDevice::Resize( const gfx::Size& pixel_size, float scale_factor) { diff --git a/default_app/default_app.js b/default_app/default_app.js index 918efd066a..b6aabc0bde 100644 --- a/default_app/default_app.js +++ b/default_app/default_app.js @@ -32,7 +32,7 @@ exports.load = (appUrl) => { backgroundColor: '#FFFFFF', useContentSize: true, webPreferences: { - offscreen: true, + // offscreen: true, nodeIntegration: false } }) @@ -81,7 +81,7 @@ exports.load = (appUrl) => { console.log(`browser #2: ${d < 10 ? ` ${d}` : d} ms`) start2 = end2 - })*/ + }) mainWindow3 = new BrowserWindow({ width: 800, diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 2d7c4e1708..7c2b9a7011 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1059,6 +1059,10 @@ win.webContents.on('did-finish-load', () => { Shows pop-up dictionary that searches the selected word on the page. +#### `contents.isOffscreen()` + +Indicates whether *offscreen rendering* is enabled. + #### `contents.startPainting()` If *offscreen rendering* is enabled and not painting, start painting. diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 7153e28d9e..3c123ac366 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1167,4 +1167,156 @@ describe('browser-window module', function () { w.loadURL(server.url) }) }) + + describe('offscreen rendering', function () { + it('creates offscreen window', function (done) { + this.timeout(10000) + let w_ = new BrowserWindow({ + show: false, + width: 400, + height: 400, + webPreferences: { + backgroundThrottling: false, + offscreen: true + } + }) + w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') + w_.webContents.once('paint', function (event, rect, data, size) { + assert.notEqual(data.length, 0) + done() + }) + }) + + describe('window.webContents.isOffscreen', function () { + it('has offscreen type', function () { + let w_ = new BrowserWindow({ + show: false, + width: 400, + height: 400, + webPreferences: { + backgroundThrottling: false, + offscreen: true + } + }) + w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') + assert.equal(w_.webContents.isOffscreen(), true) + }) + + it('is a regular window', function () { + assert.equal(w.webContents.isOffscreen(), false) + }) + }) + + describe('window.webContents.isPainting', function () { + it('is currently painting', function (done) { + this.timeout(10000) + let w_ = new BrowserWindow({ + show: false, + width: 400, + height: 400, + webPreferences: { + backgroundThrottling: false, + offscreen: true + } + }) + w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') + w_.webContents.once('paint', function (event, rect, data, size) { + assert.equal(w_.webContents.isPainting(), true) + done() + }) + }) + }) + + describe('window.webContents.stopPainting', function () { + it('stops painting', function (done) { + this.timeout(10000) + let w_ = new BrowserWindow({ + show: false, + width: 400, + height: 400, + webPreferences: { + backgroundThrottling: false, + offscreen: true + } + }) + w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') + + w_.webContents.on('dom-ready', function () { + w_.webContents.stopPainting() + assert.equal(w_.webContents.isPainting(), false) + done() + }) + }) + }) + + describe('window.webContents.startPainting', function () { + it('starts painting', function (done) { + this.timeout(10000) + let w_ = new BrowserWindow({ + show: false, + width: 400, + height: 400, + webPreferences: { + backgroundThrottling: false, + offscreen: true + } + }) + w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') + + w_.webContents.on('dom-ready', function () { + w_.webContents.stopPainting() + w_.webContents.startPainting() + w_.webContents.once('paint', function (event, rect, data, size) { + assert.equal(w_.webContents.isPainting(), true) + done() + }) + }) + }) + }) + + describe('window.webContents.getFrameRate', function () { + it('has default frame rate', function (done) { + this.timeout(10000) + let w_ = new BrowserWindow({ + show: false, + width: 400, + height: 400, + webPreferences: { + backgroundThrottling: false, + offscreen: true + } + }) + w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') + + w_.webContents.once('paint', function (event, rect, data, size) { + assert.equal(w_.webContents.getFrameRate(), 60) + done() + }) + }) + }) + + describe('window.webContents.setFrameRate', function () { + it('has custom frame rate', function (done) { + this.timeout(10000) + let w_ = new BrowserWindow({ + show: false, + width: 400, + height: 400, + webPreferences: { + backgroundThrottling: false, + offscreen: true + } + }) + w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') + + w_.webContents.on('dom-ready', function () { + w_.webContents.setFrameRate(30) + w_.webContents.once('paint', function (event, rect, data, size) { + assert.equal(w_.webContents.getFrameRate(), 30) + done() + }) + }) + }) + }) + }) }) diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index b9195702a3..90203410a1 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -40,11 +40,12 @@ describe('webContents module', function () { return a.getId() - b.getId() }) - assert.equal(all.length, 4) + assert.equal(all.length, 5) assert.equal(all[0].getType(), 'window') - assert.equal(all[1].getType(), 'window') - assert.equal(all[2].getType(), 'remote') - assert.equal(all[3].getType(), 'webview') + assert.equal(all[1].getType(), 'offscreen') + assert.equal(all[2].getType(), 'window') + assert.equal(all[3].getType(), 'remote') + assert.equal(all[4].getType(), 'webview') done() }) diff --git a/spec/fixtures/api/offscreen-rendering.html b/spec/fixtures/api/offscreen-rendering.html new file mode 100644 index 0000000000..8e61a75352 --- /dev/null +++ b/spec/fixtures/api/offscreen-rendering.html @@ -0,0 +1,11 @@ + +
+ + + +