Merge last green changeset from inbound to mozilla-central
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 26 Mar 2012 11:18:15 -0700
changeset 93610 a30fd69f1e0c75ba46caaf37ad45e2b8f3bc776c
parent 93589 ba4983d9c1f9de34648146b7189edf9a294b8ff6 (current diff)
parent 93609 5a0fa83685d7e94142f6fd41ee642c0dfd0da857 (diff)
child 93611 df8ac2a1ecdd3223a110a15ee717b3ce6882effa
child 94020 9b5e28881542f73f63abd5434e0603a97f28384a
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge last green changeset from inbound to mozilla-central
accessible/tests/mochitest/hittest/test_general.xul
layout/mathml/nsMathMLForeignFrameWrapper.cpp
layout/mathml/nsMathMLForeignFrameWrapper.h
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -1347,48 +1347,45 @@ nsAccessible::GetAttributes(nsIPersisten
   }
 
   return NS_OK;
 }
 
 nsresult
 nsAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
 {
+  // If the accessible isn't primary for its node (such as list item bullet or
+  // xul tree item then don't calculate content based attributes.
+  if (!IsPrimaryForNode())
+    return NS_OK;
+
   // Attributes set by this method will not be used to override attributes on a sub-document accessible
   // when there is a <frame>/<iframe> element that spawned the sub-document
-  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mContent));
-
-  nsAutoString tagName;
-  element->GetTagName(tagName);
-  if (!tagName.IsEmpty()) {
-    nsAutoString oldValueUnused;
-    aAttributes->SetStringProperty(NS_LITERAL_CSTRING("tag"), tagName,
-                                   oldValueUnused);
-  }
 
   nsEventShell::GetEventAttributes(GetNode(), aAttributes);
  
   // Expose class because it may have useful microformat information
   // Let the class from an iframe's document be exposed, don't override from <iframe class>
   nsAutoString _class;
   if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, _class))
     nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::_class, _class);
 
   // Get container-foo computed live region properties based on the closest container with
   // the live region attribute. 
   // Inner nodes override outer nodes within the same document --
   //   The inner nodes can be used to override live region behavior on more general outer nodes
   // However, nodes in outer documents override nodes in inner documents:
   //   Outer doc author may want to override properties on a widget they used in an iframe
-  nsIContent *startContent = mContent;
-  while (true) {
-    NS_ENSURE_STATE(startContent);
-    nsIDocument *doc = startContent->GetDocument();
+  nsIContent* startContent = mContent;
+  while (startContent) {
+    nsIDocument* doc = startContent->GetDocument();
     nsIContent* rootContent = nsCoreUtils::GetRoleContent(doc);
-    NS_ENSURE_STATE(rootContent);
+    if (!rootContent)
+      return NS_OK;
+
     nsAccUtils::SetLiveContainerAttributes(aAttributes, startContent,
                                            rootContent);
 
     // Allow ARIA live region markup from outer documents to override
     nsCOMPtr<nsISupports> container = doc->GetContainer(); 
     nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
       do_QueryInterface(container);
     if (!docShellTreeItem)
@@ -1404,31 +1401,35 @@ nsAccessible::GetAttributesInternal(nsIP
       break;
 
     startContent = parentDoc->FindContentForSubDocument(doc);      
   }
 
   if (!mContent->IsElement())
     return NS_OK;
 
+  // Expose tag.
+  nsAutoString tagName;
+  mContent->NodeInfo()->GetName(tagName);
+  nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::tag, tagName);
+
   // Expose draggable object attribute?
   nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(mContent);
   if (htmlElement) {
     bool draggable = false;
     htmlElement->GetDraggable(&draggable);
     if (draggable) {
       nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::draggable,
                              NS_LITERAL_STRING("true"));
     }
   }
 
   // Don't calculate CSS-based object attributes when no frame (i.e.
-  // the accessible is not unattached form three) or when the accessible is not
-  // primary for node (like list bullet or XUL tree items).
-  if (!mContent->GetPrimaryFrame() || !IsPrimaryForNode())
+  // the accessible is unattached from the tree).
+  if (!mContent->GetPrimaryFrame())
     return NS_OK;
 
   // CSS style based object attributes.
   nsAutoString value;
   StyleInfo styleInfo(mContent->AsElement(), mDoc->PresShell());
 
   // Expose 'display' attribute.
   styleInfo.Display(value);
--- a/accessible/src/xul/nsXULTreeAccessible.cpp
+++ b/accessible/src/xul/nsXULTreeAccessible.cpp
@@ -224,20 +224,20 @@ nsXULTreeAccessible::ChildAtPoint(PRInt3
     return nsnull;
 
   nsPresContext *presContext = frame->PresContext();
   nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
 
   nsIFrame *rootFrame = presShell->GetRootFrame();
   NS_ENSURE_TRUE(rootFrame, nsnull);
 
-  nsIntRect rootRect = rootFrame->GetScreenRectExternal();
+  nsIntRect rootRect = rootFrame->GetScreenRect();
 
-  PRInt32 clientX = presContext->DevPixelsToIntCSSPixels(aX - rootRect.x);
-  PRInt32 clientY = presContext->DevPixelsToIntCSSPixels(aY - rootRect.y);
+  PRInt32 clientX = presContext->DevPixelsToIntCSSPixels(aX) - rootRect.x;
+  PRInt32 clientY = presContext->DevPixelsToIntCSSPixels(aY) - rootRect.y;
 
   PRInt32 row = -1;
   nsCOMPtr<nsITreeColumn> column;
   nsCAutoString childEltUnused;
   mTree->GetCellAt(clientX, clientY, &row, getter_AddRefs(column),
                    childEltUnused);
 
   // If we failed to find tree cell for the given point then it might be
--- a/accessible/src/xul/nsXULTreeGridAccessible.cpp
+++ b/accessible/src/xul/nsXULTreeGridAccessible.cpp
@@ -701,20 +701,20 @@ nsXULTreeGridRowAccessible::ChildAtPoint
     return nsnull;
 
   nsPresContext *presContext = frame->PresContext();
   nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
 
   nsIFrame *rootFrame = presShell->GetRootFrame();
   NS_ENSURE_TRUE(rootFrame, nsnull);
 
-  nsIntRect rootRect = rootFrame->GetScreenRectExternal();
+  nsIntRect rootRect = rootFrame->GetScreenRect();
 
-  PRInt32 clientX = presContext->DevPixelsToIntCSSPixels(aX - rootRect.x);
-  PRInt32 clientY = presContext->DevPixelsToIntCSSPixels(aY - rootRect.y);
+  PRInt32 clientX = presContext->DevPixelsToIntCSSPixels(aX) - rootRect.x;
+  PRInt32 clientY = presContext->DevPixelsToIntCSSPixels(aY) - rootRect.y;
 
   PRInt32 row = -1;
   nsCOMPtr<nsITreeColumn> column;
   nsCAutoString childEltUnused;
   mTree->GetCellAt(clientX, clientY, &row, getter_AddRefs(column),
                    childEltUnused);
 
   // Return if we failed to find tree cell in the row for the given point.
--- a/accessible/tests/mochitest/attributes/test_obj.html
+++ b/accessible/tests/mochitest/attributes/test_obj.html
@@ -100,16 +100,20 @@ https://bugzilla.mozilla.org/show_bug.cg
       if (WIN) {
         var gfxInfo = Components.classes["@mozilla.org/gfx/info;1"].
           getService(Components.interfaces.nsIGfxInfo);
         var attrs = {
           "D2D": (gfxInfo.D2DEnabled ? "true" : "false")
         }
         testAttrs(getApplicationAccessible(), attrs, false);
       }
+
+      // no object attributes
+      testAbsentAttrs(getAccessible("listitem").firstChild, { "tag": "" });
+
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
 <body>
@@ -188,10 +192,14 @@ https://bugzilla.mozilla.org/show_bug.cg
   <input id="checkbox" type="checkbox"/>
   <div id="draggable" draggable="true">Draggable div</div>
   <table>
     <tr>
       <th id="th1"><abbr title="Social Security Number">SS#</abbr></th>
       <th id="th2" abbr="SS#" axis="social">Social Security Number</th>
     </tr>
   </table>
+
+  <ul>
+    <li id="listitem">item
+  </ul>
 </body>
 </html>
--- a/accessible/tests/mochitest/attributes/test_obj_css.html
+++ b/accessible/tests/mochitest/attributes/test_obj_css.html
@@ -1,28 +1,52 @@
 <html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=439566
-https://bugzilla.mozilla.org/show_bug.cgi?id=460932
-https://bugzilla.mozilla.org/show_bug.cgi?id=689540
--->
 <head>
   <title>CSS-like attributes tests</title>
   <link rel="stylesheet" type="text/css"
         href="chrome://mochikit/content/tests/SimpleTest/test.css" />
 
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 
   <script type="application/javascript"
           src="../common.js"></script>
   <script type="application/javascript"
           src="../attributes.js"></script>
+  <script type="application/javascript"
+          src="../events.js"></script>
 
   <script type="application/javascript">
+    var gQueue = null;
+
+    function removeElm(aID)
+    {
+      this.node = getNode(aID);
+      this.accessible = getAccessible(aID);
+
+      this.eventSeq = [
+        new invokerChecker(EVENT_HIDE, this.accessible)
+      ];
+
+      this.invoke = function removeElm_invoke()
+      {
+        this.node.parentNode.removeChild(this.node);
+      }
+
+      this.check = function removeElm_check()
+      {
+        testAbsentCSSAttrs(this.accessible);
+      }
+
+      this.getID = function removeElm_getID()
+      {
+        return "test CSS-based attributes on removed accessible";
+      }
+    }
+
     function doTest()
     {
       // CSS display
       testCSSAttrs("display_block");
       testCSSAttrs("display_inline");
       testCSSAttrs("display_inline-block");
       testCSSAttrs("display_list-item");
       testCSSAttrs("display_table");
@@ -80,17 +104,19 @@ https://bugzilla.mozilla.org/show_bug.cg
       testCSSAttrs("input");
       testCSSAttrs("table");
       testCSSAttrs("tr");
       testCSSAttrs("td");
 
       // no CSS-based object attributes
       testAbsentCSSAttrs(getAccessible("listitem").firstChild);
 
-      SimpleTest.finish();
+      gQueue = new eventQueue();
+      gQueue.push(new removeElm("div"));
+      gQueue.invoke(); // SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
 <body>
 
--- a/accessible/tests/mochitest/browser.js
+++ b/accessible/tests/mochitest/browser.js
@@ -93,31 +93,16 @@ function urlbarInput()
 /**
  * Return reload button.
  */
 function reloadButton()
 {
   return browserWindow().document.getElementById("urlbar-reload-button");
 }
 
-/**
- * Zoom the given document.
- */
-function zoomDocument(aDocument, aZoom)
-{
-  var docShell = aDocument.defaultView.
-    QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-    getInterface(Components.interfaces.nsIWebNavigation).
-    QueryInterface(Components.interfaces.nsIDocShell);
-  var docViewer = docShell.contentViewer.
-    QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
-
-  docViewer.fullZoom = aZoom;
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 // private section
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 var gBrowserContext =
 {
   browserWnd: null,
--- a/accessible/tests/mochitest/common.js
+++ b/accessible/tests/mochitest/common.js
@@ -110,16 +110,31 @@ function addA11yLoadEvent(aFunc, aWindow
       },
       0
     );
   }
 
   SimpleTest.waitForFocus(waitForDocLoad, aWindow);
 }
 
+/**
+ * Analogy of SimpleTest.is function used to compare objects.
+ */
+function isObject(aObj, aExpectedObj, aMsg)
+{
+  if (aObj == aExpectedObj) {
+    ok(true, aMsg);
+    return;
+  }
+
+  ok(false,
+     aMsg + " - got '" + prettyName(aObj) +
+            "', expected '" + prettyName(aExpectedObj) + "'");
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // Helpers for getting DOM node/accessible
 
 /**
  * Return the DOM node by identifier (may be accessible, DOM node or ID).
  */
 function getNode(aAccOrNodeOrID)
 {
--- a/accessible/tests/mochitest/elm/test_landmarks.html
+++ b/accessible/tests/mochitest/elm/test_landmarks.html
@@ -29,22 +29,22 @@
 
       // Some AT may look for this
       testAttrs("nav", {"xml-roles" : "navigation"}, true);
       testAttrs("footer", {"xml-roles" : "contentinfo"}, true);
       testAttrs("aside", {"xml-roles" : "complementary"}, true);
       testAttrs("main", {"xml-roles" : "main"}, true); // ARIA override
 
       // And some AT may look for this
-      testAttrs("nav", {"tag" : "NAV"}, true);
-      testAttrs("header", {"tag" : "HEADER"}, true);
-      testAttrs("footer", {"tag" : "FOOTER"}, true);
-      testAttrs("article", {"tag" : "ARTICLE"}, true);
-      testAttrs("aside", {"tag" : "ASIDE"}, true);
-      testAttrs("main", {"tag" : "ARTICLE"}, true); // no override expected
+      testAttrs("nav", {"tag" : "nav"}, true);
+      testAttrs("header", {"tag" : "header"}, true);
+      testAttrs("footer", {"tag" : "footer"}, true);
+      testAttrs("article", {"tag" : "article"}, true);
+      testAttrs("aside", {"tag" : "aside"}, true);
+      testAttrs("main", {"tag" : "article"}, true); // no override expected
 
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
--- a/accessible/tests/mochitest/hittest/Makefile.in
+++ b/accessible/tests/mochitest/hittest/Makefile.in
@@ -43,14 +43,15 @@ VPATH		= @srcdir@
 relativesrcdir  = accessible/hittest
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = \
 		test_browser.html \
 		test_general.html \
-		test_general.xul \
+		test_zoom_tree.xul \
 		test_zoom.html \
+		zoom_tree.xul \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
--- a/accessible/tests/mochitest/hittest/test_general.html
+++ b/accessible/tests/mochitest/hittest/test_general.html
@@ -14,53 +14,46 @@
 
   <script type="application/javascript">
     function doTest()
     {
       // Not specific case, child and deepchild testing.
       var list = getAccessible("list");
       var listitem = getAccessible("listitem");
       var image = getAccessible("image");
-      testChildAtPoint(list, 1, 1, false, listitem);
-      testChildAtPoint(list, 1, 1, true, image.firstChild);
+      testChildAtPoint(list, 1, 1, listitem, image.firstChild);
 
       // ::MustPrune case (in this case childAtPoint doesn't look inside a
       // textbox), point is inside of textbox.
       var txt = getAccessible("txt");
-      testChildAtPoint(txt, 1, 1, false, txt);
-      testChildAtPoint(txt, 1, 1, true, txt);
+      testChildAtPoint(txt, 1, 1, txt, txt);
 
       // ::MustPrune case, point is outside of textbox accessible but is in
       // document.
-      testChildAtPoint(txt, -1, 1, false, null);
-      testChildAtPoint(txt, -1, 1, true, null);
+      testChildAtPoint(txt, -1, 1, null, null);
 
       // ::MustPrune case, point is outside of root accessible.
-      testChildAtPoint(txt, -10000, 10000, false, null);
-      testChildAtPoint(txt, -10000, 10000, true, null);
+      testChildAtPoint(txt, -10000, 10000, null, null);
 
       // Not specific case, point is inside of btn accessible.
       var btn = getAccessible("btn");
       var btnText = btn.firstChild;
-      testChildAtPoint(btn, 1, 1, false, btnText);
-      testChildAtPoint(btn, 1, 1, true, btnText);
+      testChildAtPoint(btn, 1, 1, btnText, btnText);
   
       // Not specific case, point is outside of btn accessible.
-      testChildAtPoint(btn, -1, 1, false, null);
-      testChildAtPoint(btn, -1, 1, true, null);
+      testChildAtPoint(btn, -1, 1, null, null);
 
       // Out of flow accessible testing, do not return out of flow accessible
       // because it's not a child of the accessible even visually it is.
       var rectArea = getNode("area").getBoundingClientRect();
       var outOfFlow = getNode("outofflow");
       outOfFlow.style.left = rectArea.left + "px";
       outOfFlow.style.top = rectArea.top + "px";
 
-      testChildAtPoint("area", 1, 1, false, "area");
-      testChildAtPoint("area", 1, 1, true, "area");
+      testChildAtPoint("area", 1, 1, "area", "area");
 
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
rename from accessible/tests/mochitest/hittest/test_general.xul
rename to accessible/tests/mochitest/hittest/test_zoom_tree.xul
--- a/accessible/tests/mochitest/hittest/test_general.xul
+++ b/accessible/tests/mochitest/hittest/test_zoom_tree.xul
@@ -13,48 +13,89 @@
           src="../treeview.js" />
 
   <script type="application/javascript"
           src="../common.js" />
   <script type="application/javascript"
           src="../events.js" />
   <script type="application/javascript"
           src="../layout.js" />
+  <script type="application/javascript"
+          src="../browser.js" />
 
   <script type="application/javascript">
   <![CDATA[
     function doTest()
     {
-      hitTest("tree", "treecols", "col1");
+      var tabDocument = currentTabDocument();
+      var tabWindow = currentTabWindow();
+
+      var tree = tabDocument.getElementById("tree");
+      var treecols = tabDocument.getElementById("treecols");
+      var treecol1 = tabDocument.getElementById("treecol1");
+
+      // tree columns
+      hitTest(tree, treecols, treecol1);
+
+      // tree rows and cells
+      var treeBoxObject = tree.treeBoxObject;
+      var treeBodyBoxObj = tree.treeBoxObject.treeBody.boxObject;
+      var xObj = {}, yObj = {}, widthObj = {}, heightObj = {};
+      treeBoxObject.getCoordsForCellItem(1, tree.columns[0], "cell",
+                                         xObj, yObj, widthObj, heightObj);
 
+      var treeAcc = getAccessible(tree, [nsIAccessibleTable]);
+      var cellAcc = treeAcc.getCellAt(1, 0);
+      var rowAcc = cellAcc.parent;
+
+      var cssX = xObj.value + treeBodyBoxObj.x;
+      var cssY = yObj.value + treeBodyBoxObj.y;
+      var [x, y] = CSSToDevicePixels(tabWindow, cssX, cssY);
+
+      testChildAtPoint(treeAcc, x, y, rowAcc, cellAcc);
+      testChildAtPoint(rowAcc, x, y, cellAcc, cellAcc);
+
+      // do zoom
+      zoomDocument(tabDocument, 1.5);
+
+      // tree columns
+      hitTest(tree, treecols, treecol1);
+
+      // tree rows and cells
+      var [x, y] = CSSToDevicePixels(tabWindow, cssX, cssY);
+      testChildAtPoint(treeAcc, x, y, rowAcc, cellAcc);
+      testChildAtPoint(rowAcc, x, y, cellAcc, cellAcc);
+
+      closeBrowserWindow();
       SimpleTest.finish();
     }
 
+    function prepareTest()
+    {
+      var tabDocument = currentTabDocument();
+      var tree = tabDocument.getElementById("tree");
+      loadXULTreeAndDoTest(doTest, tree, new nsTableTreeView(5));
+    }
+
     SimpleTest.waitForExplicitFinish();
-    addA11yXULTreeLoadEvent(doTest, "tree", new nsTableTreeView(5));
+    openBrowserWindow(prepareTest,
+                      "chrome://mochitests/content/a11y/accessible/hittest/zoom_tree.xul",
+                      { left: 100, top: 100 });
   ]]>
   </script>
 
   <hbox flex="1" style="overflow: auto;">
     <body xmlns="http://www.w3.org/1999/xhtml">
       <a target="_blank"
          href="https://bugzilla.mozilla.org/show_bug.cgi?id=471493"
          title=" crash [@ nsPropertyTable::GetPropertyInternal]">
         Mozilla Bug 471493
       </a><br/>
       <p id="display"></p>
       <div id="content" style="display: none">
       </div>
       <pre id="test">
       </pre>
     </body>
-
-    <tree id="tree" flex="1">
-      <treecols id="treecols">
-        <treecol id="col1" flex="1" primary="true" label="column"/>
-        <treecol id="col2" flex="1" label="column 2"/>
-      </treecols>
-      <treechildren id="treechildren"/>
-    </tree>
   </hbox>
 
 </window>
 
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/hittest/zoom_tree.xul
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="nsIAccessible::getChildAtPoint and getDeepestChildAtPoint for XUL trees">
+
+  <tree id="tree" flex="1">
+    <treecols id="treecols">
+      <treecol id="treecol1" flex="1" primary="true" label="column"/>
+      <treecol id="treecol2" flex="1" label="column 2"/>
+    </treecols>
+    <treechildren id="treechildren"/>
+  </tree>
+
+</window>
+
--- a/accessible/tests/mochitest/layout.js
+++ b/accessible/tests/mochitest/layout.js
@@ -1,53 +1,69 @@
 /**
- * Tests if the given accessible at the given point is expected.
+ * Tests if the given child and grand child accessibles at the given point are
+ * expected.
  *
- * @param aIdentifier        [in] accessible identifier
- * @param aX                 [in] x coordinate of the point relative accessible
- * @param aY                 [in] y coordinate of the point relative accessible
- * @param aFindDeepestChild  [in] points whether deepest or nearest child should
- *                           be returned
- * @param aChildIdentifier   [in] expected child accessible
+ * @param aID            [in] accessible identifier
+ * @param aX             [in] x coordinate of the point relative accessible
+ * @param aY             [in] y coordinate of the point relative accessible
+ * @param aChildID       [in] expected child accessible
+ * @param aGrandChildID  [in] expected child accessible
  */
-function testChildAtPoint(aIdentifier, aX, aY, aFindDeepestChild,
-                          aChildIdentifier)
+function testChildAtPoint(aID, aX, aY, aChildID, aGrandChildID)
 {
-  var childAcc = getAccessible(aChildIdentifier);
-  var actualChildAcc = getChildAtPoint(aIdentifier, aX, aY, aFindDeepestChild);
+  var child = getChildAtPoint(aID, aX, aY, false);
+  var expectedChild = getAccessible(aChildID);
 
-  var msg = "Wrong " + (aFindDeepestChild ? "deepest" : "direct");
-  msg += " child accessible [" + prettyName(actualChildAcc);
-  msg += "] at the point (" + aX + ", " + aY + ") of accessible [";
-  msg += prettyName(aIdentifier) + "]";
+  var msg = "Wrong direct child accessible at the point (" + aX + ", " + aY +
+    ") of " + prettyName(aID);
+  isObject(child, expectedChild, msg);
 
-  is(childAcc, actualChildAcc, msg);
+  var grandChild = getChildAtPoint(aID, aX, aY, true);
+  var expectedGrandChild = getAccessible(aGrandChildID);
+
+  msg = "Wrong deepest child accessible at the point (" + aX + ", " + aY +
+    ") of " + prettyName(aID);
+  isObject(grandChild, expectedGrandChild, msg);
 }
 
 /**
  * Test if getChildAtPoint returns the given child and grand child accessibles
  * at coordinates of child accessible (direct and deep hit test).
  */
 function hitTest(aContainerID, aChildID, aGrandChildID)
 {
   var container = getAccessible(aContainerID);
   var child = getAccessible(aChildID);
   var grandChild = getAccessible(aGrandChildID);
 
   var [x, y] = getBoundsForDOMElm(child);
 
   var actualChild = container.getChildAtPoint(x + 1, y + 1);
-  is(actualChild, child,
-     "Wrong child, expected: " + prettyName(child) +
-     ", got: " + prettyName(actualChild));
+  isObject(actualChild, child,
+           "Wrong direct child of " + prettyName(aContainerID));
 
   var actualGrandChild = container.getDeepestChildAtPoint(x + 1, y + 1);
-  is(actualGrandChild, grandChild,
-     "Wrong deepest child, expected: " + prettyName(grandChild) +
-     ", got: " + prettyName(actualGrandChild));
+  isObject(actualGrandChild, grandChild,
+           "Wrong deepest child of " + prettyName(aContainerID));
+}
+
+/**
+ * Zoom the given document.
+ */
+function zoomDocument(aDocument, aZoom)
+{
+  var docShell = aDocument.defaultView.
+    QueryInterface(Components.interfaces.nsIInterfaceRequestor).
+    getInterface(Components.interfaces.nsIWebNavigation).
+    QueryInterface(Components.interfaces.nsIDocShell);
+  var docViewer = docShell.contentViewer.
+    QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
+
+  docViewer.fullZoom = aZoom;
 }
 
 /**
  * Return child accessible at the given point.
  *
  * @param aIdentifier        [in] accessible identifier
  * @param aX                 [in] x coordinate of the point relative accessible
  * @param aY                 [in] y coordinate of the point relative accessible
@@ -131,18 +147,25 @@ function getBoundsForDOMElm(aID)
     var rect = elm.getBoundingClientRect();
     x = rect.left;
     y = rect.top;
     width = rect.width;
     height = rect.height;
   }
 
   var elmWindow = elm.ownerDocument.defaultView;
-  var winUtil = elmWindow.
+  return CSSToDevicePixels(elmWindow,
+                           x + elmWindow.mozInnerScreenX,
+                           y + elmWindow.mozInnerScreenY,
+                           width,
+                           height);
+}
+
+function CSSToDevicePixels(aWindow, aX, aY, aWidth, aHeight)
+{
+  var winUtil = aWindow.
     QueryInterface(Components.interfaces.nsIInterfaceRequestor).
     getInterface(Components.interfaces.nsIDOMWindowUtils);
 
   var ratio = winUtil.screenPixelsPerCSSPixel;
-  return [ (x + elmWindow.mozInnerScreenX) * ratio,
-           (y + elmWindow.mozInnerScreenY) * ratio,
-           width * ratio,
-           height * ratio ];
+  return [aX * ratio, aY * ratio, aWidth * ratio, aHeight * ratio];
 }
+
--- a/accessible/tests/mochitest/test_nsIAccessibleDocument.html
+++ b/accessible/tests/mochitest/test_nsIAccessibleDocument.html
@@ -35,17 +35,17 @@ https://bugzilla.mozilla.org/show_bug.cg
         // check if it is focusable, read-only.
         testStates(docAcc, (STATE_READONLY | STATE_FOCUSABLE));
 
         // No actions wanted on doc
         is(docAcc.numActions, 0, "Wrong number of actions for document!");
 
         // attributes should contain tag:body
         attributes = docAcc.attributes;
-        is(attributes.getStringProperty("tag"), "BODY",
+        is(attributes.getStringProperty("tag"), "body",
            "Wrong attribute on document!");
 
         // nsIAccessibleDocument
         // getRootDirectory() depends on broken chrome-harness.js include (bug
         // 736886)
         /*
         var rootDir = getRootDirectory(window.location.href);
         is(docAcc.URL, rootDir.path + "test_nsIAccessibleDocument.html",
--- a/accessible/tests/mochitest/treeview.js
+++ b/accessible/tests/mochitest/treeview.js
@@ -1,14 +1,17 @@
 /**
  * Helper method to start a single XUL tree test.
  */
-var gXULTreeLoadQueue = null;
-function addA11yXULTreeLoadEvent(aDoTestFunc, aTreeID, aTreeView)
+function loadXULTreeAndDoTest(aDoTestFunc, aTreeID, aTreeView)
 {
+  var doTestFunc = aDoTestFunc ? aDoTestFunc : gXULTreeLoadContext.doTestFunc;
+  var treeID = aTreeID ? aTreeID : gXULTreeLoadContext.treeID;
+  var treeView = aTreeView ? aTreeView : gXULTreeLoadContext.treeView;
+
   function loadXULTree(aTreeID, aTreeView)
   {
     this.treeNode = getNode(aTreeID);
 
     this.eventSeq = [
       new invokerChecker(EVENT_REORDER, this.treeNode)
     ];
 
@@ -18,29 +21,36 @@ function addA11yXULTreeLoadEvent(aDoTest
     }
 
     this.getID = function loadXULTree_getID()
     {
       return "Load XUL tree " + prettyName(aTreeID);
     }
   }
 
-  function doXULTreeTest()
+  gXULTreeLoadContext.queue = new eventQueue();
+  gXULTreeLoadContext.queue.push(new loadXULTree(treeID, treeView));
+  gXULTreeLoadContext.queue.onFinish = function()
   {
-    gXULTreeLoadQueue = new eventQueue();
-    gXULTreeLoadQueue.push(new loadXULTree(aTreeID, aTreeView));
-    gXULTreeLoadQueue.onFinish = function()
-    {
-      SimpleTest.executeSoon(aDoTestFunc);
-      return DO_NOT_FINISH_TEST;
-    }
-    gXULTreeLoadQueue.invoke();
+    SimpleTest.executeSoon(doTestFunc);
+    return DO_NOT_FINISH_TEST;
   }
+  gXULTreeLoadContext.queue.invoke();
+}
 
-  addA11yLoadEvent(doXULTreeTest);
+/**
+ * Analogy of addA11yLoadEvent, nice helper to load XUL tree and start the test.
+ */
+function addA11yXULTreeLoadEvent(aDoTestFunc, aTreeID, aTreeView)
+{
+  gXULTreeLoadContext.doTestFunc = aDoTestFunc;
+  gXULTreeLoadContext.treeID = aTreeID;
+  gXULTreeLoadContext.treeView = aTreeView;
+
+  addA11yLoadEvent(loadXULTreeAndDoTest);
 }
 
 
 function nsTableTreeView(aRowCount)
 {
   this.__proto__ = new nsTreeView();
 
   for (var idx = 0; idx < aRowCount; idx++)
@@ -268,8 +278,19 @@ function treeItem(aText, aOpen, aChildre
     this.children = aChildren;
 }
 
 function createAtom(aName)
 {
   return Components.classes["@mozilla.org/atom-service;1"]
     .getService(Components.interfaces.nsIAtomService).getAtom(aName);
 }
+
+/**
+ * Used in conjunction with loadXULTreeAndDoTest and addA11yXULTreeLoadEvent.
+ */
+var gXULTreeLoadContext =
+{
+  doTestFunc: null,
+  treeID: null,
+  treeView: null,
+  queue: null
+};
--- a/browser/base/content/aboutDialog.css
+++ b/browser/base/content/aboutDialog.css
@@ -41,20 +41,16 @@
 }
 
 #updateButton,
 #updateDeck > hbox > label {
   -moz-margin-start: 0;
   -moz-padding-start: 0;
 }
 
-#updateDeck > hbox > label:not([class="text-link"]) {
-  font-style:italic;
-}
-
 .update-throbber {
   width: 16px;
   min-height: 16px;
   -moz-margin-end: 3px;
   list-style-image: url("chrome://global/skin/icons/loading_16.png");
 }
 
 .text-link,
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2619,16 +2619,17 @@ function UpdateUrlbarSearchSplitterState
   }
 
   if (ibefore) {
     if (!splitter) {
       splitter = document.createElement("splitter");
       splitter.id = "urlbar-search-splitter";
       splitter.setAttribute("resizebefore", "flex");
       splitter.setAttribute("resizeafter", "flex");
+      splitter.setAttribute("skipintoolbarset", "true");
       splitter.className = "chromeclass-toolbar-additional";
     }
     urlbar.parentNode.insertBefore(splitter, ibefore);
   } else if (splitter)
     splitter.parentNode.removeChild(splitter);
 }
 
 function setUrlAndSearchBarWidthForConditionalForwardButton() {
--- a/browser/installer/windows/nsis/maintenanceservice_installer.nsi
+++ b/browser/installer/windows/nsis/maintenanceservice_installer.nsi
@@ -220,26 +220,30 @@ Section "MaintenanceService"
 
   ; Write out that a maintenance service was attempted.
   ; We do this because on upgrades we will check this value and we only
   ; want to install once on the first upgrade to maintenance service.
   ; Also write out that we are currently installed, preferences will check
   ; this value to determine if we should show the service update pref.
   ; Since the Maintenance service can be installed either x86 or x64,
   ; always use the 64-bit registry for checking if an attempt was made.
-  SetRegView 64
+  ${If} ${RunningX64}
+    SetRegView 64
+  ${EndIf}
   WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Attempted" 1
   WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Installed" 1
 
   ; Included here for debug purposes only.  
   ; These keys are used to bypass the installation dir is a valid installation
   ; check from the service so that tests can be run.
   ; WriteRegStr HKLM "${FallbackKey}\0" "name" "Mozilla Corporation"
   ; WriteRegStr HKLM "${FallbackKey}\0" "issuer" "Thawte Code Signing CA - G2"
-  SetRegView lastused
+  ${If} ${RunningX64}
+    SetRegView lastused
+  ${EndIf}
 SectionEnd
 
 ; By renaming before deleting we improve things slightly in case
 ; there is a file in use error. In this case a new install can happen.
 Function un.RenameDelete
   Pop $9
   ; If the .moz-delete file already exists previously, delete it
   ; If it doesn't exist, the call is ignored.
@@ -268,13 +272,17 @@ Section "Uninstall"
   Push "$INSTDIR\maintenanceservice.old"
   Call un.RenameDelete
   Push "$INSTDIR\Uninstall.exe"
   Call un.RenameDelete
   RMDir /REBOOTOK "$INSTDIR"
 
   DeleteRegKey HKLM "${MaintUninstallKey}"
 
-  SetRegView 64
+  ${If} ${RunningX64}
+    SetRegView 64
+  ${EndIf}
   DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "Installed"
   DeleteRegKey HKLM "${FallbackKey}\"
-  SetRegView lastused
+  ${If} ${RunningX64}
+    SetRegView lastused
+  ${EndIf}
 SectionEnd
--- a/browser/installer/windows/nsis/shared.nsh
+++ b/browser/installer/windows/nsis/shared.nsh
@@ -116,20 +116,24 @@
   ; On Windows 2000 we do not install the maintenance service.
   ${AndIf} ${AtLeastWinXP}
     ; Add the registry keys for allowed certificates.
     ${AddMaintCertKeys}
 
     ; We check to see if the maintenance service install was already attempted.
     ; Since the Maintenance service can be installed either x86 or x64,
     ; always use the 64-bit registry for checking if an attempt was made.
-    SetRegView 64
+    ${If} ${RunningX64}
+      SetRegView 64
+    ${EndIf}
     ReadRegDWORD $5 HKLM "Software\Mozilla\MaintenanceService" "Attempted"
     ClearErrors
-    SetRegView lastused
+    ${If} ${RunningX64}
+      SetRegView lastused
+    ${EndIf}
 
     ; If the maintenance service is already installed, do nothing.
     ; The maintenance service will launch:
     ; maintenanceservice_installer.exe /Upgrade to upgrade the maintenance
     ; service if necessary.   If the update was done from updater.exe without 
     ; the service (i.e. service is failing), updater.exe will do the update of 
     ; the service.  The reasons we do not do it here is because we don't want 
     ; to have to prompt for limited user accounts when the service isn't used 
@@ -613,22 +617,25 @@
   ServicesHelper::PathToUniqueRegistryPath "$INSTDIR"
   Pop $R0
   ${If} $R0 != ""
     ; More than one certificate can be specified in a different subfolder
     ; for example: $R0\1, but each individual binary can be signed
     ; with at most one certificate.  A fallback certificate can only be used
     ; if the binary is replaced with a different certificate.
     ; We always use the 64bit registry for certs.
-    ; This call is ignored on 32-bit systems.
-    SetRegView 64
+    ${If} ${RunningX64}
+      SetRegView 64
+    ${EndIf}
     DeleteRegKey HKLM "$R0"
     WriteRegStr HKLM "$R0\0" "name" "${CERTIFICATE_NAME}"
     WriteRegStr HKLM "$R0\0" "issuer" "${CERTIFICATE_ISSUER}"
-    SetRegView lastused
+    ${If} ${RunningX64}
+      SetRegView lastused
+    ${EndIf}
     ClearErrors
   ${EndIf} 
   ; Restore the previously used value back
   Pop $R0
 !macroend
 !define AddMaintCertKeys "!insertmacro AddMaintCertKeys"
 !endif
 
--- a/browser/installer/windows/nsis/uninstaller.nsi
+++ b/browser/installer/windows/nsis/uninstaller.nsi
@@ -209,28 +209,32 @@ ChangeUI IDD_VERIFY "${NSISDIR}\Contrib\
 Function un.UninstallServiceIfNotUsed
   ; $0 will store if a subkey exists
   ; $1 will store the first subkey if it exists or an empty string if it doesn't
   ; Backup the old values
   Push $0
   Push $1
 
   ; The maintenance service always uses the 64-bit registry on x64 systems
-  SetRegView 64
+  ${If} ${RunningX64}
+    SetRegView 64
+  ${EndIf}
 
   ; Figure out the number of subkeys
   StrCpy $0 0
 loop:
   EnumRegKey $1 HKLM "Software\Mozilla\MaintenanceService" $0
   StrCmp $1 "" doneCount
   IntOp $0 $0 + 1
   goto loop
 doneCount:
   ; Restore back the registry view
-  SetRegView lastUsed
+  ${If} ${RunningX64}
+    SetRegView lastUsed
+  ${EndIf}
   ${If} $0 == 0
     ; Get the path of the maintenance service uninstaller
     ReadRegStr $1 HKLM ${MaintUninstallKey} "UninstallString"
 
     ; If the uninstall string does not exist, skip executing it
     StrCmp $1 "" doneUninstall
 
     ; $1 is already a quoted string pointing to the install path
@@ -429,20 +433,23 @@ Section "Uninstall"
 
 !ifdef MOZ_MAINTENANCE_SERVICE
   ; Get the path the allowed cert is at and remove it
   ; Keep this block of code last since it modfies the reg view
   ServicesHelper::PathToUniqueRegistryPath "$INSTDIR"
   Pop $MaintCertKey
   ${If} $MaintCertKey != ""
     ; We always use the 64bit registry for certs
-    ; This call is ignored on 32-bit systems.
-    SetRegView 64
-    DeleteRegKey HKLM "$MaintCertKey\"
-    SetRegView lastused
+    ${If} ${RunningX64}
+      SetRegView 64
+    ${EndIf}
+    DeleteRegKey HKLM "$MaintCertKey"
+    ${If} ${RunningX64}
+      SetRegView lastused
+    ${EndIf}
   ${EndIf}
   Call un.UninstallServiceIfNotUsed
 !endif
 
 SectionEnd
 
 ################################################################################
 # Helper Functions
--- a/content/base/src/nsImageLoadingContent.h
+++ b/content/base/src/nsImageLoadingContent.h
@@ -40,26 +40,24 @@
  * A base class which implements nsIImageLoadingContent and can be
  * subclassed by various content nodes that want to provide image
  * loading functionality (eg <img>, <object>, etc).
  */
 
 #ifndef nsImageLoadingContent_h__
 #define nsImageLoadingContent_h__
 
-#include "nsIImageLoadingContent.h"
-#include "nsINode.h"
-#include "imgIRequest.h"
-#include "prtypes.h"
+#include "imgIContainerObserver.h"
+#include "imgIDecoderObserver.h"
+#include "mozilla/CORSMode.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h" // NS_CONTENT_DELETE_LIST_MEMBER
-#include "nsString.h"
 #include "nsEventStates.h"
-#include "nsGenericHTMLElement.h"
-#include "mozilla/CORSMode.h"
+#include "nsIImageLoadingContent.h"
+#include "nsIRequest.h"
 
 class nsIURI;
 class nsIDocument;
 class imgILoader;
 class nsIIOService;
 
 class nsImageLoadingContent : public nsIImageLoadingContent
 {
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -1205,33 +1205,28 @@ nsXMLHttpRequest::GetStatus(PRUint32 *aS
       nsresult status;
       mChannel->GetStatus(&status);
       if (NS_FAILED(status)) {
         return NS_OK;
       }
     }
   }
 
+  PRUint16 readyState;
+  GetReadyState(&readyState);
+  if (readyState == UNSENT || readyState == OPENED || mErrorLoad) {
+    return NS_OK;
+  }
+
   nsCOMPtr<nsIHttpChannel> httpChannel = GetCurrentHttpChannel();
-
   if (httpChannel) {
     nsresult rv = httpChannel->GetResponseStatus(aStatus);
-    if (rv == NS_ERROR_NOT_AVAILABLE) {
-      // Someone's calling this before we got a response... Check our
-      // ReadyState.  If we're at 3 or 4, then this means the connection
-      // errored before we got any data; return 0 in that case.
-      PRUint16 readyState;
-      GetReadyState(&readyState);
-      if (readyState >= LOADING) {
-        *aStatus = 0;
-        return NS_OK;
-      }
+    if (NS_FAILED(rv)) {
+      *aStatus = 0;
     }
-
-    return rv;
   }
 
   return NS_OK;
 }
 
 /* readonly attribute AUTF8String statusText; */
 NS_IMETHODIMP
 nsXMLHttpRequest::GetStatusText(nsACString& aStatusText)
--- a/content/base/test/test_XHR.html
+++ b/content/base/test/test_XHR.html
@@ -214,22 +214,41 @@ xhr.onloadend = continueTest;
 xhr.send("{");
 yield;
 is(xhr.status, 200, "wrong status");
 checkResponseTextAccessThrows(xhr);
 checkResponseXMLAccessThrows(xhr);
 is(xhr.response, null, "Bad JSON should result in null response.");
 is(xhr.response, null, "Bad JSON should result in null response even 2nd time.");
 
+// Test status/statusText in all readyStates
+xhr = new XMLHttpRequest();
+function checkXHRStatus() {
+  if (xhr.readyState == xhr.UNSENT || xhr.readyState == xhr.OPENED) {
+    is(xhr.status, 0, "should be 0 before getting data");
+    is(xhr.statusText, "", "should be empty before getting data");
+  }
+  else {
+    is(xhr.status, 200, "should be 200 when we have data");
+    is(xhr.statusText, "OK", "should be OK when we have data");
+  }
+}
+checkXHRStatus();
+xhr.open("GET", 'file_XHR_binary1.bin'); 
+checkXHRStatus();
+xhr.responseType = 'arraybuffer';
+xhr.onreadystatechange = continueTest;
+xhr.send(null);
+while (xhr.readyState != 4) {
+  checkXHRStatus();
+  yield;
+}
+checkXHRStatus();
+
 // test response (responseType='blob')
-var onloadCount = 0;
-function checkOnloadCount() {
-  if (++onloadCount >= 6) SimpleTest.finish();
-};
-
 var responseTypes = ['blob', 'moz-blob'];
 for (var i = 0; i < responseTypes.length; i++) {
   var t = responseTypes[i];
   // with a simple text file
   xhr = new XMLHttpRequest();
   xhr.open("GET", 'file_XHR_pass2.txt'); 
   xhr.responseType = t;
   xhr.onloadend = continueTest;
@@ -239,83 +258,82 @@ for (var i = 0; i < responseTypes.length
   checkResponseTextAccessThrows(xhr);
   checkResponseXMLAccessThrows(xhr);
   var b = xhr.response;
   ok(b, "should have a non-null blob");
   ok(b instanceof Blob, "should be a Blob");
   ok(!(b instanceof File), "should not be a File");
   is(b.size, "hello pass\n".length, "wrong blob size");
 
-  (function(){
-    var fr = new FileReader();
-    fr.onload = function() {
-      ok(fr.result, "hello pass\n", "wrong values");
-      checkOnloadCount();
-    };
-    fr.readAsBinaryString(b);
-  })();
+  var fr = new FileReader();
+  fr.onload = continueTest;
+  fr.readAsBinaryString(b);
+  yield;
+  ok(fr.result, "hello pass\n", "wrong values");
 
   // with a binary file
-  (function(){
-    var xhr = new XMLHttpRequest();
-    xhr.onreadystatechange = function() {
-      switch (xhr.readyState) {
-      case 2:
-        is(xhr.status, 200, "wrong status");
-        xhr.responseType = t;
-        break;
-      case 4:
-        b = xhr.response;
-        ok(b != null, "should have a non-null blob");
-        is(b.size, 12, "wrong blob size");
+  xhr = new XMLHttpRequest();
+  xhr.onreadystatechange = continueTest;
+  xhr.open("GET", 'file_XHR_binary1.bin', true);
+  xhr.send(null);
+  while(xhr.readyState != 2)
+    yield;
+
+  is(xhr.status, 200, "wrong status");
+  xhr.responseType = t;
 
-        var fr = new FileReader();
-        fr.onload = function() {
-          is(fr.result, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb", "wrong values");
-          checkOnloadCount();
-        };
-        xhr = null; // kill the XHR object
-        SpecialPowers.gc();
-        fr.readAsBinaryString(b);
-        break;
-      }
-    };
-    xhr.open("GET", 'file_XHR_binary1.bin', true);
-    xhr.send(null);
-  })();
+  while(xhr.readyState != 4)
+    yield;
+  
+  xhr.onreadystatechange = null;
+
+  b = xhr.response;
+  ok(b != null, "should have a non-null blob");
+  is(b.size, 12, "wrong blob size");
+
+  fr = new FileReader();
+  fr.readAsBinaryString(b);
+  xhr = null; // kill the XHR object
+  b = null;
+  SpecialPowers.gc();
+  fr.onload = continueTest;
+  yield;
+  is(fr.result, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb", "wrong values");
 
-  (function(){
-    // with a larger binary file
-    var xhr = new XMLHttpRequest();
-    xhr.onreadystatechange = function() {
-      if (xhr.readyState == 4) {
-        b = xhr.response;
-        ok(b != null, "should have a non-null blob");
-        is(b.size, 65536, "wrong blob size");
+  // with a larger binary file
+  xhr = new XMLHttpRequest();
+  xhr.onreadystatechange = continueTest;
+  xhr.open("GET", 'file_XHR_binary2.bin', true);
+  xhr.responseType = t;
+  xhr.send(null);
+
+  while (xhr.readyState != 4)
+    yield;
+
+  xhr.onreadystatechange = null;
+
+  var b = xhr.response;
+  ok(b != null, "should have a non-null blob");
+  is(b.size, 65536, "wrong blob size");
 
-        var fr = new FileReader();
-        fr.onload = function() {
-          var u8 = new Uint8Array(fr.result);
-          for (var i = 0; i < 65536; i++) {
-            if (u8[i] !== (i & 255)) {
-              break;
-            }
-          }
-          is(i, 65536, "wrong value at offset " + i);
-          checkOnloadCount();
-        };
-        xhr = null; // kill the XHR object
-        SpecialPowers.gc();
-        fr.readAsArrayBuffer(b);
-      }
-    };
-    xhr.open("GET", 'file_XHR_binary2.bin', true);
-    xhr.responseType = t;
-    xhr.send(null);
-  })();
+  fr = new FileReader();
+  fr.readAsArrayBuffer(b);
+  fr.onload = continueTest;
+  xhr = null; // kill the XHR object
+  b = null;
+  SpecialPowers.gc();
+  yield;
+
+  var u8 = new Uint8Array(fr.result);
+  for (var i = 0; i < 65536; i++) {
+    if (u8[i] !== (i & 255)) {
+      break;
+    }
+  }
+  is(i, 65536, "wrong value at offset " + i);
 }
 
 var client = new XMLHttpRequest();
 client.onreadystatechange = function() {
   if(client.readyState == 4) {
     try {
       is(client.responseXML, null, "responseXML should be null.");
       is(client.responseText, "", "responseText should be empty string.");
@@ -328,14 +346,16 @@ client.onreadystatechange = function() {
       ok(false, "Shouldn't throw! [" + ex + "]");
     }
   }
 }
 client.open("GET", "file_XHR_pass1.xml", true);
 client.send();
 client.abort();
 
+SimpleTest.finish();
 yield;
+
 } /* runTests */
 </script>
 </pre>
 </body>
 </html>
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -1076,16 +1076,40 @@ protected:
   nsRefPtr<gfxASurface> mSurface;
   nsRefPtr<mozilla::gl::GLContext> mGLContext;
   mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget;
   
   PRUint32 mCanvasFramebuffer;
 
   bool mGLBufferIsPremultiplied;
   bool mNeedsYFlip;
+
+  nsRefPtr<gfxImageSurface> mCachedTempSurface;
+  gfxIntSize mCachedSize;
+  gfxImageFormat mCachedFormat;
+
+  gfxImageSurface* GetTempSurface(const gfxIntSize& aSize, const gfxImageFormat aFormat)
+  {
+    if (!mCachedTempSurface ||
+        aSize.width != mCachedSize.width ||
+        aSize.height != mCachedSize.height ||
+        aFormat != mCachedFormat)
+    {
+      mCachedTempSurface = new gfxImageSurface(aSize, aFormat);
+      mCachedSize = aSize;
+      mCachedFormat = aFormat;
+    }
+
+    return mCachedTempSurface;
+  }
+
+  void DiscardTempSurface()
+  {
+    mCachedTempSurface = nsnull;
+  }
 };
 
 void
 BasicCanvasLayer::Initialize(const Data& aData)
 {
   NS_ASSERTION(mSurface == nsnull, "BasicCanvasLayer::Initialize called twice!");
 
   if (aData.mSurface) {
@@ -1134,34 +1158,40 @@ BasicCanvasLayer::UpdateSurface(gfxASurf
                    "Destination surface must be ImageSurface type");
       return;
     }
 
     // We need to read from the GLContext
     mGLContext->MakeCurrent();
 
 #if defined (MOZ_X11) && defined (MOZ_EGL_XRENDER_COMPOSITE)
-    mGLContext->fFinish();
+    mGLContext->GuaranteeResolve();
     gfxASurface* offscreenSurface = mGLContext->GetOffscreenPixmapSurface();
 
     // XRender can only blend premuliplied alpha, so only allow xrender
     // path if we have premultiplied alpha or opaque content.
     if (offscreenSurface && (mGLBufferIsPremultiplied || (GetContentFlags() & CONTENT_OPAQUE))) {  
         mSurface = offscreenSurface;
         mNeedsYFlip = false;
+        return;
     }
-    else
 #endif
-    {
-    nsRefPtr<gfxImageSurface> isurf = aDestSurface ?
-        static_cast<gfxImageSurface*>(aDestSurface) :
-        new gfxImageSurface(gfxIntSize(mBounds.width, mBounds.height),
-                            (GetContentFlags() & CONTENT_OPAQUE)
-                              ? gfxASurface::ImageFormatRGB24
-                              : gfxASurface::ImageFormatARGB32);
+    nsRefPtr<gfxImageSurface> isurf;
+    if (aDestSurface) {
+      DiscardTempSurface();
+      isurf = static_cast<gfxImageSurface*>(aDestSurface);
+    } else {
+      nsIntSize size(mBounds.width, mBounds.height);
+      gfxImageFormat format = (GetContentFlags() & CONTENT_OPAQUE)
+                                ? gfxASurface::ImageFormatRGB24
+                                : gfxASurface::ImageFormatARGB32;
+
+      isurf = GetTempSurface(size, format);
+    }
+
 
     if (!isurf || isurf->CairoStatus() != 0) {
       return;
     }
 
     NS_ASSERTION(isurf->Stride() == mBounds.width * 4, "gfxImageSurface stride isn't what we expect!");
 
     PRUint32 currentFramebuffer = 0;
@@ -1189,17 +1219,16 @@ BasicCanvasLayer::UpdateSurface(gfxASurf
       gfxUtils::PremultiplyImageSurface(isurf);
 
     // stick our surface into mSurface, so that the Paint() path is the same
     if (!aDestSurface) {
       mSurface = isurf;
     }
   }
 }
-}
 
 void
 BasicCanvasLayer::Paint(gfxContext* aContext)
 {
   if (IsHidden())
     return;
   UpdateSurface();
   FireDidTransactionCallback();
--- a/gfx/layers/d3d10/CanvasLayerD3D10.cpp
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.cpp
@@ -167,20 +167,23 @@ CanvasLayerD3D10::UpdateSurface()
     
     HRESULT hr = mTexture->Map(0, D3D10_MAP_WRITE_DISCARD, 0, &map);
 
     if (FAILED(hr)) {
       NS_WARNING("Failed to map CanvasLayer texture.");
       return;
     }
 
+    const bool stridesMatch = map.RowPitch == mBounds.width * 4;
+
     PRUint8 *destination;
-    if (map.RowPitch != mBounds.width * 4) {
-      destination = new PRUint8[mBounds.width * mBounds.height * 4];
+    if (!stridesMatch) {
+      destination = GetTempBlob(mBounds.width * mBounds.height * 4);
     } else {
+      DiscardTempBlob();
       destination = (PRUint8*)map.pData;
     }
 
     mGLContext->MakeCurrent();
 
     PRUint32 currentFramebuffer = 0;
 
     mGLContext->fGetIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, (GLint*)&currentFramebuffer);
@@ -199,23 +202,22 @@ CanvasLayerD3D10::UpdateSurface()
                                            mBounds.width, mBounds.height,
                                            tmpSurface);
     tmpSurface = nsnull;
 
     // Put back the previous framebuffer binding.
     if (currentFramebuffer != mCanvasFramebuffer)
       mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, currentFramebuffer);
 
-    if (map.RowPitch != mBounds.width * 4) {
+    if (!stridesMatch) {
       for (int y = 0; y < mBounds.height; y++) {
         memcpy((PRUint8*)map.pData + map.RowPitch * y,
                destination + mBounds.width * 4 * y,
                mBounds.width * 4);
       }
-      delete [] destination;
     }
     mTexture->Unmap(0);
   } else if (mSurface) {
     RECT r;
     r.left = 0;
     r.top = 0;
     r.right = mBounds.width;
     r.bottom = mBounds.height;
--- a/gfx/layers/d3d10/CanvasLayerD3D10.h
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.h
@@ -82,13 +82,31 @@ private:
 
   PRUint32 mCanvasFramebuffer;
 
   bool mDataIsPremultiplied;
   bool mNeedsYFlip;
   bool mIsD2DTexture;
   bool mUsingSharedTexture;
   bool mHasAlpha;
+
+  nsAutoArrayPtr<PRUint8> mCachedTempBlob;
+  PRUint32 mCachedTempBlob_Size;
+
+  PRUint8* GetTempBlob(const PRUint32 aSize)
+  {
+      if (!mCachedTempBlob || aSize != mCachedTempBlob_Size) {
+          mCachedTempBlob = new PRUint8[aSize];
+          mCachedTempBlob_Size = aSize;
+      }
+
+      return mCachedTempBlob;
+  }
+
+  void DiscardTempBlob()
+  {
+      mCachedTempBlob = nsnull;
+  }
 };
 
 } /* layers */
 } /* mozilla */
 #endif /* GFX_CANVASLAYERD3D10_H */
--- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp
@@ -108,20 +108,23 @@ CanvasLayerD3D9::UpdateSurface()
     LockTextureRectD3D9 textureLock(mTexture);
     if (!textureLock.HasLock()) {
       NS_WARNING("Failed to lock CanvasLayer texture.");
       return;
     }
 
     D3DLOCKED_RECT r = textureLock.GetLockRect();
 
+    const bool stridesMatch = r.Pitch == mBounds.width * 4;
+
     PRUint8 *destination;
-    if (r.Pitch != mBounds.width * 4) {
-      destination = new PRUint8[mBounds.width * mBounds.height * 4];
+    if (!stridesMatch) {
+      destination = GetTempBlob(mBounds.width * mBounds.height * 4);
     } else {
+      DiscardTempBlob();
       destination = (PRUint8*)r.pBits;
     }
 
     mGLContext->MakeCurrent();
 
     PRUint32 currentFramebuffer = 0;
 
     mGLContext->fGetIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, (GLint*)&currentFramebuffer);
@@ -140,23 +143,22 @@ CanvasLayerD3D9::UpdateSurface()
                                            mBounds.width, mBounds.height,
                                            tmpSurface);
     tmpSurface = nsnull;
 
     // Put back the previous framebuffer binding.
     if (currentFramebuffer != mCanvasFramebuffer)
       mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, currentFramebuffer);
 
