From ba703deee202d00d7c9ba3fece86416d45fe8005 Mon Sep 17 00:00:00 2001 From: "trop[bot]" Date: Thu, 23 Aug 2018 15:42:08 +0900 Subject: [PATCH] Print error when removed webview attribute is used (backport: 3-0-x) (#14274) * chore: print error when removed webview attribute is used * docs: document removed webview features --- atom/browser/api/atom_api_web_contents.cc | 5 --- atom/browser/api/atom_api_web_contents.h | 1 - docs/api/breaking-changes.md | 16 +++++++ docs/api/web-contents.md | 17 -------- docs/api/webview-tag.md | 53 ----------------------- lib/browser/api/web-contents.js | 6 +++ lib/renderer/web-view/web-view.js | 26 +++++++++++ 7 files changed, 48 insertions(+), 76 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 4e0eebb799b..ce8fbeb848d 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1722,10 +1722,6 @@ void WebContents::OnCursorChange(const content::WebCursor& cursor) { } } -void WebContents::SetSize(v8::Local) { - // TODO(zcbenz): Remove this method in 4.0. -} - bool WebContents::IsGuest() const { return type_ == WEB_VIEW; } @@ -2022,7 +2018,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("beginFrameSubscription", &WebContents::BeginFrameSubscription) .SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription) .SetMethod("startDrag", &WebContents::StartDrag) - .SetMethod("setSize", &WebContents::SetSize) .SetMethod("isGuest", &WebContents::IsGuest) .SetMethod("attachToIframe", &WebContents::AttachToIframe) .SetMethod("isOffscreen", &WebContents::IsOffScreen) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index ee9c8dcb08e..336ef1f3335 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -198,7 +198,6 @@ class WebContents : public mate::TrackableObject, void CapturePage(mate::Arguments* args); // Methods for creating . - void SetSize(v8::Local); bool IsGuest() const; void AttachToIframe(content::WebContents* embedder_web_contents, int embedder_frame_id); diff --git a/docs/api/breaking-changes.md b/docs/api/breaking-changes.md index 1e38f4a8823..7e3557fbb39 100644 --- a/docs/api/breaking-changes.md +++ b/docs/api/breaking-changes.md @@ -182,6 +182,10 @@ tray.setHighlightMode('off') webContents.openDevTools({detach: true}) // Replace with webContents.openDevTools({mode: 'detach'}) + +// Removed +webContents.setSize(options) +// There is no replacement for this API ``` ## `webFrame` @@ -198,6 +202,18 @@ webFrame.registerURLSchemeAsPrivileged('app', {secure: true}) protocol.registerStandardSchemes(['app'], {secure: true}) ``` +## `` + +```js +// Removed +webview.setAttribute('disableguestresize', '') +// There is no replacement for this API + +// Removed +webview.setAttribute('guestinstance', instanceId) +// There is no replacement for this API +``` + ## Node Headers URL This is the URL specified as `disturl` in a `.npmrc` file or as the `--dist-url` diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index efba30d5be1..520b3cce7bc 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1381,23 +1381,6 @@ win.webContents.on('did-finish-load', () => { Shows pop-up dictionary that searches the selected word on the page. -#### `contents.setSize(options)` - -Set the size of the page. This is only supported for `` guest contents. - -* `options` Object - * `enableAutoSize` Boolean (optional) - true to make the webview container automatically - resize within the bounds specified by the attributes normal, min and max. - * `normal` [Size](structures/size.md) (optional) - Normal size of the page. This can be used in - combination with the [`disableguestresize`](webview-tag.md#disableguestresize) - attribute to manually resize the webview guest contents. - * `min` [Size](structures/size.md) (optional) - Minimum size of the page. This can be used in - combination with the [`disableguestresize`](webview-tag.md#disableguestresize) - attribute to manually resize the webview guest contents. - * `max` [Size](structures/size.md) (optional) - Maximium size of the page. This can be used in - combination with the [`disableguestresize`](webview-tag.md#disableguestresize) - attribute to manually resize the webview guest contents. - #### `contents.isOffscreen()` Returns `Boolean` - Indicates whether *offscreen rendering* is enabled. diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 2f790e4320a..fd48cf064f9 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -244,59 +244,6 @@ A list of strings which specifies the blink features to be disabled separated by The full list of supported feature strings can be found in the [RuntimeEnabledFeatures.json5][runtime-enabled-features] file. -### `guestinstance` - -```html - -``` - -A value that links the webview to a specific webContents. When a webview -first loads a new webContents is created and this attribute is set to its -instance identifier. Setting this attribute on a new or existing webview -connects it to the existing webContents that currently renders in a different -webview. - -The existing webview will see the `destroy` event and will then create a new -webContents when a new url is loaded. - -### `disableguestresize` - -```html - -``` - -When this attribute is present the `webview` contents will be prevented from -resizing when the `webview` element itself is resized. - -This can be used in combination with -[`webContents.setSize`](web-contents.md#contentssetsizeoptions) to manually -resize the webview contents in reaction to a window size change. This can -make resizing faster compared to relying on the webview element bounds to -automatically resize the contents. - -```javascript -const {webContents} = require('electron') - -// We assume that `win` points to a `BrowserWindow` instance containing a -// `` with `disableguestresize`. - -win.on('resize', () => { - const [width, height] = win.getContentSize() - for (let wc of webContents.getAllWebContents()) { - // Check if `wc` belongs to a webview in the `win` window. - if (wc.hostWebContents && - wc.hostWebContents.id === win.webContents.id) { - wc.setSize({ - normal: { - width: width, - height: height - } - }) - } - } -}) -``` - ## Methods The `webview` tag has the following methods: diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index 4b3e777b4dc..8f5bd037b14 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -264,6 +264,12 @@ WebContents.prototype.getZoomFactor = function (callback) { }) } +// TODO(zcbenz): Remove the stub in 4.0. +WebContents.prototype.setSize = function () { + console.error('The WebContents.setSize method has been removed, see', + 'https://github.com/electron/electron/issues/14120 for more.') +} + // Add JavaScript wrappers for WebContents class. WebContents.prototype._init = function () { // The navigation controller. diff --git a/lib/renderer/web-view/web-view.js b/lib/renderer/web-view/web-view.js index a8e6b5b108c..9e7f15bf084 100644 --- a/lib/renderer/web-view/web-view.js +++ b/lib/renderer/web-view/web-view.js @@ -16,6 +16,13 @@ const getNextId = function () { return ++nextId } +// A list of removed attributes from 3.0. +const removedAttributes = [ + 'autoresize', + 'disableguestresize', + 'guestinstance' +] + // Represents the internal state of the WebView node. class WebViewImpl { constructor (webviewNode) { @@ -24,8 +31,16 @@ class WebViewImpl { this.elementAttached = false this.beforeFirstNavigation = true + // Check for removed attributes. + for (const attributeName of removedAttributes) { + if (this.webviewNode.hasAttribute(attributeName)) { + this.reportRemovedAttribute(attributeName) + } + } + // on* Event handlers. this.on = {} + this.internalElement = this.createInternalElement() const shadowRoot = this.webviewNode.attachShadow({mode: 'open'}) shadowRoot.innerHTML = '' @@ -102,6 +117,11 @@ class WebViewImpl { // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more // details. handleWebviewAttributeMutation (attributeName, oldValue, newValue) { + if (removedAttributes.includes(attributeName)) { + this.reportRemovedAttribute(attributeName) + return + } + if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) { return } @@ -197,6 +217,12 @@ class WebViewImpl { // even documented. this.resizeObserver = new ResizeObserver(this.onElementResize.bind(this)).observe(this.internalElement) } + + // TODO(zcbenz): Remove the warning in 4.0. + reportRemovedAttribute (attributeName) { + console.error(`The "${attributeName}" attribute has been removed from the tag,`, + 'see https://github.com/electron/electron/issues/14120 for more.') + } } // Registers custom element.