Merge pull request #5373 from electron/remove-deprecated-apis

Remove deprecated apis
This commit is contained in:
Cheng Zhao 2016-05-09 19:16:38 +09:00
commit e139012f9a
29 changed files with 38 additions and 454 deletions

View file

@ -52,11 +52,6 @@ namespace api {
namespace { namespace {
// This function is implemented in JavaScript
using DeprecatedOptionsCheckCallback =
base::Callback<std::string(v8::Local<v8::Value>)>;
DeprecatedOptionsCheckCallback g_deprecated_options_check;
void OnCapturePageDone( void OnCapturePageDone(
v8::Isolate* isolate, v8::Isolate* isolate,
const base::Callback<void(const gfx::Image&)>& callback, const base::Callback<void(const gfx::Image&)>& callback,
@ -66,52 +61,6 @@ void OnCapturePageDone(
callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap)); 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. // Converts binary data to Buffer.
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) { v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), 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) { 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. // Use options.webPreferences to create WebContents.
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate); mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences); 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. // Copy the backgroundColor to webContents.
v8::Local<v8::Value> value;
if (options.Get(options::kBackgroundColor, &value)) if (options.Get(options::kBackgroundColor, &value))
web_preferences.Set(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); 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); return new Window(isolate, options);
} }
@ -822,10 +753,6 @@ v8::Local<v8::Value> Window::From(v8::Isolate* isolate,
return v8::Null(isolate); return v8::Null(isolate);
} }
void SetDeprecatedOptionsCheck(const DeprecatedOptionsCheckCallback& callback) {
g_deprecated_options_check = callback;
}
} // namespace api } // namespace api
} // namespace atom } // namespace atom
@ -848,8 +775,6 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
mate::Dictionary dict(isolate, exports); mate::Dictionary dict(isolate, exports);
dict.Set("BrowserWindow", browser_window); dict.Set("BrowserWindow", browser_window);
dict.SetMethod("_setDeprecatedOptionsCheck",
&atom::api::SetDeprecatedOptionsCheck);
} }
} // namespace } // namespace

View file

