diff --git a/atom/browser/api/atom_api_url_request.cc b/atom/browser/api/atom_api_url_request.cc index 88582708c052..51c7969e31f4 100644 --- a/atom/browser/api/atom_api_url_request.cc +++ b/atom/browser/api/atom_api_url_request.cc @@ -3,7 +3,9 @@ // found in the LICENSE file. #include "atom/browser/api/atom_api_url_request.h" + #include + #include "atom/browser/api/atom_api_session.h" #include "atom/browser/net/atom_url_request.h" #include "atom/common/api/event_emitter_caller.h" diff --git a/atom/browser/api/atom_api_url_request.h b/atom/browser/api/atom_api_url_request.h index 372ac98ac657..3b5e667d7590 100644 --- a/atom/browser/api/atom_api_url_request.h +++ b/atom/browser/api/atom_api_url_request.h @@ -7,6 +7,7 @@ #include #include + #include "atom/browser/api/event_emitter.h" #include "atom/browser/api/trackable_object.h" #include "base/memory/weak_ptr.h" diff --git a/atom/browser/api/atom_api_view.cc b/atom/browser/api/atom_api_view.cc new file mode 100644 index 000000000000..fdb63dc89fdf --- /dev/null +++ b/atom/browser/api/atom_api_view.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2018 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/api/atom_api_view.h" + +#include "native_mate/dictionary.h" + +#include "atom/common/node_includes.h" + +namespace atom { + +namespace api { + +View::View() : view_(new views::View()) { + view_->set_owned_by_client(); +} + +View::~View() {} + +// static +mate::WrappableBase* View::New(mate::Arguments* args) { + return new View(); +} + +// static +void View::BuildPrototype(v8::Isolate* isolate, + v8::Local prototype) {} + +} // namespace api + +} // namespace atom + +namespace { + +using atom::api::View; + +void Initialize(v8::Local exports, + v8::Local unused, + v8::Local context, + void* priv) { + v8::Isolate* isolate = context->GetIsolate(); + View::SetConstructor(isolate, base::Bind(&View::New)); + + mate::Dictionary constructor(isolate, + View::GetConstructor(isolate)->GetFunction()); + + mate::Dictionary dict(isolate, exports); + dict.Set("View", constructor); +} + +} // namespace + +NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_view, Initialize) diff --git a/atom/browser/api/atom_api_view.h b/atom/browser/api/atom_api_view.h new file mode 100644 index 000000000000..e60aa0329a10 --- /dev/null +++ b/atom/browser/api/atom_api_view.h @@ -0,0 +1,38 @@ +// Copyright (c) 2018 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_API_ATOM_API_VIEW_H_ +#define ATOM_BROWSER_API_ATOM_API_VIEW_H_ + +#include + +#include "atom/browser/api/event_emitter.h" +#include "ui/views/view.h" + +namespace atom { + +namespace api { + +class View : public mate::EventEmitter { + public: + static mate::WrappableBase* New(mate::Arguments* args); + + static void BuildPrototype(v8::Isolate* isolate, + v8::Local prototype); + + protected: + View(); + ~View() override; + + private: + std::unique_ptr view_; + + DISALLOW_COPY_AND_ASSIGN(View); +}; + +} // namespace api + +} // namespace atom + +#endif // ATOM_BROWSER_API_ATOM_API_VIEW_H_ diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 1f6868851476..48359d913809 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -49,6 +49,7 @@ V(atom_browser_top_level_window) \ V(atom_browser_tray) \ V(atom_browser_web_contents) \ + V(atom_browser_view) \ V(atom_browser_web_view_manager) \ V(atom_browser_window) \ V(atom_common_asar) \ diff --git a/filenames.gypi b/filenames.gypi index 43f019e945c0..205da5ebf7ec 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -38,6 +38,7 @@ 'lib/browser/api/top-level-window.js', 'lib/browser/api/touch-bar.js', 'lib/browser/api/tray.js', + 'lib/browser/api/view.js', 'lib/browser/api/web-contents.js', 'lib/browser/chrome-extension.js', 'lib/browser/desktop-capturer.js', @@ -162,6 +163,8 @@ 'atom/browser/api/atom_api_tray.h', 'atom/browser/api/atom_api_url_request.cc', 'atom/browser/api/atom_api_url_request.h', + 'atom/browser/api/atom_api_view.cc', + 'atom/browser/api/atom_api_view.h', 'atom/browser/api/atom_api_web_contents.cc', 'atom/browser/api/atom_api_web_contents.h', 'atom/browser/api/atom_api_web_contents_mac.mm', diff --git a/lib/browser/api/module-list.js b/lib/browser/api/module-list.js index 68f41b491b4c..4d534d301841 100644 --- a/lib/browser/api/module-list.js +++ b/lib/browser/api/module-list.js @@ -22,6 +22,7 @@ module.exports = [ {name: 'TopLevelWindow', file: 'top-level-window'}, {name: 'TouchBar', file: 'touch-bar'}, {name: 'Tray', file: 'tray'}, + {name: 'View', file: 'view'}, {name: 'webContents', file: 'web-contents'}, // The internal modules, invisible unless you know their names. {name: 'NavigationController', file: 'navigation-controller', private: true} diff --git a/lib/browser/api/view.js b/lib/browser/api/view.js new file mode 100644 index 000000000000..ba215aeadaa2 --- /dev/null +++ b/lib/browser/api/view.js @@ -0,0 +1,8 @@ +'use strict' + +const {EventEmitter} = require('events') +const {View} = process.atomBinding('view') + +Object.setPrototypeOf(View.prototype, EventEmitter.prototype) + +module.exports = View