Bug 1151345 - Firefox app menu sometimes contains only "Quit" on OS X. r=spohl a=lhenry
authorSteven Michaud <smichaud@pobox.com>
Tue, 16 Jun 2015 15:24:31 -0500
changeset 267737 9b8f7ed4e0d2a93f2b144c9673c58bf2e8ded176
parent 267736 37c99d72de9a10d7b017f90541ec922ad7dcb85e
child 267738 c62540b3f0e5c1b2787349998f7031c5b34449e8
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl, lhenry
bugs1151345
milestone39.0
Bug 1151345 - Firefox app menu sometimes contains only "Quit" on OS X. r=spohl a=lhenry
widget/cocoa/nsAppShell.mm
widget/cocoa/nsMenuBarX.h
widget/cocoa/nsMenuBarX.mm
--- a/widget/cocoa/nsAppShell.mm
+++ b/widget/cocoa/nsAppShell.mm
@@ -23,16 +23,17 @@
 #include "nsIWindowMediator.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIWebBrowserChrome.h"
 #include "nsObjCExceptions.h"
 #include "nsCocoaFeatures.h"
 #include "nsCocoaUtils.h"
 #include "nsChildView.h"
+#include "nsMenuBarX.h"
 #include "nsToolkit.h"
 #include "TextInputHandler.h"
 #include "mozilla/HangMonitor.h"
 #include "GeckoProfiler.h"
 #include "pratom.h"
 
 #include <IOKit/pwr_mgt/IOPMLib.h>
 #include "nsIDOMWakeLockListener.h"
@@ -642,16 +643,17 @@ nsAppShell::Run(void)
 {
   NS_ASSERTION(!mStarted, "nsAppShell::Run() called multiple times");
   if (mStarted || mTerminated)
     return NS_OK;
 
   mStarted = true;
 
   AddScreenWakeLockListener();
+  nsMenuBarX::ResetNativeApplicationMenu();
 
   NS_OBJC_TRY_ABORT([NSApp run]);
 
   RemoveScreenWakeLockListener();
 
   return NS_OK;
 }
 
--- a/widget/cocoa/nsMenuBarX.h
+++ b/widget/cocoa/nsMenuBarX.h
@@ -122,16 +122,17 @@ public:
   nsMenuX*          GetXULHelpMenu();
   void              SetSystemHelpMenu();
   nsresult          Paint(bool aDelayed = false);
   void              PaintMenuBarAfterDelay();
   void              ResetAwaitingDelayedPaint() { mAwaitingDelayedPaint = false; }
   void              ForceUpdateNativeMenuAt(const nsAString& indexString);
   void              ForceNativeMenuReload(); // used for testing
   static char       GetLocalizedAccelKey(const char *shortcutID);
+  static void       ResetNativeApplicationMenu();
 
 protected:
   void              ConstructNativeMenus();
   void              ConstructFallbackNativeMenus();
   nsresult          InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex);
   void              RemoveMenuAtIndex(uint32_t aIndex);
   void              HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode);
   void              AquifyMenuBar();
--- a/widget/cocoa/nsMenuBarX.mm
+++ b/widget/cocoa/nsMenuBarX.mm
@@ -492,16 +492,24 @@ char nsMenuBarX::GetLocalizedAccelKey(co
   if (strlen(keyASCPtr) != sizeof(char))
     return 0;
   // Make sure retval is lower case.
   char retval = tolower(keyASCPtr[0]);
 
   return retval;
 }
 
+/* static */
+void nsMenuBarX::ResetNativeApplicationMenu()
+{
+  [sApplicationMenu removeAllItems];
+  [sApplicationMenu release];
+  sApplicationMenu = nil;
+}
+
 // Hide the item in the menu by setting the 'hidden' attribute. Returns it in |outHiddenNode| so
 // the caller can hang onto it if they so choose. It is acceptable to pass nsull
 // for |outHiddenNode| if the caller doesn't care about the hidden node.
 void nsMenuBarX::HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode)
 {
   nsCOMPtr<nsIDOMElement> menuItem;
   inDoc->GetElementById(inID, getter_AddRefs(menuItem));  
   nsCOMPtr<nsIContent> menuContent(do_QueryInterface(menuItem));