Merge pull request #5373 from electron/remove-deprecated-apis
Remove deprecated apis
This commit is contained in:
commit
e139012f9a
29 changed files with 38 additions and 454 deletions
|
@ -52,11 +52,6 @@ namespace api {
|
|||
|
||||
namespace {
|
||||
|
||||
// This function is implemented in JavaScript
|
||||
using DeprecatedOptionsCheckCallback =
|
||||
base::Callback<std::string(v8::Local<v8::Value>)>;
|
||||
DeprecatedOptionsCheckCallback g_deprecated_options_check;
|
||||
|
||||
void OnCapturePageDone(
|
||||
v8::Isolate* isolate,
|
||||
const base::Callback<void(const gfx::Image&)>& callback,
|
||||
|
@ -66,52 +61,6 @@ void OnCapturePageDone(
|
|||
callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||
}
|
||||
|
||||
// Converts min-width to minWidth, returns false if no conversion is needed.
|
||||
bool TranslateOldKey(const std::string& key, std::string* new_key) {
|
||||
if (key.find('-') == std::string::npos)
|
||||
return false;
|
||||
new_key->reserve(key.size());
|
||||
bool next_upper_case = false;
|
||||
for (char c : key) {
|
||||
if (c == '-') {
|
||||
next_upper_case = true;
|
||||
} else if (next_upper_case) {
|
||||
new_key->push_back(base::ToUpperASCII(c));
|
||||
next_upper_case = false;
|
||||
} else {
|
||||
new_key->push_back(c);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Converts min-width to minWidth recursively in the dictionary.
|
||||
void TranslateOldOptions(v8::Isolate* isolate, v8::Local<v8::Object> options) {
|
||||
auto context = isolate->GetCurrentContext();
|
||||
auto maybe_keys = options->GetOwnPropertyNames(context);
|
||||
if (maybe_keys.IsEmpty())
|
||||
return;
|
||||
std::vector<std::string> keys;
|
||||
if (!mate::ConvertFromV8(isolate, maybe_keys.ToLocalChecked(), &keys))
|
||||
return;
|
||||
mate::Dictionary dict(isolate, options);
|
||||
for (const auto& key : keys) {
|
||||
v8::Local<v8::Value> value;
|
||||
if (!dict.Get(key, &value)) // Shouldn't happen, but guard it anyway.
|
||||
continue;
|
||||
// Go recursively.
|
||||
v8::Local<v8::Object> sub_options;
|
||||
if (mate::ConvertFromV8(isolate, value, &sub_options))
|
||||
TranslateOldOptions(isolate, sub_options);
|
||||
// Translate key.
|
||||
std::string new_key;
|
||||
if (TranslateOldKey(key, &new_key)) {
|
||||
dict.Set(new_key, value);
|
||||
dict.Delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Converts binary data to Buffer.
|
||||
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
||||
|
@ -125,23 +74,12 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
|||
|
||||
|
||||
Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
|
||||
// Be compatible with old style field names like min-width.
|
||||
TranslateOldOptions(isolate, options.GetHandle());
|
||||
|
||||
// Use options.webPreferences to create WebContents.
|
||||
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
||||
options.Get(options::kWebPreferences, &web_preferences);
|
||||
|
||||
// Be compatible with old options which are now in web_preferences.
|
||||
v8::Local<v8::Value> value;
|
||||
if (options.Get(options::kNodeIntegration, &value))
|
||||
web_preferences.Set(options::kNodeIntegration, value);
|
||||
if (options.Get(options::kPreloadScript, &value))
|
||||
web_preferences.Set(options::kPreloadScript, value);
|
||||
if (options.Get(options::kZoomFactor, &value))
|
||||
web_preferences.Set(options::kZoomFactor, value);
|
||||
|
||||
// Copy the backgroundColor to webContents.
|
||||
v8::Local<v8::Value> value;
|
||||
if (options.Get(options::kBackgroundColor, &value))
|
||||
web_preferences.Set(options::kBackgroundColor, value);
|
||||
|
||||
|
@ -304,13 +242,6 @@ mate::WrappableBase* Window::New(v8::Isolate* isolate, mate::Arguments* args) {
|
|||
options = mate::Dictionary::CreateEmpty(isolate);
|
||||
}
|
||||
|
||||
std::string deprecation_message = g_deprecated_options_check.Run(
|
||||
options.GetHandle());
|
||||
if (deprecation_message.length() > 0) {
|
||||
args->ThrowError(deprecation_message);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new Window(isolate, options);
|
||||
}
|
||||
|
||||
|
@ -822,10 +753,6 @@ v8::Local<v8::Value> Window::From(v8::Isolate* isolate,
|
|||
return v8::Null(isolate);
|
||||
}
|
||||
|
||||
void SetDeprecatedOptionsCheck(const DeprecatedOptionsCheckCallback& callback) {
|
||||
g_deprecated_options_check = callback;
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
@ -848,8 +775,6 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("BrowserWindow", browser_window);
|
||||
dict.SetMethod("_setDeprecatedOptionsCheck",
|
||||
&atom::api::SetDeprecatedOptionsCheck);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -318,7 +318,6 @@ void NativeImage::BuildPrototype(
|
|||
.SetMethod("toJpeg", &NativeImage::ToJPEG)
|
||||
.SetMethod("getNativeHandle", &NativeImage::GetNativeHandle)
|
||||
.SetMethod("toDataURL", &NativeImage::ToDataURL)
|
||||
.SetMethod("toDataUrl", &NativeImage::ToDataURL) // deprecated.
|
||||
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
||||
.SetMethod("getSize", &NativeImage::GetSize)
|
||||
.SetMethod("setTemplateImage", &NativeImage::SetTemplateImage)
|
||||
|
|
|
@ -52,7 +52,3 @@ Don't attach to current console session.
|
|||
## `ELECTRON_FORCE_WINDOW_MENU_BAR` _Linux_
|
||||
|
||||
Don't use global menu bar on Linux.
|
||||
|
||||
## `ELECTRON_HIDE_INTERNAL_MODULES`
|
||||
|
||||
Turns off compatibility mode for old built-in modules like `require('ipc')`.
|
||||
|
|
|
@ -61,25 +61,6 @@ const {app, BrowserWindow} = require('electron')
|
|||
However if you are using plain JavaScript, you have to wait until Chrome fully
|
||||
supports ES6.
|
||||
|
||||
## Disable old styles of using built-in modules
|
||||
|
||||
Before v0.35.0, all built-in modules have to be used in the form of
|
||||
`require('module-name')`, though it has [many disadvantages][issue-387], we are
|
||||
still supporting it for compatibility with old apps.
|
||||
|
||||
To disable the old styles completely, you can set the
|
||||
`ELECTRON_HIDE_INTERNAL_MODULES` environment variable:
|
||||
|
||||
```javascript
|
||||
process.env.ELECTRON_HIDE_INTERNAL_MODULES = 'true'
|
||||
```
|
||||
|
||||
Or call the `hideInternalModules` API:
|
||||
|
||||
```javascript
|
||||
require('electron').hideInternalModules()
|
||||
```
|
||||
|
||||
[gui]: https://en.wikipedia.org/wiki/Graphical_user_interface
|
||||
[destructuring-assignment]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
|
||||
[issue-387]: https://github.com/electron/electron/issues/387
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
'lib/browser/api/dialog.js',
|
||||
'lib/browser/api/exports/electron.js',
|
||||
'lib/browser/api/global-shortcut.js',
|
||||
'lib/browser/api/ipc.js',
|
||||
'lib/browser/api/ipc-main.js',
|
||||
'lib/browser/api/menu.js',
|
||||
'lib/browser/api/menu-item.js',
|
||||
|
@ -58,7 +57,6 @@
|
|||
'lib/renderer/web-view/web-view-constants.js',
|
||||
'lib/renderer/api/desktop-capturer.js',
|
||||
'lib/renderer/api/exports/electron.js',
|
||||
'lib/renderer/api/ipc.js',
|
||||
'lib/renderer/api/ipc-renderer.js',
|
||||
'lib/renderer/api/remote.js',
|
||||
'lib/renderer/api/screen.js',
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
'use strict'
|
||||
|
||||
const electron = require('electron')
|
||||
const {deprecate, session, Menu} = electron
|
||||
const {Menu} = require('electron')
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
|
||||
const bindings = process.atomBinding('app')
|
||||
|
@ -63,61 +62,10 @@ 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.
|
||||
setImmediate(() => {
|
||||
this.emit('finish-launching')
|
||||
})
|
||||
})
|
||||
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')
|
||||
if (process.platform === 'win32') {
|
||||
app.isAeroGlassEnabled = deprecate('app.isAeroGlassEnabled', 'systemPreferences.isAeroGlassEnabled', function () {
|
||||
return electron.systemPreferences.isAeroGlassEnabled()
|
||||
})
|
||||
} else if (process.platform === 'darwin') {
|
||||
app.isDarkMode = deprecate('app.isDarkMode', 'systemPreferences.isDarkMode', function () {
|
||||
return electron.systemPreferences.isDarkMode()
|
||||
})
|
||||
app.on = app.addListener = function (event, listener) {
|
||||
if (event === 'platform-theme-changed') {
|
||||
deprecate.warn('platform-theme-changed event', "systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', callback)")
|
||||
electron.systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', function () {
|
||||
app.emit('platform-theme-changed')
|
||||
})
|
||||
}
|
||||
EventEmitter.prototype.addListener.call(app, event, listener)
|
||||
}
|
||||
}
|
||||
|
||||
// Wrappers for native classes.
|
||||
var wrapDownloadItem = function (downloadItem) {
|
||||
// downloadItem is an EventEmitter.
|
||||
Object.setPrototypeOf(downloadItem, 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)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
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
|
||||
if (process.platform === 'win32') {
|
||||
module.exports = require('./auto-updater/auto-updater-win')
|
||||
} else {
|
||||
module.exports = require('./auto-updater/auto-updater-native')
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
'use strict'
|
||||
|
||||
const ipcMain = require('electron').ipcMain
|
||||
const deprecate = require('electron').deprecate
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
const {BrowserWindow, _setDeprecatedOptionsCheck} = process.atomBinding('window')
|
||||
const {BrowserWindow} = process.atomBinding('window')
|
||||
|
||||
Object.setPrototypeOf(BrowserWindow.prototype, EventEmitter.prototype)
|
||||
|
||||
|
@ -44,11 +43,6 @@ BrowserWindow.prototype._init = function () {
|
|||
}
|
||||
})
|
||||
|
||||
// Forward the crashed event.
|
||||
this.webContents.on('crashed', () => {
|
||||
this.emit('crashed')
|
||||
})
|
||||
|
||||
// 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
|
||||
|
@ -96,17 +90,6 @@ BrowserWindow.prototype._init = function () {
|
|||
// Notify the creation of the window.
|
||||
app.emit('browser-window-created', {}, this)
|
||||
|
||||
// Be compatible with old APIs.
|
||||
this.webContents.on('devtools-focused', () => {
|
||||
this.emit('devtools-focused')
|
||||
})
|
||||
this.webContents.on('devtools-opened', () => {
|
||||
this.emit('devtools-opened')
|
||||
})
|
||||
this.webContents.on('devtools-closed', () => {
|
||||
this.emit('devtools-closed')
|
||||
})
|
||||
|
||||
Object.defineProperty(this, 'devToolsWebContents', {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
|
@ -196,84 +179,4 @@ 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
|
||||
})
|
||||
|
||||
const isDeprecatedKey = function (key) {
|
||||
return key.indexOf('-') >= 0
|
||||
}
|
||||
|
||||
// Map deprecated key with hyphens to camel case key
|
||||
const getNonDeprecatedKey = function (deprecatedKey) {
|
||||
return deprecatedKey.replace(/-./g, function (match) {
|
||||
return match[1].toUpperCase()
|
||||
})
|
||||
}
|
||||
|
||||
// TODO Remove for 1.0
|
||||
const checkForDeprecatedOptions = function (options) {
|
||||
if (!options) return ''
|
||||
|
||||
let keysToCheck = Object.keys(options)
|
||||
if (options.webPreferences) {
|
||||
keysToCheck = keysToCheck.concat(Object.keys(options.webPreferences))
|
||||
}
|
||||
|
||||
// Check options for keys with hyphens in them
|
||||
let deprecatedKey = keysToCheck.filter(isDeprecatedKey)[0]
|
||||
if (deprecatedKey) {
|
||||
try {
|
||||
deprecate.warn(deprecatedKey, getNonDeprecatedKey(deprecatedKey))
|
||||
} catch (error) {
|
||||
// Return error message so it can be rethrown via C++
|
||||
return error.message
|
||||
}
|
||||
}
|
||||
|
||||
let webPreferenceOption
|
||||
if (options.hasOwnProperty('nodeIntegration')) {
|
||||
webPreferenceOption = 'nodeIntegration'
|
||||
} else if (options.hasOwnProperty('preload')) {
|
||||
webPreferenceOption = 'preload'
|
||||
} else if (options.hasOwnProperty('zoomFactor')) {
|
||||
webPreferenceOption = 'zoomFactor'
|
||||
}
|
||||
if (webPreferenceOption) {
|
||||
try {
|
||||
deprecate.warn(`options.${webPreferenceOption}`, `options.webPreferences.${webPreferenceOption}`)
|
||||
} catch (error) {
|
||||
// Return error message so it can be rethrown via C++
|
||||
return error.message
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
_setDeprecatedOptionsCheck(checkForDeprecatedOptions)
|
||||
|
||||
module.exports = BrowserWindow
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
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
|
|
@ -4,28 +4,4 @@ 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
|
||||
module.exports = process.atomBinding('protocol').protocol
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const EventEmitter = require('events').EventEmitter
|
||||
const bindings = process.atomBinding('session')
|
||||
const PERSIST_PREFIX = 'persist:'
|
||||
|
||||
|
@ -24,10 +23,3 @@ Object.defineProperty(exports, 'defaultSession', {
|
|||
return bindings.fromPartition('', false)
|
||||
}
|
||||
})
|
||||
|
||||
var wrapSession = function (session) {
|
||||
// session is an EventEmitter.
|
||||
Object.setPrototypeOf(session, EventEmitter.prototype)
|
||||
}
|
||||
|
||||
bindings._setWrapSession(wrapSession)
|
||||
|
|
|
@ -1,18 +1,8 @@
|
|||
const deprecate = require('electron').deprecate
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
const Tray = process.atomBinding('tray').Tray
|
||||
|
||||
Object.setPrototypeOf(Tray.prototype, 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)
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
'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')
|
||||
const sessionBinding = process.atomBinding('session')
|
||||
|
||||
let nextId = 0
|
||||
|
||||
|
@ -160,13 +160,6 @@ let wrapWebContents = function (webContents) {
|
|||
})
|
||||
})
|
||||
|
||||
// Deprecated.
|
||||
deprecate.rename(webContents, 'loadUrl', 'loadURL')
|
||||
deprecate.rename(webContents, 'getUrl', 'getURL')
|
||||
deprecate.event(webContents, 'page-title-set', 'page-title-updated', function (...args) {
|
||||
return this.emit.apply(this, ['page-title-set'].concat(args))
|
||||
})
|
||||
|
||||
webContents.printToPDF = function (options, callback) {
|
||||
var printingSetting
|
||||
printingSetting = {
|
||||
|
@ -219,8 +212,14 @@ let wrapDebugger = function (webContentsDebugger) {
|
|||
Object.setPrototypeOf(webContentsDebugger, EventEmitter.prototype)
|
||||
}
|
||||
|
||||
var wrapSession = function (session) {
|
||||
// session is an EventEmitter.
|
||||
Object.setPrototypeOf(session, EventEmitter.prototype)
|
||||
}
|
||||
|
||||
binding._setWrapWebContents(wrapWebContents)
|
||||
debuggerBinding._setWrapDebugger(wrapDebugger)
|
||||
sessionBinding._setWrapSession(wrapSession)
|
||||
|
||||
module.exports.create = function (options) {
|
||||
if (options == null) {
|
||||
|
|
|
@ -45,7 +45,7 @@ desktopCapturer.emit = function (event, name, sources) {
|
|||
results.push({
|
||||
id: source.id,
|
||||
name: source.name,
|
||||
thumbnail: source.thumbnail.toDataUrl()
|
||||
thumbnail: source.thumbnail.toDataURL()
|
||||
})
|
||||
}
|
||||
return results
|
||||
|
|
|
@ -18,10 +18,6 @@ require('../common/init')
|
|||
|
||||
var globalPaths = Module.globalPaths
|
||||
|
||||
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
||||
globalPaths.push(path.join(__dirname, 'api'))
|
||||
}
|
||||
|
||||
// Expose public APIs.
|
||||
globalPaths.push(path.join(__dirname, 'api', 'exports'))
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ var CrashReporter = (function () {
|
|||
function CrashReporter () {}
|
||||
|
||||
CrashReporter.prototype.start = function (options) {
|
||||
var app, args, autoSubmit, companyName, deprecate, env, extra, ignoreSystemCrashHandler, start, submitURL
|
||||
var app, args, autoSubmit, companyName, env, extra, ignoreSystemCrashHandler, start, submitURL
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
|
@ -21,14 +21,6 @@ var CrashReporter = (function () {
|
|||
ignoreSystemCrashHandler = options.ignoreSystemCrashHandler
|
||||
extra = options.extra
|
||||
|
||||
// Deprecated.
|
||||
deprecate = electron.deprecate
|
||||
if (options.submitUrl) {
|
||||
if (submitURL == null) {
|
||||
submitURL = options.submitUrl
|
||||
}
|
||||
deprecate.warn('submitUrl', 'submitURL')
|
||||
}
|
||||
app = (process.type === 'browser' ? electron : electron.remote).app
|
||||
if (this.productName == null) {
|
||||
this.productName = app.getName()
|
||||
|
@ -52,12 +44,10 @@ var CrashReporter = (function () {
|
|||
extra._version = app.getVersion()
|
||||
}
|
||||
if (companyName == null) {
|
||||
deprecate.log('companyName is now a required option to crashReporter.start')
|
||||
return
|
||||
throw new Error('companyName is a required option to crashReporter.start')
|
||||
}
|
||||
if (submitURL == null) {
|
||||
deprecate.log('submitURL is now a required option to crashReporter.start')
|
||||
return
|
||||
throw new Error('submitURL is a required option to crashReporter.start')
|
||||
}
|
||||
start = () => {
|
||||
binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra)
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
// Do not expose the internal modules to `require`.
|
||||
const hideInternalModules = function () {
|
||||
var globalPaths = require('module').globalPaths
|
||||
if (globalPaths.length === 3) {
|
||||
// Remove the "common/api/lib" and "browser-or-renderer/api/lib".
|
||||
return globalPaths.splice(0, 2)
|
||||
}
|
||||
}
|
||||
|
||||
// Attaches properties to |exports|.
|
||||
exports.defineProperties = function (exports) {
|
||||
return Object.defineProperties(exports, {
|
||||
hideInternalModules: {
|
||||
enumerable: true,
|
||||
value: hideInternalModules
|
||||
},
|
||||
|
||||
// Common modules, please sort with alphabet order.
|
||||
clipboard: {
|
||||
// Must be enumerable, otherwise it woulde be invisible to remote module.
|
||||
|
@ -29,12 +15,6 @@ exports.defineProperties = function (exports) {
|
|||
return require('../crash-reporter')
|
||||
}
|
||||
},
|
||||
deprecations: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../deprecations')
|
||||
}
|
||||
},
|
||||
nativeImage: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
|
@ -58,6 +38,11 @@ exports.defineProperties = function (exports) {
|
|||
get: function () {
|
||||
return require('../deprecate')
|
||||
}
|
||||
},
|
||||
deprecations: {
|
||||
get: function () {
|
||||
return require('../deprecations')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1 @@
|
|||
const deprecate = require('electron').deprecate
|
||||
const nativeImage = process.atomBinding('native_image')
|
||||
|
||||
// Deprecated.
|
||||
deprecate.rename(nativeImage, 'createFromDataUrl', 'createFromDataURL')
|
||||
|
||||
module.exports = nativeImage
|
||||
module.exports = process.atomBinding('native_image')
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
const path = require('path')
|
||||
const timers = require('timers')
|
||||
const Module = require('module')
|
||||
|
||||
process.atomBinding = function (name) {
|
||||
try {
|
||||
|
@ -12,11 +10,6 @@ process.atomBinding = function (name) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
||||
// Add common/api/lib to module search paths.
|
||||
Module.globalPaths.push(path.join(__dirname, 'api'))
|
||||
}
|
||||
|
||||
// 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
|
||||
// callbacks wouldn't be called until something else activated the uv loop,
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
const ipcRenderer = require('electron').ipcRenderer
|
||||
const deprecate = require('electron').deprecate
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
|
||||
// This module is deprecated, we mirror everything from ipcRenderer.
|
||||
deprecate.warn('ipc module', 'require("electron").ipcRenderer')
|
||||
|
||||
// Routes events of ipcRenderer.
|
||||
var ipc = new EventEmitter()
|
||||
|
||||
ipcRenderer.emit = function (channel, event, ...args) {
|
||||
ipc.emit.apply(ipc, [channel].concat(args))
|
||||
return EventEmitter.prototype.emit.apply(ipcRenderer, arguments)
|
||||
}
|
||||
|
||||
// Deprecated.
|
||||
for (var method in ipcRenderer) {
|
||||
if (method.startsWith('send')) {
|
||||
ipc[method] = ipcRenderer[method]
|
||||
}
|
||||
}
|
||||
|
||||
deprecate.rename(ipc, 'sendChannel', 'send')
|
||||
|
||||
deprecate.rename(ipc, 'sendChannelSync', 'sendSync')
|
||||
|
||||
module.exports = ipc
|
|
@ -1,6 +1,5 @@
|
|||
'use strict'
|
||||
|
||||
const deprecate = require('electron').deprecate
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
|
||||
const webFrame = process.atomBinding('web_frame').webFrame
|
||||
|
@ -11,9 +10,4 @@ Object.setPrototypeOf(webFrame, EventEmitter.prototype)
|
|||
// Lots of webview would subscribe to webFrame's events.
|
||||
webFrame.setMaxListeners(0)
|
||||
|
||||
// Deprecated.
|
||||
deprecate.rename(webFrame, 'registerUrlSchemeAsSecure', 'registerURLSchemeAsSecure')
|
||||
deprecate.rename(webFrame, 'registerUrlSchemeAsBypassingCSP', 'registerURLSchemeAsBypassingCSP')
|
||||
deprecate.rename(webFrame, 'registerUrlSchemeAsPrivileged', 'registerURLSchemeAsPrivileged')
|
||||
|
||||
module.exports = webFrame
|
||||
|
|
|
@ -16,10 +16,6 @@ require('../common/init')
|
|||
|
||||
var globalPaths = Module.globalPaths
|
||||
|
||||
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
||||
globalPaths.push(path.join(__dirname, 'api'))
|
||||
}
|
||||
|
||||
// Expose public APIs.
|
||||
globalPaths.push(path.join(__dirname, 'api', 'exports'))
|
||||
|
||||
|
|
|
@ -85,9 +85,8 @@ window.open = function (url, frameName, features) {
|
|||
}
|
||||
options = {}
|
||||
|
||||
// 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 webPreferences = ['zoom-factor', 'zoomFactor', 'node-integration', 'nodeIntegration', 'preload']
|
||||
const ints = ['x', 'y', 'width', 'height', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'zoomFactor']
|
||||
const webPreferences = ['zoomFactor', 'nodeIntegration', 'preload']
|
||||
const disposition = 'new-window'
|
||||
|
||||
// Make sure to get rid of excessive whitespace in the property name
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
'use strict'
|
||||
|
||||
const deprecate = require('electron').deprecate
|
||||
const webFrame = require('electron').webFrame
|
||||
const remote = require('electron').remote
|
||||
const ipcRenderer = require('electron').ipcRenderer
|
||||
|
@ -432,8 +431,6 @@ var registerWebViewElement = function () {
|
|||
return internal.webContents
|
||||
}
|
||||
|
||||
// Deprecated.
|
||||
deprecate.rename(proto, 'getUrl', 'getURL')
|
||||
window.WebView = webFrame.registerEmbedderCustomElement('webview', {
|
||||
prototype: proto
|
||||
})
|
||||
|
|
|
@ -9,21 +9,10 @@ const app = remote.require('electron').app
|
|||
const BrowserWindow = remote.require('electron').BrowserWindow
|
||||
|
||||
describe('electron module', function () {
|
||||
it('allows old style require by default', function () {
|
||||
require('shell')
|
||||
})
|
||||
|
||||
it('can prevent exposing internal modules to require', function (done) {
|
||||
const electron = require('electron')
|
||||
const clipboard = require('clipboard')
|
||||
assert.equal(typeof clipboard, 'object')
|
||||
electron.hideInternalModules()
|
||||
try {
|
||||
it('does not expose internal modules to require', function () {
|
||||
assert.throws(function () {
|
||||
require('clipboard')
|
||||
} catch (err) {
|
||||
assert.equal(err.message, "Cannot find module 'clipboard'")
|
||||
done()
|
||||
}
|
||||
}, /Cannot find module 'clipboard'/)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -880,24 +880,4 @@ describe('browser-window module', function () {
|
|||
w.loadURL(server.url)
|
||||
})
|
||||
})
|
||||
|
||||
describe('deprecated options', function () {
|
||||
it('throws a deprecation error for option keys using hyphens instead of camel case', function () {
|
||||
assert.throws(function () {
|
||||
return new BrowserWindow({'min-width': 500})
|
||||
}, 'min-width is deprecated. Use minWidth instead.')
|
||||
})
|
||||
|
||||
it('throws a deprecation error for webPreference keys using hyphens instead of camel case', function () {
|
||||
assert.throws(function () {
|
||||
return new BrowserWindow({webPreferences: {'node-integration': false}})
|
||||
}, 'node-integration is deprecated. Use nodeIntegration instead.')
|
||||
})
|
||||
|
||||
it('throws a deprecation error for option keys that should be set on webPreferences', function () {
|
||||
assert.throws(function () {
|
||||
return new BrowserWindow({zoomFactor: 1})
|
||||
}, 'options.zoomFactor is deprecated. Use options.webPreferences.zoomFactor instead.')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -81,12 +81,12 @@ describe('crash-reporter module', function () {
|
|||
crashReporter.start({
|
||||
companyName: 'Missing submitURL'
|
||||
})
|
||||
})
|
||||
}, /submitURL is a required option to crashReporter\.start/)
|
||||
assert.throws(function () {
|
||||
crashReporter.start({
|
||||
submitURL: 'Missing companyName'
|
||||
})
|
||||
})
|
||||
}, /companyName is a required option to crashReporter\.start/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -14,14 +14,14 @@ describe('deprecations', function () {
|
|||
messages.push(message)
|
||||
})
|
||||
|
||||
require('electron').webFrame.registerUrlSchemeAsSecure('some-scheme')
|
||||
require('electron').deprecate.log('this is deprecated')
|
||||
|
||||
assert.deepEqual(messages, ['registerUrlSchemeAsSecure is deprecated. Use registerURLSchemeAsSecure instead.'])
|
||||
assert.deepEqual(messages, ['this is deprecated'])
|
||||
})
|
||||
|
||||
it('throws an exception if no deprecation handler is specified', function () {
|
||||
assert.throws(function () {
|
||||
require('electron').webFrame.registerUrlSchemeAsPrivileged('some-scheme')
|
||||
}, 'registerUrlSchemeAsPrivileged is deprecated. Use registerURLSchemeAsPrivileged instead.')
|
||||
require('electron').deprecate.log('this is deprecated')
|
||||
}, /this is deprecated/)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -17,7 +17,7 @@ describe('asar package', function () {
|
|||
it('does not leak fd', function () {
|
||||
var readCalls = 1
|
||||
while (readCalls <= 10000) {
|
||||
fs.readFileSync(path.join(process.resourcesPath, 'electron.asar', 'renderer', 'api', 'ipc.js'))
|
||||
fs.readFileSync(path.join(process.resourcesPath, 'electron.asar', 'renderer', 'api', 'ipc-renderer.js'))
|
||||
readCalls++
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue