electron_api_view.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/api/electron_api_view.h"
  5. #include "shell/common/gin_helper/dictionary.h"
  6. #include "shell/common/gin_helper/object_template_builder.h"
  7. #include "shell/common/node_includes.h"
  8. namespace electron::api {
  9. View::View(views::View* view) : view_(view) {
  10. view_->set_owned_by_client();
  11. }
  12. View::View() : View(new views::View()) {}
  13. View::~View() {
  14. if (delete_view_)
  15. delete view_;
  16. }
  17. // static
  18. gin_helper::WrappableBase* View::New(gin::Arguments* args) {
  19. auto* view = new View();
  20. view->InitWithArgs(args);
  21. return view;
  22. }
  23. // static
  24. void View::BuildPrototype(v8::Isolate* isolate,
  25. v8::Local<v8::FunctionTemplate> prototype) {
  26. prototype->SetClassName(gin::StringToV8(isolate, "View"));
  27. }
  28. } // namespace electron::api
  29. namespace {
  30. using electron::api::View;
  31. void Initialize(v8::Local<v8::Object> exports,
  32. v8::Local<v8::Value> unused,
  33. v8::Local<v8::Context> context,
  34. void* priv) {
  35. v8::Isolate* isolate = context->GetIsolate();
  36. View::SetConstructor(isolate, base::BindRepeating(&View::New));
  37. gin_helper::Dictionary constructor(
  38. isolate,
  39. View::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
  40. gin_helper::Dictionary dict(isolate, exports);
  41. dict.Set("View", constructor);
  42. }
  43. } // namespace
  44. NODE_LINKED_BINDING_CONTEXT_AWARE(electron_browser_view, Initialize)