Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: potential crash calling tray.popUpContextMenu() #39231

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion shell/browser/api/electron_api_tray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ void Tray::PopUpContextMenu(gin::Arguments* args) {
}
}
}
tray_icon_->PopUpContextMenu(pos, menu.IsEmpty() ? nullptr : menu->model());

tray_icon_->PopUpContextMenu(
pos, menu.IsEmpty() ? nullptr : menu->model()->GetWeakPtr());
}

void Tray::CloseContextMenu() {
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/ui/tray_icon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
void TrayIcon::Focus() {}

void TrayIcon::PopUpContextMenu(const gfx::Point& pos,
raw_ptr<ElectronMenuModel> menu_model) {}
base::WeakPtr<ElectronMenuModel> menu_model) {}

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 24 in shell/browser/ui/tray_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.cc#L24

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

void TrayIcon::CloseContextMenu() {}

Expand Down
2 changes: 1 addition & 1 deletion shell/browser/ui/tray_icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

// Popups the menu.
virtual void PopUpContextMenu(const gfx::Point& pos,
raw_ptr<ElectronMenuModel> menu_model);
base::WeakPtr<ElectronMenuModel> menu_model);

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 92 in shell/browser/ui/tray_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon.h#L92

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

virtual void CloseContextMenu();

Expand Down
6 changes: 3 additions & 3 deletions shell/browser/ui/tray_icon_cocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
std::string GetTitle() override;
void SetIgnoreDoubleClickEvents(bool ignore) override;
bool GetIgnoreDoubleClickEvents() override;
void PopUpOnUI(ElectronMenuModel* menu_model);
void PopUpOnUI(base::WeakPtr<ElectronMenuModel> menu_model);
void PopUpContextMenu(const gfx::Point& pos,
raw_ptr<ElectronMenuModel>) override;
base::WeakPtr<ElectronMenuModel> menu_model) override;

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 37 in shell/browser/ui/tray_icon_cocoa.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.h#L35-L37

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
 +  void CloseContextMenu() override;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
+   void CloseContextMenu() override;
+   void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu
void CloseContextMenu() override;
void SetContextMenu(raw_ptr<ElectronMenuModel>) override;
void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
gfx::Rect GetBounds() override;

private:
Expand Down
20 changes: 12 additions & 8 deletions shell/browser/ui/tray_icon_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea_];
}

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

Check failure on line 78 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

- (void)removeItem {
// Turn off tracking events to prevent crash.
Expand All @@ -83,6 +83,11 @@
[self removeTrackingArea:trackingArea_];
trackingArea_ = nil;
}

// Ensure any open menu is closed.
if ([statusItem_ menu])
[[statusItem_ menu] cancelTracking];

[[NSStatusBar systemStatusBar] removeStatusItem:statusItem_];
[self removeFromSuperview];
statusItem_ = nil;
Expand Down Expand Up @@ -228,7 +233,6 @@
if (menuController_ && ![menuController_ isMenuOpen]) {
// Ensure the UI can update while the menu is fading out.
base::ScopedPumpMessagesInPrivateModes pump_private;

[[statusItem_ button] performClick:self];
}
}
Expand Down Expand Up @@ -354,18 +358,18 @@
return [status_item_view_ getIgnoreDoubleClickEvents];
}

void TrayIconCocoa::PopUpOnUI(ElectronMenuModel* menu_model) {
[status_item_view_ popUpContextMenu:menu_model];
void TrayIconCocoa::PopUpOnUI(base::WeakPtr<ElectronMenuModel> menu_model) {
[status_item_view_ popUpContextMenu:menu_model.get()];
}

void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
raw_ptr<ElectronMenuModel> menu_model) {
void TrayIconCocoa::PopUpContextMenu(
const gfx::Point& pos,
base::WeakPtr<ElectronMenuModel> menu_model) {
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&TrayIconCocoa::PopUpOnUI, weak_factory_.GetWeakPtr(),
base::Unretained(menu_model)));
FROM_HERE, base::BindOnce(&TrayIconCocoa::PopUpOnUI,
weak_factory_.GetWeakPtr(), menu_model));
}

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 372 in shell/browser/ui/tray_icon_cocoa.mm

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L371-L372

Patch Conflict
Raw output
++<<<<<<< HEAD
 +void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
 +                                     ElectronMenuModel* menu_model) {
++=======
+ void TrayIconCocoa::PopUpContextMenu(
+     const gfx::Point& pos,
+     base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu
void TrayIconCocoa::CloseContextMenu() {
[status_item_view_ closeContextMenu];
}
Expand Down
14 changes: 9 additions & 5 deletions shell/browser/ui/win/notify_icon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
return;
} else if (!double_button_click) { // single right click
if (menu_model_)
PopUpContextMenu(gfx::Point(), menu_model_);
PopUpContextMenu(gfx::Point(), menu_model_->GetWeakPtr());
else
NotifyRightClicked(bounds, modifiers);
}
Expand Down Expand Up @@ -191,7 +191,7 @@
}

void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
raw_ptr<ElectronMenuModel> menu_model) {
base::WeakPtr<ElectronMenuModel> menu_model) {

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 194 in shell/browser/ui/win/notify_icon.cc

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.cc#L194

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                                  ElectronMenuModel* menu_model) {
++=======
+                                   base::WeakPtr<ElectronMenuModel> menu_model) {
++>>>>>>> fix: potential crash calling tray.popUpContextMenu
// Returns if context menu isn't set.
if (menu_model == nullptr && menu_model_ == nullptr)
return;
Expand All @@ -209,9 +209,13 @@
if (pos.IsOrigin())
rect.set_origin(display::Screen::GetScreen()->GetCursorScreenPoint());

menu_runner_ = std::make_unique<views::MenuRunner>(
menu_model != nullptr ? menu_model : menu_model_,
views::MenuRunner::HAS_MNEMONICS);
if (menu_model) {
menu_runner_ = std::make_unique<views::MenuRunner>(
menu_model.get(), views::MenuRunner::HAS_MNEMONICS);
} else {
menu_runner_ = std::make_unique<views::MenuRunner>(
menu_model_, views::MenuRunner::HAS_MNEMONICS);
}
menu_runner_->RunMenuAt(nullptr, nullptr, rect,
views::MenuAnchorPosition::kTopLeft,
ui::MENU_SOURCE_MOUSE);
Expand Down
3 changes: 2 additions & 1 deletion shell/browser/ui/win/notify_icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>

#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "base/win/scoped_gdi_object.h"
#include "shell/browser/ui/tray_icon.h"
#include "shell/browser/ui/win/notify_icon_host.h"
Expand Down Expand Up @@ -65,7 +66,7 @@
void RemoveBalloon() override;
void Focus() override;
void PopUpContextMenu(const gfx::Point& pos,
raw_ptr<ElectronMenuModel> menu_model) override;
base::WeakPtr<ElectronMenuModel> menu_model) override;

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 24-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu

Check failure on line 69 in shell/browser/ui/win/notify_icon.h

View check run for this annotation

trop / Backportable? - 25-x-y

shell/browser/ui/win/notify_icon.h#L69

Patch Conflict
Raw output
++<<<<<<< HEAD
 +                        ElectronMenuModel* menu_model) override;
++=======
+                         base::WeakPtr<ElectronMenuModel> menu_model) override;
++>>>>>>> fix: potential crash calling tray.popUpContextMenu
void CloseContextMenu() override;
void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) override;
gfx::Rect GetBounds() override;
Expand Down