Bug 635844 part 1: Back out bug 615501 since we'll no longer fire the "initial popstate" event, and thus don't need a way to differentiate it. r=jlebar a=beltzner
authorJonas Sicking <jonas@sicking.cc>
Mon, 28 Feb 2011 23:08:56 -0800
changeset 63195 d34e0e81327a059a1bb6773522bb1d13ef517a37
parent 63194 410519307e63e2e48b6c6d646fc8bf3750aa65f5
child 63196 9e139c2c0c25bcee4d9cb59cd33483297bc42db2
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersjlebar, beltzner
bugs635844, 615501
milestone2.0b13pre
Bug 635844 part 1: Back out bug 615501 since we'll no longer fire the "initial popstate" event, and thus don't need a way to differentiate it. r=jlebar a=beltzner
content/events/src/nsDOMPopStateEvent.cpp
content/events/src/nsDOMPopStateEvent.h
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsIContentViewer.idl
docshell/test/Makefile.in
docshell/test/file_bug615501.html
docshell/test/test_bug615501_1.html
docshell/test/test_bug615501_2.html
docshell/test/test_bug615501_3.html
dom/base/nsDOMClassInfo.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
dom/base/nsPIDOMWindow.h
dom/interfaces/events/Makefile.in
dom/interfaces/events/nsIDOMPopStateEvent.idl
dom/interfaces/events/nsIDOMPopStateEvent_MOZILLA_2_BRANCH.idl
layout/base/nsDocumentViewer.cpp
xpcom/base/nsError.h
--- a/content/events/src/nsDOMPopStateEvent.cpp
+++ b/content/events/src/nsDOMPopStateEvent.cpp
@@ -50,17 +50,16 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMPopStateEvent, nsDOMEvent)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mState)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 DOMCI_DATA(PopStateEvent, nsDOMPopStateEvent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMPopStateEvent)
   NS_INTERFACE_MAP_ENTRY(nsIDOMPopStateEvent)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMPopStateEvent_MOZILLA_2_BRANCH)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PopStateEvent)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
 
 nsDOMPopStateEvent::~nsDOMPopStateEvent()
 {
 }
 
 NS_IMETHODIMP
