autoformat more easy files
This commit is contained in:
parent
67fa250020
commit
3855a774ab
19 changed files with 1068 additions and 1076 deletions
|
@ -1,20 +1,20 @@
|
||||||
(function () {
|
;(function () {
|
||||||
return function(process, require, asarSource) {
|
return function (process, require, asarSource) {
|
||||||
// Make asar.coffee accessible via "require".
|
// Make asar.coffee accessible via "require".
|
||||||
process.binding('natives').ATOM_SHELL_ASAR = asarSource;
|
process.binding('natives').ATOM_SHELL_ASAR = asarSource
|
||||||
|
|
||||||
// Monkey-patch the fs module.
|
// Monkey-patch the fs module.
|
||||||
require('ATOM_SHELL_ASAR').wrapFsWithAsar(require('fs'));
|
require('ATOM_SHELL_ASAR').wrapFsWithAsar(require('fs'))
|
||||||
|
|
||||||
// Make graceful-fs work with asar.
|
// Make graceful-fs work with asar.
|
||||||
var source = process.binding('natives');
|
var source = process.binding('natives')
|
||||||
source['original-fs'] = source.fs;
|
source['original-fs'] = source.fs
|
||||||
return source['fs'] = `
|
return source['fs'] = `
|
||||||
var nativeModule = new process.NativeModule('original-fs');
|
var nativeModule = new process.NativeModule('original-fs')
|
||||||
nativeModule.cache();
|
nativeModule.cache()
|
||||||
nativeModule.compile();
|
nativeModule.compile()
|
||||||
var asar = require('ATOM_SHELL_ASAR');
|
var asar = require('ATOM_SHELL_ASAR')
|
||||||
asar.wrapFsWithAsar(nativeModule.exports);
|
asar.wrapFsWithAsar(nativeModule.exports)
|
||||||
module.exports = nativeModule.exports`;
|
module.exports = nativeModule.exports`
|
||||||
};
|
}
|
||||||
})();
|
})()
|
||||||
|
|
|
@ -1,47 +1,46 @@
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
const timers = require('timers');
|
const timers = require('timers')
|
||||||
const Module = require('module');
|
const Module = require('module')
|
||||||
|
|
||||||
process.atomBinding = function(name) {
|
process.atomBinding = function (name) {
|
||||||
try {
|
try {
|
||||||
return process.binding("atom_" + process.type + "_" + name);
|
return process.binding('atom_' + process.type + '_' + name)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (/No such module/.test(error.message)) {
|
if (/No such module/.test(error.message)) {
|
||||||
return process.binding("atom_common_" + name);
|
return process.binding('atom_common_' + name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
||||||
// Add common/api/lib to module search paths.
|
// Add common/api/lib to module search paths.
|
||||||
Module.globalPaths.push(path.join(__dirname, 'api'));
|
Module.globalPaths.push(path.join(__dirname, 'api'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// setImmediate and process.nextTick makes use of uv_check and uv_prepare to
|
// setImmediate and process.nextTick makes use of uv_check and uv_prepare to
|
||||||
// run the callbacks, however since we only run uv loop on requests, the
|
// run the callbacks, however since we only run uv loop on requests, the
|
||||||
// callbacks wouldn't be called until something else activated the uv loop,
|
// callbacks wouldn't be called until something else activated the uv loop,
|
||||||
// which would delay the callbacks for arbitrary long time. So we should
|
// which would delay the callbacks for arbitrary long time. So we should
|
||||||
// initiatively activate the uv loop once setImmediate and process.nextTick is
|
// initiatively activate the uv loop once setImmediate and process.nextTick is
|
||||||
// called.
|
// called.
|
||||||
var wrapWithActivateUvLoop = function(func) {
|
var wrapWithActivateUvLoop = function (func) {
|
||||||
return function() {
|
return function () {
|
||||||
process.activateUvLoop();
|
process.activateUvLoop()
|
||||||
return func.apply(this, arguments);
|
return func.apply(this, arguments)
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
process.nextTick = wrapWithActivateUvLoop(process.nextTick);
|
process.nextTick = wrapWithActivateUvLoop(process.nextTick)
|
||||||
|
|
||||||
global.setImmediate = wrapWithActivateUvLoop(timers.setImmediate);
|
global.setImmediate = wrapWithActivateUvLoop(timers.setImmediate)
|
||||||
|
|
||||||
global.clearImmediate = timers.clearImmediate;
|
global.clearImmediate = timers.clearImmediate
|
||||||
|
|
||||||
if (process.type === 'browser') {
|
if (process.type === 'browser') {
|
||||||
// setTimeout needs to update the polling timeout of the event loop, when
|
// setTimeout needs to update the polling timeout of the event loop, when
|
||||||
// called under Chromium's event loop the node's event loop won't get a chance
|
// called under Chromium's event loop the node's event loop won't get a chance
|
||||||
// to update the timeout, so we have to force the node's event loop to
|
// to update the timeout, so we have to force the node's event loop to
|
||||||
// recalculate the timeout in browser process.
|
// recalculate the timeout in browser process.
|
||||||
global.setTimeout = wrapWithActivateUvLoop(timers.setTimeout);
|
global.setTimeout = wrapWithActivateUvLoop(timers.setTimeout)
|
||||||
global.setInterval = wrapWithActivateUvLoop(timers.setInterval);
|
global.setInterval = wrapWithActivateUvLoop(timers.setInterval)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,36 @@
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
const Module = require('module');
|
const Module = require('module')
|
||||||
|
|
||||||
// Clear Node's global search paths.
|
// Clear Node's global search paths.
|
||||||
Module.globalPaths.length = 0;
|
Module.globalPaths.length = 0
|
||||||
|
|
||||||
// Clear current and parent(init.coffee)'s search paths.
|
// Clear current and parent(init.coffee)'s search paths.
|
||||||
module.paths = [];
|
module.paths = []
|
||||||
|
|
||||||
module.parent.paths = [];
|
module.parent.paths = []
|
||||||
|
|
||||||
// Prevent Node from adding paths outside this app to search paths.
|
// Prevent Node from adding paths outside this app to search paths.
|
||||||
Module._nodeModulePaths = function(from) {
|
Module._nodeModulePaths = function (from) {
|
||||||
var dir, i, part, parts, paths, skipOutsidePaths, splitRe, tip;
|
var dir, i, part, parts, paths, skipOutsidePaths, splitRe, tip
|
||||||
from = path.resolve(from);
|
from = path.resolve(from)
|
||||||
|
|
||||||
// If "from" is outside the app then we do nothing.
|
// If "from" is outside the app then we do nothing.
|
||||||
skipOutsidePaths = from.startsWith(process.resourcesPath);
|
skipOutsidePaths = from.startsWith(process.resourcesPath)
|
||||||
|
|
||||||
// Following logoic is copied from module.js.
|
// Following logoic is copied from module.js.
|
||||||
splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//;
|
splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//
|
||||||
paths = [];
|
paths = []
|
||||||
parts = from.split(splitRe);
|
parts = from.split(splitRe)
|
||||||
for (tip = i = parts.length - 1; i >= 0; tip = i += -1) {
|
for (tip = i = parts.length - 1; i >= 0; tip = i += -1) {
|
||||||
part = parts[tip];
|
part = parts[tip]
|
||||||
if (part === 'node_modules') {
|
if (part === 'node_modules') {
|
||||||
continue;
|
continue
|
||||||
}
|
}
|
||||||
dir = parts.slice(0, tip + 1).join(path.sep);
|
dir = parts.slice(0, tip + 1).join(path.sep)
|
||||||
if (skipOutsidePaths && !dir.startsWith(process.resourcesPath)) {
|
if (skipOutsidePaths && !dir.startsWith(process.resourcesPath)) {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
paths.push(path.join(dir, 'node_modules'));
|
paths.push(path.join(dir, 'node_modules'))
|
||||||
}
|
}
|
||||||
return paths;
|
return paths
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,47 +1,47 @@
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer
|
||||||
const nativeImage = require('electron').nativeImage;
|
const nativeImage = require('electron').nativeImage
|
||||||
|
|
||||||
var nextId = 0;
|
var nextId = 0
|
||||||
var includes = [].includes;
|
var includes = [].includes
|
||||||
|
|
||||||
var getNextId = function() {
|
var getNextId = function () {
|
||||||
return ++nextId;
|
return ++nextId
|
||||||
};
|
}
|
||||||
|
|
||||||
// |options.type| can not be empty and has to include 'window' or 'screen'.
|
// |options.type| can not be empty and has to include 'window' or 'screen'.
|
||||||
var isValid = function(options) {
|
var isValid = function (options) {
|
||||||
return ((options != null ? options.types : void 0) != null) && Array.isArray(options.types);
|
return ((options != null ? options.types : void 0) != null) && Array.isArray(options.types)
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.getSources = function(options, callback) {
|
exports.getSources = function (options, callback) {
|
||||||
var captureScreen, captureWindow, id;
|
var captureScreen, captureWindow, id
|
||||||
if (!isValid(options)) {
|
if (!isValid(options)) {
|
||||||
return callback(new Error('Invalid options'));
|
return callback(new Error('Invalid options'))
|
||||||
}
|
}
|
||||||
captureWindow = includes.call(options.types, 'window');
|
captureWindow = includes.call(options.types, 'window')
|
||||||
captureScreen = includes.call(options.types, 'screen');
|
captureScreen = includes.call(options.types, 'screen')
|
||||||
if (options.thumbnailSize == null) {
|
if (options.thumbnailSize == null) {
|
||||||
options.thumbnailSize = {
|
options.thumbnailSize = {
|
||||||
width: 150,
|
width: 150,
|
||||||
height: 150
|
height: 150
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
id = getNextId();
|
id = getNextId()
|
||||||
ipcRenderer.send('ATOM_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, options.thumbnailSize, id);
|
ipcRenderer.send('ATOM_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, options.thumbnailSize, id)
|
||||||
return ipcRenderer.once("ATOM_RENDERER_DESKTOP_CAPTURER_RESULT_" + id, function(event, sources) {
|
return ipcRenderer.once('ATOM_RENDERER_DESKTOP_CAPTURER_RESULT_' + id, function (event, sources) {
|
||||||
var source;
|
var source
|
||||||
return callback(null, (function() {
|
return callback(null, (function () {
|
||||||
var i, len, results;
|
var i, len, results
|
||||||
results = [];
|
results = []
|
||||||
for (i = 0, len = sources.length; i < len; i++) {
|
for (i = 0, len = sources.length; i < len; i++) {
|
||||||
source = sources[i];
|
source = sources[i]
|
||||||
results.push({
|
results.push({
|
||||||
id: source.id,
|
id: source.id,
|
||||||
name: source.name,
|
name: source.name,
|
||||||
thumbnail: nativeImage.createFromDataURL(source.thumbnail)
|
thumbnail: nativeImage.createFromDataURL(source.thumbnail)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
return results;
|
return results
|
||||||
})());
|
})())
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,38 +1,38 @@
|
||||||
const common = require('../../../common/api/exports/electron');
|
const common = require('../../../common/api/exports/electron')
|
||||||
|
|
||||||
// Import common modules.
|
// Import common modules.
|
||||||
common.defineProperties(exports);
|
common.defineProperties(exports)
|
||||||
|
|
||||||
Object.defineProperties(exports, {
|
Object.defineProperties(exports, {
|
||||||
// Renderer side modules, please sort with alphabet order.
|
// Renderer side modules, please sort with alphabet order.
|
||||||
desktopCapturer: {
|
desktopCapturer: {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: function() {
|
get: function () {
|
||||||
return require('../desktop-capturer');
|
return require('../desktop-capturer')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ipcRenderer: {
|
ipcRenderer: {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: function() {
|
get: function () {
|
||||||
return require('../ipc-renderer');
|
return require('../ipc-renderer')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
remote: {
|
remote: {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: function() {
|
get: function () {
|
||||||
return require('../remote');
|
return require('../remote')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
screen: {
|
screen: {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: function() {
|
get: function () {
|
||||||
return require('../screen');
|
return require('../screen')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
webFrame: {
|
webFrame: {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: function() {
|
get: function () {
|
||||||
return require('../web-frame');
|
return require('../web-frame')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const binding = process.atomBinding('ipc');
|
const binding = process.atomBinding('ipc')
|
||||||
const v8Util = process.atomBinding('v8_util');
|
const v8Util = process.atomBinding('v8_util')
|
||||||
|
|
||||||
// Created by init.js.
|
// Created by init.js.
|
||||||
const ipcRenderer = v8Util.getHiddenValue(global, 'ipc');
|
const ipcRenderer = v8Util.getHiddenValue(global, 'ipc')
|
||||||
|
|
||||||
ipcRenderer.send = function(...args) {
|
ipcRenderer.send = function (...args) {
|
||||||
return binding.send('ipc-message', args);
|
return binding.send('ipc-message', args)
|
||||||
};
|
}
|
||||||
|
|
||||||
ipcRenderer.sendSync = function(...args) {
|
ipcRenderer.sendSync = function (...args) {
|
||||||
return JSON.parse(binding.sendSync('ipc-message-sync', args));
|
return JSON.parse(binding.sendSync('ipc-message-sync', args))
|
||||||
};
|
}
|
||||||
|
|
||||||
ipcRenderer.sendToHost = function(...args) {
|
ipcRenderer.sendToHost = function (...args) {
|
||||||
return binding.send('ipc-message-host', args);
|
return binding.send('ipc-message-host', args)
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = ipcRenderer;
|
module.exports = ipcRenderer
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer
|
||||||
const deprecate = require('electron').deprecate;
|
const deprecate = require('electron').deprecate
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter
|
||||||
|
|
||||||
// This module is deprecated, we mirror everything from ipcRenderer.
|
// This module is deprecated, we mirror everything from ipcRenderer.
|
||||||
deprecate.warn('ipc module', 'require("electron").ipcRenderer');
|
deprecate.warn('ipc module', 'require("electron").ipcRenderer')
|
||||||
|
|
||||||
// Routes events of ipcRenderer.
|
// Routes events of ipcRenderer.
|
||||||
var ipc = new EventEmitter;
|
var ipc = new EventEmitter
|
||||||
|
|
||||||
ipcRenderer.emit = function(channel, event, ...args) {
|
ipcRenderer.emit = function (channel, event, ...args) {
|
||||||
ipc.emit.apply(ipc, [channel].concat(args));
|
ipc.emit.apply(ipc, [channel].concat(args))
|
||||||
return EventEmitter.prototype.emit.apply(ipcRenderer, arguments);
|
return EventEmitter.prototype.emit.apply(ipcRenderer, arguments)
|
||||||
};
|
}
|
||||||
|
|
||||||
// Deprecated.
|
// Deprecated.
|
||||||
for (var method in ipcRenderer) {
|
for (var method in ipcRenderer) {
|
||||||
if (method.startsWith('send')) {
|
if (method.startsWith('send')) {
|
||||||
ipc[method] = ipcRenderer[method];
|
ipc[method] = ipcRenderer[method]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deprecate.rename(ipc, 'sendChannel', 'send');
|
deprecate.rename(ipc, 'sendChannel', 'send')
|
||||||
|
|
||||||
deprecate.rename(ipc, 'sendChannelSync', 'sendSync');
|
deprecate.rename(ipc, 'sendChannelSync', 'sendSync')
|
||||||
|
|
||||||
module.exports = ipc;
|
module.exports = ipc
|
||||||
|
|
|
@ -1,306 +1,306 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer
|
||||||
const CallbacksRegistry = require('electron').CallbacksRegistry;
|
const CallbacksRegistry = require('electron').CallbacksRegistry
|
||||||
const v8Util = process.atomBinding('v8_util');
|
const v8Util = process.atomBinding('v8_util')
|
||||||
const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap;
|
const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap
|
||||||
|
|
||||||
const callbacksRegistry = new CallbacksRegistry;
|
const callbacksRegistry = new CallbacksRegistry
|
||||||
|
|
||||||
var includes = [].includes;
|
var includes = [].includes
|
||||||
|
|
||||||
var remoteObjectCache = new IDWeakMap;
|
var remoteObjectCache = new IDWeakMap
|
||||||
|
|
||||||
// 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 (includes.call(visited, field)) {
|
if (includes.call(visited, field)) {
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
visited.push(field);
|
visited.push(field)
|
||||||
}
|
}
|
||||||
return false;
|
return false
|
||||||
};
|
}
|
||||||
|
|
||||||
// Convert the arguments object into an array of meta data.
|
// Convert the arguments object into an array of meta data.
|
||||||
var wrapArgs = function(args, visited) {
|
var wrapArgs = function (args, visited) {
|
||||||
var valueToMeta;
|
var valueToMeta
|
||||||
if (visited == null) {
|
if (visited == null) {
|
||||||
visited = [];
|
visited = []
|
||||||
}
|
}
|
||||||
valueToMeta = function(value) {
|
valueToMeta = function (value) {
|
||||||
var field, prop, ret;
|
var field, prop, ret
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
return {
|
return {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
value: wrapArgs(value, visited)
|
value: wrapArgs(value, visited)
|
||||||
};
|
}
|
||||||
} else if (Buffer.isBuffer(value)) {
|
} else if (Buffer.isBuffer(value)) {
|
||||||
return {
|
return {
|
||||||
type: 'buffer',
|
type: 'buffer',
|
||||||
value: Array.prototype.slice.call(value, 0)
|
value: Array.prototype.slice.call(value, 0)
|
||||||
};
|
}
|
||||||
} else if (value instanceof Date) {
|
} else if (value instanceof Date) {
|
||||||
return {
|
return {
|
||||||
type: 'date',
|
type: 'date',
|
||||||
value: value.getTime()
|
value: value.getTime()
|
||||||
};
|
}
|
||||||
} else if ((value != null ? value.constructor.name : void 0) === 'Promise') {
|
} else if ((value != null ? value.constructor.name : void 0) === 'Promise') {
|
||||||
return {
|
return {
|
||||||
type: 'promise',
|
type: 'promise',
|
||||||
then: valueToMeta(function(v) { value.then(v); })
|
then: valueToMeta(function (v) { value.then(v); })
|
||||||
};
|
}
|
||||||
} else if ((value != null) && typeof value === 'object' && v8Util.getHiddenValue(value, 'atomId')) {
|
} else if ((value != null) && typeof value === 'object' && v8Util.getHiddenValue(value, 'atomId')) {
|
||||||
return {
|
return {
|
||||||
type: 'remote-object',
|
type: 'remote-object',
|
||||||
id: v8Util.getHiddenValue(value, 'atomId')
|
id: v8Util.getHiddenValue(value, 'atomId')
|
||||||
};
|
}
|
||||||
} else if ((value != null) && typeof value === 'object') {
|
} else if ((value != null) && typeof value === 'object') {
|
||||||
ret = {
|
ret = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
name: value.constructor.name,
|
name: value.constructor.name,
|
||||||
members: []
|
members: []
|
||||||
};
|
}
|
||||||
for (prop in value) {
|
for (prop in value) {
|
||||||
field = value[prop];
|
field = value[prop]
|
||||||
ret.members.push({
|
ret.members.push({
|
||||||
name: prop,
|
name: prop,
|
||||||
value: valueToMeta(isCircular(field, visited) ? null : field)
|
value: valueToMeta(isCircular(field, visited) ? null : field)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
return ret;
|
return ret
|
||||||
} else if (typeof value === 'function' && v8Util.getHiddenValue(value, 'returnValue')) {
|
} else if (typeof value === 'function' && v8Util.getHiddenValue(value, 'returnValue')) {
|
||||||
return {
|
return {
|
||||||
type: 'function-with-return-value',
|
type: 'function-with-return-value',
|
||||||
value: valueToMeta(value())
|
value: valueToMeta(value())
|
||||||
};
|
}
|
||||||
} else if (typeof value === 'function') {
|
} else if (typeof value === 'function') {
|
||||||
return {
|
return {
|
||||||
type: 'function',
|
type: 'function',
|
||||||
id: callbacksRegistry.add(value),
|
id: callbacksRegistry.add(value),
|
||||||
location: v8Util.getHiddenValue(value, 'location')
|
location: v8Util.getHiddenValue(value, 'location')
|
||||||
};
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
type: 'value',
|
type: 'value',
|
||||||
value: value
|
value: value
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
return Array.prototype.slice.call(args).map(valueToMeta);
|
return Array.prototype.slice.call(args).map(valueToMeta)
|
||||||
};
|
}
|
||||||
|
|
||||||
// Populate object's members from descriptors.
|
// Populate object's members from descriptors.
|
||||||
// This matches |getObjectMemebers| in rpc-server.
|
// This matches |getObjectMemebers| in rpc-server.
|
||||||
let setObjectMembers = function(object, metaId, members) {
|
let setObjectMembers = function (object, metaId, members) {
|
||||||
for (let member of members) {
|
for (let member of members) {
|
||||||
if (object.hasOwnProperty(member.name))
|
if (object.hasOwnProperty(member.name))
|
||||||
continue;
|
continue
|
||||||
|
|
||||||
let descriptor = { enumerable: member.enumerable };
|
let descriptor = { enumerable: member.enumerable }
|
||||||
if (member.type === 'method') {
|
if (member.type === 'method') {
|
||||||
let remoteMemberFunction = function() {
|
let remoteMemberFunction = function () {
|
||||||
if (this && this.constructor === remoteMemberFunction) {
|
if (this && this.constructor === remoteMemberFunction) {
|
||||||
// Constructor call.
|
// Constructor call.
|
||||||
let ret = ipcRenderer.sendSync('ATOM_BROWSER_MEMBER_CONSTRUCTOR', metaId, member.name, wrapArgs(arguments));
|
let ret = ipcRenderer.sendSync('ATOM_BROWSER_MEMBER_CONSTRUCTOR', metaId, member.name, wrapArgs(arguments))
|
||||||
return metaToValue(ret);
|
return metaToValue(ret)
|
||||||
} else {
|
} else {
|
||||||
// Call member function.
|
// Call member function.
|
||||||
let ret = ipcRenderer.sendSync('ATOM_BROWSER_MEMBER_CALL', metaId, member.name, wrapArgs(arguments));
|
let ret = ipcRenderer.sendSync('ATOM_BROWSER_MEMBER_CALL', metaId, member.name, wrapArgs(arguments))
|
||||||
return metaToValue(ret);
|
return metaToValue(ret)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
descriptor.writable = true;
|
descriptor.writable = true
|
||||||
descriptor.configurable = true;
|
descriptor.configurable = true
|
||||||
descriptor.value = remoteMemberFunction;
|
descriptor.value = remoteMemberFunction
|
||||||
} else if (member.type === 'get') {
|
} else if (member.type === 'get') {
|
||||||
descriptor.get = function() {
|
descriptor.get = function () {
|
||||||
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_MEMBER_GET', metaId, member.name));
|
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_MEMBER_GET', metaId, member.name))
|
||||||
};
|
}
|
||||||
|
|
||||||
// Only set setter when it is writable.
|
// Only set setter when it is writable.
|
||||||
if (member.writable) {
|
if (member.writable) {
|
||||||
descriptor.set = function(value) {
|
descriptor.set = function (value) {
|
||||||
ipcRenderer.sendSync('ATOM_BROWSER_MEMBER_SET', metaId, member.name, value);
|
ipcRenderer.sendSync('ATOM_BROWSER_MEMBER_SET', metaId, member.name, value)
|
||||||
return value;
|
return value
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(object, member.name, descriptor);
|
Object.defineProperty(object, member.name, descriptor)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Populate object's prototype from descriptor.
|
// Populate object's prototype from descriptor.
|
||||||
// This matches |getObjectPrototype| in rpc-server.
|
// This matches |getObjectPrototype| in rpc-server.
|
||||||
let setObjectPrototype = function(object, metaId, descriptor) {
|
let setObjectPrototype = function (object, metaId, descriptor) {
|
||||||
if (descriptor === null)
|
if (descriptor === null)
|
||||||
return;
|
return
|
||||||
let proto = {};
|
let proto = {}
|
||||||
setObjectMembers(proto, metaId, descriptor.members);
|
setObjectMembers(proto, metaId, descriptor.members)
|
||||||
setObjectPrototype(proto, metaId, descriptor.proto);
|
setObjectPrototype(proto, metaId, descriptor.proto)
|
||||||
Object.setPrototypeOf(object, proto);
|
Object.setPrototypeOf(object, proto)
|
||||||
};
|
}
|
||||||
|
|
||||||
// Convert meta data from browser into real value.
|
// Convert meta data from browser into real value.
|
||||||
let metaToValue = function(meta) {
|
let metaToValue = function (meta) {
|
||||||
var el, i, len, ref1, results, ret;
|
var el, i, len, ref1, results, ret
|
||||||
switch (meta.type) {
|
switch (meta.type) {
|
||||||
case 'value':
|
case 'value':
|
||||||
return meta.value;
|
return meta.value
|
||||||
case 'array':
|
case 'array':
|
||||||
ref1 = meta.members;
|
ref1 = meta.members
|
||||||
results = [];
|
results = []
|
||||||
for (i = 0, len = ref1.length; i < len; i++) {
|
for (i = 0, len = ref1.length; i < len; i++) {
|
||||||
el = ref1[i];
|
el = ref1[i]
|
||||||
results.push(metaToValue(el));
|
results.push(metaToValue(el))
|
||||||
}
|
}
|
||||||
return results;
|
return results
|
||||||
case 'buffer':
|
case 'buffer':
|
||||||
return new Buffer(meta.value);
|
return new Buffer(meta.value)
|
||||||
case 'promise':
|
case 'promise':
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
then: metaToValue(meta.then)
|
then: metaToValue(meta.then)
|
||||||
});
|
})
|
||||||
case 'error':
|
case 'error':
|
||||||
return metaToPlainObject(meta);
|
return metaToPlainObject(meta)
|
||||||
case 'date':
|
case 'date':
|
||||||
return new Date(meta.value);
|
return new Date(meta.value)
|
||||||
case 'exception':
|
case 'exception':
|
||||||
throw new Error(meta.message + "\n" + meta.stack);
|
throw new Error(meta.message + '\n' + meta.stack)
|
||||||
default:
|
default:
|
||||||
if (remoteObjectCache.has(meta.id))
|
if (remoteObjectCache.has(meta.id))
|
||||||
return remoteObjectCache.get(meta.id);
|
return remoteObjectCache.get(meta.id)
|
||||||
|
|
||||||
if (meta.type === 'function') {
|
if (meta.type === 'function') {
|
||||||
// A shadow class to represent the remote function object.
|
// A shadow class to represent the remote function object.
|
||||||
let remoteFunction = function() {
|
let remoteFunction = function () {
|
||||||
if (this && this.constructor === remoteFunction) {
|
if (this && this.constructor === remoteFunction) {
|
||||||
// Constructor call.
|
// Constructor call.
|
||||||
let obj = ipcRenderer.sendSync('ATOM_BROWSER_CONSTRUCTOR', meta.id, wrapArgs(arguments));
|
let obj = ipcRenderer.sendSync('ATOM_BROWSER_CONSTRUCTOR', meta.id, wrapArgs(arguments))
|
||||||
// Returning object in constructor will replace constructed object
|
// Returning object in constructor will replace constructed object
|
||||||
// with the returned object.
|
// with the returned object.
|
||||||
// http://stackoverflow.com/questions/1978049/what-values-can-a-constructor-return-to-avoid-returning-this
|
// http://stackoverflow.com/questions/1978049/what-values-can-a-constructor-return-to-avoid-returning-this
|
||||||
return metaToValue(obj);
|
return metaToValue(obj)
|
||||||
} else {
|
} else {
|
||||||
// Function call.
|
// Function call.
|
||||||
let obj = ipcRenderer.sendSync('ATOM_BROWSER_FUNCTION_CALL', meta.id, wrapArgs(arguments));
|
let obj = ipcRenderer.sendSync('ATOM_BROWSER_FUNCTION_CALL', meta.id, wrapArgs(arguments))
|
||||||
return metaToValue(obj);
|
return metaToValue(obj)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
ret = remoteFunction;
|
ret = remoteFunction
|
||||||
} else {
|
} else {
|
||||||
ret = {};
|
ret = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate delegate members.
|
// Populate delegate members.
|
||||||
setObjectMembers(ret, meta.id, meta.members);
|
setObjectMembers(ret, meta.id, meta.members)
|
||||||
// Populate delegate prototype.
|
// Populate delegate prototype.
|
||||||
setObjectPrototype(ret, meta.id, meta.proto);
|
setObjectPrototype(ret, meta.id, meta.proto)
|
||||||
|
|
||||||
// Set constructor.name to object's name.
|
// Set constructor.name to object's name.
|
||||||
Object.defineProperty(ret.constructor, 'name', { value: meta.name });
|
Object.defineProperty(ret.constructor, 'name', { value: meta.name })
|
||||||
|
|
||||||
// Track delegate object's life time, and tell the browser to clean up
|
// Track delegate object's life time, and tell the browser to clean up
|
||||||
// when the object is GCed.
|
// when the object is GCed.
|
||||||
v8Util.setDestructor(ret, function() {
|
v8Util.setDestructor(ret, function () {
|
||||||
ipcRenderer.send('ATOM_BROWSER_DEREFERENCE', meta.id);
|
ipcRenderer.send('ATOM_BROWSER_DEREFERENCE', meta.id)
|
||||||
});
|
})
|
||||||
|
|
||||||
// Remember object's id.
|
// Remember object's id.
|
||||||
v8Util.setHiddenValue(ret, 'atomId', meta.id);
|
v8Util.setHiddenValue(ret, 'atomId', meta.id)
|
||||||
remoteObjectCache.set(meta.id, ret);
|
remoteObjectCache.set(meta.id, ret)
|
||||||
return ret;
|
return ret
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Construct a plain object from the meta.
|
// Construct a plain object from the meta.
|
||||||
var metaToPlainObject = function(meta) {
|
var metaToPlainObject = function (meta) {
|
||||||
var i, len, obj, ref1;
|
var i, len, obj, ref1
|
||||||
obj = (function() {
|
obj = (function () {
|
||||||
switch (meta.type) {
|
switch (meta.type) {
|
||||||
case 'error':
|
case 'error':
|
||||||
return new Error;
|
return new Error
|
||||||
default:
|
default:
|
||||||
return {};
|
return {}
|
||||||
}
|
}
|
||||||
})();
|
})()
|
||||||
ref1 = meta.members;
|
ref1 = meta.members
|
||||||
for (i = 0, len = ref1.length; i < len; i++) {
|
for (i = 0, len = ref1.length; i < len; i++) {
|
||||||
let {name, value} = ref1[i];
|
let {name, value} = ref1[i]
|
||||||
obj[name] = value;
|
obj[name] = value
|
||||||
}
|
}
|
||||||
return obj;
|
return obj
|
||||||
};
|
}
|
||||||
|
|
||||||
// Browser calls a callback in renderer.
|
// Browser calls a callback in renderer.
|
||||||
ipcRenderer.on('ATOM_RENDERER_CALLBACK', function(event, id, args) {
|
ipcRenderer.on('ATOM_RENDERER_CALLBACK', function (event, id, args) {
|
||||||
return callbacksRegistry.apply(id, metaToValue(args));
|
return callbacksRegistry.apply(id, metaToValue(args))
|
||||||
});
|
})
|
||||||
|
|
||||||
// A callback in browser is released.
|
// A callback in browser is released.
|
||||||
ipcRenderer.on('ATOM_RENDERER_RELEASE_CALLBACK', function(event, id) {
|
ipcRenderer.on('ATOM_RENDERER_RELEASE_CALLBACK', function (event, id) {
|
||||||
return callbacksRegistry.remove(id);
|
return callbacksRegistry.remove(id)
|
||||||
});
|
})
|
||||||
|
|
||||||
// List all built-in modules in browser process.
|
// List all built-in modules in browser process.
|
||||||
const browserModules = require('../../browser/api/exports/electron');
|
const browserModules = require('../../browser/api/exports/electron')
|
||||||
|
|
||||||
// And add a helper receiver for each one.
|
// And add a helper receiver for each one.
|
||||||
var fn = function(name) {
|
var fn = function (name) {
|
||||||
return Object.defineProperty(exports, name, {
|
return Object.defineProperty(exports, name, {
|
||||||
get: function() {
|
get: function () {
|
||||||
return exports.getBuiltin(name);
|
return exports.getBuiltin(name)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
for (var name in browserModules) {
|
for (var name in browserModules) {
|
||||||
fn(name);
|
fn(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get remote module.
|
// Get remote module.
|
||||||
exports.require = function(module) {
|
exports.require = function (module) {
|
||||||
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_REQUIRE', module));
|
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_REQUIRE', module))
|
||||||
};
|
}
|
||||||
|
|
||||||
// Alias to remote.require('electron').xxx.
|
// Alias to remote.require('electron').xxx.
|
||||||
exports.getBuiltin = function(module) {
|
exports.getBuiltin = function (module) {
|
||||||
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_GET_BUILTIN', module));
|
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_GET_BUILTIN', module))
|
||||||
};
|
}
|
||||||
|
|
||||||
// Get current BrowserWindow.
|
// Get current BrowserWindow.
|
||||||
exports.getCurrentWindow = function() {
|
exports.getCurrentWindow = function () {
|
||||||
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_CURRENT_WINDOW'));
|
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_CURRENT_WINDOW'))
|
||||||
};
|
}
|
||||||
|
|
||||||
// Get current WebContents object.
|
// Get current WebContents object.
|
||||||
exports.getCurrentWebContents = function() {
|
exports.getCurrentWebContents = function () {
|
||||||
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_CURRENT_WEB_CONTENTS'));
|
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_CURRENT_WEB_CONTENTS'))
|
||||||
};
|
}
|
||||||
|
|
||||||
// Get a global object in browser.
|
// Get a global object in browser.
|
||||||
exports.getGlobal = function(name) {
|
exports.getGlobal = function (name) {
|
||||||
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_GLOBAL', name));
|
return metaToValue(ipcRenderer.sendSync('ATOM_BROWSER_GLOBAL', name))
|
||||||
};
|
}
|
||||||
|
|
||||||
// Get the process object in browser.
|
// Get the process object in browser.
|
||||||
exports.__defineGetter__('process', function() {
|
exports.__defineGetter__('process', function () {
|
||||||
return exports.getGlobal('process');
|
return exports.getGlobal('process')
|
||||||
});
|
})
|
||||||
|
|
||||||
// Create a funtion that will return the specifed value when called in browser.
|
// Create a funtion that will return the specifed value when called in browser.
|
||||||
exports.createFunctionWithReturnValue = function(returnValue) {
|
exports.createFunctionWithReturnValue = function (returnValue) {
|
||||||
var func;
|
var func
|
||||||
func = function() {
|
func = function () {
|
||||||
return returnValue;
|
return returnValue
|
||||||
};
|
}
|
||||||
v8Util.setHiddenValue(func, 'returnValue', true);
|
v8Util.setHiddenValue(func, 'returnValue', true)
|
||||||
return func;
|
return func
|
||||||
};
|
}
|
||||||
|
|
||||||
// Get the guest WebContents from guestInstanceId.
|
// Get the guest WebContents from guestInstanceId.
|
||||||
exports.getGuestWebContents = function(guestInstanceId) {
|
exports.getGuestWebContents = function (guestInstanceId) {
|
||||||
var meta;
|
var meta
|
||||||
meta = ipcRenderer.sendSync('ATOM_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId);
|
meta = ipcRenderer.sendSync('ATOM_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId)
|
||||||
return metaToValue(meta);
|
return metaToValue(meta)
|
||||||
};
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
module.exports = require('electron').remote.screen;
|
module.exports = require('electron').remote.screen
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const deprecate = require('electron').deprecate;
|
const deprecate = require('electron').deprecate
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter
|
||||||
|
|
||||||
const webFrame = process.atomBinding('web_frame').webFrame;
|
const webFrame = process.atomBinding('web_frame').webFrame
|
||||||
|
|
||||||
// webFrame is an EventEmitter.
|
// webFrame is an EventEmitter.
|
||||||
webFrame.__proto__ = EventEmitter.prototype;
|
webFrame.__proto__ = EventEmitter.prototype
|
||||||
|
|
||||||
// Lots of webview would subscribe to webFrame's events.
|
// Lots of webview would subscribe to webFrame's events.
|
||||||
webFrame.setMaxListeners(0);
|
webFrame.setMaxListeners(0)
|
||||||
|
|
||||||
// Deprecated.
|
// Deprecated.
|
||||||
deprecate.rename(webFrame, 'registerUrlSchemeAsSecure', 'registerURLSchemeAsSecure');
|
deprecate.rename(webFrame, 'registerUrlSchemeAsSecure', 'registerURLSchemeAsSecure')
|
||||||
deprecate.rename(webFrame, 'registerUrlSchemeAsBypassingCSP', 'registerURLSchemeAsBypassingCSP');
|
deprecate.rename(webFrame, 'registerUrlSchemeAsBypassingCSP', 'registerURLSchemeAsBypassingCSP')
|
||||||
deprecate.rename(webFrame, 'registerUrlSchemeAsPrivileged', 'registerURLSchemeAsPrivileged');
|
deprecate.rename(webFrame, 'registerUrlSchemeAsPrivileged', 'registerURLSchemeAsPrivileged')
|
||||||
|
|
||||||
module.exports = webFrame;
|
module.exports = webFrame
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
const url = require('url');
|
const url = require('url')
|
||||||
const chrome = window.chrome = window.chrome || {};
|
const chrome = window.chrome = window.chrome || {}
|
||||||
|
|
||||||
chrome.extension = {
|
chrome.extension = {
|
||||||
getURL: function(path) {
|
getURL: function (path) {
|
||||||
return url.format({
|
return url.format({
|
||||||
protocol: location.protocol,
|
protocol: location.protocol,
|
||||||
slashes: true,
|
slashes: true,
|
||||||
hostname: location.hostname,
|
hostname: location.hostname,
|
||||||
pathname: path
|
pathname: path
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,139 +1,139 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const events = require('events');
|
const events = require('events')
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
const Module = require('module');
|
const Module = require('module')
|
||||||
|
|
||||||
// We modified the original process.argv to let node.js load the
|
// We modified the original process.argv to let node.js load the
|
||||||
// atom-renderer.js, we need to restore it here.
|
// atom-renderer.js, we need to restore it here.
|
||||||
process.argv.splice(1, 1);
|
process.argv.splice(1, 1)
|
||||||
|
|
||||||
// Clear search paths.
|
// Clear search paths.
|
||||||
require('../common/reset-search-paths');
|
require('../common/reset-search-paths')
|
||||||
|
|
||||||
// Import common settings.
|
// Import common settings.
|
||||||
require('../common/init');
|
require('../common/init')
|
||||||
|
|
||||||
var globalPaths = Module.globalPaths;
|
var globalPaths = Module.globalPaths
|
||||||
|
|
||||||
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
||||||
globalPaths.push(path.join(__dirname, 'api'));
|
globalPaths.push(path.join(__dirname, 'api'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expose public APIs.
|
// Expose public APIs.
|
||||||
globalPaths.push(path.join(__dirname, 'api', 'exports'));
|
globalPaths.push(path.join(__dirname, 'api', 'exports'))
|
||||||
|
|
||||||
// The global variable will be used by ipc for event dispatching
|
// The global variable will be used by ipc for event dispatching
|
||||||
var v8Util = process.atomBinding('v8_util');
|
var v8Util = process.atomBinding('v8_util')
|
||||||
|
|
||||||
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter);
|
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter)
|
||||||
|
|
||||||
// Use electron module after everything is ready.
|
// Use electron module after everything is ready.
|
||||||
const electron = require('electron');
|
const electron = require('electron')
|
||||||
|
|
||||||
// Call webFrame method.
|
// Call webFrame method.
|
||||||
electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (event, method, args) => {
|
electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (event, method, args) => {
|
||||||
electron.webFrame[method].apply(electron.webFrame, args);
|
electron.webFrame[method].apply(electron.webFrame, args)
|
||||||
});
|
})
|
||||||
|
|
||||||
electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (event, requestId, method, args) => {
|
electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (event, requestId, method, args) => {
|
||||||
const responseCallback = function(result) {
|
const responseCallback = function (result) {
|
||||||
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, result);
|
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, result)
|
||||||
};
|
}
|
||||||
args.push(responseCallback);
|
args.push(responseCallback)
|
||||||
electron.webFrame[method].apply(electron.webFrame, args);
|
electron.webFrame[method].apply(electron.webFrame, args)
|
||||||
});
|
})
|
||||||
|
|
||||||
// Process command line arguments.
|
// Process command line arguments.
|
||||||
var nodeIntegration = 'false';
|
var nodeIntegration = 'false'
|
||||||
var preloadScript = null;
|
var preloadScript = null
|
||||||
|
|
||||||
var ref = process.argv;
|
var ref = process.argv
|
||||||
var i, len, arg;
|
var i, len, arg
|
||||||
for (i = 0, len = ref.length; i < len; i++) {
|
for (i = 0, len = ref.length; i < len; i++) {
|
||||||
arg = ref[i];
|
arg = ref[i]
|
||||||
if (arg.indexOf('--guest-instance-id=') === 0) {
|
if (arg.indexOf('--guest-instance-id=') === 0) {
|
||||||
// This is a guest web view.
|
// This is a guest web view.
|
||||||
process.guestInstanceId = parseInt(arg.substr(arg.indexOf('=') + 1));
|
process.guestInstanceId = parseInt(arg.substr(arg.indexOf('=') + 1))
|
||||||
} else if (arg.indexOf('--opener-id=') === 0) {
|
} else if (arg.indexOf('--opener-id=') === 0) {
|
||||||
// This is a guest BrowserWindow.
|
// This is a guest BrowserWindow.
|
||||||
process.openerId = parseInt(arg.substr(arg.indexOf('=') + 1));
|
process.openerId = parseInt(arg.substr(arg.indexOf('=') + 1))
|
||||||
} else if (arg.indexOf('--node-integration=') === 0) {
|
} else if (arg.indexOf('--node-integration=') === 0) {
|
||||||
nodeIntegration = arg.substr(arg.indexOf('=') + 1);
|
nodeIntegration = arg.substr(arg.indexOf('=') + 1)
|
||||||
} else if (arg.indexOf('--preload=') === 0) {
|
} else if (arg.indexOf('--preload=') === 0) {
|
||||||
preloadScript = arg.substr(arg.indexOf('=') + 1);
|
preloadScript = arg.substr(arg.indexOf('=') + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.protocol === 'chrome-devtools:') {
|
if (location.protocol === 'chrome-devtools:') {
|
||||||
// Override some inspector APIs.
|
// Override some inspector APIs.
|
||||||
require('./inspector');
|
require('./inspector')
|
||||||
nodeIntegration = 'true';
|
nodeIntegration = 'true'
|
||||||
} else if (location.protocol === 'chrome-extension:') {
|
} else if (location.protocol === 'chrome-extension:') {
|
||||||
// Add implementations of chrome API.
|
// Add implementations of chrome API.
|
||||||
require('./chrome-api');
|
require('./chrome-api')
|
||||||
nodeIntegration = 'true';
|
nodeIntegration = 'true'
|
||||||
} else {
|
} else {
|
||||||
// Override default web functions.
|
// Override default web functions.
|
||||||
require('./override');
|
require('./override')
|
||||||
|
|
||||||
// Load webview tag implementation.
|
// Load webview tag implementation.
|
||||||
if (process.guestInstanceId == null) {
|
if (process.guestInstanceId == null) {
|
||||||
require('./web-view/web-view');
|
require('./web-view/web-view')
|
||||||
require('./web-view/web-view-attributes');
|
require('./web-view/web-view-attributes')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodeIntegration === 'true' || nodeIntegration === 'all' || nodeIntegration === 'except-iframe' || nodeIntegration === 'manual-enable-iframe') {
|
if (nodeIntegration === 'true' || nodeIntegration === 'all' || nodeIntegration === 'except-iframe' || nodeIntegration === 'manual-enable-iframe') {
|
||||||
// Export node bindings to global.
|
// Export node bindings to global.
|
||||||
global.require = require;
|
global.require = require
|
||||||
global.module = module;
|
global.module = module
|
||||||
|
|
||||||
// Set the __filename to the path of html file if it is file: protocol.
|
// Set the __filename to the path of html file if it is file: protocol.
|
||||||
if (window.location.protocol === 'file:') {
|
if (window.location.protocol === 'file:') {
|
||||||
var pathname = process.platform === 'win32' && window.location.pathname[0] === '/' ? window.location.pathname.substr(1) : window.location.pathname;
|
var pathname = process.platform === 'win32' && window.location.pathname[0] === '/' ? window.location.pathname.substr(1) : window.location.pathname
|
||||||
global.__filename = path.normalize(decodeURIComponent(pathname));
|
global.__filename = path.normalize(decodeURIComponent(pathname))
|
||||||
global.__dirname = path.dirname(global.__filename);
|
global.__dirname = path.dirname(global.__filename)
|
||||||
|
|
||||||
// Set module's filename so relative require can work as expected.
|
// Set module's filename so relative require can work as expected.
|
||||||
module.filename = global.__filename;
|
module.filename = global.__filename
|
||||||
|
|
||||||
// Also search for module under the html file.
|
// Also search for module under the html file.
|
||||||
module.paths = module.paths.concat(Module._nodeModulePaths(global.__dirname));
|
module.paths = module.paths.concat(Module._nodeModulePaths(global.__dirname))
|
||||||
} else {
|
} else {
|
||||||
global.__filename = __filename;
|
global.__filename = __filename
|
||||||
global.__dirname = __dirname;
|
global.__dirname = __dirname
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect window.onerror to uncaughtException.
|
// Redirect window.onerror to uncaughtException.
|
||||||
window.onerror = function(message, filename, lineno, colno, error) {
|
window.onerror = function (message, filename, lineno, colno, error) {
|
||||||
if (global.process.listeners('uncaughtException').length > 0) {
|
if (global.process.listeners('uncaughtException').length > 0) {
|
||||||
global.process.emit('uncaughtException', error);
|
global.process.emit('uncaughtException', error)
|
||||||
return true;
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
} else {
|
} else {
|
||||||
// Delete Node's symbols after the Environment has been loaded.
|
// Delete Node's symbols after the Environment has been loaded.
|
||||||
process.once('loaded', function() {
|
process.once('loaded', function () {
|
||||||
delete global.process;
|
delete global.process
|
||||||
delete global.setImmediate;
|
delete global.setImmediate
|
||||||
delete global.clearImmediate;
|
delete global.clearImmediate
|
||||||
return delete global.global;
|
return delete global.global
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the script specfied by the "preload" attribute.
|
// Load the script specfied by the "preload" attribute.
|
||||||
if (preloadScript) {
|
if (preloadScript) {
|
||||||
try {
|
try {
|
||||||
require(preloadScript);
|
require(preloadScript)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'MODULE_NOT_FOUND') {
|
if (error.code === 'MODULE_NOT_FOUND') {
|
||||||
console.error("Unable to load preload script " + preloadScript);
|
console.error('Unable to load preload script ' + preloadScript)
|
||||||
} else {
|
} else {
|
||||||
console.error(error);
|
console.error(error)
|
||||||
console.error(error.stack);
|
console.error(error.stack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
window.onload = function() {
|
window.onload = function () {
|
||||||
// Use menu API to show context menu.
|
// Use menu API to show context menu.
|
||||||
InspectorFrontendHost.showContextMenuAtPoint = createMenu;
|
InspectorFrontendHost.showContextMenuAtPoint = createMenu
|
||||||
|
|
||||||
// Use dialog API to override file chooser dialog.
|
// Use dialog API to override file chooser dialog.
|
||||||
return (WebInspector.createFileSelectorElement = createFileSelectorElement);
|
return (WebInspector.createFileSelectorElement = createFileSelectorElement)
|
||||||
};
|
}
|
||||||
|
|
||||||
var convertToMenuTemplate = function(items) {
|
var convertToMenuTemplate = function (items) {
|
||||||
var fn, i, item, len, template;
|
var fn, i, item, len, template
|
||||||
template = [];
|
template = []
|
||||||
fn = function(item) {
|
fn = function (item) {
|
||||||
var transformed;
|
var transformed
|
||||||
transformed = item.type === 'subMenu' ? {
|
transformed = item.type === 'subMenu' ? {
|
||||||
type: 'submenu',
|
type: 'submenu',
|
||||||
label: item.label,
|
label: item.label,
|
||||||
|
@ -27,55 +27,55 @@ var convertToMenuTemplate = function(items) {
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
label: item.label,
|
label: item.label,
|
||||||
enabled: item.enabled
|
enabled: item.enabled
|
||||||
};
|
|
||||||
if (item.id != null) {
|
|
||||||
transformed.click = function() {
|
|
||||||
DevToolsAPI.contextMenuItemSelected(item.id);
|
|
||||||
return DevToolsAPI.contextMenuCleared();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return template.push(transformed);
|
if (item.id != null) {
|
||||||
};
|
transformed.click = function () {
|
||||||
for (i = 0, len = items.length; i < len; i++) {
|
DevToolsAPI.contextMenuItemSelected(item.id)
|
||||||
item = items[i];
|
return DevToolsAPI.contextMenuCleared()
|
||||||
fn(item);
|
}
|
||||||
|
}
|
||||||
|
return template.push(transformed)
|
||||||
}
|
}
|
||||||
return template;
|
for (i = 0, len = items.length; i < len; i++) {
|
||||||
};
|
item = items[i]
|
||||||
|
fn(item)
|
||||||
|
}
|
||||||
|
return template
|
||||||
|
}
|
||||||
|
|
||||||
var createMenu = function(x, y, items) {
|
var createMenu = function (x, y, items) {
|
||||||
const remote = require('electron').remote;
|
const remote = require('electron').remote
|
||||||
const Menu = remote.Menu;
|
const Menu = remote.Menu
|
||||||
const menu = Menu.buildFromTemplate(convertToMenuTemplate(items));
|
const menu = Menu.buildFromTemplate(convertToMenuTemplate(items))
|
||||||
|
|
||||||
// The menu is expected to show asynchronously.
|
// The menu is expected to show asynchronously.
|
||||||
return setTimeout(function() {
|
return setTimeout(function () {
|
||||||
return menu.popup(remote.getCurrentWindow());
|
return menu.popup(remote.getCurrentWindow())
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
var showFileChooserDialog = function(callback) {
|
var showFileChooserDialog = function (callback) {
|
||||||
var dialog, files, remote;
|
var dialog, files, remote
|
||||||
remote = require('electron').remote;
|
remote = require('electron').remote
|
||||||
dialog = remote.dialog;
|
dialog = remote.dialog
|
||||||
files = dialog.showOpenDialog({});
|
files = dialog.showOpenDialog({})
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
return callback(pathToHtml5FileObject(files[0]));
|
return callback(pathToHtml5FileObject(files[0]))
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
var pathToHtml5FileObject = function(path) {
|
var pathToHtml5FileObject = function (path) {
|
||||||
var blob, fs;
|
var blob, fs
|
||||||
fs = require('fs');
|
fs = require('fs')
|
||||||
blob = new Blob([fs.readFileSync(path)]);
|
blob = new Blob([fs.readFileSync(path)])
|
||||||
blob.name = path;
|
blob.name = path
|
||||||
return blob;
|
return blob
|
||||||
};
|
}
|
||||||
|
|
||||||
var createFileSelectorElement = function(callback) {
|
var createFileSelectorElement = function (callback) {
|
||||||
var fileSelectorElement;
|
var fileSelectorElement
|
||||||
fileSelectorElement = document.createElement('span');
|
fileSelectorElement = document.createElement('span')
|
||||||
fileSelectorElement.style.display = 'none';
|
fileSelectorElement.style.display = 'none'
|
||||||
fileSelectorElement.click = showFileChooserDialog.bind(this, callback);
|
fileSelectorElement.click = showFileChooserDialog.bind(this, callback)
|
||||||
return fileSelectorElement;
|
return fileSelectorElement
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,266 +1,265 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer
|
||||||
const remote = require('electron').remote;
|
const remote = require('electron').remote
|
||||||
|
|
||||||
// Cache browser window visibility
|
// Cache browser window visibility
|
||||||
var _isVisible = true;
|
var _isVisible = true
|
||||||
var _isMinimized = false;
|
var _isMinimized = false
|
||||||
(function() {
|
;(function () {
|
||||||
var currentWindow;
|
var currentWindow
|
||||||
currentWindow = remote.getCurrentWindow();
|
currentWindow = remote.getCurrentWindow()
|
||||||
_isVisible = currentWindow.isVisible();
|
_isVisible = currentWindow.isVisible()
|
||||||
_isMinimized = currentWindow.isMinimized();
|
_isMinimized = currentWindow.isMinimized()
|
||||||
})();
|
})()
|
||||||
|
|
||||||
// Helper function to resolve relative url.
|
// Helper function to resolve relative url.
|
||||||
var a = window.top.document.createElement('a');
|
var a = window.top.document.createElement('a')
|
||||||
|
|
||||||
var resolveURL = function(url) {
|
var resolveURL = function (url) {
|
||||||
a.href = url;
|
a.href = url
|
||||||
return a.href;
|
return a.href
|
||||||
};
|
}
|
||||||
|
|
||||||
// Window object returned by "window.open".
|
// Window object returned by "window.open".
|
||||||
var BrowserWindowProxy = (function() {
|
var BrowserWindowProxy = (function () {
|
||||||
BrowserWindowProxy.proxies = {};
|
BrowserWindowProxy.proxies = {}
|
||||||
|
|
||||||
BrowserWindowProxy.getOrCreate = function(guestId) {
|
BrowserWindowProxy.getOrCreate = function (guestId) {
|
||||||
var base;
|
var base
|
||||||
return (base = this.proxies)[guestId] != null ? base[guestId] : base[guestId] = new BrowserWindowProxy(guestId);
|
return (base = this.proxies)[guestId] != null ? base[guestId] : base[guestId] = new BrowserWindowProxy(guestId)
|
||||||
};
|
|
||||||
|
|
||||||
BrowserWindowProxy.remove = function(guestId) {
|
|
||||||
return delete this.proxies[guestId];
|
|
||||||
};
|
|
||||||
|
|
||||||
function BrowserWindowProxy(guestId1) {
|
|
||||||
this.guestId = guestId1;
|
|
||||||
this.closed = false;
|
|
||||||
ipcRenderer.once("ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_" + this.guestId, () => {
|
|
||||||
BrowserWindowProxy.remove(this.guestId);
|
|
||||||
this.closed = true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindowProxy.prototype.close = function() {
|
BrowserWindowProxy.remove = function (guestId) {
|
||||||
return ipcRenderer.send('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', this.guestId);
|
return delete this.proxies[guestId]
|
||||||
};
|
}
|
||||||
|
|
||||||
BrowserWindowProxy.prototype.focus = function() {
|
function BrowserWindowProxy (guestId1) {
|
||||||
return ipcRenderer.send('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'focus');
|
this.guestId = guestId1
|
||||||
};
|
this.closed = false
|
||||||
|
ipcRenderer.once('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_' + this.guestId, () => {
|
||||||
|
BrowserWindowProxy.remove(this.guestId)
|
||||||
|
this.closed = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
BrowserWindowProxy.prototype.blur = function() {
|
BrowserWindowProxy.prototype.close = function () {
|
||||||
return ipcRenderer.send('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'blur');
|
return ipcRenderer.send('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', this.guestId)
|
||||||
};
|
}
|
||||||
|
|
||||||
|
BrowserWindowProxy.prototype.focus = function () {
|
||||||
|
return ipcRenderer.send('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'focus')
|
||||||
|
}
|
||||||
|
|
||||||
|
BrowserWindowProxy.prototype.blur = function () {
|
||||||
|
return ipcRenderer.send('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'blur')
|
||||||
|
}
|
||||||
|
|
||||||
Object.defineProperty(BrowserWindowProxy.prototype, 'location', {
|
Object.defineProperty(BrowserWindowProxy.prototype, 'location', {
|
||||||
get: function() {
|
get: function () {
|
||||||
return ipcRenderer.sendSync('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'getURL');
|
return ipcRenderer.sendSync('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'getURL')
|
||||||
},
|
},
|
||||||
set: function(url) {
|
set: function (url) {
|
||||||
return ipcRenderer.sendSync('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'loadURL', url);
|
return ipcRenderer.sendSync('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'loadURL', url)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
BrowserWindowProxy.prototype.postMessage = function(message, targetOrigin) {
|
BrowserWindowProxy.prototype.postMessage = function (message, targetOrigin) {
|
||||||
if (targetOrigin == null) {
|
if (targetOrigin == null) {
|
||||||
targetOrigin = '*';
|
targetOrigin = '*'
|
||||||
}
|
}
|
||||||
return ipcRenderer.send('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', this.guestId, message, targetOrigin, location.origin);
|
return ipcRenderer.send('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', this.guestId, message, targetOrigin, location.origin)
|
||||||
};
|
}
|
||||||
|
|
||||||
BrowserWindowProxy.prototype["eval"] = function(...args) {
|
BrowserWindowProxy.prototype['eval'] = function (...args) {
|
||||||
return ipcRenderer.send.apply(ipcRenderer, ['ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'executeJavaScript'].concat(args));
|
return ipcRenderer.send.apply(ipcRenderer, ['ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'executeJavaScript'].concat(args))
|
||||||
};
|
}
|
||||||
|
|
||||||
return BrowserWindowProxy;
|
return BrowserWindowProxy
|
||||||
|
})()
|
||||||
})();
|
|
||||||
|
|
||||||
if (process.guestInstanceId == null) {
|
if (process.guestInstanceId == null) {
|
||||||
// Override default window.close.
|
// Override default window.close.
|
||||||
window.close = function() {
|
window.close = function () {
|
||||||
return remote.getCurrentWindow().close();
|
return remote.getCurrentWindow().close()
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the browser window or guest view emit "new-window" event.
|
// Make the browser window or guest view emit "new-window" event.
|
||||||
window.open = function(url, frameName, features) {
|
window.open = function (url, frameName, features) {
|
||||||
var feature, guestId, i, j, len, len1, name, options, ref1, ref2, value;
|
var feature, guestId, i, j, len, len1, name, options, ref1, ref2, value
|
||||||
if (frameName == null) {
|
if (frameName == null) {
|
||||||
frameName = '';
|
frameName = ''
|
||||||
}
|
}
|
||||||
if (features == null) {
|
if (features == null) {
|
||||||
features = '';
|
features = ''
|
||||||
}
|
}
|
||||||
options = {};
|
options = {}
|
||||||
|
|
||||||
// TODO remove hyphenated options in both of the following arrays for 1.0
|
// TODO remove hyphenated options in both of the following arrays for 1.0
|
||||||
const ints = ['x', 'y', 'width', 'height', 'min-width', 'minWidth', 'max-width', 'maxWidth', 'min-height', 'minHeight', 'max-height', 'maxHeight', 'zoom-factor', 'zoomFactor'];
|
const ints = ['x', 'y', 'width', 'height', 'min-width', 'minWidth', 'max-width', 'maxWidth', 'min-height', 'minHeight', 'max-height', 'maxHeight', 'zoom-factor', 'zoomFactor']
|
||||||
const webPreferences = ['zoom-factor', 'zoomFactor', 'node-integration', 'nodeIntegration', 'preload'];
|
const webPreferences = ['zoom-factor', 'zoomFactor', 'node-integration', 'nodeIntegration', 'preload']
|
||||||
|
|
||||||
// Make sure to get rid of excessive whitespace in the property name
|
// Make sure to get rid of excessive whitespace in the property name
|
||||||
ref1 = features.split(/,\s*/);
|
ref1 = features.split(/,\s*/)
|
||||||
for (i = 0, len = ref1.length; i < len; i++) {
|
for (i = 0, len = ref1.length; i < len; i++) {
|
||||||
feature = ref1[i];
|
feature = ref1[i]
|
||||||
ref2 = feature.split(/\s*=/);
|
ref2 = feature.split(/\s*=/)
|
||||||
name = ref2[0];
|
name = ref2[0]
|
||||||
value = ref2[1];
|
value = ref2[1]
|
||||||
value = value === 'yes' || value === '1' ? true : value === 'no' || value === '0' ? false : value;
|
value = value === 'yes' || value === '1' ? true : value === 'no' || value === '0' ? false : value
|
||||||
if (webPreferences.includes(name)) {
|
if (webPreferences.includes(name)) {
|
||||||
if (options.webPreferences == null) {
|
if (options.webPreferences == null) {
|
||||||
options.webPreferences = {};
|
options.webPreferences = {}
|
||||||
}
|
}
|
||||||
options.webPreferences[name] = value;
|
options.webPreferences[name] = value
|
||||||
} else {
|
} else {
|
||||||
options[name] = value;
|
options[name] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.left) {
|
if (options.left) {
|
||||||
if (options.x == null) {
|
if (options.x == null) {
|
||||||
options.x = options.left;
|
options.x = options.left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.top) {
|
if (options.top) {
|
||||||
if (options.y == null) {
|
if (options.y == null) {
|
||||||
options.y = options.top;
|
options.y = options.top
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.title == null) {
|
if (options.title == null) {
|
||||||
options.title = frameName;
|
options.title = frameName
|
||||||
}
|
}
|
||||||
if (options.width == null) {
|
if (options.width == null) {
|
||||||
options.width = 800;
|
options.width = 800
|
||||||
}
|
}
|
||||||
if (options.height == null) {
|
if (options.height == null) {
|
||||||
options.height = 600;
|
options.height = 600
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve relative urls.
|
// Resolve relative urls.
|
||||||
url = resolveURL(url);
|
url = resolveURL(url)
|
||||||
for (j = 0, len1 = ints.length; j < len1; j++) {
|
for (j = 0, len1 = ints.length; j < len1; j++) {
|
||||||
name = ints[j];
|
name = ints[j]
|
||||||
if (options[name] != null) {
|
if (options[name] != null) {
|
||||||
options[name] = parseInt(options[name], 10);
|
options[name] = parseInt(options[name], 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
guestId = ipcRenderer.sendSync('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, options);
|
guestId = ipcRenderer.sendSync('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, options)
|
||||||
if (guestId) {
|
if (guestId) {
|
||||||
return BrowserWindowProxy.getOrCreate(guestId);
|
return BrowserWindowProxy.getOrCreate(guestId)
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Use the dialog API to implement alert().
|
// Use the dialog API to implement alert().
|
||||||
window.alert = function(message, title) {
|
window.alert = function(message, title) {
|
||||||
var buttons;
|
var buttons
|
||||||
if (arguments.length == 0) {
|
if (arguments.length === 0) {
|
||||||
message = '';
|
message = ''
|
||||||
}
|
}
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
title = '';
|
title = ''
|
||||||
}
|
}
|
||||||
buttons = ['OK'];
|
buttons = ['OK']
|
||||||
message = String(message);
|
message = String(message)
|
||||||
remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
message: message,
|
message: message,
|
||||||
title: title,
|
title: title,
|
||||||
buttons: buttons
|
buttons: buttons
|
||||||
});
|
})
|
||||||
|
|
||||||
// Alert should always return undefined.
|
// Alert should always return undefined.
|
||||||
};
|
}
|
||||||
|
|
||||||
// And the confirm().
|
// And the confirm().
|
||||||
window.confirm = function(message, title) {
|
window.confirm = function (message, title) {
|
||||||
var buttons, cancelId;
|
var buttons, cancelId
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
title = '';
|
title = ''
|
||||||
}
|
}
|
||||||
buttons = ['OK', 'Cancel'];
|
buttons = ['OK', 'Cancel']
|
||||||
cancelId = 1;
|
cancelId = 1
|
||||||
return !remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
return !remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
message: message,
|
message: message,
|
||||||
title: title,
|
title: title,
|
||||||
buttons: buttons,
|
buttons: buttons,
|
||||||
cancelId: cancelId
|
cancelId: cancelId
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
// But we do not support prompt().
|
// But we do not support prompt().
|
||||||
window.prompt = function() {
|
window.prompt = function () {
|
||||||
throw new Error('prompt() is and will not be supported.');
|
throw new Error('prompt() is and will not be supported.')
|
||||||
};
|
}
|
||||||
|
|
||||||
if (process.openerId != null) {
|
if (process.openerId != null) {
|
||||||
window.opener = BrowserWindowProxy.getOrCreate(process.openerId);
|
window.opener = BrowserWindowProxy.getOrCreate(process.openerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcRenderer.on('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', function (event, isVisible, isMinimized) {
|
ipcRenderer.on('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', function (event, isVisible, isMinimized) {
|
||||||
var hasChanged = _isVisible != isVisible || _isMinimized != isMinimized;
|
var hasChanged = _isVisible != isVisible || _isMinimized != isMinimized
|
||||||
|
|
||||||
if (hasChanged) {
|
if (hasChanged) {
|
||||||
_isVisible = isVisible;
|
_isVisible = isVisible
|
||||||
_isMinimized = isMinimized;
|
_isMinimized = isMinimized
|
||||||
|
|
||||||
document.dispatchEvent(new Event('visibilitychange'));
|
document.dispatchEvent(new Event('visibilitychange'))
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
ipcRenderer.on('ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', function(event, sourceId, message, sourceOrigin) {
|
ipcRenderer.on('ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', function (event, sourceId, message, sourceOrigin) {
|
||||||
// Manually dispatch event instead of using postMessage because we also need to
|
// Manually dispatch event instead of using postMessage because we also need to
|
||||||
// set event.source.
|
// set event.source.
|
||||||
event = document.createEvent('Event');
|
event = document.createEvent('Event')
|
||||||
event.initEvent('message', false, false);
|
event.initEvent('message', false, false)
|
||||||
event.data = message;
|
event.data = message
|
||||||
event.origin = sourceOrigin;
|
event.origin = sourceOrigin
|
||||||
event.source = BrowserWindowProxy.getOrCreate(sourceId);
|
event.source = BrowserWindowProxy.getOrCreate(sourceId)
|
||||||
return window.dispatchEvent(event);
|
return window.dispatchEvent(event)
|
||||||
});
|
})
|
||||||
|
|
||||||
// Forward history operations to browser.
|
// Forward history operations to browser.
|
||||||
var sendHistoryOperation = function(...args) {
|
var sendHistoryOperation = function (...args) {
|
||||||
return ipcRenderer.send.apply(ipcRenderer, ['ATOM_SHELL_NAVIGATION_CONTROLLER'].concat(args));
|
return ipcRenderer.send.apply(ipcRenderer, ['ATOM_SHELL_NAVIGATION_CONTROLLER'].concat(args))
|
||||||
};
|
}
|
||||||
|
|
||||||
var getHistoryOperation = function(...args) {
|
var getHistoryOperation = function (...args) {
|
||||||
return ipcRenderer.sendSync.apply(ipcRenderer, ['ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER'].concat(args));
|
return ipcRenderer.sendSync.apply(ipcRenderer, ['ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER'].concat(args))
|
||||||
};
|
}
|
||||||
|
|
||||||
window.history.back = function() {
|
window.history.back = function () {
|
||||||
return sendHistoryOperation('goBack');
|
return sendHistoryOperation('goBack')
|
||||||
};
|
}
|
||||||
|
|
||||||
window.history.forward = function() {
|
window.history.forward = function () {
|
||||||
return sendHistoryOperation('goForward');
|
return sendHistoryOperation('goForward')
|
||||||
};
|
}
|
||||||
|
|
||||||
window.history.go = function(offset) {
|
window.history.go = function (offset) {
|
||||||
return sendHistoryOperation('goToOffset', offset);
|
return sendHistoryOperation('goToOffset', offset)
|
||||||
};
|
}
|
||||||
|
|
||||||
Object.defineProperty(window.history, 'length', {
|
Object.defineProperty(window.history, 'length', {
|
||||||
get: function() {
|
get: function () {
|
||||||
return getHistoryOperation('length');
|
return getHistoryOperation('length')
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
// Make document.hidden and document.visibilityState return the correct value.
|
// Make document.hidden and document.visibilityState return the correct value.
|
||||||
Object.defineProperty(document, 'hidden', {
|
Object.defineProperty(document, 'hidden', {
|
||||||
get: function () {
|
get: function () {
|
||||||
return _isMinimized || !_isVisible;
|
return _isMinimized || !_isVisible
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
Object.defineProperty(document, 'visibilityState', {
|
Object.defineProperty(document, 'visibilityState', {
|
||||||
get: function() {
|
get: function () {
|
||||||
if (_isVisible && !_isMinimized) {
|
if (_isVisible && !_isMinimized) {
|
||||||
return "visible";
|
return 'visible'
|
||||||
} else {
|
} else {
|
||||||
return "hidden";
|
return 'hidden'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer
|
||||||
const webFrame = require('electron').webFrame;
|
const webFrame = require('electron').webFrame
|
||||||
|
|
||||||
var requestId= 0;
|
var requestId = 0
|
||||||
|
|
||||||
var WEB_VIEW_EVENTS = {
|
var WEB_VIEW_EVENTS = {
|
||||||
'load-commit': ['url', 'isMainFrame'],
|
'load-commit': ['url', 'isMainFrame'],
|
||||||
|
@ -36,71 +36,71 @@ var WEB_VIEW_EVENTS = {
|
||||||
'enter-html-full-screen': [],
|
'enter-html-full-screen': [],
|
||||||
'leave-html-full-screen': [],
|
'leave-html-full-screen': [],
|
||||||
'found-in-page': ['result']
|
'found-in-page': ['result']
|
||||||
};
|
}
|
||||||
|
|
||||||
var DEPRECATED_EVENTS = {
|
var DEPRECATED_EVENTS = {
|
||||||
'page-title-updated': 'page-title-set'
|
'page-title-updated': 'page-title-set'
|
||||||
};
|
}
|
||||||
|
|
||||||
var dispatchEvent = function(webView, eventName, eventKey, ...args) {
|
var dispatchEvent = function (webView, eventName, eventKey, ...args) {
|
||||||
var domEvent, f, i, j, len, ref1;
|
var domEvent, f, i, j, len, ref1
|
||||||
if (DEPRECATED_EVENTS[eventName] != null) {
|
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);
|
domEvent = new Event(eventName)
|
||||||
ref1 = WEB_VIEW_EVENTS[eventKey];
|
ref1 = WEB_VIEW_EVENTS[eventKey]
|
||||||
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
||||||
f = ref1[i];
|
f = ref1[i]
|
||||||
domEvent[f] = args[i];
|
domEvent[f] = args[i]
|
||||||
}
|
}
|
||||||
webView.dispatchEvent(domEvent);
|
webView.dispatchEvent(domEvent)
|
||||||
if (eventName === 'load-commit') {
|
if (eventName === 'load-commit') {
|
||||||
return webView.onLoadCommit(domEvent);
|
return webView.onLoadCommit(domEvent)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
registerEvents: function(webView, viewInstanceId) {
|
registerEvents: function (webView, viewInstanceId) {
|
||||||
ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-" + viewInstanceId, function(event, eventName, ...args) {
|
ipcRenderer.on('ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId, function (event, eventName, ...args) {
|
||||||
return dispatchEvent.apply(null, [webView, eventName, eventName].concat(args));
|
return dispatchEvent.apply(null, [webView, eventName, eventName].concat(args))
|
||||||
});
|
})
|
||||||
|
|
||||||
ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-" + viewInstanceId, function(event, channel, ...args) {
|
ipcRenderer.on('ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId, function (event, channel, ...args) {
|
||||||
var domEvent = new Event('ipc-message');
|
var domEvent = new Event('ipc-message')
|
||||||
domEvent.channel = channel;
|
domEvent.channel = channel
|
||||||
domEvent.args = args;
|
domEvent.args = args
|
||||||
return webView.dispatchEvent(domEvent);
|
return webView.dispatchEvent(domEvent)
|
||||||
});
|
})
|
||||||
|
|
||||||
return ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-" + viewInstanceId, function(event, ...args) {
|
return ipcRenderer.on('ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId, function (event, ...args) {
|
||||||
var domEvent, f, i, j, len, ref1;
|
var domEvent, f, i, j, len, ref1
|
||||||
domEvent = new Event('size-changed');
|
domEvent = new Event('size-changed')
|
||||||
ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight'];
|
ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
|
||||||
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
||||||
f = ref1[i];
|
f = ref1[i]
|
||||||
domEvent[f] = args[i];
|
domEvent[f] = args[i]
|
||||||
}
|
}
|
||||||
return webView.onSizeChanged(domEvent);
|
return webView.onSizeChanged(domEvent)
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
deregisterEvents: function(viewInstanceId) {
|
deregisterEvents: function (viewInstanceId) {
|
||||||
ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-" + viewInstanceId);
|
ipcRenderer.removeAllListeners('ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId)
|
||||||
ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-" + viewInstanceId);
|
ipcRenderer.removeAllListeners('ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId)
|
||||||
return ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-" + viewInstanceId);
|
return ipcRenderer.removeAllListeners('ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId)
|
||||||
},
|
},
|
||||||
createGuest: function(params, callback) {
|
createGuest: function (params, callback) {
|
||||||
requestId++;
|
requestId++
|
||||||
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId);
|
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId)
|
||||||
return ipcRenderer.once("ATOM_SHELL_RESPONSE_" + requestId, callback);
|
return ipcRenderer.once('ATOM_SHELL_RESPONSE_' + requestId, callback)
|
||||||
},
|
},
|
||||||
attachGuest: function(elementInstanceId, guestInstanceId, params) {
|
attachGuest: function (elementInstanceId, guestInstanceId, params) {
|
||||||
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params);
|
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params)
|
||||||
return webFrame.attachGuest(elementInstanceId);
|
return webFrame.attachGuest(elementInstanceId)
|
||||||
},
|
},
|
||||||
destroyGuest: function(guestInstanceId) {
|
destroyGuest: function (guestInstanceId) {
|
||||||
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId);
|
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId)
|
||||||
},
|
},
|
||||||
setSize: function(guestInstanceId, params) {
|
setSize: function (guestInstanceId, params) {
|
||||||
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', 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 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
|
||||||
|
|
||||||
// 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')
|
||||||
|
|
||||||
var resolveURL = function(url) {
|
var resolveURL = function (url) {
|
||||||
a.href = url;
|
a.href = url
|
||||||
return a.href;
|
return a.href
|
||||||
};
|
}
|
||||||
|
|
||||||
// Attribute objects.
|
// Attribute objects.
|
||||||
// Default implementation of a WebView attribute.
|
// Default implementation of a WebView attribute.
|
||||||
class WebViewAttribute {
|
class WebViewAttribute {
|
||||||
constructor(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
|
||||||
this.ignoreMutation = false;
|
this.ignoreMutation = false
|
||||||
this.defineProperty();
|
this.defineProperty()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves and returns the attribute's value.
|
// Retrieves and returns the attribute's value.
|
||||||
getValue() {
|
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.
|
||||||
setValue(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.
|
||||||
setValueIgnoreMutation(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.
|
||||||
defineProperty() {
|
defineProperty () {
|
||||||
return Object.defineProperty(this.webViewImpl.webviewNode, this.name, {
|
return Object.defineProperty(this.webViewImpl.webviewNode, this.name, {
|
||||||
get: () => {
|
get: () => {
|
||||||
return this.getValue();
|
return this.getValue()
|
||||||
},
|
},
|
||||||
set: (value) => {
|
set: (value) => {
|
||||||
return this.setValue(value);
|
return this.setValue(value)
|
||||||
},
|
},
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the attribute's value changes.
|
// Called when the attribute's value changes.
|
||||||
handleMutation() {}
|
handleMutation () {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// An attribute that is treated as a Boolean.
|
// An attribute that is treated as a Boolean.
|
||||||
class BooleanAttribute extends WebViewAttribute {
|
class BooleanAttribute extends WebViewAttribute {
|
||||||
constructor(name, webViewImpl) {
|
constructor (name, webViewImpl) {
|
||||||
super(name, webViewImpl);
|
super(name, webViewImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue() {
|
getValue () {
|
||||||
return this.webViewImpl.webviewNode.hasAttribute(this.name);
|
return this.webViewImpl.webviewNode.hasAttribute(this.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(value) {
|
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, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute used to define the demension limits of autosizing.
|
// Attribute used to define the demension limits of autosizing.
|
||||||
class AutosizeDimensionAttribute extends WebViewAttribute {
|
class AutosizeDimensionAttribute extends WebViewAttribute {
|
||||||
constructor(name, webViewImpl) {
|
constructor (name, webViewImpl) {
|
||||||
super(name, webViewImpl);
|
super(name, webViewImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue() {
|
getValue () {
|
||||||
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) || 0;
|
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) || 0
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMutation() {
|
handleMutation () {
|
||||||
if (!this.webViewImpl.guestInstanceId) {
|
if (!this.webViewImpl.guestInstanceId) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
return guestViewInternal.setSize(this.webViewImpl.guestInstanceId, {
|
return guestViewInternal.setSize(this.webViewImpl.guestInstanceId, {
|
||||||
enableAutoSize: this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue(),
|
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),
|
width: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() || 0),
|
||||||
height: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() || 0)
|
height: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() || 0)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Attribute that specifies whether the webview should be autosized.
|
// Attribute that specifies whether the webview should be autosized.
|
||||||
class AutosizeAttribute extends BooleanAttribute {
|
class AutosizeAttribute extends BooleanAttribute {
|
||||||
constructor(webViewImpl) {
|
constructor (webViewImpl) {
|
||||||
super(webViewConstants.ATTRIBUTE_AUTOSIZE, 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.
|
// Attribute representing the state of the storage partition.
|
||||||
class PartitionAttribute extends WebViewAttribute {
|
class PartitionAttribute extends WebViewAttribute {
|
||||||
constructor(webViewImpl) {
|
constructor (webViewImpl) {
|
||||||
super(webViewConstants.ATTRIBUTE_PARTITION, webViewImpl);
|
super(webViewConstants.ATTRIBUTE_PARTITION, webViewImpl)
|
||||||
this.validPartitionId = true;
|
this.validPartitionId = true
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMutation(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.
|
||||||
if (!this.webViewImpl.beforeFirstNavigation) {
|
if (!this.webViewImpl.beforeFirstNavigation) {
|
||||||
window.console.error(webViewConstants.ERROR_MSG_ALREADY_NAVIGATED);
|
window.console.error(webViewConstants.ERROR_MSG_ALREADY_NAVIGATED)
|
||||||
this.setValueIgnoreMutation(oldValue);
|
this.setValueIgnoreMutation(oldValue)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
if (newValue === 'persist:') {
|
if (newValue === 'persist:') {
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute that handles the location and navigation of the webview.
|
// Attribute that handles the location and navigation of the webview.
|
||||||
class SrcAttribute extends WebViewAttribute {
|
class SrcAttribute extends WebViewAttribute {
|
||||||
constructor(webViewImpl) {
|
constructor (webViewImpl) {
|
||||||
super(webViewConstants.ATTRIBUTE_SRC, webViewImpl);
|
super(webViewConstants.ATTRIBUTE_SRC, webViewImpl)
|
||||||
this.setupMutationObserver();
|
this.setupMutationObserver()
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue() {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setValueIgnoreMutation(value) {
|
setValueIgnoreMutation (value) {
|
||||||
super.setValueIgnoreMutation(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()
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMutation(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
|
||||||
// placeholder state.
|
// placeholder state.
|
||||||
if (!newValue && oldValue) {
|
if (!newValue && oldValue) {
|
||||||
|
|
||||||
// src attribute changes normally initiate a navigation. We suppress
|
// src attribute changes normally initiate a navigation. We suppress
|
||||||
// the next src attribute handler call to avoid reloading the page
|
// the next src attribute handler call to avoid reloading the page
|
||||||
// on every guest-initiated navigation.
|
// on every guest-initiated navigation.
|
||||||
this.setValueIgnoreMutation(oldValue);
|
this.setValueIgnoreMutation(oldValue)
|
||||||
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.
|
||||||
setupMutationObserver() {
|
setupMutationObserver () {
|
||||||
var params;
|
var params
|
||||||
this.observer = new MutationObserver((mutations) => {
|
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++) {
|
for (i = 0, len = mutations.length; i < len; i++) {
|
||||||
mutation = mutations[i];
|
mutation = mutations[i]
|
||||||
oldValue = mutation.oldValue;
|
oldValue = mutation.oldValue
|
||||||
newValue = this.getValue();
|
newValue = this.getValue()
|
||||||
if (oldValue !== newValue) {
|
if (oldValue !== newValue) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
this.handleMutation(oldValue, newValue);
|
this.handleMutation(oldValue, newValue)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
params = {
|
params = {
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeOldValue: true,
|
attributeOldValue: true,
|
||||||
attributeFilter: [this.name]
|
attributeFilter: [this.name]
|
||||||
};
|
}
|
||||||
return this.observer.observe(this.webViewImpl.webviewNode, params);
|
return this.observer.observe(this.webViewImpl.webviewNode, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
parse() {
|
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
|
||||||
}
|
}
|
||||||
if (this.webViewImpl.guestInstanceId == null) {
|
if (this.webViewImpl.guestInstanceId == null) {
|
||||||
if (this.webViewImpl.beforeFirstNavigation) {
|
if (this.webViewImpl.beforeFirstNavigation) {
|
||||||
this.webViewImpl.beforeFirstNavigation = false;
|
this.webViewImpl.beforeFirstNavigation = false
|
||||||
this.webViewImpl.createGuest();
|
this.webViewImpl.createGuest()
|
||||||
}
|
}
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Navigate to |this.src|.
|
// Navigate to |this.src|.
|
||||||
opts = {};
|
opts = {}
|
||||||
httpreferrer = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue();
|
httpreferrer = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue()
|
||||||
if (httpreferrer) {
|
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) {
|
if (useragent) {
|
||||||
opts.userAgent = useragent;
|
opts.userAgent = useragent
|
||||||
}
|
}
|
||||||
guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId);
|
guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId)
|
||||||
return guestContents.loadURL(this.getValue(), opts);
|
return guestContents.loadURL(this.getValue(), opts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute specifies HTTP referrer.
|
// Attribute specifies HTTP referrer.
|
||||||
class HttpReferrerAttribute extends WebViewAttribute {
|
class HttpReferrerAttribute extends WebViewAttribute {
|
||||||
constructor(webViewImpl) {
|
constructor (webViewImpl) {
|
||||||
super(webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl);
|
super(webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute specifies user agent
|
// Attribute specifies user agent
|
||||||
class UserAgentAttribute extends WebViewAttribute {
|
class UserAgentAttribute extends WebViewAttribute {
|
||||||
constructor(webViewImpl) {
|
constructor (webViewImpl) {
|
||||||
super(webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl);
|
super(webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute that set preload script.
|
// Attribute that set preload script.
|
||||||
class PreloadAttribute extends WebViewAttribute {
|
class PreloadAttribute extends WebViewAttribute {
|
||||||
constructor(webViewImpl) {
|
constructor (webViewImpl) {
|
||||||
super(webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl);
|
super(webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue() {
|
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
|
||||||
}
|
}
|
||||||
preload = resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name));
|
preload = resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name))
|
||||||
protocol = preload.substr(0, 5);
|
protocol = preload.substr(0, 5)
|
||||||
if (protocol !== 'file:') {
|
if (protocol !== 'file:') {
|
||||||
console.error(webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE);
|
console.error(webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE)
|
||||||
preload = '';
|
preload = ''
|
||||||
}
|
}
|
||||||
return preload;
|
return preload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute that specifies the blink features to be enabled.
|
// Attribute that specifies the blink features to be enabled.
|
||||||
class BlinkFeaturesAttribute extends WebViewAttribute {
|
class BlinkFeaturesAttribute extends WebViewAttribute {
|
||||||
constructor(webViewImpl) {
|
constructor (webViewImpl) {
|
||||||
super(webViewConstants.ATTRIBUTE_BLINKFEATURES, webViewImpl);
|
super(webViewConstants.ATTRIBUTE_BLINKFEATURES, webViewImpl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets up all of the webview attributes.
|
// Sets up all of the webview attributes.
|
||||||
WebViewImpl.prototype.setupWebViewAttributes = function() {
|
WebViewImpl.prototype.setupWebViewAttributes = function () {
|
||||||
this.attributes = {};
|
this.attributes = {}
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE] = new AutosizeAttribute(this);
|
this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE] = new AutosizeAttribute(this)
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_PARTITION] = new PartitionAttribute(this);
|
this.attributes[webViewConstants.ATTRIBUTE_PARTITION] = new PartitionAttribute(this)
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_SRC] = new SrcAttribute(this);
|
this.attributes[webViewConstants.ATTRIBUTE_SRC] = new SrcAttribute(this)
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER] = new HttpReferrerAttribute(this);
|
this.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER] = new HttpReferrerAttribute(this)
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_USERAGENT] = new UserAgentAttribute(this);
|
this.attributes[webViewConstants.ATTRIBUTE_USERAGENT] = new UserAgentAttribute(this)
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_NODEINTEGRATION] = new BooleanAttribute(webViewConstants.ATTRIBUTE_NODEINTEGRATION, 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_PLUGINS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_PLUGINS, this)
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_DISABLEWEBSECURITY] = new BooleanAttribute(webViewConstants.ATTRIBUTE_DISABLEWEBSECURITY, 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_ALLOWPOPUPS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_ALLOWPOPUPS, this)
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this);
|
this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this)
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_BLINKFEATURES] = new BlinkFeaturesAttribute(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) => {
|
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_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_PARTITION_ATTRIBUTE: 'Invalid partition attribute.',
|
||||||
ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE: 'Only "file:" protocol is supported in "preload" 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 deprecate = require('electron').deprecate
|
||||||
const webFrame = require('electron').webFrame;
|
const webFrame = require('electron').webFrame
|
||||||
const remote = require('electron').remote;
|
const remote = require('electron').remote
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer
|
||||||
|
|
||||||
const v8Util = process.atomBinding('v8_util');
|
const v8Util = process.atomBinding('v8_util')
|
||||||
const guestViewInternal = require('./guest-view-internal');
|
const guestViewInternal = require('./guest-view-internal')
|
||||||
const webViewConstants = require('./web-view-constants');
|
const webViewConstants = require('./web-view-constants')
|
||||||
|
|
||||||
var hasProp = {}.hasOwnProperty;
|
var hasProp = {}.hasOwnProperty
|
||||||
|
|
||||||
// ID generator.
|
// ID generator.
|
||||||
var nextId = 0;
|
var nextId = 0
|
||||||
|
|
||||||
var getNextId = function() {
|
var getNextId = function () {
|
||||||
return ++nextId;
|
return ++nextId
|
||||||
};
|
}
|
||||||
|
|
||||||
// Represents the internal state of the WebView node.
|
// Represents the internal state of the WebView node.
|
||||||
var WebViewImpl = (function() {
|
var WebViewImpl = (function () {
|
||||||
function WebViewImpl(webviewNode) {
|
function WebViewImpl (webviewNode) {
|
||||||
var shadowRoot;
|
var shadowRoot
|
||||||
this.webviewNode = webviewNode;
|
this.webviewNode = webviewNode
|
||||||
v8Util.setHiddenValue(this.webviewNode, 'internal', this);
|
v8Util.setHiddenValue(this.webviewNode, 'internal', this)
|
||||||
this.attached = false;
|
this.attached = false
|
||||||
this.elementAttached = false;
|
this.elementAttached = false
|
||||||
this.beforeFirstNavigation = true;
|
this.beforeFirstNavigation = true
|
||||||
|
|
||||||
// on* Event handlers.
|
// on* Event handlers.
|
||||||
this.on = {};
|
this.on = {}
|
||||||
this.browserPluginNode = this.createBrowserPluginNode();
|
this.browserPluginNode = this.createBrowserPluginNode()
|
||||||
shadowRoot = this.webviewNode.createShadowRoot();
|
shadowRoot = this.webviewNode.createShadowRoot()
|
||||||
shadowRoot.innerHTML = '<style>:host { display: flex; }</style>';
|
shadowRoot.innerHTML = '<style>:host { display: flex; }</style>'
|
||||||
this.setupWebViewAttributes();
|
this.setupWebViewAttributes()
|
||||||
this.setupFocusPropagation();
|
this.setupFocusPropagation()
|
||||||
this.viewInstanceId = getNextId();
|
this.viewInstanceId = getNextId()
|
||||||
shadowRoot.appendChild(this.browserPluginNode);
|
shadowRoot.appendChild(this.browserPluginNode)
|
||||||
|
|
||||||
// Subscribe to host's zoom level changes.
|
// Subscribe to host's zoom level changes.
|
||||||
this.onZoomLevelChanged = (zoomLevel) => {
|
this.onZoomLevelChanged = (zoomLevel) => {
|
||||||
this.webviewNode.setZoomLevel(zoomLevel);
|
this.webviewNode.setZoomLevel(zoomLevel)
|
||||||
};
|
}
|
||||||
webFrame.on('zoom-level-changed', this.onZoomLevelChanged);
|
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
|
// We create BrowserPlugin as a custom element in order to observe changes
|
||||||
// to attributes synchronously.
|
// to attributes synchronously.
|
||||||
var browserPluginNode;
|
var browserPluginNode
|
||||||
browserPluginNode = new WebViewImpl.BrowserPlugin();
|
browserPluginNode = new WebViewImpl.BrowserPlugin()
|
||||||
v8Util.setHiddenValue(browserPluginNode, 'internal', this);
|
v8Util.setHiddenValue(browserPluginNode, 'internal', this)
|
||||||
return browserPluginNode;
|
return browserPluginNode
|
||||||
};
|
}
|
||||||
|
|
||||||
// Resets some state upon reattaching <webview> element to the DOM.
|
// Resets some state upon reattaching <webview> element to the DOM.
|
||||||
WebViewImpl.prototype.reset = function() {
|
WebViewImpl.prototype.reset = function () {
|
||||||
// Unlisten the zoom-level-changed event.
|
// 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
|
// If guestInstanceId is defined then the <webview> has navigated and has
|
||||||
// already picked up a partition ID. Thus, we need to reset the initialization
|
// 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
|
// 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.
|
// that we don't end up allocating a second guest.
|
||||||
if (this.guestInstanceId) {
|
if (this.guestInstanceId) {
|
||||||
guestViewInternal.destroyGuest(this.guestInstanceId);
|
guestViewInternal.destroyGuest(this.guestInstanceId)
|
||||||
this.webContents = null;
|
this.webContents = null
|
||||||
this.guestInstanceId = void 0;
|
this.guestInstanceId = void 0
|
||||||
this.beforeFirstNavigation = true;
|
this.beforeFirstNavigation = true
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId = true;
|
this.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId = true
|
||||||
}
|
}
|
||||||
return this.internalInstanceId = 0;
|
return this.internalInstanceId = 0
|
||||||
};
|
}
|
||||||
|
|
||||||
// Sets the <webview>.request property.
|
// Sets the <webview>.request property.
|
||||||
WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function(request) {
|
WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function (request) {
|
||||||
return Object.defineProperty(this.webviewNode, 'request', {
|
return Object.defineProperty(this.webviewNode, 'request', {
|
||||||
value: request,
|
value: request,
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.setupFocusPropagation = function() {
|
WebViewImpl.prototype.setupFocusPropagation = function () {
|
||||||
if (!this.webviewNode.hasAttribute('tabIndex')) {
|
if (!this.webviewNode.hasAttribute('tabIndex')) {
|
||||||
// <webview> needs a tabIndex in order to be focusable.
|
// <webview> needs a tabIndex in order to be focusable.
|
||||||
// TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
|
// TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
|
||||||
// to allow <webview> to be focusable.
|
// to allow <webview> to be focusable.
|
||||||
// See http://crbug.com/231664.
|
// See http://crbug.com/231664.
|
||||||
this.webviewNode.setAttribute('tabIndex', -1);
|
this.webviewNode.setAttribute('tabIndex', -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focus the BrowserPlugin when the <webview> takes focus.
|
// Focus the BrowserPlugin when the <webview> takes focus.
|
||||||
this.webviewNode.addEventListener('focus', () => {
|
this.webviewNode.addEventListener('focus', () => {
|
||||||
this.browserPluginNode.focus();
|
this.browserPluginNode.focus()
|
||||||
});
|
})
|
||||||
|
|
||||||
// Blur the BrowserPlugin when the <webview> loses focus.
|
// Blur the BrowserPlugin when the <webview> loses focus.
|
||||||
this.webviewNode.addEventListener('blur', () => {
|
this.webviewNode.addEventListener('blur', () => {
|
||||||
this.browserPluginNode.blur();
|
this.browserPluginNode.blur()
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// This observer monitors mutations to attributes of the <webview> and
|
// This observer monitors mutations to attributes of the <webview> and
|
||||||
// updates the BrowserPlugin properties accordingly. In turn, updating
|
// updates the BrowserPlugin properties accordingly. In turn, updating
|
||||||
// a BrowserPlugin property will update the corresponding BrowserPlugin
|
// a BrowserPlugin property will update the corresponding BrowserPlugin
|
||||||
// attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
|
// attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
|
||||||
// details.
|
// details.
|
||||||
WebViewImpl.prototype.handleWebviewAttributeMutation = function(attributeName, oldValue, newValue) {
|
WebViewImpl.prototype.handleWebviewAttributeMutation = function (attributeName, oldValue, newValue) {
|
||||||
if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) {
|
if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let the changed attribute handle its own mutation;
|
// Let the changed attribute handle its own mutation
|
||||||
return this.attributes[attributeName].handleMutation(oldValue, newValue);
|
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) {
|
if (attributeName === webViewConstants.ATTRIBUTE_INTERNALINSTANCEID && !oldValue && !!newValue) {
|
||||||
this.browserPluginNode.removeAttribute(webViewConstants.ATTRIBUTE_INTERNALINSTANCEID);
|
this.browserPluginNode.removeAttribute(webViewConstants.ATTRIBUTE_INTERNALINSTANCEID)
|
||||||
this.internalInstanceId = parseInt(newValue);
|
this.internalInstanceId = parseInt(newValue)
|
||||||
|
|
||||||
// Track when the element resizes using the element resize callback.
|
// 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) {
|
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) {
|
WebViewImpl.prototype.onSizeChanged = function (webViewEvent) {
|
||||||
var maxHeight, maxWidth, minHeight, minWidth, newHeight, newWidth, node, width;
|
var maxHeight, maxWidth, minHeight, minWidth, newHeight, newWidth, node, width
|
||||||
newWidth = webViewEvent.newWidth;
|
newWidth = webViewEvent.newWidth
|
||||||
newHeight = webViewEvent.newHeight;
|
newHeight = webViewEvent.newHeight
|
||||||
node = this.webviewNode;
|
node = this.webviewNode
|
||||||
width = node.offsetWidth;
|
width = node.offsetWidth
|
||||||
|
|
||||||
// Check the current bounds to make sure we do not resize <webview>
|
// Check the current bounds to make sure we do not resize <webview>
|
||||||
// outside of current constraints.
|
// outside of current constraints.
|
||||||
maxWidth = this.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() | width;
|
maxWidth = this.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() | width
|
||||||
maxHeight = this.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() | width;
|
maxHeight = this.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() | width
|
||||||
minWidth = this.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() | width;
|
minWidth = this.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() | width
|
||||||
minHeight = this.attributes[webViewConstants.ATTRIBUTE_MINHEIGHT].getValue() | width;
|
minHeight = this.attributes[webViewConstants.ATTRIBUTE_MINHEIGHT].getValue() | width
|
||||||
minWidth = Math.min(minWidth, maxWidth);
|
minWidth = Math.min(minWidth, maxWidth)
|
||||||
minHeight = Math.min(minHeight, maxHeight);
|
minHeight = Math.min(minHeight, maxHeight)
|
||||||
if (!this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue() || (newWidth >= minWidth && newWidth <= maxWidth && newHeight >= minHeight && newHeight <= maxHeight)) {
|
if (!this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue() || (newWidth >= minWidth && newWidth <= maxWidth && newHeight >= minHeight && newHeight <= maxHeight)) {
|
||||||
node.style.width = newWidth + 'px';
|
node.style.width = newWidth + 'px'
|
||||||
node.style.height = newHeight + 'px';
|
node.style.height = newHeight + 'px'
|
||||||
|
|
||||||
// Only fire the DOM event if the size of the <webview> has actually
|
// Only fire the DOM event if the size of the <webview> has actually
|
||||||
// changed.
|
// changed.
|
||||||
return this.dispatchEvent(webViewEvent);
|
return this.dispatchEvent(webViewEvent)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.onElementResize = function(newSize) {
|
WebViewImpl.prototype.onElementResize = function (newSize) {
|
||||||
// Dispatch the 'resize' event.
|
// Dispatch the 'resize' event.
|
||||||
var resizeEvent;
|
var resizeEvent
|
||||||
resizeEvent = new Event('resize', {
|
resizeEvent = new Event('resize', {
|
||||||
bubbles: true
|
bubbles: true
|
||||||
});
|
})
|
||||||
resizeEvent.newWidth = newSize.width;
|
resizeEvent.newWidth = newSize.width
|
||||||
resizeEvent.newHeight = newSize.height;
|
resizeEvent.newHeight = newSize.height
|
||||||
this.dispatchEvent(resizeEvent);
|
this.dispatchEvent(resizeEvent)
|
||||||
if (this.guestInstanceId) {
|
if (this.guestInstanceId) {
|
||||||
return guestViewInternal.setSize(this.guestInstanceId, {
|
return guestViewInternal.setSize(this.guestInstanceId, {
|
||||||
normal: newSize
|
normal: newSize
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.createGuest = function() {
|
WebViewImpl.prototype.createGuest = function () {
|
||||||
return guestViewInternal.createGuest(this.buildParams(), (event, guestInstanceId) => {
|
return guestViewInternal.createGuest(this.buildParams(), (event, guestInstanceId) => {
|
||||||
this.attachWindow(guestInstanceId);
|
this.attachWindow(guestInstanceId)
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.dispatchEvent = function(webViewEvent) {
|
WebViewImpl.prototype.dispatchEvent = function (webViewEvent) {
|
||||||
return this.webviewNode.dispatchEvent(webViewEvent);
|
return this.webviewNode.dispatchEvent(webViewEvent)
|
||||||
};
|
}
|
||||||
|
|
||||||
// Adds an 'on<event>' property on the webview, which can be used to set/unset
|
// Adds an 'on<event>' property on the webview, which can be used to set/unset
|
||||||
// an event handler.
|
// an event handler.
|
||||||
WebViewImpl.prototype.setupEventProperty = function(eventName) {
|
WebViewImpl.prototype.setupEventProperty = function (eventName) {
|
||||||
var propertyName;
|
var propertyName
|
||||||
propertyName = 'on' + eventName.toLowerCase();
|
propertyName = 'on' + eventName.toLowerCase()
|
||||||
return Object.defineProperty(this.webviewNode, propertyName, {
|
return Object.defineProperty(this.webviewNode, propertyName, {
|
||||||
get: () => {
|
get: () => {
|
||||||
return this.on[propertyName];
|
return this.on[propertyName]
|
||||||
},
|
},
|
||||||
set: (value) => {
|
set: (value) => {
|
||||||
if (this.on[propertyName]) {
|
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) {
|
if (value) {
|
||||||
return this.webviewNode.addEventListener(eventName, value);
|
return this.webviewNode.addEventListener(eventName, value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
// Updates state upon loadcommit.
|
// Updates state upon loadcommit.
|
||||||
WebViewImpl.prototype.onLoadCommit = function(webViewEvent) {
|
WebViewImpl.prototype.onLoadCommit = function (webViewEvent) {
|
||||||
var newValue, oldValue;
|
var newValue, oldValue
|
||||||
oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC);
|
oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC)
|
||||||
newValue = webViewEvent.url;
|
newValue = webViewEvent.url
|
||||||
if (webViewEvent.isMainFrame && (oldValue !== newValue)) {
|
if (webViewEvent.isMainFrame && (oldValue !== newValue)) {
|
||||||
|
|
||||||
// Touching the src attribute triggers a navigation. To avoid
|
// Touching the src attribute triggers a navigation. To avoid
|
||||||
// triggering a page reload on every guest-initiated navigation,
|
// triggering a page reload on every guest-initiated navigation,
|
||||||
// we do not handle this mutation.
|
// 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) {
|
WebViewImpl.prototype.onAttach = function (storagePartitionId) {
|
||||||
return this.attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue(storagePartitionId);
|
return this.attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue(storagePartitionId)
|
||||||
};
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.buildParams = function() {
|
WebViewImpl.prototype.buildParams = function () {
|
||||||
var attribute, attributeName, css, elementRect, params, ref1;
|
var attribute, attributeName, css, elementRect, params, ref1
|
||||||
params = {
|
params = {
|
||||||
instanceId: this.viewInstanceId,
|
instanceId: this.viewInstanceId,
|
||||||
userAgentOverride: this.userAgentOverride
|
userAgentOverride: this.userAgentOverride
|
||||||
};
|
}
|
||||||
ref1 = this.attributes;
|
ref1 = this.attributes
|
||||||
for (attributeName in ref1) {
|
for (attributeName in ref1) {
|
||||||
if (!hasProp.call(ref1, attributeName)) continue;
|
if (!hasProp.call(ref1, attributeName)) continue
|
||||||
attribute = ref1[attributeName];
|
attribute = ref1[attributeName]
|
||||||
params[attributeName] = attribute.getValue();
|
params[attributeName] = attribute.getValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the WebView is not participating in layout (display:none)
|
// 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
|
// 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
|
// use that value to initially size the guest so as to avoid a relayout of
|
||||||
// the on display:block.
|
// the on display:block.
|
||||||
css = window.getComputedStyle(this.webviewNode, null);
|
css = window.getComputedStyle(this.webviewNode, null)
|
||||||
elementRect = this.webviewNode.getBoundingClientRect();
|
elementRect = this.webviewNode.getBoundingClientRect()
|
||||||
params.elementWidth = parseInt(elementRect.width) || parseInt(css.getPropertyValue('width'));
|
params.elementWidth = parseInt(elementRect.width) || parseInt(css.getPropertyValue('width'))
|
||||||
params.elementHeight = parseInt(elementRect.height) || parseInt(css.getPropertyValue('height'));
|
params.elementHeight = parseInt(elementRect.height) || parseInt(css.getPropertyValue('height'))
|
||||||
return params;
|
return params
|
||||||
};
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.attachWindow = function(guestInstanceId) {
|
WebViewImpl.prototype.attachWindow = function (guestInstanceId) {
|
||||||
this.guestInstanceId = guestInstanceId;
|
this.guestInstanceId = guestInstanceId
|
||||||
this.webContents = remote.getGuestWebContents(this.guestInstanceId);
|
this.webContents = remote.getGuestWebContents(this.guestInstanceId)
|
||||||
if (!this.internalInstanceId) {
|
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.
|
// Registers browser plugin <object> custom element.
|
||||||
var registerBrowserPluginElement = function() {
|
var registerBrowserPluginElement = function () {
|
||||||
var proto;
|
var proto
|
||||||
proto = Object.create(HTMLObjectElement.prototype);
|
proto = Object.create(HTMLObjectElement.prototype)
|
||||||
proto.createdCallback = function() {
|
proto.createdCallback = function () {
|
||||||
this.setAttribute('type', 'application/browser-plugin');
|
this.setAttribute('type', 'application/browser-plugin')
|
||||||
this.setAttribute('id', 'browser-plugin-' + getNextId());
|
this.setAttribute('id', 'browser-plugin-' + getNextId())
|
||||||
|
|
||||||
// The <object> node fills in the <webview> container.
|
// The <object> node fills in the <webview> container.
|
||||||
return this.style.flex = '1 1 auto';
|
return this.style.flex = '1 1 auto'
|
||||||
};
|
}
|
||||||
proto.attributeChangedCallback = function(name, oldValue, newValue) {
|
proto.attributeChangedCallback = function (name, oldValue, newValue) {
|
||||||
var internal;
|
var internal
|
||||||
internal = v8Util.getHiddenValue(this, 'internal');
|
internal = v8Util.getHiddenValue(this, 'internal')
|
||||||
if (!internal) {
|
if (!internal) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
return internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue);
|
return internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue)
|
||||||
};
|
}
|
||||||
proto.attachedCallback = function() {
|
proto.attachedCallback = function () {
|
||||||
// Load the plugin immediately.
|
// Load the plugin immediately.
|
||||||
return this.nonExistentAttribute;
|
return this.nonExistentAttribute
|
||||||
};
|
}
|
||||||
WebViewImpl.BrowserPlugin = webFrame.registerEmbedderCustomElement('browserplugin', {
|
WebViewImpl.BrowserPlugin = webFrame.registerEmbedderCustomElement('browserplugin', {
|
||||||
"extends": 'object',
|
'extends': 'object',
|
||||||
prototype: proto
|
prototype: proto
|
||||||
});
|
})
|
||||||
delete proto.createdCallback;
|
delete proto.createdCallback
|
||||||
delete proto.attachedCallback;
|
delete proto.attachedCallback
|
||||||
delete proto.detachedCallback;
|
delete proto.detachedCallback
|
||||||
return delete proto.attributeChangedCallback;
|
return delete proto.attributeChangedCallback
|
||||||
};
|
}
|
||||||
|
|
||||||
// Registers <webview> custom element.
|
// Registers <webview> custom element.
|
||||||
var registerWebViewElement = function() {
|
var registerWebViewElement = function () {
|
||||||
var createBlockHandler, createNonBlockHandler, i, j, len, len1, m, methods, nonblockMethods, proto;
|
var createBlockHandler, createNonBlockHandler, i, j, len, len1, m, methods, nonblockMethods, proto
|
||||||
proto = Object.create(HTMLObjectElement.prototype);
|
proto = Object.create(HTMLObjectElement.prototype)
|
||||||
proto.createdCallback = function() {
|
proto.createdCallback = function () {
|
||||||
return new WebViewImpl(this);
|
return new WebViewImpl(this)
|
||||||
};
|
}
|
||||||
proto.attributeChangedCallback = function(name, oldValue, newValue) {
|
proto.attributeChangedCallback = function (name, oldValue, newValue) {
|
||||||
var internal;
|
var internal
|
||||||
internal = v8Util.getHiddenValue(this, 'internal');
|
internal = v8Util.getHiddenValue(this, 'internal')
|
||||||
if (!internal) {
|
if (!internal) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
return internal.handleWebviewAttributeMutation(name, oldValue, newValue);
|
return internal.handleWebviewAttributeMutation(name, oldValue, newValue)
|
||||||
};
|
}
|
||||||
proto.detachedCallback = function() {
|
proto.detachedCallback = function () {
|
||||||
var internal;
|
var internal
|
||||||
internal = v8Util.getHiddenValue(this, 'internal');
|
internal = v8Util.getHiddenValue(this, 'internal')
|
||||||
if (!internal) {
|
if (!internal) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
guestViewInternal.deregisterEvents(internal.viewInstanceId);
|
guestViewInternal.deregisterEvents(internal.viewInstanceId)
|
||||||
internal.elementAttached = false;
|
internal.elementAttached = false
|
||||||
return internal.reset();
|
return internal.reset()
|
||||||
};
|
}
|
||||||
proto.attachedCallback = function() {
|
proto.attachedCallback = function () {
|
||||||
var internal;
|
var internal
|
||||||
internal = v8Util.getHiddenValue(this, 'internal');
|
internal = v8Util.getHiddenValue(this, 'internal')
|
||||||
if (!internal) {
|
if (!internal) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
if (!internal.elementAttached) {
|
if (!internal.elementAttached) {
|
||||||
guestViewInternal.registerEvents(internal, internal.viewInstanceId);
|
guestViewInternal.registerEvents(internal, internal.viewInstanceId)
|
||||||
internal.elementAttached = true;
|
internal.elementAttached = true
|
||||||
return internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse();
|
return internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse()
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Public-facing API methods.
|
// Public-facing API methods.
|
||||||
methods = [
|
methods = [
|
||||||
|
@ -378,7 +375,7 @@ var registerWebViewElement = function() {
|
||||||
'inspectServiceWorker',
|
'inspectServiceWorker',
|
||||||
'print',
|
'print',
|
||||||
'printToPDF',
|
'printToPDF',
|
||||||
];
|
]
|
||||||
nonblockMethods = [
|
nonblockMethods = [
|
||||||
'insertCSS',
|
'insertCSS',
|
||||||
'insertText',
|
'insertText',
|
||||||
|
@ -387,79 +384,79 @@ var registerWebViewElement = function() {
|
||||||
'setZoomFactor',
|
'setZoomFactor',
|
||||||
'setZoomLevel',
|
'setZoomLevel',
|
||||||
'setZoomLevelLimits',
|
'setZoomLevelLimits',
|
||||||
];
|
]
|
||||||
|
|
||||||
// Forward proto.foo* method calls to WebViewImpl.foo*.
|
// Forward proto.foo* method calls to WebViewImpl.foo*.
|
||||||
createBlockHandler = function(m) {
|
createBlockHandler = function (m) {
|
||||||
return function(...args) {
|
return function (...args) {
|
||||||
const internal = v8Util.getHiddenValue(this, 'internal');
|
const internal = v8Util.getHiddenValue(this, 'internal')
|
||||||
if (internal.webContents) {
|
if (internal.webContents) {
|
||||||
return internal.webContents[m].apply(internal.webContents, args);
|
return internal.webContents[m].apply(internal.webContents, args)
|
||||||
} else {
|
} 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++) {
|
for (i = 0, len = methods.length; i < len; i++) {
|
||||||
m = methods[i];
|
m = methods[i]
|
||||||
proto[m] = createBlockHandler(m);
|
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++) {
|
for (j = 0, len1 = nonblockMethods.length; j < len1; j++) {
|
||||||
m = nonblockMethods[j];
|
m = nonblockMethods[j]
|
||||||
proto[m] = createNonBlockHandler(m);
|
proto[m] = createNonBlockHandler(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
proto.executeJavaScript = function(code, hasUserGesture, callback) {
|
proto.executeJavaScript = function (code, hasUserGesture, callback) {
|
||||||
var internal = v8Util.getHiddenValue(this, 'internal');
|
var internal = v8Util.getHiddenValue(this, 'internal')
|
||||||
if (typeof hasUserGesture === "function") {
|
if (typeof hasUserGesture === 'function') {
|
||||||
callback = hasUserGesture;
|
callback = hasUserGesture
|
||||||
hasUserGesture = false;
|
hasUserGesture = false
|
||||||
}
|
}
|
||||||
let requestId = getNextId();
|
let requestId = getNextId()
|
||||||
ipcRenderer.send('ATOM_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', requestId, internal.guestInstanceId, "executeJavaScript", code, hasUserGesture);
|
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) {
|
ipcRenderer.once(`ATOM_RENDERER_ASYNC_CALL_TO_GUEST_VIEW_RESPONSE_${requestId}`, function (event, result) {
|
||||||
if (callback)
|
if (callback)
|
||||||
callback(result);
|
callback(result)
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
// WebContents associated with this webview.
|
// WebContents associated with this webview.
|
||||||
proto.getWebContents = function() {
|
proto.getWebContents = function () {
|
||||||
var internal = v8Util.getHiddenValue(this, 'internal');
|
var internal = v8Util.getHiddenValue(this, 'internal')
|
||||||
return internal.webContents;
|
return internal.webContents
|
||||||
};
|
}
|
||||||
|
|
||||||
// Deprecated.
|
// Deprecated.
|
||||||
deprecate.rename(proto, 'getUrl', 'getURL');
|
deprecate.rename(proto, 'getUrl', 'getURL')
|
||||||
window.WebView = webFrame.registerEmbedderCustomElement('webview', {
|
window.WebView = webFrame.registerEmbedderCustomElement('webview', {
|
||||||
prototype: proto
|
prototype: proto
|
||||||
});
|
})
|
||||||
|
|
||||||
// Delete the callbacks so developers cannot call them and produce unexpected
|
// Delete the callbacks so developers cannot call them and produce unexpected
|
||||||
// behavior.
|
// behavior.
|
||||||
delete proto.createdCallback;
|
delete proto.createdCallback
|
||||||
delete proto.attachedCallback;
|
delete proto.attachedCallback
|
||||||
delete proto.detachedCallback;
|
delete proto.detachedCallback
|
||||||
return delete proto.attributeChangedCallback;
|
return delete proto.attributeChangedCallback
|
||||||
};
|
}
|
||||||
|
|
||||||
var useCapture = true;
|
var useCapture = true
|
||||||
|
|
||||||
var listener = function(event) {
|
var listener = function (event) {
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
registerBrowserPluginElement();
|
registerBrowserPluginElement()
|
||||||
registerWebViewElement();
|
registerWebViewElement()
|
||||||
return window.removeEventListener(event.type, listener, useCapture);
|
return window.removeEventListener(event.type, listener, useCapture)
|
||||||
};
|
}
|
||||||
|
|
||||||
window.addEventListener('readystatechange', listener, true);
|
window.addEventListener('readystatechange', listener, true)
|
||||||
|
|
||||||
module.exports = WebViewImpl;
|
module.exports = WebViewImpl
|
||||||
|
|
|
@ -1,135 +1,135 @@
|
||||||
const assert = require('assert');
|
const assert = require('assert')
|
||||||
const ChildProcess = require('child_process');
|
const ChildProcess = require('child_process')
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
const remote = require('electron').remote;
|
const remote = require('electron').remote
|
||||||
|
|
||||||
const app = remote.require('electron').app;
|
const app = remote.require('electron').app
|
||||||
const BrowserWindow = remote.require('electron').BrowserWindow;
|
const BrowserWindow = remote.require('electron').BrowserWindow
|
||||||
|
|
||||||
describe('electron module', function() {
|
describe('electron module', function () {
|
||||||
it('allows old style require by default', function() {
|
it('allows old style require by default', function () {
|
||||||
require('shell');
|
require('shell')
|
||||||
});
|
})
|
||||||
|
|
||||||
it('can prevent exposing internal modules to require', function(done) {
|
it('can prevent exposing internal modules to require', function (done) {
|
||||||
const electron = require('electron');
|
const electron = require('electron')
|
||||||
const clipboard = require('clipboard');
|
const clipboard = require('clipboard')
|
||||||
assert.equal(typeof clipboard, 'object');
|
assert.equal(typeof clipboard, 'object')
|
||||||
electron.hideInternalModules();
|
electron.hideInternalModules()
|
||||||
try {
|
try {
|
||||||
require('clipboard');
|
require('clipboard')
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
assert.equal(err.message, 'Cannot find module \'clipboard\'');
|
assert.equal(err.message, "Cannot find module 'clipboard'")
|
||||||
done();
|
done()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe('app module', function() {
|
describe('app module', function () {
|
||||||
describe('app.getVersion()', function() {
|
describe('app.getVersion()', function () {
|
||||||
it('returns the version field of package.json', function() {
|
it('returns the version field of package.json', function () {
|
||||||
assert.equal(app.getVersion(), '0.1.0');
|
assert.equal(app.getVersion(), '0.1.0')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe('app.setVersion(version)', function() {
|
describe('app.setVersion(version)', function () {
|
||||||
it('overrides the version', function() {
|
it('overrides the version', function () {
|
||||||
assert.equal(app.getVersion(), '0.1.0');
|
assert.equal(app.getVersion(), '0.1.0')
|
||||||
app.setVersion('test-version');
|
app.setVersion('test-version')
|
||||||
assert.equal(app.getVersion(), 'test-version');
|
assert.equal(app.getVersion(), 'test-version')
|
||||||
app.setVersion('0.1.0');
|
app.setVersion('0.1.0')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe('app.getName()', function() {
|
describe('app.getName()', function () {
|
||||||
it('returns the name field of package.json', function() {
|
it('returns the name field of package.json', function () {
|
||||||
assert.equal(app.getName(), 'Electron Test');
|
assert.equal(app.getName(), 'Electron Test')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe('app.setName(name)', function() {
|
describe('app.setName(name)', function () {
|
||||||
it('overrides the name', function() {
|
it('overrides the name', function () {
|
||||||
assert.equal(app.getName(), 'Electron Test');
|
assert.equal(app.getName(), 'Electron Test')
|
||||||
app.setName('test-name');
|
app.setName('test-name')
|
||||||
assert.equal(app.getName(), 'test-name');
|
assert.equal(app.getName(), 'test-name')
|
||||||
app.setName('Electron Test');
|
app.setName('Electron Test')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe('app.getLocale()', function() {
|
describe('app.getLocale()', function () {
|
||||||
it('should not be empty', function() {
|
it('should not be empty', function () {
|
||||||
assert.notEqual(app.getLocale(), '');
|
assert.notEqual(app.getLocale(), '')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe('app.exit(exitCode)', function() {
|
describe('app.exit(exitCode)', function () {
|
||||||
var appProcess = null;
|
var appProcess = null
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function () {
|
||||||
appProcess != null ? appProcess.kill() : void 0;
|
appProcess != null ? appProcess.kill() : void 0
|
||||||
});
|
})
|
||||||
|
|
||||||
it('emits a process exit event with the code', function(done) {
|
it('emits a process exit event with the code', function (done) {
|
||||||
var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
|
var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
||||||
var electronPath = remote.getGlobal('process').execPath;
|
var electronPath = remote.getGlobal('process').execPath
|
||||||
var output = '';
|
var output = ''
|
||||||
appProcess = ChildProcess.spawn(electronPath, [appPath]);
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
||||||
appProcess.stdout.on('data', function(data) {
|
appProcess.stdout.on('data', function (data) {
|
||||||
output += data;
|
output += data
|
||||||
});
|
})
|
||||||
appProcess.on('close', function(code) {
|
appProcess.on('close', function (code) {
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
assert.notEqual(output.indexOf('Exit event with code: 123'), -1);
|
assert.notEqual(output.indexOf('Exit event with code: 123'), -1)
|
||||||
}
|
}
|
||||||
assert.equal(code, 123);
|
assert.equal(code, 123)
|
||||||
done();
|
done()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe('BrowserWindow events', function() {
|
describe('BrowserWindow events', function () {
|
||||||
var w = null;
|
var w = null
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function () {
|
||||||
if (w != null) {
|
if (w != null) {
|
||||||
w.destroy();
|
w.destroy()
|
||||||
}
|
}
|
||||||
w = null;
|
w = null
|
||||||
});
|
})
|
||||||
|
|
||||||
it('should emit browser-window-focus event when window is focused', function(done) {
|
it('should emit browser-window-focus event when window is focused', function (done) {
|
||||||
app.once('browser-window-focus', function(e, window) {
|
app.once('browser-window-focus', function (e, window) {
|
||||||
assert.equal(w.id, window.id);
|
assert.equal(w.id, window.id)
|
||||||
done();
|
done()
|
||||||
});
|
})
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false
|
||||||
});
|
})
|
||||||
w.emit('focus');
|
w.emit('focus')
|
||||||
});
|
})
|
||||||
|
|
||||||
it('should emit browser-window-blur event when window is blured', function(done) {
|
it('should emit browser-window-blur event when window is blured', function (done) {
|
||||||
app.once('browser-window-blur', function(e, window) {
|
app.once('browser-window-blur', function (e, window) {
|
||||||
assert.equal(w.id, window.id);
|
assert.equal(w.id, window.id)
|
||||||
done();
|
done()
|
||||||
});
|
})
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false
|
||||||
});
|
})
|
||||||
w.emit('blur');
|
w.emit('blur')
|
||||||
});
|
})
|
||||||
|
|
||||||
it('should emit browser-window-created event when window is created', function(done) {
|
it('should emit browser-window-created event when window is created', function (done) {
|
||||||
app.once('browser-window-created', function(e, window) {
|
app.once('browser-window-created', function (e, window) {
|
||||||
setImmediate(function() {
|
setImmediate(function () {
|
||||||
assert.equal(w.id, window.id);
|
assert.equal(w.id, window.id)
|
||||||
done();
|
done()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false
|
||||||
});
|
})
|
||||||
w.emit('blur');
|
w.emit('blur')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue