refactor: move set_owned_by_client calls to base View (#22739)

* refactor: move set_owned_by_client() to WebContentsView

* refactor: do set_owned_by_client() in View
This commit is contained in:
Cheng Zhao 2020-03-20 15:41:41 +09:00 committed by GitHub
parent aa15a2cc03
commit 42f138282f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 18 deletions

View file

@ -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_;

View file

@ -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());

View file

@ -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();
}

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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);