autoformat more easy files
This commit is contained in:
parent
67fa250020
commit
3855a774ab
19 changed files with 1068 additions and 1076 deletions
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
'use strict'
|
||||
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
const webFrame = require('electron').webFrame;
|
||||
const ipcRenderer = require('electron').ipcRenderer
|
||||
const webFrame = require('electron').webFrame
|
||||
|
||||
var requestId= 0;
|
||||
var requestId = 0
|
||||
|
||||
var WEB_VIEW_EVENTS = {
|
||||
'load-commit': ['url', 'isMainFrame'],
|
||||
|
@ -36,71 +36,71 @@ var WEB_VIEW_EVENTS = {
|
|||
'enter-html-full-screen': [],
|
||||
'leave-html-full-screen': [],
|
||||
'found-in-page': ['result']
|
||||
};
|
||||
}
|
||||
|
||||
var DEPRECATED_EVENTS = {
|
||||
'page-title-updated': 'page-title-set'
|
||||
};
|
||||
}
|
||||
|
||||
var dispatchEvent = function(webView, eventName, eventKey, ...args) {
|
||||
var domEvent, f, i, j, len, ref1;
|
||||
var dispatchEvent = function (webView, eventName, eventKey, ...args) {
|
||||
var domEvent, f, i, j, len, ref1
|
||||
if (DEPRECATED_EVENTS[eventName] != null) {
|
||||
dispatchEvent.apply(null, [webView, DEPRECATED_EVENTS[eventName], eventKey].concat(args));
|
||||
dispatchEvent.apply(null, [webView, DEPRECATED_EVENTS[eventName], eventKey].concat(args))
|
||||
}
|
||||
domEvent = new Event(eventName);
|
||||
ref1 = WEB_VIEW_EVENTS[eventKey];
|
||||
domEvent = new Event(eventName)
|
||||
ref1 = WEB_VIEW_EVENTS[eventKey]
|
||||
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
||||
f = ref1[i];
|
||||
domEvent[f] = args[i];
|
||||
f = ref1[i]
|
||||
domEvent[f] = args[i]
|
||||
}
|
||||
webView.dispatchEvent(domEvent);
|
||||
webView.dispatchEvent(domEvent)
|
||||
if (eventName === 'load-commit') {
|
||||
return webView.onLoadCommit(domEvent);
|
||||
return webView.onLoadCommit(domEvent)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerEvents: function(webView, viewInstanceId) {
|
||||
ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-" + viewInstanceId, function(event, eventName, ...args) {
|
||||
return dispatchEvent.apply(null, [webView, eventName, eventName].concat(args));
|
||||
});
|
||||
registerEvents: function (webView, viewInstanceId) {
|
||||
ipcRenderer.on('ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId, function (event, eventName, ...args) {
|
||||
return dispatchEvent.apply(null, [webView, eventName, eventName].concat(args))
|
||||
})
|
||||
|
||||
ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-" + viewInstanceId, function(event, channel, ...args) {
|
||||
var domEvent = new Event('ipc-message');
|
||||
domEvent.channel = channel;
|
||||
domEvent.args = args;
|
||||
return webView.dispatchEvent(domEvent);
|
||||
});
|
||||
ipcRenderer.on('ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId, function (event, channel, ...args) {
|
||||
var domEvent = new Event('ipc-message')
|
||||
domEvent.channel = channel
|
||||
domEvent.args = args
|
||||
return webView.dispatchEvent(domEvent)
|
||||
})
|
||||
|
||||
return ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-" + viewInstanceId, function(event, ...args) {
|
||||
var domEvent, f, i, j, len, ref1;
|
||||
domEvent = new Event('size-changed');
|
||||
ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight'];
|
||||
return ipcRenderer.on('ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId, function (event, ...args) {
|
||||
var domEvent, f, i, j, len, ref1
|
||||
domEvent = new Event('size-changed')
|
||||
ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
|
||||
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
||||
f = ref1[i];
|
||||
domEvent[f] = args[i];
|
||||
f = ref1[i]
|
||||
domEvent[f] = args[i]
|
||||
}
|
||||
return webView.onSizeChanged(domEvent);
|
||||
});
|
||||
return webView.onSizeChanged(domEvent)
|
||||
})
|
||||
},
|
||||
deregisterEvents: function(viewInstanceId) {
|
||||
ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-" + viewInstanceId);
|
||||
ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-" + viewInstanceId);
|
||||
return ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-" + viewInstanceId);
|
||||
deregisterEvents: function (viewInstanceId) {
|
||||
ipcRenderer.removeAllListeners('ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId)
|
||||
ipcRenderer.removeAllListeners('ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId)
|
||||
return ipcRenderer.removeAllListeners('ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId)
|
||||
},
|
||||
createGuest: function(params, callback) {
|
||||
requestId++;
|
||||
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId);
|
||||
return ipcRenderer.once("ATOM_SHELL_RESPONSE_" + requestId, callback);
|
||||
createGuest: function (params, callback) {
|
||||
requestId++
|
||||
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId)
|
||||
return ipcRenderer.once('ATOM_SHELL_RESPONSE_' + requestId, callback)
|
||||
},
|
||||
attachGuest: function(elementInstanceId, guestInstanceId, params) {
|
||||
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params);
|
||||
return webFrame.attachGuest(elementInstanceId);
|
||||
attachGuest: function (elementInstanceId, guestInstanceId, params) {
|
||||
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params)
|
||||
return webFrame.attachGuest(elementInstanceId)
|
||||
},
|
||||
destroyGuest: function(guestInstanceId) {
|
||||
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId);
|
||||
destroyGuest: function (guestInstanceId) {
|
||||
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId)
|
||||
},
|
||||
setSize: function(guestInstanceId, params) {
|
||||
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params);
|
||||
setSize: function (guestInstanceId, params) {
|
||||
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params)
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,95 +1,95 @@
|
|||
'use strict';
|
||||
'use strict'
|
||||
|
||||
const WebViewImpl = require('./web-view');
|
||||
const guestViewInternal = require('./guest-view-internal');
|
||||
const webViewConstants = require('./web-view-constants');
|
||||
const remote = require('electron').remote;
|
||||
const WebViewImpl = require('./web-view')
|
||||
const guestViewInternal = require('./guest-view-internal')
|
||||
const webViewConstants = require('./web-view-constants')
|
||||
const remote = require('electron').remote
|
||||
|
||||
// Helper function to resolve url set in attribute.
|
||||
var a = document.createElement('a');
|
||||
var a = document.createElement('a')
|
||||
|
||||
var resolveURL = function(url) {
|
||||
a.href = url;
|
||||
return a.href;
|
||||
};
|
||||
var resolveURL = function (url) {
|
||||
a.href = url
|
||||
return a.href
|
||||
}
|
||||
|
||||
// Attribute objects.
|
||||
// Default implementation of a WebView attribute.
|
||||
class WebViewAttribute {
|
||||
constructor(name, webViewImpl) {
|
||||
this.name = name;
|
||||
this.value = webViewImpl.webviewNode[name] || '';
|
||||
this.webViewImpl = webViewImpl;
|
||||
this.ignoreMutation = false;
|
||||
this.defineProperty();
|
||||
constructor (name, webViewImpl) {
|
||||
this.name = name
|
||||
this.value = webViewImpl.webviewNode[name] || ''
|
||||
this.webViewImpl = webViewImpl
|
||||
this.ignoreMutation = false
|
||||
this.defineProperty()
|
||||
}
|
||||
|
||||
// Retrieves and returns the attribute's value.
|
||||
getValue() {
|
||||
return this.webViewImpl.webviewNode.getAttribute(this.name) || this.value;
|
||||
getValue () {
|
||||
return this.webViewImpl.webviewNode.getAttribute(this.name) || this.value
|
||||
}
|
||||
|
||||
// Sets the attribute's value.
|
||||
setValue(value) {
|
||||
return this.webViewImpl.webviewNode.setAttribute(this.name, value || '');
|
||||
setValue (value) {
|
||||
return this.webViewImpl.webviewNode.setAttribute(this.name, value || '')
|
||||
}
|
||||
|
||||
// Changes the attribute's value without triggering its mutation handler.
|
||||
setValueIgnoreMutation(value) {
|
||||
this.ignoreMutation = true;
|
||||
this.setValue(value);
|
||||
return this.ignoreMutation = false;
|
||||
setValueIgnoreMutation (value) {
|
||||
this.ignoreMutation = true
|
||||
this.setValue(value)
|
||||
return this.ignoreMutation = false
|
||||
}
|
||||
|
||||
// Defines this attribute as a property on the webview node.
|
||||
defineProperty() {
|
||||
defineProperty () {
|
||||
return Object.defineProperty(this.webViewImpl.webviewNode, this.name, {
|
||||
get: () => {
|
||||
return this.getValue();
|
||||
return this.getValue()
|
||||
},
|
||||
set: (value) => {
|
||||
return this.setValue(value);
|
||||
return this.setValue(value)
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// Called when the attribute's value changes.
|
||||
handleMutation() {}
|
||||
handleMutation () {}
|
||||
}
|
||||
|
||||
// An attribute that is treated as a Boolean.
|
||||
class BooleanAttribute extends WebViewAttribute {
|
||||
constructor(name, webViewImpl) {
|
||||
super(name, webViewImpl);
|
||||
constructor (name, webViewImpl) {
|
||||
super(name, webViewImpl)
|
||||
}
|
||||
|
||||
getValue() {
|
||||
return this.webViewImpl.webviewNode.hasAttribute(this.name);
|
||||
getValue () {
|
||||
return this.webViewImpl.webviewNode.hasAttribute(this.name)
|
||||
}
|
||||
|
||||
setValue(value) {
|
||||
setValue (value) {
|
||||
if (!value) {
|
||||
return this.webViewImpl.webviewNode.removeAttribute(this.name);
|
||||
return this.webViewImpl.webviewNode.removeAttribute(this.name)
|
||||
} else {
|
||||
return this.webViewImpl.webviewNode.setAttribute(this.name, '');
|
||||
return this.webViewImpl.webviewNode.setAttribute(this.name, '')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attribute used to define the demension limits of autosizing.
|
||||
class AutosizeDimensionAttribute extends WebViewAttribute {
|
||||
constructor(name, webViewImpl) {
|
||||
super(name, webViewImpl);
|
||||
constructor (name, webViewImpl) {
|
||||
super(name, webViewImpl)
|
||||
}
|
||||
|
||||
getValue() {
|
||||
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) || 0;
|
||||
getValue () {
|
||||
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) || 0
|
||||
}
|
||||
|
||||
handleMutation() {
|
||||
handleMutation () {
|
||||
if (!this.webViewImpl.guestInstanceId) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
return guestViewInternal.setSize(this.webViewImpl.guestInstanceId, {
|
||||
enableAutoSize: this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue(),
|
||||
|
@ -101,197 +101,194 @@ class AutosizeDimensionAttribute extends WebViewAttribute {
|
|||
width: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() || 0),
|
||||
height: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() || 0)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Attribute that specifies whether the webview should be autosized.
|
||||
class AutosizeAttribute extends BooleanAttribute {
|
||||
constructor(webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_AUTOSIZE, webViewImpl);
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_AUTOSIZE, webViewImpl)
|
||||
}
|
||||
}
|
||||
|
||||
AutosizeAttribute.prototype.handleMutation = AutosizeDimensionAttribute.prototype.handleMutation;
|
||||
AutosizeAttribute.prototype.handleMutation = AutosizeDimensionAttribute.prototype.handleMutation
|
||||
|
||||
// Attribute representing the state of the storage partition.
|
||||
class PartitionAttribute extends WebViewAttribute {
|
||||
constructor(webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_PARTITION, webViewImpl);
|
||||
this.validPartitionId = true;
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_PARTITION, webViewImpl)
|
||||
this.validPartitionId = true
|
||||
}
|
||||
|
||||
handleMutation(oldValue, newValue) {
|
||||
newValue = newValue || '';
|
||||
handleMutation (oldValue, newValue) {
|
||||
newValue = newValue || ''
|
||||
|
||||
// The partition cannot change if the webview has already navigated.
|
||||
if (!this.webViewImpl.beforeFirstNavigation) {
|
||||
window.console.error(webViewConstants.ERROR_MSG_ALREADY_NAVIGATED);
|
||||
this.setValueIgnoreMutation(oldValue);
|
||||
return;
|
||||
window.console.error(webViewConstants.ERROR_MSG_ALREADY_NAVIGATED)
|
||||
this.setValueIgnoreMutation(oldValue)
|
||||
return
|
||||
}
|
||||
if (newValue === 'persist:') {
|
||||
this.validPartitionId = false;
|
||||
return window.console.error(webViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
|
||||
this.validPartitionId = false
|
||||
return window.console.error(webViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attribute that handles the location and navigation of the webview.
|
||||
class SrcAttribute extends WebViewAttribute {
|
||||
constructor(webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_SRC, webViewImpl);
|
||||
this.setupMutationObserver();
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_SRC, webViewImpl)
|
||||
this.setupMutationObserver()
|
||||
}
|
||||
|
||||
getValue() {
|
||||
getValue () {
|
||||
if (this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
||||
return resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name));
|
||||
return resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name))
|
||||
} else {
|
||||
return this.value;
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
|
||||
setValueIgnoreMutation(value) {
|
||||
super.setValueIgnoreMutation(value);
|
||||
setValueIgnoreMutation (value) {
|
||||
super.setValueIgnoreMutation(value)
|
||||
|
||||
// takeRecords() is needed to clear queued up src mutations. Without it, it
|
||||
// is possible for this change to get picked up asyncronously by src's
|
||||
// mutation observer |observer|, and then get handled even though we do not
|
||||
// want to handle this mutation.
|
||||
return this.observer.takeRecords();
|
||||
return this.observer.takeRecords()
|
||||
}
|
||||
|
||||
handleMutation(oldValue, newValue) {
|
||||
|
||||
handleMutation (oldValue, newValue) {
|
||||
// Once we have navigated, we don't allow clearing the src attribute.
|
||||
// Once <webview> enters a navigated state, it cannot return to a
|
||||
// placeholder state.
|
||||
if (!newValue && oldValue) {
|
||||
|
||||
// src attribute changes normally initiate a navigation. We suppress
|
||||
// the next src attribute handler call to avoid reloading the page
|
||||
// on every guest-initiated navigation.
|
||||
this.setValueIgnoreMutation(oldValue);
|
||||
return;
|
||||
this.setValueIgnoreMutation(oldValue)
|
||||
return
|
||||
}
|
||||
return this.parse();
|
||||
return this.parse()
|
||||
}
|
||||
|
||||
// The purpose of this mutation observer is to catch assignment to the src
|
||||
// attribute without any changes to its value. This is useful in the case
|
||||
// where the webview guest has crashed and navigating to the same address
|
||||
// spawns off a new process.
|
||||
setupMutationObserver() {
|
||||
var params;
|
||||
setupMutationObserver () {
|
||||
var params
|
||||
this.observer = new MutationObserver((mutations) => {
|
||||
var i, len, mutation, newValue, oldValue;
|
||||
var i, len, mutation, newValue, oldValue
|
||||
for (i = 0, len = mutations.length; i < len; i++) {
|
||||
mutation = mutations[i];
|
||||
oldValue = mutation.oldValue;
|
||||
newValue = this.getValue();
|
||||
mutation = mutations[i]
|
||||
oldValue = mutation.oldValue
|
||||
newValue = this.getValue()
|
||||
if (oldValue !== newValue) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
this.handleMutation(oldValue, newValue);
|
||||
this.handleMutation(oldValue, newValue)
|
||||
}
|
||||
});
|
||||
})
|
||||
params = {
|
||||
attributes: true,
|
||||
attributeOldValue: true,
|
||||
attributeFilter: [this.name]
|
||||
};
|
||||
return this.observer.observe(this.webViewImpl.webviewNode, params);
|
||||
}
|
||||
return this.observer.observe(this.webViewImpl.webviewNode, params)
|
||||
}
|
||||
|
||||
parse() {
|
||||
var guestContents, httpreferrer, opts, useragent;
|
||||
parse () {
|
||||
var guestContents, httpreferrer, opts, useragent
|
||||
if (!this.webViewImpl.elementAttached || !this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId || !this.getValue()) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
if (this.webViewImpl.guestInstanceId == null) {
|
||||
if (this.webViewImpl.beforeFirstNavigation) {
|
||||
this.webViewImpl.beforeFirstNavigation = false;
|
||||
this.webViewImpl.createGuest();
|
||||
this.webViewImpl.beforeFirstNavigation = false
|
||||
this.webViewImpl.createGuest()
|
||||
}
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
// Navigate to |this.src|.
|
||||
opts = {};
|
||||
httpreferrer = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue();
|
||||
opts = {}
|
||||
httpreferrer = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue()
|
||||
if (httpreferrer) {
|
||||
opts.httpReferrer = httpreferrer;
|
||||
opts.httpReferrer = httpreferrer
|
||||
}
|
||||
useragent = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_USERAGENT].getValue();
|
||||
useragent = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_USERAGENT].getValue()
|
||||
if (useragent) {
|
||||
opts.userAgent = useragent;
|
||||
opts.userAgent = useragent
|
||||
}
|
||||
guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId);
|
||||
return guestContents.loadURL(this.getValue(), opts);
|
||||
guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId)
|
||||
return guestContents.loadURL(this.getValue(), opts)
|
||||
}
|
||||
}
|
||||
|
||||
// Attribute specifies HTTP referrer.
|
||||
class HttpReferrerAttribute extends WebViewAttribute {
|
||||
constructor(webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl);
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl)
|
||||
}
|
||||
}
|
||||
|
||||
// Attribute specifies user agent
|
||||
class UserAgentAttribute extends WebViewAttribute {
|
||||
constructor(webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl);
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl)
|
||||
}
|
||||
}
|
||||
|
||||
// Attribute that set preload script.
|
||||
class PreloadAttribute extends WebViewAttribute {
|
||||
constructor(webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl);
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl)
|
||||
}
|
||||
|
||||
getValue() {
|
||||
var preload, protocol;
|
||||
getValue () {
|
||||
var preload, protocol
|
||||
if (!this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
||||
return this.value;
|
||||
return this.value
|
||||
}
|
||||
preload = resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name));
|
||||
protocol = preload.substr(0, 5);
|
||||
preload = resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name))
|
||||
protocol = preload.substr(0, 5)
|
||||
if (protocol !== 'file:') {
|
||||
console.error(webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE);
|
||||
preload = '';
|
||||
console.error(webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE)
|
||||
preload = ''
|
||||
}
|
||||
return preload;
|
||||
return preload
|
||||
}
|
||||
}
|
||||
|
||||
// Attribute that specifies the blink features to be enabled.
|
||||
class BlinkFeaturesAttribute extends WebViewAttribute {
|
||||
constructor(webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_BLINKFEATURES, webViewImpl);
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_BLINKFEATURES, webViewImpl)
|
||||
}
|
||||
}
|
||||
|
||||
// Sets up all of the webview attributes.
|
||||
WebViewImpl.prototype.setupWebViewAttributes = function() {
|
||||
this.attributes = {};
|
||||
this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE] = new AutosizeAttribute(this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PARTITION] = new PartitionAttribute(this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_SRC] = new SrcAttribute(this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER] = new HttpReferrerAttribute(this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_USERAGENT] = new UserAgentAttribute(this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_NODEINTEGRATION] = new BooleanAttribute(webViewConstants.ATTRIBUTE_NODEINTEGRATION, this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PLUGINS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_PLUGINS, this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_DISABLEWEBSECURITY] = new BooleanAttribute(webViewConstants.ATTRIBUTE_DISABLEWEBSECURITY, this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_ALLOWPOPUPS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_ALLOWPOPUPS, this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this);
|
||||
this.attributes[webViewConstants.ATTRIBUTE_BLINKFEATURES] = new BlinkFeaturesAttribute(this);
|
||||
WebViewImpl.prototype.setupWebViewAttributes = function () {
|
||||
this.attributes = {}
|
||||
this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE] = new AutosizeAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PARTITION] = new PartitionAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_SRC] = new SrcAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER] = new HttpReferrerAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_USERAGENT] = new UserAgentAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_NODEINTEGRATION] = new BooleanAttribute(webViewConstants.ATTRIBUTE_NODEINTEGRATION, this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PLUGINS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_PLUGINS, this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_DISABLEWEBSECURITY] = new BooleanAttribute(webViewConstants.ATTRIBUTE_DISABLEWEBSECURITY, this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_ALLOWPOPUPS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_ALLOWPOPUPS, this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_BLINKFEATURES] = new BlinkFeaturesAttribute(this)
|
||||
|
||||
const autosizeAttributes = [webViewConstants.ATTRIBUTE_MAXHEIGHT, webViewConstants.ATTRIBUTE_MAXWIDTH, webViewConstants.ATTRIBUTE_MINHEIGHT, webViewConstants.ATTRIBUTE_MINWIDTH];
|
||||
const autosizeAttributes = [webViewConstants.ATTRIBUTE_MAXHEIGHT, webViewConstants.ATTRIBUTE_MAXWIDTH, webViewConstants.ATTRIBUTE_MINHEIGHT, webViewConstants.ATTRIBUTE_MINWIDTH]
|
||||
autosizeAttributes.forEach((attribute) => {
|
||||
this.attributes[attribute] = new AutosizeDimensionAttribute(attribute, this);
|
||||
});
|
||||
};
|
||||
this.attributes[attribute] = new AutosizeDimensionAttribute(attribute, this)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -25,4 +25,4 @@ module.exports = {
|
|||
ERROR_MSG_CANNOT_INJECT_SCRIPT: '<webview>: ' + 'Script cannot be injected into content until the page has loaded.',
|
||||
ERROR_MSG_INVALID_PARTITION_ATTRIBUTE: 'Invalid partition attribute.',
|
||||
ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE: 'Only "file:" protocol is supported in "preload" attribute.'
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,63 +1,63 @@
|
|||
'use strict';
|
||||
'use strict'
|
||||
|
||||
const deprecate = require('electron').deprecate;
|
||||
const webFrame = require('electron').webFrame;
|
||||
const remote = require('electron').remote;
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
const deprecate = require('electron').deprecate
|
||||
const webFrame = require('electron').webFrame
|
||||
const remote = require('electron').remote
|
||||
const ipcRenderer = require('electron').ipcRenderer
|
||||
|
||||
const v8Util = process.atomBinding('v8_util');
|
||||
const guestViewInternal = require('./guest-view-internal');
|
||||
const webViewConstants = require('./web-view-constants');
|
||||
const v8Util = process.atomBinding('v8_util')
|
||||
const guestViewInternal = require('./guest-view-internal')
|
||||
const webViewConstants = require('./web-view-constants')
|
||||
|
||||
var hasProp = {}.hasOwnProperty;
|
||||
var hasProp = {}.hasOwnProperty
|
||||
|
||||
// ID generator.
|
||||
var nextId = 0;
|
||||
var nextId = 0
|
||||
|
||||
var getNextId = function() {
|
||||
return ++nextId;
|
||||
};
|
||||
var getNextId = function () {
|
||||
return ++nextId
|
||||
}
|
||||
|
||||
// Represents the internal state of the WebView node.
|
||||
var WebViewImpl = (function() {
|
||||
function WebViewImpl(webviewNode) {
|
||||
var shadowRoot;
|
||||
this.webviewNode = webviewNode;
|
||||
v8Util.setHiddenValue(this.webviewNode, 'internal', this);
|
||||
this.attached = false;
|
||||
this.elementAttached = false;
|
||||
this.beforeFirstNavigation = true;
|
||||
var WebViewImpl = (function () {
|
||||
function WebViewImpl (webviewNode) {
|
||||
var shadowRoot
|
||||
this.webviewNode = webviewNode
|
||||
v8Util.setHiddenValue(this.webviewNode, 'internal', this)
|
||||
this.attached = false
|
||||
this.elementAttached = false
|
||||
this.beforeFirstNavigation = true
|
||||
|
||||
// on* Event handlers.
|
||||
this.on = {};
|
||||
this.browserPluginNode = this.createBrowserPluginNode();
|
||||
shadowRoot = this.webviewNode.createShadowRoot();
|
||||
shadowRoot.innerHTML = '<style>:host { display: flex; }</style>';
|
||||
this.setupWebViewAttributes();
|
||||
this.setupFocusPropagation();
|
||||
this.viewInstanceId = getNextId();
|
||||
shadowRoot.appendChild(this.browserPluginNode);
|
||||
this.on = {}
|
||||
this.browserPluginNode = this.createBrowserPluginNode()
|
||||
shadowRoot = this.webviewNode.createShadowRoot()
|
||||
shadowRoot.innerHTML = '<style>:host { display: flex; }</style>'
|
||||
this.setupWebViewAttributes()
|
||||
this.setupFocusPropagation()
|
||||
this.viewInstanceId = getNextId()
|
||||
shadowRoot.appendChild(this.browserPluginNode)
|
||||
|
||||
// Subscribe to host's zoom level changes.
|
||||
this.onZoomLevelChanged = (zoomLevel) => {
|
||||
this.webviewNode.setZoomLevel(zoomLevel);
|
||||
};
|
||||
webFrame.on('zoom-level-changed', this.onZoomLevelChanged);
|
||||
this.webviewNode.setZoomLevel(zoomLevel)
|
||||
}
|
||||
webFrame.on('zoom-level-changed', this.onZoomLevelChanged)
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.createBrowserPluginNode = function() {
|
||||
WebViewImpl.prototype.createBrowserPluginNode = function () {
|
||||
// We create BrowserPlugin as a custom element in order to observe changes
|
||||
// to attributes synchronously.
|
||||
var browserPluginNode;
|
||||
browserPluginNode = new WebViewImpl.BrowserPlugin();
|
||||
v8Util.setHiddenValue(browserPluginNode, 'internal', this);
|
||||
return browserPluginNode;
|
||||
};
|
||||
var browserPluginNode
|
||||
browserPluginNode = new WebViewImpl.BrowserPlugin()
|
||||
v8Util.setHiddenValue(browserPluginNode, 'internal', this)
|
||||
return browserPluginNode
|
||||
}
|
||||
|
||||
// Resets some state upon reattaching <webview> element to the DOM.
|
||||
WebViewImpl.prototype.reset = function() {
|
||||
WebViewImpl.prototype.reset = function () {
|
||||
// Unlisten the zoom-level-changed event.
|
||||
webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged);
|
||||
webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged)
|
||||
|
||||
// If guestInstanceId is defined then the <webview> has navigated and has
|
||||
// already picked up a partition ID. Thus, we need to reset the initialization
|
||||
|
@ -66,174 +66,172 @@ var WebViewImpl = (function() {
|
|||
// heard back from createGuest yet. We will not reset the flag in this case so
|
||||
// that we don't end up allocating a second guest.
|
||||
if (this.guestInstanceId) {
|
||||
guestViewInternal.destroyGuest(this.guestInstanceId);
|
||||
this.webContents = null;
|
||||
this.guestInstanceId = void 0;
|
||||
this.beforeFirstNavigation = true;
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId = true;
|
||||
guestViewInternal.destroyGuest(this.guestInstanceId)
|
||||
this.webContents = null
|
||||
this.guestInstanceId = void 0
|
||||
this.beforeFirstNavigation = true
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId = true
|
||||
}
|
||||
return this.internalInstanceId = 0;
|
||||
};
|
||||
return this.internalInstanceId = 0
|
||||
}
|
||||
|
||||
// Sets the <webview>.request property.
|
||||
WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function(request) {
|
||||
WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function (request) {
|
||||
return Object.defineProperty(this.webviewNode, 'request', {
|
||||
value: request,
|
||||
enumerable: true
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.setupFocusPropagation = function() {
|
||||
WebViewImpl.prototype.setupFocusPropagation = function () {
|
||||
if (!this.webviewNode.hasAttribute('tabIndex')) {
|
||||
// <webview> needs a tabIndex in order to be focusable.
|
||||
// TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
|
||||
// to allow <webview> to be focusable.
|
||||
// See http://crbug.com/231664.
|
||||
this.webviewNode.setAttribute('tabIndex', -1);
|
||||
this.webviewNode.setAttribute('tabIndex', -1)
|
||||
}
|
||||
|
||||
// Focus the BrowserPlugin when the <webview> takes focus.
|
||||
this.webviewNode.addEventListener('focus', () => {
|
||||
this.browserPluginNode.focus();
|
||||
});
|
||||
this.browserPluginNode.focus()
|
||||
})
|
||||
|
||||
// Blur the BrowserPlugin when the <webview> loses focus.
|
||||
this.webviewNode.addEventListener('blur', () => {
|
||||
this.browserPluginNode.blur();
|
||||
});
|
||||
};
|
||||
|
||||
this.browserPluginNode.blur()
|
||||
})
|
||||
}
|
||||
|
||||
// This observer monitors mutations to attributes of the <webview> and
|
||||
// updates the BrowserPlugin properties accordingly. In turn, updating
|
||||
// a BrowserPlugin property will update the corresponding BrowserPlugin
|
||||
// attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
|
||||
// details.
|
||||
WebViewImpl.prototype.handleWebviewAttributeMutation = function(attributeName, oldValue, newValue) {
|
||||
WebViewImpl.prototype.handleWebviewAttributeMutation = function (attributeName, oldValue, newValue) {
|
||||
if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
// Let the changed attribute handle its own mutation;
|
||||
return this.attributes[attributeName].handleMutation(oldValue, newValue);
|
||||
};
|
||||
// Let the changed attribute handle its own mutation
|
||||
return this.attributes[attributeName].handleMutation(oldValue, newValue)
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.handleBrowserPluginAttributeMutation = function(attributeName, oldValue, newValue) {
|
||||
WebViewImpl.prototype.handleBrowserPluginAttributeMutation = function (attributeName, oldValue, newValue) {
|
||||
if (attributeName === webViewConstants.ATTRIBUTE_INTERNALINSTANCEID && !oldValue && !!newValue) {
|
||||
this.browserPluginNode.removeAttribute(webViewConstants.ATTRIBUTE_INTERNALINSTANCEID);
|
||||
this.internalInstanceId = parseInt(newValue);
|
||||
this.browserPluginNode.removeAttribute(webViewConstants.ATTRIBUTE_INTERNALINSTANCEID)
|
||||
this.internalInstanceId = parseInt(newValue)
|
||||
|
||||
// Track when the element resizes using the element resize callback.
|
||||
webFrame.registerElementResizeCallback(this.internalInstanceId, this.onElementResize.bind(this));
|
||||
webFrame.registerElementResizeCallback(this.internalInstanceId, this.onElementResize.bind(this))
|
||||
if (!this.guestInstanceId) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams());
|
||||
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.onSizeChanged = function(webViewEvent) {
|
||||
var maxHeight, maxWidth, minHeight, minWidth, newHeight, newWidth, node, width;
|
||||
newWidth = webViewEvent.newWidth;
|
||||
newHeight = webViewEvent.newHeight;
|
||||
node = this.webviewNode;
|
||||
width = node.offsetWidth;
|
||||
WebViewImpl.prototype.onSizeChanged = function (webViewEvent) {
|
||||
var maxHeight, maxWidth, minHeight, minWidth, newHeight, newWidth, node, width
|
||||
newWidth = webViewEvent.newWidth
|
||||
newHeight = webViewEvent.newHeight
|
||||
node = this.webviewNode
|
||||
width = node.offsetWidth
|
||||
|
||||
// Check the current bounds to make sure we do not resize <webview>
|
||||
// outside of current constraints.
|
||||
maxWidth = this.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() | width;
|
||||
maxHeight = this.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() | width;
|
||||
minWidth = this.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() | width;
|
||||
minHeight = this.attributes[webViewConstants.ATTRIBUTE_MINHEIGHT].getValue() | width;
|
||||
minWidth = Math.min(minWidth, maxWidth);
|
||||
minHeight = Math.min(minHeight, maxHeight);
|
||||
maxWidth = this.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() | width
|
||||
maxHeight = this.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() | width
|
||||
minWidth = this.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() | width
|
||||
minHeight = this.attributes[webViewConstants.ATTRIBUTE_MINHEIGHT].getValue() | width
|
||||
minWidth = Math.min(minWidth, maxWidth)
|
||||
minHeight = Math.min(minHeight, maxHeight)
|
||||
if (!this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue() || (newWidth >= minWidth && newWidth <= maxWidth && newHeight >= minHeight && newHeight <= maxHeight)) {
|
||||
node.style.width = newWidth + 'px';
|
||||
node.style.height = newHeight + 'px';
|
||||
node.style.width = newWidth + 'px'
|
||||
node.style.height = newHeight + 'px'
|
||||
|
||||
// Only fire the DOM event if the size of the <webview> has actually
|
||||
// changed.
|
||||
return this.dispatchEvent(webViewEvent);
|
||||
return this.dispatchEvent(webViewEvent)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.onElementResize = function(newSize) {
|
||||
WebViewImpl.prototype.onElementResize = function (newSize) {
|
||||
// Dispatch the 'resize' event.
|
||||
var resizeEvent;
|
||||
var resizeEvent
|
||||
resizeEvent = new Event('resize', {
|
||||
bubbles: true
|
||||
});
|
||||
resizeEvent.newWidth = newSize.width;
|
||||
resizeEvent.newHeight = newSize.height;
|
||||
this.dispatchEvent(resizeEvent);
|
||||
})
|
||||
resizeEvent.newWidth = newSize.width
|
||||
resizeEvent.newHeight = newSize.height
|
||||
this.dispatchEvent(resizeEvent)
|
||||
if (this.guestInstanceId) {
|
||||
return guestViewInternal.setSize(this.guestInstanceId, {
|
||||
normal: newSize
|
||||
});
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.createGuest = function() {
|
||||
WebViewImpl.prototype.createGuest = function () {
|
||||
return guestViewInternal.createGuest(this.buildParams(), (event, guestInstanceId) => {
|
||||
this.attachWindow(guestInstanceId);
|
||||
});
|
||||
};
|
||||
this.attachWindow(guestInstanceId)
|
||||
})
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.dispatchEvent = function(webViewEvent) {
|
||||
return this.webviewNode.dispatchEvent(webViewEvent);
|
||||
};
|
||||
WebViewImpl.prototype.dispatchEvent = function (webViewEvent) {
|
||||
return this.webviewNode.dispatchEvent(webViewEvent)
|
||||
}
|
||||
|
||||
// Adds an 'on<event>' property on the webview, which can be used to set/unset
|
||||
// an event handler.
|
||||
WebViewImpl.prototype.setupEventProperty = function(eventName) {
|
||||
var propertyName;
|
||||
propertyName = 'on' + eventName.toLowerCase();
|
||||
WebViewImpl.prototype.setupEventProperty = function (eventName) {
|
||||
var propertyName
|
||||
propertyName = 'on' + eventName.toLowerCase()
|
||||
return Object.defineProperty(this.webviewNode, propertyName, {
|
||||
get: () => {
|
||||
return this.on[propertyName];
|
||||
return this.on[propertyName]
|
||||
},
|
||||
set: (value) => {
|
||||
if (this.on[propertyName]) {
|
||||
this.webviewNode.removeEventListener(eventName, this.on[propertyName]);
|
||||
this.webviewNode.removeEventListener(eventName, this.on[propertyName])
|
||||
}
|
||||
this.on[propertyName] = value;
|
||||
this.on[propertyName] = value
|
||||
if (value) {
|
||||
return this.webviewNode.addEventListener(eventName, value);
|
||||
return this.webviewNode.addEventListener(eventName, value)
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
// Updates state upon loadcommit.
|
||||
WebViewImpl.prototype.onLoadCommit = function(webViewEvent) {
|
||||
var newValue, oldValue;
|
||||
oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC);
|
||||
newValue = webViewEvent.url;
|
||||
WebViewImpl.prototype.onLoadCommit = function (webViewEvent) {
|
||||
var newValue, oldValue
|
||||
oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC)
|
||||
newValue = webViewEvent.url
|
||||
if (webViewEvent.isMainFrame && (oldValue !== newValue)) {
|
||||
|
||||
// Touching the src attribute triggers a navigation. To avoid
|
||||
// triggering a page reload on every guest-initiated navigation,
|
||||
// we do not handle this mutation.
|
||||
return this.attributes[webViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation(newValue);
|
||||
return this.attributes[webViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation(newValue)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.onAttach = function(storagePartitionId) {
|
||||
return this.attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue(storagePartitionId);
|
||||
};
|
||||
WebViewImpl.prototype.onAttach = function (storagePartitionId) {
|
||||
return this.attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue(storagePartitionId)
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.buildParams = function() {
|
||||
var attribute, attributeName, css, elementRect, params, ref1;
|
||||
WebViewImpl.prototype.buildParams = function () {
|
||||
var attribute, attributeName, css, elementRect, params, ref1
|
||||
params = {
|
||||
instanceId: this.viewInstanceId,
|
||||
userAgentOverride: this.userAgentOverride
|
||||
};
|
||||
ref1 = this.attributes;
|
||||
}
|
||||
ref1 = this.attributes
|
||||
for (attributeName in ref1) {
|
||||
if (!hasProp.call(ref1, attributeName)) continue;
|
||||
attribute = ref1[attributeName];
|
||||
params[attributeName] = attribute.getValue();
|
||||
if (!hasProp.call(ref1, attributeName)) continue
|
||||
attribute = ref1[attributeName]
|
||||
params[attributeName] = attribute.getValue()
|
||||
}
|
||||
|
||||
// When the WebView is not participating in layout (display:none)
|
||||
|
@ -241,96 +239,95 @@ var WebViewImpl = (function() {
|
|||
// However, in the case where the WebView has a fixed size we can
|
||||
// use that value to initially size the guest so as to avoid a relayout of
|
||||
// the on display:block.
|
||||
css = window.getComputedStyle(this.webviewNode, null);
|
||||
elementRect = this.webviewNode.getBoundingClientRect();
|
||||
params.elementWidth = parseInt(elementRect.width) || parseInt(css.getPropertyValue('width'));
|
||||
params.elementHeight = parseInt(elementRect.height) || parseInt(css.getPropertyValue('height'));
|
||||
return params;
|
||||
};
|
||||
css = window.getComputedStyle(this.webviewNode, null)
|
||||
elementRect = this.webviewNode.getBoundingClientRect()
|
||||
params.elementWidth = parseInt(elementRect.width) || parseInt(css.getPropertyValue('width'))
|
||||
params.elementHeight = parseInt(elementRect.height) || parseInt(css.getPropertyValue('height'))
|
||||
return params
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.attachWindow = function(guestInstanceId) {
|
||||
this.guestInstanceId = guestInstanceId;
|
||||
this.webContents = remote.getGuestWebContents(this.guestInstanceId);
|
||||
WebViewImpl.prototype.attachWindow = function (guestInstanceId) {
|
||||
this.guestInstanceId = guestInstanceId
|
||||
this.webContents = remote.getGuestWebContents(this.guestInstanceId)
|
||||
if (!this.internalInstanceId) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams());
|
||||
};
|
||||
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams())
|
||||
}
|
||||
|
||||
return WebViewImpl;
|
||||
|
||||
})();
|
||||
return WebViewImpl
|
||||
})()
|
||||
|
||||
// Registers browser plugin <object> custom element.
|
||||
var registerBrowserPluginElement = function() {
|
||||
var proto;
|
||||
proto = Object.create(HTMLObjectElement.prototype);
|
||||
proto.createdCallback = function() {
|
||||
this.setAttribute('type', 'application/browser-plugin');
|
||||
this.setAttribute('id', 'browser-plugin-' + getNextId());
|
||||
var registerBrowserPluginElement = function () {
|
||||
var proto
|
||||
proto = Object.create(HTMLObjectElement.prototype)
|
||||
proto.createdCallback = function () {
|
||||
this.setAttribute('type', 'application/browser-plugin')
|
||||
this.setAttribute('id', 'browser-plugin-' + getNextId())
|
||||
|
||||
// The <object> node fills in the <webview> container.
|
||||
return this.style.flex = '1 1 auto';
|
||||
};
|
||||
proto.attributeChangedCallback = function(name, oldValue, newValue) {
|
||||
var internal;
|
||||
internal = v8Util.getHiddenValue(this, 'internal');
|
||||
return this.style.flex = '1 1 auto'
|
||||
}
|
||||
proto.attributeChangedCallback = function (name, oldValue, newValue) {
|
||||
var internal
|
||||
internal = v8Util.getHiddenValue(this, 'internal')
|
||||
if (!internal) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
return internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue);
|
||||
};
|
||||
proto.attachedCallback = function() {
|
||||
return internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue)
|
||||
}
|
||||
proto.attachedCallback = function () {
|
||||
// Load the plugin immediately.
|
||||
return this.nonExistentAttribute;
|
||||
};
|
||||
return this.nonExistentAttribute
|
||||
}
|
||||
WebViewImpl.BrowserPlugin = webFrame.registerEmbedderCustomElement('browserplugin', {
|
||||
"extends": 'object',
|
||||
'extends': 'object',
|
||||
prototype: proto
|
||||
});
|
||||
delete proto.createdCallback;
|
||||
delete proto.attachedCallback;
|
||||
delete proto.detachedCallback;
|
||||
return delete proto.attributeChangedCallback;
|
||||
};
|
||||
})
|
||||
delete proto.createdCallback
|
||||
delete proto.attachedCallback
|
||||
delete proto.detachedCallback
|
||||
return delete proto.attributeChangedCallback
|
||||
}
|
||||
|
||||
// Registers <webview> custom element.
|
||||
var registerWebViewElement = function() {
|
||||
var createBlockHandler, createNonBlockHandler, i, j, len, len1, m, methods, nonblockMethods, proto;
|
||||
proto = Object.create(HTMLObjectElement.prototype);
|
||||
proto.createdCallback = function() {
|
||||
return new WebViewImpl(this);
|
||||
};
|
||||
proto.attributeChangedCallback = function(name, oldValue, newValue) {
|
||||
var internal;
|
||||
internal = v8Util.getHiddenValue(this, 'internal');
|
||||
var registerWebViewElement = function () {
|
||||
var createBlockHandler, createNonBlockHandler, i, j, len, len1, m, methods, nonblockMethods, proto
|
||||
proto = Object.create(HTMLObjectElement.prototype)
|
||||
proto.createdCallback = function () {
|
||||
return new WebViewImpl(this)
|
||||
}
|
||||
proto.attributeChangedCallback = function (name, oldValue, newValue) {
|
||||
var internal
|
||||
internal = v8Util.getHiddenValue(this, 'internal')
|
||||
if (!internal) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
return internal.handleWebviewAttributeMutation(name, oldValue, newValue);
|
||||
};
|
||||
proto.detachedCallback = function() {
|
||||
var internal;
|
||||
internal = v8Util.getHiddenValue(this, 'internal');
|
||||
return internal.handleWebviewAttributeMutation(name, oldValue, newValue)
|
||||
}
|
||||
proto.detachedCallback = function () {
|
||||
var internal
|
||||
internal = v8Util.getHiddenValue(this, 'internal')
|
||||
if (!internal) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
guestViewInternal.deregisterEvents(internal.viewInstanceId);
|
||||
internal.elementAttached = false;
|
||||
return internal.reset();
|
||||
};
|
||||
proto.attachedCallback = function() {
|
||||
var internal;
|
||||
internal = v8Util.getHiddenValue(this, 'internal');
|
||||
guestViewInternal.deregisterEvents(internal.viewInstanceId)
|
||||
internal.elementAttached = false
|
||||
return internal.reset()
|
||||
}
|
||||
proto.attachedCallback = function () {
|
||||
var internal
|
||||
internal = v8Util.getHiddenValue(this, 'internal')
|
||||
if (!internal) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
if (!internal.elementAttached) {
|
||||
guestViewInternal.registerEvents(internal, internal.viewInstanceId);
|
||||
internal.elementAttached = true;
|
||||
return internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse();
|
||||
guestViewInternal.registerEvents(internal, internal.viewInstanceId)
|
||||
internal.elementAttached = true
|
||||
return internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Public-facing API methods.
|
||||
methods = [
|
||||
|
@ -378,7 +375,7 @@ var registerWebViewElement = function() {
|
|||
'inspectServiceWorker',
|
||||
'print',
|
||||
'printToPDF',
|
||||
];
|
||||
]
|
||||
nonblockMethods = [
|
||||
'insertCSS',
|
||||
'insertText',
|
||||
|
@ -387,79 +384,79 @@ var registerWebViewElement = function() {
|
|||
'setZoomFactor',
|
||||
'setZoomLevel',
|
||||
'setZoomLevelLimits',
|
||||
];
|
||||
]
|
||||
|
||||
// Forward proto.foo* method calls to WebViewImpl.foo*.
|
||||
createBlockHandler = function(m) {
|
||||
return function(...args) {
|
||||
const internal = v8Util.getHiddenValue(this, 'internal');
|
||||
createBlockHandler = function (m) {
|
||||
return function (...args) {
|
||||
const internal = v8Util.getHiddenValue(this, 'internal')
|
||||
if (internal.webContents) {
|
||||
return internal.webContents[m].apply(internal.webContents, args);
|
||||
return internal.webContents[m].apply(internal.webContents, args)
|
||||
} else {
|
||||
throw new Error(`Cannot call ${m} because the webContents is unavailable. The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.`);
|
||||
throw new Error(`Cannot call ${m} because the webContents is unavailable. The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.`)
|
||||
}
|
||||
};
|
||||
};
|
||||
for (i = 0, len = methods.length; i < len; i++) {
|
||||
m = methods[i];
|
||||
proto[m] = createBlockHandler(m);
|
||||
}
|
||||
}
|
||||
for (i = 0, len = methods.length; i < len; i++) {
|
||||
m = methods[i]
|
||||
proto[m] = createBlockHandler(m)
|
||||
}
|
||||
createNonBlockHandler = function (m) {
|
||||
return function (...args) {
|
||||
const internal = v8Util.getHiddenValue(this, 'internal')
|
||||
return ipcRenderer.send.apply(ipcRenderer, ['ATOM_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', null, internal.guestInstanceId, m].concat(args))
|
||||
}
|
||||
}
|
||||
createNonBlockHandler = function(m) {
|
||||
return function(...args) {
|
||||
const internal = v8Util.getHiddenValue(this, 'internal');
|
||||
return ipcRenderer.send.apply(ipcRenderer, ['ATOM_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', null, internal.guestInstanceId, m].concat(args));
|
||||
};
|
||||
};
|
||||
for (j = 0, len1 = nonblockMethods.length; j < len1; j++) {
|
||||
m = nonblockMethods[j];
|
||||
proto[m] = createNonBlockHandler(m);
|
||||
m = nonblockMethods[j]
|
||||
proto[m] = createNonBlockHandler(m)
|
||||
}
|
||||
|
||||
proto.executeJavaScript = function(code, hasUserGesture, callback) {
|
||||
var internal = v8Util.getHiddenValue(this, 'internal');
|
||||
if (typeof hasUserGesture === "function") {
|
||||
callback = hasUserGesture;
|
||||
hasUserGesture = false;
|
||||
proto.executeJavaScript = function (code, hasUserGesture, callback) {
|
||||
var internal = v8Util.getHiddenValue(this, 'internal')
|
||||
if (typeof hasUserGesture === 'function') {
|
||||
callback = hasUserGesture
|
||||
hasUserGesture = false
|
||||
}
|
||||
let requestId = getNextId();
|
||||
ipcRenderer.send('ATOM_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', requestId, internal.guestInstanceId, "executeJavaScript", code, hasUserGesture);
|
||||
ipcRenderer.once(`ATOM_RENDERER_ASYNC_CALL_TO_GUEST_VIEW_RESPONSE_${requestId}`, function(event, result) {
|
||||
let requestId = getNextId()
|
||||
ipcRenderer.send('ATOM_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', requestId, internal.guestInstanceId, 'executeJavaScript', code, hasUserGesture)
|
||||
ipcRenderer.once(`ATOM_RENDERER_ASYNC_CALL_TO_GUEST_VIEW_RESPONSE_${requestId}`, function (event, result) {
|
||||
if (callback)
|
||||
callback(result);
|
||||
});
|
||||
};
|
||||
callback(result)
|
||||
})
|
||||
}
|
||||
|
||||
// WebContents associated with this webview.
|
||||
proto.getWebContents = function() {
|
||||
var internal = v8Util.getHiddenValue(this, 'internal');
|
||||
return internal.webContents;
|
||||
};
|
||||
proto.getWebContents = function () {
|
||||
var internal = v8Util.getHiddenValue(this, 'internal')
|
||||
return internal.webContents
|
||||
}
|
||||
|
||||
// Deprecated.
|
||||
deprecate.rename(proto, 'getUrl', 'getURL');
|
||||
deprecate.rename(proto, 'getUrl', 'getURL')
|
||||
window.WebView = webFrame.registerEmbedderCustomElement('webview', {
|
||||
prototype: proto
|
||||
});
|
||||
})
|
||||
|
||||
// Delete the callbacks so developers cannot call them and produce unexpected
|
||||
// behavior.
|
||||
delete proto.createdCallback;
|
||||
delete proto.attachedCallback;
|
||||
delete proto.detachedCallback;
|
||||
return delete proto.attributeChangedCallback;
|
||||
};
|
||||
delete proto.createdCallback
|
||||
delete proto.attachedCallback
|
||||
delete proto.detachedCallback
|
||||
return delete proto.attributeChangedCallback
|
||||
}
|
||||
|
||||
var useCapture = true;
|
||||
var useCapture = true
|
||||
|
||||
var listener = function(event) {
|
||||
var listener = function (event) {
|
||||
if (document.readyState === 'loading') {
|
||||
return;
|
||||
return
|
||||
}
|
||||
registerBrowserPluginElement();
|
||||
registerWebViewElement();
|
||||
return window.removeEventListener(event.type, listener, useCapture);
|
||||
};
|
||||
registerBrowserPluginElement()
|
||||
registerWebViewElement()
|
||||
return window.removeEventListener(event.type, listener, useCapture)
|
||||
}
|
||||
|
||||
window.addEventListener('readystatechange', listener, true);
|
||||
window.addEventListener('readystatechange', listener, true)
|
||||
|
||||
module.exports = WebViewImpl;
|
||||
module.exports = WebViewImpl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue