Use util.inherits instead of CoffeeScript's extend function
This commit is contained in:
parent
2b95aeba3c
commit
34030d7b2b
3 changed files with 367 additions and 434 deletions
|
@ -2,17 +2,14 @@ const app = require('electron').app;
|
|||
const EventEmitter = require('events').EventEmitter;
|
||||
const url = require('url');
|
||||
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; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
var AutoUpdater = (function(superClass) {
|
||||
extend(AutoUpdater, superClass);
|
||||
const util = require('util');
|
||||
|
||||
function AutoUpdater() {
|
||||
return AutoUpdater.__super__.constructor.apply(this, arguments);
|
||||
AutoUpdater.super_.call(this);
|
||||
}
|
||||
|
||||
util.inherits(AutoUpdater, EventEmitter);
|
||||
|
||||
AutoUpdater.prototype.quitAndInstall = function() {
|
||||
squirrelUpdate.processStart();
|
||||
return app.quit();
|
||||
|
@ -57,15 +54,10 @@ var AutoUpdater = (function(superClass) {
|
|||
})(this));
|
||||
};
|
||||
|
||||
|
||||
// Private: Emit both error object and message, this is to keep compatibility
|
||||
// with Old APIs.
|
||||
AutoUpdater.prototype.emitError = function(message) {
|
||||
return this.emit('error', new Error(message), message);
|
||||
};
|
||||
|
||||
return AutoUpdater;
|
||||
|
||||
})(EventEmitter);
|
||||
|
||||
module.exports = new AutoUpdater;
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
const EventEmitter = require('events').EventEmitter;
|
||||
const util = require('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; };
|
||||
var hasProp = {}.hasOwnProperty;
|
||||
|
||||
var ObjectsRegistry = (function(superClass) {
|
||||
extend(ObjectsRegistry, superClass);
|
||||
|
||||
function ObjectsRegistry() {
|
||||
ObjectsRegistry.super_.call(this);
|
||||
|
||||
this.setMaxListeners(Number.MAX_VALUE);
|
||||
this.nextId = 0;
|
||||
|
||||
|
@ -20,6 +17,8 @@ var ObjectsRegistry = (function(superClass) {
|
|||
this.owners = {};
|
||||
}
|
||||
|
||||
util.inherits(ObjectsRegistry, EventEmitter);
|
||||
|
||||
// Register a new object, the object would be kept referenced until you release
|
||||
// it explicitly.
|
||||
ObjectsRegistry.prototype.add = function(webContentsId, obj) {
|
||||
|
@ -108,8 +107,4 @@ var ObjectsRegistry = (function(superClass) {
|
|||
}
|
||||
};
|
||||
|
||||
return ObjectsRegistry;
|
||||
|
||||
})(EventEmitter);
|
||||
|
||||
module.exports = new ObjectsRegistry;
|
||||
|
|
|
@ -2,10 +2,7 @@ const WebViewImpl = require('./web-view');
|
|||
const guestViewInternal = require('./guest-view-internal');
|
||||
const webViewConstants = require('./web-view-constants');
|
||||
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;
|
||||
var util = require('util');
|
||||
|
||||
// Helper function to resolve url set in attribute.
|
||||
var a = document.createElement('a');
|
||||
|
@ -17,7 +14,6 @@ var resolveURL = function(url) {
|
|||
|
||||
// Attribute objects.
|
||||
// Default implementation of a WebView attribute.
|
||||
var WebViewAttribute = (function() {
|
||||
function WebViewAttribute(name, webViewImpl) {
|
||||
this.name = name;
|
||||
this.value = webViewImpl.webviewNode[name] || '';
|
||||
|
@ -63,18 +59,13 @@ var WebViewAttribute = (function() {
|
|||
// 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.super_.call(this, name, webViewImpl)
|
||||
}
|
||||
|
||||
util.inherits(BooleanAttribute, WebViewAttribute);
|
||||
|
||||
BooleanAttribute.prototype.getValue = function() {
|
||||
return this.webViewImpl.webviewNode.hasAttribute(this.name);
|
||||
};
|
||||
|
@ -87,18 +78,13 @@ var BooleanAttribute = (function(superClass) {
|
|||
}
|
||||
};
|
||||
|
||||
return BooleanAttribute;
|
||||
|
||||
})(WebViewAttribute);
|
||||
|
||||
// Attribute that specifies whether transparency is allowed in the webview.
|
||||
var AllowTransparencyAttribute = (function(superClass) {
|
||||
extend(AllowTransparencyAttribute, superClass);
|
||||
|
||||
function AllowTransparencyAttribute(webViewImpl) {
|
||||
AllowTransparencyAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, webViewImpl);
|
||||
AllowTransparencyAttribute.super_.call(this, webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, webViewImpl);
|
||||
}
|
||||
|
||||
util.inherits(AllowTransparencyAttribute, BooleanAttribute);
|
||||
|
||||
AllowTransparencyAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
||||
if (!this.webViewImpl.guestInstanceId) {
|
||||
return;
|
||||
|
@ -106,18 +92,13 @@ var AllowTransparencyAttribute = (function(superClass) {
|
|||
return guestViewInternal.setAllowTransparency(this.webViewImpl.guestInstanceId, this.getValue());
|
||||
};
|
||||
|
||||
return AllowTransparencyAttribute;
|
||||
|
||||
})(BooleanAttribute);
|
||||
|
||||
// Attribute used to define the demension limits of autosizing.
|
||||
var AutosizeDimensionAttribute = (function(superClass) {
|
||||
extend(AutosizeDimensionAttribute, superClass);
|
||||
|
||||
function AutosizeDimensionAttribute(name, webViewImpl) {
|
||||
AutosizeDimensionAttribute.__super__.constructor.call(this, name, webViewImpl);
|
||||
AutosizeDimensionAttribute.super_.call(this, name, webViewImpl);
|
||||
}
|
||||
|
||||
util.inherits(AutosizeDimensionAttribute, WebViewAttribute);
|
||||
|
||||
AutosizeDimensionAttribute.prototype.getValue = function() {
|
||||
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) || 0;
|
||||
};
|
||||
|
@ -139,33 +120,23 @@ var AutosizeDimensionAttribute = (function(superClass) {
|
|||
});
|
||||
};
|
||||
|
||||
return AutosizeDimensionAttribute;
|
||||
|
||||
})(WebViewAttribute);
|
||||
|
||||
// Attribute that specifies whether the webview should be autosized.
|
||||
var AutosizeAttribute = (function(superClass) {
|
||||
extend(AutosizeAttribute, superClass);
|
||||
|
||||
function AutosizeAttribute(webViewImpl) {
|
||||
AutosizeAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_AUTOSIZE, webViewImpl);
|
||||
AutosizeAttribute.super_.constructor.call(this, webViewConstants.ATTRIBUTE_AUTOSIZE, webViewImpl);
|
||||
}
|
||||
|
||||
util.inherits(AutosizeAttribute, BooleanAttribute);
|
||||
|
||||
AutosizeAttribute.prototype.handleMutation = AutosizeDimensionAttribute.prototype.handleMutation;
|
||||
|
||||
return AutosizeAttribute;
|
||||
|
||||
})(BooleanAttribute);
|
||||
|
||||
// Attribute representing the state of the storage partition.
|
||||
var PartitionAttribute = (function(superClass) {
|
||||
extend(PartitionAttribute, superClass);
|
||||
|
||||
function PartitionAttribute(webViewImpl) {
|
||||
PartitionAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_PARTITION, webViewImpl);
|
||||
PartitionAttribute.super_.constructor.call(this, webViewConstants.ATTRIBUTE_PARTITION, webViewImpl);
|
||||
this.validPartitionId = true;
|
||||
}
|
||||
|
||||
util.inherits(PartitionAttribute, WebViewAttribute);
|
||||
|
||||
PartitionAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
||||
newValue = newValue || '';
|
||||
|
||||
|
@ -181,19 +152,14 @@ var PartitionAttribute = (function(superClass) {
|
|||
}
|
||||
};
|
||||
|
||||
return PartitionAttribute;
|
||||
|
||||
})(WebViewAttribute);
|
||||
|
||||
// Attribute that handles the location and navigation of the webview.
|
||||
var SrcAttribute = (function(superClass) {
|
||||
extend(SrcAttribute, superClass);
|
||||
|
||||
function SrcAttribute(webViewImpl) {
|
||||
SrcAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_SRC, webViewImpl);
|
||||
SrcAttribute.super_.constructor.call(this, webViewConstants.ATTRIBUTE_SRC, webViewImpl);
|
||||
this.setupMutationObserver();
|
||||
}
|
||||
|
||||
util.inherits(SrcAttribute, WebViewAttribute);
|
||||
|
||||
SrcAttribute.prototype.getValue = function() {
|
||||
if (this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
||||
return resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name));
|
||||
|
@ -228,7 +194,6 @@ var SrcAttribute = (function(superClass) {
|
|||
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
|
||||
|
@ -284,42 +249,27 @@ var SrcAttribute = (function(superClass) {
|
|||
return guestContents.loadURL(this.getValue(), opts);
|
||||
};
|
||||
|
||||
return SrcAttribute;
|
||||
|
||||
})(WebViewAttribute);
|
||||
|
||||
// Attribute specifies HTTP referrer.
|
||||
var HttpReferrerAttribute = (function(superClass) {
|
||||
extend(HttpReferrerAttribute, superClass);
|
||||
|
||||
function HttpReferrerAttribute(webViewImpl) {
|
||||
HttpReferrerAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl);
|
||||
HttpReferrerAttribute.super_.constructor.call(this, webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl);
|
||||
}
|
||||
|
||||
return HttpReferrerAttribute;
|
||||
|
||||
})(WebViewAttribute);
|
||||
util.inherits(HttpReferrerAttribute, WebViewAttribute);
|
||||
|
||||
// Attribute specifies user agent
|
||||
var UserAgentAttribute = (function(superClass) {
|
||||
extend(UserAgentAttribute, superClass);
|
||||
|
||||
function UserAgentAttribute(webViewImpl) {
|
||||
UserAgentAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl);
|
||||
UserAgentAttribute.super_.constructor.call(this, webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl);
|
||||
}
|
||||
|
||||
return UserAgentAttribute;
|
||||
|
||||
})(WebViewAttribute);
|
||||
util.inherits(UserAgentAttribute, WebViewAttribute);
|
||||
|
||||
// Attribute that set preload script.
|
||||
var PreloadAttribute = (function(superClass) {
|
||||
extend(PreloadAttribute, superClass);
|
||||
|
||||
function PreloadAttribute(webViewImpl) {
|
||||
PreloadAttribute.__super__.constructor.call(this, webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl);
|
||||
PreloadAttribute.super_.constructor.call(this, webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl);
|
||||
}
|
||||
|
||||
util.inherits(PreloadAttribute, WebViewAttribute);
|
||||
|
||||
PreloadAttribute.prototype.getValue = function() {
|
||||
var preload, protocol;
|
||||
if (!this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
||||
|
@ -334,10 +284,6 @@ var PreloadAttribute = (function(superClass) {
|
|||
return preload;
|
||||
};
|
||||
|
||||
return PreloadAttribute;
|
||||
|
||||
})(WebViewAttribute);
|
||||
|
||||
// Sets up all of the webview attributes.
|
||||
WebViewImpl.prototype.setupWebViewAttributes = function() {
|
||||
var attribute, autosizeAttributes, i, len, results;
|
||||
|
|
Loading…
Reference in a new issue