about:startup - merge with trunk try: -b do -p macosx64 -m none -u all -t tp4
authorDaniel Brooks <db48x@db48x.net>
Mon, 25 Oct 2010 06:50:51 -0500
changeset 58864 c6e28dd6326cdf7c76813783c896adbcc38a1e7f
parent 58863 bfc0fc174aa16ad0dac0ad68d2995ff8d0401a68 (current diff)
parent 56425 bbec3799beb9cbb3bf847110fce927020cbff732 (diff)
child 58865 a62968ad14d1b49d85d582202e6fd753b2ce579e
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
milestone2.0b8pre
about:startup - merge with trunk try: -b do -p macosx64 -m none -u all -t tp4
--- a/browser/base/content/test/browser_bug585785.js
+++ b/browser/base/content/test/browser_bug585785.js
@@ -1,10 +1,31 @@
+var tab;
+var performedTest = false;
+
 function test() {
   waitForExplicitFinish();
-  var tab = gBrowser.addTab();
-  executeSoon(function () {
-    info(window.getComputedStyle(tab).maxWidth);
-    gBrowser.removeTab(tab, {animate:true});
-    ok(!tab.parentNode, "tab successfully removed");
-    finish();
-  });
+
+  tab = gBrowser.addTab();
+  isnot(tab.getAttribute("fadein"), "true", "newly opened tab is yet to fade in");
+
+  // Remove the tab right before the opening animation's first frame
+  window.mozRequestAnimationFrame(checkAnimationState);
+  executeSoon(checkAnimationState);
 }
+
+function checkAnimationState() {
+  if (performedTest)
+    return;
+
+  if (tab.getAttribute("fadein") != "true") {
+    window.mozRequestAnimationFrame(checkAnimationState);
+    executeSoon(checkAnimationState);
+    return;
+  }
+
+  performedTest = true;
+
+  info(window.getComputedStyle(tab).maxWidth);
+  gBrowser.removeTab(tab, {animate:true});
+  ok(!tab.parentNode, "tab successfully removed");
+  finish();
+}
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -285,23 +285,18 @@ nsUITimerCallback::Notify(nsITimer* aTim
 {
   nsCOMPtr<nsIObserverService> obs =
     mozilla::services::GetObserverService();
   if (!obs)
     return NS_ERROR_FAILURE;
   if ((gMouseOrKeyboardEventCounter == mPreviousCount) || !aTimer) {
     gMouseOrKeyboardEventCounter = 0;
     obs->NotifyObservers(nsnull, "user-interaction-inactive", nsnull);
-    if (gUserInteractionTimer) {
-      gUserInteractionTimer->Cancel();
-      NS_RELEASE(gUserInteractionTimer);
-    }
   } else {
     obs->NotifyObservers(nsnull, "user-interaction-active", nsnull);
-    nsEventStateManager::UpdateUserActivityTimer();
   }
   mPreviousCount = gMouseOrKeyboardEventCounter;
   return NS_OK;
 }
 
 enum {
  MOUSE_SCROLL_N_LINES,
  MOUSE_SCROLL_PAGE,
@@ -784,40 +779,29 @@ nsEventStateManager::nsEventStateManager
     mRClickCount(0),
     m_haveShutdown(PR_FALSE),
     mLastLineScrollConsumedX(PR_FALSE),
     mLastLineScrollConsumedY(PR_FALSE),
     mClickHoldContextMenu(PR_FALSE)
 {
   if (sESMInstanceCount == 0) {
     gUserInteractionTimerCallback = new nsUITimerCallback();
-    if (gUserInteractionTimerCallback)
+    if (gUserInteractionTimerCallback) {
       NS_ADDREF(gUserInteractionTimerCallback);
-    UpdateUserActivityTimer();
+      CallCreateInstance("@mozilla.org/timer;1", &gUserInteractionTimer);
+      if (gUserInteractionTimer) {
+        gUserInteractionTimer->InitWithCallback(gUserInteractionTimerCallback,
+                                                NS_USER_INTERACTION_INTERVAL,
+                                                nsITimer::TYPE_REPEATING_SLACK);
+      }
+    }
   }
   ++sESMInstanceCount;
 }
 
-nsresult
-nsEventStateManager::UpdateUserActivityTimer(void)
-{
-  if (!gUserInteractionTimerCallback)
-    return NS_OK;
-
-  if (!gUserInteractionTimer)
-    CallCreateInstance("@mozilla.org/timer;1", &gUserInteractionTimer);
-
-  if (gUserInteractionTimer) {
-    gUserInteractionTimer->InitWithCallback(gUserInteractionTimerCallback,
-                                            NS_USER_INTERACTION_INTERVAL,
-                                            nsITimer::TYPE_ONE_SHOT);
-  }
-  return NS_OK;
-}
-
 NS_IMETHODIMP
 nsEventStateManager::Init()
 {
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   if (!observerService)
     return NS_ERROR_FAILURE;
 
@@ -1082,17 +1066,16 @@ nsEventStateManager::PreHandleEvent(nsPr
         aEvent->message != NS_MOUSE_EXIT) ||
        aEvent->eventStructType == NS_MOUSE_SCROLL_EVENT ||
        aEvent->eventStructType == NS_KEY_EVENT)) {
     if (gMouseOrKeyboardEventCounter == 0) {
       nsCOMPtr<nsIObserverService> obs =
         mozilla::services::GetObserverService();
       if (obs) {
         obs->NotifyObservers(nsnull, "user-interaction-active", nsnull);
-        UpdateUserActivityTimer();
       }
     }
     ++gMouseOrKeyboardEventCounter;
   }
 
   *aStatus = nsEventStatus_eIgnore;
 
   nsMouseWheelTransaction::OnEvent(aEvent);
--- a/content/events/src/nsEventStateManager.h
+++ b/content/events/src/nsEventStateManager.h
@@ -397,19 +397,16 @@ protected:
   nsCOMPtr<nsIDocument> mDocument;   // Doesn't necessarily need to be owner
 
   PRUint32 mLClickCount;
   PRUint32 mMClickCount;
   PRUint32 mRClickCount;
 
   PRPackedBool m_haveShutdown;
 
-
-public:
-  static nsresult UpdateUserActivityTimer(void);
   // Array for accesskey support
   nsCOMArray<nsIContent> mAccessKeys;
 
   // Unlocks pixel scrolling
   PRPackedBool mLastLineScrollConsumedX;
   PRPackedBool mLastLineScrollConsumedY;
 
   static PRInt32 sUserInputEventDepth;
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -172,19 +172,16 @@ static PRLogModuleInfo* gJSDiagnostics;
 #define NS_COLLECTED_OBJECTS_LIMIT  5000
 // CC will be called if GC has been called at least this number of times and
 // there are at least NS_MIN_SUSPECT_CHANGES new suspected objects.
 #define NS_MAX_GC_COUNT             5
 #define NS_MIN_SUSPECT_CHANGES      10
 // CC will be called if there are at least NS_MAX_SUSPECT_CHANGES new suspected
 // objects.
 #define NS_MAX_SUSPECT_CHANGES      100
-// When CCIfUserInactive(PR_FALSE, PR_TRUE) is called, CC is called 
-// if there are at least NS_MIN_INACTIVE_SUSPECT_CHANGES new suspected objects. 
-#define NS_MIN_INACTIVE_SUSPECT_CHANGES 5
 
 // if you add statics here, add them to the list in nsJSRuntime::Startup
 
 static PRUint32 sDelayedCCollectCount;
 static PRUint32 sCCollectCount;
 static PRBool sUserIsActive;
 static PRTime sPreviousCCTime;
 static PRUint32 sCollectedObjectsCounts;
@@ -3615,24 +3612,20 @@ nsJSContext::CC(nsICycleCollectorListene
   printf("Will run cycle collector (%i), %lldms since previous.\n",
          sCCollectCount, (PR_Now() - sPreviousCCTime) / PR_USEC_PER_MSEC);
 #endif
   sPreviousCCTime = PR_Now();
   sDelayedCCollectCount = 0;
   sCCSuspectChanges = 0;
   // nsCycleCollector_collect() no longer forces a JS garbage collection,
   // so we have to do it ourselves here.
-  if (nsContentUtils::XPConnect()) {
-    nsContentUtils::XPConnect()->GarbageCollect();
-  }
+  nsContentUtils::XPConnect()->GarbageCollect();
   sCollectedObjectsCounts = nsCycleCollector_collect(aListener);
   sCCSuspectedCount = nsCycleCollector_suspectedCount();
-  if (nsJSRuntime::sRuntime) {
-    sSavedGCCount = JS_GetGCParameter(nsJSRuntime::sRuntime, JSGC_NUMBER);
-  }
+  sSavedGCCount = JS_GetGCParameter(nsJSRuntime::sRuntime, JSGC_NUMBER);
 #ifdef DEBUG_smaug
   printf("Collected %u objects, %u suspected objects, took %lldms\n",
          sCollectedObjectsCounts, sCCSuspectedCount,
          (PR_Now() - sPreviousCCTime) / PR_USEC_PER_MSEC);
 #endif
 }
 
 static inline uint32
@@ -3693,32 +3686,21 @@ nsJSContext::MaybeCC(PRBool aHigherProba
        (sCCSuspectChanges > NS_MAX_SUSPECT_CHANGES))) {
     return IntervalCC();
   }
   return PR_FALSE;
 }
 
 //static
 void
-nsJSContext::CCIfUserInactive(PRBool aOrMaybeCC,
-                              PRBool aOnlyIfNewSuspectedObjects)
+nsJSContext::CCIfUserInactive()
 {
   if (sUserIsActive) {
-    if (aOrMaybeCC) {
-      MaybeCC(PR_TRUE);
-    }
-  } else if (!aOnlyIfNewSuspectedObjects ||
-             ((nsCycleCollector_suspectedCount() - sCCSuspectedCount) >
-              NS_MIN_INACTIVE_SUSPECT_CHANGES)) {
-#ifdef DEBUG_smaug
-    if (aOnlyIfNewSuspectedObjects) {
-      printf("CCIfUserInactive, %u suspected changes\n",
-             nsCycleCollector_suspectedCount() - sCCSuspectedCount);
-    }
-#endif
+    MaybeCC(PR_TRUE);
+  } else {
     IntervalCC();
   }
 }
 
 //static
 PRBool
 nsJSContext::IntervalCC()
 {
@@ -3920,17 +3902,17 @@ nsJSRuntime::ParseVersion(const nsString
 //static
 void
 nsJSRuntime::Startup()
 {
   // initialize all our statics, so that we can restart XPCOM
   sDelayedCCollectCount = 0;
   sCCollectCount = 0;
   sUserIsActive = PR_FALSE;
-  sPreviousCCTime = PR_Now();
+  sPreviousCCTime = 0;
   sCollectedObjectsCounts = 0;
   sSavedGCCount = 0;
   sCCSuspectChanges = 0;
   sCCSuspectedCount = 0;
   sGCTimer = nsnull;
   sReadyForGC = PR_FALSE;
   sLoadInProgressGCTimer = PR_FALSE;
   sPendingLoadCount = 0;
--- a/dom/base/nsJSEnvironment.h
+++ b/dom/base/nsJSEnvironment.h
@@ -205,23 +205,18 @@ public:
   //   MaybeCC works effectively as if aHigherProbability was true.
   // @return PR_TRUE if cycle collector was called.
   static PRBool MaybeCC(PRBool aHigherProbability);
 
   // IntervalCC() calls CC() if at least NS_MIN_CC_INTERVAL milliseconds have
   // elapsed since the previous cycle collector call.
   static PRBool IntervalCC();
 
-  // Calls IntervalCC() if user is currently inactive.
-  // If user is active and aOrMaybeCC PR_TRUE, this calls MaybeCC(PR_TRUE)
-  // If aOnlyIfNewSuspectedObjects is PR_TRUE, CC is called only if
-  // user is inactive and there are some new suspected objects.
-  
-  static void CCIfUserInactive(PRBool aOrMaybeCC = PR_TRUE,
-                               PRBool aOnlyIfNewSuspectedObjects = PR_FALSE);
+  // Calls IntervalCC() if user is currently inactive, otherwise MaybeCC(PR_TRUE)
+  static void CCIfUserInactive();
 
   static void FireGCTimer(PRBool aLoadInProgress);
 
 protected:
   nsresult InitializeExternalClasses();
 
   // Helper to convert xpcom datatypes to jsvals.
   nsresult ConvertSupportsTojsvals(nsISupports *aArgs,
--- a/embedding/android/GeckoAppShell.java
+++ b/embedding/android/GeckoAppShell.java
@@ -65,16 +65,17 @@ class GeckoAppShell
     static {
         sGeckoRunning = false;
     }
 
     // static members only
     private GeckoAppShell() { }
 
     static boolean sGeckoRunning;
+    static private GeckoEvent gPendingResize = null;
 
     static private boolean gRestartScheduled = false;
 
     static private final Timer mIMETimer = new Timer();
     static private final HashMap<Integer, AlertNotification>
          mAlertNotifications = new HashMap<Integer, AlertNotification>();
 
     static private final int NOTIFY_IME_RESETINPUTSTATE = 0;
@@ -85,17 +86,16 @@ class GeckoAppShell
 
     /* The Android-side API: API methods that Android calls */
 
     // Initialization methods
     public static native void nativeInit();
     public static native void nativeRun(String args);
 
     // helper methods
-    public static native void setInitialSize(int width, int height);
     public static native void setSurfaceView(GeckoSurfaceView sv);
     public static native void putenv(String map);
     public static native void onResume();
     public static native void onLowMemory();
     public static native void callObserver(String observerKey, String topic, String data);
     public static native void removeObserver(String observerKey);
     public static native void loadLibs(String apkName);
 
@@ -141,23 +141,35 @@ class GeckoAppShell
         // First argument is the .apk path
         String combinedArgs = apkPath + " -omnijar " + apkPath;
         if (args != null)
             combinedArgs += " " + args;
         if (url != null)
             combinedArgs += " " + url;
         // and go
         GeckoAppShell.nativeRun(combinedArgs);
+        if (gPendingResize != null) {
+            notifyGeckoOfEvent(gPendingResize);
+            gPendingResize = null;
+        }
     }
 
     private static GeckoEvent mLastDrawEvent;
 
     public static void sendEventToGecko(GeckoEvent e) {
-        if (sGeckoRunning)
+        if (sGeckoRunning) {
+            if (gPendingResize != null) {
+                notifyGeckoOfEvent(gPendingResize);
+                gPendingResize = null;
+            }
             notifyGeckoOfEvent(e);
+        } else {
+            if (e.mType == GeckoEvent.SIZE_CHANGED)
+                gPendingResize = e;
+        }
     }
 
     // Tell the Gecko event loop that an event is available.
     public static native void notifyGeckoOfEvent(GeckoEvent event);
 
     /*
      *  The Gecko-side API: API methods that Gecko calls
      */
--- a/embedding/android/GeckoSurfaceView.java
+++ b/embedding/android/GeckoSurfaceView.java
@@ -111,19 +111,16 @@ class GeckoSurfaceView
 
             mFormat = format;
             mWidth = width;
             mHeight = height;
             mSurfaceValid = true;
 
             Log.i("GeckoAppJava", "surfaceChanged: fmt: " + format + " dim: " + width + " " + height);
 
-            if (!GeckoAppShell.sGeckoRunning)
-                return;
-
             GeckoEvent e = new GeckoEvent(GeckoEvent.SIZE_CHANGED, width, height, -1, -1);
             GeckoAppShell.sendEventToGecko(e);
 
             if (mSurfaceNeedsRedraw) {
                 GeckoAppShell.scheduleRedraw();
                 mSurfaceNeedsRedraw = false;
             }
 
--- a/js/src/xpconnect/src/Makefile.in
+++ b/js/src/xpconnect/src/Makefile.in
@@ -118,17 +118,16 @@ LOCAL_INCLUDES = \
 		-I$(topsrcdir)/js/src/nanojit \
 		-I$(topsrcdir)/caps/include \
 		-I$(topsrcdir)/content/base/src \
 		-I$(topsrcdir)/content/html/content/src \
 		-I$(topsrcdir)/content/html/document/src \
 		-I$(topsrcdir)/content/svg/content/src \
 		-I$(topsrcdir)/layout/style \
 		-I$(topsrcdir)/layout/base \
-		-I$(topsrcdir)/dom/base \
 		$(NULL)
 
 EXTRA_DSO_LDOPTS += \
 		$(MOZ_COMPONENT_LIBS) \
 		$(MOZ_JS_LIBS) \
 		$(NULL)
 
 ifdef MOZ_JSLOADER
--- a/js/src/xpconnect/src/nsXPConnect.cpp
+++ b/js/src/xpconnect/src/nsXPConnect.cpp
@@ -49,17 +49,17 @@
 #include "jsatom.h"
 #include "jsobj.h"
 #include "jsfun.h"
 #include "jsscript.h"
 #include "nsThreadUtilsInternal.h"
 #include "dom_quickstubs.h"
 #include "nsNullPrincipal.h"
 #include "nsIURI.h"
-#include "nsJSEnvironment.h"
+
 #include "jstypedarray.h"
 
 #include "XrayWrapper.h"
 #include "WrapperFactory.h"
 #include "AccessCheck.h"
 
 NS_IMPL_THREADSAFE_ISUPPORTS6(nsXPConnect,
                               nsIXPConnect,
@@ -2237,20 +2237,16 @@ nsXPConnect::OnProcessNextEvent(nsIThrea
     // event processing.
     return Push(nsnull);
 }
 
 NS_IMETHODIMP
 nsXPConnect::AfterProcessNextEvent(nsIThreadInternal *aThread,
                                    PRUint32 aRecursionDepth)
 {
-    if (NS_IsMainThread()) {
-        nsJSContext::CCIfUserInactive(PR_FALSE, PR_TRUE);
-    }
-
     return Pop(nsnull);
 }
 
 NS_IMETHODIMP
 nsXPConnect::OnDispatchedEvent(nsIThreadInternal* aThread)
 {
     NS_NOTREACHED("Why tell us?");
     return NS_ERROR_UNEXPECTED;
--- a/other-licenses/android/APKOpen.cpp
+++ b/other-licenses/android/APKOpen.cpp
@@ -212,17 +212,16 @@ Java_org_mozilla_gecko_GeckoAppShell_ ##
 { \
   f_ ## name(jenv, jc, one, two, three); \
 }
 
 SHELL_WRAPPER0(nativeInit)
 SHELL_WRAPPER1(nativeRun, jstring)
 SHELL_WRAPPER1(notifyGeckoOfEvent, jobject)
 SHELL_WRAPPER1(setSurfaceView, jobject)
-SHELL_WRAPPER2(setInitialSize, int, int)
 SHELL_WRAPPER0(onResume)
 SHELL_WRAPPER0(onLowMemory)
 SHELL_WRAPPER3(callObserver, jstring, jstring, jstring)
 SHELL_WRAPPER1(removeObserver, jstring)
 
 static void * xul_handle = NULL;
 static time_t apk_mtime = 0;
 #ifdef DEBUG
@@ -503,17 +502,16 @@ loadLibs(const char *apkName)
   if (!xul_handle)
     __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libxul!");
 
 #define GETFUNC(name) f_ ## name = (name ## _t) __wrap_dlsym(xul_handle, "Java_org_mozilla_gecko_GeckoAppShell_" #name)
   GETFUNC(nativeInit);
   GETFUNC(nativeRun);
   GETFUNC(notifyGeckoOfEvent);
   GETFUNC(setSurfaceView);
-  GETFUNC(setInitialSize);
   GETFUNC(onResume);
   GETFUNC(onLowMemory);
   GETFUNC(callObserver);
   GETFUNC(removeObserver);
 #undef GETFUNC
 #ifdef DEBUG
   gettimeofday(&t1, 0);
   __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "spent %d total",
--- a/parser/html/javasrc/Tokenizer.java
+++ b/parser/html/javasrc/Tokenizer.java
@@ -137,89 +137,87 @@ public class Tokenizer implements Locato
     public static final int COMMENT_START_DASH = 33;
 
     public static final int COMMENT = 34;
 
     public static final int COMMENT_END_DASH = 35;
 
     public static final int COMMENT_END = 36;
 
-    public static final int COMMENT_END_SPACE = 37;
-
-    public static final int COMMENT_END_BANG = 38;
-
-    public static final int NON_DATA_END_TAG_NAME = 39;
-
-    public static final int MARKUP_DECLARATION_HYPHEN = 40;
-
-    public static final int MARKUP_DECLARATION_OCTYPE = 41;
-
-    public static final int DOCTYPE_UBLIC = 42;
-
-    public static final int DOCTYPE_YSTEM = 43;
-
-    public static final int AFTER_DOCTYPE_PUBLIC_KEYWORD = 44;
-
-    public static final int BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS = 45;
-
-    public static final int AFTER_DOCTYPE_SYSTEM_KEYWORD = 46;
-
-    public static final int CONSUME_CHARACTER_REFERENCE = 47;
-
-    public static final int CONSUME_NCR = 48;
-
-    public static final int CHARACTER_REFERENCE_TAIL = 49;
-
-    public static final int HEX_NCR_LOOP = 50;
-
-    public static final int DECIMAL_NRC_LOOP = 51;
-
-    public static final int HANDLE_NCR_VALUE = 52;
-
-    public static final int HANDLE_NCR_VALUE_RECONSUME = 53;
-
-    public static final int CHARACTER_REFERENCE_HILO_LOOKUP = 54;
-
-    public static final int SELF_CLOSING_START_TAG = 55;
-
-    public static final int CDATA_START = 56;
-
-    public static final int CDATA_SECTION = 57;
-
-    public static final int CDATA_RSQB = 58;
-
-    public static final int CDATA_RSQB_RSQB = 59;
-
-    public static final int SCRIPT_DATA_LESS_THAN_SIGN = 60;
-
-    public static final int SCRIPT_DATA_ESCAPE_START = 61;
-
-    public static final int SCRIPT_DATA_ESCAPE_START_DASH = 62;
-
-    public static final int SCRIPT_DATA_ESCAPED_DASH = 63;
-
-    public static final int SCRIPT_DATA_ESCAPED_DASH_DASH = 64;
-
-    public static final int BOGUS_COMMENT_HYPHEN = 65;
-
-    public static final int RAWTEXT_RCDATA_LESS_THAN_SIGN = 66;
-
-    public static final int SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN = 67;
-
-    public static final int SCRIPT_DATA_DOUBLE_ESCAPE_START = 68;
-
-    public static final int SCRIPT_DATA_DOUBLE_ESCAPED = 69;
-
-    public static final int SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN = 70;
-
-    public static final int SCRIPT_DATA_DOUBLE_ESCAPED_DASH = 71;
-
-    public static final int SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH = 72;
-
-    public static final int SCRIPT_DATA_DOUBLE_ESCAPE_END = 73;
+    public static final int COMMENT_END_BANG = 37;
+
+    public static final int NON_DATA_END_TAG_NAME = 38;
+
+    public static final int MARKUP_DECLARATION_HYPHEN = 39;
+
+    public static final int MARKUP_DECLARATION_OCTYPE = 40;
+
+    public static final int DOCTYPE_UBLIC = 41;
+
+    public static final int DOCTYPE_YSTEM = 42;
+
+    public static final int AFTER_DOCTYPE_PUBLIC_KEYWORD = 43;
+
+    public static final int BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS = 44;
+
+    public static final int AFTER_DOCTYPE_SYSTEM_KEYWORD = 45;
+
+    public static final int CONSUME_CHARACTER_REFERENCE = 46;
+
+    public static final int CONSUME_NCR = 47;
+
+    public static final int CHARACTER_REFERENCE_TAIL = 48;
+
+    public static final int HEX_NCR_LOOP = 49;
+
+    public static final int DECIMAL_NRC_LOOP = 50;
+
+    public static final int HANDLE_NCR_VALUE = 51;
+
+    public static final int HANDLE_NCR_VALUE_RECONSUME = 52;
+
+    public static final int CHARACTER_REFERENCE_HILO_LOOKUP = 53;
+
+    public static final int SELF_CLOSING_START_TAG = 54;
+
+    public static final int CDATA_START = 55;
+
+    public static final int CDATA_SECTION = 56;
+
+    public static final int CDATA_RSQB = 57;
+
+    public static final int CDATA_RSQB_RSQB = 58;
+
+    public static final int SCRIPT_DATA_LESS_THAN_SIGN = 59;
+
+    public static final int SCRIPT_DATA_ESCAPE_START = 60;
+
+    public static final int SCRIPT_DATA_ESCAPE_START_DASH = 61;
+
+    public static final int SCRIPT_DATA_ESCAPED_DASH = 62;
+
+    public static final int SCRIPT_DATA_ESCAPED_DASH_DASH = 63;
+
+    public static final int BOGUS_COMMENT_HYPHEN = 64;
+
+    public static final int RAWTEXT_RCDATA_LESS_THAN_SIGN = 65;
+
+    public static final int SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN = 66;
+
+    public static final int SCRIPT_DATA_DOUBLE_ESCAPE_START = 67;
+
+    public static final int SCRIPT_DATA_DOUBLE_ESCAPED = 68;
+
+    public static final int SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN = 69;
+
+    public static final int SCRIPT_DATA_DOUBLE_ESCAPED_DASH = 70;
+
+    public static final int SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH = 71;
+
+    public static final int SCRIPT_DATA_DOUBLE_ESCAPE_END = 72;
 
     /**
      * Magic value for UTF-16 operations.
      */
     private static final int LEAD_OFFSET = (0xD800 - (0x10000 >> 10));
 
     /**
      * UTF-16 code unit array containing less than and greater than for emitting
@@ -2598,85 +2596,16 @@ public class Tokenizer implements Locato
                                 adjustDoubleHyphenAndAppendToLongStrBufAndErr(c);
                                 /*
                                  * Switch to the comment state.
                                  */
                                 state = transition(state, Tokenizer.COMMENT, reconsume, pos);
                                 continue stateloop;
                         }
                     }
-                case COMMENT_END_SPACE:
-                    for (;;) {
-                        if (++pos == endPos) {
-                            break stateloop;
-                        }
-                        c = checkChar(buf, pos);
-                        /*
-                         * Comment end space state
-                         * 
-                         * Consume the next input character:
-                         */
-                        switch (c) {
-                            case '>':
-                                /*
-                                 * U+003E GREATER-THAN SIGN (>) Emit the comment
-                                 * token.
-                                 */
-                                emitComment(0, pos);
-                                /*
-                                 * Switch to the data state.
-                                 */
-                                state = transition(state, Tokenizer.DATA, reconsume, pos);
-                                continue stateloop;
-                            case '-':
-                                /*
-                                 * U+002D HYPHEN-MINUS (-) Switch to the comment
-                                 * end dash state.
-                                 */
-                                appendLongStrBuf(c);
-                                /*
-                                 * Switch to the comment end dash state.
-                                 */
-                                state = transition(state, Tokenizer.COMMENT_END_DASH, reconsume, pos);
-                                continue stateloop;
-                            case ' ':
-                            case '\t':
-                            case '\u000C':
-                                /*
-                                 * U+0009 CHARACTER TABULATION U+000A LINE FEED
-                                 * (LF) U+000C FORM FEED (FF) U+0020 SPACE
-                                 * Append the input character to the comment
-                                 * token's data. Stay in the comment end space
-                                 * state.
-                                 */
-                                appendLongStrBuf(c);
-                                continue;
-                            case '\r':
-                                appendLongStrBufCarriageReturn();
-                                break stateloop;
-                            case '\n':
-                                appendLongStrBufLineFeed();
-                                continue;
-                            case '\u0000':
-                                c = '\uFFFD';
-                                // fall thru
-                            default:
-                                /*
-                                 * Anything else Append the input character to
-                                 * the comment token's data. Switch to the
-                                 * comment state.
-                                 */
-                                appendLongStrBuf(c);
-                                /*
-                                 * Switch to the comment state.
-                                 */
-                                state = transition(state, Tokenizer.COMMENT, reconsume, pos);
-                                continue stateloop;
-                        }
-                    }
                     // XXX reorder point
                 case COMMENT_END_BANG:
                     for (;;) {
                         if (++pos == endPos) {
                             break stateloop;
                         }
                         c = checkChar(buf, pos);
                         /*
@@ -6127,17 +6056,16 @@ public class Tokenizer implements Locato
                         /*
                          * Reconsume the EOF character in the data state.
                          */
                         break eofloop;
                     }
                     break eofloop;
                 case COMMENT_START:
                 case COMMENT:
-                case COMMENT_END_SPACE:
                     /*
                      * EOF Parse error.
                      */
                     errEofInComment();
                     /* Emit the comment token. */
                     emitComment(0, 0);
                     /*
                      * Reconsume the EOF character in the data state.
@@ -6992,10 +6920,24 @@ public class Tokenizer implements Locato
      * 
      * @param encodingDeclarationHandler
      *            the encodingDeclarationHandler to set
      */
     public void setEncodingDeclarationHandler(
             EncodingDeclarationHandler encodingDeclarationHandler) {
         this.encodingDeclarationHandler = encodingDeclarationHandler;
     }
+    
+    // [NOCPP[
+    
+    /**
+     * Sets an offset to be added to the position reported to 
+     * <code>TransitionHandler</code>.
+     * 
+     * @param offset the offset
+     */
+    public void setTransitionBaseOffset(int offset) {
+        
+    }
+    
+    // ]NOCPP]
 
 }
--- a/parser/html/nsHtml5Tokenizer.cpp
+++ b/parser/html/nsHtml5Tokenizer.cpp
@@ -1136,58 +1136,16 @@ nsHtml5Tokenizer::stateLoop(PRInt32 stat
               adjustDoubleHyphenAndAppendToLongStrBufAndErr(c);
               state = NS_HTML5TOKENIZER_COMMENT;
               NS_HTML5_CONTINUE(stateloop);
             }
           }
         }
 
       }
