Move JavaScript to root lib/ folder

This commit is contained in:
Kevin Sawicki 2016-03-07 17:12:09 -08:00
parent a9c40de393
commit 70aa9b06ee
56 changed files with 0 additions and 0 deletions

123
lib/browser/api/app.js Normal file
View file

@ -0,0 +1,123 @@
const deprecate = require('electron').deprecate;
const session = require('electron').session;
const Menu = require('electron').Menu;
const EventEmitter = require('events').EventEmitter;
const bindings = process.atomBinding('app');
const downloadItemBindings = process.atomBinding('download_item');
const app = bindings.app;
var slice = [].slice;
app.__proto__ = EventEmitter.prototype;
app.setApplicationMenu = function(menu) {
return Menu.setApplicationMenu(menu);
};
app.getApplicationMenu = function() {
return Menu.getApplicationMenu();
};
app.commandLine = {
appendSwitch: bindings.appendSwitch,
appendArgument: bindings.appendArgument
};
if (process.platform === 'darwin') {
app.dock = {
bounce: function(type) {
if (type == null) {
type = 'informational';
}
return bindings.dockBounce(type);
},
cancelBounce: bindings.dockCancelBounce,
setBadge: bindings.dockSetBadgeText,
getBadge: bindings.dockGetBadgeText,
hide: bindings.dockHide,
show: bindings.dockShow,
setMenu: bindings.dockSetMenu,
setIcon: bindings.dockSetIcon
};
}
var appPath = null;
app.setAppPath = function(path) {
return appPath = path;
};
app.getAppPath = function() {
return appPath;
};
// Routes the events to webContents.
var ref1 = ['login', 'certificate-error', 'select-client-certificate'];
var fn = function(name) {
return app.on(name, function() {
var args, event, webContents;
event = arguments[0], webContents = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
return webContents.emit.apply(webContents, [name, event].concat(slice.call(args)));
});
};
var i, len;
for (i = 0, len = ref1.length; i < len; i++) {
fn(ref1[i]);
}
// Deprecated.
app.getHomeDir = deprecate('app.getHomeDir', 'app.getPath', function() {
return this.getPath('home');
});
app.getDataPath = deprecate('app.getDataPath', 'app.getPath', function() {
return this.getPath('userData');
});
app.setDataPath = deprecate('app.setDataPath', 'app.setPath', function(path) {
return this.setPath('userData', path);
});
app.resolveProxy = deprecate('app.resolveProxy', 'session.defaultSession.resolveProxy', function(url, callback) {
return session.defaultSession.resolveProxy(url, callback);
});
deprecate.rename(app, 'terminate', 'quit');
deprecate.event(app, 'finish-launching', 'ready', function() {
// give default app a chance to setup default menu.
return setImmediate((function(_this) {
return function() {
return _this.emit('finish-launching');
};
})(this));
});
deprecate.event(app, 'activate-with-no-open-windows', 'activate', function(event, hasVisibleWindows) {
if (!hasVisibleWindows) {
return this.emit('activate-with-no-open-windows', event);
}
});
deprecate.event(app, 'select-certificate', 'select-client-certificate');
// Wrappers for native classes.
var wrapDownloadItem = function(downloadItem) {
// downloadItem is an EventEmitter.
downloadItem.__proto__ = EventEmitter.prototype;
// Deprecated.
deprecate.property(downloadItem, 'url', 'getURL');
deprecate.property(downloadItem, 'filename', 'getFilename');
deprecate.property(downloadItem, 'mimeType', 'getMimeType');
return deprecate.rename(downloadItem, 'getUrl', 'getURL');
};
downloadItemBindings._setWrapDownloadItem(wrapDownloadItem);
// Only one App object pemitted.
module.exports = app;

View file

@ -0,0 +1,7 @@
const deprecate = require('electron').deprecate;
const autoUpdater = process.platform === 'win32' ? require('./auto-updater/auto-updater-win') : require('./auto-updater/auto-updater-native');
// Deprecated.
deprecate.rename(autoUpdater, 'setFeedUrl', 'setFeedURL');
module.exports = autoUpdater;

View file

@ -0,0 +1,6 @@
const EventEmitter = require('events').EventEmitter;
const autoUpdater = process.atomBinding('auto_updater').autoUpdater;
autoUpdater.__proto__ = EventEmitter.prototype;
module.exports = autoUpdater;

View file

@ -0,0 +1,63 @@
'use strict';
const app = require('electron').app;
const EventEmitter = require('events').EventEmitter;
const squirrelUpdate = require('./squirrel-update-win');
const util = require('util');
function AutoUpdater() {
EventEmitter.call(this);
}
util.inherits(AutoUpdater, EventEmitter);
AutoUpdater.prototype.quitAndInstall = function() {
squirrelUpdate.processStart();
return app.quit();
};
AutoUpdater.prototype.setFeedURL = function(updateURL) {
return this.updateURL = updateURL;
};
AutoUpdater.prototype.checkForUpdates = function() {
if (!this.updateURL) {
return this.emitError('Update URL is not set');
}
if (!squirrelUpdate.supported()) {
return this.emitError('Can not find Squirrel');
}
this.emit('checking-for-update');
return squirrelUpdate.download(this.updateURL, (function(_this) {
return function(error, update) {
if (error != null) {
return _this.emitError(error);
}
if (update == null) {
return _this.emit('update-not-available');
}
_this.emit('update-available');
return squirrelUpdate.update(_this.updateURL, function(error) {
var date, releaseNotes, version;
if (error != null) {
return _this.emitError(error);
}
releaseNotes = update.releaseNotes, version = update.version;
// Following information is not available on Windows, so fake them.
date = new Date;
return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() {
return _this.quitAndInstall();
});
});
};
})(this));
};
// Private: Emit both error object and message, this is to keep compatibility
// with Old APIs.
AutoUpdater.prototype.emitError = function(message) {
return this.emit('error', new Error(message), message);
};
module.exports = new AutoUpdater;

View file

@ -0,0 +1,98 @@
const fs = require('fs');
const path = require('path');
const spawn = require('child_process').spawn;
// i.e. my-app/app-0.1.13/
const appFolder = path.dirname(process.execPath);
// i.e. my-app/Update.exe
const updateExe = path.resolve(appFolder, '..', 'Update.exe');
const exeName = path.basename(process.execPath);
// Spawn a command and invoke the callback when it completes with an error
// and the output from standard out.
var spawnUpdate = function(args, detached, callback) {
var error, errorEmitted, spawnedProcess, stderr, stdout;
try {
spawnedProcess = spawn(updateExe, args, {
detached: detached
});
} catch (error1) {
error = error1;
// Shouldn't happen, but still guard it.
process.nextTick(function() {
return callback(error);
});
return;
}
stdout = '';
stderr = '';
spawnedProcess.stdout.on('data', function(data) {
return stdout += data;
});
spawnedProcess.stderr.on('data', function(data) {
return stderr += data;
});
errorEmitted = false;
spawnedProcess.on('error', function(error) {
errorEmitted = true;
return callback(error);
});
return spawnedProcess.on('exit', function(code, signal) {
// We may have already emitted an error.
if (errorEmitted) {
return;
}
// Process terminated with error.
if (code !== 0) {
return callback("Command failed: " + (signal != null ? signal : code) + "\n" + stderr);
}
// Success.
return callback(null, stdout);
});
};
// Start an instance of the installed app.
exports.processStart = function() {
return spawnUpdate(['--processStart', exeName], true, function() {});
};
// Download the releases specified by the URL and write new results to stdout.
exports.download = function(updateURL, callback) {
return spawnUpdate(['--download', updateURL], false, function(error, stdout) {
var json, ref, ref1, update;
if (error != null) {
return callback(error);
}
try {
// Last line of output is the JSON details about the releases
json = stdout.trim().split('\n').pop();
update = (ref = JSON.parse(json)) != null ? (ref1 = ref.releasesToApply) != null ? typeof ref1.pop === "function" ? ref1.pop() : void 0 : void 0 : void 0;
} catch (jsonError) {
return callback("Invalid result:\n" + stdout);
}
return callback(null, update);
});
};
// Update the application to the latest remote version specified by URL.
exports.update = function(updateURL, callback) {
return spawnUpdate(['--update', updateURL], false, callback);
};
// Is the Update.exe installed with the current application?
exports.supported = function() {
try {
fs.accessSync(updateExe, fs.R_OK);
return true;
} catch (error) {
return false;
}
};

View file

@ -0,0 +1,243 @@
const ipcMain = require('electron').ipcMain;
const deprecate = require('electron').deprecate;
const EventEmitter = require('events').EventEmitter;
const BrowserWindow = process.atomBinding('window').BrowserWindow;
BrowserWindow.prototype.__proto__ = EventEmitter.prototype;
BrowserWindow.prototype._init = function() {
// avoid recursive require.
var app, menu;
app = require('electron').app;
// Simulate the application menu on platforms other than OS X.
if (process.platform !== 'darwin') {
menu = app.getApplicationMenu();
if (menu != null) {
this.setMenu(menu);
}
}
// Make new windows requested by links behave like "window.open"
this.webContents.on('-new-window', function(event, url, frameName) {
var options;
options = {
show: true,
width: 800,
height: 600
};
return ipcMain.emit('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options);
});
// window.resizeTo(...)
// window.moveTo(...)
this.webContents.on('move', (function(_this) {
return function(event, size) {
return _this.setBounds(size);
};
})(this));
// Hide the auto-hide menu when webContents is focused.
this.webContents.on('activate', (function(_this) {
return function() {
if (process.platform !== 'darwin' && _this.isMenuBarAutoHide() && _this.isMenuBarVisible()) {
return _this.setMenuBarVisibility(false);
}
};
})(this));
// Forward the crashed event.
this.webContents.on('crashed', (function(_this) {
return function() {
return _this.emit('crashed');
};
})(this));
// Change window title to page title.
this.webContents.on('page-title-updated', (event, title) => {
// The page-title-updated event is not emitted immediately (see #3645), so
// when the callback is called the BrowserWindow might have been closed.
if (this.isDestroyed())
return;
// Route the event to BrowserWindow.
this.emit('page-title-updated', event, title);
if (!event.defaultPrevented)
this.setTitle(title);
});
// Sometimes the webContents doesn't get focus when window is shown, so we have
// to force focusing on webContents in this case. The safest way is to focus it
// when we first start to load URL, if we do it earlier it won't have effect,
// if we do it later we might move focus in the page.
// Though this hack is only needed on OS X when the app is launched from
// Finder, we still do it on all platforms in case of other bugs we don't know.
this.webContents.once('load-url', function() {
return this.focus();
});
// Redirect focus/blur event to app instance too.
this.on('blur', (function(_this) {
return function(event) {
return app.emit('browser-window-blur', event, _this);
};
})(this));
this.on('focus', (function(_this) {
return function(event) {
return app.emit('browser-window-focus', event, _this);
};
})(this));
// Notify the creation of the window.
app.emit('browser-window-created', {}, this);
// Be compatible with old APIs.
this.webContents.on('devtools-focused', (function(_this) {
return function() {
return _this.emit('devtools-focused');
};
})(this));
this.webContents.on('devtools-opened', (function(_this) {
return function() {
return _this.emit('devtools-opened');
};
})(this));
this.webContents.on('devtools-closed', (function(_this) {
return function() {
return _this.emit('devtools-closed');
};
})(this));
return Object.defineProperty(this, 'devToolsWebContents', {
enumerable: true,
configurable: false,
get: function() {
return this.webContents.devToolsWebContents;
}
});
};
BrowserWindow.getFocusedWindow = function() {
var i, len, window, windows;
windows = BrowserWindow.getAllWindows();
for (i = 0, len = windows.length; i < len; i++) {
window = windows[i];
if (window.isFocused()) {
return window;
}
}
return null;
};
BrowserWindow.fromWebContents = function(webContents) {
var i, len, ref1, window, windows;
windows = BrowserWindow.getAllWindows();
for (i = 0, len = windows.length; i < len; i++) {
window = windows[i];
if ((ref1 = window.webContents) != null ? ref1.equal(webContents) : void 0) {
return window;
}
}
};
BrowserWindow.fromDevToolsWebContents = function(webContents) {
var i, len, ref1, window, windows;
windows = BrowserWindow.getAllWindows();
for (i = 0, len = windows.length; i < len; i++) {
window = windows[i];
if ((ref1 = window.devToolsWebContents) != null ? ref1.equal(webContents) : void 0) {
return window;
}
}
};
// Helpers.
BrowserWindow.prototype.loadURL = function() {
return this.webContents.loadURL.apply(this.webContents, arguments);
};
BrowserWindow.prototype.getURL = function() {
return this.webContents.getURL();
};
BrowserWindow.prototype.reload = function() {
return this.webContents.reload.apply(this.webContents, arguments);
};
BrowserWindow.prototype.send = function() {
return this.webContents.send.apply(this.webContents, arguments);
};
BrowserWindow.prototype.openDevTools = function() {
return this.webContents.openDevTools.apply(this.webContents, arguments);
};
BrowserWindow.prototype.closeDevTools = function() {
return this.webContents.closeDevTools();
};
BrowserWindow.prototype.isDevToolsOpened = function() {
return this.webContents.isDevToolsOpened();
};
BrowserWindow.prototype.isDevToolsFocused = function() {
return this.webContents.isDevToolsFocused();
};
BrowserWindow.prototype.toggleDevTools = function() {
return this.webContents.toggleDevTools();
};
BrowserWindow.prototype.inspectElement = function() {
return this.webContents.inspectElement.apply(this.webContents, arguments);
};
BrowserWindow.prototype.inspectServiceWorker = function() {
return this.webContents.inspectServiceWorker();
};
// Deprecated.
deprecate.member(BrowserWindow, 'undo', 'webContents');
deprecate.member(BrowserWindow, 'redo', 'webContents');
deprecate.member(BrowserWindow, 'cut', 'webContents');
deprecate.member(BrowserWindow, 'copy', 'webContents');
deprecate.member(BrowserWindow, 'paste', 'webContents');
deprecate.member(BrowserWindow, 'selectAll', 'webContents');
deprecate.member(BrowserWindow, 'reloadIgnoringCache', 'webContents');
deprecate.member(BrowserWindow, 'isLoading', 'webContents');
deprecate.member(BrowserWindow, 'isWaitingForResponse', 'webContents');
deprecate.member(BrowserWindow, 'stop', 'webContents');
deprecate.member(BrowserWindow, 'isCrashed', 'webContents');
deprecate.member(BrowserWindow, 'print', 'webContents');
deprecate.member(BrowserWindow, 'printToPDF', 'webContents');
deprecate.rename(BrowserWindow, 'restart', 'reload');
deprecate.rename(BrowserWindow, 'loadUrl', 'loadURL');
deprecate.rename(BrowserWindow, 'getUrl', 'getURL');
BrowserWindow.prototype.executeJavaScriptInDevTools = deprecate('executeJavaScriptInDevTools', 'devToolsWebContents.executeJavaScript', function(code) {
var ref1;
return (ref1 = this.devToolsWebContents) != null ? ref1.executeJavaScript(code) : void 0;
});
BrowserWindow.prototype.getPageTitle = deprecate('getPageTitle', 'webContents.getTitle', function() {
var ref1;
return (ref1 = this.webContents) != null ? ref1.getTitle() : void 0;
});
module.exports = BrowserWindow;

View file

@ -0,0 +1 @@
module.exports = process.atomBinding('content_tracing');

170
lib/browser/api/dialog.js Normal file
View file

@ -0,0 +1,170 @@
const app = require('electron').app;
const BrowserWindow = require('electron').BrowserWindow;
const binding = process.atomBinding('dialog');
const v8Util = process.atomBinding('v8_util');
var slice = [].slice;
var includes = [].includes;
var fileDialogProperties = {
openFile: 1 << 0,
openDirectory: 1 << 1,
multiSelections: 1 << 2,
createDirectory: 1 << 3
};
var messageBoxTypes = ['none', 'info', 'warning', 'error', 'question'];
var messageBoxOptions = {
noLink: 1 << 0
};
var parseArgs = function(window, options, callback) {
if (!(window === null || (window != null ? window.constructor : void 0) === BrowserWindow)) {
// Shift.
callback = options;
options = window;
window = null;
}
if ((callback == null) && typeof options === 'function') {
// Shift.
callback = options;
options = null;
}
return [window, options, callback];
};
var checkAppInitialized = function() {
if (!app.isReady()) {
throw new Error('dialog module can only be used after app is ready');
}
};
module.exports = {
showOpenDialog: function() {
var args, callback, options, prop, properties, ref1, value, window, wrappedCallback;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
options = {
title: 'Open',
properties: ['openFile']
};
}
if (options.properties == null) {
options.properties = ['openFile'];
}
if (!Array.isArray(options.properties)) {
throw new TypeError('Properties need to be array');
}
properties = 0;
for (prop in fileDialogProperties) {
value = fileDialogProperties[prop];
if (includes.call(options.properties, prop)) {
properties |= value;
}
}
if (options.title == null) {
options.title = '';
}
if (options.defaultPath == null) {
options.defaultPath = '';
}
if (options.filters == null) {
options.filters = [];
}
wrappedCallback = typeof callback === 'function' ? function(success, result) {
return callback(success ? result : void 0);
} : null;
return binding.showOpenDialog(String(options.title), String(options.defaultPath), options.filters, properties, window, wrappedCallback);
},
showSaveDialog: function() {
var args, callback, options, ref1, window, wrappedCallback;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
options = {
title: 'Save'
};
}
if (options.title == null) {
options.title = '';
}
if (options.defaultPath == null) {
options.defaultPath = '';
}
if (options.filters == null) {
options.filters = [];
}
wrappedCallback = typeof callback === 'function' ? function(success, result) {
return callback(success ? result : void 0);
} : null;
return binding.showSaveDialog(String(options.title), String(options.defaultPath), options.filters, window, wrappedCallback);
},
showMessageBox: function() {
var args, callback, flags, i, j, len, messageBoxType, options, ref1, ref2, ref3, text, window;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
options = {
type: 'none'
};
}
if (options.type == null) {
options.type = 'none';
}
messageBoxType = messageBoxTypes.indexOf(options.type);
if (!(messageBoxType > -1)) {
throw new TypeError('Invalid message box type');
}
if (!Array.isArray(options.buttons)) {
throw new TypeError('Buttons need to be array');
}
if (options.title == null) {
options.title = '';
}
if (options.message == null) {
options.message = '';
}
if (options.detail == null) {
options.detail = '';
}
if (options.icon == null) {
options.icon = null;
}
if (options.defaultId == null) {
options.defaultId = -1;
}
// Choose a default button to get selected when dialog is cancelled.
if (options.cancelId == null) {
options.cancelId = 0;
ref2 = options.buttons;
for (i = j = 0, len = ref2.length; j < len; i = ++j) {
text = ref2[i];
if ((ref3 = text.toLowerCase()) === 'cancel' || ref3 === 'no') {
options.cancelId = i;
break;
}
}
}
flags = options.noLink ? messageBoxOptions.noLink : 0;
return binding.showMessageBox(messageBoxType, options.buttons, options.defaultId, options.cancelId, flags, options.title, options.message, options.detail, options.icon, window, callback);
},
showErrorBox: function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return binding.showErrorBox.apply(binding, args);
}
};
// Mark standard asynchronous functions.
var ref1 = ['showMessageBox', 'showOpenDialog', 'showSaveDialog'];
var j, len, api;
for (j = 0, len = ref1.length; j < len; j++) {
api = ref1[j];
v8Util.setHiddenValue(module.exports[api], 'asynchronous', true);
}

View file

@ -0,0 +1,112 @@
const common = require('../../../../common/api/lib/exports/electron');
// Import common modules.
common.defineProperties(exports);
Object.defineProperties(exports, {
// Browser side modules, please sort with alphabet order.
app: {
enumerable: true,
get: function() {
return require('../app');
}
},
autoUpdater: {
enumerable: true,
get: function() {
return require('../auto-updater');
}
},
BrowserWindow: {
enumerable: true,
get: function() {
return require('../browser-window');
}
},
contentTracing: {
enumerable: true,
get: function() {
return require('../content-tracing');
}
},
dialog: {
enumerable: true,
get: function() {
return require('../dialog');
}
},
ipcMain: {
enumerable: true,
get: function() {
return require('../ipc-main');
}
},
globalShortcut: {
enumerable: true,
get: function() {
return require('../global-shortcut');
}
},
Menu: {
enumerable: true,
get: function() {
return require('../menu');
}
},
MenuItem: {
enumerable: true,
get: function() {
return require('../menu-item');
}
},
powerMonitor: {
enumerable: true,
get: function() {
return require('../power-monitor');
}
},
powerSaveBlocker: {
enumerable: true,
get: function() {
return require('../power-save-blocker');
}
},
protocol: {
enumerable: true,
get: function() {
return require('../protocol');
}
},
screen: {
enumerable: true,
get: function() {
return require('../screen');
}
},
session: {
enumerable: true,
get: function() {
return require('../session');
}
},
Tray: {
enumerable: true,
get: function() {
return require('../tray');
}
},
// The internal modules, invisible unless you know their names.
NavigationController: {
get: function() {
return require('../navigation-controller');
}
},
webContents: {
get: function() {
return require('../web-contents');
}
}
});

View file

@ -0,0 +1,5 @@
var globalShortcut;
globalShortcut = process.atomBinding('global_shortcut').globalShortcut;
module.exports = globalShortcut;

View file

@ -0,0 +1,3 @@
const EventEmitter = require('events').EventEmitter;
module.exports = new EventEmitter;

7
lib/browser/api/ipc.js Normal file
View file

@ -0,0 +1,7 @@
const deprecate = require('electron').deprecate;
const ipcMain = require('electron').ipcMain;
// This module is deprecated, we mirror everything from ipcMain.
deprecate.warn('ipc module', 'require("electron").ipcMain');
module.exports = ipcMain;

View file

@ -0,0 +1,103 @@
var MenuItem, methodInBrowserWindow, nextCommandId, rolesMap;
nextCommandId = 0;
// Maps role to methods of webContents
rolesMap = {
undo: 'undo',
redo: 'redo',
cut: 'cut',
copy: 'copy',
paste: 'paste',
selectall: 'selectAll',
minimize: 'minimize',
close: 'close',
delete: 'delete'
};
// Maps methods that should be called directly on the BrowserWindow instance
methodInBrowserWindow = {
minimize: true,
close: true
};
MenuItem = (function() {
MenuItem.types = ['normal', 'separator', 'submenu', 'checkbox', 'radio'];
function MenuItem(options) {
var click, ref;
const Menu = require('electron').Menu;
click = options.click, this.selector = options.selector, this.type = options.type, this.role = options.role, this.label = options.label, this.sublabel = options.sublabel, this.accelerator = options.accelerator, this.icon = options.icon, this.enabled = options.enabled, this.visible = options.visible, this.checked = options.checked, this.submenu = options.submenu;
if ((this.submenu != null) && this.submenu.constructor !== Menu) {
this.submenu = Menu.buildFromTemplate(this.submenu);
}
if ((this.type == null) && (this.submenu != null)) {
this.type = 'submenu';
}
if (this.type === 'submenu' && ((ref = this.submenu) != null ? ref.constructor : void 0) !== Menu) {
throw new Error('Invalid submenu');
}
this.overrideReadOnlyProperty('type', 'normal');
this.overrideReadOnlyProperty('role');
this.overrideReadOnlyProperty('accelerator');
this.overrideReadOnlyProperty('icon');
this.overrideReadOnlyProperty('submenu');
this.overrideProperty('label', '');
this.overrideProperty('sublabel', '');
this.overrideProperty('enabled', true);
this.overrideProperty('visible', true);
this.overrideProperty('checked', false);
if (MenuItem.types.indexOf(this.type) === -1) {
throw new Error("Unknown menu type " + this.type);
}
this.commandId = ++nextCommandId;
this.click = (function(_this) {
return function(focusedWindow) {
// Manually flip the checked flags when clicked.
var methodName, ref1, ref2;
if ((ref1 = _this.type) === 'checkbox' || ref1 === 'radio') {
_this.checked = !_this.checked;
}
if (_this.role && rolesMap[_this.role] && process.platform !== 'darwin' && (focusedWindow != null)) {
methodName = rolesMap[_this.role];
if (methodInBrowserWindow[methodName]) {
return focusedWindow[methodName]();
} else {
return (ref2 = focusedWindow.webContents) != null ? ref2[methodName]() : void 0;
}
} else if (typeof click === 'function') {
return click(_this, focusedWindow);
} else if (typeof _this.selector === 'string' && process.platform === 'darwin') {
return Menu.sendActionToFirstResponder(_this.selector);
}
};
})(this);
}
MenuItem.prototype.overrideProperty = function(name, defaultValue) {
if (defaultValue == null) {
defaultValue = null;
}
return this[name] != null ? this[name] : this[name] = defaultValue;
};
MenuItem.prototype.overrideReadOnlyProperty = function(name, defaultValue) {
if (defaultValue == null) {
defaultValue = null;
}
if (this[name] == null) {
this[name] = defaultValue;
}
return Object.defineProperty(this, name, {
enumerable: true,
writable: false,
value: this[name]
});
};
return MenuItem;
})();
module.exports = MenuItem;

