Skip to content

Commit

Permalink
refactor: move set_owned_by_client calls to base View (#22739)
Browse files Browse the repository at this point in the history
* refactor: move set_owned_by_client() to WebContentsView

* refactor: do set_owned_by_client() in View
  • Loading branch information
zcbenz committed Mar 20, 2020
1 parent aa15a2c commit 42f1382
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 18 deletions.
6 changes: 3 additions & 3 deletions shell/browser/api/electron_api_view.cc
Expand Up @@ -12,12 +12,12 @@ namespace electron {

namespace api {

View::View(views::View* view) : view_(view) {}

View::View() : view_(new views::View()) {
View::View(views::View* view) : view_(view) {
view_->set_owned_by_client();
}

View::View() : View(new views::View()) {}

View::~View() {
if (delete_view_)
delete view_;
Expand Down
10 changes: 4 additions & 6 deletions shell/browser/api/electron_api_web_contents_view.cc
Expand Up @@ -53,12 +53,10 @@ WebContentsView::WebContentsView(v8::Isolate* isolate,
#endif
web_contents_(isolate, web_contents->GetWrapper()),
api_web_contents_(web_contents.get()) {
#if defined(OS_MACOSX)
// On macOS a View is created to wrap the NSView, and its lifetime is managed
// by us.
view()->set_owned_by_client();
#else
// On other platforms the View is managed by InspectableWebContents.
#if !defined(OS_MACOSX)
// On macOS the View is a newly-created |DelayedNativeViewHost| and it is our
// responsibility to delete it. On other platforms the View is created and
// managed by InspectableWebContents.
set_delete_view(false);
#endif
WebContentsViewRelay::CreateForWebContents(web_contents->web_contents());
Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/views/electron_api_button.cc
Expand Up @@ -13,7 +13,6 @@ namespace electron {
namespace api {

Button::Button(views::Button* impl) : View(impl) {
view()->set_owned_by_client();
// Make the button focusable as per the platform.
button()->SetFocusForPlatform();
}
Expand Down
4 changes: 1 addition & 3 deletions shell/browser/api/views/electron_api_resize_area.cc
Expand Up @@ -12,9 +12,7 @@ namespace electron {

namespace api {

ResizeArea::ResizeArea() : View(new views::ResizeArea(this)) {
view()->set_owned_by_client();
}
ResizeArea::ResizeArea() : View(new views::ResizeArea(this)) {}

ResizeArea::~ResizeArea() {}

Expand Down
4 changes: 1 addition & 3 deletions shell/browser/api/views/electron_api_text_field.cc
Expand Up @@ -13,9 +13,7 @@ namespace electron {

namespace api {

TextField::TextField() : View(new views::Textfield()) {
view()->set_owned_by_client();
}
TextField::TextField() : View(new views::Textfield()) {}

TextField::~TextField() {}

Expand Down
2 changes: 0 additions & 2 deletions shell/browser/ui/views/inspectable_web_contents_view_views.cc
Expand Up @@ -87,8 +87,6 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews(
devtools_visible_(false),
devtools_window_delegate_(nullptr),
title_(base::ASCIIToUTF16("Developer Tools")) {
set_owned_by_client();

if (!inspectable_web_contents_->IsGuest() &&
inspectable_web_contents_->GetWebContents()->GetNativeView()) {
views::WebView* contents_web_view = new views::WebView(nullptr);
Expand Down

0 comments on commit 42f1382

Please sign in to comment.