Browse Source

fix: don't expose view APIs when not enabled (#14312)

Milan Burda 6 years ago
parent
commit
edd1eaee5c
2 changed files with 21 additions and 5 deletions
  1. 9 0
      atom/common/api/features.cc
  2. 12 5
      lib/browser/api/module-list.js

+ 9 - 0
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<v8::Object> exports,
                 v8::Local<v8::Value> unused,
                 v8::Local<v8::Context> context,
@@ -49,6 +57,7 @@ void Initialize(v8::Local<v8::Object> exports,
   dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled);
   dict.SetMethod("isFakeLocationProviderEnabled",
                  &IsFakeLocationProviderEnabled);
+  dict.SetMethod("isViewApiEnabled", &IsViewApiEnabled);
 }
 
 }  // namespace

+ 12 - 5
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'}
+  )
+}