-    if (r.Pitch != mBounds.width * 4) {
+    if (!stridesMatch) {
       for (int y = 0; y < mBounds.height; y++) {
         memcpy((PRUint8*)r.pBits + r.Pitch * y,
                destination + mBounds.width * 4 * y,
                mBounds.width * 4);
       }
-      delete [] destination;
     }
   } else {
     RECT r;
     r.left = mBounds.x;
     r.top = mBounds.y;
     r.right = mBounds.XMost();
     r.bottom = mBounds.YMost();
 
--- a/gfx/layers/d3d9/CanvasLayerD3D9.h
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.h
@@ -87,16 +87,34 @@ protected:
   nsRefPtr<IDirect3DTexture9> mTexture;
   RefPtr<gfx::DrawTarget> mDrawTarget;
 
   PRUint32 mCanvasFramebuffer;
 
   bool mDataIsPremultiplied;
   bool mNeedsYFlip;
   bool mHasAlpha;
+
+  nsAutoArrayPtr<PRUint8> mCachedTempBlob;
+  PRUint32 mCachedTempBlob_Size;
+
+  PRUint8* GetTempBlob(const PRUint32 aSize)
+  {
+      if (!mCachedTempBlob || aSize != mCachedTempBlob_Size) {
+          mCachedTempBlob = new PRUint8[aSize];
+          mCachedTempBlob_Size = aSize;
+      }
+
+      return mCachedTempBlob;
+  }
+
+  void DiscardTempBlob()
+  {
+      mCachedTempBlob = nsnull;
+  }
 };
 
 // NB: eventually we'll have separate shadow canvas2d and shadow
 // canvas3d layers, but currently they look the same from the
 // perspective of the compositor process
 class ShadowCanvasLayerD3D9 : public ShadowCanvasLayer,
                              public LayerD3D9
 {
--- a/gfx/layers/opengl/CanvasLayerOGL.cpp
+++ b/gfx/layers/opengl/CanvasLayerOGL.cpp
@@ -173,52 +173,56 @@ CanvasLayerOGL::UpdateSurface()
   if (mPixmap) {
     return;
   }
 #endif
 
   if (mCanvasGLContext &&
       mCanvasGLContext->GetContextType() == gl()->GetContextType())
   {
+    DiscardTempSurface();
+
     // Can texture share, just make sure it's resolved first
     mCanvasGLContext->MakeCurrent();
     mCanvasGLContext->GuaranteeResolve();
 
     if (gl()->BindOffscreenNeedsTexture(mCanvasGLContext) &&
         mTexture == 0)
     {
       mOGLManager->MakeCurrent();
       MakeTexture();
     }
   } else {
     nsRefPtr<gfxASurface> updatedAreaSurface;
+
     if (mDrawTarget) {
       // TODO: This is suboptimal - We should have direct handling for the surface types instead of
       // going via a gfxASurface.
       updatedAreaSurface = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mDrawTarget);
     } else if (mCanvasSurface) {
       updatedAreaSurface = mCanvasSurface;
     } else if (mCanvasGLContext) {
+      gfxIntSize size(mBounds.width, mBounds.height);
       nsRefPtr<gfxImageSurface> updatedAreaImageSurface =
-        new gfxImageSurface(gfxIntSize(mBounds.width, mBounds.height),
-                            gfxASurface::ImageFormatARGB32);
+        GetTempSurface(size, gfxASurface::ImageFormatARGB32);
+
       mCanvasGLContext->ReadPixelsIntoImageSurface(0, 0,
                                                    mBounds.width,
                                                    mBounds.height,
                                                    updatedAreaImageSurface);
+
       updatedAreaSurface = updatedAreaImageSurface;
     }
 
     mOGLManager->MakeCurrent();
-    mLayerProgram =
-      gl()->UploadSurfaceToTexture(updatedAreaSurface,
-                                   mBounds,
-                                   mTexture,
-                                   false,
-                                   nsIntPoint(0, 0));
+    mLayerProgram = gl()->UploadSurfaceToTexture(updatedAreaSurface,
+                                                 mBounds,
+                                                 mTexture,
+                                                 false,
+                                                 nsIntPoint(0, 0));
   }
 }
 
 void
 CanvasLayerOGL::RenderLayer(int aPreviousDestination,
                             const nsIntPoint& aOffset)
 {
   UpdateSurface();
--- a/gfx/layers/opengl/CanvasLayerOGL.h
+++ b/gfx/layers/opengl/CanvasLayerOGL.h
@@ -89,16 +89,40 @@ protected:
   GLuint mTexture;
 
   bool mDelayedUpdates;
   bool mGLBufferIsPremultiplied;
   bool mNeedsYFlip;
 #if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
   GLXPixmap mPixmap;
 #endif
+
+  nsRefPtr<gfxImageSurface> mCachedTempSurface;
+  gfxIntSize mCachedSize;
+  gfxImageFormat mCachedFormat;
+
+  gfxImageSurface* GetTempSurface(const gfxIntSize& aSize, const gfxImageFormat aFormat)
+  {
+    if (!mCachedTempSurface ||
+        aSize.width != mCachedSize.width ||
+        aSize.height != mCachedSize.height ||
+        aFormat != mCachedFormat)
+    {
+      mCachedTempSurface = new gfxImageSurface(aSize, aFormat);
+      mCachedSize = aSize;
+      mCachedFormat = aFormat;
+    }
+
+    return mCachedTempSurface;
+  }
+
+  void DiscardTempSurface()
+  {
+    mCachedTempSurface = nsnull;
+  }
 };
 
 // NB: eventually we'll have separate shadow canvas2d and shadow
 // canvas3d layers, but currently they look the same from the
 // perspective of the compositor process
 class ShadowCanvasLayerOGL : public ShadowCanvasLayer,
                              public LayerOGL
 {
--- a/hal/gonk/GonkSensor.cpp
+++ b/hal/gonk/GonkSensor.cpp
@@ -8,24 +8,27 @@
 
 #include "Hal.h"
 #include "HalSensor.h"
 #include "hardware/sensors.h"
 #include "mozilla/Util.h"
 #include "SensorDevice.h"
 #include "nsThreadUtils.h"
 
+#include <android/log.h>
+
 using namespace mozilla::hal;
 using namespace android;
 
+#define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GonkSensor" , ## args)
+
 namespace mozilla {
 
 #define DEFAULT_DEVICE_POLL_RATE 100000000 /*100ms*/
 
-
 double radToDeg(double a) {
   return a * (180.0 / M_PI);
 }
 
 static SensorType
 HardwareSensorToHalSensor(int type)
 {     
   switch(type) {
@@ -77,17 +80,16 @@ SensorseventStatus(const sensors_event_t
       return data.orientation.status;
     case SENSOR_LINEAR_ACCELERATION:
     case SENSOR_ACCELERATION:
       return data.acceleration.status;
     case SENSOR_GYROSCOPE:
       return data.gyro.status;
   }
 
-
   return SENSOR_STATUS_UNRELIABLE;
 }
 
 class SensorRunnable : public nsRunnable
 {
 public:
   SensorRunnable(const sensors_event_t& data)
   {
@@ -117,126 +119,133 @@ public:
 
 private:
   SensorData mSensorData;
   InfallibleTArray<float> mSensorValues;
 };
 
 namespace hal_impl {
 
-static pthread_t sThread;
-static bool sInitialized = false;
-static bool sContinue = true;
+class SensorStatus {
+public:
+  SensorData data;
+  DebugOnly<int> count;
+};
+
 static int sActivatedSensors = 0;
+static SensorStatus sSensorStatus[NUM_SENSOR_TYPE];
 static nsCOMPtr<nsIThread> sSwitchThread;
 
-static void*
-UpdateSensorData(void* /*unused*/)
-{
-  SensorDevice &device = SensorDevice::getInstance();
-  const size_t numEventMax = 16;
-  sensors_event_t buffer[numEventMax];
-  int count = 0;
-
-  while (sContinue) {
-    count = device.poll(buffer, numEventMax);
+class PollSensor {
+  public:
+    NS_INLINE_DECL_REFCOUNTING(PollSensor);
+ 
+    static nsCOMPtr<nsIRunnable> GetRunnable() {
+      if (!mRunnable)
+        mRunnable = NS_NewRunnableMethod(new PollSensor(), &PollSensor::Poll);
+      return mRunnable;
+    }
+ 
+    void Poll() {
+      if (!sActivatedSensors) {
+        return;
+      }
 
-    if (count < 0) {
-      continue;
-    }
-
-    for (int i=0; i<count; i++) {
-      if (SensorseventStatus(buffer[i]) == SENSOR_STATUS_UNRELIABLE) {
-        continue;
-      }
-      NS_DispatchToMainThread(new SensorRunnable(buffer[i]));
-    }
-  }
-
-  return NULL;
-}
+      SensorDevice &device = SensorDevice::getInstance();
+      const size_t numEventMax = 16;
+      sensors_event_t buffer[numEventMax];
 
-static void 
-InitializeResources()
-{
-  sInitialized = true;
-  sContinue = true;
-  pthread_create(&sThread, NULL, &UpdateSensorData, NULL);
-  NS_NewThread(getter_AddRefs(sSwitchThread));
-}
+      int n = device.poll(buffer, numEventMax);
+      if (n < 0) {
+        LOG("Error polling for sensor data (err=%d)", n);
+        return;
+      }
+
+      for (int i = 0; i < n; ++i) {
+        if (SensorseventStatus(buffer[i]) == SENSOR_STATUS_UNRELIABLE) {
+          continue;
+        }
+        NS_DispatchToMainThread(new SensorRunnable(buffer[i]));
+      }
 
-static void 
-ReleaseResources()
-{
-  sContinue = false;
-  pthread_join(sThread, NULL);
-  sSwitchThread->Shutdown();
-  sInitialized = false;
-}
+      if (sActivatedSensors) {
+        sSwitchThread->Dispatch(GetRunnable(), NS_DISPATCH_NORMAL);
+      }
+    }
+  private:
+    static nsCOMPtr<nsIRunnable> mRunnable;
+};
 
-// This class is used as a runnable on the sSwitchThread
-class SensorInfo {
+nsCOMPtr<nsIRunnable> PollSensor::mRunnable = NULL;
+
+class SwitchSensor {
   public:
-    NS_INLINE_DECL_REFCOUNTING(SensorInfo)
-
-    SensorInfo(bool aActivate, sensor_t aSensor, pthread_t aThreadId) :
-               activate(aActivate), sensor(aSensor), threadId(aThreadId) { }
+    NS_INLINE_DECL_REFCOUNTING(SwitchSensor)
+    
+    SwitchSensor(bool aActivate, sensor_t aSensor, pthread_t aThreadId) :
+      mActivate(aActivate), mSensor(aSensor), mThreadId(aThreadId) { }
 
     void Switch() {
-     SensorDevice& device = SensorDevice::getInstance();
-     device.activate((void*)threadId, sensor.handle, activate);
-     device.setDelay((void*)threadId, sensor.handle, DEFAULT_DEVICE_POLL_RATE);
-    }
+      int index = HardwareSensorToHalSensor(mSensor.type);
+
+      MOZ_ASSERT(sSensorStatus[index].count == 0 || mActivate);
+
+      SensorDevice& device = SensorDevice::getInstance();
+      
+      device.activate((void*)mThreadId, mSensor.handle, mActivate);
+      device.setDelay((void*)mThreadId, mSensor.handle, DEFAULT_DEVICE_POLL_RATE);
 
+      if (mActivate) {
+        if (++sActivatedSensors == 1) {
+          sSwitchThread->Dispatch(PollSensor::GetRunnable(), NS_DISPATCH_NORMAL);
+        }
+        sSensorStatus[index].count++;
+      } else {
+        sSensorStatus[index].count--;
+        --sActivatedSensors;
+      }
+    }
+  
   protected:
-    SensorInfo() { };
-    bool      activate;
-    sensor_t  sensor;
-    pthread_t threadId;
+    SwitchSensor() { };
+    bool      mActivate;
+    sensor_t  mSensor;
+    pthread_t mThreadId;
 };
 
+
 static void
-SensorSwitch(SensorType aSensor, bool activate)
+SetSensorState(SensorType aSensor, bool activate)
 {
   int type = HalSensorToHardwareSensor(aSensor);
   const sensor_t* sensors = NULL;
   SensorDevice& device = SensorDevice::getInstance();
   size_t size = device.getSensorList(&sensors);
   for (size_t i = 0; i < size; i++) {
     if (sensors[i].type == type) {
-      // Post an event to the activation thread
-      nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(new SensorInfo(activate, sensors[i], pthread_self()),
-                                                         &SensorInfo::Switch);
+      // Post an event to the sensor thread
+      nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(new SwitchSensor(activate, sensors[i], pthread_self()),
+                                                         &SwitchSensor::Switch);
+
       sSwitchThread->Dispatch(event, NS_DISPATCH_NORMAL);
       break;
     }
   }
 }
 
 void
 EnableSensorNotifications(SensorType aSensor) 
 {
-  if (!sInitialized) {
-    InitializeResources();
+  if (sSwitchThread == nsnull) {
+    NS_NewThread(getter_AddRefs(sSwitchThread));
   }
   
-  SensorSwitch(aSensor, true);
-  sActivatedSensors++;
+  SetSensorState(aSensor, true);
 }
 
 void
 DisableSensorNotifications(SensorType aSensor) 
 {
-  if (!sInitialized) {
-    NS_WARNING("Disable sensors without initializing first");
-    return;
-  }
-  
-  SensorSwitch(aSensor, false);  
-  sActivatedSensors--;
-
-  if (!sActivatedSensors) {
-    ReleaseResources();  
-  }
+  SetSensorState(aSensor, false);
 }
 
 } // hal_impl
 } // mozilla
--- a/intl/locale/src/windows/nsWin32Locale.cpp
+++ b/intl/locale/src/windows/nsWin32Locale.cpp
@@ -642,17 +642,17 @@ nsWin32Locale::GetPlatformLocale(const n
       *winLCID = lcid;
       return NS_OK;
     }
   }
 
   char    locale_string[9] = {'\0','\0','\0','\0','\0','\0','\0','\0','\0'};
   char*   language_code;
   char*   country_code;
-  int     i,j;
+  size_t  i, j;
 
   // parse the locale
   const PRUnichar* data;
   j = NS_StringGetData(locale, &data);
   for (i = 0; i < 7 && i < j; i++) {
     locale_string[i] = data[i] == '-' ? '\0' : data[i];
   }
 
@@ -695,17 +695,17 @@ nsWin32Locale::GetXPLocale(LCID winLCID,
     if (rv != 0)
     {
       locale.Assign(ret_locale);
       return;
     }
   }
 
   DWORD    lang_id, sublang_id;
-  int      i,j;
+  size_t   i, j;
 
   lang_id = PRIMARYLANGID(LANGIDFROMLCID(winLCID));
   sublang_id = SUBLANGID(LANGIDFROMLCID(winLCID));
 
   /* Special-case Norwegian Bokmal and Norwegian Nynorsk, which have the same
      LANG_ID on Windows, but have separate ISO-639-2 codes */
   if (lang_id == LANG_NORWEGIAN) {
     if (sublang_id == SUBLANG_NORWEGIAN_BOKMAL) {
@@ -749,17 +749,17 @@ nsWin32Locale::GetXPLocale(LCID winLCID,
   locale.AssignLiteral("en-US"); 
   return;
 }
 
 #ifdef DEBUG
 void
 test_internal_tables(void)
 {
-	int	i;
+	size_t i;
 
 	for(i=1;i<LENGTH_MAPPING_LIST;i++) {
 		if (strcmp(dbg_list[i-1].iso_code,dbg_list[i].iso_code)>=0)
 			fprintf(stderr,"nsLocale: language_list %s and %s are not ordered\n",dbg_list[i-1].iso_code,dbg_list[i].iso_code);
 	}
 
 	i=0;
 	while(strlen(dbg_list[i].iso_code)!=0) {
--- a/intl/uconv/src/nsConverterInputStream.cpp
+++ b/intl/uconv/src/nsConverterInputStream.cpp
@@ -250,17 +250,17 @@ nsConverterInputStream::Fill(nsresult * 
       // bug 160784 again
       srcConsumed = NS_MAX<PRUint32>(srcConsumed, 0);
       mConverter->Reset();
     }
     NS_ASSERTION(srcConsumed <= mByteData->GetLength(),
                  "Whoa.  The converter should have returned NS_OK_UDEC_MOREINPUT before this point!");
   } while (mReplacementChar &&
            NS_FAILED(*aErrorCode) &&
-           mUnicharData->GetBufferSize() > mUnicharDataLength);
+           PRUint32(mUnicharData->GetBufferSize()) > mUnicharDataLength);
 
   mLeftOverBytes = mByteData->GetLength() - srcConsumed;
 
   return mUnicharDataLength;
 }
 
 NS_IMETHODIMP
 nsConverterInputStream::ReadLine(nsAString& aLine, bool* aResult)
--- a/intl/uconv/util/nsUCSupport.h
+++ b/intl/uconv/util/nsUCSupport.h
@@ -44,17 +44,17 @@
 #include "uconvutil.h"
 #include "mozilla/Mutex.h"
 
 #define ONE_BYTE_TABLE_SIZE 256
 
 inline bool WillOverrun(PRUnichar* aDest, PRUnichar* aDestEnd, PRUint32 aLength)
 {
   NS_ASSERTION(aDest <= aDestEnd, "Pointer overrun even before check");
-  return ((aDestEnd - aDest) < aLength);
+  return (PRUint32(aDestEnd - aDest) < aLength);
 }
 #define CHECK_OVERRUN(dest, destEnd, length) (WillOverrun(dest, destEnd, length))
 
 #ifdef NS_DEBUG
 // {7AFC9F0A-CFE1-44ea-A755-E3B86AB1226E}
 #define NS_IBASICDECODER_IID \
 { 0x7afc9f0a, 0xcfe1, 0x44ea, { 0xa7, 0x55, 0xe3, 0xb8, 0x6a, 0xb1, 0x22, 0x6e } }
 
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -154,18 +154,17 @@ mozJSLoaderErrorReporter(JSContext *cx, 
     nsCOMPtr<nsIScriptError> errorObject =
         do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
 
     if (consoleService && errorObject) {
         /*
          * Got an error object; prepare appropriate-width versions of
          * various arguments to it.
          */
-        nsAutoString fileUni;
-        fileUni.AssignWithConversion(rep->filename);
+        NS_ConvertASCIItoUTF16 fileUni(rep->filename);
 
         PRUint32 column = rep->uctokenptr - rep->uclinebuf;
 
         rv = errorObject->Init(reinterpret_cast<const PRUnichar*>
                                                (rep->ucmessage),
                                fileUni.get(),
                                reinterpret_cast<const PRUnichar*>
                                                (rep->uclinebuf),
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -1480,17 +1480,17 @@ XPCConvert::JSErrorToXPCException(XPCCal
 {
     nsresult rv = NS_ERROR_FAILURE;
     nsRefPtr<nsScriptError> data;
     if (report) {
         nsAutoString bestMessage;
         if (report && report->ucmessage) {
             bestMessage = (const PRUnichar *)report->ucmessage;
         } else if (message) {
-            bestMessage.AssignWithConversion(message);
+            CopyASCIItoUTF16(message, bestMessage);
         } else {
             bestMessage.AssignLiteral("JavaScript Error");
         }
 
         data = new nsScriptError();
         if (!data)
             return NS_ERROR_OUT_OF_MEMORY;
 
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -1104,18 +1104,17 @@ nsXPCWrappedJSClass::CheckForException(X
                         // No luck getting one from the exception, so
                         // try to cook one up.
                         scriptError = do_CreateInstance(XPC_SCRIPT_ERROR_CONTRACTID);
                         if (nsnull != scriptError) {
                             char* exn_string;
                             rv = xpc_exception->ToString(&exn_string);
                             if (NS_SUCCEEDED(rv)) {
                                 // use toString on the exception as the message
-                                nsAutoString newMessage;
-                                newMessage.AssignWithConversion(exn_string);
+                                NS_ConvertASCIItoUTF16 newMessage(exn_string);
                                 nsMemory::Free((void *) exn_string);
 
                                 // try to get filename, lineno from the first
                                 // stack frame location.
                                 PRInt32 lineNumber = 0;
                                 nsXPIDLCString sourceName;
 
                                 nsCOMPtr<nsIStackFrame> location;
--- a/js/xpconnect/tests/chrome/test_doublewrappedcompartments.xul
+++ b/js/xpconnect/tests/chrome/test_doublewrappedcompartments.xul
@@ -23,22 +23,24 @@ https://bugzilla.mozilla.org/show_bug.cg
   <!-- test code goes here -->
   <script type="application/javascript"><![CDATA[
       const Ci = Components.interfaces;
       const utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
                           .getInterface(Ci.nsIDOMWindowUtils);
 
       function go() {
         var wrappedWin = $('ifr').contentWindow;
+        is(typeof wrappedWin.expando, 'undefined', "Shouldn't be able to see the expando");
+
         var unwrapped = wrappedWin.wrappedJSObject;
 
-        var filter = unwrapped.filter;
-        is(utils.getClassName(filter), 'Proxy', 'properly wrapped');
-        is(typeof filter.QueryInterface, 'function', 'double wrapped');
+        var expando = unwrapped.expando;
+        is(utils.getClassName(expando), 'Proxy', 'properly wrapped');
+        is(typeof expando.QueryInterface, 'function', 'double wrapped');
 
-        ok(unwrapped.testme(filter),
+        ok(unwrapped.testme(expando),
            "content didn't get a proxy, but another double wrapped object");
         SimpleTest.finish();
       }
 
       SimpleTest.waitForExplicitFinish();
   ]]></script>
 </window>
--- a/js/xpconnect/tests/mochitest/file_doublewrappedcompartments.html
+++ b/js/xpconnect/tests/mochitest/file_doublewrappedcompartments.html
@@ -1,14 +1,16 @@
 <html>
     <head>
         <script>
-            var fcn = function() {};
-            var iter = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, fcn, false);
-            var filter = iter.filter;
+            // We want to put an expando on the object, but we want this object
+            // to be wrapped in other compartments. This means that the expando
+            // must implement precreate, which happens (in general) for nodes.
+            // So we just do a cyclic reference to the document body.
+            window.expando = document.documentElement;
 
             function testme(obj) {
                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                 const Ci = Components.interfaces;
                 const utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
                                     .getInterface(Ci.nsIDOMWindowUtils);
 
                 return utils.getClassName(obj) != "Proxy" &&
--- a/js/xpconnect/wrappers/WrapperFactory.cpp
+++ b/js/xpconnect/wrappers/WrapperFactory.cpp
@@ -182,21 +182,16 @@ WrapperFactory::PrepareForWrapping(JSCon
     // those objects in a security wrapper, then we need to hand back the
     // wrapper for the new scope instead. Also, global objects don't move
     // between scopes so for those we also want to return the wrapper. So...
     if (!IS_WN_WRAPPER(obj) || !js::GetObjectParent(obj))
         return DoubleWrap(cx, obj, flags);
 
     XPCWrappedNative *wn = static_cast<XPCWrappedNative *>(xpc_GetJSPrivate(obj));
 
-    // If the object doesn't have classinfo we want to return the same
-    // XPCWrappedNative so that we keep the same set of interfaces.
-    if (!wn->GetClassInfo())
-        return DoubleWrap(cx, obj, flags);
-
     JSAutoEnterCompartment ac;
     if (!ac.enter(cx, obj))
         return nsnull;
     XPCCallContext ccx(JS_CALLER, cx, obj);
 
     {
         if (NATIVE_HAS_FLAG(&ccx, WantPreCreate)) {
             // We have a precreate hook. This object might enforce that we only
--- a/layout/generic/nsQueryFrame.h
+++ b/layout/generic/nsQueryFrame.h
@@ -137,17 +137,16 @@ public:
     nsInlineFrame_id,
     nsLeafBoxFrame_id,
     nsLeafFrame_id,
     nsLegendFrame_id,
     nsListBoxBodyFrame_id,
     nsListControlFrame_id,
     nsListItemFrame_id,
     nsMathMLContainerFrame_id,
-    nsMathMLForeignFrameWrapper_id,
     nsMathMLFrame_id,
     nsMathMLmactionFrame_id,
     nsMathMLmathBlockFrame_id,
     nsMathMLmathInlineFrame_id,
     nsMathMLmencloseFrame_id,
     nsMathMLmfencedFrame_id,
     nsMathMLmfracFrame_id,
     nsMathMLmmultiscriptsFrame_id,
--- a/layout/mathml/Makefile.in
+++ b/layout/mathml/Makefile.in
@@ -57,17 +57,16 @@ LOCAL_INCLUDES = \
 	-I$(topsrcdir)/content/base/src \
 	-I$(topsrcdir)/content/mathml/content/src \
 	-I$(srcdir)/../xul/base/src \
 	$(NULL)
 
 CPPSRCS =         nsMathMLChar.cpp		        \
                   nsMathMLFrame.cpp		\
                   nsMathMLContainerFrame.cpp		\
-                  nsMathMLForeignFrameWrapper.cpp		\
                   nsMathMLOperators.cpp \
                   nsMathMLTokenFrame.cpp		\
                   nsMathMLmoFrame.cpp			\
                   nsMathMLmrowFrame.cpp		        \
                   nsMathMLmphantomFrame.cpp		\
                   nsMathMLmfencedFrame.cpp		\
                   nsMathMLmfracFrame.cpp		\
                   nsMathMLmsupFrame.cpp			\
deleted file mode 100644
--- a/layout/mathml/nsMathMLForeignFrameWrapper.cpp
+++ /dev/null
@@ -1,90 +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 MathML Project.
- *
- * The Initial Developer of the Original Code is
- * The University Of Queensland.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roger B. Sidje <rbs@maths.uq.edu.au>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of 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 ***** */
-
-//
-// a helper frame class to wrap non-MathML frames so that foreign elements 
-// (e.g., html:img) can mix better with other surrounding MathML markups
-//
-
-#include "nsCOMPtr.h"
-#include "nsHTMLParts.h"
-#include "nsFrame.h"
-#include "nsBlockFrame.h"
-#include "nsLineLayout.h"
-#include "nsPresContext.h"
-#include "nsStyleContext.h"
-#include "nsStyleConsts.h"
-
-#include "nsMathMLForeignFrameWrapper.h"
-
-NS_QUERYFRAME_HEAD(nsMathMLForeignFrameWrapper)
-  NS_QUERYFRAME_ENTRY(nsMathMLFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
-
-nsIFrame*
-NS_NewMathMLForeignFrameWrapper(nsIPresShell* aPresShell, nsStyleContext* aContext)
-{
-  return new (aPresShell) nsMathMLForeignFrameWrapper(aContext);
-}
-
-NS_IMPL_FRAMEARENA_HELPERS(nsMathMLForeignFrameWrapper)
-
-NS_IMETHODIMP
-nsMathMLForeignFrameWrapper::Reflow(nsPresContext*          aPresContext,
-                                    nsHTMLReflowMetrics&     aDesiredSize,
-                                    const nsHTMLReflowState& aReflowState,
-                                    nsReflowStatus&          aStatus)
-{
-  // Let the base class do the reflow
-  nsresult rv = nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
-
-  mReference.x = 0;
-  mReference.y = aDesiredSize.ascent;
-
-  // just make-up a bounding metrics
-  mBoundingMetrics = nsBoundingMetrics();
-  mBoundingMetrics.ascent = aDesiredSize.ascent;
-  mBoundingMetrics.descent = aDesiredSize.height - aDesiredSize.ascent;
-  mBoundingMetrics.width = aDesiredSize.width;
-  mBoundingMetrics.leftBearing = 0;
-  mBoundingMetrics.rightBearing = aDesiredSize.width;
-  aDesiredSize.mBoundingMetrics = mBoundingMetrics;
-
-  NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
-  return rv;
-}
deleted file mode 100644
--- a/layout/mathml/nsMathMLForeignFrameWrapper.h
+++ /dev/null
@@ -1,122 +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 MathML Project.
- *
- * The Initial Developer of the Original Code is
- * The University Of Queensland.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roger B. Sidje <rbs@maths.uq.edu.au>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of 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 ***** */
-
-//
-// a helper frame class to wrap non-MathML frames so that foreign elements 
-// (e.g., html:img) can mix better with other surrounding MathML markups
-//
-
-#ifndef nsMathMLForeignFrameWrapper_h___
-#define nsMathMLForeignFrameWrapper_h___
-
-#include "nsCOMPtr.h"
-#include "nsMathMLContainerFrame.h"
-
-class nsMathMLForeignFrameWrapper : public nsBlockFrame,
-                                    public nsMathMLFrame {
-public:
-  friend nsIFrame* NS_NewMathMLForeignFrameWrapper(nsIPresShell* aPresShell, nsStyleContext* aContext);
-
-  NS_DECL_QUERYFRAME
-  NS_DECL_FRAMEARENA_HELPERS
-
-  // Overloaded nsIMathMLFrame methods
-
-  NS_IMETHOD
-  UpdatePresentationDataFromChildAt(PRInt32         aFirstIndex,
-                                    PRInt32         aLastIndex,
-                                    PRUint32        aFlagsValues,
-                                    PRUint32        aFlagsToUpdate)
-  {
-    nsMathMLContainerFrame::PropagatePresentationDataFromChildAt(this,
-      aFirstIndex, aLastIndex, aFlagsValues, aFlagsToUpdate);
-    return NS_OK;
-  }
-
-  // overloaded nsBlockFrame methods
-
-#ifdef NS_DEBUG
-  NS_IMETHOD
-  SetInitialChildList(ChildListID     aListID,
-                      nsFrameList&    aChildList)
-  {
-    NS_ASSERTION(aChildList.NotEmpty() && aChildList.GetLength() == 1,
-                 "there must be one and only one child frame");
-    return nsBlockFrame::SetInitialChildList(aListID, aChildList);
-  }
-#endif
-
-  NS_IMETHOD
-  Reflow(nsPresContext*          aPresContext,
-         nsHTMLReflowMetrics&     aDesiredSize,
-         const nsHTMLReflowState& aReflowState,
-         nsReflowStatus&          aStatus);
-
-  // we are just a wrapper and these methods shouldn't be called
-  NS_IMETHOD
-  AppendFrames(ChildListID     aListID,
-               nsFrameList&    aFrameList)
-  {
-    NS_NOTREACHED("unsupported operation");
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
-  NS_IMETHOD
-  InsertFrames(ChildListID     aListID,
-               nsIFrame*       aPrevFrame,
-               nsFrameList&    aFrameList)
-  {
-    NS_NOTREACHED("unsupported operation");
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
-  // Our life is bound to the life of our unique child.
-  // When our child goes away, we ask our parent to delete us
-  NS_IMETHOD
-  RemoveFrame(ChildListID     aListID,
-              nsIFrame*       aOldFrame)
-  {
-    return mParent->RemoveFrame(aListID, this);
-  }
-
-protected:
-  nsMathMLForeignFrameWrapper(nsStyleContext* aContext) : nsBlockFrame(aContext) {}
-  virtual ~nsMathMLForeignFrameWrapper() {}
-};
-
-#endif /* nsMathMLForeignFrameWrapper_h___ */
--- a/layout/mathml/nsMathMLParts.h
+++ b/layout/mathml/nsMathMLParts.h
@@ -38,17 +38,16 @@
 
 #ifndef nsMathMLParts_h___
 #define nsMathMLParts_h___
 
 #include "nscore.h"
 #include "nsISupports.h"
 
 // Factory methods for creating MathML objects
-nsIFrame* NS_NewMathMLForeignFrameWrapper(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame* NS_NewMathMLTokenFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame* NS_NewMathMLmoFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame* NS_NewMathMLmrowFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame* NS_NewMathMLmphantomFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame* NS_NewMathMLmpaddedFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame* NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame* NS_NewMathMLmsFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame* NS_NewMathMLmfencedFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
--- a/layout/svg/base/src/Makefile.in
+++ b/layout/svg/base/src/Makefile.in
@@ -101,17 +101,16 @@ include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES	= \
 		-I$(srcdir)/../../../base \
 		-I$(srcdir)/../../../generic \
 		-I$(srcdir)/../../../style \
 		-I$(srcdir)/../../../xul/base/src \
 		-I$(srcdir)/../../../../content/svg/content/src \
 		-I$(srcdir)/../../../../content/base/src \
-		-I$(srcdir)/../../../../content/html/content/src \
 		$(NULL)
 
 libs::
 	$(INSTALL) $(srcdir)/svg.css $(DIST)/bin/res
 
 install::
 	$(SYSINSTALL) $(IFLAGS1) $(srcdir)/svg.css $(DESTDIR)$(mozappdir)/res
 
--- a/layout/svg/base/src/SVGFEContainerFrame.cpp
+++ b/layout/svg/base/src/SVGFEContainerFrame.cpp
@@ -29,17 +29,21 @@
  * 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 ***** */
 
+// Keep in (case-insensitive) order:
 #include "nsContainerFrame.h"
+#include "nsGkAtoms.h"
+#include "nsIFrame.h"
+#include "nsLiteralString.h"
 #include "nsSVGEffects.h"
 #include "nsSVGFilters.h"
 
 typedef nsContainerFrame SVGFEContainerFrameBase;
 
 /*
  * This frame is used by filter primitive elements that
  * have special child elements that provide parameters.
--- a/layout/svg/base/src/SVGFEImageFrame.cpp
+++ b/layout/svg/base/src/SVGFEImageFrame.cpp
@@ -29,21 +29,23 @@
  * 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 ***** */
 
+// Keep in (case-insensitive) order:
+#include "nsContentUtils.h"
 #include "nsFrame.h"
+#include "nsGkAtoms.h"
+#include "nsLiteralString.h"
 #include "nsSVGEffects.h"
 #include "nsSVGFilters.h"
-#include "nsContentUtils.h"
-#include "nsImageLoadingContent.h"
 
 using namespace mozilla;
 
 typedef nsFrame SVGFEImageFrameBase;
 
 class SVGFEImageFrame : public SVGFEImageFrameBase
 {
   friend nsIFrame*
--- a/layout/svg/base/src/SVGFELeafFrame.cpp
+++ b/layout/svg/base/src/SVGFELeafFrame.cpp
@@ -29,19 +29,21 @@
  * 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 ***** */
 
+// Keep in (case-insensitive) order:
 #include "nsFrame.h"
+#include "nsGkAtoms.h"
+#include "nsSVGEffects.h"
 #include "nsSVGFilters.h"
-#include "nsSVGEffects.h"
 
 typedef nsFrame SVGFELeafFrameBase;
 
 /*
  * This frame is used by filter primitive elements that don't
  * have special child elements that provide parameters.
  */
 class SVGFELeafFrame : public SVGFELeafFrameBase
--- a/layout/svg/base/src/SVGFEUnstyledLeafFrame.cpp
+++ b/layout/svg/base/src/SVGFEUnstyledLeafFrame.cpp
@@ -29,19 +29,21 @@
  * 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 ***** */
 
+// Keep in (case-insensitive) order:
 #include "nsFrame.h"
+#include "nsGkAtoms.h"
+#include "nsSVGEffects.h"
 #include "nsSVGFilters.h"
-#include "nsSVGEffects.h"
 
 typedef nsFrame SVGFEUnstyledLeafFrameBase;
 
 class SVGFEUnstyledLeafFrame : public SVGFEUnstyledLeafFrameBase
 {
   friend nsIFrame*
   NS_NewSVGFEUnstyledLeafFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 protected:
--- a/layout/svg/base/src/nsSVGAFrame.cpp
+++ b/layout/svg/base/src/nsSVGAFrame.cpp
@@ -31,22 +31,21 @@
  * 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 ***** */
 
+// Keep in (case-insensitive) order:
+#include "gfxMatrix.h"
+#include "nsSVGAElement.h"
 #include "nsSVGTSpanFrame.h"
-#include "nsISVGGlyphFragmentNode.h"
-#include "nsSVGGraphicElement.h"
-#include "nsSVGAElement.h"
 #include "nsSVGUtils.h"
-#include "gfxMatrix.h"
 #include "SVGLengthList.h"
 
 // <a> elements can contain text. nsSVGGlyphFrames expect to have
 // a class derived from nsSVGTextContainerFrame as a parent. We
 // also need something that implements nsISVGGlyphFragmentNode to get
 // the text DOM to work.
 
 using namespace mozilla;
--- a/layout/svg/base/src/nsSVGClipPathFrame.cpp
+++ b/layout/svg/base/src/nsSVGClipPathFrame.cpp
@@ -29,27 +29,27 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGClipPathFrame.h"
 
-#include "nsIDOMDocument.h"
-#include "nsIDocument.h"
+// Keep others in (case-insensitive) order:
+#include "gfxContext.h"
+#include "nsGkAtoms.h"
 #include "nsIDOMSVGClipPathElement.h"
 #include "nsRenderingContext.h"
-#include "nsGkAtoms.h"
-#include "nsSVGUtils.h"
+#include "nsSVGClipPathElement.h"
 #include "nsSVGEffects.h"
-#include "nsSVGClipPathElement.h"
-#include "gfxContext.h"
+#include "nsSVGUtils.h"
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsIFrame*
 NS_NewSVGClipPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsSVGClipPathFrame(aContext);
--- a/layout/svg/base/src/nsSVGContainerFrame.cpp
+++ b/layout/svg/base/src/nsSVGContainerFrame.cpp
@@ -29,20 +29,22 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGContainerFrame.h"
+
+// Keep others in (case-insensitive) order:
 #include "nsSVGElement.h"
 #include "nsSVGUtils.h"
-#include "nsSVGOuterSVGFrame.h"
 
 NS_QUERYFRAME_HEAD(nsSVGContainerFrame)
   NS_QUERYFRAME_ENTRY(nsSVGContainerFrame)
 NS_QUERYFRAME_TAIL_INHERITING(nsSVGContainerFrameBase)
 
 NS_QUERYFRAME_HEAD(nsSVGDisplayContainerFrame)
   NS_QUERYFRAME_ENTRY(nsSVGDisplayContainerFrame)
   NS_QUERYFRAME_ENTRY(nsISVGChildFrame)
--- a/layout/svg/base/src/nsSVGEffects.cpp
+++ b/layout/svg/base/src/nsSVGEffects.cpp
@@ -30,25 +30,26 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGEffects.h"
+
+// Keep others in (case-insensitive) order:
+#include "nsCSSFrameConstructor.h"
 #include "nsISupportsImpl.h"
-#include "nsSVGOuterSVGFrame.h"
+#include "nsSVGClipPathFrame.h"
 #include "nsSVGFilterFrame.h"
-#include "nsSVGClipPathFrame.h"
 #include "nsSVGMaskFrame.h"
 #include "nsSVGTextPathFrame.h"
-#include "nsCSSFrameConstructor.h"
-#include "nsFrameManager.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 // nsSVGRenderingObserver impl
 NS_IMPL_ISUPPORTS1(nsSVGRenderingObserver, nsIMutationObserver)
 
 void
--- a/layout/svg/base/src/nsSVGFilterFrame.cpp
+++ b/layout/svg/base/src/nsSVGFilterFrame.cpp
@@ -29,33 +29,29 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGFilterFrame.h"
 
+// Keep others in (case-insensitive) order:
+#include "gfxASurface.h"
+#include "gfxUtils.h"
+#include "nsGkAtoms.h"
 #include "nsRenderingContext.h"
-#include "nsIDocument.h"
-#include "nsSVGOuterSVGFrame.h"
-#include "nsGkAtoms.h"
 #include "nsSVGEffects.h"
-#include "nsSVGUtils.h"
 #include "nsSVGFilterElement.h"
-#include "nsSVGFilters.h"
-#include "gfxASurface.h"
-#include "gfxContext.h"
-#include "gfxImageSurface.h"
+#include "nsSVGFilterInstance.h"
 #include "nsSVGFilterPaintCallback.h"
-#include "nsSVGRect.h"
-#include "nsSVGFilterInstance.h"
-#include "gfxUtils.h"
+#include "nsSVGUtils.h"
 
 nsIFrame*
 NS_NewSVGFilterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsSVGFilterFrame(aContext);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSVGFilterFrame)
--- a/layout/svg/base/src/nsSVGFilterInstance.cpp
+++ b/layout/svg/base/src/nsSVGFilterInstance.cpp
@@ -29,26 +29,27 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGFilterInstance.h"
 
-#include "nsRenderingContext.h"
-#include "nsSVGUtils.h"
-#include "nsIDOMSVGUnitTypes.h"
+// Keep others in (case-insensitive) order:
 #include "gfxPlatform.h"
-#include "nsSVGFilterPaintCallback.h"
+#include "gfxUtils.h"
+#include "nsIDOMSVGUnitTypes.h"
+#include "nsRenderingContext.h"
 #include "nsSVGFilterElement.h"
-#include "nsLayoutUtils.h"
-#include "gfxUtils.h"
+#include "nsSVGFilterPaintCallback.h"
+#include "nsSVGUtils.h"
 
 float
 nsSVGFilterInstance::GetPrimitiveNumber(PRUint8 aCtxType, float aValue) const
 {
   nsSVGLength2 val;
   val.Init(aCtxType, 0xff, aValue,
            nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
 
--- a/layout/svg/base/src/nsSVGForeignObjectFrame.cpp
+++ b/layout/svg/base/src/nsSVGForeignObjectFrame.cpp
@@ -31,34 +31,33 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGForeignObjectFrame.h"
 
+// Keep others in (case-insensitive) order:
+#include "gfxContext.h"
+#include "gfxMatrix.h"
+#include "nsGkAtoms.h"
 #include "nsIDOMSVGForeignObjectElem.h"
-#include "nsIDOMSVGSVGElement.h"
-#include "nsSVGOuterSVGFrame.h"
+#include "nsINameSpaceManager.h"
+#include "nsLayoutUtils.h"
 #include "nsRegion.h"
 #include "nsRenderingContext.h"
-#include "nsGkAtoms.h"
-#include "nsLayoutUtils.h"
-#include "nsSVGUtils.h"
-#include "nsIURI.h"
-#include "nsSVGRect.h"
-#include "nsINameSpaceManager.h"
+#include "nsSVGContainerFrame.h"
 #include "nsSVGEffects.h"
 #include "nsSVGForeignObjectElement.h"
-#include "nsSVGContainerFrame.h"
-#include "gfxContext.h"
-#include "gfxMatrix.h"
+#include "nsSVGOuterSVGFrame.h"
+#include "nsSVGUtils.h"
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsIFrame*
 NS_NewSVGForeignObjectFrame(nsIPresShell   *aPresShell,
                             nsStyleContext *aContext)
 {
--- a/layout/svg/base/src/nsSVGGFrame.cpp
+++ b/layout/svg/base/src/nsSVGGFrame.cpp
@@ -31,22 +31,25 @@
  * 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 ***** */
 
+// Main header first:
+#include "nsSVGGFrame.h"
+
+// Keep others in (case-insensitive) order:
+#include "nsGkAtoms.h"
 #include "nsIDOMSVGTransformable.h"
-#include "nsSVGGFrame.h"
 #include "nsIFrame.h"
-#include "nsGkAtoms.h"
+#include "nsSVGGraphicElement.h"
 #include "nsSVGUtils.h"
-#include "nsSVGGraphicElement.h"
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsIFrame*
 NS_NewSVGGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {  
   return new (aPresShell) nsSVGGFrame(aContext);
--- a/layout/svg/base/src/nsSVGGenericContainerFrame.cpp
+++ b/layout/svg/base/src/nsSVGGenericContainerFrame.cpp
@@ -31,18 +31,18 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGGenericContainerFrame.h"
-#include "nsSVGUtils.h"
 
 //----------------------------------------------------------------------
 // nsSVGGenericContainerFrame Implementation
 
 nsIFrame*
 NS_NewSVGGenericContainerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsSVGGenericContainerFrame(aContext);
--- a/layout/svg/base/src/nsSVGGeometryFrame.cpp
+++ b/layout/svg/base/src/nsSVGGeometryFrame.cpp
@@ -29,24 +29,26 @@
  * 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 ***** */
 
+// Main header first:
+#include "nsSVGGeometryFrame.h"
+
+// Keep others in (case-insensitive) order:
+#include "gfxContext.h"
 #include "nsPresContext.h"
+#include "nsSVGEffects.h"
+#include "nsSVGPaintServerFrame.h"
 #include "nsSVGPathElement.h"
 #include "nsSVGUtils.h"
-#include "nsSVGGeometryFrame.h"
-#include "nsSVGPaintServerFrame.h"
-#include "nsContentUtils.h"
-#include "gfxContext.h"
-#include "nsSVGEffects.h"
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSVGGeometryFrame)
 
 //----------------------------------------------------------------------
 // nsIFrame methods
 
 NS_IMETHODIMP
 nsSVGGeometryFrame::Init(nsIContent* aContent,
--- a/layout/svg/base/src/nsSVGGlyphFrame.cpp
+++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp
@@ -31,37 +31,36 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGGlyphFrame.h"
 
-#include "nsRenderingContext.h"
-#include "nsSVGTextFrame.h"
-#include "mozilla/LookAndFeel.h"
-#include "nsTextFragment.h"
-#include "nsBidiPresUtils.h"
-#include "nsSVGUtils.h"
-#include "SVGLengthList.h"
-#include "nsIDOMSVGLength.h"
-#include "nsIDOMSVGRect.h"
+// Keep others in (case-insensitive) order:
 #include "DOMSVGPoint.h"
-#include "nsSVGTextPathFrame.h"
-#include "nsSVGPathElement.h"
-#include "nsSVGRect.h"
-#include "nsDOMError.h"
 #include "gfxContext.h"
 #include "gfxMatrix.h"
 #include "gfxPlatform.h"
+#include "mozilla/LookAndFeel.h"
+#include "nsBidiPresUtils.h"
+#include "nsDOMError.h"
+#include "nsIDOMSVGRect.h"
+#include "nsRenderingContext.h"
 #include "nsSVGEffects.h"
 #include "nsSVGPaintServerFrame.h"
+#include "nsSVGRect.h"
+#include "nsSVGTextPathFrame.h"
+#include "nsSVGUtils.h"
+#include "nsTextFragment.h"
+#include "SVGLengthList.h"
 
 using namespace mozilla;
 
 struct CharacterPosition {
   gfxPoint pos;
   gfxFloat angle;
   bool draw;
 };
--- a/layout/svg/base/src/nsSVGGradientFrame.cpp
+++ b/layout/svg/base/src/nsSVGGradientFrame.cpp
@@ -32,27 +32,27 @@
  * 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 "nsIDOMSVGAnimatedNumber.h"
-#include "nsIDOMSVGAnimTransformList.h"
-#include "SVGAnimatedTransformList.h"
-#include "nsSVGEffects.h"
-#include "nsIDOMSVGStopElement.h"
-#include "nsSVGGradientElement.h"
-#include "nsSVGGeometryFrame.h"
+// Main header first:
 #include "nsSVGGradientFrame.h"
-#include "gfxContext.h"
+
+// Keep others in (case-insensitive) order:
 #include "gfxPattern.h"
 #include "nsContentUtils.h"
+#include "nsIDOMSVGAnimatedNumber.h"
+#include "nsIDOMSVGStopElement.h"
+#include "nsSVGEffects.h"
+#include "nsSVGGradientElement.h"
+#include "SVGAnimatedTransformList.h"
 
 using mozilla::SVGAnimatedTransformList;
 
 //----------------------------------------------------------------------
 // Helper classes
 
 class nsSVGGradientFrame::AutoGradientReferencer
 {
--- a/layout/svg/base/src/nsSVGImageFrame.cpp
+++ b/layout/svg/base/src/nsSVGImageFrame.cpp
@@ -29,36 +29,33 @@
  * 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 "nsSVGPathGeometryFrame.h"
-
-#include "nsRenderingContext.h"
+// Keep in (case-insensitive) order:
+#include "gfxContext.h"
+#include "gfxMatrix.h"
+#include "gfxPlatform.h"
 #include "imgIContainer.h"
-#include "nsStubImageDecoderObserver.h"
-#include "nsImageLoadingContent.h"
 #include "nsIDOMSVGImageElement.h"
 #include "nsLayoutUtils.h"
+#include "nsRenderingContext.h"
+#include "nsStubImageDecoderObserver.h"
 #include "nsSVGEffects.h"
 #include "nsSVGImageElement.h"
+#include "nsSVGPathGeometryFrame.h"
+#include "nsSVGSVGElement.h"
 #include "nsSVGUtils.h"
-#include "gfxContext.h"
-#include "gfxMatrix.h"
-#include "nsIInterfaceRequestorUtils.h"
-#include "gfxPlatform.h"
-#include "nsSVGSVGElement.h"
 
 using namespace mozilla;
 
-class nsRenderingContext;
 class nsSVGImageFrame;
 
 class nsSVGImageListener MOZ_FINAL : public nsStubImageDecoderObserver
 {
 public:
   nsSVGImageListener(nsSVGImageFrame *aFrame);
 
   NS_DECL_ISUPPORTS
--- a/layout/svg/base/src/nsSVGInnerSVGFrame.cpp
+++ b/layout/svg/base/src/nsSVGInnerSVGFrame.cpp
@@ -31,25 +31,26 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGInnerSVGFrame.h"
 
-#include "nsRenderingContext.h"
+// Keep others in (case-insensitive) order:
+#include "gfxContext.h"
 #include "nsIFrame.h"
 #include "nsISVGChildFrame.h"
-#include "nsIDOMSVGAnimatedRect.h"
+#include "nsRenderingContext.h"
+#include "nsSVGContainerFrame.h"
 #include "nsSVGSVGElement.h"
-#include "nsSVGContainerFrame.h"
-#include "gfxContext.h"
 
 nsIFrame*
 NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsSVGInnerSVGFrame(aContext);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSVGInnerSVGFrame)
--- a/layout/svg/base/src/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/base/src/nsSVGIntegrationUtils.cpp
@@ -30,31 +30,31 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGIntegrationUtils.h"
 
+// Keep others in (case-insensitive) order:
+#include "gfxDrawable.h"
+#include "nsDisplayList.h"
+#include "nsLayoutUtils.h"
 #include "nsRenderingContext.h"
-#include "nsSVGUtils.h"
+#include "nsSVGClipPathFrame.h"
 #include "nsSVGEffects.h"
-#include "nsRegion.h"
-#include "nsLayoutUtils.h"
-#include "nsDisplayList.h"
+#include "nsSVGFilterFrame.h"
 #include "nsSVGFilterPaintCallback.h"
-#include "nsSVGFilterFrame.h"
-#include "nsSVGClipPathFrame.h"
 #include "nsSVGMaskFrame.h"
-#include "gfxPlatform.h"
-#include "gfxDrawable.h"
 #include "nsSVGPaintServerFrame.h"
+#include "nsSVGUtils.h"
 
 // ----------------------------------------------------------------------
 
 bool
 nsSVGIntegrationUtils::UsingEffectsForFrame(const nsIFrame* aFrame)
 {
   if (aFrame->IsFrameOfType(nsIFrame::eSVG)) {
     return false;
--- a/layout/svg/base/src/nsSVGLeafFrame.cpp
+++ b/layout/svg/base/src/nsSVGLeafFrame.cpp
@@ -29,19 +29,19 @@
  * 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 ***** */
 
+// Keep in (case-insensitive) order:
 #include "nsFrame.h"
 #include "nsSVGEffects.h"
-#include "nsImageLoadingContent.h"
 
 class nsSVGLeafFrame : public nsFrame
 {
   friend nsIFrame*
   NS_NewSVGLeafFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 protected:
   nsSVGLeafFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
 
--- a/layout/svg/base/src/nsSVGMarkerFrame.cpp
+++ b/layout/svg/base/src/nsSVGMarkerFrame.cpp
@@ -29,27 +29,26 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGMarkerFrame.h"
 
-#include "nsIDOMSVGAnimatedRect.h"
-#include "nsIDOMSVGRect.h"
-#include "nsIDocument.h"
+// Keep others in (case-insensitive) order:
+#include "gfxContext.h"
 #include "nsRenderingContext.h"
-#include "nsSVGPathGeometryFrame.h"
 #include "nsSVGEffects.h"
 #include "nsSVGMarkerElement.h"
 #include "nsSVGPathGeometryElement.h"
-#include "gfxContext.h"
+#include "nsSVGPathGeometryFrame.h"
 
 nsIFrame*
 NS_NewSVGMarkerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsSVGMarkerFrame(aContext);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSVGMarkerFrame)
--- a/layout/svg/base/src/nsSVGMaskFrame.cpp
+++ b/layout/svg/base/src/nsSVGMaskFrame.cpp
@@ -29,25 +29,25 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGMaskFrame.h"
 
-#include "nsIDocument.h"
-#include "nsRenderingContext.h"
-#include "nsSVGContainerFrame.h"
-#include "nsSVGMaskElement.h"
-#include "nsSVGEffects.h"
+// Keep others in (case-insensitive) order:
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
+#include "nsRenderingContext.h"
+#include "nsSVGEffects.h"
+#include "nsSVGMaskElement.h"
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsIFrame*
 NS_NewSVGMaskFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsSVGMaskFrame(aContext);
--- a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp
+++ b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp
@@ -31,35 +31,32 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGOuterSVGFrame.h"
 
+// Keep others in (case-insensitive) order:
+#include "DOMSVGTests.h"
+#include "gfxMatrix.h"
+#include "nsDisplayList.h"
+#include "nsIDocument.h"
 #include "nsIDOMSVGSVGElement.h"
+#include "nsIDOMWindow.h"
+#include "nsIInterfaceRequestorUtils.h"
+#include "nsIObjectLoadingContent.h"
 #include "nsRenderingContext.h"
+#include "nsStubMutationObserver.h"
 #include "nsSVGSVGElement.h"
 #include "nsSVGTextFrame.h"
-#include "DOMSVGTests.h"
-#include "nsDisplayList.h"
-#include "nsStubMutationObserver.h"
-#include "gfxContext.h"
-#include "gfxMatrix.h"
-#include "gfxRect.h"
-#include "nsIContentViewer.h"
-#include "nsIDocShell.h"
-#include "nsIDOMDocument.h"
-#include "nsIDOMWindow.h"
-#include "nsPIDOMWindow.h"
-#include "nsIObjectLoadingContent.h"
-#include "nsIInterfaceRequestorUtils.h"
 
 namespace dom = mozilla::dom;
 
 class nsSVGMutationObserver : public nsStubMutationObserver
 {
 public:
   // nsIMutationObserver interface
   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
--- a/layout/svg/base/src/nsSVGPaintServerFrame.cpp
+++ b/layout/svg/base/src/nsSVGPaintServerFrame.cpp
@@ -29,17 +29,20 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGPaintServerFrame.h"
+
+// Keep others in (case-insensitive) order:
 #include "nsSVGGeometryFrame.h"
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSVGPaintServerFrame)
 
 bool
 nsSVGPaintServerFrame::SetupPaintServer(gfxContext *aContext,
                                         nsSVGGeometryFrame *aSource,
                                         float aOpacity)
--- a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp
+++ b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp
@@ -31,29 +31,29 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGPathGeometryFrame.h"
 
+// Keep others in (case-insensitive) order:
+#include "gfxContext.h"
+#include "gfxPlatform.h"
 #include "nsGkAtoms.h"
 #include "nsRenderingContext.h"
-#include "nsSVGMarkerFrame.h"
-#include "nsSVGUtils.h"
 #include "nsSVGEffects.h"
 #include "nsSVGGraphicElement.h"
-#include "nsSVGOuterSVGFrame.h"
-#include "nsSVGRect.h"
+#include "nsSVGMarkerFrame.h"
 #include "nsSVGPathGeometryElement.h"
-#include "gfxContext.h"
-#include "gfxPlatform.h"
+#include "nsSVGUtils.h"
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsIFrame*
 NS_NewSVGPathGeometryFrame(nsIPresShell* aPresShell,
                            nsStyleContext* aContext)
 {
--- a/layout/svg/base/src/nsSVGPatternFrame.cpp
+++ b/layout/svg/base/src/nsSVGPatternFrame.cpp
@@ -31,36 +31,34 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGPatternFrame.h"
 
+// Keep others in (case-insensitive) order:
+#include "gfxContext.h"
+#include "gfxMatrix.h"
+#include "gfxPattern.h"
+#include "gfxPlatform.h"
+#include "nsContentUtils.h"
 #include "nsGkAtoms.h"
-#include "nsIDOMSVGAnimatedRect.h"
+#include "nsISVGChildFrame.h"
 #include "nsRenderingContext.h"
-#include "SVGAnimatedTransformList.h"
 #include "nsStyleContext.h"
-#include "nsINameSpaceManager.h"
-#include "nsISVGChildFrame.h"
-#include "nsSVGRect.h"
+#include "nsSVGEffects.h"
+#include "nsSVGGeometryFrame.h"
+#include "nsSVGPatternElement.h"
 #include "nsSVGUtils.h"
-#include "nsSVGEffects.h"
-#include "nsSVGOuterSVGFrame.h"
-#include "nsSVGPatternElement.h"
-#include "nsSVGGeometryFrame.h"
-#include "gfxContext.h"
-#include "gfxPlatform.h"
-#include "gfxPattern.h"
-#include "gfxMatrix.h"
-#include "nsContentUtils.h"
+#include "SVGAnimatedTransformList.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------
 // Helper classes
 
 class nsSVGPatternFrame::AutoPatternReferencer
 {
--- a/layout/svg/base/src/nsSVGStopFrame.cpp
+++ b/layout/svg/base/src/nsSVGStopFrame.cpp
@@ -31,20 +31,21 @@
  * 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 ***** */
 
+// Keep in (case-insensitive) order:
+#include "nsFrame.h"
+#include "nsGkAtoms.h"
 #include "nsIDOMSVGStopElement.h"
 #include "nsStyleContext.h"
-#include "nsFrame.h"
-#include "nsGkAtoms.h"
 #include "nsSVGEffects.h"
 
 // This is a very simple frame whose only purpose is to capture style change
 // events and propagate them to the parent.  Most of the heavy lifting is done
 // within the nsSVGGradientFrame, which is the parent for this frame
 
 typedef nsFrame  nsSVGStopFrameBase;
 
--- a/layout/svg/base/src/nsSVGSwitchFrame.cpp
+++ b/layout/svg/base/src/nsSVGSwitchFrame.cpp
@@ -31,22 +31,22 @@
  * 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 "nsSVGEffects.h"
+// Keep in (case-insensitive) order:
+#include "gfxMatrix.h"
+#include "gfxRect.h"
 #include "nsSVGGFrame.h"
 #include "nsSVGSwitchElement.h"
 #include "nsSVGUtils.h"
-#include "gfxRect.h"
-#include "gfxMatrix.h"
 
 class nsRenderingContext;
 
 typedef nsSVGGFrame nsSVGSwitchFrameBase;
 
 class nsSVGSwitchFrame : public nsSVGSwitchFrameBase
 {
   friend nsIFrame*
--- a/layout/svg/base/src/nsSVGTSpanFrame.cpp
+++ b/layout/svg/base/src/nsSVGTSpanFrame.cpp
@@ -31,22 +31,23 @@
  * 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 ***** */
 
+// Main header first:
+#include "nsSVGTSpanFrame.h"
+
+// Keep others in (case-insensitive) order:
 #include "nsIDOMSVGTSpanElement.h"
 #include "nsIDOMSVGAltGlyphElement.h"
-#include "nsSVGTSpanFrame.h"
 #include "nsSVGUtils.h"
-#include "nsSVGTextFrame.h"
-#include "nsSVGOuterSVGFrame.h"
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsIFrame*
 NS_NewSVGTSpanFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsSVGTSpanFrame(aContext);
--- a/layout/svg/base/src/nsSVGTextContainerFrame.cpp
+++ b/layout/svg/base/src/nsSVGTextContainerFrame.cpp
@@ -29,28 +29,27 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGContainerFrame.h"
+
+// Keep others in (case-insensitive) order:
+#include "nsDOMError.h"
+#include "nsSVGGlyphFrame.h"
 #include "nsSVGTextFrame.h"
 #include "nsSVGUtils.h"
-#include "nsSVGOuterSVGFrame.h"
-#include "nsIDOMSVGTextElement.h"
-#include "nsIDOMSVGAnimatedLengthList.h"
 #include "SVGAnimatedNumberList.h"
+#include "SVGLengthList.h"
 #include "SVGNumberList.h"
-#include "nsSVGGlyphFrame.h"
-#include "nsDOMError.h"
-#include "SVGLengthList.h"
-#include "nsSVGTextPositioningElement.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------
 // nsQueryFrame methods
 
 NS_QUERYFRAME_HEAD(nsSVGTextContainerFrame)
   NS_QUERYFRAME_ENTRY(nsSVGTextContainerFrame)
--- a/layout/svg/base/src/nsSVGTextFrame.cpp
+++ b/layout/svg/base/src/nsSVGTextFrame.cpp
@@ -31,31 +31,30 @@
  * 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 "nsIDOMSVGTextElement.h"
+// Main header first:
 #include "nsSVGTextFrame.h"
-#include "SVGLengthList.h"
-#include "nsIDOMSVGLength.h"
-#include "nsIDOMSVGAnimatedNumber.h"
+
+// Keep others in (case-insensitive) order:
+#include "nsGkAtoms.h"
+#include "nsIDOMSVGRect.h"
+#include "nsIDOMSVGTextElement.h"
 #include "nsISVGGlyphFragmentNode.h"
 #include "nsSVGGlyphFrame.h"
-#include "nsSVGOuterSVGFrame.h"
-#include "nsIDOMSVGRect.h"
-#include "nsSVGRect.h"
-#include "nsGkAtoms.h"
+#include "nsSVGGraphicElement.h"
+#include "nsSVGPathElement.h"
 #include "nsSVGTextPathFrame.h"
-#include "nsSVGPathElement.h"
 #include "nsSVGUtils.h"
-#include "nsSVGGraphicElement.h"
+#include "SVGLengthList.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsIFrame*
 NS_NewSVGTextFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
--- a/layout/svg/base/src/nsSVGTextPathFrame.cpp
+++ b/layout/svg/base/src/nsSVGTextPathFrame.cpp
@@ -29,23 +29,24 @@
  * 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 ***** */
 
+// Main header first:
 #include "nsSVGTextPathFrame.h"
 
+// Keep others in (case-insensitive) order:
+#include "nsContentUtils.h"
 #include "nsIDOMSVGTextPathElement.h"
+#include "nsSVGEffects.h"
 #include "nsSVGLength2.h"
-#include "nsIDOMSVGURIReference.h"
-#include "nsSVGEffects.h"
-#include "nsContentUtils.h"
 #include "nsSVGPathElement.h"
 #include "nsSVGTextPathElement.h"
 #include "SVGLengthList.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------
 // Implementation
--- a/layout/svg/base/src/nsSVGUseFrame.cpp
+++ b/layout/svg/base/src/nsSVGUseFrame.cpp
@@ -29,23 +29,21 @@
  * 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 "nsSVGGFrame.h"
+// Keep in (case-insensitive) order:
 #include "nsIAnonymousContentCreator.h"
 #include "nsIDOMSVGUseElement.h"
-#include "nsIDOMSVGTransformable.h"
-#include "nsSVGElement.h"
+#include "nsSVGGFrame.h"
 #include "nsSVGUseElement.h"
-#include "gfxMatrix.h"
 
 typedef nsSVGGFrame nsSVGUseFrameBase;
 
 class nsSVGUseFrame : public nsSVGUseFrameBase,
                       public nsIAnonymousContentCreator
 {
   friend nsIFrame*
   NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -29,74 +29,63 @@
  * 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 nsSVGUtils.h first to ensure definition of M_SQRT1_2 is picked up
+// Main header first:
+// This is also necessary to ensure our definition of M_SQRT1_2 is picked up
 #include "nsSVGUtils.h"
 
-#include "nsIDOMDocument.h"
-#include "nsIDOMSVGElement.h"
-#include "nsIDOMSVGSVGElement.h"
-#include "nsRenderingContext.h"
-#include "nsStyleCoord.h"
-#include "nsPresContext.h"
-#include "nsSVGSVGElement.h"
+// Keep others in (case-insensitive) order:
+#include "gfxContext.h"
+#include "gfxImageSurface.h"
+#include "gfxMatrix.h"
+#include "gfxPlatform.h"
+#include "gfxRect.h"
+#include "gfxUtils.h"
+#include "mozilla/gfx/2D.h"
+#include "mozilla/Preferences.h"
+#include "nsComputedDOMStyle.h"
+#include "nsContentUtils.h"
+#include "nsFrameList.h"
+#include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
+#include "nsIDOMSVGElement.h"
+#include "nsIDOMSVGUnitTypes.h"
 #include "nsIFrame.h"
-#include "nsGkAtoms.h"
-#include "nsIURI.h"
-#include "nsStyleStruct.h"
+#include "nsINameSpaceManager.h"
 #include "nsIPresShell.h"
-#include "nsNetUtil.h"
-#include "nsFrameList.h"
+#include "nsIScriptError.h"
 #include "nsISVGChildFrame.h"
-#include "nsContentDLF.h"
-#include "nsContentUtils.h"
+#include "nsPresContext.h"
+#include "nsRenderingContext.h"
+#include "nsStyleCoord.h"
+#include "nsStyleStruct.h"
+#include "nsSVGClipPathFrame.h"
+#include "nsSVGContainerFrame.h"
+#include "nsSVGEffects.h"
 #include "nsSVGFilterFrame.h"
-#include "nsINameSpaceManager.h"
-#include "nsDOMError.h"
-#include "nsSVGOuterSVGFrame.h"
+#include "nsSVGFilterPaintCallback.h"
+#include "nsSVGForeignObjectFrame.h"
+#include "nsSVGGeometryFrame.h"
 #include "nsSVGInnerSVGFrame.h"
-#include "SVGAnimatedPreserveAspectRatio.h"
-#include "nsSVGClipPathFrame.h"
-#include "nsSVGMaskFrame.h"
-#include "nsSVGContainerFrame.h"
-#include "nsSVGTextContainerFrame.h"
+#include "nsSVGIntegrationUtils.h"
 #include "nsSVGLength2.h"
-#include "nsGenericElement.h"
-#include "nsSVGGraphicElement.h"
-#include "nsAttrValue.h"
-#include "nsIScriptError.h"
-#include "gfxContext.h"
-#include "gfxMatrix.h"
-#include "gfxRect.h"
-#include "gfxImageSurface.h"
-#include "gfxPlatform.h"
-#include "nsSVGForeignObjectFrame.h"
-#include "nsIDOMSVGUnitTypes.h"
-#include "nsSVGEffects.h"
-#include "nsMathUtils.h"
-#include "nsSVGIntegrationUtils.h"
-#include "nsSVGFilterPaintCallback.h"
-#include "nsSVGGeometryFrame.h"
-#include "nsComputedDOMStyle.h"
+#include "nsSVGMaskFrame.h"
+#include "nsSVGOuterSVGFrame.h"
+#include "nsSVGPathGeometryElement.h"
 #include "nsSVGPathGeometryFrame.h"
-#include "nsSVGPathGeometryElement.h"
-#include "prdtoa.h"
-#include "mozilla/dom/Element.h"
-#include "gfxUtils.h"
-#include "mozilla/Preferences.h"
-
-#include "mozilla/gfx/2D.h"
+#include "nsSVGSVGElement.h"
+#include "nsSVGTextContainerFrame.h"
+#include "SVGAnimatedPreserveAspectRatio.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::gfx;
 
 // c = n / 255
 // (c <= 0.0031308 ? c * 12.92 : 1.055 * pow(c, 1 / 2.4) - 0.055) * 255 + 0.5
 static const PRUint8 glinearRGBTosRGBMap[256] = {
--- a/toolkit/content/tests/chrome/Makefile.in
+++ b/toolkit/content/tests/chrome/Makefile.in
@@ -104,29 +104,26 @@ include $(topsrcdir)/config/rules.mk
 		window_browser_drop.xul \
 		test_subframe_origin.xul \
 		window_subframe_origin.xul \
 		frame_subframe_origin_subframe1.xul \
 		frame_subframe_origin_subframe2.xul \
 		RegisterUnregisterChrome.js \
 		test_panel.xul \
 		window_panel.xul \
-		$(NULL)
-
-
-_TEST_FILES +=  \
 		test_bug360220.xul \
 		test_bug365773.xul \
 		test_bug382990.xul \
 		test_bug457632.xul \
 		test_bug460942.xul \
 		test_bug509732.xul \
 		test_bug554279.xul \
 		test_bug557987.xul\
 		test_bug562554.xul \
+		test_bug585946.xul \
 		test_button.xul \
 		test_closemenu_attribute.xul \
 		test_colorpicker_popup.xul \
 		test_menulist.xul \
 		test_menuitem_blink.xul \
 		test_menulist_keynav.xul \
 		test_popup_coords.xul \
 		test_popup_recreate.xul \
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/chrome/test_bug585946.xul
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
+
+<window title="Toolbar" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        onload="startTest();">
+
+  <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <toolbox>
+    <toolbarpalette/>
+    <toolbar id="toolbar" defaultset="node1,node2">
+      <toolbarbutton id="node1" label="node1" removable="true"/>
+      <toolbarbutton id="node2" label="node2" removable="true"/>
+    </toolbar>
+  </toolbox>
+
+  <!-- test resuls are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml"
+        style="height: 300px; overflow: auto;"/>
+  
+  <!-- test code goes here -->
+  <script type="application/javascript"><![CDATA[
+
+SimpleTest.waitForExplicitFinish();
+
+function startTest() {
+  var toolbar = $("toolbar");
+
+  var splitter = document.createElement("splitter");
+  splitter.setAttribute("id", "dynsplitter");
+  splitter.setAttribute("skipintoolbarset", "true");
+
+  toolbar.insertBefore(splitter, $("node2"));
+
+  function checkPos() {
+    is($("dynsplitter").previousSibling, $("node1"));
+    is($("dynsplitter").nextSibling, $("node2"));
+  }
+
+  checkPos();
+  toolbar.style.MozBinding = "url(chrome://global/content/bindings/toolbar.xml#toolbar-drag)";
+  toolbar.clientTop; // style flush
+  checkPos();
+
+  SimpleTest.finish();
+}
+
+  ]]></script>
+</window>
--- a/toolkit/content/widgets/toolbar.xml
+++ b/toolkit/content/widgets/toolbar.xml
@@ -175,16 +175,19 @@
         ]]>
         </body>
       </method>
 
       <method name="_idFromNode">
         <parameter name="aNode"/>
         <body>
         <![CDATA[
+          if (aNode.getAttribute("skipintoolbarset") == "true")
+            return "";
+
           switch (aNode.localName) {
             case "toolbarseparator":
               return "separator";
             case "toolbarspring":
               return "spring";
             case "toolbarspacer":
               return "spacer";
             default:
@@ -208,16 +211,19 @@
             }
 
             return currentSet.join(",") || "__empty";
           ]]>
         </getter>
 
         <setter>
           <![CDATA[
+            if (val == this.currentSet)
+              return;
+
             var ids = (val == "__empty") ? [] : val.split(",");
 
             var nodeidx = 0;
             var paletteItems = { }, added = { };
 
             var palette = this.toolbox ? this.toolbox.palette : null;
 
             // build a cache of items in the toolbarpalette
--- a/toolkit/system/gnome/nsAlertsIconListener.cpp
+++ b/toolkit/system/gnome/nsAlertsIconListener.cpp
@@ -48,16 +48,17 @@
 #include <gdk/gdk.h>
 
 // Compatibility macro for <libnotify-0.7
 #ifndef NOTIFY_CHECK_VERSION
 #define NOTIFY_CHECK_VERSION(x,y,z) 0
 #endif
 
 static bool gHasActions = false;
+static bool gHasCaps = false;
 
 static void notify_action_cb(NotifyNotification *notification,
                              gchar *action, gpointer user_data)
 {
   nsAlertsIconListener* alert = static_cast<nsAlertsIconListener*> (user_data);
   alert->SendCallback();
 }
 
@@ -339,27 +340,34 @@ nsAlertsIconListener::InitAlertAsync(con
       appShortName.AssignLiteral("Mozilla");
     }
 
     if (!notify_init(appShortName.get()))
       return NS_ERROR_FAILURE;
 
     GList *server_caps = notify_get_server_caps();
     if (server_caps) {
+      gHasCaps = true;
       for (GList* cap = server_caps; cap != NULL; cap = cap->next) {
         if (!strcmp((char*) cap->data, "actions")) {
           gHasActions = true;
           break;
         }
       }
       g_list_foreach(server_caps, (GFunc)g_free, NULL);
       g_list_free(server_caps);
     }
   }
 
+  if (!gHasCaps) {
+    // if notify_get_server_caps() failed above we need to assume
+    // there is no notification-server to display anything
+    return NS_ERROR_FAILURE;
+  }
+
   if (!gHasActions && aAlertTextClickable)
     return NS_ERROR_FAILURE; // No good, fallback to XUL
 
   nsCOMPtr<nsIObserverService> obsServ =
       do_GetService("@mozilla.org/observer-service;1");
   if (obsServ)
     obsServ->AddObserver(this, "quit-application", true);