-      case NS_HTML5TOKENIZER_COMMENT_END_SPACE: {
-        for (; ; ) {
-          if (++pos == endPos) {
-            NS_HTML5_BREAK(stateloop);
-          }
-          c = checkChar(buf, pos);
-          switch(c) {
-            case '>': {
-              emitComment(0, pos);
-              state = NS_HTML5TOKENIZER_DATA;
-              NS_HTML5_CONTINUE(stateloop);
-            }
-            case '-': {
-              appendLongStrBuf(c);
-              state = NS_HTML5TOKENIZER_COMMENT_END_DASH;
-              NS_HTML5_CONTINUE(stateloop);
-            }
-            case ' ':
-            case '\t':
-            case '\f': {
-              appendLongStrBuf(c);
-              continue;
-            }
-            case '\r': {
-              appendLongStrBufCarriageReturn();
-              NS_HTML5_BREAK(stateloop);
-            }
-            case '\n': {
-              appendLongStrBufLineFeed();
-              continue;
-            }
-            case '\0': {
-              c = 0xfffd;
-            }
-            default: {
-              appendLongStrBuf(c);
-              state = NS_HTML5TOKENIZER_COMMENT;
-              NS_HTML5_CONTINUE(stateloop);
-            }
-          }
-        }
-      }
       case NS_HTML5TOKENIZER_COMMENT_END_BANG: {
         for (; ; ) {
           if (++pos == endPos) {
             NS_HTML5_BREAK(stateloop);
           }
           c = checkChar(buf, pos);
           switch(c) {
             case '>': {
@@ -3488,18 +3446,17 @@ nsHtml5Tokenizer::eof()
           }
           forceQuirks = PR_TRUE;
           emitDoctypeToken(0);
           NS_HTML5_BREAK(eofloop);
         }
         NS_HTML5_BREAK(eofloop);
       }
       case NS_HTML5TOKENIZER_COMMENT_START:
-      case NS_HTML5TOKENIZER_COMMENT:
-      case NS_HTML5TOKENIZER_COMMENT_END_SPACE: {
+      case NS_HTML5TOKENIZER_COMMENT: {
 
         emitComment(0, 0);
         NS_HTML5_BREAK(eofloop);
       }
       case NS_HTML5TOKENIZER_COMMENT_END: {
 
         emitComment(2, 0);
         NS_HTML5_BREAK(eofloop);
--- a/parser/html/nsHtml5Tokenizer.h
+++ b/parser/html/nsHtml5Tokenizer.h
@@ -347,51 +347,50 @@ jArray<PRUnichar,PRInt32> nsHtml5Tokeniz
 #define NS_HTML5TOKENIZER_DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED 29
 #define NS_HTML5TOKENIZER_AFTER_DOCTYPE_SYSTEM_IDENTIFIER 30
 #define NS_HTML5TOKENIZER_BOGUS_DOCTYPE 31
 #define NS_HTML5TOKENIZER_COMMENT_START 32
 #define NS_HTML5TOKENIZER_COMMENT_START_DASH 33
 #define NS_HTML5TOKENIZER_COMMENT 34
 #define NS_HTML5TOKENIZER_COMMENT_END_DASH 35
 #define NS_HTML5TOKENIZER_COMMENT_END 36
-#define NS_HTML5TOKENIZER_COMMENT_END_SPACE 37
-#define NS_HTML5TOKENIZER_COMMENT_END_BANG 38
-#define NS_HTML5TOKENIZER_NON_DATA_END_TAG_NAME 39
-#define NS_HTML5TOKENIZER_MARKUP_DECLARATION_HYPHEN 40
-#define NS_HTML5TOKENIZER_MARKUP_DECLARATION_OCTYPE 41
-#define NS_HTML5TOKENIZER_DOCTYPE_UBLIC 42
-#define NS_HTML5TOKENIZER_DOCTYPE_YSTEM 43
-#define NS_HTML5TOKENIZER_AFTER_DOCTYPE_PUBLIC_KEYWORD 44
-#define NS_HTML5TOKENIZER_BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS 45
-#define NS_HTML5TOKENIZER_AFTER_DOCTYPE_SYSTEM_KEYWORD 46
-#define NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE 47
-#define NS_HTML5TOKENIZER_CONSUME_NCR 48
-#define NS_HTML5TOKENIZER_CHARACTER_REFERENCE_TAIL 49
-#define NS_HTML5TOKENIZER_HEX_NCR_LOOP 50
-#define NS_HTML5TOKENIZER_DECIMAL_NRC_LOOP 51
-#define NS_HTML5TOKENIZER_HANDLE_NCR_VALUE 52
-#define NS_HTML5TOKENIZER_HANDLE_NCR_VALUE_RECONSUME 53
-#define NS_HTML5TOKENIZER_CHARACTER_REFERENCE_HILO_LOOKUP 54
-#define NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG 55
-#define NS_HTML5TOKENIZER_CDATA_START 56
-#define NS_HTML5TOKENIZER_CDATA_SECTION 57
-#define NS_HTML5TOKENIZER_CDATA_RSQB 58
-#define NS_HTML5TOKENIZER_CDATA_RSQB_RSQB 59
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_LESS_THAN_SIGN 60
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPE_START 61
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPE_START_DASH 62
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH 63
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH_DASH 64
-#define NS_HTML5TOKENIZER_BOGUS_COMMENT_HYPHEN 65
-#define NS_HTML5TOKENIZER_RAWTEXT_RCDATA_LESS_THAN_SIGN 66
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN 67
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPE_START 68
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED 69
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN 70
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_DASH 71
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH 72
-#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPE_END 73
+#define NS_HTML5TOKENIZER_COMMENT_END_BANG 37
+#define NS_HTML5TOKENIZER_NON_DATA_END_TAG_NAME 38
+#define NS_HTML5TOKENIZER_MARKUP_DECLARATION_HYPHEN 39
+#define NS_HTML5TOKENIZER_MARKUP_DECLARATION_OCTYPE 40
+#define NS_HTML5TOKENIZER_DOCTYPE_UBLIC 41
+#define NS_HTML5TOKENIZER_DOCTYPE_YSTEM 42
+#define NS_HTML5TOKENIZER_AFTER_DOCTYPE_PUBLIC_KEYWORD 43
+#define NS_HTML5TOKENIZER_BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS 44
+#define NS_HTML5TOKENIZER_AFTER_DOCTYPE_SYSTEM_KEYWORD 45
+#define NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE 46
+#define NS_HTML5TOKENIZER_CONSUME_NCR 47
+#define NS_HTML5TOKENIZER_CHARACTER_REFERENCE_TAIL 48
+#define NS_HTML5TOKENIZER_HEX_NCR_LOOP 49
+#define NS_HTML5TOKENIZER_DECIMAL_NRC_LOOP 50
+#define NS_HTML5TOKENIZER_HANDLE_NCR_VALUE 51
+#define NS_HTML5TOKENIZER_HANDLE_NCR_VALUE_RECONSUME 52
+#define NS_HTML5TOKENIZER_CHARACTER_REFERENCE_HILO_LOOKUP 53
+#define NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG 54
+#define NS_HTML5TOKENIZER_CDATA_START 55
+#define NS_HTML5TOKENIZER_CDATA_SECTION 56
+#define NS_HTML5TOKENIZER_CDATA_RSQB 57
+#define NS_HTML5TOKENIZER_CDATA_RSQB_RSQB 58
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_LESS_THAN_SIGN 59
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPE_START 60
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPE_START_DASH 61
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH 62
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH_DASH 63
+#define NS_HTML5TOKENIZER_BOGUS_COMMENT_HYPHEN 64
+#define NS_HTML5TOKENIZER_RAWTEXT_RCDATA_LESS_THAN_SIGN 65
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN 66
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPE_START 67
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED 68
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN 69
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_DASH 70
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH 71
+#define NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPE_END 72
 #define NS_HTML5TOKENIZER_LEAD_OFFSET (0xD800 - (0x10000 >> 10))
 #define NS_HTML5TOKENIZER_BUFFER_GROW_BY 1024
 
 
 #endif
 
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -1862,17 +1862,17 @@ Engine.prototype = {
           // quoted attribute.
           var betweenEqualAndQuote = lLine.substring(valueStart, quoteStart);
           if (/\S/.test(betweenEqualAndQuote))
             return lLine.substr(valueStart).replace(/\s.*$/, "");
 
           // Adjust the start index to account for the opening quote
           valueStart = quoteStart + "\"".length;
           // Find the closing quote
-          let valueEnd = lLine.indexOf("\"", valueStart);
+          var valueEnd = lLine.indexOf("\"", valueStart);
           // If there is no closing quote, just go to the end of the line
           if (valueEnd == -1)
             valueEnd = aLine.length;
         }
         return aLine.substring(valueStart, valueEnd);
       }
 
       var inputs = [];
--- a/widget/src/android/AndroidJNI.cpp
+++ b/widget/src/android/AndroidJNI.cpp
@@ -53,17 +53,16 @@
 using namespace mozilla;
 
 /* Forward declare all the JNI methods as extern "C" */
 
 extern "C" {
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_nativeInit(JNIEnv *, jclass);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent(JNIEnv *, jclass, jobject event);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setSurfaceView(JNIEnv *jenv, jclass, jobject sv);
-    NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setInitialSize(JNIEnv *jenv, jclass, int width, int height);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onResume(JNIEnv *, jclass);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onLowMemory(JNIEnv *, jclass);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_callObserver(JNIEnv *, jclass, jstring observerKey, jstring topic, jstring data);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_removeObserver(JNIEnv *jenv, jclass, jstring jObserverKey);
 }
 
 
 /*
@@ -88,22 +87,16 @@ Java_org_mozilla_gecko_GeckoAppShell_not
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_setSurfaceView(JNIEnv *jenv, jclass, jobject obj)
 {
     AndroidBridge::Bridge()->SetSurfaceView(jenv->NewGlobalRef(obj));
 }
 
 NS_EXPORT void JNICALL
-Java_org_mozilla_gecko_GeckoAppShell_setInitialSize(JNIEnv *jenv, jclass, int width, int height)
-{
-    nsWindow::SetInitialAndroidBounds(gfxIntSize(width, height));
-}
-
-NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_onLowMemory(JNIEnv *jenv, jclass jc)
 {
     nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os)
         os->NotifyObservers(nsnull, "memory-pressure", NS_LITERAL_STRING("low-memory").get());
 }
 
 NS_EXPORT void JNICALL
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -201,35 +201,36 @@ nsCocoaWindow::~nsCocoaWindow()
   if (mModal) {
     --gXULModalLevel;
     NS_ASSERTION(gXULModalLevel >= 0, "Wierdness setting modality!");
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
-// Very large windows work in Cocoa, but can take a long time to
-// process (multiple minutes), during which time the system is
-// unresponsive and seems hung. Although it's likely that windows
-// much larger than screen size are bugs, be conservative and only
-// intervene if the values are so large as to hog the cpu.
-#define SIZE_LIMIT 100000
-static bool WindowSizeAllowed(PRInt32 aWidth, PRInt32 aHeight)
+static void FitRectToVisibleAreaForScreen(nsIntRect &aRect, NSScreen *screen)
 {
-  if (aWidth > SIZE_LIMIT) {
-    NS_ERROR(nsPrintfCString(256, "Requested Cocoa window width of %d is too much, max allowed is %d",
-                             aWidth, SIZE_LIMIT).get());
-    return false;
+  if (!screen)
+    return;
+  
+  nsIntRect screenBounds(nsCocoaUtils::CocoaRectToGeckoRect([screen visibleFrame]));
+  
+  if (aRect.width > screenBounds.width) {
+    aRect.width = screenBounds.width;
   }
-  if (aHeight > SIZE_LIMIT) {
-    NS_ERROR(nsPrintfCString(256, "Requested Cocoa window height of %d is too much, max allowed is %d",
-                             aHeight, SIZE_LIMIT).get());
-    return false;
+  if (aRect.height > screenBounds.height) {
+    aRect.height = screenBounds.height;
   }
-  return true;
+  
+  if (aRect.x - screenBounds.x + aRect.width > screenBounds.width) {
+    aRect.x += screenBounds.width - (aRect.x - screenBounds.x + aRect.width);
+  }
+  if (aRect.y - screenBounds.y + aRect.height > screenBounds.height) {
+    aRect.y += screenBounds.height - (aRect.y - screenBounds.y + aRect.height);
+  }
 }
 
 // Some applications like Camino use native popup windows
 // (native context menus, native tooltips)
 static PRBool UseNativePopupWindows()
 {
   nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
   if (!prefs)
@@ -250,38 +251,38 @@ nsresult nsCocoaWindow::Create(nsIWidget
                                nsWidgetInitData *aInitData)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   // Because the hidden window is created outside of an event loop,
   // we have to provide an autorelease pool (see bug 559075).
   nsAutoreleasePool localPool;
 
-  if (!WindowSizeAllowed(aRect.width, aRect.height))
-    return NS_ERROR_FAILURE;
+  nsIntRect newBounds = aRect;
+  FitRectToVisibleAreaForScreen(newBounds, [NSScreen mainScreen]);
 
   // Set defaults which can be overriden from aInitData in BaseCreate
   mWindowType = eWindowType_toplevel;
   mBorderStyle = eBorderStyle_default;
 
-  Inherited::BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aAppShell,
+  Inherited::BaseCreate(aParent, newBounds, aHandleEventFunction, aContext, aAppShell,
                         aToolkit, aInitData);
 
   mParent = aParent;
 
   // Applications that use native popups don't want us to create popup windows.
   if ((mWindowType == eWindowType_popup) && UseNativePopupWindows())
     return NS_OK;
 
-  nsresult rv = CreateNativeWindow(nsCocoaUtils::GeckoRectToCocoaRect(aRect),
+  nsresult rv = CreateNativeWindow(nsCocoaUtils::GeckoRectToCocoaRect(newBounds),
                                    mBorderStyle, PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mWindowType == eWindowType_popup)
-    return CreatePopupContentView(aRect, aHandleEventFunction, aContext, aAppShell, aToolkit);
+    return CreatePopupContentView(newBounds, aHandleEventFunction, aContext, aAppShell, aToolkit);
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle)
 {
@@ -1121,27 +1122,27 @@ NS_METHOD nsCocoaWindow::MakeFullScreen(
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 
 NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
-  if (!WindowSizeAllowed(aWidth, aHeight))
-    return NS_ERROR_FAILURE;
+  nsIntRect newBounds = nsIntRect(aX, aY, aWidth, aHeight);
+  FitRectToVisibleAreaForScreen(newBounds, [mWindow screen]);
 
   nsIntRect windowBounds(nsCocoaUtils::CocoaRectToGeckoRect([mWindow frame]));
-  BOOL isMoving = (windowBounds.x != aX || windowBounds.y != aY);
-  BOOL isResizing = (windowBounds.width != aWidth || windowBounds.height != aHeight);
+  BOOL isMoving = (windowBounds.x != newBounds.x || windowBounds.y != newBounds.y);
+  BOOL isResizing = (windowBounds.width != newBounds.width || windowBounds.height != newBounds.height);
 
   if (IsResizing() || !mWindow || (!isMoving && !isResizing))
     return NS_OK;
-
-  mBounds = nsIntRect(aX, aY, aWidth, aHeight);
+  
+  mBounds = newBounds;
   NSRect newFrame = nsCocoaUtils::GeckoRectToCocoaRect(mBounds);
 
   // We have to report the size event -first-, to make sure that content
   // repositions itself.  Cocoa views are anchored at the bottom left,
   // so if we don't do this our child view will end up being stuck in the
   // wrong place during a resize.
   if (isResizing)
     ReportSizeEvent(&newFrame);
@@ -1166,20 +1167,17 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRIn
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
-  if (!WindowSizeAllowed(aWidth, aHeight))
-    return NS_ERROR_FAILURE;
-
+  
   nsIntRect windowBounds(nsCocoaUtils::CocoaRectToGeckoRect([mWindow frame]));
   return Resize(windowBounds.x, windowBounds.y, aWidth, aHeight, aRepaint);
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(nsIntRect &aRect)
 {
--- a/widget/tests/Makefile.in
+++ b/widget/tests/Makefile.in
@@ -76,22 +76,25 @@ include $(topsrcdir)/config/rules.mk
 		window_wheeltransaction.xul \
 		test_imestate.html \
 		window_imestate_iframes.html \
 		test_plugin_scroll_consistency.html \
 		test_composition_text_querycontent.xul \
 		window_composition_text_querycontent.xul \
 		test_input_events_on_deactive_window.xul \
 		$(NULL)
+		
+# test_bug413277.html mac-only based on 604789, 605178
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 _CHROME_FILES += native_menus_window.xul \
                test_native_menus.xul \
                native_mouse_mac_window.xul \
                test_native_mouse_mac.xul \
+               test_bug413277.html \
                test_bug428405.xul \
                test_bug466599.xul \
                test_bug485118.xul \
                test_bug522217.xul \
                window_bug522217.xul \
                test_platform_colors.xul \
                test_standalone_native_menu.xul \
                standalone_native_menu_window.xul \
new file mode 100644
--- /dev/null
+++ b/widget/tests/test_bug413277.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=413277
+-->
+<head>
+  <title>Test for Bug 413277</title>
+  <script type="text/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="text/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css"
+          href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=413277">Mozilla Bug 413277</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script class="testbody" type="application/javascript">
+  var atts='width=100, height=100, top=100, screenY=100';
+  atts += ', left=100, screenX=100, toolbar=no';
+  atts += ', location=no, directories=no, status=no';
+  atts += ', menubar=no, scrollbars=no, resizable=no';
+  var newWindow = window.open('_blank', 'win_name', atts);
+  
+  newWindow.resizeBy(1000000, 1000000);
+  SimpleTest.is(newWindow.outerWidth, newWindow.screen.availWidth, true);
+  SimpleTest.is(newWindow.outerHeight, newWindow.screen.availHeight, true);
+  SimpleTest.is(newWindow.screenY, newWindow.screen.availTop, true);
+  SimpleTest.is(newWindow.screenX, newWindow.screen.availLeft, true);
+  
+  newWindow.close();
+</script>
+</pre>
+</body>