From 0f7c25fc63887b276d40af08050d329d23f8a99f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 24 May 2018 15:35:50 +0900 Subject: [PATCH] Put View APIs under a build flag --- atom/browser/api/atom_api_view.cc | 4 ++++ atom/browser/api/atom_api_view.h | 2 ++ atom/common/node_bindings.cc | 12 ++++++++++-- electron.gyp | 5 +++++ features.gypi | 2 ++ filenames.gypi | 18 ++++++++++++------ 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/atom/browser/api/atom_api_view.cc b/atom/browser/api/atom_api_view.cc index a79e6fa689..9094fd5476 100644 --- a/atom/browser/api/atom_api_view.cc +++ b/atom/browser/api/atom_api_view.cc @@ -23,6 +23,7 @@ View::~View() { delete view_; } +#if defined(ENABLE_VIEW_API) void View::SetLayoutManager(mate::Handle layout_manager) { layout_manager_.Reset(isolate(), layout_manager->GetWrapper()); // TODO(zcbenz): New versions of Chrome takes std::unique_ptr instead of raw @@ -41,6 +42,7 @@ void View::AddChildViewAt(mate::Handle child, size_t index) { isolate(), child->GetWrapper()); // v8::Global(args...) view()->AddChildViewAt(child->view(), index); } +#endif // static mate::WrappableBase* View::New(mate::Arguments* args) { @@ -53,10 +55,12 @@ mate::WrappableBase* View::New(mate::Arguments* args) { void View::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { prototype->SetClassName(mate::StringToV8(isolate, "View")); +#if defined(ENABLE_VIEW_API) mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("setLayoutManager", &View::SetLayoutManager) .SetMethod("addChildView", &View::AddChildView) .SetMethod("addChildViewAt", &View::AddChildViewAt); +#endif } } // namespace api diff --git a/atom/browser/api/atom_api_view.h b/atom/browser/api/atom_api_view.h index 80f17e6141..03b4e10823 100644 --- a/atom/browser/api/atom_api_view.h +++ b/atom/browser/api/atom_api_view.h @@ -23,9 +23,11 @@ class View : public mate::TrackableObject { static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); +#if defined(ENABLE_VIEW_API) void SetLayoutManager(mate::Handle layout_manager); void AddChildView(mate::Handle view); void AddChildViewAt(mate::Handle view, size_t index); +#endif views::View* view() const { return view_; } diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 8af9114de8..e939de0708 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -31,7 +31,6 @@ V(atom_browser_app) \ V(atom_browser_auto_updater) \ V(atom_browser_browser_view) \ - V(atom_browser_box_layout) \ V(atom_browser_content_tracing) \ V(atom_browser_debugger) \ V(atom_browser_desktop_capturer) \ @@ -39,7 +38,6 @@ V(atom_browser_download_item) \ V(atom_browser_global_shortcut) \ V(atom_browser_in_app_purchase) \ - V(atom_browser_layout_manager) \ V(atom_browser_menu) \ V(atom_browser_net) \ V(atom_browser_power_monitor) \ @@ -67,6 +65,10 @@ V(atom_renderer_ipc) \ V(atom_renderer_web_frame) +#define ELECTRON_VIEW_MODULES(V) \ + V(atom_browser_box_layout) \ + V(atom_browser_layout_manager) + // This is used to load built-in modules. Instead of using // __attribute__((constructor)), we call the _register_ // function for each built-in modules explicitly. This is only @@ -74,6 +76,9 @@ // implementation when calling the NODE_BUILTIN_MODULE_CONTEXT_AWARE. #define V(modname) void _register_##modname(); ELECTRON_BUILTIN_MODULES(V) +#if defined(ENABLE_VIEW_API) +ELECTRON_VIEW_MODULES(V) +#endif #undef V namespace { @@ -167,6 +172,9 @@ NodeBindings::~NodeBindings() { void NodeBindings::RegisterBuiltinModules() { #define V(modname) _register_##modname(); ELECTRON_BUILTIN_MODULES(V) +#if defined(ENABLE_VIEW_API) + ELECTRON_VIEW_MODULES(V) +#endif #undef V } diff --git a/electron.gyp b/electron.gyp index fec9239e48..b040ee1ab8 100644 --- a/electron.gyp +++ b/electron.gyp @@ -38,6 +38,11 @@ 'ENABLE_RUN_AS_NODE', ], }], # enable_run_as_node + ['enable_view_api==1', { + 'defines': [ + 'ENABLE_VIEW_API', + ], + }], # enable_view_api ], }, 'targets': [ diff --git a/features.gypi b/features.gypi index 247d828bbc..b3dca5da2c 100644 --- a/features.gypi +++ b/features.gypi @@ -5,9 +5,11 @@ 'enable_osr%': 1, # FIXME(alexeykuzmin) 'enable_pdf_viewer%': 0, # FIXME(deepak1556) 'enable_run_as_node%': 1, + 'enable_view_api%': 0, }, 'enable_osr%': '<(enable_osr)', 'enable_pdf_viewer%': '<(enable_pdf_viewer)', 'enable_run_as_node%': '<(enable_run_as_node)', + 'enable_view_api%': '<(enable_view_api)', }, } diff --git a/filenames.gypi b/filenames.gypi index 9da6d9cdff..4cecf4b896 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -13,7 +13,6 @@ 'lib/browser/api/auto-updater/auto-updater-native.js', 'lib/browser/api/auto-updater/auto-updater-win.js', 'lib/browser/api/auto-updater/squirrel-update-win.js', - 'lib/browser/api/box-layout.js', 'lib/browser/api/browser-view.js', 'lib/browser/api/browser-window.js', 'lib/browser/api/content-tracing.js', @@ -22,7 +21,6 @@ 'lib/browser/api/global-shortcut.js', 'lib/browser/api/ipc-main.js', 'lib/browser/api/in-app-purchase.js', - 'lib/browser/api/layout-manager.js', 'lib/browser/api/menu-item-roles.js', 'lib/browser/api/menu-item.js', 'lib/browser/api/menu-utils.js', @@ -115,8 +113,6 @@ 'atom/browser/api/atom_api_app.h', 'atom/browser/api/atom_api_auto_updater.cc', 'atom/browser/api/atom_api_auto_updater.h', - 'atom/browser/api/atom_api_box_layout.cc', - 'atom/browser/api/atom_api_box_layout.h', 'atom/browser/api/atom_api_browser_view.cc', 'atom/browser/api/atom_api_browser_view.h', 'atom/browser/api/atom_api_content_tracing.cc', @@ -133,8 +129,6 @@ 'atom/browser/api/atom_api_global_shortcut.h', 'atom/browser/api/atom_api_in_app_purchase.cc', 'atom/browser/api/atom_api_in_app_purchase.h', - 'atom/browser/api/atom_api_layout_manager.cc', - 'atom/browser/api/atom_api_layout_manager.h', 'atom/browser/api/atom_api_menu.cc', 'atom/browser/api/atom_api_menu.h', 'atom/browser/api/atom_api_menu_mac.h', @@ -781,6 +775,18 @@ 'atom/app/node_main.h', ], }], # enable_run_as_node + ['enable_view_api==1', { + 'js_sources': [ + 'lib/browser/api/box-layout.js', + 'lib/browser/api/layout-manager.js', + ], + 'lib_sources': [ + 'atom/browser/api/atom_api_box_layout.cc', + 'atom/browser/api/atom_api_box_layout.h', + 'atom/browser/api/atom_api_layout_manager.cc', + 'atom/browser/api/atom_api_layout_manager.h', + ], + }], # enable_view_api ['mas_build==1', { 'lib_sources': [ 'atom/browser/api/atom_api_app_mas.mm',