@@ -72,39 +71,20 @@ nsDOMPopStateEvent::GetState(nsIVariant 
 }
 
 NS_IMETHODIMP
 nsDOMPopStateEvent::InitPopStateEvent(const nsAString &aTypeArg,
                                       PRBool aCanBubbleArg,
                                       PRBool aCancelableArg,
                                       nsIVariant *aStateArg)
 {
-  return InitPopStateEvent(aTypeArg, aCanBubbleArg, aCancelableArg, aStateArg, PR_FALSE);
-}
-
-NS_IMETHODIMP
-nsDOMPopStateEvent::InitPopStateEvent(const nsAString &aTypeArg,
-                                      PRBool aCanBubbleArg,
-                                      PRBool aCancelableArg,
-                                      nsIVariant *aStateArg,
-                                      PRBool aIsInitial)
-{
   nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mState = aStateArg;
-  mIsInitial = aIsInitial;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMPopStateEvent::GetInitial(PRBool *aOut)
-{
-  NS_ENSURE_ARG_POINTER(aOut);
-  *aOut = mIsInitial;
   return NS_OK;
 }
 
 nsresult NS_NewDOMPopStateEvent(nsIDOMEvent** aInstancePtrResult,
                                 nsPresContext* aPresContext,
                                 nsEvent* aEvent)
 {
   nsDOMPopStateEvent* event =
--- a/content/events/src/nsDOMPopStateEvent.h
+++ b/content/events/src/nsDOMPopStateEvent.h
@@ -33,43 +33,39 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsDOMPopStateEvent_h__
 #define nsDOMPopStateEvent_h__
 
 class nsEvent;
 
 #include "nsIDOMPopStateEvent.h"
-#include "nsIDOMPopStateEvent_MOZILLA_2_BRANCH.h"
 #include "nsDOMEvent.h"
 #include "nsIVariant.h"
 #include "nsCycleCollectionParticipant.h"
 
 class nsDOMPopStateEvent : public nsDOMEvent,
-                           public nsIDOMPopStateEvent,
-                           public nsIDOMPopStateEvent_MOZILLA_2_BRANCH
+                           public nsIDOMPopStateEvent
 {
 public:
   nsDOMPopStateEvent(nsPresContext* aPresContext, nsEvent* aEvent)
     : nsDOMEvent(aPresContext, aEvent)  // state
   {
   }
 
   virtual ~nsDOMPopStateEvent();
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMPopStateEvent, nsDOMEvent)
 
   NS_DECL_NSIDOMPOPSTATEEVENT
-  NS_DECL_NSIDOMPOPSTATEEVENT_MOZILLA_2_BRANCH
 
   NS_FORWARD_TO_NSDOMEVENT
 
 protected:
   nsCOMPtr<nsIVariant> mState;
-  PRBool mIsInitial;
 };
 
 nsresult NS_NewDOMPopStateEvent(nsIDOMEvent** aInstancePtrResult,
                                 nsPresContext* aPresContext,
                                 nsEvent* aEvent);
 
 #endif // nsDOMPopStateEvent_h__
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -6072,37 +6072,17 @@ nsDocShell::EndPageLoad(nsIWebProgress *
     // Notify the ContentViewer that the Document has finished loading.  This
     // will cause any OnLoad(...) and PopState(...) handlers to fire.
     if (!mEODForCurrentDocument && mContentViewer) {
         // Set the pending state object which will be returned to the page in
         // the popstate event.
         SetDocCurrentStateObj(mLSHE);
 
         mIsExecutingOnLoadHandler = PR_TRUE;
-        rv = mContentViewer->LoadComplete(aStatus);
-
-        // If the load wasn't stopped during LoadComplete, fire the popstate
-        // event, if we're not suppressing it.
-        if (NS_SUCCEEDED(rv) && rv != NS_SUCCESS_LOAD_STOPPED &&
-            !mSuppressPopstate) {
-
-            // XXX should I get the window via mScriptGlobal?  This is tricky
-            // since we're near onload and things might be changing.  But I
-            // think mContentViewer has the right view of the world.
-            nsCOMPtr<nsIDocument> document = mContentViewer->GetDocument();
-            if (document) {
-                nsCOMPtr<nsPIDOMWindow> window = document->GetWindow();
-                if (window) {
-                    // Dispatch the popstate event , passing PR_TRUE to indicate
-                    // that this is an "initial" (i.e. after-onload) popstate.
-                    window->DispatchSyncPopState(PR_TRUE);
-                }
-            }
-        }
-
+        mContentViewer->LoadComplete(aStatus);
         mIsExecutingOnLoadHandler = PR_FALSE;
 
         mEODForCurrentDocument = PR_TRUE;
 
         // If all documents have completed their loading
         // favor native event dispatch priorities
         // over performance
         if (--gNumberOfDocumentsLoading == 0) {
@@ -8244,21 +8224,17 @@ nsDocShell::InternalLoad(nsIURI * aURI,
         // reset loadType so we don't have to add lots of tests for
         // LOAD_NORMAL_EXTERNAL after this point
         aLoadType = LOAD_NORMAL;
     }
 
     mAllowKeywordFixup =
       (aFlags & INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) != 0;
     mURIResultedInDocument = PR_FALSE;  // reset the clock...
-
-    // If we've gotten this far, reset our "don't fire a popState" flag.  This
-    // will get set to true the next time someone calls push/replaceState.
-    mSuppressPopstate = PR_FALSE;
-
+   
     //
     // First:
     // Check to see if the new URI is an anchor in the existing document.
     // Skip this check if we're doing some sort of abnormal load, if the
     // new load is a non-history load and has postdata, or if we're doing
     // a history load and the page identifiers of mOSHE and aSHEntry
     // don't match.
     //
@@ -8448,22 +8424,17 @@ nsDocShell::InternalLoad(nsIURI * aURI,
                 doc->SetDocumentURI(newURI);
             }
 
             SetDocCurrentStateObj(mOSHE);
 
             // Dispatch the popstate and hashchange events, as appropriate.
             nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mScriptGlobal);
             if (window) {
-                NS_ASSERTION(!mSuppressPopstate,
-                             "Popstate shouldn't be suppressed here.");
-
-                // Pass PR_FALSE to indicate that this is not an "initial" (i.e.
-                // after-onload) popstate.
-                window->DispatchSyncPopState(PR_FALSE);
+                window->DispatchSyncPopState();
 
                 if (doHashchange)
                   window->DispatchAsyncHashchange();
             }
 
             return NS_OK;
         }
     }
@@ -9853,20 +9824,16 @@ nsDocShell::AddState(nsIVariant *aData, 
         document->SetDocumentURI(newURI);
 
         AddURIVisit(newURI, oldURI, oldURI, 0);
     }
     else {
         FireDummyOnLocationChange();
     }
 
-    // A call to push/replaceState prevents popstate events from firing until
-    // the next time we call InternalLoad.
-    mSuppressPopstate = PR_TRUE;
-
     return NS_OK;
 }
 
 PRBool
 nsDocShell::ShouldAddToSessionHistory(nsIURI * aURI)
 {
     // I believe none of the about: urls should go in the history. But then
     // that could just be me... If the intent is only deny about:blank then we
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -818,19 +818,16 @@ protected:
 
     // Indicates to CreateContentViewer() that it is safe to cache the old
     // presentation of the page, and to SetupNewViewer() that the old viewer
     // should be passed a SHEntry to save itself into.
     PRPackedBool               mSavingOldViewer;
 
     // @see nsIDocShellHistory::createdDynamically
     PRPackedBool               mDynamicallyCreated;
-
-    // If this is true, we won't fire a popstate event.
-    PRPackedBool               mSuppressPopstate;
 #ifdef DEBUG
     PRPackedBool               mInEnsureScriptEnv;
 #endif
     PRUint64                   mHistoryID;
 
     static nsIURIFixup *sURIFixup;
 
 #ifdef DEBUG
--- a/docshell/base/nsIContentViewer.idl
+++ b/docshell/base/nsIContentViewer.idl
@@ -20,21 +20,16 @@ interface nsIContentViewer : nsISupports
 {
 
   [noscript] void init(in nsIWidgetPtr aParentWidget,
                        [const] in nsIntRectRef aBounds);
 
   attribute nsISupports container;
 
   void loadStart(in nsISupports aDoc);
-
-  /**
-   * On success, returns NS_SUCCESS_LOAD_STOPPED if the load was stopped by the
-   * end of the method, and NS_OK otherwise.
-   */
   void loadComplete(in unsigned long aStatus);
 
   /**
    * Checks if the document wants to prevent unloading by firing beforeunload on
    * the document, and if it does, prompts the user. The result is returned.
    *
    * @param aCallerClosesWindow indicates that the current caller will close the
    *        window. If the method returns true, all subsequent calls will be
--- a/docshell/test/Makefile.in
+++ b/docshell/test/Makefile.in
@@ -88,20 +88,16 @@ include $(topsrcdir)/config/rules.mk
 		test_bug540462.html \
 		file_bug540462.html \
 		test_bug580069.html \
 		file_bug580069_1.html \
 		file_bug580069_2.sjs \
 		test_bug590573.html \
 		file_bug590573_1.html \
 		file_bug590573_2.html \
-		test_bug615501_1.html \
-		test_bug615501_2.html \
-		test_bug615501_3.html \
-		file_bug615501.html \
 		test_bug634834.html \
 		file_bug634834.html \
 		$(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 _TEST_FILES += \
 		test_bug511449.html \
 		file_bug511449.html \
deleted file mode 100644
--- a/docshell/test/file_bug615501.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<html>
-<head>
-
-<script>
-addEventListener('DOMContentLoaded', function() {
-  (opener || parent).innerDOMContentLoaded();
-}, false);
-
-addEventListener('load', function() {
-  (opener || parent).innerLoad();
-}, false);
-
-addEventListener('popstate', function(e) {
-  (opener || parent).innerPopstate(e);
-}, false);
-</script>
-
-</head>
-
-<body>
-
-</body>
-</html>
deleted file mode 100644
--- a/docshell/test/test_bug615501_1.html
+++ /dev/null
@@ -1,56 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=615501
--->
-<head>
-  <title>Test for Bug 615501</title>
-  <script type="application/javascript" src="/MochiKit/packed.js"></script>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=615501">Mozilla Bug 615501</a>
-
-<iframe id='iframe' src='file_bug615501.html'></iframe>
-
-<script type="application/javascript;version=1.7">
-
-/** Test for Bug 615501 **/
-
-SimpleTest.waitForExplicitFinish();
-
-// This is the same as test_bug615501_2.html, except it calls pushState
-// instead of replaceState.
-
-// Called by inner frame on DOMContentLoaded.
-function innerDOMContentLoaded() {
-  ok(true, "Got DOMContentLoaded event.");
-  $('iframe').contentWindow.history.pushState('', '', '');
-}
-
-// Called by inner frame on load.
-function innerLoad() {
-  ok(true, "Got load event.");
-
-  // Spin the event loop a few times to give popstate a chance to fire, then
-  // declare that we're done.
-  setTimeout(function(count) {
-    if (count > 0) {
-      setTimeout(arguments.callee, 0, count-1);
-    }
-    else {
-      SimpleTest.finish();
-    }
-  }, 0, 10);
-
-}
-
-// Called by inner frame on popstate.
-function innerPopstate() {
-  ok(false, "Shouldn't get a popstate.");
-}
-</script>
-
-</body>
-</html>
deleted file mode 100644
--- a/docshell/test/test_bug615501_2.html
+++ /dev/null
@@ -1,56 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=615501
--->
-<head>
-  <title>Test for Bug 615501</title>
-  <script type="application/javascript" src="/MochiKit/packed.js"></script>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=615501">Mozilla Bug 615501</a>
-
-<iframe id='iframe' src='file_bug615501.html'></iframe>
-
-<script type="application/javascript;version=1.7">
-
-/** Test for Bug 615501 **/
-
-// This is the same as test_bug615501_1.html, except it calls replaceState
-// instead of pushState.
-
-SimpleTest.waitForExplicitFinish();
-
-// Called by inner frame on DOMContentLoaded.
-function innerDOMContentLoaded() {
-  ok(true, "Got DOMContentLoaded event.");
-  $('iframe').contentWindow.history.replaceState('', '', '');
-}
-
-// Called by inner frame on load.
-function innerLoad() {
-  ok(true, "Got load event.");
-
-  // Spin the event loop a few times to give popstate a chance to fire, then
-  // declare that we're done.
-  setTimeout(function(count) {
-    if (count > 0) {
-      setTimeout(arguments.callee, 0, count-1);
-    }
-    else {
-      SimpleTest.finish();
-    }
-  }, 0, 10);
-
-}
-
-// Called by inner frame on popstate.
-function innerPopstate() {
-  ok(false, "Shouldn't get a popstate.");
-}
-</script>
-
-</body>
-</html>
deleted file mode 100644
--- a/docshell/test/test_bug615501_3.html
+++ /dev/null
@@ -1,63 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=615501
--->
-<head>
-  <title>Test for Bug 615501</title>
-  <script type="application/javascript" src="/MochiKit/packed.js"></script>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=615501">Mozilla Bug 615501</a>
-
-<iframe id='iframe' src='file_bug615501.html'></iframe>
-
-<script type="application/javascript;version=1.7">
-
-/** Test for Bug 615501 **/
-
-SimpleTest.waitForExplicitFinish();
-
-// Called by inner frame on DOMContentLoaded.
-function innerDOMContentLoaded() {
-}
-
-// Called by inner frame on load.
-function innerLoad() {
-}
-
-// Called by inner frame on popstate.
-var numPopstates = 0;
-function innerPopstate(e) {
-  numPopstates++;
-
-  if (numPopstates == 1) {
-    // This is the inner frame's initial popstate.  Spin the event loop, then
-    // start the test.
-    ok(true, 'Got initial popstate.');
-    is(e.initial, true, 'Initial popstate should have .initial set to true.');
-    setTimeout(runTest, 0);
-  }
-  else {
-    is(e.initial, false, 'State-change popstate should have .initial set to false.');
-    is(e.state, '1', 'Correct state after back.');
-    SimpleTest.finish();
-  }
-}
-
-function runTest() {
-  var win = $('iframe').contentWindow;
-  win.history.replaceState('1', '1', '1');
-  win.history.pushState('2', '2', '2');
-  win.history.back();
-
-  // If back() is synchronous, this replaceState call won't cause us to cancel
-  // the popstate from the call to back.
-  win.history.replaceState('a', 'a', 'a');
-}
-
-</script>
-</body>
-</html>
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -83,17 +83,16 @@
 #include "nsIDOM3Document.h"
 #include "nsIDOMXMLDocument.h"
 #include "nsIDOMNSDocument.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMNSEvent.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsIDOMEventListener.h"
 #include "nsIDOMPopStateEvent.h"
-#include "nsIDOMPopStateEvent_MOZILLA_2_BRANCH.h"
 #include "nsContentUtils.h"
 #include "nsDOMWindowUtils.h"
 #include "nsIDOMGlobalPropertyInitializer.h"
 
 // Window scriptable helper includes
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeNode.h"
@@ -2494,17 +2493,16 @@ nsDOMClassInfo::Init()
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMDragEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMMouseEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSMouseEvent)
     DOM_CLASSINFO_UI_EVENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(PopStateEvent, nsIDOMPopStateEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMPopStateEvent)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMPopStateEvent_MOZILLA_2_BRANCH)
     DOM_CLASSINFO_EVENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(HTMLDocument, nsIDOMHTMLDocument)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLDocument)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLDocument)
     DOM_CLASSINFO_DOCUMENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -114,17 +114,16 @@
 #include "nsIDOMElement.h"
 #include "nsIDOMDocumentEvent.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMHTMLAnchorElement.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsIDOMMessageEvent.h"
 #include "nsIDOMPopupBlockedEvent.h"
 #include "nsIDOMPopStateEvent.h"