335
lib/browser/api/menu.js Normal file
View file

@ -0,0 +1,335 @@
const BrowserWindow = require('electron').BrowserWindow;
const MenuItem = require('electron').MenuItem;
const EventEmitter = require('events').EventEmitter;
const v8Util = process.atomBinding('v8_util');
const bindings = process.atomBinding('menu');
// Automatically generated radio menu item's group id.
var nextGroupId = 0;
// Search between separators to find a radio menu item and return its group id,
// otherwise generate a group id.
var generateGroupId = function(items, pos) {
var i, item, j, k, ref1, ref2, ref3;
if (pos > 0) {
for (i = j = ref1 = pos - 1; ref1 <= 0 ? j <= 0 : j >= 0; i = ref1 <= 0 ? ++j : --j) {
item = items[i];
if (item.type === 'radio') {
return item.groupId;
}
if (item.type === 'separator') {
break;
}
}
} else if (pos < items.length) {
for (i = k = ref2 = pos, ref3 = items.length - 1; ref2 <= ref3 ? k <= ref3 : k >= ref3; i = ref2 <= ref3 ? ++k : --k) {
item = items[i];
if (item.type === 'radio') {
return item.groupId;
}
if (item.type === 'separator') {
break;
}
}
}
return ++nextGroupId;
};
// Returns the index of item according to |id|.
var indexOfItemById = function(items, id) {
var i, item, j, len;
for (i = j = 0, len = items.length; j < len; i = ++j) {
item = items[i];
if (item.id === id) {
return i;
}
}
return -1;
};
// Returns the index of where to insert the item according to |position|.
var indexToInsertByPosition = function(items, position) {
var id, insertIndex, query, ref1;
if (!position) {
return items.length;
}
ref1 = position.split('='), query = ref1[0], id = ref1[1];
insertIndex = indexOfItemById(items, id);
if (insertIndex === -1 && query !== 'endof') {
console.warn("Item with id '" + id + "' is not found");
return items.length;
}
switch (query) {
case 'after':
insertIndex++;
break;
case 'endof':
// If the |id| doesn't exist, then create a new group with the |id|.
if (insertIndex === -1) {
items.push({
id: id,
type: 'separator'
});
insertIndex = items.length - 1;
}
// Find the end of the group.
insertIndex++;
while (insertIndex < items.length && items[insertIndex].type !== 'separator') {
insertIndex++;
}
}
return insertIndex;
};
const Menu = bindings.Menu;
Menu.prototype.__proto__ = EventEmitter.prototype;
Menu.prototype._init = function() {
this.commandsMap = {};
this.groupsMap = {};
this.items = [];
return this.delegate = {
isCommandIdChecked: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.checked : void 0;
};
})(this),
isCommandIdEnabled: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.enabled : void 0;
};
})(this),
isCommandIdVisible: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.visible : void 0;
};
})(this),
getAcceleratorForCommandId: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.accelerator : void 0;
};
})(this),
getIconForCommandId: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.icon : void 0;
};
})(this),
executeCommand: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.click(BrowserWindow.getFocusedWindow()) : void 0;
};
})(this),
menuWillShow: (function(_this) {
return function() {
// Make sure radio groups have at least one menu item seleted.
var checked, group, id, j, len, radioItem, ref1, results;
ref1 = _this.groupsMap;
results = [];
for (id in ref1) {
group = ref1[id];
checked = false;
for (j = 0, len = group.length; j < len; j++) {
radioItem = group[j];
if (!radioItem.checked) {
continue;
}
checked = true;
break;
}
if (!checked) {
results.push(v8Util.setHiddenValue(group[0], 'checked', true));
} else {
results.push(void 0);
}
}
return results;
};
})(this)
};
};
Menu.prototype.popup = function(window, x, y, positioningItem) {
if (typeof window != 'object' || window.constructor !== BrowserWindow) {
// Shift.
positioningItem = y;
y = x;
x = window;
window = BrowserWindow.getFocusedWindow();
}
// Default parameters.
if (typeof x !== 'number') x = -1;
if (typeof y !== 'number') y = -1;
if (typeof positioningItem !== 'number') positioningItem = 0;
this.popupAt(window, x, y, positioningItem);
};
Menu.prototype.append = function(item) {
return this.insert(this.getItemCount(), item);
};
Menu.prototype.insert = function(pos, item) {
var base, name;
if ((item != null ? item.constructor : void 0) !== MenuItem) {
throw new TypeError('Invalid item');
}
switch (item.type) {
case 'normal':
this.insertItem(pos, item.commandId, item.label);
break;
case 'checkbox':
this.insertCheckItem(pos, item.commandId, item.label);
break;
case 'separator':
this.insertSeparator(pos);
break;
case 'submenu':
this.insertSubMenu(pos, item.commandId, item.label, item.submenu);
break;
case 'radio':
// Grouping radio menu items.
item.overrideReadOnlyProperty('groupId', generateGroupId(this.items, pos));
if ((base = this.groupsMap)[name = item.groupId] == null) {
base[name] = [];
}
this.groupsMap[item.groupId].push(item);
// Setting a radio menu item should flip other items in the group.
v8Util.setHiddenValue(item, 'checked', item.checked);
Object.defineProperty(item, 'checked', {
enumerable: true,
get: function() {
return v8Util.getHiddenValue(item, 'checked');
},
set: (function(_this) {
return function() {
var j, len, otherItem, ref1;
ref1 = _this.groupsMap[item.groupId];
for (j = 0, len = ref1.length; j < len; j++) {
otherItem = ref1[j];
if (otherItem !== item) {
v8Util.setHiddenValue(otherItem, 'checked', false);
}
}
return v8Util.setHiddenValue(item, 'checked', true);
};
})(this)
});
this.insertRadioItem(pos, item.commandId, item.label, item.groupId);
}
if (item.sublabel != null) {
this.setSublabel(pos, item.sublabel);
}
if (item.icon != null) {
this.setIcon(pos, item.icon);
}
if (item.role != null) {
this.setRole(pos, item.role);
}
// Make menu accessable to items.
item.overrideReadOnlyProperty('menu', this);
// Remember the items.
this.items.splice(pos, 0, item);
return this.commandsMap[item.commandId] = item;
};
// Force menuWillShow to be called
Menu.prototype._callMenuWillShow = function() {
var item, j, len, ref1, ref2, results;
if ((ref1 = this.delegate) != null) {
ref1.menuWillShow();
}
ref2 = this.items;
results = [];
for (j = 0, len = ref2.length; j < len; j++) {
item = ref2[j];
if (item.submenu != null) {
results.push(item.submenu._callMenuWillShow());
}
}
return results;
};
var applicationMenu = null;
Menu.setApplicationMenu = function(menu) {
var j, len, results, w, windows;
if (!(menu === null || menu.constructor === Menu)) {
throw new TypeError('Invalid menu');
}
// Keep a reference.
applicationMenu = menu;
if (process.platform === 'darwin') {
if (menu === null) {
return;
}
menu._callMenuWillShow();
return bindings.setApplicationMenu(menu);
} else {
windows = BrowserWindow.getAllWindows();
results = [];
for (j = 0, len = windows.length; j < len; j++) {
w = windows[j];
results.push(w.setMenu(menu));
}
return results;
}
};
Menu.getApplicationMenu = function() {
return applicationMenu;
};
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder;
Menu.buildFromTemplate = function(template) {
var insertIndex, item, j, k, key, len, len1, menu, menuItem, positionedTemplate, value;
if (!Array.isArray(template)) {
throw new TypeError('Invalid template for Menu');
}
positionedTemplate = [];
insertIndex = 0;
for (j = 0, len = template.length; j < len; j++) {
item = template[j];
if (item.position) {
insertIndex = indexToInsertByPosition(positionedTemplate, item.position);
} else {
// If no |position| is specified, insert after last item.
insertIndex++;
}
positionedTemplate.splice(insertIndex, 0, item);
}
menu = new Menu;
for (k = 0, len1 = positionedTemplate.length; k < len1; k++) {
item = positionedTemplate[k];
if (typeof item !== 'object') {
throw new TypeError('Invalid template for MenuItem');
}
menuItem = new MenuItem(item);
for (key in item) {
value = item[key];
if (menuItem[key] == null) {
menuItem[key] = value;
}
}
menu.append(menuItem);
}
return menu;
};
module.exports = Menu;

View file

@ -0,0 +1,188 @@
const ipcMain = require('electron').ipcMain;
var slice = [].slice;
// The history operation in renderer is redirected to browser.
ipcMain.on('ATOM_SHELL_NAVIGATION_CONTROLLER', function() {
var args, event, method, ref;
event = arguments[0], method = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
return (ref = event.sender)[method].apply(ref, args);
});
ipcMain.on('ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', function() {
var args, event, method, ref;
event = arguments[0], method = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
return event.returnValue = (ref = event.sender)[method].apply(ref, args);
});
// JavaScript implementation of Chromium's NavigationController.
// Instead of relying on Chromium for history control, we compeletely do history
// control on user land, and only rely on WebContents.loadURL for navigation.
// This helps us avoid Chromium's various optimizations so we can ensure renderer
// process is restarted everytime.
var NavigationController = (function() {
function NavigationController(webContents) {
this.webContents = webContents;
this.clearHistory();
// webContents may have already navigated to a page.
if (this.webContents._getURL()) {
this.currentIndex++;
this.history.push(this.webContents._getURL());
}
this.webContents.on('navigation-entry-commited', (function(_this) {
return function(event, url, inPage, replaceEntry) {
var currentEntry;
if (_this.inPageIndex > -1 && !inPage) {
// Navigated to a new page, clear in-page mark.
_this.inPageIndex = -1;
} else if (_this.inPageIndex === -1 && inPage) {
// Started in-page navigations.
_this.inPageIndex = _this.currentIndex;
}
if (_this.pendingIndex >= 0) {
// Go to index.
_this.currentIndex = _this.pendingIndex;
_this.pendingIndex = -1;
return _this.history[_this.currentIndex] = url;
} else if (replaceEntry) {
// Non-user initialized navigation.
return _this.history[_this.currentIndex] = url;
} else {
// Normal navigation. Clear history.
_this.history = _this.history.slice(0, _this.currentIndex + 1);
currentEntry = _this.history[_this.currentIndex];
if ((currentEntry != null ? currentEntry.url : void 0) !== url) {
_this.currentIndex++;
return _this.history.push(url);
}
}
};
})(this));
}
NavigationController.prototype.loadURL = function(url, options) {
if (options == null) {
options = {};
}
this.pendingIndex = -1;
this.webContents._loadURL(url, options);
return this.webContents.emit('load-url', url, options);
};
NavigationController.prototype.getURL = function() {
if (this.currentIndex === -1) {
return '';
} else {
return this.history[this.currentIndex];
}
};
NavigationController.prototype.stop = function() {
this.pendingIndex = -1;
return this.webContents._stop();
};
NavigationController.prototype.reload = function() {
this.pendingIndex = this.currentIndex;
return this.webContents._loadURL(this.getURL(), {});
};
NavigationController.prototype.reloadIgnoringCache = function() {
this.pendingIndex = this.currentIndex;
return this.webContents._loadURL(this.getURL(), {
extraHeaders: "pragma: no-cache\n"
});
};
NavigationController.prototype.canGoBack = function() {
return this.getActiveIndex() > 0;
};
NavigationController.prototype.canGoForward = function() {
return this.getActiveIndex() < this.history.length - 1;
};
NavigationController.prototype.canGoToIndex = function(index) {
return index >= 0 && index < this.history.length;
};
NavigationController.prototype.canGoToOffset = function(offset) {
return this.canGoToIndex(this.currentIndex + offset);
};
NavigationController.prototype.clearHistory = function() {
this.history = [];
this.currentIndex = -1;
this.pendingIndex = -1;
return this.inPageIndex = -1;
};
NavigationController.prototype.goBack = function() {
if (!this.canGoBack()) {
return;
}
this.pendingIndex = this.getActiveIndex() - 1;
if (this.inPageIndex > -1 && this.pendingIndex >= this.inPageIndex) {
return this.webContents._goBack();
} else {
return this.webContents._loadURL(this.history[this.pendingIndex], {});
}
};
NavigationController.prototype.goForward = function() {
if (!this.canGoForward()) {
return;
}
this.pendingIndex = this.getActiveIndex() + 1;
if (this.inPageIndex > -1 && this.pendingIndex >= this.inPageIndex) {
return this.webContents._goForward();
} else {
return this.webContents._loadURL(this.history[this.pendingIndex], {});
}
};
NavigationController.prototype.goToIndex = function(index) {
if (!this.canGoToIndex(index)) {
return;
}
this.pendingIndex = index;
return this.webContents._loadURL(this.history[this.pendingIndex], {});
};
NavigationController.prototype.goToOffset = function(offset) {
var pendingIndex;
if (!this.canGoToOffset(offset)) {
return;
}
pendingIndex = this.currentIndex + offset;
if (this.inPageIndex > -1 && pendingIndex >= this.inPageIndex) {
this.pendingIndex = pendingIndex;
return this.webContents._goToOffset(offset);
} else {
return this.goToIndex(pendingIndex);
}
};
NavigationController.prototype.getActiveIndex = function() {
if (this.pendingIndex === -1) {
return this.currentIndex;
} else {
return this.pendingIndex;
}
};
NavigationController.prototype.length = function() {
return this.history.length;
};
return NavigationController;
})();
module.exports = NavigationController;

