Skip to content

Commit edd1eae

Browse files
miniakCheng Zhao
authored andcommitted
fix: don't expose view APIs when not enabled (electron#14312)
1 parent 90545bd commit edd1eae

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

atom/common/api/features.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ bool IsFakeLocationProviderEnabled() {
3939
#endif
4040
}
4141

42+
bool IsViewApiEnabled() {
43+
#if defined(ENABLE_VIEW_API)
44+
return true;
45+
#else
46+
return false;
47+
#endif
48+
}
49+
4250
void Initialize(v8::Local<v8::Object> exports,
4351
v8::Local<v8::Value> unused,
4452
v8::Local<v8::Context> context,
@@ -49,6 +57,7 @@ void Initialize(v8::Local<v8::Object> exports,
4957
dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled);
5058
dict.SetMethod("isFakeLocationProviderEnabled",
5159
&IsFakeLocationProviderEnabled);
60+
dict.SetMethod("isViewApiEnabled", &IsViewApiEnabled);
5261
}
5362

5463
} // namespace

lib/browser/api/module-list.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1+
const features = process.atomBinding('features')
2+
13
// Browser side modules, please sort alphabetically.
24
module.exports = [
35
{name: 'app', file: 'app'},
46
{name: 'autoUpdater', file: 'auto-updater'},
5-
{name: 'BoxLayout', file: 'box-layout'},
6-
{name: 'Button', file: 'button'},
77
{name: 'BrowserView', file: 'browser-view'},
88
{name: 'BrowserWindow', file: 'browser-window'},
99
{name: 'contentTracing', file: 'content-tracing'},
1010
{name: 'dialog', file: 'dialog'},
1111
{name: 'globalShortcut', file: 'global-shortcut'},
1212
{name: 'ipcMain', file: 'ipc-main'},
1313
{name: 'inAppPurchase', file: 'in-app-purchase'},
14-
{name: 'LabelButton', file: 'label-button'},
15-
{name: 'LayoutManager', file: 'layout-manager'},
1614
{name: 'Menu', file: 'menu'},
1715
{name: 'MenuItem', file: 'menu-item'},
1816
{name: 'net', file: 'net'},
@@ -24,7 +22,6 @@ module.exports = [
2422
{name: 'screen', file: 'screen'},
2523
{name: 'session', file: 'session'},
2624
{name: 'systemPreferences', file: 'system-preferences'},
27-
{name: 'TextField', file: 'text-field'},
2825
{name: 'TopLevelWindow', file: 'top-level-window'},
2926
{name: 'TouchBar', file: 'touch-bar'},
3027
{name: 'Tray', file: 'tray'},
@@ -34,3 +31,13 @@ module.exports = [
3431
// The internal modules, invisible unless you know their names.
3532
{name: 'NavigationController', file: 'navigation-controller', private: true}
3633
]
34+
35+
if (features.isViewApiEnabled()) {
36+
module.exports.push(
37+
{name: 'BoxLayout', file: 'box-layout'},
38+
{name: 'Button', file: 'button'},
39+
{name: 'LabelButton', file: 'label-button'},
40+
{name: 'LayoutManager', file: 'layout-manager'},
41+
{name: 'TextField', file: 'text-field'}
42+
)
43+
}

0 commit comments

Comments
 (0)