-#include "nsIDOMPopStateEvent_MOZILLA_2_BRANCH.h"
 #include "nsIDOMOfflineResourceList.h"
 #include "nsIDOMGeoGeolocation.h"
 #include "nsIDOMDesktopNotification.h"
 #include "nsPIDOMStorage.h"
 #include "nsDOMString.h"
 #include "nsIEmbeddingSiteWindow2.h"
 #include "nsThreadUtils.h"
 #include "nsIEventStateManager.h"
@@ -7694,19 +7693,19 @@ nsGlobalWindow::FireHashchange()
   // Dispatch the hashchange event, which doesn't bubble and isn't cancelable,
   // to the outer window.
   return nsContentUtils::DispatchTrustedEvent(mDoc, GetOuterWindow(),
                                               NS_LITERAL_STRING("hashchange"),
                                               PR_FALSE, PR_FALSE);
 }
 
 nsresult
-nsGlobalWindow::DispatchSyncPopState(PRBool aIsInitial)
-{
-  FORWARD_TO_INNER(DispatchSyncPopState, (aIsInitial), NS_OK);
+nsGlobalWindow::DispatchSyncPopState()
+{
+  FORWARD_TO_INNER(DispatchSyncPopState, (), NS_OK);
 
   NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
                "Must be safe to run script here.");
 
   // Check that PopState hasn't been pref'ed off.
   if (!nsContentUtils::GetBoolPref(sPopStatePrefStr, PR_FALSE))
     return NS_OK;
 
@@ -7742,36 +7741,34 @@ nsGlobalWindow::DispatchSyncPopState(PRB
                                       NS_LITERAL_STRING("popstateevent"),
                                       getter_AddRefs(domEvent));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(domEvent);
   NS_ENSURE_TRUE(privateEvent, NS_ERROR_FAILURE);
 
   // Initialize the popstate event, which does bubble but isn't cancellable.
-  nsCOMPtr<nsIDOMPopStateEvent_MOZILLA_2_BRANCH> popstateEvent =
-    do_QueryInterface(domEvent);
+  nsCOMPtr<nsIDOMPopStateEvent> popstateEvent = do_QueryInterface(domEvent);
   rv = popstateEvent->InitPopStateEvent(NS_LITERAL_STRING("popstate"),
                                         PR_TRUE, PR_FALSE,
-                                        stateObj,
-                                        aIsInitial);
+                                        stateObj);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = privateEvent->SetTrusted(PR_TRUE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMEventTarget> outerWindow =
     do_QueryInterface(GetOuterWindow());
   NS_ENSURE_TRUE(outerWindow, NS_ERROR_UNEXPECTED);
 
   rv = privateEvent->SetTarget(outerWindow);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool dummy; // default action
-  return DispatchEvent(domEvent, &dummy);
+  return DispatchEvent(popstateEvent, &dummy);
 }
 
 // Find an nsICanvasFrame under aFrame.  Only search the principal
 // child lists.  aFrame must be non-null.
 static nsCanvasFrame* FindCanvasFrame(nsIFrame* aFrame)
 {
     nsCanvasFrame* canvasFrame = do_QueryFrame(aFrame);
     if (canvasFrame) {
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -544,17 +544,17 @@ public:
   virtual NS_HIDDEN_(void)
     CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey,
                              nsScriptObjectHolder& aHandler);
 
   virtual PRBool TakeFocus(PRBool aFocus, PRUint32 aFocusMethod);
   virtual void SetReadyForFocus();
   virtual void PageHidden();
   virtual nsresult DispatchAsyncHashchange();
-  virtual nsresult DispatchSyncPopState(PRBool aIsInitial);
+  virtual nsresult DispatchSyncPopState();
 
   virtual nsresult SetArguments(nsIArray *aArguments, nsIPrincipal *aOrigin);
 
   static PRBool DOMWindowDumpEnabled();
 
   void MaybeForgiveSpamCount();
   PRBool IsClosedOrClosing() {
     return (mIsClosed ||
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -526,20 +526,18 @@ public:
   /**
    * Instructs this window to asynchronously dispatch a hashchange event.  This
    * method must be called on an inner window.
    */
   virtual nsresult DispatchAsyncHashchange() = 0;
 
   /**
    * Instructs this window to synchronously dispatch a popState event.
-   * aIsInitial should be true if the event corresponds to a popState fired
-   * immediately after onload and false otherwise.
    */
-  virtual nsresult DispatchSyncPopState(PRBool aIsInitial) = 0;
+  virtual nsresult DispatchSyncPopState() = 0;
 
   /**
    * Tell this window that there is an observer for orientation changes
    */
   virtual void SetHasOrientationEventListener() = 0;
 
   /**
    * Set a arguments for this window. This will be set on the window
--- a/dom/interfaces/events/Makefile.in
+++ b/dom/interfaces/events/Makefile.in
@@ -81,13 +81,12 @@ XPIDLSRCS =					\
 	nsIDOMPaintRequestList.idl		\
 	nsIDOMSimpleGestureEvent.idl		\
 	nsIDOMNSMouseEvent.idl			\
 	nsIDOMMozTouchEvent.idl			\
 	nsIDOMOrientationEvent.idl              \
 	nsIDOMScrollAreaEvent.idl		\
 	nsIDOMTransitionEvent.idl		\
 	nsIDOMPopStateEvent.idl			\
-	nsIDOMPopStateEvent_MOZILLA_2_BRANCH.idl \
 	nsIDOMCloseEvent.idl			\
 	$(NULL)
 
 include $(topsrcdir)/config/rules.mk
--- a/dom/interfaces/events/nsIDOMPopStateEvent.idl
+++ b/dom/interfaces/events/nsIDOMPopStateEvent.idl
@@ -39,17 +39,13 @@ interface nsIVariant;
 [scriptable, uuid(f3834fd5-0ef5-4ccd-a741-0b6685414342)]
 interface nsIDOMPopStateEvent : nsIDOMEvent
 {
   /**
    * The state associated with this popstate event
    */
   readonly attribute nsIVariant state;
 
-  /**
-   * This function sets isInitial to false.  If you want to set isInitial to
-   * true, use the method in nsIDOMPopStateEvent_MOZILLA_2_BRANCH.
-   */
-  [noscript] void initPopStateEvent(in DOMString typeArg,
-                                    in boolean canBubbleArg,
-                                    in boolean cancelableArg,
-                                    in nsIVariant stateArg);
+  void initPopStateEvent(in DOMString typeArg,
+                         in boolean canBubbleArg,
+                         in boolean cancelableArg,
+                         in nsIVariant stateArg);
 };
deleted file mode 100644
--- a/dom/interfaces/events/nsIDOMPopStateEvent_MOZILLA_2_BRANCH.idl
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * the Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Ms2ger <ms2ger@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsIDOMPopStateEvent.idl"
-
-[scriptable, uuid(a0273086-e5da-4da6-a219-930235f9bfef)]
-interface nsIDOMPopStateEvent_MOZILLA_2_BRANCH : nsISupports
-{
-  /**
-   * initial is true if the event is being fired due to an onload, and false
-   * otherwise.
-   */
-  readonly attribute boolean initial;
-
-  void initPopStateEvent(in DOMString typeArg,
-                         in boolean canBubbleArg,
-                         in boolean cancelableArg,
-                         in nsIVariant stateArg,
-                         [optional] in boolean isInitial);
-};
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -1013,16 +1013,17 @@ DocumentViewerImpl::LoadComplete(nsresul
   // Note that this could destroy the window, so do this before
   // checking for our mDocument and its window.
   if (mPresShell && !mStopped) {
     // Hold strong ref because this could conceivably run script
     nsCOMPtr<nsIPresShell> shell = mPresShell;
     shell->FlushPendingNotifications(Flush_Layout);
   }
 
+  nsresult rv = NS_OK;
   NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
 
   // First, get the window from the document...
   nsPIDOMWindow *window = mDocument->GetWindow();
 
   mLoaded = PR_TRUE;
 
   // Now, fire either an OnLoad or OnError event to the document...
@@ -1108,17 +1109,21 @@ DocumentViewerImpl::LoadComplete(nsresul
     mPrintIsPending        = PR_FALSE;
     mPrintDocIsFullyLoaded = PR_TRUE;
     Print(mCachedPrintSettings, mCachedPrintWebProgressListner);
     mCachedPrintSettings           = nsnull;
     mCachedPrintWebProgressListner = nsnull;
   }
 #endif
 
-  return mStopped ? NS_SUCCESS_LOAD_STOPPED : NS_OK;
+  if (!mStopped && window) {
+    window->DispatchSyncPopState();
+  }
+
+  return rv;
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::PermitUnload(PRBool aCallerClosesWindow, PRBool *aPermitUnload)
 {
   *aPermitUnload = PR_TRUE;
 
   if (!mDocument || mInPermitUnload || mCallerIsClosingWindow) {
--- a/xpcom/base/nsError.h
+++ b/xpcom/base/nsError.h
@@ -313,22 +313,16 @@ inline int NS_SUCCEEDED(nsresult _nsresu
 #define NS_ERROR_NOT_SAME_THREAD                NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM,  4)
 
 /**
  * Various operations are not permitted during XPCOM shutdown and will fail
  * with this exception.
  */
 #define NS_ERROR_ILLEGAL_DURING_SHUTDOWN        NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 30)
 
-/**
- * Returned by DocumentViewerImpl::LoadComplete when the function completes
- * successfully but mStopped is true at the end.
- */
-#define NS_SUCCESS_LOAD_STOPPED                 NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 1)
-
  /*
   * This will return the nsresult corresponding to the most recent NSPR failure
   * returned by PR_GetError.
   *
   ***********************************************************************
   *      Do not depend on this function. It will be going away!
   ***********************************************************************
   */