From ff539c1d611475aa8a3e5514d7cefb9c0ef18953 Mon Sep 17 00:00:00 2001 From: "trop[bot]" Date: Mon, 27 Aug 2018 13:00:19 +0900 Subject: [PATCH] fix: don't expose view APIs when not enabled (#14321) --- atom/common/api/features.cc | 9 +++++++++ lib/browser/api/module-list.js | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/atom/common/api/features.cc b/atom/common/api/features.cc index c78c6897ef4e..83a95bf30ac9 100644 --- a/atom/common/api/features.cc +++ b/atom/common/api/features.cc @@ -39,6 +39,14 @@ bool IsFakeLocationProviderEnabled() { #endif } +bool IsViewApiEnabled() { +#if defined(ENABLE_VIEW_API) + return true; +#else + return false; +#endif +} + void Initialize(v8::Local exports, v8::Local unused, v8::Local context, @@ -49,6 +57,7 @@ void Initialize(v8::Local exports, dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled); dict.SetMethod("isFakeLocationProviderEnabled", &IsFakeLocationProviderEnabled); + dict.SetMethod("isViewApiEnabled", &IsViewApiEnabled); } } // namespace diff --git a/lib/browser/api/module-list.js b/lib/browser/api/module-list.js index c84a8ce29cf5..7878a8e5ec30 100644 --- a/lib/browser/api/module-list.js +++ b/lib/browser/api/module-list.js @@ -1,9 +1,9 @@ +const features = process.atomBinding('features') + // Browser side modules, please sort alphabetically. module.exports = [ {name: 'app', file: 'app'}, {name: 'autoUpdater', file: 'auto-updater'}, - {name: 'BoxLayout', file: 'box-layout'}, - {name: 'Button', file: 'button'}, {name: 'BrowserView', file: 'browser-view'}, {name: 'BrowserWindow', file: 'browser-window'}, {name: 'contentTracing', file: 'content-tracing'}, @@ -11,8 +11,6 @@ module.exports = [ {name: 'globalShortcut', file: 'global-shortcut'}, {name: 'ipcMain', file: 'ipc-main'}, {name: 'inAppPurchase', file: 'in-app-purchase'}, - {name: 'LabelButton', file: 'label-button'}, - {name: 'LayoutManager', file: 'layout-manager'}, {name: 'Menu', file: 'menu'}, {name: 'MenuItem', file: 'menu-item'}, {name: 'net', file: 'net'}, @@ -24,7 +22,6 @@ module.exports = [ {name: 'screen', file: 'screen'}, {name: 'session', file: 'session'}, {name: 'systemPreferences', file: 'system-preferences'}, - {name: 'TextField', file: 'text-field'}, {name: 'TopLevelWindow', file: 'top-level-window'}, {name: 'TouchBar', file: 'touch-bar'}, {name: 'Tray', file: 'tray'}, @@ -34,3 +31,13 @@ module.exports = [ // The internal modules, invisible unless you know their names. {name: 'NavigationController', file: 'navigation-controller', private: true} ] + +if (features.isViewApiEnabled()) { + module.exports.push( + {name: 'BoxLayout', file: 'box-layout'}, + {name: 'Button', file: 'button'}, + {name: 'LabelButton', file: 'label-button'}, + {name: 'LayoutManager', file: 'layout-manager'}, + {name: 'TextField', file: 'text-field'} + ) +}