refactor: make electron::api::BaseWindow fields private (#46689)

refactor: make electron::api::BaseWindow fields private
This commit is contained in:
Charles Kerr 2025-04-22 03:19:11 -05:00 committed by GitHub
parent ac2c0c76fe
commit 7083419361
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View file

@ -42,7 +42,8 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype); v8::Local<v8::FunctionTemplate> prototype);
NativeWindow* window() const { return window_.get(); } const NativeWindow* window() const { return window_.get(); }
NativeWindow* window() { return window_.get(); }
protected: protected:
// Common constructor. // Common constructor.
@ -262,6 +263,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
#endif #endif
int32_t GetID() const; int32_t GetID() const;
private:
// Helpers. // Helpers.
// Remove this window from parent window's |child_windows_|. // Remove this window from parent window's |child_windows_|.
@ -290,7 +292,6 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
// Reference to JS wrapper to prevent garbage collection. // Reference to JS wrapper to prevent garbage collection.
v8::Global<v8::Value> self_ref_; v8::Global<v8::Value> self_ref_;
private:
base::WeakPtrFactory<BaseWindow> weak_factory_{this}; base::WeakPtrFactory<BaseWindow> weak_factory_{this};
}; };

View file

@ -36,7 +36,7 @@ BrowserWindow::BrowserWindow(gin::Arguments* args,
std::string color; std::string color;
if (options.Get(options::kBackgroundColor, &color)) { if (options.Get(options::kBackgroundColor, &color)) {
web_preferences.SetHidden(options::kBackgroundColor, color); web_preferences.SetHidden(options::kBackgroundColor, color);
} else if (window_->IsTranslucent()) { } else if (window()->IsTranslucent()) {
// If the BrowserWindow is transparent or a vibrancy type has been set, // If the BrowserWindow is transparent or a vibrancy type has been set,
// also propagate transparency to the WebContents unless a separate // also propagate transparency to the WebContents unless a separate
// backgroundColor has been set. // backgroundColor has been set.
@ -67,7 +67,7 @@ BrowserWindow::BrowserWindow(gin::Arguments* args,
gin::Handle<WebContentsView> web_contents_view = gin::Handle<WebContentsView> web_contents_view =
WebContentsView::Create(isolate, web_preferences); WebContentsView::Create(isolate, web_preferences);
DCHECK(web_contents_view.get()); DCHECK(web_contents_view.get());
window_->AddDraggableRegionProvider(web_contents_view.get()); window()->AddDraggableRegionProvider(web_contents_view.get());
web_contents_view_.Reset(isolate, web_contents_view.ToV8()); web_contents_view_.Reset(isolate, web_contents_view.ToV8());
// Save a reference of the WebContents. // Save a reference of the WebContents.
@ -209,7 +209,7 @@ void BrowserWindow::UpdateWindowControlsOverlay(
void BrowserWindow::CloseImmediately() { void BrowserWindow::CloseImmediately() {
// Close all child windows before closing current window. // Close all child windows before closing current window.
v8::HandleScope handle_scope(isolate()); v8::HandleScope handle_scope(isolate());
for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) { for (v8::Local<v8::Value> value : GetChildWindows()) {
gin::Handle<BrowserWindow> child; gin::Handle<BrowserWindow> child;
if (gin::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty()) if (gin::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty())
child->window()->CloseImmediately(); child->window()->CloseImmediately();