Merge pull request #4121 from atom/format-coffee-helpers
Format leftover CoffeeScript helpers
This commit is contained in:
commit
25afcf2673
7 changed files with 139 additions and 201 deletions
|
@ -1,28 +1,25 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
const app = require('electron').app;
|
const app = require('electron').app;
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const squirrelUpdate = require('./squirrel-update-win');
|
const squirrelUpdate = require('./squirrel-update-win');
|
||||||
|
|
||||||
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
class AutoUpdater extends EventEmitter {
|
||||||
hasProp = {}.hasOwnProperty;
|
constructor() {
|
||||||
|
super();
|
||||||
var AutoUpdater = (function(superClass) {
|
|
||||||
extend(AutoUpdater, superClass);
|
|
||||||
|
|
||||||
function AutoUpdater() {
|
|
||||||
return AutoUpdater.__super__.constructor.apply(this, arguments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoUpdater.prototype.quitAndInstall = function() {
|
quitAndInstall() {
|
||||||
squirrelUpdate.processStart();
|
squirrelUpdate.processStart();
|
||||||
return app.quit();
|
return app.quit();
|
||||||
};
|
}
|
||||||
|
|
||||||
AutoUpdater.prototype.setFeedURL = function(updateURL) {
|
setFeedURL(updateURL) {
|
||||||
return this.updateURL = updateURL;
|
return this.updateURL = updateURL;
|
||||||
};
|
}
|
||||||
|
|
||||||
AutoUpdater.prototype.checkForUpdates = function() {
|
checkForUpdates() {
|
||||||
if (!this.updateURL) {
|
if (!this.updateURL) {
|
||||||
return this.emitError('Update URL is not set');
|
return this.emitError('Update URL is not set');
|
||||||
}
|
}
|
||||||
|
@ -55,17 +52,13 @@ var AutoUpdater = (function(superClass) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
})(this));
|
})(this));
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// Private: Emit both error object and message, this is to keep compatibility
|
// Private: Emit both error object and message, this is to keep compatibility
|
||||||
// with Old APIs.
|
// with Old APIs.
|
||||||
AutoUpdater.prototype.emitError = function(message) {
|
emitError(message) {
|
||||||
return this.emit('error', new Error(message), message);
|
return this.emit('error', new Error(message), message);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return AutoUpdater;
|
|
||||||
|
|
||||||
})(EventEmitter);
|
|
||||||
|
|
||||||
module.exports = new AutoUpdater;
|
module.exports = new AutoUpdater;
|
||||||
|
|
|
@ -4,7 +4,8 @@ const binding = process.atomBinding('dialog');
|
||||||
const v8Util = process.atomBinding('v8_util');
|
const v8Util = process.atomBinding('v8_util');
|
||||||
|
|
||||||
var slice = [].slice;
|
var slice = [].slice;
|
||||||
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
var includes = [].includes;
|
||||||
|
var indexOf = [].indexOf;
|
||||||
|
|
||||||
var fileDialogProperties = {
|
var fileDialogProperties = {
|
||||||
openFile: 1 << 0,
|
openFile: 1 << 0,
|
||||||
|
@ -61,7 +62,7 @@ module.exports = {
|
||||||
properties = 0;
|
properties = 0;
|
||||||
for (prop in fileDialogProperties) {
|
for (prop in fileDialogProperties) {
|
||||||
value = fileDialogProperties[prop];
|
value = fileDialogProperties[prop];
|
||||||
if (indexOf.call(options.properties, prop) >= 0) {
|
if (includes.call(options.properties, prop)) {
|
||||||
properties |= value;
|
properties |= value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const v8Util = process.atomBinding('v8_util');
|
const v8Util = process.atomBinding('v8_util');
|
||||||
|
|
||||||
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
class ObjectsRegistry extends EventEmitter {
|
||||||
var hasProp = {}.hasOwnProperty;
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
var ObjectsRegistry = (function(superClass) {
|
|
||||||
extend(ObjectsRegistry, superClass);
|
|
||||||
|
|
||||||
function ObjectsRegistry() {
|
|
||||||
this.setMaxListeners(Number.MAX_VALUE);
|
this.setMaxListeners(Number.MAX_VALUE);
|
||||||
this.nextId = 0;
|
this.nextId = 0;
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@ var ObjectsRegistry = (function(superClass) {
|
||||||
|
|
||||||
// Register a new object, the object would be kept referenced until you release
|
// Register a new object, the object would be kept referenced until you release
|
||||||
// it explicitly.
|
// it explicitly.
|
||||||
ObjectsRegistry.prototype.add = function(webContentsId, obj) {
|
add(webContentsId, obj) {
|
||||||
var base, base1, id;
|
var base, base1, id;
|
||||||
id = this.saveToStorage(obj);
|
id = this.saveToStorage(obj);
|
||||||
|
|
||||||
|
@ -37,18 +36,16 @@ var ObjectsRegistry = (function(superClass) {
|
||||||
|
|
||||||
// Returns object's id
|
// Returns object's id
|
||||||
return id;
|
return id;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get an object according to its ID.
|
// Get an object according to its ID.
|
||||||
ObjectsRegistry.prototype.get = function(id) {
|
get(id) {
|
||||||
var ref;
|
var ref;
|
||||||
return (ref = this.storage[id]) != null ? ref.object : void 0;
|
return (ref = this.storage[id]) != null ? ref.object : void 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// Dereference an object according to its ID.
|
// Dereference an object according to its ID.
|
||||||
ObjectsRegistry.prototype.remove = function(webContentsId, id) {
|
remove(webContentsId, id) {
|
||||||
var pointer;
|
var pointer;
|
||||||
this.dereference(id, 1);
|
this.dereference(id, 1);
|
||||||
|
|
||||||
|
@ -61,10 +58,10 @@ var ObjectsRegistry = (function(superClass) {
|
||||||
if (pointer[id] === 0) {
|
if (pointer[id] === 0) {
|
||||||
return delete pointer[id];
|
return delete pointer[id];
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Clear all references to objects refrenced by the WebContents.
|
// Clear all references to objects refrenced by the WebContents.
|
||||||
ObjectsRegistry.prototype.clear = function(webContentsId) {
|
clear(webContentsId) {
|
||||||
var count, id, ref;
|
var count, id, ref;
|
||||||
this.emit("clear-" + webContentsId);
|
this.emit("clear-" + webContentsId);
|
||||||
if (this.owners[webContentsId] == null) {
|
if (this.owners[webContentsId] == null) {
|
||||||
|
@ -76,10 +73,10 @@ var ObjectsRegistry = (function(superClass) {
|
||||||
this.dereference(id, count);
|
this.dereference(id, count);
|
||||||
}
|
}
|
||||||
return delete this.owners[webContentsId];
|
return delete this.owners[webContentsId];
|
||||||
};
|
}
|
||||||
|
|
||||||
// Private: Saves the object into storage and assigns an ID for it.
|
// Private: Saves the object into storage and assigns an ID for it.
|
||||||
ObjectsRegistry.prototype.saveToStorage = function(object) {
|
saveToStorage(object) {
|
||||||
var id;
|
var id;
|
||||||
id = v8Util.getHiddenValue(object, 'atomId');
|
id = v8Util.getHiddenValue(object, 'atomId');
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
@ -92,10 +89,10 @@ var ObjectsRegistry = (function(superClass) {
|
||||||
}
|
}
|
||||||
++this.storage[id].count;
|
++this.storage[id].count;
|
||||||
return id;
|
return id;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Private: Dereference the object from store.
|
// Private: Dereference the object from store.
|
||||||
ObjectsRegistry.prototype.dereference = function(id, count) {
|
dereference(id, count) {
|
||||||
var pointer;
|
var pointer;
|
||||||
pointer = this.storage[id];
|
pointer = this.storage[id];
|
||||||
if (pointer == null) {
|
if (pointer == null) {
|
||||||
|
@ -106,10 +103,7 @@ var ObjectsRegistry = (function(superClass) {
|
||||||
v8Util.deleteHiddenValue(pointer.object, 'atomId');
|
v8Util.deleteHiddenValue(pointer.object, 'atomId');
|
||||||
return delete this.storage[id];
|
return delete this.storage[id];
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return ObjectsRegistry;
|
|
||||||
|
|
||||||
})(EventEmitter);
|
|
||||||
|
|
||||||
module.exports = new ObjectsRegistry;
|
module.exports = new ObjectsRegistry;
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
var CallbacksRegistry, v8Util,
|
'use strict';
|
||||||
slice = [].slice;
|
|
||||||
|
|
||||||
v8Util = process.atomBinding('v8_util');
|
var slice = [].slice;
|
||||||
|
|
||||||
module.exports = CallbacksRegistry = (function() {
|
const v8Util = process.atomBinding('v8_util');
|
||||||
function CallbacksRegistry() {
|
|
||||||
|
class CallbacksRegistry {
|
||||||
|
constructor() {
|
||||||
this.nextId = 0;
|
this.nextId = 0;
|
||||||
this.callbacks = {};
|
this.callbacks = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.add = function(callback) {
|
add(callback) {
|
||||||
// The callback is already added.
|
// The callback is already added.
|
||||||
var filenameAndLine, id, location, match, ref, regexp, stackString, x;
|
var filenameAndLine, id, location, match, ref, regexp, stackString, x;
|
||||||
id = v8Util.getHiddenValue(callback, 'callbackId');
|
id = v8Util.getHiddenValue(callback, 'callbackId');
|
||||||
|
@ -37,29 +38,28 @@ module.exports = CallbacksRegistry = (function() {
|
||||||
v8Util.setHiddenValue(callback, 'callbackId', id);
|
v8Util.setHiddenValue(callback, 'callbackId', id);
|
||||||
v8Util.setHiddenValue(callback, 'location', filenameAndLine);
|
v8Util.setHiddenValue(callback, 'location', filenameAndLine);
|
||||||
return id;
|
return id;
|
||||||
};
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.get = function(id) {
|
get(id) {
|
||||||
var ref;
|
var ref;
|
||||||
return (ref = this.callbacks[id]) != null ? ref : function() {};
|
return (ref = this.callbacks[id]) != null ? ref : function() {};
|
||||||
};
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.call = function() {
|
call() {
|
||||||
var args, id, ref;
|
var args, id, ref;
|
||||||
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||||
return (ref = this.get(id)).call.apply(ref, [global].concat(slice.call(args)));
|
return (ref = this.get(id)).call.apply(ref, [global].concat(slice.call(args)));
|
||||||
};
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.apply = function() {
|
apply() {
|
||||||
var args, id, ref;
|
var args, id, ref;
|
||||||
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||||
return (ref = this.get(id)).apply.apply(ref, [global].concat(slice.call(args)));
|
return (ref = this.get(id)).apply.apply(ref, [global].concat(slice.call(args)));
|
||||||
};
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.remove = function(id) {
|
remove(id) {
|
||||||
return delete this.callbacks[id];
|
return delete this.callbacks[id];
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CallbacksRegistry;
|
modules.exports = CallbacksRegistry
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ const ipcRenderer = require('electron').ipcRenderer;
|
||||||
const nativeImage = require('electron').nativeImage;
|
const nativeImage = require('electron').nativeImage;
|
||||||
|
|
||||||
var nextId = 0;
|
var nextId = 0;
|
||||||
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
var includes = [].includes;
|
||||||
|
|
||||||
var getNextId = function() {
|
var getNextId = function() {
|
||||||
return ++nextId;
|
return ++nextId;
|
||||||
|
@ -18,8 +18,8 @@ exports.getSources = function(options, callback) {
|
||||||
if (!isValid(options)) {
|
if (!isValid(options)) {
|
||||||
return callback(new Error('Invalid options'));
|
return callback(new Error('Invalid options'));
|
||||||
}
|
}
|
||||||
captureWindow = indexOf.call(options.types, 'window') >= 0;
|
captureWindow = includes.call(options.types, 'window');
|
||||||
captureScreen = indexOf.call(options.types, 'screen') >= 0;
|
captureScreen = includes.call(options.types, 'screen');
|
||||||
if (options.thumbnailSize == null) {
|
if (options.thumbnailSize == null) {
|
||||||
options.thumbnailSize = {
|
options.thumbnailSize = {
|
||||||
width: 150,
|
width: 150,
|
||||||
|
|
|
@ -4,12 +4,12 @@ const v8Util = process.atomBinding('v8_util');
|
||||||
|
|
||||||
const callbacksRegistry = new CallbacksRegistry;
|
const callbacksRegistry = new CallbacksRegistry;
|
||||||
|
|
||||||
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
var includes = [].includes;
|
||||||
|
|
||||||
// Check for circular reference.
|
// Check for circular reference.
|
||||||
var isCircular = function(field, visited) {
|
var isCircular = function(field, visited) {
|
||||||
if (typeof field === 'object') {
|
if (typeof field === 'object') {
|
||||||
if (indexOf.call(visited, field) >= 0) {
|
if (includes.call(visited, field)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
visited.push(field);
|
visited.push(field);
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
const WebViewImpl = require('./web-view');
|
const WebViewImpl = require('./web-view');
|
||||||
const guestViewInternal = require('./guest-view-internal');
|
const guestViewInternal = require('./guest-view-internal');
|
||||||
const webViewConstants = require('./web-view-constants');
|
const webViewConstants = require('./web-view-constants');
|
||||||
const remote = require('electron').remote;
|
const remote = require('electron').remote;
|
||||||
|
|
||||||
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
||||||
|
|
||||||
var hasProp = {}.hasOwnProperty;
|
|
||||||
|
|
||||||
// Helper function to resolve url set in attribute.
|
// Helper function to resolve url set in attribute.
|
||||||
var a = document.createElement('a');
|
var a = document.createElement('a');
|
||||||
|
|
||||||
|
@ -17,8 +15,8 @@ var resolveURL = function(url) {
|
||||||
|
|
||||||
// Attribute objects.
|
// Attribute objects.
|
||||||
// Default implementation of a WebView attribute.
|
// Default implementation of a WebView attribute.
|
||||||
var WebViewAttribute = (function() {
|
class WebViewAttribute {
|
||||||
function WebViewAttribute(name, webViewImpl) {
|
constructor(name, webViewImpl) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = webViewImpl.webviewNode[name] || '';
|
this.value = webViewImpl.webviewNode[name] || '';
|
||||||
this.webViewImpl = webViewImpl;
|
this.webViewImpl = webViewImpl;
|
||||||
|
@ -27,24 +25,24 @@ var WebViewAttribute = (function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves and returns the attribute's value.
|
// Retrieves and returns the attribute's value.
|
||||||
WebViewAttribute.prototype.getValue = function() {
|
getValue() {
|
||||||
return this.webViewImpl.webviewNode.getAttribute(this.name) || this.value;
|
return this.webViewImpl.webviewNode.getAttribute(this.name) || this.value;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Sets the attribute's value.
|
// Sets the attribute's value.
|
||||||
WebViewAttribute.prototype.setValue = function(value) {
|
setValue(value) {
|
||||||
return this.webViewImpl.webviewNode.setAttribute(this.name, value || '');
|
return this.webViewImpl.webviewNode.setAttribute(this.name, value || '');
|
||||||
};
|
}
|
||||||
|
|
||||||
// Changes the attribute's value without triggering its mutation handler.
|
// Changes the attribute's value without triggering its mutation handler.
|
||||||
WebViewAttribute.prototype.setValueIgnoreMutation = function(value) {
|
setValueIgnoreMutation(value) {
|
||||||
this.ignoreMutation = true;
|
this.ignoreMutation = true;
|
||||||
this.setValue(value);
|
this.setValue(value);
|
||||||
return this.ignoreMutation = false;
|
return this.ignoreMutation = false;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Defines this attribute as a property on the webview node.
|
// Defines this attribute as a property on the webview node.
|
||||||
WebViewAttribute.prototype.defineProperty = function() {
|
defineProperty() {
|
||||||
return Object.defineProperty(this.webViewImpl.webviewNode, this.name, {
|
return Object.defineProperty(this.webViewImpl.webviewNode, this.name, {
|
||||||
get: (function(_this) {
|
get: (function(_this) {
|
||||||
return function() {
|
return function() {
|
||||||
|
@ -58,71 +56,56 @@ var WebViewAttribute = (function() {
|
||||||
})(this),
|
})(this),
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
// Called when the attribute's value changes.
|
|
||||||
WebViewAttribute.prototype.handleMutation = function() {};
|
|
||||||
|
|
||||||
return WebViewAttribute;
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
// An attribute that is treated as a Boolean.
|
|
||||||
var BooleanAttribute = (function(superClass) {
|
|
||||||
extend(BooleanAttribute, superClass);
|
|
||||||
|
|
||||||
function BooleanAttribute(name, webViewImpl) {
|
|
||||||
BooleanAttribute.__super__.constructor.call(this, name, webViewImpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BooleanAttribute.prototype.getValue = function() {
|
// Called when the attribute's value changes.
|
||||||
return this.webViewImpl.webviewNode.hasAttribute(this.name);
|
handleMutation() {}
|
||||||
};
|
}
|
||||||
|
|
||||||
BooleanAttribute.prototype.setValue = function(value) {
|
// An attribute that is treated as a Boolean.
|
||||||
|
class BooleanAttribute extends WebViewAttribute {
|
||||||
|
constructor(name, webViewImpl) {
|
||||||
|
super(name, webViewImpl);
|
||||||
|
}
|
||||||
|
|
||||||
|
getValue() {
|
||||||
|
return this.webViewImpl.webviewNode.hasAttribute(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return this.webViewImpl.webviewNode.removeAttribute(this.name);
|
return this.webViewImpl.webviewNode.removeAttribute(this.name);
|
||||||
} else {
|
} else {
|
||||||
return this.webViewImpl.webviewNode.setAttribute(this.name, '');
|
return this.webViewImpl.webviewNode.setAttribute(this.name, '');
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return BooleanAttribute;
|
|
||||||
|
|
||||||
})(WebViewAttribute);
|
|
||||||
|
|
||||||
// Attribute that specifies whether transparency is allowed in the webview.
|
// Attribute that specifies whether transparency is allowed in the webview.
|
||||||
var AllowTransparencyAttribute = (function(superClass) {
|
class AllowTransparencyAttribute extends BooleanAttribute {
|
||||||
extend(AllowTransparencyAttribute, superClass);
|
constructor(webViewImpl) {
|
||||||
|
super(webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, webViewImpl);
|
||||||
function AllowTransparencyAttribute(webViewImpl) {
|
|
||||||
AllowTransparencyAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, webViewImpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AllowTransparencyAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
handleMutation(oldValue, newValue) {
|
||||||
if (!this.webViewImpl.guestInstanceId) {
|
if (!this.webViewImpl.guestInstanceId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return guestViewInternal.setAllowTransparency(this.webViewImpl.guestInstanceId, this.getValue());
|
return guestViewInternal.setAllowTransparency(this.webViewImpl.guestInstanceId, this.getValue());
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return AllowTransparencyAttribute;
|
|
||||||
|
|
||||||
})(BooleanAttribute);
|
|
||||||
|
|
||||||
// Attribute used to define the demension limits of autosizing.
|
// Attribute used to define the demension limits of autosizing.
|
||||||
var AutosizeDimensionAttribute = (function(superClass) {
|
class AutosizeDimensionAttribute extends WebViewAttribute {
|
||||||
extend(AutosizeDimensionAttribute, superClass);
|
constructor(name, webViewImpl) {
|
||||||
|
super(name, webViewImpl);
|
||||||
function AutosizeDimensionAttribute(name, webViewImpl) {
|
|
||||||
AutosizeDimensionAttribute.__super__.constructor.call(this, name, webViewImpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AutosizeDimensionAttribute.prototype.getValue = function() {
|
getValue() {
|
||||||
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) || 0;
|
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) || 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
AutosizeDimensionAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
handleMutation(oldValue, newValue) {
|
||||||
if (!this.webViewImpl.guestInstanceId) {
|
if (!this.webViewImpl.guestInstanceId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -137,36 +120,27 @@ var AutosizeDimensionAttribute = (function(superClass) {
|
||||||
height: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() || 0)
|
height: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() || 0)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return AutosizeDimensionAttribute;
|
|
||||||
|
|
||||||
})(WebViewAttribute);
|
|
||||||
|
|
||||||
// Attribute that specifies whether the webview should be autosized.
|
// Attribute that specifies whether the webview should be autosized.
|
||||||
var AutosizeAttribute = (function(superClass) {
|
class AutosizeAttribute extends BooleanAttribute {
|
||||||
extend(AutosizeAttribute, superClass);
|
constructor(webViewImpl) {
|
||||||
|
super(webViewConstants.ATTRIBUTE_AUTOSIZE, webViewImpl);
|
||||||
function AutosizeAttribute(webViewImpl) {
|
|
||||||
AutosizeAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_AUTOSIZE, webViewImpl);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AutosizeAttribute.prototype.handleMutation = AutosizeDimensionAttribute.prototype.handleMutation;
|
AutosizeAttribute.prototype.handleMutation = AutosizeDimensionAttribute.prototype.handleMutation;
|
||||||
|
|
||||||
return AutosizeAttribute;
|
|
||||||
|
|
||||||
})(BooleanAttribute);
|
|
||||||
|
|
||||||
// Attribute representing the state of the storage partition.
|
// Attribute representing the state of the storage partition.
|
||||||
var PartitionAttribute = (function(superClass) {
|
class PartitionAttribute extends WebViewAttribute {
|
||||||
extend(PartitionAttribute, superClass);
|
constructor(webViewImpl) {
|
||||||
|
super(webViewConstants.ATTRIBUTE_PARTITION, webViewImpl);
|
||||||
function PartitionAttribute(webViewImpl) {
|
|
||||||
PartitionAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_PARTITION, webViewImpl);
|
|
||||||
this.validPartitionId = true;
|
this.validPartitionId = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
handleMutation(oldValue, newValue) {
|
||||||
newValue = newValue || '';
|
newValue = newValue || '';
|
||||||
|
|
||||||
// The partition cannot change if the webview has already navigated.
|
// The partition cannot change if the webview has already navigated.
|
||||||
|
@ -179,40 +153,35 @@ var PartitionAttribute = (function(superClass) {
|
||||||
this.validPartitionId = false;
|
this.validPartitionId = false;
|
||||||
return window.console.error(webViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
|
return window.console.error(webViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return PartitionAttribute;
|
|
||||||
|
|
||||||
})(WebViewAttribute);
|
|
||||||
|
|
||||||
// Attribute that handles the location and navigation of the webview.
|
// Attribute that handles the location and navigation of the webview.
|
||||||
var SrcAttribute = (function(superClass) {
|
class SrcAttribute extends WebViewAttribute {
|
||||||
extend(SrcAttribute, superClass);
|
constructor(webViewImpl) {
|
||||||
|
super(webViewConstants.ATTRIBUTE_SRC, webViewImpl);
|
||||||
function SrcAttribute(webViewImpl) {
|
|
||||||
SrcAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_SRC, webViewImpl);
|
|
||||||
this.setupMutationObserver();
|
this.setupMutationObserver();
|
||||||
}
|
}
|
||||||
|
|
||||||
SrcAttribute.prototype.getValue = function() {
|
getValue() {
|
||||||
if (this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
if (this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
||||||
return resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name));
|
return resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name));
|
||||||
} else {
|
} else {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
SrcAttribute.prototype.setValueIgnoreMutation = function(value) {
|
setValueIgnoreMutation(value) {
|
||||||
WebViewAttribute.prototype.setValueIgnoreMutation.call(this, value);
|
super.setValueIgnoreMutation(value);
|
||||||
|
|
||||||
// takeRecords() is needed to clear queued up src mutations. Without it, it
|
// 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
|
// 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
|
// mutation observer |observer|, and then get handled even though we do not
|
||||||
// want to handle this mutation.
|
// want to handle this mutation.
|
||||||
return this.observer.takeRecords();
|
return this.observer.takeRecords();
|
||||||
};
|
}
|
||||||
|
|
||||||
SrcAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
handleMutation(oldValue, newValue) {
|
||||||
|
|
||||||
// Once we have navigated, we don't allow clearing the src attribute.
|
// Once we have navigated, we don't allow clearing the src attribute.
|
||||||
// Once <webview> enters a navigated state, it cannot return to a
|
// Once <webview> enters a navigated state, it cannot return to a
|
||||||
|
@ -226,14 +195,13 @@ var SrcAttribute = (function(superClass) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return this.parse();
|
return this.parse();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// The purpose of this mutation observer is to catch assignment to the src
|
// 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
|
// 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
|
// where the webview guest has crashed and navigating to the same address
|
||||||
// spawns off a new process.
|
// spawns off a new process.
|
||||||
SrcAttribute.prototype.setupMutationObserver = function() {
|
setupMutationObserver() {
|
||||||
var params;
|
var params;
|
||||||
this.observer = new MutationObserver((function(_this) {
|
this.observer = new MutationObserver((function(_this) {
|
||||||
return function(mutations) {
|
return function(mutations) {
|
||||||
|
@ -255,9 +223,9 @@ var SrcAttribute = (function(superClass) {
|
||||||
attributeFilter: [this.name]
|
attributeFilter: [this.name]
|
||||||
};
|
};
|
||||||
return this.observer.observe(this.webViewImpl.webviewNode, params);
|
return this.observer.observe(this.webViewImpl.webviewNode, params);
|
||||||
};
|
}
|
||||||
|
|
||||||
SrcAttribute.prototype.parse = function() {
|
parse() {
|
||||||
var guestContents, httpreferrer, opts, useragent;
|
var guestContents, httpreferrer, opts, useragent;
|
||||||
if (!this.webViewImpl.elementAttached || !this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId || !this.getValue()) {
|
if (!this.webViewImpl.elementAttached || !this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId || !this.getValue()) {
|
||||||
return;
|
return;
|
||||||
|
@ -282,45 +250,30 @@ var SrcAttribute = (function(superClass) {
|
||||||
}
|
}
|
||||||
guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId);
|
guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId);
|
||||||
return guestContents.loadURL(this.getValue(), opts);
|
return guestContents.loadURL(this.getValue(), opts);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return SrcAttribute;
|
|
||||||
|
|
||||||
})(WebViewAttribute);
|
|
||||||
|
|
||||||
// Attribute specifies HTTP referrer.
|
// Attribute specifies HTTP referrer.
|
||||||
var HttpReferrerAttribute = (function(superClass) {
|
class HttpReferrerAttribute extends WebViewAttribute {
|
||||||
extend(HttpReferrerAttribute, superClass);
|
constructor(webViewImpl) {
|
||||||
|
super(webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl);
|
||||||
function HttpReferrerAttribute(webViewImpl) {
|
|
||||||
HttpReferrerAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return HttpReferrerAttribute;
|
|
||||||
|
|
||||||
})(WebViewAttribute);
|
|
||||||
|
|
||||||
// Attribute specifies user agent
|
// Attribute specifies user agent
|
||||||
var UserAgentAttribute = (function(superClass) {
|
class UserAgentAttribute extends WebViewAttribute {
|
||||||
extend(UserAgentAttribute, superClass);
|
constructor(webViewImpl) {
|
||||||
|
super(webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl);
|
||||||
function UserAgentAttribute(webViewImpl) {
|
|
||||||
UserAgentAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return UserAgentAttribute;
|
|
||||||
|
|
||||||
})(WebViewAttribute);
|
|
||||||
|
|
||||||
// Attribute that set preload script.
|
// Attribute that set preload script.
|
||||||
var PreloadAttribute = (function(superClass) {
|
class PreloadAttribute extends WebViewAttribute {
|
||||||
extend(PreloadAttribute, superClass);
|
constructor(webViewImpl) {
|
||||||
|
super(webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl);
|
||||||
function PreloadAttribute(webViewImpl) {
|
|
||||||
PreloadAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PreloadAttribute.prototype.getValue = function() {
|
getValue() {
|
||||||
var preload, protocol;
|
var preload, protocol;
|
||||||
if (!this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
if (!this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
||||||
return this.value;
|
return this.value;
|
||||||
|
@ -332,11 +285,8 @@ var PreloadAttribute = (function(superClass) {
|
||||||
preload = '';
|
preload = '';
|
||||||
}
|
}
|
||||||
return preload;
|
return preload;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return PreloadAttribute;
|
|
||||||
|
|
||||||
})(WebViewAttribute);
|
|
||||||
|
|
||||||
// Sets up all of the webview attributes.
|
// Sets up all of the webview attributes.
|
||||||
WebViewImpl.prototype.setupWebViewAttributes = function() {
|
WebViewImpl.prototype.setupWebViewAttributes = function() {
|
||||||
|
|
Loading…
Reference in a new issue