fix hang on page with five or more Flash objects. patch by Steven Michaud. r=josh r=mento sr=pav
authorjoshmoz@gmail.com
Thu, 05 Apr 2007 17:16:07 -0700
changeset 383 fc0056f89fe691e293f24ff5b82f79f3562c3c72
parent 382 d5c4dd952527ab747d707cfa6a563115a7bac5ff
child 384 c38e8b054daaf43ad799bf835f389b62fe83dde5
push idunknown
push userunknown
push dateunknown
reviewersjosh, mento, pav
milestone1.9a4pre
fix hang on page with five or more Flash objects. patch by Steven Michaud. r=josh r=mento sr=pav
widget/src/cocoa/nsAppShell.h
widget/src/cocoa/nsAppShell.mm
widget/src/mac/nsAppShell.cpp
widget/src/mac/nsAppShell.h
--- a/widget/src/cocoa/nsAppShell.h
+++ b/widget/src/cocoa/nsAppShell.h
@@ -76,11 +76,12 @@ protected:
   NSAutoreleasePool* mMainPool;
   CFMutableArrayRef  mAutoreleasePools;
 
   NSPort*            mPort;
   AppShellDelegate*  mDelegate;
 
   PRPackedBool       mRunningEventLoop;
   PRPackedBool       mTerminated;
+  PRPackedBool       mSkippedNativeCallback;
 };
 
 #endif // nsAppShell_h_
--- a/widget/src/cocoa/nsAppShell.mm
+++ b/widget/src/cocoa/nsAppShell.mm
@@ -69,27 +69,32 @@
 @end
 
 // nsAppShell implementation
 
 NS_IMETHODIMP
 nsAppShell::ResumeNative(void)
 {
   nsresult retval = nsBaseAppShell::ResumeNative();
-  if (NS_SUCCEEDED(retval) && (mSuspendNativeCount == 0))
+  if (NS_SUCCEEDED(retval) && (mSuspendNativeCount == 0) &&
+      mSkippedNativeCallback)
+  {
+    mSkippedNativeCallback = PR_FALSE;
     ScheduleNativeEventCallback();
+  }
   return retval;
 }
 
 nsAppShell::nsAppShell()
 : mAutoreleasePools(nsnull)
 , mPort(nil)
 , mDelegate(nil)
 , mRunningEventLoop(PR_FALSE)
 , mTerminated(PR_FALSE)
+, mSkippedNativeCallback(PR_FALSE)
 {
   // mMainPool sits low on the autorelease pool stack to serve as a catch-all
   // for autoreleased objects on this thread.  Because it won't be popped
   // until the appshell is destroyed, objects attached to this pool will
   // be leaked until app shutdown.  You probably don't want this!
   //
   // Objects autoreleased to this pool may result in warnings in the future.
   mMainPool = [[NSAutoreleasePool alloc] init];
@@ -199,18 +204,21 @@ nsAppShell::ProcessGeckoEvents()
                                     windowNumber:-1
                                          context:NULL
                                          subtype:0
                                            data1:0
                                            data2:0]
              atStart:NO];
   }
 
-  if (mSuspendNativeCount <= 0)
+  if (mSuspendNativeCount <= 0) {
     NativeEventCallback();
+  } else {
+    mSkippedNativeCallback = PR_TRUE;
+  }
 
   [NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined
                                       location:NSMakePoint(0,0)
                                  modifierFlags:0
                                      timestamp:0
                                   windowNumber:-1
                                        context:NULL
                                        subtype:0
--- a/widget/src/mac/nsAppShell.cpp
+++ b/widget/src/mac/nsAppShell.cpp
@@ -55,25 +55,30 @@ enum {
 };
 
 // nsAppShell implementation
 
 NS_IMETHODIMP
 nsAppShell::ResumeNative(void)
 {
   nsresult retval = nsBaseAppShell::ResumeNative();
-  if (NS_SUCCEEDED(retval) && (mSuspendNativeCount == 0))
+  if (NS_SUCCEEDED(retval) && (mSuspendNativeCount == 0) &&
+      mSkippedNativeCallback)
+  {
+    mSkippedNativeCallback = PR_FALSE;
     ScheduleNativeEventCallback();
+  }
   return retval;
 }
 
 nsAppShell::nsAppShell()
 : mCFRunLoop(NULL)
 , mCFRunLoopSource(NULL)
 , mRunningEventLoop(PR_FALSE)
+, mSkippedNativeCallback(PR_FALSE)
 {
 }
 
 nsAppShell::~nsAppShell()
 {
   if (mCFRunLoopSource) {
     ::CFRunLoopRemoveSource(mCFRunLoop, mCFRunLoopSource,
                             kCFRunLoopCommonModes);
@@ -204,13 +209,16 @@ nsAppShell::ProcessGeckoEvents(void* aIn
                                  kEventAttributeNone, &bogusEvent);
     if (err == noErr) {
       ::PostEventToQueue(::GetMainEventQueue(), bogusEvent,
                          kEventPriorityStandard);
       ::ReleaseEvent(bogusEvent);
     }
   }
 
-  if (self->mSuspendNativeCount <= 0)
-    self->NativeEventCallback();
+  if (mSuspendNativeCount <= 0) {
+    NativeEventCallback();
+  } else {
+    mSkippedNativeCallback = PR_TRUE;
+  }
 
   NS_RELEASE(self);
 }
--- a/widget/src/mac/nsAppShell.h
+++ b/widget/src/mac/nsAppShell.h
@@ -74,11 +74,12 @@ protected:
 protected:
   nsCOMPtr<nsIToolkit>        mToolkit;
   nsAutoPtr<nsMacMessagePump> mMacPump;
 
   CFRunLoopRef                mCFRunLoop;
   CFRunLoopSourceRef          mCFRunLoopSource;
 
   PRBool                      mRunningEventLoop;
+  PRBool                      mSkippedNativeCallback;
 };
 
 #endif // nsAppShell_h__