@ -318,7 +318,6 @@ void NativeImage::BuildPrototype(
.SetMethod("toJpeg", &NativeImage::ToJPEG) .SetMethod("toJpeg", &NativeImage::ToJPEG)
.SetMethod("getNativeHandle", &NativeImage::GetNativeHandle) .SetMethod("getNativeHandle", &NativeImage::GetNativeHandle)
.SetMethod("toDataURL", &NativeImage::ToDataURL) .SetMethod("toDataURL", &NativeImage::ToDataURL)
.SetMethod("toDataUrl", &NativeImage::ToDataURL) // deprecated.
.SetMethod("isEmpty", &NativeImage::IsEmpty) .SetMethod("isEmpty", &NativeImage::IsEmpty)
.SetMethod("getSize", &NativeImage::GetSize) .SetMethod("getSize", &NativeImage::GetSize)
.SetMethod("setTemplateImage", &NativeImage::SetTemplateImage) .SetMethod("setTemplateImage", &NativeImage::SetTemplateImage)

View file

@ -52,7 +52,3 @@ Don't attach to current console session.
## `ELECTRON_FORCE_WINDOW_MENU_BAR` _Linux_ ## `ELECTRON_FORCE_WINDOW_MENU_BAR` _Linux_
Don't use global menu bar on 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')`.

View file

@ -61,25 +61,6 @@ const {app, BrowserWindow} = require('electron')
However if you are using plain JavaScript, you have to wait until Chrome fully However if you are using plain JavaScript, you have to wait until Chrome fully
supports ES6. 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 [gui]: https://en.wikipedia.org/wiki/Graphical_user_interface
[destructuring-assignment]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment [destructuring-assignment]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
[issue-387]: https://github.com/electron/electron/issues/387 [issue-387]: https://github.com/electron/electron/issues/387

View file

@ -18,7 +18,6 @@
'lib/browser/api/dialog.js', 'lib/browser/api/dialog.js',
'lib/browser/api/exports/electron.js', 'lib/browser/api/exports/electron.js',
'lib/browser/api/global-shortcut.js', 'lib/browser/api/global-shortcut.js',
'lib/browser/api/ipc.js',
'lib/browser/api/ipc-main.js', 'lib/browser/api/ipc-main.js',
'lib/browser/api/menu.js', 'lib/browser/api/menu.js',
'lib/browser/api/menu-item.js', 'lib/browser/api/menu-item.js',
@ -58,7 +57,6 @@
'lib/renderer/web-view/web-view-constants.js', 'lib/renderer/web-view/web-view-constants.js',
'lib/renderer/api/desktop-capturer.js', 'lib/renderer/api/desktop-capturer.js',
'lib/renderer/api/exports/electron.js', 'lib/renderer/api/exports/electron.js',
'lib/renderer/api/ipc.js',
'lib/renderer/api/ipc-renderer.js', 'lib/renderer/api/ipc-renderer.js',
'lib/renderer/api/remote.js', 'lib/renderer/api/remote.js',
'lib/renderer/api/screen.js', 'lib/renderer/api/screen.js',

View file

@ -1,7 +1,6 @@
'use strict' 'use strict'
const electron = require('electron') const {Menu} = require('electron')
const {deprecate, session, Menu} = electron
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const bindings = process.atomBinding('app') const bindings = process.atomBinding('app')
@ -63,61 +62,10 @@ for (i = 0, len = ref1.length; i < len; i++) {
fn(ref1[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. // Wrappers for native classes.
var wrapDownloadItem = function (downloadItem) { var wrapDownloadItem = function (downloadItem) {
// downloadItem is an EventEmitter. // downloadItem is an EventEmitter.
Object.setPrototypeOf(downloadItem, EventEmitter.prototype) 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) downloadItemBindings._setWrapDownloadItem(wrapDownloadItem)

View file

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

View file

@ -1,9 +1,8 @@
'use strict' 'use strict'
const ipcMain = require('electron').ipcMain const ipcMain = require('electron').ipcMain
const deprecate = require('electron').deprecate
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const {BrowserWindow, _setDeprecatedOptionsCheck} = process.atomBinding('window') const {BrowserWindow} = process.atomBinding('window')
Object.setPrototypeOf(BrowserWindow.prototype, EventEmitter.prototype) 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. // Change window title to page title.
this.webContents.on('page-title-updated', (event, title) => { this.webContents.on('page-title-updated', (event, title) => {
// The page-title-updated event is not emitted immediately (see #3645), so // 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. // Notify the creation of the window.
app.emit('browser-window-created', {}, this) 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', { Object.defineProperty(this, 'devToolsWebContents', {
enumerable: true, enumerable: true,
configurable: false, configurable: false,
@ -196,84 +179,4 @@ BrowserWindow.prototype.inspectServiceWorker = function () {
return this.webContents.inspectServiceWorker() 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 module.exports = BrowserWindow

View file

@ -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

View file

@ -4,28 +4,4 @@ if (!app.isReady()) {
throw new Error('Can not initialize protocol module before app is ready') throw new Error('Can not initialize protocol module before app is ready')
} }
const protocol = process.atomBinding('protocol').protocol module.exports = 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

@ -1,4 +1,3 @@
const EventEmitter = require('events').EventEmitter
const bindings = process.atomBinding('session') const bindings = process.atomBinding('session')
const PERSIST_PREFIX = 'persist:' const PERSIST_PREFIX = 'persist:'
@ -24,10 +23,3 @@ Object.defineProperty(exports, 'defaultSession', {
return bindings.fromPartition('', false) return bindings.fromPartition('', false)
} }
}) })
var wrapSession = function (session) {
// session is an EventEmitter.
Object.setPrototypeOf(session, EventEmitter.prototype)
}
bindings._setWrapSession(wrapSession)

View file

@ -1,18 +1,8 @@
const deprecate = require('electron').deprecate
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const Tray = process.atomBinding('tray').Tray const Tray = process.atomBinding('tray').Tray
Object.setPrototypeOf(Tray.prototype, EventEmitter.prototype) 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) { Tray.prototype.setContextMenu = function (menu) {
this._setContextMenu(menu) this._setContextMenu(menu)

View file

@ -1,13 +1,13 @@
'use strict' 'use strict'
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const deprecate = require('electron').deprecate
const ipcMain = require('electron').ipcMain const ipcMain = require('electron').ipcMain
const NavigationController = require('electron').NavigationController const NavigationController = require('electron').NavigationController
const Menu = require('electron').Menu const Menu = require('electron').Menu
const binding = process.atomBinding('web_contents') const binding = process.atomBinding('web_contents')
const debuggerBinding = process.atomBinding('debugger') const debuggerBinding = process.atomBinding('debugger')
const sessionBinding = process.atomBinding('session')
let nextId = 0 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) { webContents.printToPDF = function (options, callback) {
var printingSetting var printingSetting
printingSetting = { printingSetting = {
@ -219,8 +212,14 @@ let wrapDebugger = function (webContentsDebugger) {
Object.setPrototypeOf(webContentsDebugger, EventEmitter.prototype) Object.setPrototypeOf(webContentsDebugger, EventEmitter.prototype)
} }
var wrapSession = function (session) {
// session is an EventEmitter.
Object.setPrototypeOf(session, EventEmitter.prototype)
}
binding._setWrapWebContents(wrapWebContents) binding._setWrapWebContents(wrapWebContents)
debuggerBinding._setWrapDebugger(wrapDebugger) debuggerBinding._setWrapDebugger(wrapDebugger)
sessionBinding._setWrapSession(wrapSession)
module.exports.create = function (options) { module.exports.create = function (options) {
if (options == null) { if (options == null) {

View file

@ -45,7 +45,7 @@ desktopCapturer.emit = function (event, name, sources) {
results.push({ results.push({
id: source.id, id: source.id,
name: source.name, name: source.name,
thumbnail: source.thumbnail.toDataUrl() thumbnail: source.thumbnail.toDataURL()
}) })
} }
return results return results

View file

@ -18,10 +18,6 @@ require('../common/init')
var globalPaths = Module.globalPaths var globalPaths = Module.globalPaths
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
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'))

View file

@ -10,7 +10,7 @@ var CrashReporter = (function () {
function CrashReporter () {} function CrashReporter () {}
CrashReporter.prototype.start = function (options) { 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) { if (options == null) {
options = {} options = {}
} }
@ -21,14 +21,6 @@ var CrashReporter = (function () {
ignoreSystemCrashHandler = options.ignoreSystemCrashHandler ignoreSystemCrashHandler = options.ignoreSystemCrashHandler
extra = options.extra 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 app = (process.type === 'browser' ? electron : electron.remote).app
if (this.productName == null) { if (this.productName == null) {
this.productName = app.getName() this.productName = app.getName()
@ -52,12 +44,10 @@ var CrashReporter = (function () {
extra._version = app.getVersion() extra._version = app.getVersion()
} }
if (companyName == null) { if (companyName == null) {
deprecate.log('companyName is now a required option to crashReporter.start') throw new Error('companyName is a required option to crashReporter.start')
return
} }
if (submitURL == null) { if (submitURL == null) {
deprecate.log('submitURL is now a required option to crashReporter.start') throw new Error('submitURL is a required option to crashReporter.start')
return
} }
start = () => { start = () => {
binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra) binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra)

View file

@ -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|. // Attaches properties to |exports|.
exports.defineProperties = function (exports) { exports.defineProperties = function (exports) {
return Object.defineProperties(exports, { return Object.defineProperties(exports, {
hideInternalModules: {
enumerable: true,
value: hideInternalModules
},
// Common modules, please sort with alphabet order. // Common modules, please sort with alphabet order.
clipboard: { clipboard: {
// Must be enumerable, otherwise it woulde be invisible to remote module. // Must be enumerable, otherwise it woulde be invisible to remote module.
@ -29,12 +15,6 @@ exports.defineProperties = function (exports) {
return require('../crash-reporter') return require('../crash-reporter')
} }
}, },
deprecations: {
enumerable: true,
get: function () {
return require('../deprecations')
}
},
nativeImage: { nativeImage: {
enumerable: true, enumerable: true,
get: function () { get: function () {
@ -58,6 +38,11 @@ exports.defineProperties = function (exports) {
get: function () { get: function () {
return require('../deprecate') return require('../deprecate')
} }
},
deprecations: {
get: function () {
return require('../deprecations')
}
} }
}) })
} }

View file

@ -1,7 +1 @@
const deprecate = require('electron').deprecate module.exports = process.atomBinding('native_image')
const nativeImage = process.atomBinding('native_image')
// Deprecated.
deprecate.rename(nativeImage, 'createFromDataUrl', 'createFromDataURL')
module.exports = nativeImage

View file

@ -1,6 +1,4 @@
const path = require('path')
const timers = require('timers') const timers = require('timers')
const Module = require('module')
process.atomBinding = function (name) { process.atomBinding = function (name) {
try { 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 // 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,

View file

@ -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

View file

@ -1,6 +1,5 @@
'use strict' 'use strict'
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
@ -11,9 +10,4 @@ Object.setPrototypeOf(webFrame, 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.
deprecate.rename(webFrame, 'registerUrlSchemeAsSecure', 'registerURLSchemeAsSecure')
deprecate.rename(webFrame, 'registerUrlSchemeAsBypassingCSP', 'registerURLSchemeAsBypassingCSP')
deprecate.rename(webFrame, 'registerUrlSchemeAsPrivileged', 'registerURLSchemeAsPrivileged')
module.exports = webFrame module.exports = webFrame

View file

@ -16,10 +16,6 @@ require('../common/init')
var globalPaths = Module.globalPaths var globalPaths = Module.globalPaths
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
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'))

View file

@ -85,9 +85,8 @@ window.open = function (url, frameName, features) {
} }
options = {} options = {}
// TODO remove hyphenated options in both of the following arrays for 1.0 const ints = ['x', 'y', 'width', 'height', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'zoomFactor']
const ints = ['x', 'y', 'width', 'height', 'min-width', 'minWidth', 'max-width', 'maxWidth', 'min-height', 'minHeight', 'max-height', 'maxHeight', 'zoom-factor', 'zoomFactor'] const webPreferences = ['zoomFactor', 'nodeIntegration', 'preload']
const webPreferences = ['zoom-factor', 'zoomFactor', 'node-integration', 'nodeIntegration', 'preload']
const disposition = 'new-window' const disposition = 'new-window'
// Make sure to get rid of excessive whitespace in the property name // Make sure to get rid of excessive whitespace in the property name

View file

@ -1,6 +1,5 @@
'use strict' 'use strict'
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
@ -432,8 +431,6 @@ var registerWebViewElement = function () {
return internal.webContents return internal.webContents
} }
// Deprecated.
deprecate.rename(proto, 'getUrl', 'getURL')
window.WebView = webFrame.registerEmbedderCustomElement('webview', { window.WebView = webFrame.registerEmbedderCustomElement('webview', {
prototype: proto prototype: proto
}) })

View file

@ -9,21 +9,10 @@ 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('does not expose internal modules to require', function () {
require('shell') assert.throws(function () {
})
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 {
require('clipboard') require('clipboard')
} catch (err) { }, /Cannot find module 'clipboard'/)
assert.equal(err.message, "Cannot find module 'clipboard'")
done()
}
}) })
}) })

View file

@ -880,24 +880,4 @@ describe('browser-window module', function () {
w.loadURL(server.url) 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.')
})
})
}) })

View file

@ -81,12 +81,12 @@ describe('crash-reporter module', function () {
crashReporter.start({ crashReporter.start({
companyName: 'Missing submitURL' companyName: 'Missing submitURL'
}) })
}) }, /submitURL is a required option to crashReporter\.start/)
assert.throws(function () { assert.throws(function () {
crashReporter.start({ crashReporter.start({
submitURL: 'Missing companyName' submitURL: 'Missing companyName'
}) })
}) }, /companyName is a required option to crashReporter\.start/)
}) })
}) })
}) })

View file

@ -14,14 +14,14 @@ describe('deprecations', function () {
messages.push(message) 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 () { it('throws an exception if no deprecation handler is specified', function () {
assert.throws(function () { assert.throws(function () {
require('electron').webFrame.registerUrlSchemeAsPrivileged('some-scheme') require('electron').deprecate.log('this is deprecated')
}, 'registerUrlSchemeAsPrivileged is deprecated. Use registerURLSchemeAsPrivileged instead.') }, /this is deprecated/)
}) })
}) })

View file

@ -17,7 +17,7 @@ describe('asar package', function () {
it('does not leak fd', function () { it('does not leak fd', function () {
var readCalls = 1 var readCalls = 1
while (readCalls <= 10000) { 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++ readCalls++
} }
}) })