View file

@ -0,0 +1,6 @@
const EventEmitter = require('events').EventEmitter;
const powerMonitor = process.atomBinding('power_monitor').powerMonitor;
powerMonitor.__proto__ = EventEmitter.prototype;
module.exports = powerMonitor;

View file

@ -0,0 +1,5 @@
var powerSaveBlocker;
powerSaveBlocker = process.atomBinding('power_save_blocker').powerSaveBlocker;
module.exports = powerSaveBlocker;

View file

@ -0,0 +1,31 @@
const app = require('electron').app;
if (!app.isReady()) {
throw new Error('Can not initialize protocol module before app is ready');
}
const protocol = process.atomBinding('protocol').protocol;
// Warn about removed APIs.
var logAndThrow = function(callback, message) {
console.error(message);
if (callback) {
return callback(new Error(message));
} else {
throw new Error(message);
}
};
protocol.registerProtocol = function(scheme, handler, callback) {
return logAndThrow(callback, 'registerProtocol API has been replaced by the register[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.');
};
protocol.isHandledProtocol = function(scheme, callback) {
return logAndThrow(callback, 'isHandledProtocol API has been replaced by isProtocolHandled.');
};
protocol.interceptProtocol = function(scheme, handler, callback) {
return logAndThrow(callback, 'interceptProtocol API has been replaced by the intercept[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.');
};
module.exports = protocol;

View file

@ -0,0 +1,6 @@
const EventEmitter = require('events').EventEmitter;
const screen = process.atomBinding('screen').screen;
screen.__proto__ = EventEmitter.prototype;
module.exports = screen;

View file

@ -0,0 +1,33 @@
const EventEmitter = require('events').EventEmitter;
const bindings = process.atomBinding('session');
const PERSIST_PREFIX = 'persist:';
// Returns the Session from |partition| string.
exports.fromPartition = function(partition) {
if (partition == null) {
partition = '';
}
if (partition === '') {
return exports.defaultSession;
}
if (partition.startsWith(PERSIST_PREFIX)) {
return bindings.fromPartition(partition.substr(PERSIST_PREFIX.length), false);
} else {
return bindings.fromPartition(partition, true);
}
};
// Returns the default session.
Object.defineProperty(exports, 'defaultSession', {
enumerable: true,
get: function() {
return bindings.fromPartition('', false);
}
});
var wrapSession = function(session) {
// session is an EventEmitter.
return session.__proto__ = EventEmitter.prototype;
};
bindings._setWrapSession(wrapSession);

23
lib/browser/api/tray.js Normal file
View file

@ -0,0 +1,23 @@
const deprecate = require('electron').deprecate;
const EventEmitter = require('events').EventEmitter;
const Tray = process.atomBinding('tray').Tray;
Tray.prototype.__proto__ = EventEmitter.prototype;
Tray.prototype._init = function() {
// Deprecated.
deprecate.rename(this, 'popContextMenu', 'popUpContextMenu');
deprecate.event(this, 'clicked', 'click');
deprecate.event(this, 'double-clicked', 'double-click');
deprecate.event(this, 'right-clicked', 'right-click');
return deprecate.event(this, 'balloon-clicked', 'balloon-click');
};
Tray.prototype.setContextMenu = function(menu) {
this._setContextMenu(menu);
// Keep a strong reference of menu.
return this.menu = menu;
};
module.exports = Tray;

View file

@ -0,0 +1,247 @@
'use strict';
const EventEmitter = require('events').EventEmitter;
const deprecate = require('electron').deprecate;
const ipcMain = require('electron').ipcMain;
const NavigationController = require('electron').NavigationController;
const Menu = require('electron').Menu;
const binding = process.atomBinding('web_contents');
const debuggerBinding = process.atomBinding('debugger');
let slice = [].slice;
let nextId = 0;
let getNextId = function() {
return ++nextId;
};
let PDFPageSize = {
A5: {
custom_display_name: "A5",
height_microns: 210000,
name: "ISO_A5",
width_microns: 148000
},
A4: {
custom_display_name: "A4",
height_microns: 297000,
name: "ISO_A4",
is_default: "true",
width_microns: 210000
},
A3: {
custom_display_name: "A3",
height_microns: 420000,
name: "ISO_A3",
width_microns: 297000
},
Legal: {
custom_display_name: "Legal",
height_microns: 355600,
name: "NA_LEGAL",
width_microns: 215900
},
Letter: {
custom_display_name: "Letter",
height_microns: 279400,
name: "NA_LETTER",
width_microns: 215900
},
Tabloid: {
height_microns: 431800,
name: "NA_LEDGER",
width_microns: 279400,
custom_display_name: "Tabloid"
}
};
// Following methods are mapped to webFrame.
const webFrameMethods = [
'insertText',
'setZoomFactor',
'setZoomLevel',
'setZoomLevelLimits'
];
let wrapWebContents = function(webContents) {
// webContents is an EventEmitter.
var controller, method, name, ref1;
webContents.__proto__ = EventEmitter.prototype;
// Every remote callback from renderer process would add a listenter to the
// render-view-deleted event, so ignore the listenters warning.
webContents.setMaxListeners(0);
// WebContents::send(channel, args..)
webContents.send = function() {
var args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
var channel = arguments[0];
if (channel == null) {
throw new Error('Missing required channel argument');
}
return this._send(channel, slice.call(args));
};
// The navigation controller.
controller = new NavigationController(webContents);
ref1 = NavigationController.prototype;
for (name in ref1) {
method = ref1[name];
if (method instanceof Function) {
(function(name, method) {
return webContents[name] = function() {
return method.apply(controller, arguments);
};
})(name, method);
}
}
// Mapping webFrame methods.
for (let method of webFrameMethods) {
webContents[method] = function() {
let args = Array.prototype.slice.call(arguments);
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args);
};
}
const asyncWebFrameMethods = function(requestId, method, callback, ...args) {
this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args);
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function(event, result) {
if (callback)
callback(result);
});
};
// Make sure webContents.executeJavaScript would run the code only when the
// webContents has been loaded.
webContents.executeJavaScript = function(code, hasUserGesture, callback) {
let requestId = getNextId();
if (typeof hasUserGesture === "function") {
callback = hasUserGesture;
hasUserGesture = false;
}
if (this.getURL() && !this.isLoading())
return asyncWebFrameMethods.call(this, requestId, "executeJavaScript", callback, code, hasUserGesture);
else
return this.once('did-finish-load', asyncWebFrameMethods.bind(this, requestId, "executeJavaScript", callback, code, hasUserGesture));
};
// Dispatch IPC messages to the ipc module.
webContents.on('ipc-message', function(event, packed) {
var args, channel;
channel = packed[0], args = 2 <= packed.length ? slice.call(packed, 1) : [];
return ipcMain.emit.apply(ipcMain, [channel, event].concat(slice.call(args)));
});
webContents.on('ipc-message-sync', function(event, packed) {
var args, channel;
channel = packed[0], args = 2 <= packed.length ? slice.call(packed, 1) : [];
Object.defineProperty(event, 'returnValue', {
set: function(value) {
return event.sendReply(JSON.stringify(value));
}
});
return ipcMain.emit.apply(ipcMain, [channel, event].concat(slice.call(args)));
});
// Handle context menu action request from pepper plugin.
webContents.on('pepper-context-menu', function(event, params) {
var menu;
menu = Menu.buildFromTemplate(params.menu);
return menu.popup(params.x, params.y);
});
// This error occurs when host could not be found.
webContents.on('did-fail-provisional-load', function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
// Calling loadURL during this event might cause crash, so delay the event
// until next tick.
return setImmediate((function(_this) {
return function() {
return _this.emit.apply(_this, ['did-fail-load'].concat(slice.call(args)));
};
})(this));
});
// Delays the page-title-updated event to next tick.
webContents.on('-page-title-updated', function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return setImmediate((function(_this) {
return function() {
return _this.emit.apply(_this, ['page-title-updated'].concat(slice.call(args)));
};
})(this));
});
// Deprecated.
deprecate.rename(webContents, 'loadUrl', 'loadURL');
deprecate.rename(webContents, 'getUrl', 'getURL');
deprecate.event(webContents, 'page-title-set', 'page-title-updated', function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return this.emit.apply(this, ['page-title-set'].concat(slice.call(args)));
});
return webContents.printToPDF = function(options, callback) {
var printingSetting;
printingSetting = {
pageRage: [],
mediaSize: {},
landscape: false,
color: 2,
headerFooterEnabled: false,
marginsType: 0,
isFirstRequest: false,
requestID: getNextId(),
previewModifiable: true,
printToPDF: true,
printWithCloudPrint: false,
printWithPrivet: false,
printWithExtension: false,
deviceName: "Save as PDF",
generateDraftData: true,
fitToPageEnabled: false,
duplex: 0,
copies: 1,
collate: true,
shouldPrintBackgrounds: false,
shouldPrintSelectionOnly: false
};
if (options.landscape) {
printingSetting.landscape = options.landscape;
}
if (options.marginsType) {
printingSetting.marginsType = options.marginsType;
}
if (options.printSelectionOnly) {
printingSetting.shouldPrintSelectionOnly = options.printSelectionOnly;
}
if (options.printBackground) {
printingSetting.shouldPrintBackgrounds = options.printBackground;
}
if (options.pageSize && PDFPageSize[options.pageSize]) {
printingSetting.mediaSize = PDFPageSize[options.pageSize];
} else {
printingSetting.mediaSize = PDFPageSize['A4'];
}
return this._printToPDF(printingSetting, callback);
};
};
// Wrapper for native class.
let wrapDebugger = function(webContentsDebugger) {
// debugger is an EventEmitter.
webContentsDebugger.__proto__ = EventEmitter.prototype;
};
binding._setWrapWebContents(wrapWebContents);
debuggerBinding._setWrapDebugger(wrapDebugger);
module.exports.create = function(options) {
if (options == null) {
options = {};
}
return binding.create(options);
};