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

fix: potential crash calling tray.popUpContextMenu

1b1e107
Select commit
Loading
Failed to load commit list.
Merged

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

fix: potential crash calling tray.popUpContextMenu
1b1e107
Select commit
Loading
Failed to load commit list.
trop / Backportable? - 25-x-y completed Jul 31, 2023 in 3d 17h 26m 57s

Backport Failed

This PR was checked and could not be automatically backported to "25-x-y" cleanly

Details

Failed Diff:

diff --cc shell/browser/ui/tray_icon.cc
index 4415f6c9b7,7f22f3b6da..0000000000
--- a/shell/browser/ui/tray_icon.cc
+++ b/shell/browser/ui/tray_icon.cc
@@@ -21,7 -21,7 +21,11 @@@ void TrayIcon::RemoveBalloon() {
  void TrayIcon::Focus() {}
  
  void TrayIcon::PopUpContextMenu(const gfx::Point& pos,
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model) {}
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model) {}
++>>>>>>> fix: potential crash calling tray.popUpContextMenu
  
  void TrayIcon::CloseContextMenu() {}
  
diff --cc shell/browser/ui/tray_icon.h
index 6654c69ac3,85a66163b6..0000000000
--- a/shell/browser/ui/tray_icon.h
+++ b/shell/browser/ui/tray_icon.h
@@@ -89,7 -89,7 +89,11 @@@ class TrayIcon 
  
    // Popups the menu.
    virtual void PopUpContextMenu(const gfx::Point& pos,
++<<<<<<< HEAD
 +                                ElectronMenuModel* menu_model);
++=======
+                                 base::WeakPtr<ElectronMenuModel> menu_model);
++>>>>>>> fix: potential crash calling tray.popUpContextMenu
  
    virtual void CloseContextMenu();
  
diff --cc shell/browser/ui/tray_icon_cocoa.h
index 4db1114cd9,d7a7904571..0000000000
--- a/shell/browser/ui/tray_icon_cocoa.h
+++ b/shell/browser/ui/tray_icon_cocoa.h
@@@ -29,11 -32,11 +29,17 @@@ class TrayIconCocoa : public TrayIcon 
    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,
++<<<<<<< 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
    gfx::Rect GetBounds() override;
  
   private:
diff --cc shell/browser/ui/tray_icon_cocoa.mm
index 443bfefb13,9d6d6d4bd0..0000000000
--- a/shell/browser/ui/tray_icon_cocoa.mm
+++ b/shell/browser/ui/tray_icon_cocoa.mm
@@@ -78,11 -81,16 +78,16 @@@
    // Turn off tracking events to prevent crash.
    if (trackingArea_) {
      [self removeTrackingArea:trackingArea_];
 -    trackingArea_ = nil;
 +    trackingArea_.reset();
    }
+ 
+   // Ensure any open menu is closed.
+   if ([statusItem_ menu])
+     [[statusItem_ menu] cancelTracking];
+ 
    [[NSStatusBar systemStatusBar] removeStatusItem:statusItem_];
    [self removeFromSuperview];
 -  statusItem_ = nil;
 +  statusItem_.reset();
  }
  
  - (void)setImage:(NSImage*)image {
@@@ -358,16 -358,16 +362,21 @@@ bool TrayIconCocoa::GetIgnoreDoubleClic
    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()];
  }
  
++<<<<<<< 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
    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));
  }
  
  void TrayIconCocoa::CloseContextMenu() {
diff --cc shell/browser/ui/win/notify_icon.cc
index 2bbbbf2155,195589f877..0000000000
--- a/shell/browser/ui/win/notify_icon.cc
+++ b/shell/browser/ui/win/notify_icon.cc
@@@ -191,7 -191,7 +191,11 @@@ void NotifyIcon::Focus() 
  }
  
  void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
++<<<<<<< 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;
diff --cc shell/browser/ui/win/notify_icon.h
index 1568615601,ee45864292..0000000000
--- a/shell/browser/ui/win/notify_icon.h
+++ b/shell/browser/ui/win/notify_icon.h
@@@ -65,9 -66,9 +66,13 @@@ class NotifyIcon : public TrayIcon 
    void RemoveBalloon() override;
    void Focus() override;
    void PopUpContextMenu(const gfx::Point& pos,
++<<<<<<< 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;
 +  void SetContextMenu(ElectronMenuModel* menu_model) override;
    gfx::Rect GetBounds() override;
  
    base::WeakPtr<NotifyIcon> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }

Annotations

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

See this annotation in the file changed.

@trop 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 92 in shell/browser/ui/tray_icon.h

See this annotation in the file changed.

@trop 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 37 in shell/browser/ui/tray_icon_cocoa.h

See this annotation in the file changed.

@trop 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 78 in shell/browser/ui/tray_icon_cocoa.mm

See this annotation in the file changed.

@trop trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

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

See this annotation in the file changed.

@trop 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 194 in shell/browser/ui/win/notify_icon.cc

See this annotation in the file changed.

@trop 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 69 in shell/browser/ui/win/notify_icon.h

See this annotation in the file changed.

@trop 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 24 in shell/browser/ui/tray_icon.cc

See this annotation in the file changed.

@trop 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 92 in shell/browser/ui/tray_icon.h

See this annotation in the file changed.

@trop 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 37 in shell/browser/ui/tray_icon_cocoa.h

See this annotation in the file changed.

@trop 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 78 in shell/browser/ui/tray_icon_cocoa.mm

See this annotation in the file changed.

@trop trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

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

See this annotation in the file changed.

@trop 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 194 in shell/browser/ui/win/notify_icon.cc

See this annotation in the file changed.

@trop 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 69 in shell/browser/ui/win/notify_icon.h

See this annotation in the file changed.

@trop 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 24 in shell/browser/ui/tray_icon.cc

See this annotation in the file changed.

@trop 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 92 in shell/browser/ui/tray_icon.h

See this annotation in the file changed.

@trop 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 37 in shell/browser/ui/tray_icon_cocoa.h

See this annotation in the file changed.

@trop 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 78 in shell/browser/ui/tray_icon_cocoa.mm

See this annotation in the file changed.

@trop trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict

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

See this annotation in the file changed.

@trop 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 194 in shell/browser/ui/win/notify_icon.cc

See this annotation in the file changed.

@trop 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 69 in shell/browser/ui/win/notify_icon.h

See this annotation in the file changed.

@trop 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 24 in shell/browser/ui/tray_icon.cc

See this annotation in the file changed.

@trop 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 92 in shell/browser/ui/tray_icon.h

See this annotation in the file changed.

@trop 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 37 in shell/browser/ui/tray_icon_cocoa.h

See this annotation in the file changed.

@trop 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 78 in shell/browser/ui/tray_icon_cocoa.mm

See this annotation in the file changed.

@trop trop / Backportable? - 25-x-y

shell/browser/ui/tray_icon_cocoa.mm#L78

Patch Conflict