Merge m-c to f-t
authorPhil Ringnalda <philringnalda@gmail.com>
Sat, 15 Mar 2014 18:21:41 -0700
changeset 192033 e3b76b155ca4a68e3333f4c428df9bda20e106e5
parent 192032 72020c04591217709c63a17b124523c0e10af1e5 (current diff)
parent 192014 e182de48f6284bc310ee36345a440aeae0659dba (diff)
child 192038 41671703c80629d0879cde421c4f6e22f02cd016
child 192041 744d754b68742ebf27c8cd2632ce2d97d08fbabc
child 192045 a6195a333647cb85ec41437ecdab9f64d328f47c
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone30.0a1
first release with
nightly linux32
e3b76b155ca4 / 30.0a1 / 20140316030202 / files
nightly linux64
e3b76b155ca4 / 30.0a1 / 20140316030202 / files
nightly mac
e3b76b155ca4 / 30.0a1 / 20140316030202 / files
nightly win32
e3b76b155ca4 / 30.0a1 / 20140316030202 / files
nightly win64
e3b76b155ca4 / 30.0a1 / 20140316030202 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge m-c to f-t
browser/modules/webappsUI.jsm
toolkit/webapps/WebappsInstaller.jsm
webapprt/WebappsHandler.jsm
--- a/b2g/app/ua-update.json.in
+++ b/b2g/app/ua-update.json.in
@@ -1,17 +1,15 @@
 // Comments must be on their own lines and must start with "//"
 
 // Send these sites a custom user-agent. Bugs to remove each override after
 // evangelism are included.
 {
   // bug 826335, globo.com
   "globo.com": "\\(Mobile#(Android; Mobile",
-  // bug 826342, mercadolivre.com.br
-  "mercadolivre.com.br": "\\(Mobile#(Android; Mobile",
   // bug 826344, abril.com.br
   "abril.com.br": "\\(Mobile#(Android; Mobile",
   // bug 826347, msn.com
   "msn.com": "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19",
   // bug 826348, linkedin.com
   "linkedin.com": "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19",
   // bug 826353, itau.com.br
   "itau.com.br": "\\(Mobile#(Android; Mobile",
@@ -20,96 +18,76 @@
   // bug 826510, r7.com
   "r7.com": "\\(Mobile#(Android; Mobile",
   // bug 826514, estadao.com.br
   "estadao.com.br": "\\(Mobile#(Android; Mobile",
   // bug 826711, bb.com.br
   "bb.com.br": "\\(Mobile#(Android; Mobile",
   // bug 826712, orkut.com
   "orkut.com": "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19",
-  // bug 826715, noticias.uol.com.br
-  "noticias.uol.com.br": "\\(Mobile#(Android; Mobile",
-  // bug 826845, techtudo.com.br
-  "techtudo.com.br": "\\(Mobile#(Android; Mobile",
   // bug 826958, ebay.com
   "ebay.com": "\\(Mobile#(Android; Mobile",
   // bug 827622, bing.com
   "bing.com": "\\(Mobile#(Android; Mobile",
   // bug 827626, magazineluiza.com.br
   "magazineluiza.com.br": "\\(Mobile#(Android; Mobile",
   // bug 827628, groupon.com.br
   "groupon.com.br": "\\(Mobile#(Android; Mobile",
-  // bug 827630, vagalume.com.br
-  "vagalume.com.br": "\\(Mobile#(Android; Mobile",
   // bug 827632, tecmundo.com.br
   "tecmundo.com.br": "\\(Mobile#(Android; Mobile",
   // bug 827633, hao123.com
   "hao123.com": "\\(Mobile#(Android; Mobile",
   // bug 827573, webmotors.com.br
   "webmotors.com.br": "\\(Mobile#(Android; Mobile",
-  // bug 827661, mercadolibre.com.co
-  "mercadolibre.com.co": "\\(Mobile#(Android; Mobile",
   // bug 827670, elpais.com.co
   "elpais.com.co": "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19",
   // bug 827674, avianca.com
   "avianca.com": "\\(Mobile#(Android; Mobile",
   // bug 827678, marca.com
   "marca.com": "\\(Mobile#(Android; Mobile",
   // bug 828354, gazeta.pl
   "gazeta.pl": "\\(Mobile#(Android; Mobile",
   // bug 828360, sport.pl
   "sport.pl": "\\(Mobile#(Android; Mobile",
-  // bug 828364, nk.pl
-  "nk.pl": "\\(Mobile#(Android; Mobile",
-  // bug 828369, money.pl
-  "money.pl": "\\(Mobile#(Android; Mobile",
   // bug 828371, ingbank.pl
   "ingbank.pl": "\\(Mobile#(Android; Mobile",
   // bug 828378, wyborcza.pl
   "wyborcza.pl": "\\(Mobile#(Android; Mobile",
   // bug 828380, deser.pl
   "deser.pl": "\\(Mobile#(Android; Mobile",
   // bug 828386, ebay.es
   "ebay.es": "\\(Mobile#(Android; Mobile",
   // bug 828392, infojobs.net
   "infojobs.net": "\\(Mobile#(Android; Mobile",
   // bug 828399, antena3.com
   "antena3.com": "\\(Mobile#(Android; Mobile",
-  // bug 828406, orange.es
-  "orange.es": "\\(Mobile#(Android; Mobile",
   // bug 828416, loteriasyapuestas.es
   "loteriasyapuestas.es": "\\(Mobile#(Android; Mobile",
   // bug 828418, bbva.es
   "bbva.es": "\\(Mobile#(Android; Mobile",
   // bug 828422, publico.es
   "publico.es": "\\(Mobile#(Android; Mobile",
-  // bug 828425, mercadolibre.com.ve
-  "mercadolibre.com.ve": "\\(Mobile#(Android; Mobile",
   // bug 828439, movistar.com.ve
   "movistar.com.ve": "\\(Mobile#(Android; Mobile",
   // bug 843126, es.playstation.com
   "es.playstation.com": "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19",
   // bug 843129, 11870.com
   "iphonejuegosgratis.com": "\\(Mobile#(Android; Mobile",
   // bug 843132, comunio.es
   "comunio.es": "\\(Mobile#(Android; Mobile",
   // bug 843151, citibank.com
   "citibank.com": "\\(Mobile#(Android; Mobile",
   // bug 843153, games.com
   "games.com": "\\(Mobile#(Android; Mobile",
   // bug 843160, ehow.com
   "ehow.com": "\\(Mobile#(Android; Mobile",
-  // bug 843186, chevrolet.com
-  "chevrolet.com": "\\(Mobile#(Android; Mobile",
   // bug 866577, 3g.qq.com
   "3g.qq.com": "\\(Mobile#(Android; Mobile",
   // bug 878228, blikk.hu
   "blikk.hu": "\\(Mobile#(Android; Mobile",
-  // bug 878230, citromail.hu
-  "citromail.hu": "\\(Mobile#(Android; Mobile",
   // bug 878232, hazipatika.com
   "hazipatika.com": "\\(Mobile#(Android; Mobile",
   // bug 878238, koponyeg.hu
   "koponyeg.hu": "\\(Mobile#(Android; Mobile",
   // bug 878240, kuruc.info
   "kuruc.info": "\\(Mobile#(Android; Mobile",
   // bug 878242, nemzetisport.hu
   "nemzetisport.hu": "\\(Mobile#(Android; Mobile",
@@ -126,27 +104,21 @@
   // bug 878262, download.com
   "download.com": "\\(Mobile#(Android; Mobile",
   // bug 878264, haber.ba
   "haber.ba": "\\(Mobile#(Android; Mobile",
   // bug 878271, kurir-info.rs
   "kurir-info.rs": "\\(Mobile#(Android; Mobile",
   // bug 878273, livescore.com
   "livescore.com": "\\(Mobile#(Android; Mobile",
-  // bug 878275, mondo.rs
-  "mondo.rs": "\\(Mobile#(Android; Mobile",
   // bug 878277, naslovi.net
   "naslovi.net": "\\(Mobile#(Android; Mobile",
   // bug 878630, ask.com
   "ask.com": "\\(Mobile#(Android; Mobile",
   // bug 878632, banorte.com
   "banorte.com": "\\(Mobile#(Android; Mobile",
-  // bug 878637, eluniversal.com.mx
-  "eluniversal.com.mx": "\\(Mobile#(Android; Mobile",
-  // bug 878642, mercadolibre.com.mx
-  "mercadolibre.com.mx": "\\(Mobile#(Android; Mobile",
   // bug 878649, univision.com
   "univision.com": "\\(Mobile#(Android; Mobile",
   // bug 878653, redstarbelgrade.info
   "redstarbelgrade.info": "\\(Mobile#(Android; Mobile",
   // bug 878655, vesti-online.com
   "vesti-online.com": "\\(Mobile#(Android; Mobile"
 }
--- a/browser/components/feeds/src/WebContentConverter.js
+++ b/browser/components/feeds/src/WebContentConverter.js
@@ -869,22 +869,16 @@ WebContentConverterRegistrar.prototype =
    */
   createInstance: function WCCR_createInstance(outer, iid) {
     if (outer != null)
       throw Cr.NS_ERROR_NO_AGGREGATION;
     return this.QueryInterface(iid);
   },
 
   classID: WCCR_CLASSID,
-  classInfo: XPCOMUtils.generateCI({classID: WCCR_CLASSID,
-                                    contractID: WCCR_CONTRACTID,
-                                    interfaces: [Ci.nsIWebContentConverterService,
-                                                 Ci.nsIWebContentHandlerRegistrar,
-                                                 Ci.nsIObserver, Ci.nsIFactory],
-                                    flags: Ci.nsIClassInfo.DOM_OBJECT}),
 
   /**
    * See nsISupports
    */
   QueryInterface: XPCOMUtils.generateQI(
      [Ci.nsIWebContentConverterService, 
       Ci.nsIWebContentHandlerRegistrar,
       Ci.nsIObserver,
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -33,18 +33,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/PlacesUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
                                   "resource://gre/modules/BookmarkHTMLUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "BookmarkJSONUtils",
                                   "resource://gre/modules/BookmarkJSONUtils.jsm");
 
-XPCOMUtils.defineLazyModuleGetter(this, "webappsUI",
-                                  "resource:///modules/webappsUI.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "WebappManager",
+                                  "resource:///modules/WebappManager.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PageThumbs",
                                   "resource://gre/modules/PageThumbs.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
                                   "resource://gre/modules/NewTabUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserNewTabPreloader",
@@ -463,17 +463,17 @@ BrowserGlue.prototype = {
     // prefs are applied in _onAppDefaults()
     this._distributionCustomizer.applyCustomizations();
 
     // handle any UI migration
     this._migrateUI();
 
     this._syncSearchEngines();
 
-    webappsUI.init();
+    WebappManager.init();
     PageThumbs.init();
     NewTabUtils.init();
     BrowserNewTabPreloader.init();
     SignInToWebsiteUX.init();
     PdfJs.init();
 #ifdef NIGHTLY_BUILD
     ShumwayUtils.init();
 #endif
@@ -649,17 +649,17 @@ BrowserGlue.prototype = {
                          .getService(Ci.nsIAppStartup);
       appStartup.trackStartupCrashEnd();
     } catch (e) {
       Cu.reportError("Could not end startup crash tracking in quit-application-granted: " + e);
     }
 
     BrowserNewTabPreloader.uninit();
     CustomizationTabPreloader.uninit();
-    webappsUI.uninit();
+    WebappManager.uninit();
     SignInToWebsiteUX.uninit();
     webrtcUI.uninit();
   },
 
   // All initial windows have opened.
   _onWindowsRestored: function BG__onWindowsRestored() {
     // Show update notification, if needed.
     if (Services.prefs.prefHasUserValue("app.update.postupdate"))
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -793,17 +793,17 @@ bin/libfreebl_32int64_3.so
 @BINPATH@/webapprt/components/CommandLineHandler.js
 @BINPATH@/webapprt/components/ContentPermission.js
 @BINPATH@/webapprt/components/DirectoryProvider.js
 @BINPATH@/webapprt/components/PaymentUIGlue.js
 @BINPATH@/webapprt/components/components.manifest
 @BINPATH@/webapprt/defaults/preferences/prefs.js
 @BINPATH@/webapprt/modules/Startup.jsm
 @BINPATH@/webapprt/modules/WebappRT.jsm
-@BINPATH@/webapprt/modules/WebappsHandler.jsm
+@BINPATH@/webapprt/modules/WebappManager.jsm
 @BINPATH@/webapprt/modules/RemoteDebugger.jsm
 @BINPATH@/webapprt/modules/WebRTCHandler.jsm
 #endif
 
 #ifdef MOZ_METRO
 @BINPATH@/components/MetroUIUtils.js
 @BINPATH@/components/MetroUIUtils.manifest
 [metro]
rename from browser/modules/webappsUI.jsm
rename to browser/modules/WebappManager.jsm
--- a/browser/modules/webappsUI.jsm
+++ b/browser/modules/WebappManager.jsm
@@ -1,45 +1,45 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-this.EXPORTED_SYMBOLS = ["webappsUI"];
+this.EXPORTED_SYMBOLS = ["WebappManager"];
 
 let Ci = Components.interfaces;
 let Cc = Components.classes;
 let Cu = Components.utils;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Webapps.jsm");
 Cu.import("resource://gre/modules/AppsUtils.jsm");
-Cu.import("resource://gre/modules/WebappsInstaller.jsm");
+Cu.import("resource://gre/modules/NativeApp.jsm");
 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
-this.webappsUI = {
+this.WebappManager = {
   // List of promises for in-progress installations
   installations: {},
 
-  init: function webappsUI_init() {
+  init: function() {
     Services.obs.addObserver(this, "webapps-ask-install", false);
     Services.obs.addObserver(this, "webapps-launch", false);
     Services.obs.addObserver(this, "webapps-uninstall", false);
     cpmm.addMessageListener("Webapps:Install:Return:OK", this);
     cpmm.addMessageListener("Webapps:Install:Return:KO", this);
     cpmm.addMessageListener("Webapps:UpdateState", this);
   },
 
-  uninit: function webappsUI_uninit() {
+  uninit: function() {
     Services.obs.removeObserver(this, "webapps-ask-install");
     Services.obs.removeObserver(this, "webapps-launch");
     Services.obs.removeObserver(this, "webapps-uninstall");
     cpmm.removeMessageListener("Webapps:Install:Return:OK", this);
     cpmm.removeMessageListener("Webapps:Install:Return:KO", this);
     cpmm.removeMessageListener("Webapps:UpdateState", this);
   },
 
@@ -66,17 +66,17 @@ this.webappsUI = {
       if (!manifest.appcache_path) {
         this.installations[manifestURL].resolve();
       }
     } else if (aMessage.name == "Webapps:Install:Return:KO") {
       this.installations[manifestURL].reject(data.error);
     }
   },
 
-  observe: function webappsUI_observe(aSubject, aTopic, aData) {
+  observe: function(aSubject, aTopic, aData) {
     let data = JSON.parse(aData);
     data.mm = aSubject;
 
     switch(aTopic) {
       case "webapps-ask-install":
         let win = this._getWindowForId(data.oid);
         if (win && win.location.href == data.from) {
           this.doInstall(data, win);
@@ -103,16 +103,18 @@ this.webappsUI = {
                          .chromeEventHandler;
     let chromeDoc = browser.ownerDocument;
     let chromeWin = chromeDoc.defaultView;
     let popupProgressContent =
       chromeDoc.getElementById("webapps-install-progress-content");
 
     let bundle = chromeWin.gNavigatorBundle;
 
+    let jsonManifest = aData.isPackage ? aData.app.updateManifest : aData.app.manifest;
+
     let notification;
 
     let mainAction = {
       label: bundle.getString("webapps.install"),
       accessKey: bundle.getString("webapps.install.accesskey"),
       callback: () => {
         notification.remove();
 
@@ -123,62 +125,60 @@ this.webappsUI = {
                              "webapps-notification-icon");
 
         let progressMeter = chromeDoc.createElement("progressmeter");
         progressMeter.setAttribute("mode", "undetermined");
         popupProgressContent.appendChild(progressMeter);
 
         let manifestURL = aData.app.manifestURL;
 
-        let cleanup = (ex) => {
+        let cleanup = () => {
           popupProgressContent.removeChild(progressMeter);
           delete this.installations[manifestURL];
           if (Object.getOwnPropertyNames(this.installations).length == 0) {
             notification.remove();
           }
         };
 
         this.installations[manifestURL] = Promise.defer();
         this.installations[manifestURL].promise.then(null, (error) => {
           Cu.reportError("Error installing webapp: " + error);
           cleanup();
         });
 
-        let app = WebappsInstaller.init(aData);
-
-        if (app) {
-          let localDir = null;
-          if (app.appProfile) {
-            localDir = app.appProfile.localDir;
-          }
-
-          DOMApplicationRegistry.confirmInstall(aData, localDir,
-            (aManifest, aZipPath) => {
-              Task.spawn(function() {
-                try {
-                  yield WebappsInstaller.install(aData, aManifest, aZipPath);
-                  yield this.installations[manifestURL].promise;
-                  installationSuccessNotification(aData, app, bundle);
-                } catch (ex) {
-                  Cu.reportError("Error installing webapp: " + ex);
-                  // TODO: Notify user that the installation has failed
-                } finally {
-                  cleanup();
-                }
-              }.bind(this));
-            });
-        } else {
+        let nativeApp = new NativeApp(aData.app, jsonManifest,
+                                      aData.app.categories);
+        let localDir;
+        try {
+          localDir = nativeApp.createProfile();
+        } catch (ex) {
+          Cu.reportError("Error installing webapp: " + ex);
           DOMApplicationRegistry.denyInstall(aData);
           cleanup();
+          return;
         }
+
+        DOMApplicationRegistry.confirmInstall(aData, localDir,
+          (aManifest, aZipPath) => Task.spawn((function*() {
+            try {
+              yield nativeApp.install(aManifest, aZipPath);
+              yield this.installations[manifestURL].promise;
+              notifyInstallSuccess(aData.app, nativeApp, bundle);
+            } catch (ex) {
+              Cu.reportError("Error installing webapp: " + ex);
+              // TODO: Notify user that the installation has failed
+            } finally {
+              cleanup();
+            }
+          }).bind(this))
+        );
       }
     };
 
     let requestingURI = chromeWin.makeURI(aData.from);
-    let jsonManifest = aData.isPackage ? aData.app.updateManifest : aData.app.manifest;
     let manifest = new ManifestHelper(jsonManifest, aData.app.origin);
 
     let host;
     try {
       host = requestingURI.host;
     } catch(e) {
       host = requestingURI.spec;
     }
@@ -190,27 +190,27 @@ this.webappsUI = {
                                                      "webapps-install",
                                                      message,
                                                      "webapps-notification-icon",
                                                      mainAction);
 
   }
 }
 
-function installationSuccessNotification(aData, app, aBundle) {
+function notifyInstallSuccess(aApp, aNativeApp, aBundle) {
   let launcher = {
     observe: function(aSubject, aTopic) {
       if (aTopic == "alertclickcallback") {
-        WebappOSUtils.launch(aData.app);
+        WebappOSUtils.launch(aApp);
       }
     }
   };
 
   try {
     let notifier = Cc["@mozilla.org/alerts-service;1"].
                    getService(Ci.nsIAlertsService);
 
-    notifier.showAlertNotification(app.iconURI.spec,
+    notifier.showAlertNotification(aNativeApp.iconURI.spec,
                                    aBundle.getString("webapps.install.success"),
-                                   app.appNameAsFilename,
+                                   aNativeApp.appNameAsFilename,
                                    true, null, launcher);
   } catch (ex) {}
 }
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -15,17 +15,17 @@ EXTRA_JS_MODULES += [
     'Feeds.jsm',
     'NetworkPrioritizer.jsm',
     'offlineAppCache.jsm',
     'SharedFrame.jsm',
     'SignInToWebsite.jsm',
     'SitePermissions.jsm',
     'Social.jsm',
     'TabCrashReporter.jsm',
-    'webappsUI.jsm',
+    'WebappManager.jsm',
     'webrtcUI.jsm',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     EXTRA_JS_MODULES += [
         'WindowsJumpLists.jsm',
         'WindowsPreviewPerTab.jsm',
     ]
--- a/caps/src/nsPrincipal.cpp
+++ b/caps/src/nsPrincipal.cpp
@@ -488,40 +488,47 @@ nsPrincipal::GetBaseDomain(nsACString& a
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrincipal::Read(nsIObjectInputStream* aStream)
 {
+  nsCOMPtr<nsISupports> supports;
   nsCOMPtr<nsIURI> codebase;
-  nsresult rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(codebase));
+  nsresult rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
+  codebase = do_QueryInterface(supports);
+
   nsCOMPtr<nsIURI> domain;
-  rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(domain));
+  rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
+  domain = do_QueryInterface(supports);
+
   uint32_t appId;
   rv = aStream->Read32(&appId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool inMozBrowser;
   rv = aStream->ReadBoolean(&inMozBrowser);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIContentSecurityPolicy> csp;
-  rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(csp));
+  rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // This may be null.
+  nsCOMPtr<nsIContentSecurityPolicy> csp = do_QueryInterface(supports, &rv);
+
   rv = Init(codebase, appId, inMozBrowser);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = SetCsp(csp);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // need to link in the CSP context here (link in a reference to this
   // nsIPrincipal and to the URI of the protected resource).
--- a/content/base/public/Element.h
+++ b/content/base/public/Element.h
@@ -114,17 +114,17 @@ class DOMRectList;
 #define NS_ELEMENT_IID \
 { 0xf7c18f0f, 0xa8fd, 0x4a95, \
   { 0x91, 0x72, 0xd3, 0xa7, 0x4a, 0xb8, 0xc4, 0xbe } }
 
 class Element : public FragmentOrElement
 {
 public:
 #ifdef MOZILLA_INTERNAL_API
-  Element(already_AddRefed<nsINodeInfo> aNodeInfo) :
+  Element(already_AddRefed<nsINodeInfo>& aNodeInfo) :
     FragmentOrElement(aNodeInfo),
     mState(NS_EVENT_STATE_MOZ_READONLY)
   {
     NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::ELEMENT_NODE,
                       "Bad NodeType in aNodeInfo");
     SetIsElement();
   }
 #endif // MOZILLA_INTERNAL_API
@@ -1205,19 +1205,20 @@ inline bool nsINode::HasAttributes() con
 /**
  * Macros to implement Clone(). _elementName is the class for which to implement
  * Clone.
  */
 #define NS_IMPL_ELEMENT_CLONE(_elementName)                                 \
 nsresult                                                                    \
 _elementName::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const        \
 {                                                                           \
-  *aResult = nullptr;                                                        \
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;                                     \
-  _elementName *it = new _elementName(ni.forget());                         \
+  *aResult = nullptr;                                                       \
+  already_AddRefed<nsINodeInfo> ni =                                        \
+    nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();                              \
+  _elementName *it = new _elementName(ni);                                  \
   if (!it) {                                                                \
     return NS_ERROR_OUT_OF_MEMORY;                                          \
   }                                                                         \
                                                                             \
   nsCOMPtr<nsINode> kungFuDeathGrip = it;                                   \
   nsresult rv = const_cast<_elementName*>(this)->CopyInnerTo(it);           \
   if (NS_SUCCEEDED(rv)) {                                                   \
     kungFuDeathGrip.swap(*aResult);                                         \
@@ -1225,19 +1226,20 @@ nsresult                                
                                                                             \
   return rv;                                                                \
 }
 
 #define NS_IMPL_ELEMENT_CLONE_WITH_INIT(_elementName)                       \
 nsresult                                                                    \
 _elementName::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const        \
 {                                                                           \
-  *aResult = nullptr;                                                        \
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;                                     \
-  _elementName *it = new _elementName(ni.forget());                         \
+  *aResult = nullptr;                                                       \
+  already_AddRefed<nsINodeInfo> ni =                                        \
+    nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();                              \
+  _elementName *it = new _elementName(ni);                                  \
   if (!it) {                                                                \
     return NS_ERROR_OUT_OF_MEMORY;                                          \
   }                                                                         \
                                                                             \
   nsCOMPtr<nsINode> kungFuDeathGrip = it;                                   \
   nsresult rv = it->Init();                                                 \
   nsresult rv2 = const_cast<_elementName*>(this)->CopyInnerTo(it);          \
   if (NS_FAILED(rv2)) {                                                     \
@@ -1372,44 +1374,44 @@ NS_IMETHOD GetAttributeNode(const nsAStr
 NS_IMETHOD SetAttributeNode(nsIDOMAttr* newAttr,                              \
                             nsIDOMAttr** _retval) MOZ_FINAL                   \
 {                                                                             \
   if (!newAttr) {                                                             \
     return NS_ERROR_INVALID_POINTER;                                          \
   }                                                                           \
   mozilla::ErrorResult rv;                                                    \
   mozilla::dom::Attr* attr = static_cast<mozilla::dom::Attr*>(newAttr);       \
-  *_retval = Element::SetAttributeNode(*attr, rv).get();                      \
+  *_retval = Element::SetAttributeNode(*attr, rv).take();                     \
   return rv.ErrorCode();                                                      \
 }                                                                             \
 NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* oldAttr,                           \
                                nsIDOMAttr** _retval) MOZ_FINAL                \
 {                                                                             \
   if (!oldAttr) {                                                             \
     return NS_ERROR_INVALID_POINTER;                                          \
   }                                                                           \
   mozilla::ErrorResult rv;                                                    \
   mozilla::dom::Attr* attr = static_cast<mozilla::dom::Attr*>(oldAttr);       \
-  *_retval = Element::RemoveAttributeNode(*attr, rv).get();                   \
+  *_retval = Element::RemoveAttributeNode(*attr, rv).take();                  \
   return rv.ErrorCode();                                                      \
 }                                                                             \
 NS_IMETHOD GetAttributeNodeNS(const nsAString& namespaceURI,                  \
                               const nsAString& localName,                     \
                               nsIDOMAttr** _retval) MOZ_FINAL                 \
 {                                                                             \
   NS_IF_ADDREF(*_retval = Element::GetAttributeNodeNS(namespaceURI,           \
                                                       localName));            \
   return NS_OK;                                                               \
 }                                                                             \
 NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* newAttr,                            \
                               nsIDOMAttr** _retval) MOZ_FINAL                 \
 {                                                                             \
   mozilla::ErrorResult rv;                                                    \
   mozilla::dom::Attr* attr = static_cast<mozilla::dom::Attr*>(newAttr);       \
-  *_retval = Element::SetAttributeNodeNS(*attr, rv).get();                    \
+  *_retval = Element::SetAttributeNodeNS(*attr, rv).take();                   \
   return rv.ErrorCode();                                                      \
 }                                                                             \
 NS_IMETHOD GetElementsByTagName(const nsAString& name,                        \
                                 nsIDOMHTMLCollection** _retval) MOZ_FINAL     \
 {                                                                             \
   Element::GetElementsByTagName(name, _retval);                               \
   return NS_OK;                                                               \
 }                                                                             \
@@ -1475,22 +1477,22 @@ NS_IMETHOD GetChildElementCount(uint32_t
 }                                                                             \
 NS_IMETHOD MozRemove() MOZ_FINAL                                              \
 {                                                                             \
   nsINode::Remove();                                                          \
   return NS_OK;                                                               \
 }                                                                             \
 NS_IMETHOD GetClientRects(nsIDOMClientRectList** _retval) MOZ_FINAL           \
 {                                                                             \
-  *_retval = Element::GetClientRects().get();                                 \
+  *_retval = Element::GetClientRects().take();                                \
   return NS_OK;                                                               \
 }                                                                             \
 NS_IMETHOD GetBoundingClientRect(nsIDOMClientRect** _retval) MOZ_FINAL        \
 {                                                                             \
-  *_retval = Element::GetBoundingClientRect().get();                          \
+  *_retval = Element::GetBoundingClientRect().take();                         \
   return NS_OK;                                                               \
 }                                                                             \
 NS_IMETHOD GetScrollTop(int32_t* aScrollTop) MOZ_FINAL                        \
 {                                                                             \
   *aScrollTop = Element::ScrollTop();                                         \
   return NS_OK;                                                               \
 }                                                                             \
 NS_IMETHOD SetScrollTop(int32_t aScrollTop) MOZ_FINAL                         \
--- a/content/base/public/FragmentOrElement.h
+++ b/content/base/public/FragmentOrElement.h
@@ -161,17 +161,18 @@ namespace mozilla {
 namespace dom {
 
 class ShadowRoot;
 class UndoManager;
 
 class FragmentOrElement : public nsIContent
 {
 public:
-  FragmentOrElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  FragmentOrElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
+  FragmentOrElement(already_AddRefed<nsINodeInfo>&& aNodeInfo);
   virtual ~FragmentOrElement();
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
   NS_DECL_SIZEOF_EXCLUDING_THIS
 
   // nsINode interface methods
   virtual uint32_t GetChildCount() const MOZ_OVERRIDE;
--- a/content/base/public/nsContentCreatorFunctions.h
+++ b/content/base/public/nsContentCreatorFunctions.h
@@ -25,50 +25,52 @@ class nsGenericHTMLElement;
 namespace mozilla {
 namespace dom {
 class Element;
 } // namespace dom
 } // namespace mozilla
 
 nsresult
 NS_NewElement(mozilla::dom::Element** aResult,
-              already_AddRefed<nsINodeInfo> aNodeInfo,
+              already_AddRefed<nsINodeInfo>&& aNodeInfo,
               mozilla::dom::FromParser aFromParser);
 
 nsresult
 NS_NewXMLElement(mozilla::dom::Element** aResult,
-                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 nsresult
 NS_NewHTMLElement(mozilla::dom::Element** aResult,
-                  already_AddRefed<nsINodeInfo> aNodeInfo,
+                  already_AddRefed<nsINodeInfo>&& aNodeInfo,
                   mozilla::dom::FromParser aFromParser);
 
 // First argument should be nsHTMLTag, but that adds dependency to parser
 // for a bunch of files.
 already_AddRefed<nsGenericHTMLElement>
-CreateHTMLElement(uint32_t aNodeType, already_AddRefed<nsINodeInfo> aNodeInfo,
+CreateHTMLElement(uint32_t aNodeType,
+                  already_AddRefed<nsINodeInfo>&& aNodeInfo,
                   mozilla::dom::FromParser aFromParser);
 
 nsresult
 NS_NewMathMLElement(mozilla::dom::Element** aResult,
-                    already_AddRefed<nsINodeInfo> aNodeInfo);
+                    already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 #ifdef MOZ_XUL
 nsresult
 NS_NewXULElement(mozilla::dom::Element** aResult,
-                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 void
-NS_TrustedNewXULElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo);
+NS_TrustedNewXULElement(nsIContent** aResult,
+                        already_AddRefed<nsINodeInfo>&& aNodeInfo);
 #endif
 
 nsresult
 NS_NewSVGElement(mozilla::dom::Element** aResult,
-                 already_AddRefed<nsINodeInfo> aNodeInfo,
+                 already_AddRefed<nsINodeInfo>&& aNodeInfo,
                  mozilla::dom::FromParser aFromParser);
 
 nsresult
 NS_NewGenConImageContent(nsIContent** aResult,
-                         already_AddRefed<nsINodeInfo> aNodeInfo,
+                         already_AddRefed<nsINodeInfo>&& aNodeInfo,
                          imgRequestProxy* aImageRequest);
 
 #endif // nsContentCreatorFunctions_h__
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -20,16 +20,17 @@
 #include "js/TypeDecls.h"
 #include "js/Value.h"
 #include "js/RootingAPI.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/GuardObjects.h"
 #include "mozilla/TimeStamp.h"
 #include "nsContentListDeclarations.h"
 #include "nsMathUtils.h"
+#include "nsTArrayForwardDeclare.h"
 #include "Units.h"
 
 #if defined(XP_WIN)
 // Undefine LoadImage to prevent naming conflict with Windows.
 #undef LoadImage
 #endif
 
 class imgICache;
@@ -97,17 +98,16 @@ class nsViewportInfo;
 class nsWrapperCache;
 class nsAttrValue;
 
 struct JSPropertyDescriptor;
 struct JSRuntime;
 struct nsIntMargin;
 
 template<class E> class nsCOMArray;
-template<class E> class nsTArray;
 template<class K, class V> class nsDataHashtable;
 template<class K, class V> class nsRefPtrHashtable;
 template<class T> class nsReadingIterator;
 
 namespace mozilla {
 class ErrorResult;
 class Selection;
 
--- a/content/base/public/nsIAttribute.h
+++ b/content/base/public/nsIAttribute.h
@@ -35,17 +35,18 @@ public:
   /**
    * Called when our ownerElement is moved into a new document.
    * Updates the nodeinfo of this node.
    */
   virtual nsresult SetOwnerDocument(nsIDocument* aDocument) = 0;
 
 protected:
 #ifdef MOZILLA_INTERNAL_API
-  nsIAttribute(nsDOMAttributeMap *aAttrMap, already_AddRefed<nsINodeInfo> aNodeInfo,
+  nsIAttribute(nsDOMAttributeMap *aAttrMap,
+               already_AddRefed<nsINodeInfo>& aNodeInfo,
                bool aNsAware);
 #endif //MOZILLA_INTERNAL_API
   virtual ~nsIAttribute();
 
   nsRefPtr<nsDOMAttributeMap> mAttrMap;
   bool mNsAware;
 };
 
--- a/content/base/public/nsIContent.h
+++ b/content/base/public/nsIContent.h
@@ -48,21 +48,20 @@ enum nsLinkState {
 class nsIContent : public nsINode {
 public:
   typedef mozilla::widget::IMEState IMEState;
 
 #ifdef MOZILLA_INTERNAL_API
   // If you're using the external API, the only thing you can know about
   // nsIContent is that it exists with an IID
 
-  nsIContent(already_AddRefed<nsINodeInfo> aNodeInfo)
+  nsIContent(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsINode(aNodeInfo)
   {
-    NS_ASSERTION(mNodeInfo,
-                 "No nsINodeInfo passed to nsIContent, PREPARE TO CRASH!!!");
+    MOZ_ASSERT(mNodeInfo);
     SetNodeIsContent();
   }
 #endif // MOZILLA_INTERNAL_API
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID)
 
   /**
    * Bind this content node to a tree.  If this method throws, the caller must
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -314,17 +314,17 @@ public:
   }
 
   friend class nsNodeUtils;
   friend class nsNodeWeakReference;
   friend class nsNodeSupportsWeakRefTearoff;
   friend class nsAttrAndChildArray;
 
 #ifdef MOZILLA_INTERNAL_API
-  nsINode(already_AddRefed<nsINodeInfo> aNodeInfo)
+  nsINode(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : mNodeInfo(aNodeInfo),
     mParent(nullptr),
     mBoolFlags(0),
     mNextSibling(nullptr),
     mPreviousSibling(nullptr),
     mFirstChild(nullptr),
     mSubtreeRoot(MOZ_THIS_IN_INITIALIZER_LIST()),
     mSlots(nullptr)
@@ -1877,17 +1877,17 @@ ToCanonicalSupports(nsINode* aPointer)
     if (aArgc == 0) { \
       aDeep = true; \
     } \
     mozilla::ErrorResult rv; \
     nsCOMPtr<nsINode> clone = nsINode::CloneNode(aDeep, rv); \
     if (rv.Failed()) { \
       return rv.ErrorCode(); \
     } \
-    *aResult = clone.forget().get()->AsDOMNode(); \
+    *aResult = clone.forget().take()->AsDOMNode(); \
     return NS_OK; \
   } \
   NS_IMETHOD Normalize() __VA_ARGS__ \
   { \
     nsINode::Normalize(); \
     return NS_OK; \
   } \
   NS_IMETHOD GetNamespaceURI(nsAString& aNamespaceURI) __VA_ARGS__ \
--- a/content/base/src/Attr.cpp
+++ b/content/base/src/Attr.cpp
@@ -25,34 +25,34 @@
 #include "nsNodeUtils.h"
 #include "nsEventListenerManager.h"
 #include "nsTextNode.h"
 #include "mozAutoDocUpdate.h"
 #include "nsAsyncDOMEvent.h"
 #include "nsWrapperCacheInlines.h"
 
 nsIAttribute::nsIAttribute(nsDOMAttributeMap* aAttrMap,
-                           already_AddRefed<nsINodeInfo> aNodeInfo,
+                           already_AddRefed<nsINodeInfo>& aNodeInfo,
                            bool aNsAware)
 : nsINode(aNodeInfo), mAttrMap(aAttrMap), mNsAware(aNsAware)
 {
 }
 
 nsIAttribute::~nsIAttribute()
 {
 }
 
 namespace mozilla {
 namespace dom {
 
 //----------------------------------------------------------------------
 bool Attr::sInitialized;
 
 Attr::Attr(nsDOMAttributeMap *aAttrMap,
-           already_AddRefed<nsINodeInfo> aNodeInfo,
+           already_AddRefed<nsINodeInfo>&& aNodeInfo,
            const nsAString  &aValue, bool aNsAware)
   : nsIAttribute(aAttrMap, aNodeInfo, aNsAware), mValue(aValue)
 {
   NS_ABORT_IF_FALSE(mNodeInfo, "We must get a nodeinfo here!");
   NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::ATTRIBUTE_NODE,
                     "Wrong nodeType");
 
   // We don't add a reference to our content. It will tell us
--- a/content/base/src/Attr.h
+++ b/content/base/src/Attr.h
@@ -27,17 +27,17 @@ namespace dom {
 
 // Attribute helper class used to wrap up an attribute with a dom
 // object that implements nsIDOMAttr and nsIDOMNode
 class Attr MOZ_FINAL : public nsIAttribute,
                        public nsIDOMAttr
 {
 public:
   Attr(nsDOMAttributeMap* aAttrMap,
-       already_AddRefed<nsINodeInfo> aNodeInfo,
+       already_AddRefed<nsINodeInfo>&& aNodeInfo,
        const nsAString& aValue,
        bool aNsAware);
   virtual ~Attr() {}
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
   // nsIDOMNode interface
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
--- a/content/base/src/Comment.h
+++ b/content/base/src/Comment.h
@@ -19,17 +19,17 @@ class Comment MOZ_FINAL : public nsGener
 private:
   void Init()
   {
     NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE,
                       "Bad NodeType in aNodeInfo");
   }
 
 public:
-  Comment(already_AddRefed<nsINodeInfo> aNodeInfo)
+  Comment(already_AddRefed<nsINodeInfo>&& aNodeInfo)
     : nsGenericDOMDataNode(aNodeInfo)
   {
     Init();
   }
 
   Comment(nsNodeInfoManager* aNodeInfoManager)
     : nsGenericDOMDataNode(aNodeInfoManager->GetCommentNodeInfo())
   {
--- a/content/base/src/DOMImplementation.cpp
+++ b/content/base/src/DOMImplementation.cpp
@@ -83,17 +83,18 @@ DOMImplementation::CreateDocumentType(co
 
 NS_IMETHODIMP
 DOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
                                       const nsAString& aPublicId,
                                       const nsAString& aSystemId,
                                       nsIDOMDocumentType** aReturn)
 {
   ErrorResult rv;
-  *aReturn = CreateDocumentType(aQualifiedName, aPublicId, aSystemId, rv).get();
+  *aReturn =
+    CreateDocumentType(aQualifiedName, aPublicId, aSystemId, rv).take();
   return rv.ErrorCode();
 }
 
 nsresult
 DOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
                                   const nsAString& aQualifiedName,
                                   nsIDOMDocumentType* aDoctype,
                                   nsIDocument** aDocument,
--- a/content/base/src/DocumentFragment.h
+++ b/content/base/src/DocumentFragment.h
@@ -46,17 +46,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // interface nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
   // interface nsIDOMDocumentFragment
   NS_DECL_NSIDOMDOCUMENTFRAGMENT
 
-  DocumentFragment(already_AddRefed<nsINodeInfo> aNodeInfo)
+  DocumentFragment(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : FragmentOrElement(aNodeInfo), mHost(nullptr)
   {
     Init();
   }
 
   DocumentFragment(nsNodeInfoManager* aNodeInfoManager)
     : FragmentOrElement(aNodeInfoManager->GetNodeInfo(
                                             nsGkAtoms::documentFragmentNodeName,
--- a/content/base/src/DocumentType.cpp
+++ b/content/base/src/DocumentType.cpp
@@ -23,54 +23,54 @@ NS_NewDOMDocumentType(nsIDOMDocumentType
                       nsIAtom *aName,
                       const nsAString& aPublicId,
                       const nsAString& aSystemId,
                       const nsAString& aInternalSubset)
 {
   NS_ENSURE_ARG_POINTER(aDocType);
   mozilla::ErrorResult rv;
   *aDocType = NS_NewDOMDocumentType(aNodeInfoManager, aName, aPublicId,
-                                    aSystemId, aInternalSubset, rv).get();
+                                    aSystemId, aInternalSubset, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<mozilla::dom::DocumentType>
 NS_NewDOMDocumentType(nsNodeInfoManager* aNodeInfoManager,
                       nsIAtom *aName,
                       const nsAString& aPublicId,
                       const nsAString& aSystemId,
                       const nsAString& aInternalSubset,
                       mozilla::ErrorResult& rv)
 {
   if (!aName) {
     rv.Throw(NS_ERROR_INVALID_POINTER);
     return nullptr;
   }
 
-  nsCOMPtr<nsINodeInfo> ni =
+  already_AddRefed<nsINodeInfo> ni =
     aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nullptr,
                                   kNameSpaceID_None,
                                   nsIDOMNode::DOCUMENT_TYPE_NODE,
                                   aName);
 
   nsRefPtr<mozilla::dom::DocumentType> docType =
-    new mozilla::dom::DocumentType(ni.forget(), aPublicId, aSystemId, aInternalSubset);
+    new mozilla::dom::DocumentType(ni, aPublicId, aSystemId, aInternalSubset);
   return docType.forget();
 }
 
 namespace mozilla {
 namespace dom {
 
 JSObject*
 DocumentType::WrapNode(JSContext *cx, JS::Handle<JSObject*> scope)
 {
   return DocumentTypeBinding::Wrap(cx, scope, this);
 }
 
-DocumentType::DocumentType(already_AddRefed<nsINodeInfo> aNodeInfo,
+DocumentType::DocumentType(already_AddRefed<nsINodeInfo>& aNodeInfo,
                            const nsAString& aPublicId,
                            const nsAString& aSystemId,
                            const nsAString& aInternalSubset) :
   DocumentTypeForward(aNodeInfo),
   mPublicId(aPublicId),
   mSystemId(aSystemId),
   mInternalSubset(aInternalSubset)
 {
@@ -136,16 +136,15 @@ DocumentType::MozRemove()
 {
   Remove();
   return NS_OK;
 }
 
 nsGenericDOMDataNode*
 DocumentType::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const
 {
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-  return new DocumentType(ni.forget(), mPublicId, mSystemId,
-                          mInternalSubset);
+  already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
+  return new DocumentType(ni, mPublicId, mSystemId, mInternalSubset);
 }
 
 } // namespace dom
 } // namespace mozilla
 
--- a/content/base/src/DocumentType.h
+++ b/content/base/src/DocumentType.h
@@ -24,29 +24,29 @@ namespace dom {
 // CharacterData object, even though DocumentType is not character
 // data. This is done simply for convenience and should be changed if
 // this restricts what should be done for character data.
 
 class DocumentTypeForward : public nsGenericDOMDataNode,
                             public nsIDOMDocumentType
 {
 public:
-  DocumentTypeForward(already_AddRefed<nsINodeInfo> aNodeInfo)
+  DocumentTypeForward(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericDOMDataNode(aNodeInfo)
   {
   }
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 };
 
 class DocumentType MOZ_FINAL : public DocumentTypeForward
 {
 public:
-  DocumentType(already_AddRefed<nsINodeInfo> aNodeInfo,
+  DocumentType(already_AddRefed<nsINodeInfo>& aNodeInfo,
                const nsAString& aPublicId,
                const nsAString& aSystemId,
                const nsAString& aInternalSubset);
 
   virtual ~DocumentType();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -473,17 +473,17 @@ Element::GetElementsByTagName(const nsAS
 {
   return NS_GetContentList(this, kNameSpaceID_Unknown, aLocalName);
 }
 
 void
 Element::GetElementsByTagName(const nsAString& aLocalName,
                               nsIDOMHTMLCollection** aResult)
 {
-  *aResult = GetElementsByTagName(aLocalName).get();
+  *aResult = GetElementsByTagName(aLocalName).take();
 }
 
 nsIFrame*
 Element::GetStyledFrame()
 {
   nsIFrame *frame = GetPrimaryFrame(Flush_Layout);
   return frame ? nsLayoutUtils::GetStyleFrame(frame) : nullptr;
 }
@@ -1047,17 +1047,18 @@ Element::GetElementsByClassName(const ns
 {
   return nsContentUtils::GetElementsByClassName(this, aClassNames);
 }
 
 nsresult
 Element::GetElementsByClassName(const nsAString& aClassNames,
                                 nsIDOMHTMLCollection** aResult)
 {
-  *aResult = nsContentUtils::GetElementsByClassName(this, aClassNames).get();
+  *aResult =
+    nsContentUtils::GetElementsByClassName(this, aClassNames).take();
   return NS_OK;
 }
 
 nsresult
 Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                     nsIContent* aBindingParent,
                     bool aCompileEventHandlers)
 {
--- a/content/base/src/FragmentOrElement.cpp
+++ b/content/base/src/FragmentOrElement.cpp
@@ -614,17 +614,22 @@ FragmentOrElement::nsDOMSlots::SizeOfInc
   // - mChildrenList
   // - mClassList
 
   // The following members are not measured:
   // - mBindingParent / mControllers: because they're   non-owning
   return n;
 }
 
-FragmentOrElement::FragmentOrElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+FragmentOrElement::FragmentOrElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
+  : nsIContent(aNodeInfo)
+{
+}
+
+FragmentOrElement::FragmentOrElement(already_AddRefed<nsINodeInfo>&& aNodeInfo)
   : nsIContent(aNodeInfo)
 {
 }
 
 FragmentOrElement::~FragmentOrElement()
 {
   NS_PRECONDITION(!IsInDoc(),
                   "Please remove this from the document properly");
--- a/content/base/src/NodeIterator.cpp
+++ b/content/base/src/NodeIterator.cpp
@@ -193,17 +193,17 @@ NS_IMETHODIMP NodeIterator::GetWhatToSho
     return NS_OK;
 }
 
 /* readonly attribute nsIDOMNodeFilter filter; */
 NS_IMETHODIMP NodeIterator::GetFilter(nsIDOMNodeFilter **aFilter)
 {
     NS_ENSURE_ARG_POINTER(aFilter);
 
-    *aFilter = mFilter.ToXPCOMCallback().get();
+    *aFilter = mFilter.ToXPCOMCallback().take();
 
     return NS_OK;
 }
 
 /* nsIDOMNode nextNode ()  raises (DOMException); */
 NS_IMETHODIMP NodeIterator::NextNode(nsIDOMNode **_retval)
 {
     return ImplNodeGetter(&NodeIterator::NextNode, _retval);
--- a/content/base/src/NodeIterator.h
+++ b/content/base/src/NodeIterator.h
@@ -96,17 +96,17 @@ private:
     typedef already_AddRefed<nsINode> (NodeIterator::*NodeGetter)(ErrorResult&);
     inline nsresult ImplNodeGetter(NodeGetter aGetter, nsIDOMNode** aRetval)
     {
         mozilla::ErrorResult rv;
         nsCOMPtr<nsINode> node = (this->*aGetter)(rv);
         if (rv.Failed()) {
             return rv.ErrorCode();
         }
-        *aRetval = node ? node.forget().get()->AsDOMNode() : nullptr;
+        *aRetval = node ? node.forget().take()->AsDOMNode() : nullptr;
         return NS_OK;
     }
 
     // Have to return a strong ref, because the act of testing the node can
     // remove it from the DOM so we're holding the only ref to it.
     already_AddRefed<nsINode>
     NextOrPrevNode(NodePointer::MoveToMethodType aMove, ErrorResult& aResult);
 
--- a/content/base/src/ShadowRoot.cpp
+++ b/content/base/src/ShadowRoot.cpp
@@ -60,17 +60,17 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
   NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
 NS_INTERFACE_MAP_END_INHERITING(DocumentFragment)
 
 NS_IMPL_ADDREF_INHERITED(ShadowRoot, DocumentFragment)
 NS_IMPL_RELEASE_INHERITED(ShadowRoot, DocumentFragment)
 
 ShadowRoot::ShadowRoot(nsIContent* aContent,
-                       already_AddRefed<nsINodeInfo> aNodeInfo,
+                       already_AddRefed<nsINodeInfo>&& aNodeInfo,
                        nsXBLPrototypeBinding* aProtoBinding)
   : DocumentFragment(aNodeInfo), mPoolHost(aContent),
     mProtoBinding(aProtoBinding), mShadowElement(nullptr),
     mInsertionPointChanged(false)
 {
   SetHost(aContent);
   SetFlags(NODE_IS_IN_SHADOW_TREE);
   // ShadowRoot isn't really in the document but it behaves like it is.
--- a/content/base/src/ShadowRoot.h
+++ b/content/base/src/ShadowRoot.h
@@ -37,17 +37,17 @@ public:
                                            DocumentFragment)
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
 
-  ShadowRoot(nsIContent* aContent, already_AddRefed<nsINodeInfo> aNodeInfo,
+  ShadowRoot(nsIContent* aContent, already_AddRefed<nsINodeInfo>&& aNodeInfo,
              nsXBLPrototypeBinding* aProtoBinding);
   virtual ~ShadowRoot();
 
   void AddToIdTable(Element* aElement, nsIAtom* aId);
   void RemoveFromIdTable(Element* aElement, nsIAtom* aId);
   void InsertSheet(nsCSSStyleSheet* aSheet, nsIContent* aLinkingContent);
   void RemoveSheet(nsCSSStyleSheet* aSheet);
   bool ApplyAuthorStyles();
--- a/content/base/src/Text.h
+++ b/content/base/src/Text.h
@@ -10,17 +10,21 @@
 #include "mozilla/ErrorResult.h"
 
 namespace mozilla {
 namespace dom {
 
 class Text : public nsGenericDOMDataNode
 {
 public:
-  Text(already_AddRefed<nsINodeInfo> aNodeInfo)
+  Text(already_AddRefed<nsINodeInfo>& aNodeInfo)
+    : nsGenericDOMDataNode(aNodeInfo)
+  {}
+
+  Text(already_AddRefed<nsINodeInfo>&& aNodeInfo)
     : nsGenericDOMDataNode(aNodeInfo)
   {}
 
   using nsGenericDOMDataNode::GetWholeText;
 
   // WebIDL API
   already_AddRefed<Text> SplitText(uint32_t aOffset, ErrorResult& rv);
   void GetWholeText(nsAString& aWholeText, ErrorResult& rv)
--- a/content/base/src/TreeWalker.cpp
+++ b/content/base/src/TreeWalker.cpp
@@ -75,17 +75,17 @@ NS_IMETHODIMP TreeWalker::GetWhatToShow(
     return NS_OK;
 }
 
 /* readonly attribute nsIDOMNodeFilter filter; */
 NS_IMETHODIMP TreeWalker::GetFilter(nsIDOMNodeFilter * *aFilter)
 {
     NS_ENSURE_ARG_POINTER(aFilter);
 
-    *aFilter = mFilter.ToXPCOMCallback().get();
+    *aFilter = mFilter.ToXPCOMCallback().take();
 
     return NS_OK;
 }
 
 /* attribute nsIDOMNode currentNode; */
 NS_IMETHODIMP TreeWalker::GetCurrentNode(nsIDOMNode * *aCurrentNode)
 {
     if (mCurrentNode) {
--- a/content/base/src/TreeWalker.h
+++ b/content/base/src/TreeWalker.h
@@ -93,17 +93,17 @@ private:
     typedef already_AddRefed<nsINode> (TreeWalker::*NodeGetter)(ErrorResult&);
     inline nsresult ImplNodeGetter(NodeGetter aGetter, nsIDOMNode** aRetval)
     {
         mozilla::ErrorResult rv;
         nsCOMPtr<nsINode> node = (this->*aGetter)(rv);
         if (rv.Failed()) {
             return rv.ErrorCode();
         }
-        *aRetval = node ? node.forget().get()->AsDOMNode() : nullptr;
+        *aRetval = node ? node.forget().take()->AsDOMNode() : nullptr;
         return NS_OK;
     }
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_TreeWalker_h
--- a/content/base/src/WebSocket.cpp
+++ b/content/base/src/WebSocket.cpp
@@ -1407,17 +1407,17 @@ WebSocket::GetLoadGroup(nsILoadGroup** a
   *aLoadGroup = nullptr;
 
   nsresult rv;
   nsIScriptContext* sc = GetContextForEventHandlers(&rv);
   nsCOMPtr<nsIDocument> doc =
     nsContentUtils::GetDocumentFromScriptContext(sc);
 
   if (doc) {
-    *aLoadGroup = doc->GetDocumentLoadGroup().get();  // already_AddRefed
+    *aLoadGroup = doc->GetDocumentLoadGroup().take();
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebSocket::SetLoadGroup(nsILoadGroup* aLoadGroup)
 {
--- a/content/base/src/nsAttrValue.cpp
+++ b/content/base/src/nsAttrValue.cpp
@@ -370,17 +370,17 @@ nsAttrValue::SetTo(const nsAttrValue& aO
   // work correctly.
   cont->mType = otherCont->mType;
 }
 
 void
 nsAttrValue::SetTo(const nsAString& aValue)
 {
   ResetIfSet();
-  nsStringBuffer* buf = GetStringBuffer(aValue).get();
+  nsStringBuffer* buf = GetStringBuffer(aValue).take();
   if (buf) {
     SetPtrValueAndType(buf, eStringBase);
   }
 }
 
 void
 nsAttrValue::SetTo(nsIAtom* aValue)
 {
@@ -1227,17 +1227,17 @@ nsAttrValue::Contains(const nsAString& a
 
 void
 nsAttrValue::ParseAtom(const nsAString& aValue)
 {
   ResetIfSet();
 
   nsCOMPtr<nsIAtom> atom = NS_NewAtom(aValue);
   if (atom) {
-    SetPtrValueAndType(atom.forget().get(), eAtomBase);
+    SetPtrValueAndType(atom.forget().take(), eAtomBase);
   }
 }
 
 void
 nsAttrValue::ParseAtomArray(const nsAString& aValue)
 {
   nsAString::const_iterator iter, end;
   aValue.BeginReading(iter);
@@ -1523,17 +1523,17 @@ nsAttrValue::ParsePositiveIntValue(const
   SetIntValueAndType(originalVal, eInteger, strict ? nullptr : &aString);
 
   return true;
 }
 
 void
 nsAttrValue::SetColorValue(nscolor aColor, const nsAString& aString)
 {
-  nsStringBuffer* buf = GetStringBuffer(aString).get();
+  nsStringBuffer* buf = GetStringBuffer(aString).take();
   if (!buf) {
     return;
   }
 
   MiscContainer* cont = EnsureEmptyMiscContainer();
   cont->mValue.mColor = aColor;
   cont->mType = eColor;
 
@@ -1711,20 +1711,20 @@ nsAttrValue::SetMiscAtomOrString(const n
     // Add other types as needed.
     NS_ASSERTION(len || Type() == eCSSStyleRule || Type() == eEnum,
                  "Empty string?");
     MiscContainer* cont = GetMiscContainer();
     if (len <= NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM) {
       nsCOMPtr<nsIAtom> atom = NS_NewAtom(*aValue);
       if (atom) {
         cont->mStringBits =
-          reinterpret_cast<uintptr_t>(atom.forget().get()) | eAtomBase;
+          reinterpret_cast<uintptr_t>(atom.forget().take()) | eAtomBase;
       }
     } else {
-      nsStringBuffer* buf = GetStringBuffer(*aValue).get();
+      nsStringBuffer* buf = GetStringBuffer(*aValue).take();
       if (buf) {
         cont->mStringBits = reinterpret_cast<uintptr_t>(buf) | eStringBase;
       }
     }
   }
 }
 
 void
--- a/content/base/src/nsCSPService.cpp
+++ b/content/base/src/nsCSPService.cpp
@@ -288,18 +288,20 @@ CSPService::AsyncOnChannelRedirect(nsICh
                                 NS_GET_IID(nsISupports),
                                 getter_AddRefs(policyContainer));
 
   // see if we have a valid nsIChannelPolicy containing CSP and load type
   nsCOMPtr<nsIChannelPolicy> channelPolicy(do_QueryInterface(policyContainer));
   if (!channelPolicy)
     return NS_OK;
 
+  nsCOMPtr<nsISupports> supports;
   nsCOMPtr<nsIContentSecurityPolicy> csp;
-  channelPolicy->GetContentSecurityPolicy(getter_AddRefs(csp));
+  channelPolicy->GetContentSecurityPolicy(getter_AddRefs(supports));
+  csp = do_QueryInterface(supports);
   uint32_t loadType;
   channelPolicy->GetLoadType(&loadType);
 
   // if no CSP in the channelPolicy, nothing for us to add to the channel
   if (!csp)
     return NS_OK;
 
   /* Since redirecting channels don't call into nsIContentPolicy, we call our
--- a/content/base/src/nsContentAreaDragDrop.cpp
+++ b/content/base/src/nsContentAreaDragDrop.cpp
@@ -659,31 +659,40 @@ DragDataProducer::Produce(DataTransfer* 
                                                       getter_AddRefs(transferable));
     }
     else {
       rv = nsCopySupport::GetTransferableForNode(nodeToSerialize, doc,
                                                  getter_AddRefs(transferable));
     }
     NS_ENSURE_SUCCESS(rv, rv);
 
+    nsCOMPtr<nsISupports> supports;
     nsCOMPtr<nsISupportsString> data;
     uint32_t dataSize;
-    rv = transferable->GetTransferData(kHTMLMime, getter_AddRefs(data), &dataSize);
+    rv = transferable->GetTransferData(kHTMLMime, getter_AddRefs(supports),
+                                       &dataSize);
+    data = do_QueryInterface(supports);
     if (NS_SUCCEEDED(rv)) {
       data->GetData(mHtmlString);
     }
-    rv = transferable->GetTransferData(kHTMLContext, getter_AddRefs(data), &dataSize);
+    rv = transferable->GetTransferData(kHTMLContext, getter_AddRefs(supports),
+                                       &dataSize);
+    data = do_QueryInterface(supports);
     if (NS_SUCCEEDED(rv)) {
       data->GetData(mContextString);
     }
-    rv = transferable->GetTransferData(kHTMLInfo, getter_AddRefs(data), &dataSize);
+    rv = transferable->GetTransferData(kHTMLInfo, getter_AddRefs(supports),
+                                       &dataSize);
+    data = do_QueryInterface(supports);
     if (NS_SUCCEEDED(rv)) {
       data->GetData(mInfoString);
     }
-    rv = transferable->GetTransferData(kUnicodeMime, getter_AddRefs(data), &dataSize);
+    rv = transferable->GetTransferData(kUnicodeMime, getter_AddRefs(supports),
+                                       &dataSize);
+    data = do_QueryInterface(supports);
     NS_ENSURE_SUCCESS(rv, rv); // require plain text at a minimum
     data->GetData(mTitleString);
   }
 
   // default text value is the URL
   if (mTitleString.IsEmpty()) {
     mTitleString = mUrlString;
   }
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -2497,21 +2497,21 @@ nsContentUtils::SplitQName(const nsICont
                                                                   colon),
                                                         nameSpace);
     NS_ENSURE_SUCCESS(rv, rv);
 
     *aNamespace = NameSpaceManager()->GetNameSpaceID(nameSpace);
     if (*aNamespace == kNameSpaceID_Unknown)
       return NS_ERROR_FAILURE;
 
-    *aLocalName = NS_NewAtom(Substring(colon + 1, end)).get();
+    *aLocalName = NS_NewAtom(Substring(colon + 1, end)).take();
   }
   else {
     *aNamespace = kNameSpaceID_None;
-    *aLocalName = NS_NewAtom(aQName).get();
+    *aLocalName = NS_NewAtom(aQName).take();
   }
   NS_ENSURE_TRUE(aLocalName, NS_ERROR_OUT_OF_MEMORY);
   return NS_OK;
 }
 
 // static
 nsresult
 nsContentUtils::GetNodeInfoFromQName(const nsAString& aNamespaceURI,
@@ -2586,30 +2586,30 @@ nsContentUtils::SplitExpatName(const cha
     }
     else {
       *aNameSpaceID = kNameSpaceID_Unknown;
     }
 
     nameStart = (uriEnd + 1);
     if (nameEnd)  {
       const char16_t *prefixStart = nameEnd + 1;
-      *aPrefix = NS_NewAtom(Substring(prefixStart, pos)).get();
+      *aPrefix = NS_NewAtom(Substring(prefixStart, pos)).take();
     }
     else {
       nameEnd = pos;
       *aPrefix = nullptr;
     }
   }
   else {
     *aNameSpaceID = kNameSpaceID_None;
     nameStart = aExpatName;
     nameEnd = pos;
     *aPrefix = nullptr;
   }
-  *aLocalName = NS_NewAtom(Substring(nameStart, nameEnd)).get();
+  *aLocalName = NS_NewAtom(Substring(nameStart, nameEnd)).take();
 }
 
 // static
 nsPresContext*
 nsContentUtils::GetContextForContent(const nsIContent* aContent)
 {
   nsIDocument* doc = aContent->GetCurrentDoc();
   if (doc) {
@@ -2890,17 +2890,17 @@ nsresult
 nsContentUtils::NameChanged(nsINodeInfo* aNodeInfo, nsIAtom* aName,
                             nsINodeInfo** aResult)
 {
   nsNodeInfoManager *niMgr = aNodeInfo->NodeInfoManager();
 
   *aResult = niMgr->GetNodeInfo(aName, aNodeInfo->GetPrefixAtom(),
                                 aNodeInfo->NamespaceID(),
                                 aNodeInfo->NodeType(),
-                                aNodeInfo->GetExtraName()).get();
+                                aNodeInfo->GetExtraName()).take();
   return NS_OK;
 }
 
 
 static bool
 TestSitePerm(nsIPrincipal* aPrincipal, const char* aType, uint32_t aPerm, bool aExactHostMatch)
 {
   if (!aPrincipal) {
@@ -3824,17 +3824,17 @@ nsContentUtils::IsValidNodeName(nsIAtom 
 nsresult
 nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
                                          const nsAString& aFragment,
                                          bool aPreventScriptExecution,
                                          nsIDOMDocumentFragment** aReturn)
 {
   ErrorResult rv;
   *aReturn = CreateContextualFragment(aContextNode, aFragment,
-                                      aPreventScriptExecution, rv).get();
+                                      aPreventScriptExecution, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<DocumentFragment>
 nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
                                          const nsAString& aFragment,
                                          bool aPreventScriptExecution,
                                          ErrorResult& aRv)
--- a/content/base/src/nsDOMAttributeMap.cpp
+++ b/content/base/src/nsDOMAttributeMap.cpp
@@ -237,28 +237,28 @@ nsDOMAttributeMap::GetNamedItem(const ns
 
 NS_IMETHODIMP
 nsDOMAttributeMap::SetNamedItem(nsIDOMAttr* aAttr, nsIDOMAttr** aReturn)
 {
   Attr* attribute = static_cast<Attr*>(aAttr);
   NS_ENSURE_ARG(attribute);
 
   ErrorResult rv;
-  *aReturn = SetNamedItem(*attribute, rv).get();
+  *aReturn = SetNamedItem(*attribute, rv).take();
   return rv.ErrorCode();
 }
 
 NS_IMETHODIMP
 nsDOMAttributeMap::SetNamedItemNS(nsIDOMAttr* aAttr, nsIDOMAttr** aReturn)
 {
   Attr* attribute = static_cast<Attr*>(aAttr);
   NS_ENSURE_ARG(attribute);
 
   ErrorResult rv;
-  *aReturn = SetNamedItemNS(*attribute, rv).get();
+  *aReturn = SetNamedItemNS(*attribute, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<Attr>
 nsDOMAttributeMap::SetNamedItemInternal(Attr& aAttr,
                                         bool aWithNS,
                                         ErrorResult& aError)
 {
@@ -351,17 +351,17 @@ nsDOMAttributeMap::SetNamedItemInternal(
 
 NS_IMETHODIMP
 nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName,
                                    nsIDOMAttr** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
 
   ErrorResult rv;
-  *aReturn = RemoveNamedItem(aName, rv).get();
+  *aReturn = RemoveNamedItem(aName, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<Attr>
 nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName, ErrorResult& aError)
 {
   if (!mContent) {
     aError.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
@@ -492,17 +492,17 @@ nsDOMAttributeMap::GetAttrNodeInfo(const
 
 NS_IMETHODIMP
 nsDOMAttributeMap::RemoveNamedItemNS(const nsAString& aNamespaceURI,
                                      const nsAString& aLocalName,
                                      nsIDOMAttr** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   ErrorResult rv;
-  *aReturn = RemoveNamedItemNS(aNamespaceURI, aLocalName, rv).get();
+  *aReturn = RemoveNamedItemNS(aNamespaceURI, aLocalName, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<Attr>
 nsDOMAttributeMap::RemoveNamedItemNS(const nsAString& aNamespaceURI,
                                      const nsAString& aLocalName,
                                      ErrorResult& aError)
 {
--- a/content/base/src/nsDOMDataChannel.cpp
+++ b/content/base/src/nsDOMDataChannel.cpp
@@ -75,17 +75,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_ADDREF_INHERITED(nsDOMDataChannel, nsDOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(nsDOMDataChannel, nsDOMEventTargetHelper)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMDataChannel)
   NS_INTERFACE_MAP_ENTRY(nsIDOMDataChannel)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
-nsDOMDataChannel::nsDOMDataChannel(already_AddRefed<mozilla::DataChannel> aDataChannel,
+nsDOMDataChannel::nsDOMDataChannel(already_AddRefed<mozilla::DataChannel>& aDataChannel,
                                    nsPIDOMWindow* aWindow)
   : nsDOMEventTargetHelper(aWindow && aWindow->IsOuterWindow() ?
                              aWindow->GetCurrentInnerWindow() : aWindow)
   , mDataChannel(aDataChannel)
   , mBinaryType(DC_BINARY_TYPE_BLOB)
 {
 }
 
@@ -485,17 +485,17 @@ nsDOMDataChannel::OnChannelClosed(nsISup
 void
 nsDOMDataChannel::AppReady()
 {
   mDataChannel->AppReady();
 }
 
 /* static */
 nsresult
-NS_NewDOMDataChannel(already_AddRefed<mozilla::DataChannel> aDataChannel,
+NS_NewDOMDataChannel(already_AddRefed<mozilla::DataChannel>&& aDataChannel,
                      nsPIDOMWindow* aWindow,
                      nsIDOMDataChannel** aDomDataChannel)
 {
   nsRefPtr<nsDOMDataChannel> domdc =
     new nsDOMDataChannel(aDataChannel, aWindow);
 
   nsresult rv = domdc->Init(aWindow);
   NS_ENSURE_SUCCESS(rv,rv);
--- a/content/base/src/nsDOMDataChannel.h
+++ b/content/base/src/nsDOMDataChannel.h
@@ -20,17 +20,17 @@ namespace mozilla {
 class DataChannel;
 };
 
 class nsDOMDataChannel : public nsDOMEventTargetHelper,
                          public nsIDOMDataChannel,
                          public mozilla::DataChannelListener
 {
 public:
-  nsDOMDataChannel(already_AddRefed<mozilla::DataChannel> aDataChannel,
+  nsDOMDataChannel(already_AddRefed<mozilla::DataChannel>& aDataChannel,
                    nsPIDOMWindow* aWindow);
   ~nsDOMDataChannel();
 
   nsresult Init(nsPIDOMWindow* aDOMWindow);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMDATACHANNEL
 
--- a/content/base/src/nsDOMDataChannelDeclarations.h
+++ b/content/base/src/nsDOMDataChannelDeclarations.h
@@ -15,16 +15,16 @@
 
 namespace mozilla {
    class DataChannel;
 }
 
 class nsPIDOMWindow;
 
 nsresult
-NS_NewDOMDataChannel(already_AddRefed<mozilla::DataChannel> dataChannel,
+NS_NewDOMDataChannel(already_AddRefed<mozilla::DataChannel>&& dataChannel,
                      nsPIDOMWindow* aWindow,
                      nsIDOMDataChannel** domDataChannel);
 
 // Tell DataChannel it's ok to deliver open and message events
 void NS_DataChannelAppReady(nsIDOMDataChannel* domDataChannel);
 
 #endif // nsDOMDataChannelDeclarations_h
--- a/content/base/src/nsDOMFile.cpp
+++ b/content/base/src/nsDOMFile.cpp
@@ -251,17 +251,17 @@ nsDOMFileBase::Slice(int64_t aStart, int
   if (optional_argc < 2) {
     aEnd = (int64_t)thisLength;
   }
 
   ParseSize((int64_t)thisLength, aStart, aEnd);
   
   // Create the new file
   *aBlob = CreateSlice((uint64_t)aStart, (uint64_t)(aEnd - aStart),
-                       aContentType).get();
+                       aContentType).take();
 
   return *aBlob ? NS_OK : NS_ERROR_UNEXPECTED;
 }
 
 NS_IMETHODIMP
 nsDOMFileBase::GetInternalStream(nsIInputStream **aStream)
 {
   // Must be overridden
--- a/content/base/src/nsDOMMutationObserver.cpp
+++ b/content/base/src/nsDOMMutationObserver.cpp
@@ -602,17 +602,17 @@ nsDOMMutationObserver::HandleMutation()
   if (mutations.SetCapacity(mPendingMutationCount)) {
     // We can't use TakeRecords easily here, because it deals with a
     // different type of array, and we want to optimize out any extra copying.
     nsRefPtr<nsDOMMutationRecord> current;
     current.swap(mFirstPendingMutation);
     for (uint32_t i = 0; i < mPendingMutationCount; ++i) {
       nsRefPtr<nsDOMMutationRecord> next;
       current->mNext.swap(next);
-      *mutations.AppendElement() = current.forget();
+      *mutations.AppendElement() = current;
       current.swap(next);
     }
   }
   ClearPendingRecords();
 
   mozilla::ErrorResult rv;
   mCallback->Call(this, mutations, *this, rv);
 }
--- a/content/base/src/nsDOMMutationObserver.h
+++ b/content/base/src/nsDOMMutationObserver.h
@@ -338,17 +338,17 @@ public:
 #define NS_DOM_MUTATION_OBSERVER_IID \
 { 0x0c3b91f8, 0xcc3b, 0x4b08, \
   { 0x9e, 0xab, 0x07, 0x47, 0xa9, 0xe4, 0x65, 0xb4 } }
 
 class nsDOMMutationObserver : public nsISupports,
                               public nsWrapperCache
 {
 public:
-  nsDOMMutationObserver(already_AddRefed<nsPIDOMWindow> aOwner,
+  nsDOMMutationObserver(already_AddRefed<nsPIDOMWindow>&& aOwner,
                         mozilla::dom::MutationCallback& aCb)
   : mOwner(aOwner), mLastPendingMutation(nullptr), mPendingMutationCount(0),
     mCallback(&aCb), mWaitingForRun(false), mId(++sCount)
   {
     SetIsDOMBinding();
   }
   virtual ~nsDOMMutationObserver();
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@@ -382,24 +382,25 @@ public:
   void HandleMutation();
 
   void GetObservingInfo(nsTArray<Nullable<MutationObservingInfo> >& aResult);
 
   mozilla::dom::MutationCallback* MutationCallback() { return mCallback; }
 
   void AppendMutationRecord(already_AddRefed<nsDOMMutationRecord> aRecord)
   {
-    MOZ_ASSERT(aRecord.get());
+    nsRefPtr<nsDOMMutationRecord> record = aRecord;
+    MOZ_ASSERT(record);
     if (!mLastPendingMutation) {
       MOZ_ASSERT(!mFirstPendingMutation);
-      mFirstPendingMutation = aRecord;
+      mFirstPendingMutation = record.forget();
       mLastPendingMutation = mFirstPendingMutation;
     } else {
       MOZ_ASSERT(mFirstPendingMutation);
-      mLastPendingMutation->mNext = aRecord;
+      mLastPendingMutation->mNext = record.forget();
       mLastPendingMutation = mLastPendingMutation->mNext;
     }
     ++mPendingMutationCount;
   }
 
   void ClearPendingRecords()
   {
     mFirstPendingMutation = nullptr;
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1260,17 +1260,17 @@ IMPL_SHIM(nsIApplicationCacheContainer)
       nsCOMPtr<_i> real = do_GetInterface(mCallbacks);                     \
       if (!real) {                                                         \
         return NS_NOINTERFACE;                                             \
       }                                                                    \
       nsCOMPtr<_i> shim = new _i##Shim(this, real);                        \
       if (!shim) {                                                         \
         return NS_ERROR_OUT_OF_MEMORY;                                     \
       }                                                                    \
-      *aSink = shim.forget().get();                                        \
+      shim.forget(aSink);                                                  \
       return NS_OK;                                                        \
     }                                                                      \
   PR_END_MACRO
 
 NS_IMETHODIMP
 nsExternalResourceMap::LoadgroupCallbacks::GetInterface(const nsIID & aIID,
                                                         void **aSink)
 {
@@ -1421,21 +1421,23 @@ struct nsIDocument::FrameRequest
   bool operator<(int32_t aHandle) const {
     return mHandle < aHandle;
   }
 
   FrameRequestCallbackHolder mCallback;
   int32_t mHandle;
 };
 
+static already_AddRefed<nsINodeInfo> nullNodeInfo(nullptr);
+
 // ==================================================================
 // =
 // ==================================================================
 nsIDocument::nsIDocument()
-  : nsINode(nullptr),
+  : nsINode(nullNodeInfo),
     mCharacterSet(NS_LITERAL_CSTRING("ISO-8859-1")),
     mNodeInfoManager(nullptr),
     mCompatMode(eCompatibility_FullStandards),
     mVisibilityState(dom::VisibilityState::Hidden),
     mIsInitialDocumentInWindow(false),
     mMayStartLayout(true),
     mVisible(true),
     mRemovedFromDocShell(false),
@@ -3363,17 +3365,17 @@ nsDocument::NodesFromRectHelper(float aX
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocument::GetElementsByClassName(const nsAString& aClasses,
                                    nsIDOMNodeList** aReturn)
 {
-  *aReturn = nsIDocument::GetElementsByClassName(aClasses).get();
+  *aReturn = nsIDocument::GetElementsByClassName(aClasses).take();
   return NS_OK;
 }
 
 already_AddRefed<nsContentList>
 nsIDocument::GetElementsByClassName(const nsAString& aClasses)
 {
   return nsContentUtils::GetElementsByClassName(this, aClasses);
 }
@@ -5101,17 +5103,17 @@ nsIDocument::CreateElement(const nsAStri
   }
 
   nsCOMPtr<nsIContent> content;
   rv = CreateElem(needsLowercase ? lcTagName : aTagName,
                   nullptr, mDefaultElementType, getter_AddRefs(content));
   if (rv.Failed()) {
     return nullptr;
   }
-  return dont_AddRef(content.forget().get()->AsElement());
+  return dont_AddRef(content.forget().take()->AsElement());
 }
 
 void
 nsDocument::SwizzleCustomElement(Element* aElement,
                                  const nsAString& aTypeExtension,
                                  uint32_t aNamespaceID,
                                  ErrorResult& rv)
 {
@@ -5232,47 +5234,47 @@ nsDocument::CreateElementNS(const nsAStr
   }
 
   return elem.forget();
 }
 
 NS_IMETHODIMP
 nsDocument::CreateTextNode(const nsAString& aData, nsIDOMText** aReturn)
 {
-  *aReturn = nsIDocument::CreateTextNode(aData).get();
+  *aReturn = nsIDocument::CreateTextNode(aData).take();
   return NS_OK;
 }
 
 already_AddRefed<nsTextNode>
 nsIDocument::CreateTextNode(const nsAString& aData) const
 {
   nsRefPtr<nsTextNode> text = new nsTextNode(mNodeInfoManager);
   // Don't notify; this node is still being created.
   text->SetText(aData, false);
   return text.forget();
 }
 
 NS_IMETHODIMP
 nsDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
 {
-  *aReturn = nsIDocument::CreateDocumentFragment().get();
+  *aReturn = nsIDocument::CreateDocumentFragment().take();
   return NS_OK;
 }
 
 already_AddRefed<DocumentFragment>
 nsIDocument::CreateDocumentFragment() const
 {
   nsRefPtr<DocumentFragment> frag = new DocumentFragment(mNodeInfoManager);
   return frag.forget();
 }
 
 NS_IMETHODIMP
 nsDocument::CreateComment(const nsAString& aData, nsIDOMComment** aReturn)
 {
-  *aReturn = nsIDocument::CreateComment(aData).get();
+  *aReturn = nsIDocument::CreateComment(aData).take();
   return NS_OK;
 }
 
 // Unfortunately, bareword "Comment" is ambiguous with some Mac system headers.
 already_AddRefed<dom::Comment>
 nsIDocument::CreateComment(const nsAString& aData) const
 {
   nsRefPtr<dom::Comment> comment = new dom::Comment(mNodeInfoManager);
@@ -5283,17 +5285,17 @@ nsIDocument::CreateComment(const nsAStri
 }
 
 NS_IMETHODIMP
 nsDocument::CreateCDATASection(const nsAString& aData,
                                nsIDOMCDATASection** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   ErrorResult rv;
-  *aReturn = nsIDocument::CreateCDATASection(aData, rv).get();
+  *aReturn = nsIDocument::CreateCDATASection(aData, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<CDATASection>
 nsIDocument::CreateCDATASection(const nsAString& aData,
                                 ErrorResult& rv)
 {
   if (IsHTML()) {
@@ -5315,17 +5317,18 @@ nsIDocument::CreateCDATASection(const ns
 }
 
 NS_IMETHODIMP
 nsDocument::CreateProcessingInstruction(const nsAString& aTarget,
                                         const nsAString& aData,
                                         nsIDOMProcessingInstruction** aReturn)
 {
   ErrorResult rv;
-  *aReturn = nsIDocument::CreateProcessingInstruction(aTarget, aData, rv).get();
+  *aReturn =
+    nsIDocument::CreateProcessingInstruction(aTarget, aData, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<ProcessingInstruction>
 nsIDocument::CreateProcessingInstruction(const nsAString& aTarget,
                                          const nsAString& aData,
                                          ErrorResult& rv) const
 {
@@ -5346,17 +5349,17 @@ nsIDocument::CreateProcessingInstruction
   return pi.forget();
 }
 
 NS_IMETHODIMP
 nsDocument::CreateAttribute(const nsAString& aName,
                             nsIDOMAttr** aReturn)
 {
   ErrorResult rv;
-  *aReturn = nsIDocument::CreateAttribute(aName, rv).get();
+  *aReturn = nsIDocument::CreateAttribute(aName, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<Attr>
 nsIDocument::CreateAttribute(const nsAString& aName, ErrorResult& rv)
 {
   WarnOnceAbout(eCreateAttribute);
 
@@ -5387,17 +5390,17 @@ nsIDocument::CreateAttribute(const nsASt
 
 NS_IMETHODIMP
 nsDocument::CreateAttributeNS(const nsAString & aNamespaceURI,
                               const nsAString & aQualifiedName,
                               nsIDOMAttr **aResult)
 {
   ErrorResult rv;
   *aResult =
-    nsIDocument::CreateAttributeNS(aNamespaceURI, aQualifiedName, rv).get();
+    nsIDocument::CreateAttributeNS(aNamespaceURI, aQualifiedName, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<Attr>
 nsIDocument::CreateAttributeNS(const nsAString& aNamespaceURI,
                                const nsAString& aQualifiedName,
                                ErrorResult& rv)
 {
@@ -5951,17 +5954,17 @@ nsDocument::RegisterElement(JSContext* a
 NS_IMETHODIMP
 nsDocument::GetElementsByTagName(const nsAString& aTagname,
                                  nsIDOMNodeList** aReturn)
 {
   nsRefPtr<nsContentList> list = GetElementsByTagName(aTagname);
   NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
 
   // transfer ref to aReturn
-  *aReturn = list.forget().get();
+  list.forget(aReturn);
   return NS_OK;
 }
 
 already_AddRefed<nsContentList>
 nsIDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
                                     const nsAString& aLocalName,
                                     ErrorResult& aResult)
 {
@@ -5989,17 +5992,17 @@ nsDocument::GetElementsByTagNameNS(const
   ErrorResult rv;
   nsRefPtr<nsContentList> list =
     nsIDocument::GetElementsByTagNameNS(aNamespaceURI, aLocalName, rv);
   if (rv.Failed()) {
     return rv.ErrorCode();
   }
 
   // transfer ref to aReturn
-  *aReturn = list.forget().get();
+  list.forget(aReturn);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocument::GetAsync(bool *aAsync)
 {
   NS_ERROR("nsDocument::GetAsync() should be overriden by subclass!");
 
@@ -6417,17 +6420,17 @@ nsIDocument::GetAnonymousNodes(Element& 
 {
   return BindingManager()->GetAnonymousNodesFor(&aElement);
 }
 
 NS_IMETHODIMP
 nsDocument::CreateRange(nsIDOMRange** aReturn)
 {
   ErrorResult rv;
-  *aReturn = nsIDocument::CreateRange(rv).get();
+  *aReturn = nsIDocument::CreateRange(rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<nsRange>
 nsIDocument::CreateRange(ErrorResult& rv)
 {
   nsRefPtr<nsRange> range = new nsRange(this);
   nsresult res = range->Set(this, 0, this, 0);
@@ -6457,17 +6460,17 @@ nsDocument::CreateNodeIterator(nsIDOMNod
   }
 
   nsCOMPtr<nsINode> root = do_QueryInterface(aRoot);
   NS_ENSURE_TRUE(root, NS_ERROR_UNEXPECTED);
 
   ErrorResult rv;
   NodeFilterHolder holder(aFilter);
   *_retval = nsIDocument::CreateNodeIterator(*root, aWhatToShow, holder,
-                                             rv).get();
+                                             rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<NodeIterator>
 nsIDocument::CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
                                 NodeFilter* aFilter,
                                 ErrorResult& rv) const
 {
@@ -6500,17 +6503,17 @@ nsDocument::CreateTreeWalker(nsIDOMNode 
   }
 
   nsCOMPtr<nsINode> root = do_QueryInterface(aRoot);
   NS_ENSURE_TRUE(root, NS_ERROR_DOM_NOT_SUPPORTED_ERR);
 
   ErrorResult rv;
   NodeFilterHolder holder(aFilter);
   *_retval = nsIDocument::CreateTreeWalker(*root, aWhatToShow, holder,
-                                           rv).get();
+                                           rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<TreeWalker>
 nsIDocument::CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
                               NodeFilter* aFilter,
                               ErrorResult& rv) const
 {
@@ -6536,17 +6539,17 @@ nsDocument::GetDefaultView(nsIDOMWindow*
   nsCOMPtr<nsPIDOMWindow> win = GetWindow();
   win.forget(aDefaultView);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocument::GetLocation(nsIDOMLocation **_retval)
 {
-  *_retval = nsIDocument::GetLocation().get();
+  *_retval = nsIDocument::GetLocation().take();
   return NS_OK;
 }
 
 already_AddRefed<nsIDOMLocation>
 nsIDocument::GetLocation() const
 {
   nsCOMPtr<nsIDOMWindow> w = do_QueryInterface(mScriptGlobalObject);
 
@@ -7647,17 +7650,17 @@ nsDocument::PreHandleEvent(nsEventChainP
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocument::CreateEvent(const nsAString& aEventType, nsIDOMEvent** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   ErrorResult rv;
-  *aReturn = nsIDocument::CreateEvent(aEventType, rv).get();
+  *aReturn = nsIDocument::CreateEvent(aEventType, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<Event>
 nsIDocument::CreateEvent(const nsAString& aEventType, ErrorResult& rv) const
 {
   nsIPresShell *shell = GetShell();
 
@@ -7669,17 +7672,17 @@ nsIDocument::CreateEvent(const nsAString
   }
 
   // Create event even without presContext.
   nsCOMPtr<nsIDOMEvent> ev;
   rv =
     nsEventDispatcher::CreateEvent(const_cast<nsIDocument*>(this),
                                    presContext, nullptr, aEventType,
                                    getter_AddRefs(ev));
-  return ev ? dont_AddRef(ev.forget().get()->InternalDOMEvent()) : nullptr;
+  return ev ? dont_AddRef(ev.forget().take()->InternalDOMEvent()) : nullptr;
 }
 
 void
 nsDocument::FlushPendingNotifications(mozFlushType aType)
 {
   nsDocumentOnStack dos(this);
 
   // We need to flush the sink for non-HTML documents (because the XML
@@ -10129,17 +10132,17 @@ nsIDocument::CaretPositionFromPoint(floa
   }
   return aCaretPos.forget();
 }
 
 NS_IMETHODIMP
 nsDocument::CaretPositionFromPoint(float aX, float aY, nsISupports** aCaretPos)
 {
   NS_ENSURE_ARG_POINTER(aCaretPos);
-  *aCaretPos = nsIDocument::CaretPositionFromPoint(aX, aY).get();
+  *aCaretPos = nsIDocument::CaretPositionFromPoint(aX, aY).take();
   return NS_OK;
 }
 
 void
 nsIDocument::ObsoleteSheet(nsIURI *aSheetURI, ErrorResult& rv)
 {
   nsresult res = CSSLoader()->ObsoleteSheet(aSheetURI);
   if (NS_FAILED(res)) {
@@ -10265,17 +10268,18 @@ FullscreenRoots::Contains(nsIDocument* a
 /* static */
 void
 FullscreenRoots::Add(nsIDocument* aRoot)
 {
   if (!FullscreenRoots::Contains(aRoot)) {
     if (!sInstance) {
       sInstance = new FullscreenRoots();
     }
-    sInstance->mRoots.AppendElement(do_GetWeakReference(aRoot));
+    nsWeakPtr weakRoot = do_GetWeakReference(aRoot);
+    sInstance->mRoots.AppendElement(weakRoot);
   }
 }
 
 /* static */
 uint32_t
 FullscreenRoots::Find(nsIDocument* aRoot)
 {
   if (!sInstance) {
@@ -10832,17 +10836,18 @@ nsDocument::FullScreenStackPush(Element*
   }
   if (top) {
     // We're pushing a new element onto the full-screen stack, so we must
     // remove the ancestor and full-screen styles from the former top of the
     // stack.
     nsEventStateManager::SetFullScreenState(top, false);
   }
   nsEventStateManager::SetFullScreenState(aElement, true);
-  mFullScreenStack.AppendElement(do_GetWeakReference(aElement));
+  nsWeakPtr weakElement = do_GetWeakReference(aElement);
+  mFullScreenStack.AppendElement(weakElement);
   NS_ASSERTION(GetFullScreenElement() == aElement, "Should match");
   return true;
 }
 
 void
 nsDocument::FullScreenStackPop()
 {
   if (mFullScreenStack.IsEmpty()) {
--- a/content/base/src/nsDocumentEncoder.cpp
+++ b/content/base/src/nsDocumentEncoder.cpp
@@ -1020,17 +1020,17 @@ nsDocumentEncoder::EncodeToString(nsAStr
   if (!mDocument)
     return NS_ERROR_NOT_INITIALIZED;
 
   aOutputString.Truncate();
 
   nsString output;
   static const size_t bufferSize = 2048;
   if (!mCachedBuffer) {
-    mCachedBuffer = nsStringBuffer::Alloc(bufferSize).get();
+    mCachedBuffer = nsStringBuffer::Alloc(bufferSize).take();
   }
   NS_ASSERTION(!mCachedBuffer->IsReadonly(),
                "DocumentEncoder shouldn't keep reference to non-readonly buffer!");
   static_cast<char16_t*>(mCachedBuffer->Data())[0] = char16_t(0);
   mCachedBuffer->ToString(0, output, true);
   // output owns the buffer now!
   mCachedBuffer = nullptr;
   
--- a/content/base/src/nsGenConImageContent.cpp
+++ b/content/base/src/nsGenConImageContent.cpp
@@ -17,17 +17,17 @@
 #include "nsEventStates.h"
 #include "nsEventDispatcher.h"
 #include "mozilla/BasicEvents.h"
 
 class nsGenConImageContent MOZ_FINAL : public nsXMLElement,
                                        public nsImageLoadingContent
 {
 public:
-  nsGenConImageContent(already_AddRefed<nsINodeInfo> aNodeInfo)
+  nsGenConImageContent(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsXMLElement(aNodeInfo)
   {
     // nsImageLoadingContent starts out broken, so we start out
     // suppressed to match it.
     AddStatesSilently(NS_EVENT_STATE_SUPPRESSED);
   }
 
   nsresult Init(imgRequestProxy* aImageRequest)
@@ -63,17 +63,17 @@ public:
 
 NS_IMPL_ISUPPORTS_INHERITED3(nsGenConImageContent,
                              nsXMLElement,
                              nsIImageLoadingContent,
                              imgINotificationObserver,
                              imgIOnloadBlocker)
 
 nsresult
-NS_NewGenConImageContent(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewGenConImageContent(nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo,
                          imgRequestProxy* aImageRequest)
 {
   NS_PRECONDITION(aImageRequest, "Must have request!");
   nsGenConImageContent *it = new nsGenConImageContent(aNodeInfo);
   if (!it)
     return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(*aResult = it);
   nsresult rv = it->Init(aImageRequest);
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -37,17 +37,29 @@
 
 #include "pldhash.h"
 #include "prprf.h"
 #include "nsWrapperCacheInlines.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
-nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<nsINodeInfo> aNodeInfo)
+nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<nsINodeInfo>& aNodeInfo)
+  : nsIContent(aNodeInfo)
+{
+  NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE ||
+                    mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE ||
+                    mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE ||
+                    mNodeInfo->NodeType() ==
+                      nsIDOMNode::PROCESSING_INSTRUCTION_NODE ||
+                    mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE,
+                    "Bad NodeType in aNodeInfo");
+}
+
+nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<nsINodeInfo>&& aNodeInfo)
   : nsIContent(aNodeInfo)
 {
   NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE ||
                     mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE ||
                     mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE ||
                     mNodeInfo->NodeType() ==
                       nsIDOMNode::PROCESSING_INSTRUCTION_NODE ||
                     mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE,
--- a/content/base/src/nsGenericDOMDataNode.h
+++ b/content/base/src/nsGenericDOMDataNode.h
@@ -65,17 +65,18 @@ ASSERT_NODE_FLAGS_SPACE(NODE_TYPE_SPECIF
 
 class nsGenericDOMDataNode : public nsIContent
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
   NS_DECL_SIZEOF_EXCLUDING_THIS
 
-  nsGenericDOMDataNode(already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsGenericDOMDataNode(already_AddRefed<nsINodeInfo>& aNodeInfo);
+  nsGenericDOMDataNode(already_AddRefed<nsINodeInfo>&& aNodeInfo);
   virtual ~nsGenericDOMDataNode();
 
   virtual void GetNodeValueInternal(nsAString& aNodeValue) MOZ_OVERRIDE;
   virtual void SetNodeValueInternal(const nsAString& aNodeValue,
                                     mozilla::ErrorResult& aError) MOZ_OVERRIDE;
 
   // Implementation for nsIDOMCharacterData
   nsresult GetData(nsAString& aData) const;
--- a/content/base/src/nsHostObjectURI.cpp
+++ b/content/base/src/nsHostObjectURI.cpp
@@ -57,17 +57,22 @@ nsHostObjectURI::GetPrincipalUri(nsIURI*
 // nsISerializable methods:
 
 NS_IMETHODIMP
 nsHostObjectURI::Read(nsIObjectInputStream* aStream)
 {
   nsresult rv = nsSimpleURI::Read(aStream);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return NS_ReadOptionalObject(aStream, true, getter_AddRefs(mPrincipal));
+  nsCOMPtr<nsISupports> supports;
+  rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  mPrincipal = do_QueryInterface(supports, &rv);
+  return rv;
 }
 
 NS_IMETHODIMP
 nsHostObjectURI::Write(nsIObjectOutputStream* aStream)
 {
   nsresult rv = nsSimpleURI::Write(aStream);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -2187,17 +2187,17 @@ nsINode::GetBoundMutationObservers(nsTAr
 {
   nsCOMArray<nsISupports>* objects =
     static_cast<nsCOMArray<nsISupports>*>(GetProperty(nsGkAtoms::keepobjectsalive));
   if (objects) {
     for (int32_t i = 0; i < objects->Count(); ++i) {
       nsCOMPtr<nsDOMMutationObserver> mo = do_QueryInterface(objects->ObjectAt(i));
       if (mo) {
         MOZ_ASSERT(!aResult.Contains(mo));
-        aResult.AppendElement(mo.forget());
+        aResult.AppendElement(mo);
       }
     }
   }
 }
 
 size_t
 nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
@@ -2540,17 +2540,17 @@ nsINode::QuerySelector(const nsAString& 
   elt.forget(aReturn);
   return NS_OK;
 }
 
 nsresult
 nsINode::QuerySelectorAll(const nsAString& aSelector, nsIDOMNodeList **aReturn)
 {
   ErrorResult rv;
-  *aReturn = nsINode::QuerySelectorAll(aSelector, rv).get();
+  *aReturn = nsINode::QuerySelectorAll(aSelector, rv).take();
   return rv.ErrorCode();
 }
 
 Element*
 nsINode::GetElementById(const nsAString& aId)
 {
   MOZ_ASSERT(IsElement() || IsNodeOfType(eDOCUMENT_FRAGMENT),
              "Bogus this object for GetElementById call");
--- a/content/base/src/nsImageLoadingContent.cpp
+++ b/content/base/src/nsImageLoadingContent.cpp
@@ -420,17 +420,17 @@ nsImageLoadingContent::GetRequest(int32_
 
 NS_IMETHODIMP
 nsImageLoadingContent::GetRequest(int32_t aRequestType,
                                   imgIRequest** aRequest)
 {
   NS_ENSURE_ARG_POINTER(aRequest);
 
   ErrorResult result;
-  *aRequest = GetRequest(aRequestType, result).get();
+  *aRequest = GetRequest(aRequestType, result).take();
 
   return result.ErrorCode();
 }
 
 NS_IMETHODIMP_(void)
 nsImageLoadingContent::FrameCreated(nsIFrame* aFrame)
 {
   NS_ASSERTION(aFrame, "aFrame is null");
@@ -534,17 +534,17 @@ nsImageLoadingContent::GetCurrentURI(Err
 }
 
 NS_IMETHODIMP
 nsImageLoadingContent::GetCurrentURI(nsIURI** aURI)
 {
   NS_ENSURE_ARG_POINTER(aURI);
 
   ErrorResult result;
-  *aURI = GetCurrentURI(result).get();
+  *aURI = GetCurrentURI(result).take();
   return result.ErrorCode();
 }
 
 already_AddRefed<nsIStreamListener>
 nsImageLoadingContent::LoadImageWithChannel(nsIChannel* aChannel,
                                             ErrorResult& aError)
 {
   if (!nsContentUtils::GetImgLoaderForChannel(aChannel)) {
@@ -589,17 +589,17 @@ nsImageLoadingContent::LoadImageWithChan
 
 NS_IMETHODIMP
 nsImageLoadingContent::LoadImageWithChannel(nsIChannel* aChannel,
                                             nsIStreamListener** aListener)
 {
   NS_ENSURE_ARG_POINTER(aListener);
 
   ErrorResult result;
-  *aListener = LoadImageWithChannel(aChannel, result).get();
+  *aListener = LoadImageWithChannel(aChannel, result).take();
   return result.ErrorCode();
 }
 
 void
 nsImageLoadingContent::ForceReload(ErrorResult& aError)
 {
   nsCOMPtr<nsIURI> currentURI;
   GetCurrentURI(getter_AddRefs(currentURI));
--- a/content/base/src/nsMappedAttributeElement.h
+++ b/content/base/src/nsMappedAttributeElement.h
@@ -23,17 +23,17 @@ typedef void (*nsMapRuleToAttributesFunc
 
 typedef nsStyledElement nsMappedAttributeElementBase;
 
 class nsMappedAttributeElement : public nsMappedAttributeElementBase
 {
 
 protected:
 
-  nsMappedAttributeElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  nsMappedAttributeElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsMappedAttributeElementBase(aNodeInfo)
   {}
 
 public:
   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
 
   static void MapNoAttributesInto(const nsMappedAttributes* aAttributes, 
                                   nsRuleData* aRuleData);
--- a/content/base/src/nsNameSpaceManager.cpp
+++ b/content/base/src/nsNameSpaceManager.cpp
@@ -132,39 +132,41 @@ nsNameSpaceManager::GetNameSpaceID(const
     return nameSpaceID;
   }
 
   return kNameSpaceID_Unknown;
 }
 
 nsresult
 NS_NewElement(Element** aResult,
-              already_AddRefed<nsINodeInfo> aNodeInfo, FromParser aFromParser)
+              already_AddRefed<nsINodeInfo>&& aNodeInfo,
+              FromParser aFromParser)
 {
-  int32_t ns = aNodeInfo.get()->NamespaceID();
+  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
+  int32_t ns = ni->NamespaceID();
   if (ns == kNameSpaceID_XHTML) {
-    return NS_NewHTMLElement(aResult, aNodeInfo, aFromParser);
+    return NS_NewHTMLElement(aResult, ni.forget(), aFromParser);
   }
 #ifdef MOZ_XUL
   if (ns == kNameSpaceID_XUL) {
-    return NS_NewXULElement(aResult, aNodeInfo);
+    return NS_NewXULElement(aResult, ni.forget());
   }
 #endif
   if (ns == kNameSpaceID_MathML) {
-    return NS_NewMathMLElement(aResult, aNodeInfo);
+    return NS_NewMathMLElement(aResult, ni.forget());
   }
   if (ns == kNameSpaceID_SVG) {
-    return NS_NewSVGElement(aResult, aNodeInfo, aFromParser);
+    return NS_NewSVGElement(aResult, ni.forget(), aFromParser);
   }
-  if (ns == kNameSpaceID_XBL && aNodeInfo.get()->Equals(nsGkAtoms::children)) {
-    NS_ADDREF(*aResult = new XBLChildrenElement(aNodeInfo));
+  if (ns == kNameSpaceID_XBL && ni->Equals(nsGkAtoms::children)) {
+    NS_ADDREF(*aResult = new XBLChildrenElement(ni.forget()));
     return NS_OK;
   }
 
-  return NS_NewXMLElement(aResult, aNodeInfo);
+  return NS_NewXMLElement(aResult, ni.forget());
 }
 
 bool
 nsNameSpaceManager::HasElementCreator(int32_t aNameSpaceID)
 {
   return aNameSpaceID == kNameSpaceID_XHTML ||
 #ifdef MOZ_XUL
          aNameSpaceID == kNameSpaceID_XUL ||
--- a/content/base/src/nsRange.cpp
+++ b/content/base/src/nsRange.cpp
@@ -2172,17 +2172,17 @@ nsRange::CloneParentsBetween(nsINode *aA
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsRange::CloneContents(nsIDOMDocumentFragment** aReturn)
 {
   ErrorResult rv;
-  *aReturn = CloneContents(rv).get();
+  *aReturn = CloneContents(rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<DocumentFragment>
 nsRange::CloneContents(ErrorResult& aRv)
 {
   nsCOMPtr<nsINode> commonAncestor = GetCommonAncestorContainer(aRv);
   MOZ_ASSERT(!aRv.Failed(), "GetCommonAncestorContainer() shouldn't fail!");
@@ -2395,17 +2395,17 @@ nsRange::CloneRange() const
   range->DoSetRange(mStartParent, mStartOffset, mEndParent, mEndOffset, mRoot);
 
   return range.forget();
 }
 
 NS_IMETHODIMP
 nsRange::CloneRange(nsIDOMRange** aReturn)
 {
-  *aReturn = CloneRange().get();
+  *aReturn = CloneRange().take();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsRange::InsertNode(nsIDOMNode* aNode)
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   if (!node) {
@@ -2872,17 +2872,17 @@ static void CollectClientRects(nsLayoutU
         nsLayoutUtils::GetContainingBlockForClientRect(frame), aCollector);
     }
   } while (!iter.IsDone());
 }
 
 NS_IMETHODIMP
 nsRange::GetBoundingClientRect(nsIDOMClientRect** aResult)
 {
-  *aResult = GetBoundingClientRect().get();
+  *aResult = GetBoundingClientRect().take();
   return NS_OK;
 }
 
 already_AddRefed<DOMRect>
 nsRange::GetBoundingClientRect()
 {
   nsRefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
   if (!mStartParent) {
@@ -2897,17 +2897,17 @@ nsRange::GetBoundingClientRect()
     accumulator.mResultRect;
   rect->SetLayoutRect(r);
   return rect.forget();
 }
 
 NS_IMETHODIMP
 nsRange::GetClientRects(nsIDOMClientRectList** aResult)
 {
-  *aResult = GetClientRects().get();
+  *aResult = GetClientRects().take();
   return NS_OK;
 }
 
 already_AddRefed<DOMRectList>
 nsRange::GetClientRects()
 {
   if (!mStartParent) {
     return nullptr;
--- a/content/base/src/nsStyledElement.h
+++ b/content/base/src/nsStyledElement.h
@@ -25,17 +25,17 @@ class StyleRule;
 
 typedef mozilla::dom::Element nsStyledElementBase;
 
 class nsStyledElementNotElementCSSInlineStyle : public nsStyledElementBase
 {
 
 protected:
 
-  inline nsStyledElementNotElementCSSInlineStyle(already_AddRefed<nsINodeInfo> aNodeInfo)
+  inline nsStyledElementNotElementCSSInlineStyle(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsStyledElementBase(aNodeInfo)
   {}
 
 public:
   // nsIContent interface methods
   virtual nsIAtom* GetClassAttributeName() const MOZ_OVERRIDE;
   virtual nsIAtom* GetIDAttributeName() const MOZ_OVERRIDE;
   virtual nsIAtom* DoGetID() const MOZ_OVERRIDE;
@@ -77,14 +77,14 @@ protected:
    * string.  If aForceInDataDoc is true, will reparse even if we're in a data
    * document.
    */
   nsresult  ReparseStyleAttribute(bool aForceInDataDoc);
 };
 
 class nsStyledElement : public nsStyledElementNotElementCSSInlineStyle {
 protected:
-  inline nsStyledElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  inline nsStyledElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsStyledElementNotElementCSSInlineStyle(aNodeInfo)
   {}
 };
 
 #endif // __NS_STYLEDELEMENT_H_
--- a/content/base/src/nsTextNode.cpp
+++ b/content/base/src/nsTextNode.cpp
@@ -27,17 +27,17 @@ using namespace mozilla::dom;
  * class used to implement attr() generated content
  */
 class nsAttributeTextNode MOZ_FINAL : public nsTextNode,
                                       public nsStubMutationObserver
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   
-  nsAttributeTextNode(already_AddRefed<nsINodeInfo> aNodeInfo,
+  nsAttributeTextNode(already_AddRefed<nsINodeInfo>& aNodeInfo,
                       int32_t aNameSpaceID,
                       nsIAtom* aAttrName) :
     nsTextNode(aNodeInfo),
     mGrandparent(nullptr),
     mNameSpaceID(aNameSpaceID),
     mAttrName(aAttrName)
   {
     NS_ASSERTION(mNameSpaceID != kNameSpaceID_Unknown, "Must know namespace");
@@ -55,18 +55,19 @@ public:
                               bool aNullParent = true);
 
   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
   NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
 
   virtual nsGenericDOMDataNode *CloneDataNode(nsINodeInfo *aNodeInfo,
                                               bool aCloneText) const
   {
-    nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-    nsAttributeTextNode *it = new nsAttributeTextNode(ni.forget(),
+    already_AddRefed<nsINodeInfo> ni =
+      nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
+    nsAttributeTextNode *it = new nsAttributeTextNode(ni,
                                                       mNameSpaceID,
                                                       mAttrName);
     if (it && aCloneText) {
       it->mText = mText;
     }
 
     return it;
   }
@@ -107,19 +108,19 @@ bool
 nsTextNode::IsNodeOfType(uint32_t aFlags) const
 {
   return !(aFlags & ~(eCONTENT | eTEXT | eDATA_NODE));
 }
 
 nsGenericDOMDataNode*
 nsTextNode::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const
 {
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-  nsTextNode *it = new nsTextNode(ni.forget());
-  if (it && aCloneText) {
+  already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
+  nsTextNode *it = new nsTextNode(ni);
+  if (aCloneText) {
     it->mText = mText;
   }
 
   return it;
 }
 
 nsresult
 nsTextNode::AppendTextForNormalize(const char16_t* aBuffer, uint32_t aLength,
@@ -201,22 +202,19 @@ NS_NewAttributeContent(nsNodeInfoManager
                        nsIContent** aResult)
 {
   NS_PRECONDITION(aNodeInfoManager, "Missing nodeInfoManager");
   NS_PRECONDITION(aAttrName, "Must have an attr name");
   NS_PRECONDITION(aNameSpaceID != kNameSpaceID_Unknown, "Must know namespace");
   
   *aResult = nullptr;
 
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfoManager->GetTextNodeInfo();
-  if (!ni) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  already_AddRefed<nsINodeInfo> ni = aNodeInfoManager->GetTextNodeInfo();
 
-  nsAttributeTextNode* textNode = new nsAttributeTextNode(ni.forget(),
+  nsAttributeTextNode* textNode = new nsAttributeTextNode(ni,
                                                           aNameSpaceID,
                                                           aAttrName);
   if (!textNode) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   NS_ADDREF(*aResult = textNode);
 
--- a/content/base/src/nsTextNode.h
+++ b/content/base/src/nsTextNode.h
@@ -26,17 +26,17 @@ class nsTextNode : public mozilla::dom::
 private:
   void Init()
   {
     NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE,
                       "Bad NodeType in aNodeInfo");
   }
 
 public:
-  nsTextNode(already_AddRefed<nsINodeInfo> aNodeInfo)
+  nsTextNode(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : mozilla::dom::Text(aNodeInfo)
   {
     Init();
   }
 
   nsTextNode(nsNodeInfoManager* aNodeInfoManager)
     : mozilla::dom::Text(aNodeInfoManager->GetTextNodeInfo())
   {
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -3511,21 +3511,21 @@ nsXMLHttpRequest::GetInterface(const nsI
   nsresult rv;
 
   // Make sure to return ourselves for the channel event sink interface and
   // progress event sink interface, no matter what.  We can forward these to
   // mNotificationCallbacks if it wants to get notifications for them.  But we
   // need to see these notifications for proper functioning.
   if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {
     mChannelEventSink = do_GetInterface(mNotificationCallbacks);
-    *aResult = static_cast<nsIChannelEventSink*>(EnsureXPCOMifier().get());
+    *aResult = static_cast<nsIChannelEventSink*>(EnsureXPCOMifier().take());
     return NS_OK;
   } else if (aIID.Equals(NS_GET_IID(nsIProgressEventSink))) {
     mProgressEventSink = do_GetInterface(mNotificationCallbacks);
-    *aResult = static_cast<nsIProgressEventSink*>(EnsureXPCOMifier().get());
+    *aResult = static_cast<nsIProgressEventSink*>(EnsureXPCOMifier().take());
     return NS_OK;
   }
 
   // Now give mNotificationCallbacks (if non-null) a chance to return the
   // desired interface.
   if (mNotificationCallbacks) {
     rv = mNotificationCallbacks->GetInterface(aIID, aResult);
     if (NS_SUCCEEDED(rv)) {
@@ -3614,25 +3614,25 @@ nsXMLHttpRequest::GetInterface(const nsI
 
     return wwatch->GetPrompt(window, aIID,
                              reinterpret_cast<void**>(aResult));
   }
   // Now check for the various XHR non-DOM interfaces, except
   // nsIProgressEventSink and nsIChannelEventSink which we already
   // handled above.
   else if (aIID.Equals(NS_GET_IID(nsIStreamListener))) {
-    *aResult = static_cast<nsIStreamListener*>(EnsureXPCOMifier().get());
+    *aResult = static_cast<nsIStreamListener*>(EnsureXPCOMifier().take());
     return NS_OK;
   }
   else if (aIID.Equals(NS_GET_IID(nsIRequestObserver))) {
-    *aResult = static_cast<nsIRequestObserver*>(EnsureXPCOMifier().get());
+    *aResult = static_cast<nsIRequestObserver*>(EnsureXPCOMifier().take());
     return NS_OK;
   }
   else if (aIID.Equals(NS_GET_IID(nsITimerCallback))) {
-    *aResult = static_cast<nsITimerCallback*>(EnsureXPCOMifier().get());
+    *aResult = static_cast<nsITimerCallback*>(EnsureXPCOMifier().take());
     return NS_OK;
   }
 
   return QueryInterface(aIID, aResult);
 }
 
 JS::Value
 nsXMLHttpRequest::GetInterface(JSContext* aCx, nsIJSID* aIID, ErrorResult& aRv)
--- a/content/canvas/test/webgl/non-conf-tests/test_no_arr_points.html
+++ b/content/canvas/test/webgl/non-conf-tests/test_no_arr_points.html
@@ -119,17 +119,18 @@ void main(void) {
     var checkGLTestFunc = todo;
     if (DriverInfo.getDriver() == DriverInfo.DRIVER.ANGLE ||
         DriverInfo.getOS() == DriverInfo.OS.ANDROID)
     {
       // ANGLE and Android slaves seem to work fine.
       elemTestFunc = ok;
       checkGLTestFunc = ok;
     }
-    if (DriverInfo.getDriver() == DriverInfo.DRIVER.ANDROID_X86_EMULATOR)
+    if (DriverInfo.getDriver() == DriverInfo.DRIVER.ANDROID_X86_EMULATOR ||
+        DriverInfo.getOS() == DriverInfo.OS.B2G)
     {
       // ...but the Android 4.2 x86 emulator environment is different
       elemTestFunc = todo;
       checkGLTestFunc = ok;
     }
 
     // Now for drawElements:
     gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
--- a/content/canvas/test/webgl/non-conf-tests/test_webgl_available.html
+++ b/content/canvas/test/webgl/non-conf-tests/test_webgl_available.html
@@ -22,22 +22,16 @@ function test() {
       DriverInfo.getOSVersion() < 15)
   {
     // Consider 'random'. Actually, ARMv6 fails, and ARMv7 succeeds, but we have
     // not been successful at determining this from JS. (see bug 917478)
     shouldSucceed = false;
     shouldFail = false;
   }
 
-  if (DriverInfo.getOS() == DriverInfo.OS.B2G) {
-    // We don't run these mochitests on hardware with WebGL-capable hardware yet.
-    shouldSucceed = false;
-    shouldFail = true;
-  }
-
   var gl = WebGLUtil.getWebGL('c');
   if (shouldSucceed) {
     ok(gl, 'Expected WebGL creation to succeed.');
   }
   if (shouldFail) {
     ok(!gl, 'Expected WebGL creation to fail.');
   }
 
--- a/content/canvas/test/webgl/non-conf-tests/test_webgl_request_context.html
+++ b/content/canvas/test/webgl/non-conf-tests/test_webgl_request_context.html
@@ -6,19 +6,16 @@
 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
 <script src="driver-info.js"></script>
 <body>
 <canvas id="c1"></canvas>
 <canvas id="c2"></canvas>
 <script>
 
 var testFunc = ok;
-if (DriverInfo.getOS() == DriverInfo.OS.B2G) {
-  testFunc = todo;
-}
 
 function testContextRetrieval(canvasId, creationId, shouldSucceed) {
   var canvas = document.getElementById(canvasId);
   ok(canvas, 'Invalid `canvasId`: ' + canvasId);
 
   var createdGL = canvas.getContext(creationId);
   if (shouldSucceed) {
     testFunc(createdGL, 'Request for \'' + creationId + '\' should succeed.');
--- a/content/html/content/public/HTMLAudioElement.h
+++ b/content/html/content/public/HTMLAudioElement.h
@@ -19,17 +19,17 @@ typedef uint16_t nsMediaReadyState;
 namespace mozilla {
 namespace dom {
 
 class HTMLAudioElement MOZ_FINAL : public HTMLMediaElement,
                                    public nsITimerCallback,
                                    public nsIDOMHTMLAudioElement
 {
 public:
-  HTMLAudioElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLAudioElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLAudioElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLMediaElement
   using HTMLMediaElement::GetPaused;
   NS_FORWARD_NSIDOMHTMLMEDIAELEMENT(HTMLMediaElement::)
--- a/content/html/content/public/HTMLCanvasElement.h
+++ b/content/html/content/public/HTMLCanvasElement.h
@@ -41,17 +41,17 @@ class HTMLCanvasElement MOZ_FINAL : publ
     DEFAULT_CANVAS_WIDTH = 300,
     DEFAULT_CANVAS_HEIGHT = 150
   };
 
   typedef layers::CanvasLayer CanvasLayer;
   typedef layers::LayerManager LayerManager;
 
 public:
-  HTMLCanvasElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLCanvasElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLCanvasElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLCanvasElement, canvas)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLCanvasElement
--- a/content/html/content/public/HTMLMediaElement.h
+++ b/content/html/content/public/HTMLMediaElement.h
@@ -67,17 +67,17 @@ public:
   typedef mozilla::MediaResource MediaResource;
   typedef mozilla::MediaDecoderOwner MediaDecoderOwner;
   typedef mozilla::MetadataTags MetadataTags;
 
   CORSMode GetCORSMode() {
     return mCORSMode;
   }
 
-  HTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLMediaElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLMediaElement();
 
   /**
    * This is used when the browser is constructing a video element to play
    * a channel that we've already started loading. The src attribute and
    * <source> children are ignored.
    * @param aChannel the channel to use
    * @param aListener returns a stream listener that should receive
--- a/content/html/content/public/HTMLVideoElement.h
+++ b/content/html/content/public/HTMLVideoElement.h
@@ -16,17 +16,17 @@ namespace dom {
 
 class WakeLock;
 class VideoPlaybackQuality;
 
 class HTMLVideoElement MOZ_FINAL : public HTMLMediaElement,
                                    public nsIDOMHTMLVideoElement
 {
 public:
-  HTMLVideoElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLVideoElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLVideoElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLVideoElement, video)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLMediaElement
--- a/content/html/content/public/nsIHTMLCollection.h
+++ b/content/html/content/public/nsIHTMLCollection.h
@@ -2,22 +2,22 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsIHTMLCollection_h___
 #define nsIHTMLCollection_h___
 
 #include "nsIDOMHTMLCollection.h"
+#include "nsTArrayForwardDeclare.h"
 #include "nsWrapperCache.h"
 #include "js/TypeDecls.h"
 
 class nsINode;
 class nsString;
-template<class> class nsTArray;
 
 namespace mozilla {
 class ErrorResult;
 
 namespace dom {
 class Element;
 } // namespace dom
 } // namespace mozilla
--- a/content/html/content/src/HTMLAnchorElement.h
+++ b/content/html/content/src/HTMLAnchorElement.h
@@ -19,17 +19,17 @@ namespace dom {
 class HTMLAnchorElement MOZ_FINAL : public nsGenericHTMLElement,
                                     public nsIDOMHTMLAnchorElement,
                                     public Link
 {
 public:
   using Element::GetText;
   using Element::SetText;
 
-  HTMLAnchorElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLAnchorElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
     , Link(MOZ_THIS_IN_INITIALIZER_LIST())
   {
   }
   virtual ~HTMLAnchorElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
--- a/content/html/content/src/HTMLAreaElement.cpp
+++ b/content/html/content/src/HTMLAreaElement.cpp
@@ -10,17 +10,17 @@
 #include "mozilla/dom/HTMLAreaElementBinding.h"
 #include "mozilla/MemoryReporting.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Area)
 
 namespace mozilla {
 namespace dom {
 
-HTMLAreaElement::HTMLAreaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLAreaElement::HTMLAreaElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
   , Link(MOZ_THIS_IN_INITIALIZER_LIST())
 {
 }
 
 HTMLAreaElement::~HTMLAreaElement()
 {
 }
--- a/content/html/content/src/HTMLAreaElement.h
+++ b/content/html/content/src/HTMLAreaElement.h
@@ -20,17 +20,17 @@ class nsIDocument;
 namespace mozilla {
 namespace dom {
 
 class HTMLAreaElement MOZ_FINAL : public nsGenericHTMLElement,
                                   public nsIDOMHTMLAreaElement,
                                   public Link
 {
 public:
-  HTMLAreaElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLAreaElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLAreaElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // CC
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLAreaElement,
                                            nsGenericHTMLElement)
--- a/content/html/content/src/HTMLAudioElement.cpp
+++ b/content/html/content/src/HTMLAudioElement.cpp
@@ -31,17 +31,17 @@ extern bool IsAudioAPIEnabled();
 
 NS_IMPL_ISUPPORTS_INHERITED4(HTMLAudioElement, HTMLMediaElement,
                              nsIDOMHTMLMediaElement, nsIDOMHTMLAudioElement,
                              nsITimerCallback, nsIAudioChannelAgentCallback)
 
 NS_IMPL_ELEMENT_CLONE(HTMLAudioElement)
 
 
-HTMLAudioElement::HTMLAudioElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLAudioElement::HTMLAudioElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : HTMLMediaElement(aNodeInfo),
     mTimerActivated(false)
 {
 }
 
 HTMLAudioElement::~HTMLAudioElement()
 {
 }
@@ -54,22 +54,22 @@ HTMLAudioElement::Audio(const GlobalObje
 {
   nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
   nsIDocument* doc;
   if (!win || !(doc = win->GetExtantDoc())) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsCOMPtr<nsINodeInfo> nodeInfo =
+  already_AddRefed<nsINodeInfo> nodeInfo =
     doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nullptr,
                                         kNameSpaceID_XHTML,
                                         nsIDOMNode::ELEMENT_NODE);
 
-  nsRefPtr<HTMLAudioElement> audio = new HTMLAudioElement(nodeInfo.forget());
+  nsRefPtr<HTMLAudioElement> audio = new HTMLAudioElement(nodeInfo);
   audio->SetHTMLAttr(nsGkAtoms::preload, NS_LITERAL_STRING("auto"), aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   if (aSrc.WasPassed()) {
     aRv = audio->SetSrc(aSrc.Value());
   }
--- a/content/html/content/src/HTMLBRElement.cpp
+++ b/content/html/content/src/HTMLBRElement.cpp
@@ -12,17 +12,17 @@
 #include "nsRuleData.h"
 
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(BR)
 
 namespace mozilla {
 namespace dom {
 
-HTMLBRElement::HTMLBRElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLBRElement::HTMLBRElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLBRElement::~HTMLBRElement()
 {
 }
 
--- a/content/html/content/src/HTMLBRElement.h
+++ b/content/html/content/src/HTMLBRElement.h
@@ -13,17 +13,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLBRElement MOZ_FINAL : public nsGenericHTMLElement,
                                 public nsIDOMHTMLBRElement
 {
 public:
-  HTMLBRElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLBRElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLBRElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLBRElement
   NS_DECL_NSIDOMHTMLBRELEMENT
 
--- a/content/html/content/src/HTMLBodyElement.h
+++ b/content/html/content/src/HTMLBodyElement.h
@@ -35,17 +35,17 @@ public:
 
 class HTMLBodyElement MOZ_FINAL : public nsGenericHTMLElement,
                                   public nsIDOMHTMLBodyElement
 {
 public:
   using Element::GetText;
   using Element::SetText;
 
-  HTMLBodyElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLBodyElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLBodyElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLButtonElement.cpp
+++ b/content/html/content/src/HTMLButtonElement.cpp
@@ -49,17 +49,17 @@ static const nsAttrValue::EnumTable kBut
   { 0 }
 };
 
 // Default type is 'submit'.
 static const nsAttrValue::EnumTable* kButtonDefaultType = &kButtonTypeTable[2];
 
 
 // Construction, destruction
-HTMLButtonElement::HTMLButtonElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLButtonElement::HTMLButtonElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                      FromParser aFromParser)
   : nsGenericHTMLFormElementWithState(aNodeInfo),
     mType(kButtonDefaultType->value),
     mDisabledChanged(false),
     mInInternalActivate(false),
     mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT))
 {
   // <button> is always barred from constraint validation.
--- a/content/html/content/src/HTMLButtonElement.h
+++ b/content/html/content/src/HTMLButtonElement.h
@@ -16,17 +16,17 @@ namespace dom {
 
 class HTMLButtonElement MOZ_FINAL : public nsGenericHTMLFormElementWithState,
                                     public nsIDOMHTMLButtonElement,
                                     public nsIConstraintValidation
 {
 public:
   using nsIConstraintValidation::GetValidationMessage;
 
-  HTMLButtonElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLButtonElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                       FromParser aFromParser = NOT_FROM_PARSER);
   virtual ~HTMLButtonElement();
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLButtonElement,
                                            nsGenericHTMLFormElementWithState)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
--- a/content/html/content/src/HTMLCanvasElement.cpp
+++ b/content/html/content/src/HTMLCanvasElement.cpp
@@ -108,17 +108,17 @@ HTMLCanvasPrintState::NotifyDone()
   mPendingNotify = false;
   if (mCallback) {
     mCallback->Notify(nullptr);
   }
 }
 
 // ---------------------------------------------------------------------------
 
-HTMLCanvasElement::HTMLCanvasElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLCanvasElement::HTMLCanvasElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo),
     mWriteOnly(false)
 {
 }
 
 HTMLCanvasElement::~HTMLCanvasElement()
 {
   ResetPrintCallback();
@@ -668,17 +668,18 @@ HTMLCanvasElement::GetContextHelper(cons
   return NS_OK;
 }
 
 nsresult
 HTMLCanvasElement::GetContext(const nsAString& aContextId,
                               nsISupports** aContext)
 {
   ErrorResult rv;
-  *aContext = GetContext(nullptr, aContextId, JS::NullHandleValue, rv).get();
+  *aContext =
+    GetContext(nullptr, aContextId, JS::NullHandleValue, rv).take();
   return rv.ErrorCode();
 }
 
 static bool
 IsContextIdWebGL(const nsAString& str)
 {
   return str.EqualsLiteral("webgl") ||
          str.EqualsLiteral("experimental-webgl");
--- a/content/html/content/src/HTMLContentElement.cpp
+++ b/content/html/content/src/HTMLContentElement.cpp
@@ -16,17 +16,17 @@
 #include "nsRuleProcessorData.h"
 #include "nsRuleWalker.h"
 #include "nsCSSParser.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Content)
 
 using namespace mozilla::dom;
 
-HTMLContentElement::HTMLContentElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLContentElement::HTMLContentElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo), mValidSelector(true), mIsInsertionPoint(false)
 {
   SetIsDOMBinding();
 }
 
 HTMLContentElement::~HTMLContentElement()
 {
 }
--- a/content/html/content/src/HTMLContentElement.h
+++ b/content/html/content/src/HTMLContentElement.h
@@ -14,17 +14,17 @@ class nsCSSSelectorList;
 namespace mozilla {
 namespace dom {
 
 class DistributedContentList;
 
 class HTMLContentElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLContentElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLContentElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLContentElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLContentElement,
                                            nsGenericHTMLElement)
 
--- a/content/html/content/src/HTMLDataElement.cpp
+++ b/content/html/content/src/HTMLDataElement.cpp
@@ -7,17 +7,17 @@
 #include "mozilla/dom/HTMLDataElementBinding.h"
 #include "nsGenericHTMLElement.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Data)
 
 namespace mozilla {
 namespace dom {
 
-HTMLDataElement::HTMLDataElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLDataElement::HTMLDataElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLDataElement::~HTMLDataElement()
 {
 }
 
--- a/content/html/content/src/HTMLDataElement.h
+++ b/content/html/content/src/HTMLDataElement.h
@@ -12,17 +12,17 @@
 #include "nsGkAtoms.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLDataElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLDataElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLDataElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLDataElement();
 
   // HTMLDataElement WebIDL
   void GetValue(nsAString& aValue)
   {
     GetHTMLAttr(nsGkAtoms::value, aValue);
   }
 
--- a/content/html/content/src/HTMLDataListElement.h
+++ b/content/html/content/src/HTMLDataListElement.h
@@ -10,17 +10,17 @@
 #include "nsContentList.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLDataListElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLDataListElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLDataListElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLDataListElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLDivElement.h
+++ b/content/html/content/src/HTMLDivElement.h
@@ -11,17 +11,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLDivElement MOZ_FINAL : public nsGenericHTMLElement,
                                  public nsIDOMHTMLDivElement
 {
 public:
-  HTMLDivElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLDivElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLDivElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLElement.cpp
+++ b/content/html/content/src/HTMLElement.cpp
@@ -8,30 +8,30 @@
 #include "nsContentUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLElement();
 
   NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) MOZ_OVERRIDE;
 
   virtual nsresult Clone(nsINodeInfo* aNodeInfo,
                          nsINode** aResult) const MOZ_OVERRIDE;
 
 protected:
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 };
 
-HTMLElement::HTMLElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLElement::HTMLElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLElement::~HTMLElement()
 {
 }
 
@@ -63,13 +63,13 @@ HTMLElement::WrapNode(JSContext *aCx, JS
 }
 
 } // namespace dom
 } // namespace mozilla
 
 // Here, we expand 'NS_IMPL_NS_NEW_HTML_ELEMENT()' by hand.
 // (Calling the macro directly (with no args) produces compiler warnings.)
 nsGenericHTMLElement*
-NS_NewHTMLElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLElement(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                   mozilla::dom::FromParser aFromParser)
 {
   return new mozilla::dom::HTMLElement(aNodeInfo);
 }
--- a/content/html/content/src/HTMLFieldSetElement.cpp
+++ b/content/html/content/src/HTMLFieldSetElement.cpp
@@ -9,17 +9,17 @@
 #include "nsContentList.h"
 #include "nsEventDispatcher.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(FieldSet)
 
 namespace mozilla {
 namespace dom {
 
-HTMLFieldSetElement::HTMLFieldSetElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLFieldSetElement::HTMLFieldSetElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLFormElement(aNodeInfo)
   , mElements(nullptr)
   , mFirstLegend(nullptr)
   , mInvalidElementsCount(0)
 {
   // <fieldset> is always barred from constraint validation.
   SetBarredFromConstraintValidation(true);
 
--- a/content/html/content/src/HTMLFieldSetElement.h
+++ b/content/html/content/src/HTMLFieldSetElement.h
@@ -21,17 +21,17 @@ class HTMLFieldSetElement MOZ_FINAL : pu
                                       public nsIConstraintValidation
 {
 public:
   using nsGenericHTMLFormElement::GetForm;
   using nsIConstraintValidation::Validity;
   using nsIConstraintValidation::CheckValidity;
   using nsIConstraintValidation::GetValidationMessage;
 
-  HTMLFieldSetElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLFieldSetElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLFieldSetElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLFieldSetElement, fieldset)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLFieldSetElement
--- a/content/html/content/src/HTMLFontElement.h
+++ b/content/html/content/src/HTMLFontElement.h
@@ -9,17 +9,17 @@
 #include "nsGenericHTMLElement.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLFontElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLFontElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLFontElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLFontElement();
 
   void GetColor(nsString& aColor)
   {
     GetHTMLAttr(nsGkAtoms::color, aColor);
--- a/content/html/content/src/HTMLFormElement.cpp
+++ b/content/html/content/src/HTMLFormElement.cpp
@@ -57,17 +57,17 @@
 #include "nsIDOMHTMLButtonElement.h"
 #include "nsSandboxFlags.h"
 
 // images
 #include "mozilla/dom/HTMLImageElement.h"
 
 // construction, destruction
 nsGenericHTMLElement*
-NS_NewHTMLFormElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLFormElement(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                       mozilla::dom::FromParser aFromParser)
 {
   mozilla::dom::HTMLFormElement* it = new mozilla::dom::HTMLFormElement(aNodeInfo);
 
   nsresult rv = it->Init();
 
   if (NS_FAILED(rv)) {
     delete it;
@@ -89,17 +89,17 @@ static const nsAttrValue::EnumTable kFor
   { 0 }
 };
 // Default autocomplete value is 'on'.
 static const nsAttrValue::EnumTable* kFormDefaultAutocomplete = &kFormAutocompleteTable[0];
 
 bool HTMLFormElement::gFirstFormSubmitted = false;
 bool HTMLFormElement::gPasswordManagerInitialized = false;
 
-HTMLFormElement::HTMLFormElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLFormElement::HTMLFormElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo),
     mSelectedRadioButtons(4),
     mRequiredRadioButtonCounts(4),
     mValueMissingRadioGroups(4),
     mGeneratingSubmit(false),
     mGeneratingReset(false),
     mIsSubmitting(false),
     mDeferSubmission(false),
--- a/content/html/content/src/HTMLFormElement.h
+++ b/content/html/content/src/HTMLFormElement.h
@@ -35,17 +35,17 @@ class HTMLFormElement MOZ_FINAL : public
                                   public nsIDOMHTMLFormElement,
                                   public nsIWebProgressListener,
                                   public nsIForm,
                                   public nsIRadioGroupContainer
 {
   friend class HTMLFormControlsCollection;
 
 public:
-  HTMLFormElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLFormElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLFormElement();
 
   nsresult Init();
 
   enum {
     FORM_CONTROL_LIST_HASHTABLE_SIZE = 16
   };
 
--- a/content/html/content/src/HTMLFrameElement.cpp
+++ b/content/html/content/src/HTMLFrameElement.cpp
@@ -8,17 +8,17 @@
 
 class nsIDOMDocument;
 
 NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Frame)
 
 namespace mozilla {
 namespace dom {
 
-HTMLFrameElement::HTMLFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLFrameElement::HTMLFrameElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                    FromParser aFromParser)
   : nsGenericHTMLFrameElement(aNodeInfo, aFromParser)
 {
 }
 
 HTMLFrameElement::~HTMLFrameElement()
 {
 }
--- a/content/html/content/src/HTMLFrameElement.h
+++ b/content/html/content/src/HTMLFrameElement.h
@@ -17,17 +17,17 @@ namespace mozilla {
 namespace dom {
 
 class HTMLFrameElement MOZ_FINAL : public nsGenericHTMLFrameElement,
                                    public nsIDOMHTMLFrameElement
 {
 public:
   using nsGenericHTMLFrameElement::SwapFrameLoaders;
 
-  HTMLFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLFrameElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                    FromParser aFromParser = NOT_FROM_PARSER);
   virtual ~HTMLFrameElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLFrameElement
   NS_DECL_NSIDOMHTMLFRAMEELEMENT
--- a/content/html/content/src/HTMLFrameSetElement.h
+++ b/content/html/content/src/HTMLFrameSetElement.h
@@ -41,17 +41,17 @@ namespace mozilla {
 namespace dom {
 
 class OnBeforeUnloadEventHandlerNonNull;
 
 class HTMLFrameSetElement MOZ_FINAL : public nsGenericHTMLElement,
                                       public nsIDOMHTMLFrameSetElement
 {
 public:
-  HTMLFrameSetElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLFrameSetElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo),
       mNumRows(0),
       mNumCols(0),
       mCurrentRowColHint(NS_STYLE_HINT_REFLOW)
   {
     SetHasWeirdParserInsertionMode();
   }
   virtual ~HTMLFrameSetElement();
--- a/content/html/content/src/HTMLHRElement.cpp
+++ b/content/html/content/src/HTMLHRElement.cpp
@@ -6,17 +6,17 @@
 #include "mozilla/dom/HTMLHRElement.h"
 #include "mozilla/dom/HTMLHRElementBinding.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(HR)
 
 namespace mozilla {
 namespace dom {
 
-HTMLHRElement::HTMLHRElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLHRElement::HTMLHRElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLHRElement::~HTMLHRElement()
 {
 }
 
--- a/content/html/content/src/HTMLHRElement.h
+++ b/content/html/content/src/HTMLHRElement.h
@@ -15,17 +15,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLHRElement MOZ_FINAL : public nsGenericHTMLElement,
                                 public nsIDOMHTMLHRElement
 {
 public:
-  HTMLHRElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLHRElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLHRElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLHRElement
   NS_DECL_NSIDOMHTMLHRELEMENT
 
--- a/content/html/content/src/HTMLHeadingElement.h
+++ b/content/html/content/src/HTMLHeadingElement.h
@@ -12,17 +12,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLHeadingElement MOZ_FINAL : public nsGenericHTMLElement,
 				     public nsIDOMHTMLHeadingElement
 {
 public:
-  HTMLHeadingElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLHeadingElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLHeadingElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLIFrameElement.cpp
+++ b/content/html/content/src/HTMLIFrameElement.cpp
@@ -12,17 +12,17 @@
 #include "nsStyleConsts.h"
 #include "nsContentUtils.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(IFrame)
 
 namespace mozilla {
 namespace dom {
 
-HTMLIFrameElement::HTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLIFrameElement::HTMLIFrameElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                      FromParser aFromParser)
   : nsGenericHTMLFrameElement(aNodeInfo, aFromParser)
 {
 }
 
 HTMLIFrameElement::~HTMLIFrameElement()
 {
 }
--- a/content/html/content/src/HTMLIFrameElement.h
+++ b/content/html/content/src/HTMLIFrameElement.h
@@ -13,17 +13,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLIFrameElement MOZ_FINAL : public nsGenericHTMLFrameElement
                                   , public nsIDOMHTMLIFrameElement
 {
 public:
-  HTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLIFrameElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                     FromParser aFromParser = NOT_FROM_PARSER);
   virtual ~HTMLIFrameElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLIFrameElement, iframe)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLImageElement.cpp
+++ b/content/html/content/src/HTMLImageElement.cpp
@@ -40,17 +40,17 @@
 
 #include "nsLayoutUtils.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Image)
 
 namespace mozilla {
 namespace dom {
 
-HTMLImageElement::HTMLImageElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLImageElement::HTMLImageElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
   , mForm(nullptr)
 {
   // We start out broken
   AddStatesSilently(NS_EVENT_STATE_BROKEN);
 }
 
 HTMLImageElement::~HTMLImageElement()
@@ -542,22 +542,22 @@ HTMLImageElement::Image(const GlobalObje
 {
   nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
   nsIDocument* doc;
   if (!win || !(doc = win->GetExtantDoc())) {
     aError.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsCOMPtr<nsINodeInfo> nodeInfo =
+  already_AddRefed<nsINodeInfo> nodeInfo =
     doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::img, nullptr,
                                         kNameSpaceID_XHTML,
                                         nsIDOMNode::ELEMENT_NODE);
 
-  nsRefPtr<HTMLImageElement> img = new HTMLImageElement(nodeInfo.forget());
+  nsRefPtr<HTMLImageElement> img = new HTMLImageElement(nodeInfo);
 
   if (aWidth.WasPassed()) {
     img->SetWidth(aWidth.Value(), aError);
     if (aError.Failed()) {
       return nullptr;
     }
 
     if (aHeight.WasPassed()) {
--- a/content/html/content/src/HTMLImageElement.h
+++ b/content/html/content/src/HTMLImageElement.h
@@ -16,17 +16,17 @@
 namespace mozilla {
 namespace dom {
 
 class HTMLImageElement MOZ_FINAL : public nsGenericHTMLElement,
                                    public nsImageLoadingContent,
                                    public nsIDOMHTMLImageElement
 {
 public:
-  explicit HTMLImageElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  explicit HTMLImageElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLImageElement();
 
   static already_AddRefed<HTMLImageElement>
     Image(const GlobalObject& aGlobal,
           const Optional<uint32_t>& aWidth,
           const Optional<uint32_t>& aHeight,
           ErrorResult& aError);
 
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -394,17 +394,17 @@ public:
     mNextFile->GetLeafName(leafName);
     MOZ_ASSERT(leafName.Length() <= path.Length());
     int32_t length = path.Length() - leafName.Length();
     MOZ_ASSERT(length >= 0);
     if (length > 0) {
       // Note that we leave the trailing "/" on the path.
       domFile->SetPath(Substring(path, 0, uint32_t(length)));
     }
-    *aResult = static_cast<nsIDOMFile*>(domFile.forget().get());
+    *aResult = domFile.forget().downcast<nsIDOMFile>().take();
     LookupAndCacheNext();
     return NS_OK;
   }
 
   NS_IMETHOD
   HasMoreElements(bool* aResult)
   {
     *aResult = !!mNextFile;
@@ -1104,17 +1104,17 @@ static nsresult FireEventForAccessibilit
                                           nsPresContext* aPresContext,
                                           const nsAString& aEventType);
 #endif
 
 //
 // construction, destruction
 //
 
-HTMLInputElement::HTMLInputElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLInputElement::HTMLInputElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                    FromParser aFromParser)
   : nsGenericHTMLFormElementWithState(aNodeInfo)
   , mType(kInputDefaultType->value)
   , mDisabledChanged(false)
   , mValueChanged(false)
   , mCheckedChanged(false)
   , mChecked(false)
   , mHandlingSelectEvent(false)
@@ -1240,19 +1240,18 @@ NS_IMPL_NSICONSTRAINTVALIDATION_EXCEPT_S
 
 // nsIDOMNode
 
 nsresult
 HTMLInputElement::Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const
 {
   *aResult = nullptr;
 
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-  nsRefPtr<HTMLInputElement> it =
-    new HTMLInputElement(ni.forget(), NOT_FROM_PARSER);
+  already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
+  nsRefPtr<HTMLInputElement> it = new HTMLInputElement(ni, NOT_FROM_PARSER);
 
   nsresult rv = const_cast<HTMLInputElement*>(this)->CopyInnerTo(it);
   NS_ENSURE_SUCCESS(rv, rv);
 
   switch (GetValueMode()) {
     case VALUE_MODE_VALUE:
       if (mValueChanged) {
         // We don't have our default value anymore.  Set our value on
--- a/content/html/content/src/HTMLInputElement.h
+++ b/content/html/content/src/HTMLInputElement.h
@@ -92,17 +92,17 @@ class HTMLInputElement MOZ_FINAL : publi
 
 public:
   using nsIConstraintValidation::GetValidationMessage;
   using nsIConstraintValidation::CheckValidity;
   using nsIConstraintValidation::WillValidate;
   using nsIConstraintValidation::Validity;
   using nsGenericHTMLFormElementWithState::GetForm;
 
-  HTMLInputElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLInputElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                    mozilla::dom::FromParser aFromParser);
   virtual ~HTMLInputElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLInputElement, input)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLLIElement.h
+++ b/content/html/content/src/HTMLLIElement.h
@@ -13,17 +13,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLLIElement MOZ_FINAL : public nsGenericHTMLElement,
                                 public nsIDOMHTMLLIElement
 {
 public:
-  HTMLLIElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLLIElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLLIElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLLabelElement.h
+++ b/content/html/content/src/HTMLLabelElement.h
@@ -15,17 +15,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLLabelElement MOZ_FINAL : public nsGenericHTMLFormElement,
                                    public nsIDOMHTMLLabelElement
 {
 public:
-  HTMLLabelElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLLabelElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLFormElement(aNodeInfo),
       mHandlingEvent(false)
   {
   }
   virtual ~HTMLLabelElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLLabelElement, label)
 
--- a/content/html/content/src/HTMLLegendElement.h
+++ b/content/html/content/src/HTMLLegendElement.h
@@ -11,17 +11,17 @@
 #include "mozilla/dom/HTMLFormElement.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLLegendElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLLegendElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLLegendElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLLegendElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLLegendElement, legend)
 
   using nsGenericHTMLElement::Focus;
--- a/content/html/content/src/HTMLLinkElement.cpp
+++ b/content/html/content/src/HTMLLinkElement.cpp
@@ -26,17 +26,17 @@
 #include "nsStyleConsts.h"
 #include "nsUnicharUtils.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Link)
 
 namespace mozilla {
 namespace dom {
 
-HTMLLinkElement::HTMLLinkElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLLinkElement::HTMLLinkElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
   , Link(MOZ_THIS_IN_INITIALIZER_LIST())
 {
 }
 
 HTMLLinkElement::~HTMLLinkElement()
 {
 }
--- a/content/html/content/src/HTMLLinkElement.h
+++ b/content/html/content/src/HTMLLinkElement.h
@@ -16,17 +16,17 @@ namespace mozilla {
 namespace dom {
 
 class HTMLLinkElement MOZ_FINAL : public nsGenericHTMLElement,
                                   public nsIDOMHTMLLinkElement,
                                   public nsStyleLinkElement,
                                   public Link
 {
 public:
-  HTMLLinkElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLLinkElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLLinkElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // CC
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLLinkElement,
                                            nsGenericHTMLElement)
--- a/content/html/content/src/HTMLMapElement.cpp
+++ b/content/html/content/src/HTMLMapElement.cpp
@@ -10,17 +10,17 @@
 #include "nsContentList.h"
 #include "nsCOMPtr.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Map)
 
 namespace mozilla {
 namespace dom {
 
-HTMLMapElement::HTMLMapElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLMapElement::HTMLMapElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLMapElement)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLMapElement,
                                                   nsGenericHTMLElement)
--- a/content/html/content/src/HTMLMapElement.h
+++ b/content/html/content/src/HTMLMapElement.h
@@ -16,17 +16,17 @@ class nsContentList;
 
 namespace mozilla {
 namespace dom {
 
 class HTMLMapElement MOZ_FINAL : public nsGenericHTMLElement,
                                  public nsIDOMHTMLMapElement
 {
 public:
-  HTMLMapElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLMapElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLMapElement
   NS_DECL_NSIDOMHTMLMAPELEMENT
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -1824,17 +1824,17 @@ HTMLMediaElement::MozCaptureStream(Error
   }
 
   return stream.forget();
 }
 
 NS_IMETHODIMP HTMLMediaElement::MozCaptureStream(nsIDOMMediaStream** aStream)
 {
   ErrorResult rv;
-  *aStream = MozCaptureStream(rv).get();
+  *aStream = MozCaptureStream(rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<DOMMediaStream>
 HTMLMediaElement::MozCaptureStreamUntilEnded(ErrorResult& aRv)
 {
   nsRefPtr<DOMMediaStream> stream = CaptureStreamInternal(true);
   if (!stream) {
@@ -1843,17 +1843,17 @@ HTMLMediaElement::MozCaptureStreamUntilE
   }
 
   return stream.forget();
 }
 
 NS_IMETHODIMP HTMLMediaElement::MozCaptureStreamUntilEnded(nsIDOMMediaStream** aStream)
 {
   ErrorResult rv;
-  *aStream = MozCaptureStreamUntilEnded(rv).get();
+  *aStream = MozCaptureStreamUntilEnded(rv).take();
   return rv.ErrorCode();
 }
 
 NS_IMETHODIMP HTMLMediaElement::GetMozAudioCaptured(bool* aCaptured)
 {
   *aCaptured = MozAudioCaptured();
   return NS_OK;
 }
@@ -1956,17 +1956,17 @@ HTMLMediaElement::LookupMediaElementURIT
       if (resource->CanClone()) {
         return elem;
       }
     }
   }
   return nullptr;
 }
 
-HTMLMediaElement::HTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLMediaElement::HTMLMediaElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo),
     mSrcStreamListener(nullptr),
     mCurrentLoadID(0),
     mNetworkState(nsIDOMHTMLMediaElement::NETWORK_EMPTY),
     mReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING),
     mLoadWaitStatus(NOT_WAITING),
     mVolume(1.0),
     mChannels(0),
--- a/content/html/content/src/HTMLMenuElement.cpp
+++ b/content/html/content/src/HTMLMenuElement.cpp
@@ -40,17 +40,17 @@ enum SeparatorType
 {
   ST_TRUE_INIT = -1,
   ST_FALSE = 0,
   ST_TRUE = 1
 };
 
 
 
-HTMLMenuElement::HTMLMenuElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLMenuElement::HTMLMenuElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo), mType(MENU_TYPE_LIST)
 {
 }
 
 HTMLMenuElement::~HTMLMenuElement()
 {
 }
 
--- a/content/html/content/src/HTMLMenuElement.h
+++ b/content/html/content/src/HTMLMenuElement.h
@@ -14,17 +14,17 @@
 namespace mozilla {
 namespace dom {
 
 class HTMLMenuElement MOZ_FINAL : public nsGenericHTMLElement,
                                   public nsIDOMHTMLMenuElement,
                                   public nsIHTMLMenu
 {
 public:
-  HTMLMenuElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLMenuElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLMenuElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLMenuElement, menu)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLMenuElement
--- a/content/html/content/src/HTMLMenuItemElement.cpp
+++ b/content/html/content/src/HTMLMenuItemElement.cpp
@@ -151,17 +151,17 @@ protected:
   Visitor* mVisitor1;
   Visitor* mVisitor2;
   bool mContinue1;
   bool mContinue2;
 };
 
 
 HTMLMenuItemElement::HTMLMenuItemElement(
-  already_AddRefed<nsINodeInfo> aNodeInfo, FromParser aFromParser)
+  already_AddRefed<nsINodeInfo>& aNodeInfo, FromParser aFromParser)
   : nsGenericHTMLElement(aNodeInfo),
     mType(kMenuItemDefaultType->value),
     mParserCreating(false),
     mShouldInitChecked(false),
     mCheckedDirty(false),
     mChecked(false)
 {
   mParserCreating = aFromParser;
@@ -175,19 +175,19 @@ HTMLMenuItemElement::~HTMLMenuItemElemen
 NS_IMPL_ISUPPORTS_INHERITED1(HTMLMenuItemElement, nsGenericHTMLElement,
                              nsIDOMHTMLMenuItemElement)
 
 //NS_IMPL_ELEMENT_CLONE(HTMLMenuItemElement)
 nsresult
 HTMLMenuItemElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   *aResult = nullptr;
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
+  already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
   nsRefPtr<HTMLMenuItemElement> it =
-    new HTMLMenuItemElement(ni.forget(), NOT_FROM_PARSER);
+    new HTMLMenuItemElement(ni, NOT_FROM_PARSER);
   nsresult rv = const_cast<HTMLMenuItemElement*>(this)->CopyInnerTo(it);
   if (NS_SUCCEEDED(rv)) {
     switch (mType) {
       case CMD_TYPE_CHECKBOX:
       case CMD_TYPE_RADIO:
         if (mCheckedDirty) {
           // We no longer have our original checked state.  Set our
           // checked state on the clone.
--- a/content/html/content/src/HTMLMenuItemElement.h
+++ b/content/html/content/src/HTMLMenuItemElement.h
@@ -16,17 +16,17 @@ namespace dom {
 class Visitor;
 
 class HTMLMenuItemElement MOZ_FINAL : public nsGenericHTMLElement,
                                       public nsIDOMHTMLMenuItemElement
 {
 public:
   using mozilla::dom::Element::GetText;
 
-  HTMLMenuItemElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLMenuItemElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                       mozilla::dom::FromParser aFromParser);
   virtual ~HTMLMenuItemElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLMenuItemElement, menuitem)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLMetaElement.cpp
+++ b/content/html/content/src/HTMLMetaElement.cpp
@@ -9,17 +9,17 @@
 #include "nsAsyncDOMEvent.h"
 #include "nsContentUtils.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Meta)
 
 namespace mozilla {
 namespace dom {
 
-HTMLMetaElement::HTMLMetaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLMetaElement::HTMLMetaElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLMetaElement::~HTMLMetaElement()
 {
 }
 
--- a/content/html/content/src/HTMLMetaElement.h
+++ b/content/html/content/src/HTMLMetaElement.h
@@ -12,17 +12,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLMetaElement MOZ_FINAL : public nsGenericHTMLElement,
                                   public nsIDOMHTMLMetaElement
 {
 public:
-  HTMLMetaElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLMetaElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLMetaElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLMetaElement
   NS_DECL_NSIDOMHTMLMETAELEMENT
 
--- a/content/html/content/src/HTMLMeterElement.cpp
+++ b/content/html/content/src/HTMLMeterElement.cpp
@@ -11,17 +11,17 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Meter)
 namespace mozilla {
 namespace dom {
 
 const double HTMLMeterElement::kDefaultValue =  0.0;
 const double HTMLMeterElement::kDefaultMin   =  0.0;
 const double HTMLMeterElement::kDefaultMax   =  1.0;
 
 
-HTMLMeterElement::HTMLMeterElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLMeterElement::HTMLMeterElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLMeterElement::~HTMLMeterElement()
 {
 }
 
--- a/content/html/content/src/HTMLMeterElement.h
+++ b/content/html/content/src/HTMLMeterElement.h
@@ -15,17 +15,17 @@
 #include <algorithm>
 
 namespace mozilla {
 namespace dom {
 
 class HTMLMeterElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLMeterElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLMeterElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLMeterElement();
 
   virtual nsEventStates IntrinsicState() const MOZ_OVERRIDE;
 
   nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const MOZ_OVERRIDE;
 
   bool ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute,
                       const nsAString& aValue, nsAttrValue& aResult) MOZ_OVERRIDE;
--- a/content/html/content/src/HTMLModElement.cpp
+++ b/content/html/content/src/HTMLModElement.cpp
@@ -7,17 +7,17 @@
 #include "mozilla/dom/HTMLModElementBinding.h"
 #include "nsStyleConsts.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Mod)
 
 namespace mozilla {
 namespace dom {
 
-HTMLModElement::HTMLModElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLModElement::HTMLModElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLModElement::~HTMLModElement()
 {
 }
 
--- a/content/html/content/src/HTMLModElement.h
+++ b/content/html/content/src/HTMLModElement.h
@@ -11,17 +11,17 @@
 #include "nsGkAtoms.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLModElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLModElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLModElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLModElement();
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   void GetCite(nsString& aCite)
   {
     GetHTMLURIAttr(nsGkAtoms::cite, aCite);
   }
--- a/content/html/content/src/HTMLObjectElement.cpp
+++ b/content/html/content/src/HTMLObjectElement.cpp
@@ -18,17 +18,17 @@
 #include "nsIObjectFrame.h"
 #include "nsNPAPIPluginInstance.h"
 #include "nsIWidget.h"
 #include "nsContentUtils.h"
 
 namespace mozilla {
 namespace dom {
 
-HTMLObjectElement::HTMLObjectElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLObjectElement::HTMLObjectElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                      FromParser aFromParser)
   : nsGenericHTMLFormElement(aNodeInfo),
     mIsDoneAddingChildren(!aFromParser)
 {
   RegisterFreezableElement();
   SetIsNetworkCreated(aFromParser == FROM_PARSER_NETWORK);
 
   // <object> is always barred from constraint validation.
--- a/content/html/content/src/HTMLObjectElement.h
+++ b/content/html/content/src/HTMLObjectElement.h
@@ -17,17 +17,17 @@ namespace mozilla {
 namespace dom {
 
 class HTMLObjectElement MOZ_FINAL : public nsGenericHTMLFormElement
                                   , public nsObjectLoadingContent
                                   , public nsIDOMHTMLObjectElement
                                   , public nsIConstraintValidation
 {
 public:
-  HTMLObjectElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLObjectElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                     FromParser aFromParser = NOT_FROM_PARSER);
   virtual ~HTMLObjectElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
--- a/content/html/content/src/HTMLOptGroupElement.cpp
+++ b/content/html/content/src/HTMLOptGroupElement.cpp
@@ -20,17 +20,17 @@ namespace mozilla {
 namespace dom {
 
 /**
  * The implementation of &lt;optgroup&gt;
  */
 
 
 
-HTMLOptGroupElement::HTMLOptGroupElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLOptGroupElement::HTMLOptGroupElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
   // We start off enabled
   AddStatesSilently(NS_EVENT_STATE_ENABLED);
 }
 
 HTMLOptGroupElement::~HTMLOptGroupElement()
 {
--- a/content/html/content/src/HTMLOptGroupElement.h
+++ b/content/html/content/src/HTMLOptGroupElement.h
@@ -12,17 +12,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLOptGroupElement MOZ_FINAL : public nsGenericHTMLElement,
                                       public nsIDOMHTMLOptGroupElement
 {
 public:
-  HTMLOptGroupElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLOptGroupElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLOptGroupElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLOptGroupElement, optgroup)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLOptGroupElement
--- a/content/html/content/src/HTMLOptionElement.cpp
+++ b/content/html/content/src/HTMLOptionElement.cpp
@@ -32,17 +32,17 @@
  * Implementation of &lt;option&gt;
  */
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Option)
 
 namespace mozilla {
 namespace dom {
 
-HTMLOptionElement::HTMLOptionElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLOptionElement::HTMLOptionElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo),
     mSelectedChanged(false),
     mIsSelected(false),
     mIsInSetDefaultSelected(false)
 {
   // We start off enabled
   AddStatesSilently(NS_EVENT_STATE_ENABLED);
 }
@@ -358,22 +358,22 @@ HTMLOptionElement::Option(const GlobalOb
 {
   nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
   nsIDocument* doc;
   if (!win || !(doc = win->GetExtantDoc())) {
     aError.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsCOMPtr<nsINodeInfo> nodeInfo =
+  already_AddRefed<nsINodeInfo> nodeInfo =
     doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::option, nullptr,
                                         kNameSpaceID_XHTML,
                                         nsIDOMNode::ELEMENT_NODE);
 
-  nsRefPtr<HTMLOptionElement> option = new HTMLOptionElement(nodeInfo.forget());
+  nsRefPtr<HTMLOptionElement> option = new HTMLOptionElement(nodeInfo);
 
   if (aText.WasPassed()) {
     // Create a new text node and append it to the option
     nsRefPtr<nsTextNode> textContent =
       new nsTextNode(option->NodeInfo()->NodeInfoManager());
 
     textContent->SetText(aText.Value(), false);
 
--- a/content/html/content/src/HTMLOptionElement.h
+++ b/content/html/content/src/HTMLOptionElement.h
@@ -17,17 +17,17 @@ namespace mozilla {
 namespace dom {
 
 class HTMLSelectElement;
 
 class HTMLOptionElement MOZ_FINAL : public nsGenericHTMLElement,
                                     public nsIDOMHTMLOptionElement
 {
 public:
-  HTMLOptionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLOptionElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLOptionElement();
 
   static already_AddRefed<HTMLOptionElement>
     Option(const GlobalObject& aGlobal,
            const Optional<nsAString>& aText,
            const Optional<nsAString>& aValue,
            const Optional<bool>& aDefaultSelected,
            const Optional<bool>& aSelected, ErrorResult& aError);
--- a/content/html/content/src/HTMLOutputElement.cpp
+++ b/content/html/content/src/HTMLOutputElement.cpp
@@ -13,17 +13,17 @@
 #include "nsEventStates.h"
 #include "nsFormSubmission.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Output)
 
 namespace mozilla {
 namespace dom {
 
-HTMLOutputElement::HTMLOutputElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLOutputElement::HTMLOutputElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLFormElement(aNodeInfo)
   , mValueModeFlag(eModeDefault)
 {
   AddMutationObserver(this);
 
   // We start out valid and ui-valid (since we have no form).
   AddStatesSilently(NS_EVENT_STATE_VALID | NS_EVENT_STATE_MOZ_UI_VALID);
 }
--- a/content/html/content/src/HTMLOutputElement.h
+++ b/content/html/content/src/HTMLOutputElement.h
@@ -16,17 +16,17 @@ namespace dom {
 
 class HTMLOutputElement MOZ_FINAL : public nsGenericHTMLFormElement,
                                     public nsStubMutationObserver,
                                     public nsIConstraintValidation
 {
 public:
   using nsIConstraintValidation::GetValidationMessage;
 
-  HTMLOutputElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLOutputElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLOutputElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIFormControl
   NS_IMETHOD_(uint32_t) GetType() const { return NS_FORM_OUTPUT; }
   NS_IMETHOD Reset() MOZ_OVERRIDE;
--- a/content/html/content/src/HTMLParagraphElement.h
+++ b/content/html/content/src/HTMLParagraphElement.h
@@ -13,17 +13,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLParagraphElement MOZ_FINAL : public nsGenericHTMLElement,
                                        public nsIDOMHTMLParagraphElement
 {
 public:
-  HTMLParagraphElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLParagraphElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLParagraphElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLPreElement.h
+++ b/content/html/content/src/HTMLPreElement.h
@@ -13,17 +13,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLPreElement MOZ_FINAL : public nsGenericHTMLElement,
                                  public nsIDOMHTMLPreElement
 {
 public:
-  HTMLPreElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLPreElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLPreElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLProgressElement.cpp
+++ b/content/html/content/src/HTMLProgressElement.cpp
@@ -11,17 +11,17 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Progress)
 namespace mozilla {
 namespace dom {
 
 const double HTMLProgressElement::kIndeterminatePosition = -1.0;
 const double HTMLProgressElement::kDefaultValue          =  0.0;
 const double HTMLProgressElement::kDefaultMax            =  1.0;
 
 
-HTMLProgressElement::HTMLProgressElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLProgressElement::HTMLProgressElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
   // We start out indeterminate
   AddStatesSilently(NS_EVENT_STATE_INDETERMINATE);
 }
 
 HTMLProgressElement::~HTMLProgressElement()
 {
--- a/content/html/content/src/HTMLProgressElement.h
+++ b/content/html/content/src/HTMLProgressElement.h
@@ -14,17 +14,17 @@
 #include <algorithm>
 
 namespace mozilla {
 namespace dom {
 
 class HTMLProgressElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLProgressElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLProgressElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLProgressElement();
 
   nsEventStates IntrinsicState() const MOZ_OVERRIDE;
 
   nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const MOZ_OVERRIDE;
 
   bool ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute,
                         const nsAString& aValue, nsAttrValue& aResult) MOZ_OVERRIDE;
--- a/content/html/content/src/HTMLScriptElement.cpp
+++ b/content/html/content/src/HTMLScriptElement.cpp
@@ -29,17 +29,17 @@ namespace mozilla {
 namespace dom {
 
 JSObject*
 HTMLScriptElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return HTMLScriptElementBinding::Wrap(aCx, aScope, this);
 }
 
-HTMLScriptElement::HTMLScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLScriptElement::HTMLScriptElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                      FromParser aFromParser)
   : nsGenericHTMLElement(aNodeInfo)
   , nsScriptElement(aFromParser)
 {
   AddMutationObserver(this);
 }
 
 HTMLScriptElement::~HTMLScriptElement()
@@ -85,19 +85,18 @@ HTMLScriptElement::ParseAttribute(int32_
                                               aResult);
 }
 
 nsresult
 HTMLScriptElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   *aResult = nullptr;
 
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-  HTMLScriptElement* it =
-    new HTMLScriptElement(ni.forget(), NOT_FROM_PARSER);
+  already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
+  HTMLScriptElement* it = new HTMLScriptElement(ni, NOT_FROM_PARSER);
 
   nsCOMPtr<nsINode> kungFuDeathGrip = it;
   nsresult rv = const_cast<HTMLScriptElement*>(this)->CopyInnerTo(it);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // The clone should be marked evaluated if we are.
   it->mAlreadyStarted = mAlreadyStarted;
   it->mLineNumber = mLineNumber;
--- a/content/html/content/src/HTMLScriptElement.h
+++ b/content/html/content/src/HTMLScriptElement.h
@@ -18,18 +18,18 @@ namespace dom {
 class HTMLScriptElement MOZ_FINAL : public nsGenericHTMLElement,
                                     public nsIDOMHTMLScriptElement,
                                     public nsScriptElement
 {
 public:
   using Element::GetText;
   using Element::SetText;
 
-  HTMLScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
-                      FromParser aFromParser);
+  HTMLScriptElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
+                    FromParser aFromParser);
   virtual ~HTMLScriptElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) MOZ_OVERRIDE;
   using nsGenericHTMLElement::SetInnerHTML;
   virtual void SetInnerHTML(const nsAString& aInnerHTML,
--- a/content/html/content/src/HTMLSelectElement.cpp
+++ b/content/html/content/src/HTMLSelectElement.cpp
@@ -95,17 +95,17 @@ SafeOptionListMutation::~SafeOptionListM
 //----------------------------------------------------------------------
 //
 // HTMLSelectElement
 //
 
 // construction, destruction
 
 
-HTMLSelectElement::HTMLSelectElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLSelectElement::HTMLSelectElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                      FromParser aFromParser)
   : nsGenericHTMLFormElementWithState(aNodeInfo),
     mOptions(new HTMLOptionsCollection(MOZ_THIS_IN_INITIALIZER_LIST())),
     mIsDoneAddingChildren(!aFromParser),
     mDisabledChanged(false),
     mMutating(false),
     mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT)),
     mSelectionHasChanged(false),
--- a/content/html/content/src/HTMLSelectElement.h
+++ b/content/html/content/src/HTMLSelectElement.h
@@ -125,17 +125,17 @@ public:
     IS_SELECTED   = 1 << 0,
     CLEAR_ALL     = 1 << 1,
     SET_DISABLED  = 1 << 2,
     NOTIFY        = 1 << 3
   };
 
   using nsIConstraintValidation::GetValidationMessage;
 
-  HTMLSelectElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLSelectElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                     FromParser aFromParser = NOT_FROM_PARSER);
   virtual ~HTMLSelectElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLSelectElement, select)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLShadowElement.cpp
+++ b/content/html/content/src/HTMLShadowElement.cpp
@@ -8,17 +8,17 @@
 #include "nsContentUtils.h"
 #include "mozilla/dom/HTMLShadowElement.h"
 #include "mozilla/dom/HTMLShadowElementBinding.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Shadow)
 
 using namespace mozilla::dom;
 
-HTMLShadowElement::HTMLShadowElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLShadowElement::HTMLShadowElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo), mIsInsertionPoint(false)
 {
   SetIsDOMBinding();
 }
 
 HTMLShadowElement::~HTMLShadowElement()
 {
   if (mProjectedShadow) {
--- a/content/html/content/src/HTMLShadowElement.h
+++ b/content/html/content/src/HTMLShadowElement.h
@@ -10,17 +10,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLShadowElement MOZ_FINAL : public nsGenericHTMLElement,
                                     public nsStubMutationObserver
 {
 public:
-  HTMLShadowElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLShadowElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLShadowElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
--- a/content/html/content/src/HTMLSharedElement.h
+++ b/content/html/content/src/HTMLSharedElement.h
@@ -24,17 +24,17 @@ namespace dom {
 class HTMLSharedElement MOZ_FINAL : public nsGenericHTMLElement,
                                     public nsIDOMHTMLBaseElement,
                                     public nsIDOMHTMLDirectoryElement,
                                     public nsIDOMHTMLQuoteElement,
                                     public nsIDOMHTMLHeadElement,
                                     public nsIDOMHTMLHtmlElement
 {
 public:
-  HTMLSharedElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLSharedElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
     if (mNodeInfo->Equals(nsGkAtoms::head) ||
         mNodeInfo->Equals(nsGkAtoms::html)) {
       SetHasWeirdParserInsertionMode();
     }
   }
   virtual ~HTMLSharedElement();
--- a/content/html/content/src/HTMLSharedListElement.h
+++ b/content/html/content/src/HTMLSharedListElement.h
@@ -15,17 +15,17 @@
 namespace mozilla {
 namespace dom {
 
 class HTMLSharedListElement MOZ_FINAL : public nsGenericHTMLElement,
                                         public nsIDOMHTMLOListElement,
                                         public nsIDOMHTMLUListElement
 {
 public:
-  HTMLSharedListElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLSharedListElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLSharedListElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLSharedObjectElement.cpp
+++ b/content/html/content/src/HTMLSharedObjectElement.cpp
@@ -17,17 +17,17 @@
 #include "nsIWidget.h"
 #include "nsContentUtils.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(SharedObject)
 
 namespace mozilla {
 namespace dom {
 
-HTMLSharedObjectElement::HTMLSharedObjectElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLSharedObjectElement::HTMLSharedObjectElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                                  FromParser aFromParser)
   : nsGenericHTMLElement(aNodeInfo),
     mIsDoneAddingChildren(mNodeInfo->Equals(nsGkAtoms::embed) || !aFromParser)
 {
   RegisterFreezableElement();
   SetIsNetworkCreated(aFromParser == FROM_PARSER_NETWORK);
 
   // By default we're in the loading state
--- a/content/html/content/src/HTMLSharedObjectElement.h
+++ b/content/html/content/src/HTMLSharedObjectElement.h
@@ -19,17 +19,17 @@ namespace mozilla {
 namespace dom {
 
 class HTMLSharedObjectElement MOZ_FINAL : public nsGenericHTMLElement
                                         , public nsObjectLoadingContent
                                         , public nsIDOMHTMLAppletElement
                                         , public nsIDOMHTMLEmbedElement
 {
 public:
-  HTMLSharedObjectElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLSharedObjectElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                           mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
   virtual ~HTMLSharedObjectElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
--- a/content/html/content/src/HTMLSourceElement.cpp
+++ b/content/html/content/src/HTMLSourceElement.cpp
@@ -7,17 +7,17 @@
 #include "mozilla/dom/HTMLSourceElement.h"
 #include "mozilla/dom/HTMLSourceElementBinding.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Source)
 
 namespace mozilla {
 namespace dom {
 
-HTMLSourceElement::HTMLSourceElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLSourceElement::HTMLSourceElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLSourceElement::~HTMLSourceElement()
 {
 }
 
--- a/content/html/content/src/HTMLSourceElement.h
+++ b/content/html/content/src/HTMLSourceElement.h
@@ -14,17 +14,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLSourceElement MOZ_FINAL : public nsGenericHTMLElement,
                                     public nsIDOMHTMLSourceElement
 {
 public:
-  HTMLSourceElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLSourceElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLSourceElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLSourceElement
   NS_DECL_NSIDOMHTMLSOURCEELEMENT
 
--- a/content/html/content/src/HTMLSpanElement.h
+++ b/content/html/content/src/HTMLSpanElement.h
@@ -15,17 +15,17 @@
 #include "nsRuleData.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLSpanElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLSpanElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLSpanElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~HTMLSpanElement();
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
 protected:
--- a/content/html/content/src/HTMLStyleElement.cpp
+++ b/content/html/content/src/HTMLStyleElement.cpp
@@ -15,17 +15,17 @@
 #include "nsContentUtils.h"
 #include "nsStubMutationObserver.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Style)
 
 namespace mozilla {
 namespace dom {
 
-HTMLStyleElement::HTMLStyleElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLStyleElement::HTMLStyleElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
   AddMutationObserver(this);
 }
 
 HTMLStyleElement::~HTMLStyleElement()
 {
 }
--- a/content/html/content/src/HTMLStyleElement.h
+++ b/content/html/content/src/HTMLStyleElement.h
@@ -18,17 +18,17 @@ namespace mozilla {
 namespace dom {
 
 class HTMLStyleElement MOZ_FINAL : public nsGenericHTMLElement,
                                    public nsIDOMHTMLStyleElement,
                                    public nsStyleLinkElement,
                                    public nsStubMutationObserver
 {
 public:
-  HTMLStyleElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLStyleElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLStyleElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // CC
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLStyleElement,
                                            nsGenericHTMLElement)
--- a/content/html/content/src/HTMLTableCaptionElement.h
+++ b/content/html/content/src/HTMLTableCaptionElement.h
@@ -11,17 +11,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class HTMLTableCaptionElement MOZ_FINAL : public nsGenericHTMLElement,
                                           public nsIDOMHTMLTableCaptionElement
 {
 public:
-  HTMLTableCaptionElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLTableCaptionElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
     SetHasWeirdParserInsertionMode();
   }
   virtual ~HTMLTableCaptionElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
--- a/content/html/content/src/HTMLTableCellElement.h
+++ b/content/html/content/src/HTMLTableCellElement.h
@@ -15,17 +15,17 @@ namespace mozilla {
 namespace dom {
 
 class HTMLTableElement;
 
 class HTMLTableCellElement MOZ_FINAL : public nsGenericHTMLElement,
                                        public nsIDOMHTMLTableCellElement
 {
 public:
-  HTMLTableCellElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLTableCellElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
     SetHasWeirdParserInsertionMode();
   }
   virtual ~HTMLTableCellElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
--- a/content/html/content/src/HTMLTableColElement.h
+++ b/content/html/content/src/HTMLTableColElement.h
@@ -9,17 +9,17 @@
 #include "nsGenericHTMLElement.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLTableColElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLTableColElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLTableColElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
     SetHasWeirdParserInsertionMode();
   }
   virtual ~HTMLTableColElement();
 
   uint32_t Span() const
   {
--- a/content/html/content/src/HTMLTableElement.cpp
+++ b/content/html/content/src/HTMLTableElement.cpp
@@ -277,17 +277,17 @@ TableRowsCollection::ParentDestroyed()
   // see comment in destructor, do NOT release mParent!
   mParent = nullptr;
 
   return NS_OK;
 }
 
 /* --------------------------- HTMLTableElement ---------------------------- */
 
-HTMLTableElement::HTMLTableElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLTableElement::HTMLTableElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo),
     mTableInheritedAttributes(TABLE_ATTRS_DIRTY)
 {
   SetHasWeirdParserInsertionMode();
 }
 
 HTMLTableElement::~HTMLTableElement()
 {
--- a/content/html/content/src/HTMLTableElement.h
+++ b/content/html/content/src/HTMLTableElement.h
@@ -17,17 +17,17 @@ namespace dom {
 #define TABLE_ATTRS_DIRTY ((nsMappedAttributes*)0x1)
 
 class TableRowsCollection;
 
 class HTMLTableElement MOZ_FINAL : public nsGenericHTMLElement,
                                    public nsIDOMHTMLTableElement
 {
 public:
-  HTMLTableElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLTableElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLTableElement();
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLTableElement, table)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   HTMLTableCaptionElement* GetCaption() const
--- a/content/html/content/src/HTMLTableRowElement.h
+++ b/content/html/content/src/HTMLTableRowElement.h
@@ -14,17 +14,17 @@ class nsContentList;
 namespace mozilla {
 namespace dom {
 
 class HTMLTableSectionElement;
 
 class HTMLTableRowElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLTableRowElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLTableRowElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
     SetHasWeirdParserInsertionMode();
   }
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLTableRowElement, tr)
 
   // nsISupports
--- a/content/html/content/src/HTMLTableSectionElement.h
+++ b/content/html/content/src/HTMLTableSectionElement.h
@@ -10,17 +10,17 @@
 #include "nsContentList.h" // For ctor.
 
 namespace mozilla {
 namespace dom {
 
 class HTMLTableSectionElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLTableSectionElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLTableSectionElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
     SetHasWeirdParserInsertionMode();
   }
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/html/content/src/HTMLTemplateElement.cpp
+++ b/content/html/content/src/HTMLTemplateElement.cpp
@@ -9,33 +9,33 @@
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsIAtom.h"
 #include "nsRuleData.h"
 
 using namespace mozilla::dom;
 
 nsGenericHTMLElement*
-NS_NewHTMLTemplateElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLTemplateElement(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                           FromParser aFromParser)
 {
   HTMLTemplateElement* it = new HTMLTemplateElement(aNodeInfo);
   nsresult rv = it->Init();
   if (NS_FAILED(rv)) {
     delete it;
     return nullptr;
   }
 
   return it;
 }
 
 namespace mozilla {
 namespace dom {
 
-HTMLTemplateElement::HTMLTemplateElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLTemplateElement::HTMLTemplateElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
   SetHasWeirdParserInsertionMode();
 }
 
 nsresult
 HTMLTemplateElement::Init()
 {
--- a/content/html/content/src/HTMLTemplateElement.h
+++ b/content/html/content/src/HTMLTemplateElement.h
@@ -12,17 +12,17 @@
 #include "mozilla/dom/DocumentFragment.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLTemplateElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLTemplateElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLTemplateElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLTemplateElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTemplateElement,
                                            nsGenericHTMLElement)
 
--- a/content/html/content/src/HTMLTextAreaElement.cpp
+++ b/content/html/content/src/HTMLTextAreaElement.cpp
@@ -43,17 +43,17 @@ static NS_DEFINE_CID(kXULControllersCID,
 
 #define NS_NO_CONTENT_DISPATCH (1 << 0)
 
 NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(TextArea)
 
 namespace mozilla {
 namespace dom {
 
-HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                          FromParser aFromParser)
   : nsGenericHTMLFormElementWithState(aNodeInfo),
     mValueChanged(false),
     mHandlingSelect(false),
     mDoneAddingChildren(!aFromParser),
     mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT)),
     mDisabledChanged(false),
     mCanShowInvalidUI(true),
--- a/content/html/content/src/HTMLTextAreaElement.h
+++ b/content/html/content/src/HTMLTextAreaElement.h
@@ -36,17 +36,17 @@ class HTMLTextAreaElement MOZ_FINAL : pu
                                       public nsITextControlElement,
                                       public nsIDOMNSEditableElement,
                                       public nsStubMutationObserver,
                                       public nsIConstraintValidation
 {
 public:
   using nsIConstraintValidation::GetValidationMessage;
 
-  HTMLTextAreaElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  HTMLTextAreaElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                       FromParser aFromParser = NOT_FROM_PARSER);
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
   // nsIDOMHTMLTextAreaElement
--- a/content/html/content/src/HTMLTimeElement.cpp
+++ b/content/html/content/src/HTMLTimeElement.cpp
@@ -9,17 +9,17 @@
 #include "nsVariant.h"
 #include "nsGkAtoms.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Time)
 
 namespace mozilla {
 namespace dom {
 
-HTMLTimeElement::HTMLTimeElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLTimeElement::HTMLTimeElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLTimeElement::~HTMLTimeElement()
 {
 }
 
--- a/content/html/content/src/HTMLTimeElement.h
+++ b/content/html/content/src/HTMLTimeElement.h
@@ -12,17 +12,17 @@
 #include "nsGkAtoms.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLTimeElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLTimeElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLTimeElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLTimeElement();
 
   // HTMLTimeElement WebIDL
   void GetDateTime(nsAString& aDateTime)
   {
     GetHTMLAttr(nsGkAtoms::datetime, aDateTime);
   }
 
--- a/content/html/content/src/HTMLTitleElement.cpp
+++ b/content/html/content/src/HTMLTitleElement.cpp
@@ -12,17 +12,17 @@
 #include "nsContentUtils.h"
 
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Title)
 
 namespace mozilla {
 namespace dom {
 
-HTMLTitleElement::HTMLTitleElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLTitleElement::HTMLTitleElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
   AddMutationObserver(this);
 }
 
 HTMLTitleElement::~HTMLTitleElement()
 {
 }
--- a/content/html/content/src/HTMLTitleElement.h
+++ b/content/html/content/src/HTMLTitleElement.h
@@ -19,17 +19,17 @@ namespace dom {
 class HTMLTitleElement MOZ_FINAL : public nsGenericHTMLElement,
                                    public nsIDOMHTMLTitleElement,
                                    public nsStubMutationObserver
 {
 public:
   using Element::GetText;
   using Element::SetText;
 
-  HTMLTitleElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLTitleElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLTitleElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLTitleElement
   NS_DECL_NSIDOMHTMLTITLEELEMENT
 
--- a/content/html/content/src/HTMLTrackElement.cpp
+++ b/content/html/content/src/HTMLTrackElement.cpp
@@ -43,17 +43,17 @@ static PRLogModuleInfo* gTrackElementLog
 #define LOG(type, msg) PR_LOG(gTrackElementLog, type, msg)
 #else
 #define LOG(type, msg)
 #endif
 
 // Replace the usual NS_IMPL_NS_NEW_HTML_ELEMENT(Track) so
 // we can return an UnknownElement instead when pref'd off.
 nsGenericHTMLElement*
-NS_NewHTMLTrackElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLTrackElement(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                        mozilla::dom::FromParser aFromParser)
 {
   if (!mozilla::dom::HTMLTrackElement::IsWebVTTEnabled()) {
     return new mozilla::dom::HTMLUnknownElement(aNodeInfo);
   }
 
   return new mozilla::dom::HTMLTrackElement(aNodeInfo);
 }
@@ -70,17 +70,17 @@ static MOZ_CONSTEXPR nsAttrValue::EnumTa
   { "metadata", static_cast<int16_t>(TextTrackKind::Metadata) },
   { 0 }
 };
 
 // The default value for kKindTable is "subtitles"
 static MOZ_CONSTEXPR const char* kKindTableDefaultString = kKindTable->tag;
 
 /** HTMLTrackElement */
-HTMLTrackElement::HTMLTrackElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLTrackElement::HTMLTrackElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 #ifdef PR_LOGGING
   if (!gTrackElementLog) {
     gTrackElementLog = PR_NewLogModule("nsTrackElement");
   }
 #endif
 }
--- a/content/html/content/src/HTMLTrackElement.h
+++ b/content/html/content/src/HTMLTrackElement.h
@@ -21,17 +21,17 @@
 namespace mozilla {
 namespace dom {
 
 class WebVTTListener;
 
 class HTMLTrackElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLTrackElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  HTMLTrackElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~HTMLTrackElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTrackElement,
                                            nsGenericHTMLElement)
 
   // HTMLTrackElement WebIDL
--- a/content/html/content/src/HTMLUnknownElement.h
+++ b/content/html/content/src/HTMLUnknownElement.h
@@ -9,17 +9,17 @@
 #include "nsGenericHTMLElement.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLUnknownElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
-  HTMLUnknownElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  HTMLUnknownElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
     if (NodeInfo()->Equals(nsGkAtoms::bdi)) {
       SetHasDirAuto();
     }
   }
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
--- a/content/html/content/src/HTMLVideoElement.cpp
+++ b/content/html/content/src/HTMLVideoElement.cpp
@@ -61,17 +61,17 @@ NS_IMETHODIMP HTMLVideoElement::GetVideo
 
 /* readonly attribute unsigned long videoHeight; */
 NS_IMETHODIMP HTMLVideoElement::GetVideoHeight(uint32_t *aVideoHeight)
 {
   *aVideoHeight = VideoHeight();
   return NS_OK;
 }
 
-HTMLVideoElement::HTMLVideoElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+HTMLVideoElement::HTMLVideoElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : HTMLMediaElement(aNodeInfo)
 {
 }
 
 HTMLVideoElement::~HTMLVideoElement()
 {
 }
 
--- a/content/html/content/src/nsFormSubmission.cpp
+++ b/content/html/content/src/nsFormSubmission.cpp
@@ -556,17 +556,17 @@ nsFSMultipartFormData::GetEncodedSubmiss
 
   nsAutoCString contentType;
   GetContentType(contentType);
   mimeStream->AddHeader("Content-Type", contentType.get());
   mimeStream->SetAddContentLength(true);
   uint64_t unused;
   mimeStream->SetData(GetSubmissionBody(&unused));
 
-  *aPostDataStream = mimeStream.forget().get();
+  mimeStream.forget(aPostDataStream);
 
   return NS_OK;
 }
 
 nsresult
 nsFSMultipartFormData::AddPostDataStream()
 {
   nsresult rv = NS_OK;
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -317,17 +317,17 @@ nsGenericHTMLElement::Dataset()
 
   nsRefPtr<nsDOMStringMap> ret = slots->mDataset;
   return ret.forget();
 }
 
 NS_IMETHODIMP
 nsGenericHTMLElement::GetDataset(nsISupports** aDataset)
 {
-  *aDataset = Dataset().get();
+  *aDataset = Dataset().take();
   return NS_OK;
 }
 
 nsresult
 nsGenericHTMLElement::ClearDataset()
 {
   nsDOMSlots *slots = GetExistingDOMSlots();
 
@@ -740,17 +740,17 @@ nsGenericHTMLElement::PostHandleEventFor
   return PostHandleEventForLinks(aVisitor);
 }
 
 bool
 nsGenericHTMLElement::IsHTMLLink(nsIURI** aURI) const
 {
   NS_PRECONDITION(aURI, "Must provide aURI out param");
 
-  *aURI = GetHrefURIForAnchors().get();
+  *aURI = GetHrefURIForAnchors().take();
   // We promise out param is non-null if we return true, so base rv on it
   return *aURI != nullptr;
 }
 
 already_AddRefed<nsIURI>
 nsGenericHTMLElement::GetHrefURIForAnchors() const
 {
   // This is used by the three Link implementations and
@@ -1956,17 +1956,17 @@ nsGenericHTMLElement::SetUndoScopeIntern
 bool
 nsGenericHTMLElement::TouchEventsEnabled(JSContext* /* unused */, JSObject* /* unused */)
 {
   return TouchEvent::PrefEnabled();
 }
 
 //----------------------------------------------------------------------
 
-nsGenericHTMLFormElement::nsGenericHTMLFormElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+nsGenericHTMLFormElement::nsGenericHTMLFormElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
   , mForm(nullptr)
   , mFieldSet(nullptr)
 {
   // We should add the NS_EVENT_STATE_ENABLED bit here as needed, but
   // that depends on our type, which is not initialized yet.  So we
   // have to do this in subclasses.
 }
@@ -2975,17 +2975,17 @@ nsGenericHTMLElement::ChangeEditableStat
   nsAutoScriptBlocker scriptBlocker;
   MakeContentDescendantsEditable(this, document);
 }
 
 
 //----------------------------------------------------------------------
 
 nsGenericHTMLFormElementWithState::nsGenericHTMLFormElementWithState(
-    already_AddRefed<nsINodeInfo> aNodeInfo
+    already_AddRefed<nsINodeInfo>& aNodeInfo
   )
   : nsGenericHTMLFormElement(aNodeInfo)
 {
   mStateKey.SetIsVoid(true);
 }
 
 nsresult
 nsGenericHTMLFormElementWithState::GenerateStateKey()
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -51,17 +51,17 @@ typedef nsMappedAttributeElement nsGener
 
 /**
  * A common superclass for HTML elements
  */
 class nsGenericHTMLElement : public nsGenericHTMLElementBase,
                              public nsIDOMHTMLElement
 {
 public:
-  nsGenericHTMLElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  nsGenericHTMLElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsGenericHTMLElementBase(aNodeInfo),
       mScrollgrab(false)
   {
     NS_ASSERTION(mNodeInfo->NamespaceID() == kNameSpaceID_XHTML,
                  "Unexpected namespace");
     AddStatesSilently(NS_EVENT_STATE_LTR);
     SetFlags(NODE_HAS_DIRECTION_LTR);
   }
@@ -1274,17 +1274,17 @@ ASSERT_NODE_FLAGS_SPACE(ELEMENT_TYPE_SPE
 
 /**
  * A helper class for form elements that can contain children
  */
 class nsGenericHTMLFormElement : public nsGenericHTMLElement,
                                  public nsIFormControl
 {
 public:
-  nsGenericHTMLFormElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsGenericHTMLFormElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~nsGenericHTMLFormElement();
 
   NS_DECL_ISUPPORTS_INHERITED
 
   nsINode* GetParentObject() const;
 
   virtual bool IsNodeOfType(uint32_t aFlags) const MOZ_OVERRIDE;
   virtual void SaveSubtreeState() MOZ_OVERRIDE;
@@ -1430,17 +1430,17 @@ protected:
 
   /* This is a pointer to our closest fieldset parent if any */
   mozilla::dom::HTMLFieldSetElement* mFieldSet;
 };
 
 class nsGenericHTMLFormElementWithState : public nsGenericHTMLFormElement
 {
 public:
-  nsGenericHTMLFormElementWithState(already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsGenericHTMLFormElementWithState(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   /**
    * Get the presentation state for a piece of content, or create it if it does
    * not exist.  Generally used by SaveState().
    */
   nsPresState* GetPrimaryPresState();
 
   /**
@@ -1697,51 +1697,51 @@ protected:
  */
 #define NS_DECLARE_NS_NEW_HTML_ELEMENT(_elementName)                       \
 namespace mozilla {                                                        \
 namespace dom {                                                            \
 class HTML##_elementName##Element;                                         \
 }                                                                          \
 }                                                                          \
 nsGenericHTMLElement*                                                      \
-NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo> aNodeInfo, \
+NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo>&& aNodeInfo, \
                                   mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
 
 #define NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(_elementName)             \
 inline nsGenericHTMLElement*                                               \
-NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo> aNodeInfo, \
+NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo>&& aNodeInfo, \
                                   mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER) \
 {                                                                          \
-  return NS_NewHTMLSharedElement(aNodeInfo, aFromParser);                  \
+  return NS_NewHTMLSharedElement(mozilla::Move(aNodeInfo), aFromParser);   \
 }
 
 /**
  * A macro to implement the NS_NewHTMLXXXElement() functions.
  */
 #define NS_IMPL_NS_NEW_HTML_ELEMENT(_elementName)                            \
 nsGenericHTMLElement*                                                        \
-NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo> aNodeInfo,   \
+NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo>&& aNodeInfo, \
                                   mozilla::dom::FromParser aFromParser)      \
 {                                                                            \
   return new mozilla::dom::HTML##_elementName##Element(aNodeInfo);           \
 }
 
 #define NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(_elementName)               \
 nsGenericHTMLElement*                                                        \
-NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo> aNodeInfo,   \
+NS_NewHTML##_elementName##Element(already_AddRefed<nsINodeInfo>&& aNodeInfo, \
                                   mozilla::dom::FromParser aFromParser)      \
 {                                                                            \
   return new mozilla::dom::HTML##_elementName##Element(aNodeInfo,            \
                                                        aFromParser);         \
 }
 
 // Here, we expand 'NS_DECLARE_NS_NEW_HTML_ELEMENT()' by hand.
 // (Calling the macro directly (with no args) produces compiler warnings.)
 nsGenericHTMLElement*
-NS_NewHTMLElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLElement(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                   mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
 
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Shared)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedList)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedObject)
 
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Anchor)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Area)
--- a/content/html/content/src/nsGenericHTMLFrameElement.h
+++ b/content/html/content/src/nsGenericHTMLFrameElement.h
@@ -22,17 +22,17 @@ class nsXULElement;
 /**
  * A helper class for frame elements
  */
 class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
                                   public nsIFrameLoaderOwner,
                                   public nsIMozBrowserFrame
 {
 public:
-  nsGenericHTMLFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  nsGenericHTMLFrameElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                             mozilla::dom::FromParser aFromParser)
     : nsGenericHTMLElement(aNodeInfo)
     , mNetworkCreated(aFromParser == mozilla::dom::FROM_PARSER_NETWORK)
     , mBrowserFrameListenersRegistered(false)
     , mFrameLoaderCreationDisallowed(false)
   {
   }
 
--- a/content/html/content/test/test_ignoreuserfocus.html
+++ b/content/html/content/test/test_ignoreuserfocus.html
@@ -138,13 +138,15 @@
         document.body.appendChild(witness2);
       }
       addEventListener("load", function() {
         SpecialPowers.addPermission("browser", true, document);
         SpecialPowers.pushPrefEnv({
           "set": [
             ["dom.mozBrowserFramesEnabled", true]
           ]
-        }, runTest);
+        }, function() {
+          SimpleTest.waitForFocus(runTest);
+        });
       });
     </script>
   </body>
 </html>
--- a/content/html/document/src/ImageDocument.cpp
+++ b/content/html/document/src/ImageDocument.cpp
@@ -318,17 +318,17 @@ ImageDocument::GetImageRequest(ErrorResu
   }
   return imageRequest.forget();
 }
 
 NS_IMETHODIMP
 ImageDocument::GetImageRequest(imgIRequest** aImageRequest)
 {
   ErrorResult rv;
-  *aImageRequest = GetImageRequest(rv).get();
+  *aImageRequest = GetImageRequest(rv).take();
   return rv.ErrorCode();
 }
 
 void
 ImageDocument::ShrinkToFit()
 {
   if (!mImageContent) {
     return;
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -82,21 +82,21 @@
 #include "nsTextNode.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 //----------------------------------------------------------------------
 
 typedef nsGenericHTMLElement*
-  (*contentCreatorCallback)(already_AddRefed<nsINodeInfo>,
+  (*contentCreatorCallback)(already_AddRefed<nsINodeInfo>&&,
                             FromParser aFromParser);
 
 nsGenericHTMLElement*
-NS_NewHTMLNOTUSEDElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLNOTUSEDElement(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                          FromParser aFromParser)
 {
   NS_NOTREACHED("The element ctor should never be called");
   return nullptr;
 }
 
 #define HTML_TAG(_tag, _classname) NS_NewHTML##_classname##Element,
 #define HTML_HTMLELEMENT_TAG(_tag) NS_NewHTMLElement,
@@ -237,17 +237,17 @@ public:
   };
 
   Node* mStack;
   int32_t mStackSize;
   int32_t mStackPos;
 };
 
 nsresult
-NS_NewHTMLElement(Element** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewHTMLElement(Element** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo,
                   FromParser aFromParser)
 {
   *aResult = nullptr;
 
   nsCOMPtr<nsINodeInfo> nodeInfo = aNodeInfo;
 
   nsIParserService* parserService = nsContentUtils::GetParserService();
   if (!parserService)
@@ -258,53 +258,54 @@ NS_NewHTMLElement(Element** aResult, alr
   NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML), 
                "Trying to HTML elements that don't have the XHTML namespace");
 
   // Per the Custom Element specification, unknown tags that are valid custom
   // element names should be HTMLElement instead of HTMLUnknownElement.
   int32_t tag = parserService->HTMLCaseSensitiveAtomTagToId(name);
   if (tag == eHTMLTag_userdefined &&
       nsContentUtils::IsCustomElementName(name)) {
+    nsIDocument* doc = nodeInfo->GetDocument();
+
     NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser));
     if (!*aResult) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
-    nsIDocument* doc = aNodeInfo.get()->GetDocument();
-
     // Element may be unresolved at this point.
     doc->RegisterUnresolvedElement(*aResult);
 
     // Try to enqueue a created callback. The custom element data will be set
     // and created callback will be enqueued if the custom element type
     // has already been registered.
     doc->EnqueueLifecycleCallback(nsIDocument::eCreated, *aResult);
 
     return NS_OK;
   }
 
   *aResult = CreateHTMLElement(tag,
-                               nodeInfo.forget(), aFromParser).get();
+                               nodeInfo.forget(), aFromParser).take();
   return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
 already_AddRefed<nsGenericHTMLElement>
-CreateHTMLElement(uint32_t aNodeType, already_AddRefed<nsINodeInfo> aNodeInfo,
+CreateHTMLElement(uint32_t aNodeType,
+                  already_AddRefed<nsINodeInfo>&& aNodeInfo,
                   FromParser aFromParser)
 {
   NS_ASSERTION(aNodeType <= NS_HTML_TAG_MAX ||
                aNodeType == eHTMLTag_userdefined,
                "aNodeType is out of bounds");
 
   contentCreatorCallback cb = sContentCreatorCallbacks[aNodeType];
 
   NS_ASSERTION(cb != NS_NewHTMLNOTUSEDElement,
                "Don't know how to construct tag element!");
 
-  nsRefPtr<nsGenericHTMLElement> result = cb(aNodeInfo, aFromParser);
+  nsRefPtr<nsGenericHTMLElement> result = cb(Move(aNodeInfo), aFromParser);
 
   return result.forget();
 }
 
 //----------------------------------------------------------------------
 
 SinkContext::SinkContext(HTMLContentSink* aSink)
   : mSink(aSink),
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -1315,32 +1315,32 @@ nsHTMLDocument::Open(const nsAString& aC
                      const nsAString& aFeatures,
                      JSContext* cx, uint8_t aOptionalArgCount,
                      nsISupports** aReturn)
 {
   // When called with 3 or more arguments, document.open() calls window.open().
   if (aOptionalArgCount > 2) {
     ErrorResult rv;
     *aReturn = Open(cx, aContentTypeOrUrl, aReplaceOrName, aFeatures,
-                    false, rv).get();
+                    false, rv).take();
     return rv.ErrorCode();
   }
 
   nsString type;
   if (aOptionalArgCount > 0) {
     type = aContentTypeOrUrl;
   } else {
     type.AssignLiteral("text/html");
   }
   nsString replace;
   if (aOptionalArgCount > 1) {
     replace = aReplaceOrName;
   }
   ErrorResult rv;
-  *aReturn = Open(cx, type, replace, rv).get();
+  *aReturn = Open(cx, type, replace, rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<nsIDOMWindow>
 nsHTMLDocument::Open(JSContext* /* unused */,
                      const nsAString& aURL,
                      const nsAString& aName,
                      const nsAString& aFeatures,
@@ -1905,17 +1905,17 @@ nsHTMLDocument::UseExistingNameString(ns
 {
   return const_cast<nsString*>(aName);
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::GetElementsByName(const nsAString& aElementName,
                                   nsIDOMNodeList** aReturn)
 {
-  *aReturn = GetElementsByName(aElementName).get();
+  *aReturn = GetElementsByName(aElementName).take();
   return NS_OK;
 }
 
 static bool MatchItems(nsIContent* aContent, int32_t aNameSpaceID, 
                        nsIAtom* aAtom, void* aData)
 {
   if (!(aContent->IsElement() && aContent->AsElement()->IsHTML())) {
     return false;
@@ -1965,30 +1965,31 @@ static void* CreateTokens(nsINode* aRoot
   // parse the tokens
   while (iter != end) {
     nsAString::const_iterator start(iter);
 
     do {
       ++iter;
     } while (iter != end && !nsContentUtils::IsHTMLWhitespace(*iter));
 
-    tokens->AppendElement(do_GetAtom(Substring(start, iter)));
+    nsCOMPtr<nsIAtom> token = do_GetAtom(Substring(start, iter));
+    tokens->AppendElement(token);
 
     // skip whitespace
     while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) {
       ++iter;
     }
   }
   return tokens;
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::GetItems(const nsAString& types, nsIDOMNodeList** aReturn)
 {
-  *aReturn = GetItems(types).get();
+  *aReturn = GetItems(types).take();
   return NS_OK;
 }
 
 already_AddRefed<nsINodeList>
 nsHTMLDocument::GetItems(const nsAString& aTypeNames)
 {
   return NS_GetFuncStringNodeList(this, MatchItems, DestroyTokens, CreateTokens,
                                   aTypeNames);
@@ -2148,17 +2149,17 @@ nsHTMLDocument::Embeds()
   }
   return mEmbeds;
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::GetSelection(nsISelection** aReturn)
 {
   ErrorResult rv;
-  *aReturn = GetSelection(rv).get();
+  *aReturn = GetSelection(rv).take();
   return rv.ErrorCode();
 }
 
 already_AddRefed<Selection>
 nsHTMLDocument::GetSelection(ErrorResult& rv)
 {
   nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(GetScopeObject());
   nsCOMPtr<nsPIDOMWindow> pwin = do_QueryInterface(window);
--- a/content/mathml/content/src/nsMathMLElement.cpp
+++ b/content/mathml/content/src/nsMathMLElement.cpp
@@ -66,17 +66,24 @@ ReportParseErrorNoTag(const nsString& aV
     { aValue.get(), aAtom->GetUTF16String() };
   return nsContentUtils::
          ReportToConsole(nsIScriptError::errorFlag,
                          NS_LITERAL_CSTRING("MathML"), aDocument,
                          nsContentUtils::eMATHML_PROPERTIES,
                          "AttributeParsingErrorNoTag", argv, 2);
 }
 
-nsMathMLElement::nsMathMLElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+nsMathMLElement::nsMathMLElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
+: nsMathMLElementBase(aNodeInfo),
+  ALLOW_THIS_IN_INITIALIZER_LIST(Link(this)),
+  mIncrementScriptLevel(false)
+{
+}
+
+nsMathMLElement::nsMathMLElement(already_AddRefed<nsINodeInfo>&& aNodeInfo)
 : nsMathMLElementBase(aNodeInfo),
   ALLOW_THIS_IN_INITIALIZER_LIST(Link(this)),
   mIncrementScriptLevel(false)
 {
 }
 
 nsresult
 nsMathMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
--- a/content/mathml/content/src/nsMathMLElement.h
+++ b/content/mathml/content/src/nsMathMLElement.h
@@ -20,17 +20,18 @@ typedef nsMappedAttributeElement nsMathM
 /*
  * The base class for MathML elements.
  */
 class nsMathMLElement MOZ_FINAL : public nsMathMLElementBase,
                                   public nsIDOMElement,
                                   public mozilla::dom::Link
 {
 public:
-  nsMathMLElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsMathMLElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
+  nsMathMLElement(already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
   // Implementation of nsISupports is inherited from nsMathMLElementBase
   NS_DECL_ISUPPORTS_INHERITED
 
   // Forward implementations of parent interfaces of nsMathMLElement to 
   // our base class
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
   NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
--- a/content/mathml/content/src/nsMathMLElementFactory.cpp
+++ b/content/mathml/content/src/nsMathMLElementFactory.cpp
@@ -6,17 +6,18 @@
 #include "nsContentCreatorFunctions.h"
 #include "nsGkAtoms.h"
 #include "nsMathMLElement.h"
 
 using namespace mozilla::dom;
 
 // MathML Element Factory (declared in nsContentCreatorFunctions.h)
 nsresult
-NS_NewMathMLElement(Element** aResult, already_AddRefed<nsINodeInfo> aNodeInfo)
+NS_NewMathMLElement(Element** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo)
 {
-  aNodeInfo.get()->SetIDAttributeAtom(nsGkAtoms::id);
+  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
+  ni->SetIDAttributeAtom(nsGkAtoms::id);
 
-  nsMathMLElement* it = new nsMathMLElement(aNodeInfo);
+  nsMathMLElement* it = new nsMathMLElement(ni.forget());
 
   NS_ADDREF(*aResult = it);
   return NS_OK;
 }
--- a/content/media/AudioChannelFormat.h
+++ b/content/media/AudioChannelFormat.h
@@ -3,18 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef MOZILLA_AUDIOCHANNELFORMAT_H_
 #define MOZILLA_AUDIOCHANNELFORMAT_H_
 
 #include <stdint.h>
 
-template <class T>
-class nsTArray;
+#include "nsTArrayForwardDeclare.h"
 
 namespace mozilla {
 
 /*
  * This file provides utilities for upmixing and downmixing channels.
  *
  * The channel layouts, upmixing and downmixing are consistent with the
  * Web Audio spec.
--- a/content/media/AudioNodeStream.cpp
+++ b/content/media/AudioNodeStream.cpp
@@ -144,22 +144,22 @@ AudioNodeStream::SetThreeDPointParameter
     uint32_t mIndex;
   };
 
   MOZ_ASSERT(this);
   GraphImpl()->AppendMessage(new Message(this, aIndex, aValue));
 }
 
 void
-AudioNodeStream::SetBuffer(already_AddRefed<ThreadSharedFloatArrayBufferList> aBuffer)
+AudioNodeStream::SetBuffer(already_AddRefed<ThreadSharedFloatArrayBufferList>&& aBuffer)
 {
   class Message : public ControlMessage {
   public:
     Message(AudioNodeStream* aStream,
-            already_AddRefed<ThreadSharedFloatArrayBufferList> aBuffer)
+            already_AddRefed<ThreadSharedFloatArrayBufferList>& aBuffer)
       : ControlMessage(aStream), mBuffer(aBuffer) {}
     virtual void Run()
     {
       static_cast<AudioNodeStream*>(mStream)->Engine()->
           SetBuffer(mBuffer.forget());
     }
     nsRefPtr<ThreadSharedFloatArrayBufferList> mBuffer;
   };
--- a/content/media/AudioNodeStream.h
+++ b/content/media/AudioNodeStream.h
@@ -73,17 +73,17 @@ public:
    * This time is converted to a time relative to this stream when it's set.
    */
   void SetStreamTimeParameter(uint32_t aIndex, AudioContext* aContext,
                               double aStreamTime);
   void SetDoubleParameter(uint32_t aIndex, double aValue);
   void SetInt32Parameter(uint32_t aIndex, int32_t aValue);
   void SetTimelineParameter(uint32_t aIndex, const dom::AudioParamTimeline& aValue);
   void SetThreeDPointParameter(uint32_t aIndex, const dom::ThreeDPoint& aValue);
-  void SetBuffer(already_AddRefed<ThreadSharedFloatArrayBufferList> aBuffer);
+  void SetBuffer(already_AddRefed<ThreadSharedFloatArrayBufferList>&& aBuffer);
   // This consumes the contents of aData.  aData will be emptied after this returns.
   void SetRawArrayData(nsTArray<float>& aData);
   void SetChannelMixingParameters(uint32_t aNumberOfChannels,
                                   ChannelCountMode aChannelCountMoe,
                                   ChannelInterpretation aChannelInterpretation);
   ChannelInterpretation GetChannelInterpretation()
   {
     return mChannelInterpretation;
--- a/content/media/MediaRecorder.cpp
+++ b/content/media/MediaRecorder.cpp
@@ -154,17 +154,17 @@ class MediaRecorder::Session: public nsI
     nsRefPtr<Session> mSession;
   };
 
   // Main thread task.
   // To delete RecordingSession object.
   class DestroyRunnable : public nsRunnable
   {
   public:
-    DestroyRunnable(const already_AddRefed<Session> &aSession)
+    DestroyRunnable(already_AddRefed<Session>&& aSession)
       : mSession(aSession) {}
 
     NS_IMETHODIMP Run()
     {
       MOZ_ASSERT(NS_IsMainThread() && mSession.get());
       MediaRecorder *recorder = mSession->mRecorder;
 
       // SourceMediaStream is ended, and send out TRACK_EVENT_END notification.
@@ -534,27 +534,45 @@ MediaRecorder::Resume(ErrorResult& aResu
     if (NS_FAILED(rv)) {
       NotifyError(rv);
       return;
     }
     mState = RecordingState::Recording;
   }
 }
 
+class CreateAndDispatchBlobEventRunnable : public nsRunnable {
+  nsCOMPtr<nsIDOMBlob> mBlob;
+  nsRefPtr<MediaRecorder> mRecorder;
+public:
+  CreateAndDispatchBlobEventRunnable(already_AddRefed<nsIDOMBlob>&& aBlob,
+                                     MediaRecorder* aRecorder)
+    : mBlob(aBlob), mRecorder(aRecorder)
+  { }
+
+  NS_IMETHOD
+  Run();
+};
+
+NS_IMETHODIMP
+CreateAndDispatchBlobEventRunnable::Run()
+{
+  return mRecorder->CreateAndDispatchBlobEvent(mBlob.forget());
+}
+
 void
 MediaRecorder::RequestData(ErrorResult& aResult)
 {
   if (mState != RecordingState::Recording) {
     aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
   NS_DispatchToMainThread(
-    NS_NewRunnableMethodWithArg<const already_AddRefed<nsIDOMBlob> >(this,
-      &MediaRecorder::CreateAndDispatchBlobEvent, mSession->GetEncodedData()),
+    new CreateAndDispatchBlobEventRunnable(mSession->GetEncodedData(), this),
     NS_DISPATCH_NORMAL);
 }
 
 JSObject*
 MediaRecorder::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return MediaRecorderBinding::Wrap(aCx, aScope, this);
 }
@@ -575,17 +593,17 @@ MediaRecorder::Constructor(const GlobalO
     return nullptr;
   }
 
   nsRefPtr<MediaRecorder> object = new MediaRecorder(aStream, ownerWindow);
   return object.forget();
 }
 
 nsresult
-MediaRecorder::CreateAndDispatchBlobEvent(const already_AddRefed<nsIDOMBlob> &aBlob)
+MediaRecorder::CreateAndDispatchBlobEvent(already_AddRefed<nsIDOMBlob>&& aBlob)
 {
   NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
 
   if (!CheckPrincipal()) {
     // Media is not same-origin, don't allow the data out.
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
--- a/content/media/MediaRecorder.h
+++ b/content/media/MediaRecorder.h
@@ -32,16 +32,17 @@ namespace dom {
  * Thread model:
  * When the recorder starts, it creates a "Media Encoder" thread to read data from MediaEncoder object and store buffer in EncodedBufferCache object.
  * Also extract the encoded data and create blobs on every timeslice passed from start function or RequestData function called by UA.
  */
 
 class MediaRecorder : public nsDOMEventTargetHelper
 {
   class Session;
+  friend class CreateAndDispatchBlobEventRunnable;
 
 public:
   MediaRecorder(DOMMediaStream&, nsPIDOMWindow* aOwnerWindow);
   virtual ~MediaRecorder();
 
   // nsWrapperCache
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
@@ -80,17 +81,17 @@ public:
   IMPL_EVENT_HANDLER(dataavailable)
   IMPL_EVENT_HANDLER(error)
   IMPL_EVENT_HANDLER(stop)
   IMPL_EVENT_HANDLER(warning)
 
 protected:
   MediaRecorder& operator = (const MediaRecorder& x) MOZ_DELETE;
   // Create dataavailable event with Blob data and it runs in main thread
-  nsresult CreateAndDispatchBlobEvent(const already_AddRefed<nsIDOMBlob> &aBlob);
+  nsresult CreateAndDispatchBlobEvent(already_AddRefed<nsIDOMBlob>&& aBlob);
   // Creating a simple event to notify UA simple event.
   void DispatchSimpleEvent(const nsAString & aStr);
   // Creating a error event with message.
   void NotifyError(nsresult aRv);
   // Check if the recorder's principal is the subsume of mediaStream
   bool CheckPrincipal();
   // Set encoded MIME type.
   void SetMimeType(const nsString &aMimeType);
--- a/content/media/MediaStreamGraph.cpp
+++ b/content/media/MediaStreamGraph.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MediaStreamGraphImpl.h"
 #include "mozilla/LinkedList.h"
+#include "mozilla/unused.h"
 
 #include "AudioSegment.h"
 #include "VideoSegment.h"
 #include "nsContentUtils.h"
 #include "nsIAppShell.h"
 #include "nsIObserver.h"
 #include "nsServiceManagerUtils.h"
 #include "nsWidgetsCID.h"
@@ -19,16 +20,17 @@
 #include "ImageContainer.h"
 #include "AudioChannelCommon.h"
 #include "AudioNodeEngine.h"
 #include "AudioNodeStream.h"
 #include "AudioNodeExternalInputStream.h"
 #include <algorithm>
 #include "DOMMediaStream.h"
 #include "GeckoProfiler.h"
+#include "mozilla/unused.h"
 
 using namespace mozilla::layers;
 using namespace mozilla::dom;
 using namespace mozilla::gfx;
 
 namespace mozilla {
 
 #ifdef PR_LOGGING
@@ -2382,17 +2384,17 @@ ProcessedMediaStream::AllocateInputPort(
     Message(MediaInputPort* aPort)
       : ControlMessage(aPort->GetDestination()),
         mPort(aPort) {}
     virtual void Run()
     {
       mPort->Init();
       // The graph holds its reference implicitly
       mPort->GraphImpl()->SetStreamOrderDirty();
-      mPort.forget();
+      unused << mPort.forget();
     }
     virtual void RunDuringShutdown()
     {
       Run();
     }
     nsRefPtr<MediaInputPort> mPort;
   };
   nsRefPtr<MediaInputPort> port = new MediaInputPort(aStream, this, aFlags,
--- a/content/media/VideoSegment.cpp
+++ b/content/media/VideoSegment.cpp
@@ -7,17 +7,18 @@
 
 #include "gfx2DGlue.h"
 #include "ImageContainer.h"
 
 namespace mozilla {
 
 using namespace layers;
 
-VideoFrame::VideoFrame(already_AddRefed<Image> aImage, const gfxIntSize& aIntrinsicSize)
+VideoFrame::VideoFrame(already_AddRefed<Image>& aImage,
+                       const gfxIntSize& aIntrinsicSize)
   : mImage(aImage), mIntrinsicSize(aIntrinsicSize), mForceBlack(false)
 {}
 
 VideoFrame::VideoFrame()
   : mIntrinsicSize(0, 0), mForceBlack(false)
 {}
 
 VideoFrame::~VideoFrame()
@@ -39,17 +40,18 @@ VideoFrame::TakeFrom(VideoFrame* aFrame)
 
 VideoChunk::VideoChunk()
 {}
 
 VideoChunk::~VideoChunk()
 {}
 
 void
-VideoSegment::AppendFrame(already_AddRefed<Image> aImage, TrackTicks aDuration,
+VideoSegment::AppendFrame(already_AddRefed<Image>&& aImage,
+                          TrackTicks aDuration,
                           const IntSize& aIntrinsicSize)
 {
   VideoChunk* chunk = AppendChunk(aDuration);
   VideoFrame frame(aImage, ThebesIntSize(aIntrinsicSize));
   chunk->mFrame.TakeFrom(&frame);
 }
 
 VideoSegment::VideoSegment()
--- a/content/media/VideoSegment.h
+++ b/content/media/VideoSegment.h
@@ -17,17 +17,17 @@ namespace mozilla {
 namespace layers {
 class Image;
 }
 
 class VideoFrame {
 public:
   typedef mozilla::layers::Image Image;
 
-  VideoFrame(already_AddRefed<Image> aImage, const gfxIntSize& aIntrinsicSize);
+  VideoFrame(already_AddRefed<Image>& aImage, const gfxIntSize& aIntrinsicSize);
   VideoFrame();
   ~VideoFrame();
 
   bool operator==(const VideoFrame& aFrame) const
   {
     return mIntrinsicSize == aFrame.mIntrinsicSize &&
            mForceBlack == aFrame.mForceBlack &&
            ((mForceBlack && aFrame.mForceBlack) || mImage == aFrame.mImage);
@@ -84,17 +84,17 @@ struct VideoChunk {
 class VideoSegment : public MediaSegmentBase<VideoSegment, VideoChunk> {
 public:
   typedef mozilla::layers::Image Image;
   typedef mozilla::gfx::IntSize IntSize;
 
   VideoSegment();
   ~VideoSegment();
 
-  void AppendFrame(already_AddRefed<Image> aImage, TrackTicks aDuration,
+  void AppendFrame(already_AddRefed<Image>&& aImage, TrackTicks aDuration,
                    const IntSize& aIntrinsicSize);
   const VideoFrame* GetFrameAt(TrackTicks aOffset, TrackTicks* aStart = nullptr)
   {
     VideoChunk* c = FindChunkContaining(aOffset, aStart);
     if (!c) {
       return nullptr;
     }
     return &c->mFrame;
--- a/content/media/gstreamer/GStreamerReader-0.10.cpp
+++ b/content/media/gstreamer/GStreamerReader-0.10.cpp
@@ -41,18 +41,18 @@ GstFlowReturn GStreamerReader::AllocateV
                                                        GstBuffer** aBuf,
                                                        nsRefPtr<PlanarYCbCrImage>& aImage)
 {
   /* allocate an image using the container */
   ImageContainer* container = mDecoder->GetImageContainer();
   if (container == nullptr) {
     return GST_FLOW_ERROR;
   }
-  PlanarYCbCrImage* img = reinterpret_cast<PlanarYCbCrImage*>(container->CreateImage(ImageFormat::PLANAR_YCBCR).get());
-  nsRefPtr<PlanarYCbCrImage> image = dont_AddRef(img);
+  nsRefPtr<PlanarYCbCrImage> image =
+    container->CreateImage(ImageFormat::PLANAR_YCBCR).downcast<PlanarYCbCrImage>();
 
   /* prepare a GstBuffer pointing to the underlying PlanarYCbCrImage buffer */
   GstBuffer* buf = GST_BUFFER(gst_moz_video_buffer_new());
   GST_BUFFER_SIZE(buf) = aSize;
   /* allocate the actual YUV buffer */
   GST_BUFFER_DATA(buf) = image->AllocateAndGetNewBuffer(aSize);
 
   aImage = image;
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -465,17 +465,17 @@ AudioContext::DecodeAudioData(const Arra
     failureCallback = &aFailureCallback.Value();
   }
   nsRefPtr<WebAudioDecodeJob> job(
     new WebAudioDecodeJob(contentType, this, aBuffer,
                           &aSuccessCallback, failureCallback));
   mDecoder.AsyncDecodeMedia(contentType.get(),
                             aBuffer.Data(), aBuffer.Length(), *job);
   // Transfer the ownership to mDecodeJobs
-  mDecodeJobs.AppendElement(job.forget());
+  mDecodeJobs.AppendElement(job);
 }
 
 void
 AudioContext::RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob)
 {
   mDecodeJobs.RemoveElement(aDecodeJob);
 }
 
--- a/content/media/webrtc/MediaEngineDefault.cpp
+++ b/content/media/webrtc/MediaEngineDefault.cpp
@@ -262,22 +262,18 @@ MediaEngineDefaultVideoSource::NotifyPul
 
   // Note: we're not giving up mImage here
   nsRefPtr<layers::Image> image = mImage;
   TrackTicks target = TimeToTicksRoundUp(USECS_PER_S, aDesiredTime);
   TrackTicks delta = target - aLastEndTime;
 
   if (delta > 0) {
     // nullptr images are allowed
-    if (image) {
-      segment.AppendFrame(image.forget(), delta,
-                          IntSize(mOpts.mWidth, mOpts.mHeight));
-    } else {
-      segment.AppendFrame(nullptr, delta, IntSize(0, 0));
-    }
+    IntSize size(image ? mOpts.mWidth : 0, image ? mOpts.mHeight : 0);
+    segment.AppendFrame(image.forget(), delta, size);
     // This can fail if either a) we haven't added the track yet, or b)
     // we've removed or finished the track.
     if (aSource->AppendToTrack(aID, &segment)) {
       aLastEndTime = target;
     }
   }
 }
 
--- a/content/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/content/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -151,22 +151,18 @@ NotifyPull(MediaStreamGraph*, SourceMedi
   MonitorAutoLock mon(mMonitor);
 
   // Note: we're not giving up mImage here
   nsRefPtr<layers::CairoImage> image = mImage;
   TrackTicks target = TimeToTicksRoundUp(USECS_PER_S, aDesiredTime);
   TrackTicks delta = target - aLastEndTime;
   if (delta > 0) {
     // nullptr images are allowed
-    if (image) {
-      gfx::IntSize size = image->GetSize();
-      segment.AppendFrame(image.forget(), delta, size);
-    } else {
-      segment.AppendFrame(nullptr, delta, IntSize(0, 0));
-    }
+    gfx::IntSize size = image ? image->GetSize() : IntSize(0, 0);
+    segment.AppendFrame(image.forget().downcast<layers::Image>(), delta, size);
     // This can fail if either a) we haven't added the track yet, or b)
     // we've removed or finished the track.
     if (aSource->AppendToTrack(aID, &(segment))) {
       aLastEndTime = target;
     }
   }
 }
 
--- a/content/media/webrtc/MediaEngineWebRTCVideo.cpp
+++ b/content/media/webrtc/MediaEngineWebRTCVideo.cpp
@@ -150,21 +150,18 @@ MediaEngineWebRTCVideoSource::NotifyPull
   // cameras often don't return the requested frame rate especially in low
   // light; we should consider surfacing this so that we can switch to a
   // lower resolution (which may up the frame rate)
 
   // Don't append if we've already provided a frame that supposedly goes past the current aDesiredTime
   // Doing so means a negative delta and thus messes up handling of the graph
   if (delta > 0) {
     // nullptr images are allowed
-    if (image) {
-      segment.AppendFrame(image.forget(), delta, IntSize(mWidth, mHeight));
-    } else {
-      segment.AppendFrame(nullptr, delta, IntSize(0, 0));
-    }
+    IntSize size(image ? mWidth : 0, image ? mHeight : 0);
+    segment.AppendFrame(image.forget(), delta, size);
     // This can fail if either a) we haven't added the track yet, or b)
     // we've removed or finished the track.
     if (aSource->AppendToTrack(aID, &(segment))) {
       aLastEndTime = target;
     }
   }
 }
 
--- a/content/media/webspeech/recognition/SpeechRecognition.cpp
+++ b/content/media/webspeech/recognition/SpeechRecognition.cpp
@@ -796,45 +796,45 @@ SpeechRecognition::FillSamplesBuffer(con
  * chunks of equal size. The chunks are stored in the array
  * received as argument.
  * Returns the offset of the end of the last chunk that was
  * created.
  */
 uint32_t
 SpeechRecognition::SplitSamplesBuffer(const int16_t* aSamplesBuffer,
                                       uint32_t aSampleCount,
-                                      nsTArray<already_AddRefed<SharedBuffer> >& aResult)
+                                      nsTArray<nsRefPtr<SharedBuffer>>& aResult)
 {
   uint32_t chunkStart = 0;
 
   while (chunkStart + mAudioSamplesPerChunk <= aSampleCount) {
     nsRefPtr<SharedBuffer> chunk =
       SharedBuffer::Create(mAudioSamplesPerChunk * sizeof(int16_t));
 
     memcpy(chunk->Data(), aSamplesBuffer + chunkStart,
            mAudioSamplesPerChunk * sizeof(int16_t));
 
-    aResult.AppendElement(chunk.forget());
+    aResult.AppendElement(chunk);
     chunkStart += mAudioSamplesPerChunk;
   }
 
   return chunkStart;
 }
 
 AudioSegment*
-SpeechRecognition::CreateAudioSegment(nsTArray<already_AddRefed<SharedBuffer> >& aChunks)
+SpeechRecognition::CreateAudioSegment(nsTArray<nsRefPtr<SharedBuffer>>& aChunks)
 {
   AudioSegment* segment = new AudioSegment();
   for (uint32_t i = 0; i < aChunks.Length(); ++i) {
-    const int16_t* chunkData =
-      static_cast<const int16_t*>(aChunks[i].get()->Data());
+    nsRefPtr<SharedBuffer> buffer = aChunks[i];
+    const int16_t* chunkData = static_cast<const int16_t*>(buffer->Data());
 
     nsAutoTArray<const int16_t*, 1> channels;
     channels.AppendElement(chunkData);
-    segment->AppendFrames(aChunks[i], channels, mAudioSamplesPerChunk);
+    segment->AppendFrames(buffer.forget(), channels, mAudioSamplesPerChunk);
   }
 
   return segment;
 }
 
 void
 SpeechRecognition::FeedAudioData(already_AddRefed<SharedBuffer> aSamples,
                                  uint32_t aDuration,
@@ -849,24 +849,25 @@ SpeechRecognition::FeedAudioData(already
   // chunks, we must buffer and split them in chunks of mAudioSamplesPerChunk
   // (a multiple of Endpointer's frame size) before feeding to Endpointer.
 
   // ensure aSamples is deleted
   nsRefPtr<SharedBuffer> refSamples = aSamples;
 
   uint32_t samplesIndex = 0;
   const int16_t* samples = static_cast<int16_t*>(refSamples->Data());
-  nsAutoTArray<already_AddRefed<SharedBuffer>, 5> chunksToSend;
+  nsAutoTArray<nsRefPtr<SharedBuffer>, 5> chunksToSend;
 
   // fill up our buffer and make a chunk out of it, if possible
   if (mBufferedSamples > 0) {
     samplesIndex += FillSamplesBuffer(samples, aDuration);
 
     if (mBufferedSamples == mAudioSamplesPerChunk) {
-      chunksToSend.AppendElement(mAudioSamplesBuffer.forget());
+      chunksToSend.AppendElement(mAudioSamplesBuffer);
+      mAudioSamplesBuffer = nullptr;
       mBufferedSamples = 0;
     }
   }
 
   // create sample chunks of correct size
   if (samplesIndex < aDuration) {
     samplesIndex += SplitSamplesBuffer(samples + samplesIndex,
                                        aDuration - samplesIndex,
--- a/content/media/webspeech/recognition/SpeechRecognition.h
+++ b/content/media/webspeech/recognition/SpeechRecognition.h
@@ -125,18 +125,18 @@ public:
     EVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT,
     EVENT_RECOGNITIONSERVICE_FINAL_RESULT,
     EVENT_RECOGNITIONSERVICE_ERROR,
     EVENT_COUNT
   };
 
   void DispatchError(EventType aErrorType, SpeechRecognitionErrorCode aErrorCode, const nsAString& aMessage);
   uint32_t FillSamplesBuffer(const int16_t* aSamples, uint32_t aSampleCount);
-  uint32_t SplitSamplesBuffer(const int16_t* aSamplesBuffer, uint32_t aSampleCount, nsTArray<already_AddRefed<SharedBuffer> >& aResult);
-  AudioSegment* CreateAudioSegment(nsTArray<already_AddRefed<SharedBuffer> >& aChunks);
+  uint32_t SplitSamplesBuffer(const int16_t* aSamplesBuffer, uint32_t aSampleCount, nsTArray<nsRefPtr<SharedBuffer>>& aResult);
+  AudioSegment* CreateAudioSegment(nsTArray<nsRefPtr<SharedBuffer>>& aChunks);
   void FeedAudioData(already_AddRefed<SharedBuffer> aSamples, uint32_t aDuration, MediaStreamListener* aProvider);
 
   static struct TestConfig
   {
   public:
     bool mEnableTests;
     bool mFakeFSMEvents;
     bool mFakeRecognitionService;
--- a/content/media/webspeech/synth/pico/nsPicoService.cpp
+++ b/content/media/webspeech/synth/pico/nsPicoService.cpp
@@ -231,17 +231,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSISPEECHTASKCALLBACK
 
   NS_IMETHOD Run() MOZ_OVERRIDE;
 
   bool IsCurrentTask() { return mService->mCurrentTask == mTask; }
 
 private:
-  void DispatchSynthDataRunnable(already_AddRefed<SharedBuffer> aBuffer,
+  void DispatchSynthDataRunnable(already_AddRefed<SharedBuffer>&& aBuffer,
                                  size_t aBufferSize);
 
   nsCString mText;
 
   float mRate;
 
   float mPitch;
 
@@ -299,17 +299,17 @@ PicoCallbackRunnable::Run()
                                          &bytes_sent);
       PICO_ENSURE_SUCCESS("pico_putTextUtf8", status, NS_ERROR_FAILURE);
       // XXX: End speech task on error
       text_remaining -= bytes_sent;
       text_offset += bytes_sent;
     } else {
       // If we already fed all the text to the engine, send a zero length buffer
       // and quit.
-      DispatchSynthDataRunnable(nullptr, 0);
+      DispatchSynthDataRunnable(already_AddRefed<SharedBuffer>(nullptr), 0);
       break;
     }
 
     do {
       // Run this loop while the result of getData is STEP_BUSY, when it finishes
       // synthesizing audio for the given text, it returns STEP_IDLE. We then
       // break to the outer loop and feed more text, if there is any left.
       if (!IsCurrentTask()) {
@@ -334,22 +334,22 @@ PicoCallbackRunnable::Run()
     } while (status == PICO_STEP_BUSY);
   }
 
   return NS_OK;
 }
 
 void
 PicoCallbackRunnable::DispatchSynthDataRunnable(
-  already_AddRefed<SharedBuffer> aBuffer, size_t aBufferSize)
+  already_AddRefed<SharedBuffer>&& aBuffer, size_t aBufferSize)
 {
   class PicoSynthDataRunnable MOZ_FINAL : public nsRunnable
   {
   public:
-    PicoSynthDataRunnable(already_AddRefed<SharedBuffer> aBuffer,
+    PicoSynthDataRunnable(already_AddRefed<SharedBuffer>& aBuffer,
                           size_t aBufferSize, bool aFirstData,
                           PicoCallbackRunnable* aCallback)
       : mBuffer(aBuffer)
       , mBufferSize(aBufferSize)
       , mFirstData(aFirstData)
       , mCallback(aCallback) {
     }
 
@@ -531,20 +531,23 @@ nsPicoService::Init()
 
   bool hasMoreElements = false;
   rv = dirIterator->HasMoreElements(&hasMoreElements);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
   MonitorAutoLock autoLock(mVoicesMonitor);
 
   while (hasMoreElements && NS_SUCCEEDED(rv)) {
-    nsCOMPtr<nsIFile> voiceFile;
-    rv = dirIterator->GetNext(getter_AddRefs(voiceFile));
+    nsCOMPtr<nsISupports> supports;
+    rv = dirIterator->GetNext(getter_AddRefs(supports));
     MOZ_ASSERT(NS_SUCCEEDED(rv));
 
+    nsCOMPtr<nsIFile> voiceFile = do_QueryInterface(supports);
+    MOZ_ASSERT(voiceFile);
+
     nsAutoCString leafName;
     voiceFile->GetNativeLeafName(leafName);
 
     nsAutoString lang;
 
     if (GetVoiceFileLanguage(leafName, lang)) {
       nsAutoString uri;
       uri.AssignLiteral("urn:moz-tts:pico:");
--- a/content/svg/content/src/SVGAElement.cpp
+++ b/content/svg/content/src/SVGAElement.cpp
@@ -55,17 +55,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_ADDREF_INHERITED(SVGAElement, SVGAElementBase)
 NS_IMPL_RELEASE_INHERITED(SVGAElement, SVGAElementBase)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGAElement::SVGAElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGAElement::SVGAElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGAElementBase(aNodeInfo)
   , Link(MOZ_THIS_IN_INITIALIZER_LIST())
 {
 }
 
 already_AddRefed<SVGAnimatedString>
 SVGAElement::Href()
 {
--- a/content/svg/content/src/SVGAElement.h
+++ b/content/svg/content/src/SVGAElement.h
@@ -6,30 +6,30 @@
 #ifndef mozilla_dom_SVGAElement_h
 #define mozilla_dom_SVGAElement_h
 
 #include "Link.h"
 #include "nsSVGString.h"
 #include "mozilla/dom/SVGGraphicsElement.h"
 
 nsresult NS_NewSVGAElement(nsIContent **aResult,
-                           already_AddRefed<nsINodeInfo> aNodeInfo);
+                           already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGGraphicsElement SVGAElementBase;
 
 class SVGAElement MOZ_FINAL : public SVGAElementBase,
                               public Link
 {
 protected:
-  SVGAElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGAElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   friend nsresult (::NS_NewSVGAElement(nsIContent **aResult,
-                                       already_AddRefed<nsINodeInfo> aNodeInfo));
+                                       already_AddRefed<nsINodeInfo>&& aNodeInfo));
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGAElement, SVGAElementBase)
 
   // nsINode interface methods
--- a/content/svg/content/src/SVGAltGlyphElement.cpp
+++ b/content/svg/content/src/SVGAltGlyphElement.cpp
@@ -21,17 +21,17 @@ nsSVGElement::StringInfo SVGAltGlyphElem
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, false }
 };
 
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGAltGlyphElement::SVGAltGlyphElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGAltGlyphElement::SVGAltGlyphElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGAltGlyphElementBase(aNodeInfo)
 {
 }
 
 nsSVGElement::EnumAttributesInfo
 SVGAltGlyphElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
--- a/content/svg/content/src/SVGAltGlyphElement.h
+++ b/content/svg/content/src/SVGAltGlyphElement.h
@@ -5,29 +5,29 @@
 
 #ifndef mozilla_dom_SVGAltGlyphElement_h
 #define mozilla_dom_SVGAltGlyphElement_h
 
 #include "mozilla/dom/SVGTextPositioningElement.h"
 #include "nsSVGString.h"
 
 nsresult NS_NewSVGAltGlyphElement(nsIContent **aResult,
-                                  already_AddRefed<nsINodeInfo> aNodeInfo);
+                                  already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGTextPositioningElement SVGAltGlyphElementBase;
 
 class SVGAltGlyphElement MOZ_FINAL : public SVGAltGlyphElementBase
 {
 protected:
   friend nsresult (::NS_NewSVGAltGlyphElement(nsIContent **aResult,
-                                              already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGAltGlyphElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                              already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGAltGlyphElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGAnimateElement.cpp
+++ b/content/svg/content/src/SVGAnimateElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGAnimateElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGAnimateElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGAnimateElement::SVGAnimateElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGAnimateElement::SVGAnimateElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGAnimationElement(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGAnimateElement)
--- a/content/svg/content/src/SVGAnimateElement.h
+++ b/content/svg/content/src/SVGAnimateElement.h
@@ -6,30 +6,30 @@
 #ifndef mozilla_dom_SVGAnimateElement_h
 #define mozilla_dom_SVGAnimateElement_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimationElement.h"
 #include "nsSMILAnimationFunction.h"
 
 nsresult NS_NewSVGAnimateElement(nsIContent **aResult,
-                                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGAnimateElement MOZ_FINAL : public SVGAnimationElement
 {
 protected:
-  SVGAnimateElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGAnimateElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   nsSMILAnimationFunction mAnimationFunction;
   friend nsresult
     (::NS_NewSVGAnimateElement(nsIContent **aResult,
-                               already_AddRefed<nsINodeInfo> aNodeInfo));
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // nsIDOMNode
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
--- a/content/svg/content/src/SVGAnimateMotionElement.cpp
+++ b/content/svg/content/src/SVGAnimateMotionElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGAnimateMotionElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGAnimateMotionElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGAnimateMotionElement::SVGAnimateMotionElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGAnimateMotionElement::SVGAnimateMotionElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGAnimationElement(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGAnimateMotionElement)
--- a/content/svg/content/src/SVGAnimateMotionElement.h
+++ b/content/svg/content/src/SVGAnimateMotionElement.h
@@ -6,30 +6,30 @@
 #ifndef mozilla_dom_SVGAnimateMotionElement_h
 #define mozilla_dom_SVGAnimateMotionElement_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimationElement.h"
 #include "SVGMotionSMILAnimationFunction.h"
 
 nsresult NS_NewSVGAnimateMotionElement(nsIContent **aResult,
-                                       already_AddRefed<nsINodeInfo> aNodeInfo);
+                                       already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGAnimateMotionElement MOZ_FINAL : public SVGAnimationElement
 {
 protected:
-  SVGAnimateMotionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGAnimateMotionElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   SVGMotionSMILAnimationFunction mAnimationFunction;
   friend nsresult
     (::NS_NewSVGAnimateMotionElement(nsIContent **aResult,
-                                     already_AddRefed<nsINodeInfo> aNodeInfo));
+                                     already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // nsIDOMNode specializations
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
--- a/content/svg/content/src/SVGAnimateTransformElement.cpp
+++ b/content/svg/content/src/SVGAnimateTransformElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGAnimateTransformElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGAnimateTransformElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGAnimateTransformElement::SVGAnimateTransformElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGAnimateTransformElement::SVGAnimateTransformElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGAnimationElement(aNodeInfo)
 {
 }
 
 bool
 SVGAnimateTransformElement::ParseAttribute(int32_t aNamespaceID,
                                            nsIAtom* aAttribute,
                                            const nsAString& aValue,
--- a/content/svg/content/src/SVGAnimateTransformElement.h
+++ b/content/svg/content/src/SVGAnimateTransformElement.h
@@ -6,30 +6,30 @@
 #ifndef mozilla_dom_SVGAnimateTransformElement_h
 #define mozilla_dom_SVGAnimateTransformElement_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimationElement.h"
 #include "nsSMILAnimationFunction.h"
 
 nsresult NS_NewSVGAnimateTransformElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo);
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGAnimateTransformElement MOZ_FINAL : public SVGAnimationElement
 {
 protected:
-  SVGAnimateTransformElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGAnimateTransformElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   nsSMILAnimationFunction mAnimationFunction;
   friend nsresult
     (::NS_NewSVGAnimateTransformElement(nsIContent **aResult,
-                                        already_AddRefed<nsINodeInfo> aNodeInfo));
+                                        already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // nsIDOMNode specializations
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
--- a/content/svg/content/src/SVGAnimationElement.cpp
+++ b/content/svg/content/src/SVGAnimationElement.cpp
@@ -38,17 +38,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
                                                   SVGAnimationElementBase)
   tmp->mHrefTarget.Traverse(&cb);
   tmp->mTimedElement.Traverse(&cb);
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGAnimationElement::SVGAnimationElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGAnimationElement::SVGAnimationElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGAnimationElementBase(aNodeInfo),
     mHrefTarget(MOZ_THIS_IN_INITIALIZER_LIST())
 {
 }
 
 nsresult
 SVGAnimationElement::Init()
 {
--- a/content/svg/content/src/SVGAnimationElement.h
+++ b/content/svg/content/src/SVGAnimationElement.h
@@ -22,17 +22,17 @@ enum nsSMILTargetAttrType {
   eSMILTargetAttrType_CSS,
   eSMILTargetAttrType_XML
 };
 
 class SVGAnimationElement : public SVGAnimationElementBase,
                             public SVGTests
 {
 protected:
-  SVGAnimationElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGAnimationElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   nsresult Init();
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGAnimationElement,
                                            SVGAnimationElementBase)
--- a/content/svg/content/src/SVGCircleElement.cpp
+++ b/content/svg/content/src/SVGCircleElement.cpp
@@ -27,17 +27,17 @@ nsSVGElement::LengthInfo SVGCircleElemen
   { &nsGkAtoms::cx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
   { &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
   { &nsGkAtoms::r, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::XY }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGCircleElement::SVGCircleElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGCircleElement::SVGCircleElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGCircleElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGCircleElement)
--- a/content/svg/content/src/SVGCircleElement.h
+++ b/content/svg/content/src/SVGCircleElement.h
@@ -5,31 +5,31 @@
 
 #ifndef mozilla_dom_SVGCircleElement_h
 #define mozilla_dom_SVGCircleElement_h
 
 #include "nsSVGPathGeometryElement.h"
 #include "nsSVGLength2.h"
 
 nsresult NS_NewSVGCircleElement(nsIContent **aResult,
-                                already_AddRefed<nsINodeInfo> aNodeInfo);
+                                already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGPathGeometryElement SVGCircleElementBase;
 
 namespace mozilla {
 namespace dom {
 
 class SVGCircleElement MOZ_FINAL : public SVGCircleElementBase
 {
 protected:
-  SVGCircleElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGCircleElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
   friend nsresult (::NS_NewSVGCircleElement(nsIContent **aResult,
-                                            already_AddRefed<nsINodeInfo> aNodeInfo));
+                                            already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const MOZ_OVERRIDE;
 
   // nsSVGPathGeometryElement methods:
   virtual void ConstructPath(gfxContext *aCtx) MOZ_OVERRIDE;
   virtual TemporaryRef<Path> BuildPath() MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGClipPathElement.cpp
+++ b/content/svg/content/src/SVGClipPathElement.cpp
@@ -26,17 +26,17 @@ nsSVGElement::EnumInfo SVGClipPathElemen
     sSVGUnitTypesMap,
     SVG_UNIT_TYPE_USERSPACEONUSE
   }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGClipPathElement::SVGClipPathElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGClipPathElement::SVGClipPathElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGClipPathElementBase(aNodeInfo)
 {
 }
 
 already_AddRefed<SVGAnimatedEnumeration>
 SVGClipPathElement::ClipPathUnits()
 {
   return mEnumAttributes[CLIPPATHUNITS].ToDOMAnimatedEnum(this);
--- a/content/svg/content/src/SVGClipPathElement.h
+++ b/content/svg/content/src/SVGClipPathElement.h
@@ -7,31 +7,31 @@
 #define mozilla_dom_SVGClipPathElement_h
 
 #include "nsSVGEnum.h"
 #include "mozilla/dom/SVGTransformableElement.h"
 
 class nsSVGClipPathFrame;
 
 nsresult NS_NewSVGClipPathElement(nsIContent **aResult,
-                                  already_AddRefed<nsINodeInfo> aNodeInfo);
+                                  already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGTransformableElement SVGClipPathElementBase;
 
 class SVGClipPathElement MOZ_FINAL : public SVGClipPathElementBase
 {
   friend class ::nsSVGClipPathFrame;
 
 protected:
   friend nsresult (::NS_NewSVGClipPathElement(nsIContent **aResult,
-                                              already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGClipPathElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                              already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGClipPathElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   // WebIDL
   already_AddRefed<SVGAnimatedEnumeration> ClipPathUnits();
--- a/content/svg/content/src/SVGComponentTransferFunctionElement.h
+++ b/content/svg/content/src/SVGComponentTransferFunctionElement.h
@@ -22,17 +22,17 @@ class DOMSVGAnimatedNumberList;
 
 namespace dom {
 
 typedef SVGFEUnstyledElement SVGComponentTransferFunctionElementBase;
 
 class SVGComponentTransferFunctionElement : public SVGComponentTransferFunctionElementBase
 {
 protected:
-  SVGComponentTransferFunctionElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGComponentTransferFunctionElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGComponentTransferFunctionElementBase(aNodeInfo)
   {
   }
 
 public:
   typedef gfx::AttributeMap AttributeMap;
 
   // interfaces:
@@ -76,105 +76,105 @@ protected:
   static nsSVGEnumMapping sTypeMap[];
   static EnumInfo sEnumInfo[1];
 };
 
 } // namespace dom
 } // namespace mozilla
 
 nsresult NS_NewSVGFEFuncRElement(
-    nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo);
+    nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGFEFuncRElement : public SVGComponentTransferFunctionElement
 {
   friend nsresult (::NS_NewSVGFEFuncRElement(
-    nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo));
+    nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEFuncRElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEFuncRElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGComponentTransferFunctionElement(aNodeInfo) {}
 
 public:
   virtual int32_t GetChannel() MOZ_OVERRIDE { return 0; }
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 nsresult NS_NewSVGFEFuncGElement(
-  nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGFEFuncGElement : public SVGComponentTransferFunctionElement
 {
   friend nsresult (::NS_NewSVGFEFuncGElement(
-    nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo));
+    nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEFuncGElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEFuncGElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGComponentTransferFunctionElement(aNodeInfo) {}
 
 public:
   virtual int32_t GetChannel() MOZ_OVERRIDE { return 1; }
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 nsresult NS_NewSVGFEFuncBElement(
-  nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGFEFuncBElement : public SVGComponentTransferFunctionElement
 {
   friend nsresult (::NS_NewSVGFEFuncBElement(
-    nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo));
+    nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEFuncBElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEFuncBElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGComponentTransferFunctionElement(aNodeInfo) {}
 
 public:
   virtual int32_t GetChannel() MOZ_OVERRIDE { return 2; }
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 nsresult NS_NewSVGFEFuncAElement(
-  nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGFEFuncAElement : public SVGComponentTransferFunctionElement
 {
   friend nsresult (::NS_NewSVGFEFuncAElement(
-    nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo));
+    nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEFuncAElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEFuncAElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGComponentTransferFunctionElement(aNodeInfo) {}
 
 public:
   virtual int32_t GetChannel() MOZ_OVERRIDE { return 3; }
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   virtual JSObject* WrapNode(JSContext* aCx,
--- a/content/svg/content/src/SVGDefsElement.cpp
+++ b/content/svg/content/src/SVGDefsElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGDefsElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGDefsElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGDefsElement::SVGDefsElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGDefsElement::SVGDefsElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGGraphicsElement(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 
--- a/content/svg/content/src/SVGDefsElement.h
+++ b/content/svg/content/src/SVGDefsElement.h
@@ -4,27 +4,27 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGDefsElement_h
 #define mozilla_dom_SVGDefsElement_h
 
 #include "SVGGraphicsElement.h"
 
 nsresult NS_NewSVGDefsElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGDefsElement MOZ_FINAL : public SVGGraphicsElement
 {
 protected:
   friend nsresult (::NS_NewSVGDefsElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGDefsElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGDefsElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // nsIContent
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
--- a/content/svg/content/src/SVGDescElement.cpp
+++ b/content/svg/content/src/SVGDescElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGDescElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGDescElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGDescElement::SVGDescElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGDescElement::SVGDescElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGDescElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGDescElement)
--- a/content/svg/content/src/SVGDescElement.h
+++ b/content/svg/content/src/SVGDescElement.h
@@ -5,29 +5,29 @@
 
 #ifndef mozilla_dom_SVGDescElement_h
 #define mozilla_dom_SVGDescElement_h
 
 #include "mozilla/Attributes.h"
 #include "nsSVGElement.h"
 
 nsresult NS_NewSVGDescElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGElement SVGDescElementBase;
 
 namespace mozilla {
 namespace dom {
 
 class SVGDescElement MOZ_FINAL : public SVGDescElementBase
 {
 protected:
   friend nsresult (::NS_NewSVGDescElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGDescElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGDescElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 };
 
--- a/content/svg/content/src/SVGElementFactory.cpp
+++ b/content/svg/content/src/SVGElementFactory.cpp
@@ -19,42 +19,42 @@ static PLHashTable* sTagAtomTable = null
 
 // We don't want to store 0 in the hash table as a return value of 0 from
 // PL_HashTableLookupConst indicates that the value is not found
 #define TABLE_VALUE_OFFSET 1
 
 #define SVG_TAG(_tag, _classname) \
 nsresult \
 NS_NewSVG##_classname##Element(nsIContent** aResult, \
-                               already_AddRefed<nsINodeInfo> aNodeInfo); \
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo); \
 \
 static inline nsresult \
 Create##_classname##Element(nsIContent** aResult, \
-                            already_AddRefed<nsINodeInfo> aNodeInfo, \
+                            already_AddRefed<nsINodeInfo>&& aNodeInfo, \
                             FromParser aFromParser) \
 { \
-  return NS_NewSVG##_classname##Element(aResult, aNodeInfo); \
+  return NS_NewSVG##_classname##Element(aResult, mozilla::Move(aNodeInfo)); \
 }
 
 #define SVG_FROM_PARSER_TAG(_tag, _classname) \
 nsresult \
 NS_NewSVG##_classname##Element(nsIContent** aResult, \
-                               already_AddRefed<nsINodeInfo> aNodeInfo, \
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo, \
                                FromParser aFromParser);
 #include "SVGTagList.h"
 #undef SVG_TAG
 #undef SVG_FROM_PARSER_TAG
 
 nsresult
 NS_NewSVGElement(Element** aResult,
-                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsresult
   (*contentCreatorCallback)(nsIContent** aResult,
-                            already_AddRefed<nsINodeInfo> aNodeInfo,
+                            already_AddRefed<nsINodeInfo>&& aNodeInfo,
                             FromParser aFromParser);
 
 static const contentCreatorCallback sContentCreatorCallbacks[] = {
 #define SVG_TAG(_tag, _classname) Create##_classname##Element,
 #define SVG_FROM_PARSER_TAG(_tag, _classname)  NS_NewSVG##_classname##Element,
 #include "SVGTagList.h"
 #undef SVG_TAG
 #undef SVG_FROM_PARSER_TAG
@@ -107,37 +107,38 @@ bool
 SVGElementFactory::Exists(nsIAtom *aTag)
 {
   MOZ_ASSERT(sTagAtomTable, "no lookup table, needs SVGElementFactory::Init");
   void* tag = PL_HashTableLookupConst(sTagAtomTable, aTag);
   return tag != nullptr;
 }
 
 nsresult
-NS_NewSVGElement(Element** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
+NS_NewSVGElement(Element** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo,
                  FromParser aFromParser)
 {
   NS_ASSERTION(sTagAtomTable, "no lookup table, needs SVGElementFactory::Init");
 
-  nsIAtom* name = aNodeInfo.get()->NameAtom();
+  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
+  nsIAtom* name = ni->NameAtom();
 
-  NS_ASSERTION(aNodeInfo.get()->NamespaceEquals(kNameSpaceID_SVG), 
+  NS_ASSERTION(ni->NamespaceEquals(kNameSpaceID_SVG),
                "Trying to create SVG elements that aren't in the SVG namespace");
 
   void* tag = PL_HashTableLookupConst(sTagAtomTable, name);
   if (tag) {
     int32_t index = NS_PTR_TO_INT32(tag) - TABLE_VALUE_OFFSET;
     if (index < 0 || index >= eSVGTag_Count) {
       NS_WARNING("About to index out of array bounds - crashing instead");
       MOZ_CRASH();
     }
 
     contentCreatorCallback cb = sContentCreatorCallbacks[index];
 
     nsCOMPtr<nsIContent> content;
-    nsresult rv = cb(getter_AddRefs(content), aNodeInfo, aFromParser);
-    *aResult = content.forget().get()->AsElement();
+    nsresult rv = cb(getter_AddRefs(content), ni.forget(), aFromParser);
+    *aResult = content.forget().take()->AsElement();
     return rv;
   }
 
   // if we don't know what to create, just create a standard svg element:
-  return NS_NewSVGElement(aResult, aNodeInfo);
+  return NS_NewSVGElement(aResult, ni.forget());
 }
--- a/content/svg/content/src/SVGEllipseElement.cpp
+++ b/content/svg/content/src/SVGEllipseElement.cpp
@@ -28,17 +28,17 @@ nsSVGElement::LengthInfo SVGEllipseEleme
   { &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
   { &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
   { &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGEllipseElement::SVGEllipseElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGEllipseElement::SVGEllipseElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGEllipseElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGEllipseElement)
--- a/content/svg/content/src/SVGEllipseElement.h
+++ b/content/svg/content/src/SVGEllipseElement.h
@@ -5,31 +5,31 @@
 
 #ifndef mozilla_dom_SVGEllipseElement_h
 #define mozilla_dom_SVGEllipseElement_h
 
 #include "nsSVGPathGeometryElement.h"
 #include "nsSVGLength2.h"
 
 nsresult NS_NewSVGEllipseElement(nsIContent **aResult,
-                                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGPathGeometryElement SVGEllipseElementBase;
 
 class SVGEllipseElement MOZ_FINAL : public SVGEllipseElementBase
 {
 protected:
-  SVGEllipseElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGEllipseElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
   friend nsresult (::NS_NewSVGEllipseElement(nsIContent **aResult,
-                                             already_AddRefed<nsINodeInfo> aNodeInfo));
+                                             already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const MOZ_OVERRIDE;
 
   // nsSVGPathGeometryElement methods:
   virtual void ConstructPath(gfxContext *aCtx) MOZ_OVERRIDE;
   virtual TemporaryRef<Path> BuildPath() MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGFEBlendElement.h
+++ b/content/svg/content/src/SVGFEBlendElement.h
@@ -5,28 +5,28 @@
 
 #ifndef mozilla_dom_SVGFEBlendElement_h
 #define mozilla_dom_SVGFEBlendElement_h
 
 #include "nsSVGFilters.h"
 #include "nsSVGEnum.h"
 
 nsresult NS_NewSVGFEBlendElement(nsIContent **aResult,
-                                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEBlendElementBase;
 
 class SVGFEBlendElement : public SVGFEBlendElementBase
 {
   friend nsresult (::NS_NewSVGFEBlendElement(nsIContent **aResult,
-                                             already_AddRefed<nsINodeInfo> aNodeInfo));
+                                             already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEBlendElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEBlendElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEBlendElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEColorMatrixElement.h
+++ b/content/svg/content/src/SVGFEColorMatrixElement.h
@@ -6,29 +6,29 @@
 #ifndef mozilla_dom_SVGFEColorMatrixElement_h
 #define mozilla_dom_SVGFEColorMatrixElement_h
 
 #include "nsSVGEnum.h"
 #include "nsSVGFilters.h"
 #include "SVGAnimatedNumberList.h"
 
 nsresult NS_NewSVGFEColorMatrixElement(nsIContent **aResult,
-                                       already_AddRefed<nsINodeInfo> aNodeInfo);
+                                       already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEColorMatrixElementBase;
 
 class SVGFEColorMatrixElement : public SVGFEColorMatrixElementBase
 {
   friend nsresult (::NS_NewSVGFEColorMatrixElement(nsIContent **aResult,
-                                                   already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                   already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEColorMatrixElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEColorMatrixElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEColorMatrixElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEComponentTransferElement.h
+++ b/content/svg/content/src/SVGFEComponentTransferElement.h
@@ -6,27 +6,27 @@
 #ifndef mozilla_dom_SVGFEComponentTransferElement_h
 #define mozilla_dom_SVGFEComponentTransferElement_h
 
 #include "nsSVGFilters.h"
 
 typedef nsSVGFE SVGFEComponentTransferElementBase;
 
 nsresult NS_NewSVGFEComponentTransferElement(nsIContent **aResult,
-                                             already_AddRefed<nsINodeInfo> aNodeInfo);
+                                             already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGFEComponentTransferElement : public SVGFEComponentTransferElementBase
 {
   friend nsresult (::NS_NewSVGFEComponentTransferElement(nsIContent **aResult,
-                                                         already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                         already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEComponentTransferElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEComponentTransferElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEComponentTransferElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFECompositeElement.h
+++ b/content/svg/content/src/SVGFECompositeElement.h
@@ -6,29 +6,29 @@
 #ifndef mozilla_dom_SVGFECompositeElement_h
 #define mozilla_dom_SVGFECompositeElement_h
 
 #include "nsSVGEnum.h"
 #include "nsSVGFilters.h"
 #include "nsSVGNumber2.h"
 
 nsresult NS_NewSVGFECompositeElement(nsIContent **aResult,
-                                     already_AddRefed<nsINodeInfo> aNodeInfo);
+                                     already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFECompositeElementBase;
 
 class SVGFECompositeElement : public SVGFECompositeElementBase
 {
   friend nsresult (::NS_NewSVGFECompositeElement(nsIContent **aResult,
-                                                 already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                 already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFECompositeElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFECompositeElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFECompositeElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEConvolveMatrixElement.h
+++ b/content/svg/content/src/SVGFEConvolveMatrixElement.h
@@ -11,32 +11,32 @@
 #include "nsSVGFilters.h"
 #include "nsSVGInteger.h"
 #include "nsSVGIntegerPair.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGString.h"
 #include "SVGAnimatedNumberList.h"
 
 nsresult NS_NewSVGFEConvolveMatrixElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo);
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 class DOMSVGAnimatedNumberList;
 
 namespace dom {
 class SVGAnimatedBoolean;
 
 typedef nsSVGFE SVGFEConvolveMatrixElementBase;
 
 class SVGFEConvolveMatrixElement : public SVGFEConvolveMatrixElementBase
 {
   friend nsresult (::NS_NewSVGFEConvolveMatrixElement(nsIContent **aResult,
-                                                      already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                      already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEConvolveMatrixElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEConvolveMatrixElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEConvolveMatrixElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEDiffuseLightingElement.h
+++ b/content/svg/content/src/SVGFEDiffuseLightingElement.h
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGFEDiffuseLightingElement_h
 #define mozilla_dom_SVGFEDiffuseLightingElement_h
 
 #include "nsSVGFilters.h"
 
 nsresult NS_NewSVGFEDiffuseLightingElement(nsIContent **aResult,
-                                           already_AddRefed<nsINodeInfo> aNodeInfo);
+                                           already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFELightingElement SVGFEDiffuseLightingElementBase;
 
 class SVGFEDiffuseLightingElement : public SVGFEDiffuseLightingElementBase
 {
   friend nsresult (::NS_NewSVGFEDiffuseLightingElement(nsIContent **aResult,
-                                                       already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                       already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEDiffuseLightingElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEDiffuseLightingElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEDiffuseLightingElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEDisplacementMapElement.h
+++ b/content/svg/content/src/SVGFEDisplacementMapElement.h
@@ -5,29 +5,29 @@
 
 #ifndef mozilla_dom_SVGFEDisplacementMapElement_h
 #define mozilla_dom_SVGFEDisplacementMapElement_h
 
 #include "nsSVGEnum.h"
 #include "nsSVGFilters.h"
 
 nsresult NS_NewSVGFEDisplacementMapElement(nsIContent **aResult,
-                                           already_AddRefed<nsINodeInfo> aNodeInfo);
+                                           already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEDisplacementMapElementBase;
 
 class SVGFEDisplacementMapElement : public SVGFEDisplacementMapElementBase
 {
 protected:
   friend nsresult (::NS_NewSVGFEDisplacementMapElement(nsIContent **aResult,
-                                                       already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGFEDisplacementMapElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+                                                       already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGFEDisplacementMapElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEDisplacementMapElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEDistantLightElement.h
+++ b/content/svg/content/src/SVGFEDistantLightElement.h
@@ -5,29 +5,29 @@
 
 #ifndef mozilla_dom_SVGFEDistantLightElement_h
 #define mozilla_dom_SVGFEDistantLightElement_h
 
 #include "nsSVGFilters.h"
 #include "nsSVGNumber2.h"
 
 nsresult NS_NewSVGFEDistantLightElement(nsIContent **aResult,
-                                        already_AddRefed<nsINodeInfo> aNodeInfo);
+                                        already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGFELightElement SVGFEDistantLightElementBase;
 
 class SVGFEDistantLightElement : public SVGFEDistantLightElementBase
 {
   friend nsresult (::NS_NewSVGFEDistantLightElement(nsIContent **aResult,
-                                                    already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                    already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEDistantLightElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEDistantLightElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEDistantLightElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual AttributeMap ComputeLightAttributes(nsSVGFilterInstance* aInstance) MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGFEDropShadowElement.h
+++ b/content/svg/content/src/SVGFEDropShadowElement.h
@@ -7,29 +7,29 @@
 #define mozilla_dom_SVGFEDropShadowElement_h
 
 #include "nsSVGFilters.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGNumberPair.h"
 #include "nsSVGString.h"
 
 nsresult NS_NewSVGFEDropShadowElement(nsIContent **aResult,
-                                      already_AddRefed<nsINodeInfo> aNodeInfo);
+                                      already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEDropShadowElementBase;
 
 class SVGFEDropShadowElement : public SVGFEDropShadowElementBase
 {
   friend nsresult (::NS_NewSVGFEDropShadowElement(nsIContent **aResult,
-                                                  already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                  already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEDropShadowElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEDropShadowElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEDropShadowElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEFloodElement.h
+++ b/content/svg/content/src/SVGFEFloodElement.h
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGFEFloodElement_h
 #define mozilla_dom_SVGFEFloodElement_h
 
 #include "nsSVGFilters.h"
 
 nsresult NS_NewSVGFEFloodElement(nsIContent **aResult,
-                                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEFloodElementBase;
 
 class SVGFEFloodElement : public SVGFEFloodElementBase
 {
   friend nsresult (::NS_NewSVGFEFloodElement(nsIContent **aResult,
-                                             already_AddRefed<nsINodeInfo> aNodeInfo));
+                                             already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEFloodElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEFloodElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEFloodElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   virtual bool SubregionIsUnionOfRegions() MOZ_OVERRIDE { return false; }
--- a/content/svg/content/src/SVGFEGaussianBlurElement.h
+++ b/content/svg/content/src/SVGFEGaussianBlurElement.h
@@ -6,29 +6,29 @@
 #ifndef mozilla_dom_SVGFEGaussianBlurElement_h
 #define mozilla_dom_SVGFEGaussianBlurElement_h
 
 #include "nsSVGFilters.h"
 #include "nsSVGNumberPair.h"
 #include "nsSVGString.h"
 
 nsresult NS_NewSVGFEGaussianBlurElement(nsIContent **aResult,
-                                        already_AddRefed<nsINodeInfo> aNodeInfo);
+                                        already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEGaussianBlurElementBase;
 
 class SVGFEGaussianBlurElement : public SVGFEGaussianBlurElementBase
 {
   friend nsresult (::NS_NewSVGFEGaussianBlurElement(nsIContent **aResult,
-                                                    already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                    already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEGaussianBlurElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEGaussianBlurElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEGaussianBlurElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEImageElement.cpp
+++ b/content/svg/content/src/SVGFEImageElement.cpp
@@ -39,17 +39,17 @@ nsSVGElement::StringInfo SVGFEImageEleme
 NS_IMPL_ISUPPORTS_INHERITED6(SVGFEImageElement, SVGFEImageElementBase,
                              nsIDOMNode, nsIDOMElement, nsIDOMSVGElement,
                              imgINotificationObserver, nsIImageLoadingContent,
                              imgIOnloadBlocker)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGFEImageElement::SVGFEImageElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGFEImageElement::SVGFEImageElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGFEImageElementBase(aNodeInfo)
 {
   // We start out broken
   AddStatesSilently(NS_EVENT_STATE_BROKEN);
 }
 
 SVGFEImageElement::~SVGFEImageElement()
 {
--- a/content/svg/content/src/SVGFEImageElement.h
+++ b/content/svg/content/src/SVGFEImageElement.h
@@ -7,32 +7,32 @@
 #define mozilla_dom_SVGFEImageElement_h
 
 #include "nsSVGFilters.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 
 class SVGFEImageFrame;
 
 nsresult NS_NewSVGFEImageElement(nsIContent **aResult,
-                                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEImageElementBase;
 
 class SVGFEImageElement : public SVGFEImageElementBase,
                           public nsImageLoadingContent
 {
   friend class ::SVGFEImageFrame;
 
 protected:
   friend nsresult (::NS_NewSVGFEImageElement(nsIContent **aResult,
-                                             already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGFEImageElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                             already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGFEImageElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~SVGFEImageElement();
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual bool SubregionIsUnionOfRegions() MOZ_OVERRIDE { return false; }
 
   // interfaces:
--- a/content/svg/content/src/SVGFEMergeElement.h
+++ b/content/svg/content/src/SVGFEMergeElement.h
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGFEMergeElement_h
 #define mozilla_dom_SVGFEMergeElement_h
 
 #include "nsSVGFilters.h"
 
 nsresult NS_NewSVGFEMergeElement(nsIContent **aResult,
-                                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEMergeElementBase;
 
 class SVGFEMergeElement : public SVGFEMergeElementBase
 {
   friend nsresult (::NS_NewSVGFEMergeElement(nsIContent **aResult,
-                                             already_AddRefed<nsINodeInfo> aNodeInfo));
+                                             already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEMergeElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEMergeElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEMergeElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEMergeNodeElement.h
+++ b/content/svg/content/src/SVGFEMergeNodeElement.h
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGFEMergeNodeElement_h
 #define mozilla_dom_SVGFEMergeNodeElement_h
 
 #include "nsSVGFilters.h"
 
 nsresult NS_NewSVGFEMergeNodeElement(nsIContent** aResult,
-                                     already_AddRefed<nsINodeInfo> aNodeInfo);
+                                     already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGFEUnstyledElement SVGFEMergeNodeElementBase;
 
 class SVGFEMergeNodeElement : public SVGFEMergeNodeElementBase
 {
   friend nsresult (::NS_NewSVGFEMergeNodeElement(nsIContent **aResult,
-                                                 already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                 already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEMergeNodeElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEMergeNodeElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEMergeNodeElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGFEMorphologyElement.h
+++ b/content/svg/content/src/SVGFEMorphologyElement.h
@@ -7,29 +7,29 @@
 #define mozilla_dom_SVGFEMorphologyElement_h
 
 #include "nsSVGEnum.h"
 #include "nsSVGFilters.h"
 #include "nsSVGNumberPair.h"
 #include "nsSVGString.h"
 
 nsresult NS_NewSVGFEMorphologyElement(nsIContent **aResult,
-                                      already_AddRefed<nsINodeInfo> aNodeInfo);
+                                      already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEMorphologyElementBase;
 
 class SVGFEMorphologyElement : public SVGFEMorphologyElementBase
 {
   friend nsresult (::NS_NewSVGFEMorphologyElement(nsIContent **aResult,
-                                                  already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                  already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEMorphologyElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEMorphologyElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEMorphologyElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEOffsetElement.h
+++ b/content/svg/content/src/SVGFEOffsetElement.h
@@ -6,29 +6,29 @@
 #ifndef mozilla_dom_SVGFEOffsetElement_h
 #define mozilla_dom_SVGFEOffsetElement_h
 
 #include "nsSVGFilters.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGString.h"
 
 nsresult NS_NewSVGFEOffsetElement(nsIContent **aResult,
-                                  already_AddRefed<nsINodeInfo> aNodeInfo);
+                                  already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFEOffsetElementBase;
 
 class SVGFEOffsetElement : public SVGFEOffsetElementBase
 {
   friend nsresult (::NS_NewSVGFEOffsetElement(nsIContent **aResult,
-                                              already_AddRefed<nsINodeInfo> aNodeInfo));
+                                              already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEOffsetElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEOffsetElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEOffsetElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual FilterPrimitiveDescription
--- a/content/svg/content/src/SVGFEPointLightElement.h
+++ b/content/svg/content/src/SVGFEPointLightElement.h
@@ -5,29 +5,29 @@
 
 #ifndef mozilla_dom_SVGFEPointLightElement_h
 #define mozilla_dom_SVGFEPointLightElement_h
 
 #include "nsSVGFilters.h"
 #include "nsSVGNumber2.h"
 
 nsresult NS_NewSVGFEPointLightElement(nsIContent **aResult,
-                                      already_AddRefed<nsINodeInfo> aNodeInfo);
+                                      already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGFELightElement SVGFEPointLightElementBase;
 
 class SVGFEPointLightElement : public SVGFEPointLightElementBase
 {
   friend nsresult (::NS_NewSVGFEPointLightElement(nsIContent **aResult,
-                                                  already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                  already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFEPointLightElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEPointLightElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEPointLightElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   virtual AttributeMap ComputeLightAttributes(nsSVGFilterInstance* aInstance) MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGFESpecularLightingElement.h
+++ b/content/svg/content/src/SVGFESpecularLightingElement.h
@@ -4,31 +4,31 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGFESpecularLightingElement_h
 #define mozilla_dom_SVGFESpecularLightingElement_h
 
 #include "nsSVGFilters.h"
 
 nsresult NS_NewSVGFESpecularLightingElement(nsIContent **aResult,
-                                            already_AddRefed<nsINodeInfo> aNodeInfo);
+                                            already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 //---------------------SpecularLighting------------------------
 
 typedef nsSVGFELightingElement SVGFESpecularLightingElementBase;
 
 class SVGFESpecularLightingElement : public SVGFESpecularLightingElementBase
 {
   friend nsresult (::NS_NewSVGFESpecularLightingElement(nsIContent **aResult,
-                                                        already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                        already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFESpecularLightingElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFESpecularLightingElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFESpecularLightingElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
--- a/content/svg/content/src/SVGFESpotLightElement.h
+++ b/content/svg/content/src/SVGFESpotLightElement.h
@@ -5,30 +5,30 @@
 
 #ifndef mozilla_dom_SVGFESpotLightElement_h
 #define mozilla_dom_SVGFESpotLightElement_h
 
 #include "nsSVGFilters.h"
 #include "nsSVGNumber2.h"
 
 nsresult NS_NewSVGFESpotLightElement(nsIContent **aResult,
-                                     already_AddRefed<nsINodeInfo> aNodeInfo);
+                                     already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGFELightElement SVGFESpotLightElementBase;
 
 class SVGFESpotLightElement : public SVGFESpotLightElementBase
 {
   friend nsresult (::NS_NewSVGFESpotLightElement(nsIContent **aResult,
-                                                 already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                 already_AddRefed<nsINodeInfo>&& aNodeInfo));
   friend class ::nsSVGFELightingElement;
 protected:
-  SVGFESpotLightElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFESpotLightElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFESpotLightElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual AttributeMap ComputeLightAttributes(nsSVGFilterInstance* aInstance) MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGFETileElement.h
+++ b/content/svg/content/src/SVGFETileElement.h
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGFETileElement_h
 #define mozilla_dom_SVGFETileElement_h
 
 #include "nsSVGFilters.h"
 
 nsresult NS_NewSVGFETileElement(nsIContent **aResult,
-                                already_AddRefed<nsINodeInfo> aNodeInfo);
+                                already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFETileElementBase;
 
 class SVGFETileElement : public SVGFETileElementBase
 {
   friend nsresult (::NS_NewSVGFETileElement(nsIContent **aResult,
-                                            already_AddRefed<nsINodeInfo> aNodeInfo));
+                                            already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFETileElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFETileElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFETileElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   virtual bool SubregionIsUnionOfRegions() { return false; }
--- a/content/svg/content/src/SVGFETurbulenceElement.h
+++ b/content/svg/content/src/SVGFETurbulenceElement.h
@@ -8,29 +8,29 @@
 
 #include "nsSVGEnum.h"
 #include "nsSVGFilters.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGInteger.h"
 #include "nsSVGString.h"
 
 nsresult NS_NewSVGFETurbulenceElement(nsIContent **aResult,
-                                      already_AddRefed<nsINodeInfo> aNodeInfo);
+                                      already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGFE SVGFETurbulenceElementBase;
 
 class SVGFETurbulenceElement : public SVGFETurbulenceElementBase
 {
   friend nsresult (::NS_NewSVGFETurbulenceElement(nsIContent **aResult,
-                                                  already_AddRefed<nsINodeInfo> aNodeInfo));
+                                                  already_AddRefed<nsINodeInfo>&& aNodeInfo));
 protected:
-  SVGFETurbulenceElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFETurbulenceElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFETurbulenceElementBase(aNodeInfo)
   {
   }
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual bool SubregionIsUnionOfRegions() MOZ_OVERRIDE { return false; }
--- a/content/svg/content/src/SVGFilterElement.cpp
+++ b/content/svg/content/src/SVGFilterElement.cpp
@@ -45,17 +45,17 @@ nsSVGElement::EnumInfo SVGFilterElement:
 nsSVGElement::StringInfo SVGFilterElement::sStringInfo[1] =
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, true }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGFilterElement::SVGFilterElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGFilterElement::SVGFilterElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGFilterElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 
--- a/content/svg/content/src/SVGFilterElement.h
+++ b/content/svg/content/src/SVGFilterElement.h
@@ -13,31 +13,31 @@
 #include "nsSVGString.h"
 
 typedef nsSVGElement SVGFilterElementBase;
 
 class nsSVGFilterFrame;
 class nsSVGFilterInstance;
 
 nsresult NS_NewSVGFilterElement(nsIContent **aResult,
-                                already_AddRefed<nsINodeInfo> aNodeInfo);
+                                already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 class SVGAnimatedLength;
 
 class SVGFilterElement : public SVGFilterElementBase
 {
   friend class ::nsSVGFilterFrame;
   friend class ::nsSVGFilterInstance;
 
 protected:
   friend nsresult (::NS_NewSVGFilterElement(nsIContent **aResult,
-                                            already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGFilterElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                            already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGFilterElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // nsIContent
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE;
 
--- a/content/svg/content/src/SVGForeignObjectElement.cpp
+++ b/content/svg/content/src/SVGForeignObjectElement.cpp
@@ -26,17 +26,17 @@ nsSVGElement::LengthInfo SVGForeignObjec
   { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
   { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
   { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGForeignObjectElement::SVGForeignObjectElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGForeignObjectElement::SVGForeignObjectElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGGraphicsElement(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGForeignObjectElement)
--- a/content/svg/content/src/SVGForeignObjectElement.h
+++ b/content/svg/content/src/SVGForeignObjectElement.h
@@ -5,31 +5,31 @@
 
 #ifndef mozilla_dom_SVGForeignObjectElement_h
 #define mozilla_dom_SVGForeignObjectElement_h
 
 #include "mozilla/dom/SVGGraphicsElement.h"
 #include "nsSVGLength2.h"
 
 nsresult NS_NewSVGForeignObjectElement(nsIContent **aResult,
-                                       already_AddRefed<nsINodeInfo> aNodeInfo);
+                                       already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 class nsSVGForeignObjectFrame;
 
 namespace mozilla {
 namespace dom {
 
 class SVGForeignObjectElement MOZ_FINAL : public SVGGraphicsElement
 {
   friend class ::nsSVGForeignObjectFrame;
 
 protected:
   friend nsresult (::NS_NewSVGForeignObjectElement(nsIContent **aResult,
-                                                   already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGForeignObjectElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                                   already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGForeignObjectElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // nsSVGElement specializations:
   virtual gfxMatrix PrependLocalTransformsTo(const gfxMatrix &aMatrix,
                       TransformTypes aWhich = eAllTransforms) const MOZ_OVERRIDE;
   virtual bool HasValidDimensions() const MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGGElement.cpp
+++ b/content/svg/content/src/SVGGElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGGElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGGElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGGElement::SVGGElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGGElement::SVGGElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGGraphicsElement(aNodeInfo)
 {
 }
 
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
--- a/content/svg/content/src/SVGGElement.h
+++ b/content/svg/content/src/SVGGElement.h
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGGElement_h
 #define mozilla_dom_SVGGElement_h
 
 #include "mozilla/dom/SVGGraphicsElement.h"
 
 nsresult NS_NewSVGGElement(nsIContent **aResult,
-                           already_AddRefed<nsINodeInfo> aNodeInfo);
+                           already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGGElement MOZ_FINAL : public SVGGraphicsElement
 {
 protected:
-  SVGGElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGGElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
   friend nsresult (::NS_NewSVGGElement(nsIContent **aResult,
-                                       already_AddRefed<nsINodeInfo> aNodeInfo));
+                                       already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // nsIContent
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 };
 
--- a/content/svg/content/src/SVGGradientElement.cpp
+++ b/content/svg/content/src/SVGGradientElement.cpp
@@ -43,17 +43,17 @@ nsSVGElement::EnumInfo SVGGradientElemen
 nsSVGElement::StringInfo SVGGradientElement::sStringInfo[1] =
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, true }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGGradientElement::SVGGradientElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGGradientElement::SVGGradientElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGGradientElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
 nsSVGElement::EnumAttributesInfo
@@ -127,17 +127,17 @@ nsSVGElement::LengthInfo SVGLinearGradie
   { &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
   { &nsGkAtoms::x2, 100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
   { &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGLinearGradientElement::SVGLinearGradientElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGLinearGradientElement::SVGLinearGradientElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGLinearGradientElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGLinearGradientElement)
@@ -202,17 +202,17 @@ nsSVGElement::LengthInfo SVGRadialGradie
   { &nsGkAtoms::r, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::XY },
   { &nsGkAtoms::fx, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
   { &nsGkAtoms::fy, 50, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGRadialGradientElement::SVGRadialGradientElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGRadialGradientElement::SVGRadialGradientElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGRadialGradientElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGRadialGradientElement)
--- a/content/svg/content/src/SVGGradientElement.h
+++ b/content/svg/content/src/SVGGradientElement.h
@@ -18,36 +18,36 @@ static const unsigned short SVG_SPREADME
 static const unsigned short SVG_SPREADMETHOD_REPEAT  = 3;
 
 class nsSVGGradientFrame;
 class nsSVGLinearGradientFrame;
 class nsSVGRadialGradientFrame;
 
 nsresult
 NS_NewSVGLinearGradientElement(nsIContent** aResult,
-                               already_AddRefed<nsINodeInfo> aNodeInfo);
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo);
 nsresult
 NS_NewSVGRadialGradientElement(nsIContent** aResult,
-                               already_AddRefed<nsINodeInfo> aNodeInfo);
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGAnimatedTransformList;
 
 //--------------------- Gradients------------------------
 
 typedef nsSVGElement SVGGradientElementBase;
 
 class SVGGradientElement : public SVGGradientElementBase
 {
   friend class ::nsSVGGradientFrame;
 
 protected:
-  SVGGradientElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGGradientElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE = 0;
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE = 0;
 
   // nsIContent
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE;
@@ -85,20 +85,20 @@ protected:
 
 typedef SVGGradientElement SVGLinearGradientElementBase;
 
 class SVGLinearGradientElement : public SVGLinearGradientElementBase
 {
   friend class ::nsSVGLinearGradientFrame;
   friend nsresult
     (::NS_NewSVGLinearGradientElement(nsIContent** aResult,
-                                      already_AddRefed<nsINodeInfo> aNodeInfo));
+                                      already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 protected:
-  SVGLinearGradientElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGLinearGradientElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   // WebIDL
   already_AddRefed<SVGAnimatedLength> X1();
@@ -119,20 +119,20 @@ protected:
 
 typedef SVGGradientElement SVGRadialGradientElementBase;
 
 class SVGRadialGradientElement : public SVGRadialGradientElementBase
 {
   friend class ::nsSVGRadialGradientFrame;
   friend nsresult
     (::NS_NewSVGRadialGradientElement(nsIContent** aResult,
-                                      already_AddRefed<nsINodeInfo> aNodeInfo));
+                                      already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 protected:
-  SVGRadialGradientElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGRadialGradientElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   // WebIDL
   already_AddRefed<SVGAnimatedLength> Cx();
--- a/content/svg/content/src/SVGGraphicsElement.cpp
+++ b/content/svg/content/src/SVGGraphicsElement.cpp
@@ -16,15 +16,15 @@ NS_IMPL_RELEASE_INHERITED(SVGGraphicsEle
 
 NS_INTERFACE_MAP_BEGIN(SVGGraphicsElement)
   NS_INTERFACE_MAP_ENTRY(mozilla::dom::SVGTests)
 NS_INTERFACE_MAP_END_INHERITING(SVGGraphicsElementBase)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGGraphicsElement::SVGGraphicsElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGGraphicsElement::SVGGraphicsElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGGraphicsElementBase(aNodeInfo)
 {
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/content/svg/content/src/SVGGraphicsElement.h
+++ b/content/svg/content/src/SVGGraphicsElement.h
@@ -13,17 +13,17 @@ namespace mozilla {
 namespace dom {
 
 typedef SVGTransformableElement SVGGraphicsElementBase;
 
 class SVGGraphicsElement : public SVGGraphicsElementBase,
                            public SVGTests
 {
 protected:
-  SVGGraphicsElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGGraphicsElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/content/svg/content/src/SVGImageElement.cpp
+++ b/content/svg/content/src/SVGImageElement.cpp
@@ -48,17 +48,17 @@ NS_IMPL_ISUPPORTS_INHERITED6(SVGImageEle
                              nsIDOMNode, nsIDOMElement,
                              nsIDOMSVGElement,
                              imgINotificationObserver,
                              nsIImageLoadingContent, imgIOnloadBlocker)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGImageElement::SVGImageElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGImageElement::SVGImageElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGImageElementBase(aNodeInfo)
 {
   // We start out broken
   AddStatesSilently(NS_EVENT_STATE_BROKEN);
 }
 
 SVGImageElement::~SVGImageElement()
 {
--- a/content/svg/content/src/SVGImageElement.h
+++ b/content/svg/content/src/SVGImageElement.h
@@ -8,38 +8,38 @@
 
 #include "nsImageLoadingContent.h"
 #include "nsSVGLength2.h"
 #include "nsSVGPathGeometryElement.h"
 #include "nsSVGString.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 
 nsresult NS_NewSVGImageElement(nsIContent **aResult,
-                               already_AddRefed<nsINodeInfo> aNodeInfo);
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGPathGeometryElement SVGImageElementBase;
 
 class nsSVGImageFrame;
 
 namespace mozilla {
 namespace dom {
 class DOMSVGAnimatedPreserveAspectRatio;
 
 class SVGImageElement : public SVGImageElementBase,
                         public nsImageLoadingContent
 {
   friend class ::nsSVGImageFrame;
 
 protected:
-  SVGImageElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGImageElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~SVGImageElement();
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
   friend nsresult (::NS_NewSVGImageElement(nsIContent **aResult,
-                                           already_AddRefed<nsINodeInfo> aNodeInfo));
+                                           already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIContent interface
   virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
--- a/content/svg/content/src/SVGLineElement.cpp
+++ b/content/svg/content/src/SVGLineElement.cpp
@@ -27,17 +27,17 @@ nsSVGElement::LengthInfo SVGLineElement:
   { &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
   { &nsGkAtoms::x2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
   { &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGLineElement::SVGLineElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGLineElement::SVGLineElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGLineElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGLineElement)
--- a/content/svg/content/src/SVGLineElement.h
+++ b/content/svg/content/src/SVGLineElement.h
@@ -5,31 +5,31 @@
 
 #ifndef mozilla_dom_SVGLineElement_h
 #define mozilla_dom_SVGLineElement_h
 
 #include "nsSVGPathGeometryElement.h"
 #include "nsSVGLength2.h"
 
 nsresult NS_NewSVGLineElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGPathGeometryElement SVGLineElementBase;
 
 class SVGLineElement MOZ_FINAL : public SVGLineElementBase
 {
 protected:
-  SVGLineElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGLineElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
   friend nsresult (::NS_NewSVGLineElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const MOZ_OVERRIDE;
 
   // nsSVGPathGeometryElement methods:
   virtual bool IsMarkable() MOZ_OVERRIDE { return true; }
   virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGMPathElement.cpp
+++ b/content/svg/content/src/SVGMPathElement.cpp
@@ -50,17 +50,17 @@ NS_IMPL_RELEASE_INHERITED(SVGMPathElemen
 
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(SVGMPathElement)
   NS_INTERFACE_TABLE_INHERITED4(SVGMPathElement, nsIDOMNode, nsIDOMElement,
                                 nsIDOMSVGElement,
                                 nsIMutationObserver)
 NS_INTERFACE_TABLE_TAIL_INHERITING(SVGMPathElementBase)
 
 // Constructor
-SVGMPathElement::SVGMPathElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGMPathElement::SVGMPathElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGMPathElementBase(aNodeInfo),
     mHrefTarget(MOZ_THIS_IN_INITIALIZER_LIST())
 {
 }
 
 SVGMPathElement::~SVGMPathElement()
 {
   UnlinkHrefTarget(false);
--- a/content/svg/content/src/SVGMPathElement.h
+++ b/content/svg/content/src/SVGMPathElement.h
@@ -7,31 +7,31 @@
 #define mozilla_dom_SVGMPathElement_h
 
 #include "nsSVGElement.h"
 #include "nsStubMutationObserver.h"
 #include "nsSVGString.h"
 #include "nsReferencedElement.h"
 
 nsresult NS_NewSVGMPathElement(nsIContent **aResult,
-                               already_AddRefed<nsINodeInfo> aNodeInfo);
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGElement SVGMPathElementBase;
 
 namespace mozilla {
 namespace dom {
 class SVGPathElement;
 
 class SVGMPathElement MOZ_FINAL : public SVGMPathElementBase,
                                   public nsStubMutationObserver
 {
 protected:
   friend nsresult (::NS_NewSVGMPathElement(nsIContent **aResult,
-                                           already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGMPathElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                           already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGMPathElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   ~SVGMPathElement();
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
--- a/content/svg/content/src/SVGMarkerElement.cpp
+++ b/content/svg/content/src/SVGMarkerElement.cpp
@@ -86,17 +86,17 @@ nsSVGOrientType::SetBaseValue(uint16_t a
 already_AddRefed<SVGAnimatedEnumeration>
 nsSVGOrientType::ToDOMAnimatedEnum(nsSVGElement *aSVGElement)
 {
   nsRefPtr<SVGAnimatedEnumeration> toReturn =
     new DOMAnimatedEnum(this, aSVGElement);
   return toReturn.forget();
 }
 
-SVGMarkerElement::SVGMarkerElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGMarkerElement::SVGMarkerElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGMarkerElementBase(aNodeInfo), mCoordCtx(nullptr)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGMarkerElement)
--- a/content/svg/content/src/SVGMarkerElement.h
+++ b/content/svg/content/src/SVGMarkerElement.h
@@ -13,17 +13,17 @@
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "nsSVGElement.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimatedEnumeration.h"
 
 class nsSVGMarkerFrame;
 
 nsresult NS_NewSVGMarkerElement(nsIContent **aResult,
-                                already_AddRefed<nsINodeInfo> aNodeInfo);
+                                already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 // Marker Unit Types
 static const unsigned short SVG_MARKERUNITS_UNKNOWN         = 0;
 static const unsigned short SVG_MARKERUNITS_USERSPACEONUSE = 1;
 static const unsigned short SVG_MARKERUNITS_STROKEWIDTH    = 2;
@@ -99,18 +99,18 @@ private:
 typedef nsSVGElement SVGMarkerElementBase;
 
 class SVGMarkerElement : public SVGMarkerElementBase
 {
   friend class ::nsSVGMarkerFrame;
 
 protected:
   friend nsresult (::NS_NewSVGMarkerElement(nsIContent **aResult,
-                                            already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGMarkerElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                            already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGMarkerElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const MOZ_OVERRIDE;
 
   virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
--- a/content/svg/content/src/SVGMaskElement.cpp
+++ b/content/svg/content/src/SVGMaskElement.cpp
@@ -41,17 +41,17 @@ nsSVGElement::EnumInfo SVGMaskElement::s
     sSVGUnitTypesMap,
     SVG_UNIT_TYPE_USERSPACEONUSE
   }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGMaskElement::SVGMaskElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGMaskElement::SVGMaskElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGMaskElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode method
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGMaskElement)
--- a/content/svg/content/src/SVGMaskElement.h
+++ b/content/svg/content/src/SVGMaskElement.h
@@ -8,33 +8,33 @@
 
 #include "nsSVGEnum.h"
 #include "nsSVGLength2.h"
 #include "nsSVGElement.h"
 
 class nsSVGMaskFrame;
 
 nsresult NS_NewSVGMaskElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 //--------------------- Masks ------------------------
 
 typedef nsSVGElement SVGMaskElementBase;
 
 class SVGMaskElement MOZ_FINAL : public SVGMaskElementBase
 {
   friend class ::nsSVGMaskFrame;
 
 protected:
   friend nsresult (::NS_NewSVGMaskElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGMaskElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGMaskElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // nsIContent interface
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE;
 
--- a/content/svg/content/src/SVGMetadataElement.cpp
+++ b/content/svg/content/src/SVGMetadataElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGMetadataElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGMetadataElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGMetadataElement::SVGMetadataElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGMetadataElement::SVGMetadataElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGMetadataElementBase(aNodeInfo)
 {
 }
 
 
 nsresult
 SVGMetadataElement::Init()
 {
--- a/content/svg/content/src/SVGMetadataElement.h
+++ b/content/svg/content/src/SVGMetadataElement.h
@@ -5,29 +5,29 @@
 
 #ifndef mozilla_dom_SVGMetadataElement_h
 #define mozilla_dom_SVGMetadataElement_h
 
 #include "mozilla/Attributes.h"
 #include "nsSVGElement.h"
 
 nsresult NS_NewSVGMetadataElement(nsIContent **aResult,
-                                  already_AddRefed<nsINodeInfo> aNodeInfo);
+                                  already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGElement SVGMetadataElementBase;
 
 namespace mozilla {
 namespace dom {
 
 class SVGMetadataElement MOZ_FINAL : public SVGMetadataElementBase
 {
 protected:
   friend nsresult (::NS_NewSVGMetadataElement(nsIContent **aResult,
-                                              already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGMetadataElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                              already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGMetadataElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
   nsresult Init();
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 };
--- a/content/svg/content/src/SVGPathElement.cpp
+++ b/content/svg/content/src/SVGPathElement.cpp
@@ -36,17 +36,17 @@ SVGPathElement::WrapNode(JSContext *aCx,
 }
 
 nsSVGElement::NumberInfo SVGPathElement::sNumberInfo = 
 { &nsGkAtoms::pathLength, 0, false };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGPathElement::SVGPathElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGPathElement::SVGPathElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGPathElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPathElement)
--- a/content/svg/content/src/SVGPathElement.h
+++ b/content/svg/content/src/SVGPathElement.h
@@ -9,17 +9,17 @@
 #include "mozilla/gfx/2D.h"
 #include "mozilla/RefPtr.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGPathGeometryElement.h"
 #include "SVGAnimatedPathSegList.h"
 #include "DOMSVGPathSeg.h"
 
 nsresult NS_NewSVGPathElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 class gfxContext;
 
 typedef nsSVGPathGeometryElement SVGPathElementBase;
 
 namespace mozilla {
 
 class nsISVGPoint;
@@ -29,20 +29,20 @@ namespace dom {
 class SVGPathElement MOZ_FINAL : public SVGPathElementBase
 {
 friend class nsSVGPathFrame;
 
   typedef mozilla::gfx::Path Path;
 
 protected:
   friend nsresult (::NS_NewSVGPathElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
-  SVGPathElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGPathElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
 public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const MOZ_OVERRIDE;
 
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const MOZ_OVERRIDE;
 
--- a/content/svg/content/src/SVGPatternElement.cpp
+++ b/content/svg/content/src/SVGPatternElement.cpp
@@ -47,17 +47,17 @@ nsSVGElement::EnumInfo SVGPatternElement
 nsSVGElement::StringInfo SVGPatternElement::sStringInfo[1] =
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, true }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGPatternElement::SVGPatternElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGPatternElement::SVGPatternElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGPatternElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode method
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPatternElement)
--- a/content/svg/content/src/SVGPatternElement.h
+++ b/content/svg/content/src/SVGPatternElement.h
@@ -12,32 +12,32 @@
 #include "nsSVGElement.h"
 #include "nsSVGViewBox.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "nsSVGAnimatedTransformList.h"
 
 class nsSVGPatternFrame;
 
 nsresult NS_NewSVGPatternElement(nsIContent **aResult,
-                                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 class SVGAnimatedTransformList;
 
 typedef nsSVGElement SVGPatternElementBase;
 
 class SVGPatternElement MOZ_FINAL : public SVGPatternElementBase
 {
   friend class ::nsSVGPatternFrame;
 
 protected:
   friend nsresult (::NS_NewSVGPatternElement(nsIContent **aResult,
-                                             already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGPatternElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                             already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGPatternElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGPolygonElement.cpp
+++ b/content/svg/content/src/SVGPolygonElement.cpp
@@ -17,17 +17,17 @@ JSObject*
 SVGPolygonElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGPolygonElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGPolygonElement::SVGPolygonElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGPolygonElement::SVGPolygonElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGPolygonElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPolygonElement)
--- a/content/svg/content/src/SVGPolygonElement.h
+++ b/content/svg/content/src/SVGPolygonElement.h
@@ -5,31 +5,31 @@
 
 #ifndef mozilla_dom_SVGPolygonElement_h
 #define mozilla_dom_SVGPolygonElement_h
 
 #include "mozilla/Attributes.h"
 #include "nsSVGPolyElement.h"
 
 nsresult NS_NewSVGPolygonElement(nsIContent **aResult,
-                                 already_AddRefed<nsINodeInfo> aNodeInfo);
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGPolyElement SVGPolygonElementBase;
 
 namespace mozilla {
 namespace dom {
 
 class SVGPolygonElement MOZ_FINAL : public SVGPolygonElementBase
 {
 protected:
-  SVGPolygonElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGPolygonElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
   friend nsresult (::NS_NewSVGPolygonElement(nsIContent **aResult,
-                                             already_AddRefed<nsINodeInfo> aNodeInfo));
+                                             already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // nsSVGPathGeometryElement methods:
   virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
   virtual void ConstructPath(gfxContext *aCtx) MOZ_OVERRIDE;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 };
--- a/content/svg/content/src/SVGPolylineElement.cpp
+++ b/content/svg/content/src/SVGPolylineElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGPolylineElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGPolylineElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGPolylineElement::SVGPolylineElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGPolylineElement::SVGPolylineElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGPolylineElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPolylineElement)
--- a/content/svg/content/src/SVGPolylineElement.h
+++ b/content/svg/content/src/SVGPolylineElement.h
@@ -4,31 +4,31 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGPolylineElement_h
 #define mozilla_dom_SVGPolylineElement_h
 
 #include "nsSVGPolyElement.h"
 
 nsresult NS_NewSVGPolylineElement(nsIContent **aResult,
-                                  already_AddRefed<nsINodeInfo> aNodeInfo);
+                                  already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGPolyElement SVGPolylineElementBase;
 
 namespace mozilla {
 namespace dom {
 
 class SVGPolylineElement MOZ_FINAL : public SVGPolylineElementBase
 {
 protected:
-  SVGPolylineElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGPolylineElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
   friend nsresult (::NS_NewSVGPolylineElement(nsIContent **aResult,
-                                              already_AddRefed<nsINodeInfo> aNodeInfo));
+                                              already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // nsIContent interface
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 };
 
 } // namespace mozilla
 } // namespace dom
--- a/content/svg/content/src/SVGRectElement.cpp
+++ b/content/svg/content/src/SVGRectElement.cpp
@@ -34,17 +34,17 @@ nsSVGElement::LengthInfo SVGRectElement:
   { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
   { &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
   { &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGRectElement::SVGRectElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGRectElement::SVGRectElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGRectElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGRectElement)
--- a/content/svg/content/src/SVGRectElement.h
+++ b/content/svg/content/src/SVGRectElement.h
@@ -5,31 +5,31 @@
 
 #ifndef mozilla_dom_SVGRectElement_h
 #define mozilla_dom_SVGRectElement_h
 
 #include "nsSVGPathGeometryElement.h"
 #include "nsSVGLength2.h"
 
 nsresult NS_NewSVGRectElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGPathGeometryElement SVGRectElementBase;
 
 namespace mozilla {
 namespace dom {
 
 class SVGRectElement MOZ_FINAL : public SVGRectElementBase
 {
 protected:
-  SVGRectElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGRectElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
   friend nsresult (::NS_NewSVGRectElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const MOZ_OVERRIDE;
 
   // nsSVGPathGeometryElement methods:
   virtual void ConstructPath(gfxContext *aCtx) MOZ_OVERRIDE;
   virtual TemporaryRef<Path> BuildPath() MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGSVGElement.cpp
+++ b/content/svg/content/src/SVGSVGElement.cpp
@@ -151,18 +151,18 @@ NS_IMPL_RELEASE_INHERITED(SVGSVGElement,
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(SVGSVGElement)
   NS_INTERFACE_TABLE_INHERITED3(SVGSVGElement, nsIDOMNode, nsIDOMElement,
                                 nsIDOMSVGElement)
 NS_INTERFACE_TABLE_TAIL_INHERITING(SVGSVGElementBase)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGSVGElement::SVGSVGElement(already_AddRefed<nsINodeInfo> aNodeInfo,
-                                 FromParser aFromParser)
+SVGSVGElement::SVGSVGElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
+                             FromParser aFromParser)
   : SVGSVGElementBase(aNodeInfo),
     mViewportWidth(0),
     mViewportHeight(0),
     mCurrentTranslate(0.0f, 0.0f),
     mCurrentScale(1.0f),
     mPreviousTranslate(0.0f, 0.0f),
     mPreviousScale(1.0f),
     mStartAnimationOnBindToTree(aFromParser == NOT_FROM_PARSER ||
@@ -178,18 +178,18 @@ SVGSVGElement::SVGSVGElement(already_Add
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 // From NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGSVGElement)
 nsresult
 SVGSVGElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   *aResult = nullptr;
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-  SVGSVGElement *it = new SVGSVGElement(ni.forget(), NOT_FROM_PARSER);
+  already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
+  SVGSVGElement *it = new SVGSVGElement(ni, NOT_FROM_PARSER);
 
   nsCOMPtr<nsINode> kungFuDeathGrip = it;
   nsresult rv1 = it->Init();
   nsresult rv2 = const_cast<SVGSVGElement*>(this)->CopyInnerTo(it);
   if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) {
     kungFuDeathGrip.swap(*aResult);
   }
 
--- a/content/svg/content/src/SVGSVGElement.h
+++ b/content/svg/content/src/SVGSVGElement.h
@@ -13,17 +13,17 @@
 #include "SVGGraphicsElement.h"
 #include "SVGImageContext.h"
 #include "nsSVGViewBox.h"
 #include "SVGPreserveAspectRatio.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "mozilla/Attributes.h"
 
 nsresult NS_NewSVGSVGElement(nsIContent **aResult,
-                             already_AddRefed<nsINodeInfo> aNodeInfo,
+                             already_AddRefed<nsINodeInfo>&& aNodeInfo,
                              mozilla::dom::FromParser aFromParser);
 
 class nsIDOMSVGNumber;
 class nsSMILTimeContainer;
 class nsSVGOuterSVGFrame;
 class nsSVGInnerSVGFrame;
 class nsSVGImageFrame;
 
@@ -84,23 +84,23 @@ typedef SVGGraphicsElement SVGSVGElement
 
 class SVGSVGElement MOZ_FINAL : public SVGSVGElementBase
 {
   friend class ::nsSVGOuterSVGFrame;
   friend class ::nsSVGInnerSVGFrame;
   friend class mozilla::SVGFragmentIdentifier;
   friend class mozilla::AutoSVGRenderingState;
 
-  SVGSVGElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  SVGSVGElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                 FromParser aFromParser);
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
   friend nsresult (::NS_NewSVGSVGElement(nsIContent **aResult,
-                                         already_AddRefed<nsINodeInfo> aNodeInfo,
+                                         already_AddRefed<nsINodeInfo>&& aNodeInfo,
                                          mozilla::dom::FromParser aFromParser));
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGSVGElement, SVGSVGElementBase)
 
   /**
--- a/content/svg/content/src/SVGScriptElement.cpp
+++ b/content/svg/content/src/SVGScriptElement.cpp
@@ -33,34 +33,34 @@ NS_IMPL_ISUPPORTS_INHERITED6(SVGScriptEl
                              nsIDOMNode, nsIDOMElement,
                              nsIDOMSVGElement,
                              nsIScriptLoaderObserver,
                              nsIScriptElement, nsIMutationObserver)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGScriptElement::SVGScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+SVGScriptElement::SVGScriptElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                                    FromParser aFromParser)
   : SVGScriptElementBase(aNodeInfo)
   , nsScriptElement(aFromParser)
 {
   AddMutationObserver(this);
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 nsresult
 SVGScriptElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   *aResult = nullptr;
 
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-  SVGScriptElement* it = new SVGScriptElement(ni.forget(), NOT_FROM_PARSER);
+  already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
+  SVGScriptElement* it = new SVGScriptElement(ni, NOT_FROM_PARSER);
 
   nsCOMPtr<nsINode> kungFuDeathGrip = it;
   nsresult rv1 = it->Init();
   nsresult rv2 = const_cast<SVGScriptElement*>(this)->CopyInnerTo(it);
   NS_ENSURE_SUCCESS(rv1, rv1);
   NS_ENSURE_SUCCESS(rv2, rv2);
 
   // The clone should be marked evaluated if we are.
--- a/content/svg/content/src/SVGScriptElement.h
+++ b/content/svg/content/src/SVGScriptElement.h
@@ -10,32 +10,32 @@
 #include "nsSVGElement.h"
 #include "nsCOMPtr.h"
 #include "nsSVGString.h"
 #include "nsScriptElement.h"
 
 class nsIDocument;
 
 nsresult NS_NewSVGScriptElement(nsIContent **aResult,
-                                already_AddRefed<nsINodeInfo> aNodeInfo,
+                                already_AddRefed<nsINodeInfo>&& aNodeInfo,
                                 mozilla::dom::FromParser aFromParser);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGElement SVGScriptElementBase;
 
 class SVGScriptElement MOZ_FINAL : public SVGScriptElementBase,
                                    public nsScriptElement
 {
 protected:
   friend nsresult (::NS_NewSVGScriptElement(nsIContent **aResult,
-                                            already_AddRefed<nsINodeInfo> aNodeInfo,
+                                            already_AddRefed<nsINodeInfo>&& aNodeInfo,
                                             mozilla::dom::FromParser aFromParser));
-  SVGScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
+  SVGScriptElement(already_AddRefed<nsINodeInfo>& aNodeInfo,
                    FromParser aFromParser);
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // interfaces:
 
--- a/content/svg/content/src/SVGSetElement.cpp
+++ b/content/svg/content/src/SVGSetElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGSetElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGSetElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGSetElement::SVGSetElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGSetElement::SVGSetElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGAnimationElement(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGSetElement)
--- a/content/svg/content/src/SVGSetElement.h
+++ b/content/svg/content/src/SVGSetElement.h
@@ -6,30 +6,30 @@
 #ifndef mozilla_dom_SVGSetElement_h
 #define mozilla_dom_SVGSetElement_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimationElement.h"
 #include "nsSMILSetAnimationFunction.h"
 
 nsresult NS_NewSVGSetElement(nsIContent **aResult,
-                             already_AddRefed<nsINodeInfo> aNodeInfo);
+                             already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 class SVGSetElement MOZ_FINAL : public SVGAnimationElement
 {
 protected:
-  SVGSetElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGSetElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   nsSMILSetAnimationFunction mAnimationFunction;
 
   friend nsresult (::NS_NewSVGSetElement(nsIContent **aResult,
-                                         already_AddRefed<nsINodeInfo> aNodeInfo));
+                                         already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // nsIDOMNode
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
--- a/content/svg/content/src/SVGStopElement.cpp
+++ b/content/svg/content/src/SVGStopElement.cpp
@@ -18,17 +18,17 @@ SVGStopElement::WrapNode(JSContext *aCx,
 }
 
 nsSVGElement::NumberInfo SVGStopElement::sNumberInfo =
 { &nsGkAtoms::offset, 0, true };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGStopElement::SVGStopElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGStopElement::SVGStopElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGStopElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGStopElement)
--- a/content/svg/content/src/SVGStopElement.h
+++ b/content/svg/content/src/SVGStopElement.h
@@ -5,29 +5,29 @@
 
 #ifndef mozilla_dom_SVGStopElement_h
 #define mozilla_dom_SVGStopElement_h
 
 #include "nsSVGElement.h"
 #include "nsSVGNumber2.h"
 
 nsresult NS_NewSVGStopElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGElement SVGStopElementBase;
 
 namespace mozilla {
 namespace dom {
 
 class SVGStopElement MOZ_FINAL : public SVGStopElementBase
 {
 protected:
   friend nsresult (::NS_NewSVGStopElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGStopElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGStopElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGStyleElement.cpp
+++ b/content/svg/content/src/SVGStyleElement.cpp
@@ -41,17 +41,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGStyleElement,
                                                 SVGStyleElementBase)
   tmp->nsStyleLinkElement::Unlink();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGStyleElement::SVGStyleElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGStyleElement::SVGStyleElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGStyleElementBase(aNodeInfo)
 {
   AddMutationObserver(this);
 }
 
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
--- a/content/svg/content/src/SVGStyleElement.h
+++ b/content/svg/content/src/SVGStyleElement.h
@@ -7,31 +7,31 @@
 #define mozilla_dom_SVGStyleElement_h
 
 #include "mozilla/Attributes.h"
 #include "nsSVGElement.h"
 #include "nsStyleLinkElement.h"
 #include "nsStubMutationObserver.h"
 
 nsresult NS_NewSVGStyleElement(nsIContent **aResult,
-                               already_AddRefed<nsINodeInfo> aNodeInfo);
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 typedef nsSVGElement SVGStyleElementBase;
 
 namespace mozilla {
 namespace dom {
 
 class SVGStyleElement MOZ_FINAL : public SVGStyleElementBase,
                                   public nsStyleLinkElement,
                                   public nsStubMutationObserver
 {
 protected:
   friend nsresult (::NS_NewSVGStyleElement(nsIContent **aResult,
-                                           already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGStyleElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                           already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGStyleElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGStyleElement,
--- a/content/svg/content/src/SVGSwitchElement.cpp
+++ b/content/svg/content/src/SVGSwitchElement.cpp
@@ -33,17 +33,17 @@ NS_IMPL_ADDREF_INHERITED(SVGSwitchElemen
 NS_IMPL_RELEASE_INHERITED(SVGSwitchElement,SVGSwitchElementBase)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SVGSwitchElement)
 NS_INTERFACE_MAP_END_INHERITING(SVGSwitchElementBase)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGSwitchElement::SVGSwitchElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGSwitchElement::SVGSwitchElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGSwitchElementBase(aNodeInfo)
 {
 }
 
 void
 SVGSwitchElement::MaybeInvalidate()
 {
   // We must not change mActiveChild until after
--- a/content/svg/content/src/SVGSwitchElement.h
+++ b/content/svg/content/src/SVGSwitchElement.h
@@ -6,30 +6,30 @@
 #ifndef mozilla_dom_SVGSwitchElement_h
 #define mozilla_dom_SVGSwitchElement_h
 
 #include "mozilla/dom/SVGGraphicsElement.h"
 
 class nsSVGSwitchFrame;
 
 nsresult NS_NewSVGSwitchElement(nsIContent **aResult,
-                                already_AddRefed<nsINodeInfo> aNodeInfo);
+                                already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGGraphicsElement SVGSwitchElementBase;
 
 class SVGSwitchElement MOZ_FINAL : public SVGSwitchElementBase
 {
   friend class nsSVGSwitchFrame;
 protected:
   friend nsresult (::NS_NewSVGSwitchElement(nsIContent **aResult,
-                                            already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGSwitchElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                            already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGSwitchElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   nsIContent * GetActiveChild() const
   { return mActiveChild; }
   void MaybeInvalidate();
 
--- a/content/svg/content/src/SVGSymbolElement.cpp
+++ b/content/svg/content/src/SVGSymbolElement.cpp
@@ -22,17 +22,17 @@ SVGSymbolElement::WrapNode(JSContext *aC
 
 NS_IMPL_ISUPPORTS_INHERITED4(SVGSymbolElement, SVGSymbolElementBase,
                              nsIDOMNode, nsIDOMElement,
                              nsIDOMSVGElement, mozilla::dom::SVGTests)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGSymbolElement::SVGSymbolElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGSymbolElement::SVGSymbolElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGSymbolElementBase(aNodeInfo)
 {
 }
 
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
--- a/content/svg/content/src/SVGSymbolElement.h
+++ b/content/svg/content/src/SVGSymbolElement.h
@@ -7,30 +7,30 @@
 #define mozilla_dom_SVGSymbolElement_h
 
 #include "mozilla/dom/SVGTests.h"
 #include "nsSVGElement.h"
 #include "nsSVGViewBox.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 
 nsresult NS_NewSVGSymbolElement(nsIContent **aResult,
-                                already_AddRefed<nsINodeInfo> aNodeInfo);
+                                already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef nsSVGElement SVGSymbolElementBase;
 
 class SVGSymbolElement MOZ_FINAL : public SVGSymbolElementBase,
                                    public SVGTests
 {
 protected:
   friend nsresult (::NS_NewSVGSymbolElement(nsIContent **aResult,
-                                            already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGSymbolElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                            already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGSymbolElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
 
--- a/content/svg/content/src/SVGTSpanElement.cpp
+++ b/content/svg/content/src/SVGTSpanElement.cpp
@@ -16,17 +16,17 @@ SVGTSpanElement::WrapNode(JSContext *aCx
 {
   return SVGTSpanElementBinding::Wrap(aCx, aScope, this);
 }
 
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGTSpanElement::SVGTSpanElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGTSpanElement::SVGTSpanElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGTSpanElementBase(aNodeInfo)
 {
 }
 
 nsSVGElement::EnumAttributesInfo
 SVGTSpanElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
--- a/content/svg/content/src/SVGTSpanElement.h
+++ b/content/svg/content/src/SVGTSpanElement.h
@@ -4,29 +4,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGTSpanElement_h
 #define mozilla_dom_SVGTSpanElement_h
 
 #include "mozilla/dom/SVGTextPositioningElement.h"
 
 nsresult NS_NewSVGTSpanElement(nsIContent **aResult,
-                               already_AddRefed<nsINodeInfo> aNodeInfo);
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGTextPositioningElement SVGTSpanElementBase;
 
 class SVGTSpanElement MOZ_FINAL : public SVGTSpanElementBase
 {
 protected:
   friend nsresult (::NS_NewSVGTSpanElement(nsIContent **aResult,
-                                           already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGTSpanElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                           already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGTSpanElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGTextContentElement.h
+++ b/content/svg/content/src/SVGTextContentElement.h
@@ -41,17 +41,17 @@ public:
   already_AddRefed<nsISVGPoint> GetStartPositionOfChar(uint32_t charnum, ErrorResult& rv);
   already_AddRefed<nsISVGPoint> GetEndPositionOfChar(uint32_t charnum, ErrorResult& rv);
   already_AddRefed<SVGIRect> GetExtentOfChar(uint32_t charnum, ErrorResult& rv);
   float GetRotationOfChar(uint32_t charnum, ErrorResult& rv);
   int32_t GetCharNumAtPosition(nsISVGPoint& point);
 
 protected:
 
-  SVGTextContentElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGTextContentElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGTextContentElementBase(aNodeInfo)
   {}
 
   SVGTextFrame* GetSVGTextFrame();
 
   enum { LENGTHADJUST };
   virtual nsSVGEnum* EnumAttributes() = 0;
   static nsSVGEnumMapping sLengthAdjustMap[];
--- a/content/svg/content/src/SVGTextElement.cpp
+++ b/content/svg/content/src/SVGTextElement.cpp
@@ -15,17 +15,17 @@ JSObject*
 SVGTextElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGTextElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGTextElement::SVGTextElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGTextElement::SVGTextElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGTextElementBase(aNodeInfo)
 {
 }
 
 nsSVGElement::EnumAttributesInfo
 SVGTextElement::GetEnumInfo()
 {
   return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
--- a/content/svg/content/src/SVGTextElement.h
+++ b/content/svg/content/src/SVGTextElement.h
@@ -4,32 +4,32 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGTextElement_h
 #define mozilla_dom_SVGTextElement_h
 
 #include "mozilla/dom/SVGTextPositioningElement.h"
 
 nsresult NS_NewSVGTextElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGTextPositioningElement SVGTextElementBase;
 
 class SVGTextElement MOZ_FINAL : public SVGTextElementBase
 {
 protected:
-  SVGTextElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGTextElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
   friend nsresult (::NS_NewSVGTextElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
 
 public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
 protected:
--- a/content/svg/content/src/SVGTextPathElement.cpp
+++ b/content/svg/content/src/SVGTextPathElement.cpp
@@ -63,17 +63,17 @@ nsSVGElement::EnumInfo SVGTextPathElemen
 nsSVGElement::StringInfo SVGTextPathElement::sStringInfo[1] =
 {
   { &nsGkAtoms::href, kNameSpaceID_XLink, true }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGTextPathElement::SVGTextPathElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGTextPathElement::SVGTextPathElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGTextPathElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTextPathElement)
--- a/content/svg/content/src/SVGTextPathElement.h
+++ b/content/svg/content/src/SVGTextPathElement.h
@@ -11,17 +11,17 @@
 #include "nsSVGString.h"
 #include "mozilla/dom/SVGTextContentElement.h"
 
 class nsIAtom;
 class nsIContent;
 class nsINodeInfo;
 
 nsresult NS_NewSVGTextPathElement(nsIContent **aResult,
-                                  already_AddRefed<nsINodeInfo> aNodeInfo);
+                                  already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 // textPath Method Types
 static const unsigned short TEXTPATH_METHODTYPE_UNKNOWN  = 0;
 static const unsigned short TEXTPATH_METHODTYPE_ALIGN    = 1;
 static const unsigned short TEXTPATH_METHODTYPE_STRETCH  = 2;
@@ -33,18 +33,18 @@ static const unsigned short TEXTPATH_SPA
 typedef SVGTextContentElement SVGTextPathElementBase;
 
 class SVGTextPathElement MOZ_FINAL : public SVGTextPathElementBase
 {
 friend class ::SVGTextFrame;
 
 protected:
   friend nsresult (::NS_NewSVGTextPathElement(nsIContent **aResult,
-                                              already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGTextPathElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                              already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGTextPathElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
--- a/content/svg/content/src/SVGTextPositioningElement.h
+++ b/content/svg/content/src/SVGTextPositioningElement.h
@@ -27,17 +27,17 @@ public:
   already_AddRefed<DOMSVGAnimatedLengthList> X();
   already_AddRefed<DOMSVGAnimatedLengthList> Y();
   already_AddRefed<DOMSVGAnimatedLengthList> Dx();
   already_AddRefed<DOMSVGAnimatedLengthList> Dy();
   already_AddRefed<DOMSVGAnimatedNumberList> Rotate();
 
 protected:
 
-  SVGTextPositioningElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGTextPositioningElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGTextPositioningElementBase(aNodeInfo)
   {}
 
   virtual LengthListAttributesInfo GetLengthListInfo() MOZ_OVERRIDE;
   virtual NumberListAttributesInfo GetNumberListInfo() MOZ_OVERRIDE;
 
   enum { ATTR_X, ATTR_Y, ATTR_DX, ATTR_DY };
   SVGAnimatedLengthList mLengthListAttributes[4];
--- a/content/svg/content/src/SVGTitleElement.cpp
+++ b/content/svg/content/src/SVGTitleElement.cpp
@@ -23,17 +23,17 @@ SVGTitleElement::WrapNode(JSContext *aCx
 NS_IMPL_ISUPPORTS_INHERITED4(SVGTitleElement, SVGTitleElementBase,
                              nsIDOMNode, nsIDOMElement,
                              nsIDOMSVGElement,
                              nsIMutationObserver)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGTitleElement::SVGTitleElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGTitleElement::SVGTitleElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGTitleElementBase(aNodeInfo)
 {
   AddMutationObserver(this);
 }
 
 void
 SVGTitleElement::CharacterDataChanged(nsIDocument *aDocument,
                                       nsIContent *aContent,
--- a/content/svg/content/src/SVGTitleElement.h
+++ b/content/svg/content/src/SVGTitleElement.h
@@ -8,27 +8,27 @@
 
 #include "mozilla/Attributes.h"
 #include "nsSVGElement.h"
 #include "nsStubMutationObserver.h"
 
 typedef nsSVGElement SVGTitleElementBase;
 
 nsresult NS_NewSVGTitleElement(nsIContent **aResult,
-                               already_AddRefed<nsINodeInfo> aNodeInfo);
+                               already_AddRefed<nsINodeInfo>&& aNodeInfo);
 namespace mozilla {
 namespace dom {
 
 class SVGTitleElement MOZ_FINAL : public SVGTitleElementBase,
                                   public nsStubMutationObserver
 {
 protected:
   friend nsresult (::NS_NewSVGTitleElement(nsIContent **aResult,
-                                           already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGTitleElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                           already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGTitleElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
--- a/content/svg/content/src/SVGTransformableElement.h
+++ b/content/svg/content/src/SVGTransformableElement.h
@@ -18,17 +18,17 @@ namespace dom {
 class SVGAnimatedTransformList;
 class SVGGraphicsElement;
 class SVGMatrix;
 class SVGIRect;
 
 class SVGTransformableElement : public nsSVGElement
 {
 public:
-  SVGTransformableElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGTransformableElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsSVGElement(aNodeInfo) {}
   virtual ~SVGTransformableElement() {}
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE = 0;
 
   // WebIDL
   already_AddRefed<SVGAnimatedTransformList> Transform();
   nsSVGElement* GetNearestViewportElement();
--- a/content/svg/content/src/SVGUseElement.cpp
+++ b/content/svg/content/src/SVGUseElement.cpp
@@ -66,35 +66,35 @@ NS_IMPL_RELEASE_INHERITED(SVGUseElement,
 
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(SVGUseElement)
   NS_INTERFACE_TABLE_INHERITED1(SVGUseElement, nsIMutationObserver)
 NS_INTERFACE_TABLE_TAIL_INHERITING(SVGUseElementBase)
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGUseElement::SVGUseElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGUseElement::SVGUseElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGUseElementBase(aNodeInfo), mSource(MOZ_THIS_IN_INITIALIZER_LIST())
 {
 }
 
 SVGUseElement::~SVGUseElement()
 {
   UnlinkSource();
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 nsresult
 SVGUseElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   *aResult = nullptr;
-  nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
-  SVGUseElement *it = new SVGUseElement(ni.forget());
+  already_AddRefed<nsINodeInfo> ni = nsCOMPtr<nsINodeInfo>(aNodeInfo).forget();
+  SVGUseElement *it = new SVGUseElement(ni);
 
   nsCOMPtr<nsINode> kungFuDeathGrip(it);
   nsresult rv1 = it->Init();
   nsresult rv2 = const_cast<SVGUseElement*>(this)->CopyInnerTo(it);
 
   // SVGUseElement specific portion - record who we cloned from
   it->mOriginal = const_cast<SVGUseElement*>(this);
 
--- a/content/svg/content/src/SVGUseElement.h
+++ b/content/svg/content/src/SVGUseElement.h
@@ -15,34 +15,34 @@
 #include "nsTArray.h"
 
 class nsIContent;
 class nsINodeInfo;
 class nsSVGUseFrame;
 
 nsresult
 NS_NewSVGSVGElement(nsIContent **aResult,
-                    already_AddRefed<nsINodeInfo> aNodeInfo,
+                    already_AddRefed<nsINodeInfo>&& aNodeInfo,
                     mozilla::dom::FromParser aFromParser);
 nsresult NS_NewSVGUseElement(nsIContent **aResult,
-                             already_AddRefed<nsINodeInfo> aNodeInfo);
+                             already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 namespace dom {
 
 typedef SVGGraphicsElement SVGUseElementBase;
 
 class SVGUseElement MOZ_FINAL : public SVGUseElementBase,
                                 public nsStubMutationObserver
 {
   friend class ::nsSVGUseFrame;
 protected:
   friend nsresult (::NS_NewSVGUseElement(nsIContent **aResult,
-                                         already_AddRefed<nsINodeInfo> aNodeInfo));
-  SVGUseElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+                                         already_AddRefed<nsINodeInfo>&& aNodeInfo));
+  SVGUseElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   virtual ~SVGUseElement();
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
--- a/content/svg/content/src/SVGViewElement.cpp
+++ b/content/svg/content/src/SVGViewElement.cpp
@@ -35,17 +35,17 @@ nsSVGElement::EnumInfo SVGViewElement::s
     sZoomAndPanMap,
     SVG_ZOOMANDPAN_MAGNIFY
   }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
-SVGViewElement::SVGViewElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+SVGViewElement::SVGViewElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : SVGViewElementBase(aNodeInfo)
 {
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGViewElement)
--- a/content/svg/content/src/SVGViewElement.h
+++ b/content/svg/content/src/SVGViewElement.h
@@ -16,33 +16,33 @@ static const unsigned short SVG_ZOOMANDP
 static const unsigned short SVG_ZOOMANDPAN_DISABLE = 1;
 static const unsigned short SVG_ZOOMANDPAN_MAGNIFY = 2;
 
 typedef nsSVGElement SVGViewElementBase;
 
 class nsSVGOuterSVGFrame;
 
 nsresult NS_NewSVGViewElement(nsIContent **aResult,
-                              already_AddRefed<nsINodeInfo> aNodeInfo);
+                              already_AddRefed<nsINodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 class SVGFragmentIdentifier;
 
 namespace dom {
 class SVGSVGElement;
 
 class SVGViewElement : public SVGViewElementBase
 {
 protected:
   friend class mozilla::SVGFragmentIdentifier;
   friend class SVGSVGElement;
   friend class ::nsSVGOuterSVGFrame;
-  SVGViewElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  SVGViewElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   friend nsresult (::NS_NewSVGViewElement(nsIContent **aResult,
-                                          already_AddRefed<nsINodeInfo> aNodeInfo));
+                                          already_AddRefed<nsINodeInfo>&& aNodeInfo));
   virtual JSObject* WrapNode(JSContext *cx,
                              JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   // WebIDL
   uint16_t ZoomAndPan() { return mEnumAttributes[ZOOMANDPAN].GetAnimValue(); }
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/DebugOnly.h"
+#include "mozilla/unused.h"
 
 #include "nsSVGElement.h"
 
 #include "mozilla/dom/SVGSVGElement.h"
 #include "mozilla/dom/SVGTests.h"
 #include "nsContentUtils.h"
 #include "nsICSSDeclaration.h"
 #include "nsIDocument.h"
@@ -44,29 +45,30 @@
 #include "SVGContentUtils.h"
 #include "nsIFrame.h"
 #include <stdarg.h>
 #include "nsSMILMappedAttribute.h"
 #include "SVGMotionSMILAttr.h"
 #include "nsAttrValueOrString.h"
 #include "nsSMILAnimationController.h"
 #include "mozilla/dom/SVGElementBinding.h"
+#include "mozilla/unused.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 // This is needed to ensure correct handling of calls to the
 // vararg-list methods in this file:
 //   nsSVGElement::GetAnimated{Length,Number,Integer}Values
 // See bug 547964 for details:
 static_assert(sizeof(void*) == sizeof(nullptr),
               "nullptr should be the correct size");
 
 nsresult
-NS_NewSVGElement(Element **aResult, already_AddRefed<nsINodeInfo> aNodeInfo) 
+NS_NewSVGElement(Element **aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo)
 {
   nsRefPtr<nsSVGElement> it = new nsSVGElement(aNodeInfo);
   nsresult rv = it->Init();
 
   if (NS_FAILED(rv)) {
     return rv;
   }
 
@@ -77,34 +79,34 @@ NS_NewSVGElement(Element **aResult, alre
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGElement)
 
 nsSVGEnumMapping nsSVGElement::sSVGUnitTypesMap[] = {
   {&nsGkAtoms::userSpaceOnUse, SVG_UNIT_TYPE_USERSPACEONUSE},
   {&nsGkAtoms::objectBoundingBox, SVG_UNIT_TYPE_OBJECTBOUNDINGBOX},
   {nullptr, 0}
 };
 
-nsSVGElement::nsSVGElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+nsSVGElement::nsSVGElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsSVGElementBase(aNodeInfo)
 {
 }
 
 JSObject*
 nsSVGElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return SVGElementBinding::Wrap(aCx, aScope, this);
 }
 
 //----------------------------------------------------------------------
 
 /* readonly attribute SVGAnimatedString className; */
 NS_IMETHODIMP
 nsSVGElement::GetClassName(nsISupports** aClassName)
 {
-  *aClassName = ClassName().get();
+  *aClassName = ClassName().take();
   return NS_OK;
 }
 
 /* readonly attribute nsIDOMCSSStyleDeclaration style; */
 NS_IMETHODIMP
 nsSVGElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
 {
   NS_ADDREF(*aStyle = Style());
@@ -1358,17 +1360,17 @@ nsSVGElement::UpdateAnimatedContentStyle
   if (animContentStyleRule) {
 #ifdef DEBUG
     nsresult rv =
 #endif
       SetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
                   SMIL_MAPPED_ATTR_STYLERULE_ATOM,
                   animContentStyleRule.get(),
                   ReleaseStyleRule);
-    animContentStyleRule.forget();
+    unused << animContentStyleRule.forget();
     NS_ABORT_IF_FALSE(rv == NS_OK,
                       "SetProperty failed (or overwrote something)");
   }
 }
 
 css::StyleRule*
 nsSVGElement::GetAnimatedContentStyleRule()
 {
--- a/content/svg/content/src/nsSVGElement.h
+++ b/content/svg/content/src/nsSVGElement.h
@@ -68,19 +68,19 @@ struct gfxMatrix;
 struct nsSVGEnumMapping;
 
 typedef nsStyledElementNotElementCSSInlineStyle nsSVGElementBase;
 
 class nsSVGElement : public nsSVGElementBase    // nsIContent
                    , public nsIDOMSVGElement
 {
 protected:
-  nsSVGElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsSVGElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
   friend nsresult NS_NewSVGElement(mozilla::dom::Element **aResult,
-                                   already_AddRefed<nsINodeInfo> aNodeInfo);
+                                   already_AddRefed<nsINodeInfo>&& aNodeInfo);
   nsresult Init();
   virtual ~nsSVGElement(){}
 
 public:
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
 
   typedef mozilla::SVGNumberList SVGNumberList;
@@ -629,17 +629,17 @@ private:
 };
 
 /**
  * A macro to implement the NS_NewSVGXXXElement() functions.
  */
 #define NS_IMPL_NS_NEW_SVG_ELEMENT(_elementName)                             \
 nsresult                                                                     \
 NS_NewSVG##_elementName##Element(nsIContent **aResult,                       \
-                                 already_AddRefed<nsINodeInfo> aNodeInfo)    \
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo)  \
 {                                                                            \
   nsRefPtr<nsSVG##_elementName##Element> it =                                \
     new nsSVG##_elementName##Element(aNodeInfo);                             \
                                                                              \
   nsresult rv = it->Init();                                                  \
                                                                              \
   if (NS_FAILED(rv)) {                                                       \
     return rv;                                                               \
@@ -648,17 +648,17 @@ NS_NewSVG##_elementName##Element(nsICont
   it.forget(aResult);                                                        \
                                                                              \
   return rv;                                                                 \
 }
 
 #define NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(_elementName)                  \
 nsresult                                                                     \
 NS_NewSVG##_elementName##Element(nsIContent **aResult,                       \
-                                 already_AddRefed<nsINodeInfo> aNodeInfo)    \
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo)  \
 {                                                                            \
   nsRefPtr<mozilla::dom::SVG##_elementName##Element> it =                    \
     new mozilla::dom::SVG##_elementName##Element(aNodeInfo);                 \
                                                                              \
   nsresult rv = it->Init();                                                  \
                                                                              \
   if (NS_FAILED(rv)) {                                                       \
     return rv;                                                               \
@@ -667,17 +667,17 @@ NS_NewSVG##_elementName##Element(nsICont
   it.forget(aResult);                                                        \
                                                                              \
   return rv;                                                                 \
 }
 
 #define NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT_CHECK_PARSER(_elementName)     \
 nsresult                                                                     \
 NS_NewSVG##_elementName##Element(nsIContent **aResult,                       \
-                                 already_AddRefed<nsINodeInfo> aNodeInfo,    \
+                                 already_AddRefed<nsINodeInfo>&& aNodeInfo,  \
                                  mozilla::dom::FromParser aFromParser)       \
 {                                                                            \
   nsRefPtr<mozilla::dom::SVG##_elementName##Element> it =                    \
     new mozilla::dom::SVG##_elementName##Element(aNodeInfo, aFromParser);    \
                                                                              \
   nsresult rv = it->Init();                                                  \
                                                                              \
   if (NS_FAILED(rv)) {                                                       \
--- a/content/svg/content/src/nsSVGFilters.h
+++ b/content/svg/content/src/nsSVGFilters.h
@@ -46,17 +46,18 @@ class nsSVGFE : public nsSVGFEBase
 
 protected:
   typedef mozilla::gfx::SourceSurface SourceSurface;
   typedef mozilla::gfx::Size Size;
   typedef mozilla::gfx::IntRect IntRect;
   typedef mozilla::gfx::ColorSpace ColorSpace;
   typedef mozilla::gfx::FilterPrimitiveDescription FilterPrimitiveDescription;
 
-  nsSVGFE(already_AddRefed<nsINodeInfo> aNodeInfo) : nsSVGFEBase(aNodeInfo) {}
+  nsSVGFE(already_AddRefed<nsINodeInfo>& aNodeInfo)
+    : nsSVGFEBase(aNodeInfo) {}
 
 public:
   typedef mozilla::gfx::AttributeMap AttributeMap;
 
   ColorSpace
   GetInputColorSpace(int32_t aInputIndex, ColorSpace aUnchangedInputColorSpace) {
     return OperatesOnSRGB(aInputIndex, aUnchangedInputColorSpace == mozilla::gfx::SRGB) ?
              mozilla::gfx::SRGB : mozilla::gfx::LINEAR_RGB;
@@ -147,17 +148,17 @@ protected:
   static LengthInfo sLengthInfo[4];
 };
 
 typedef nsSVGElement SVGFEUnstyledElementBase;
 
 class SVGFEUnstyledElement : public SVGFEUnstyledElementBase
 {
 protected:
-  SVGFEUnstyledElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFEUnstyledElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFEUnstyledElementBase(aNodeInfo) {}
 
 public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE = 0;
 
   // returns true if changes to the attribute should cause us to
   // repaint the filter
   virtual bool AttributeAffectsRendering(
@@ -166,17 +167,17 @@ public:
 
 //------------------------------------------------------------
 
 typedef nsSVGFE nsSVGFELightingElementBase;
 
 class nsSVGFELightingElement : public nsSVGFELightingElementBase
 {
 protected:
-  nsSVGFELightingElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  nsSVGFELightingElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : nsSVGFELightingElementBase(aNodeInfo) {}
 
 public:
   // interfaces:
   NS_DECL_ISUPPORTS_INHERITED
 
   virtual bool AttributeAffectsRendering(
           int32_t aNameSpaceID, nsIAtom* aAttribute) const MOZ_OVERRIDE;
@@ -216,17 +217,17 @@ protected:
 namespace mozilla {
 namespace dom {
 
 typedef SVGFEUnstyledElement SVGFELightElementBase;
 
 class SVGFELightElement : public SVGFELightElementBase
 {
 protected:
-  SVGFELightElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  SVGFELightElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : SVGFELightElementBase(aNodeInfo) {}
 
 public:
   typedef gfx::AttributeMap AttributeMap;
 
   virtual AttributeMap
     ComputeLightAttributes(nsSVGFilterInstance* aInstance) = 0;
 };
--- a/content/svg/content/src/nsSVGPathGeometryElement.cpp
+++ b/content/svg/content/src/nsSVGPathGeometryElement.cpp
@@ -12,17 +12,17 @@
 #include "SVGContentUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 //----------------------------------------------------------------------
 // Implementation
 
-nsSVGPathGeometryElement::nsSVGPathGeometryElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+nsSVGPathGeometryElement::nsSVGPathGeometryElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsSVGPathGeometryElementBase(aNodeInfo)
 {
 }
 
 bool
 nsSVGPathGeometryElement::AttributeDefinesGeometry(const nsIAtom *aName)
 {
   // Check for nsSVGLength2 attribute
--- a/content/svg/content/src/nsSVGPathGeometryElement.h
+++ b/content/svg/content/src/nsSVGPathGeometryElement.h
@@ -5,17 +5,16 @@
 
 #ifndef __NS_SVGPATHGEOMETRYELEMENT_H__
 #define __NS_SVGPATHGEOMETRYELEMENT_H__
 
 #include "mozilla/gfx/2D.h"
 #include "SVGGraphicsElement.h"
 
 struct gfxMatrix;
-template <class E> class nsTArray;
 
 struct nsSVGMark {
   enum Type {
     eStart,
     eMid,
     eEnd,
 
     eTypeCount
@@ -35,17 +34,17 @@ class nsSVGPathGeometryElement : public 
 {
 protected:
   typedef mozilla::gfx::FillRule FillRule;
   typedef mozilla::gfx::Float Float;
   typedef mozilla::gfx::Path Path;
   typedef mozilla::gfx::PathBuilder PathBuilder;
 
 public:
-  nsSVGPathGeometryElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsSVGPathGeometryElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
   virtual bool AttributeDefinesGeometry(const nsIAtom *aName);
 
   /**
    * Returns true if this element's geometry depends on the width or height of its
    * coordinate context (typically the viewport established by its nearest <svg>
    * ancestor). In other words, returns true if one of the attributes for which
    * AttributeDefinesGeometry returns true has a percentage value.
--- a/content/svg/content/src/nsSVGPolyElement.cpp
+++ b/content/svg/content/src/nsSVGPolyElement.cpp
@@ -19,17 +19,17 @@ NS_IMPL_ADDREF_INHERITED(nsSVGPolyElemen
 NS_IMPL_RELEASE_INHERITED(nsSVGPolyElement,nsSVGPolyElementBase)
 
 NS_INTERFACE_MAP_BEGIN(nsSVGPolyElement)
 NS_INTERFACE_MAP_END_INHERITING(nsSVGPolyElementBase)
 
 //----------------------------------------------------------------------
 // Implementation
 
-nsSVGPolyElement::nsSVGPolyElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+nsSVGPolyElement::nsSVGPolyElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsSVGPolyElementBase(aNodeInfo)
 {
 }
 
 already_AddRefed<DOMSVGPointList>
 nsSVGPolyElement::Points()
 {
   void *key = mPoints.GetBaseValKey();
--- a/content/svg/content/src/nsSVGPolyElement.h
+++ b/content/svg/content/src/nsSVGPolyElement.h
@@ -16,17 +16,17 @@ class gfxContext;
 
 namespace mozilla {
 class DOMSVGPointList;
 }
 
 class nsSVGPolyElement : public nsSVGPolyElementBase
 {
 protected:
-  nsSVGPolyElement(already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsSVGPolyElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
 
 public:
   //interfaces
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
--- a/content/xml/content/src/ProcessingInstruction.cpp
+++ b/content/xml/content/src/ProcessingInstruction.cpp
@@ -39,19 +39,19 @@ NS_NewXMLProcessingInstruction(nsNodeInf
     new ProcessingInstruction(ni.forget(), aData);
 
   return instance.forget();
 }
 
 namespace mozilla {
 namespace dom {
 
-ProcessingInstruction::ProcessingInstruction(already_AddRefed<nsINodeInfo> aNodeInfo,
+ProcessingInstruction::ProcessingInstruction(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                                              const nsAString& aData)
-  : nsGenericDOMDataNode(aNodeInfo)
+  : nsGenericDOMDataNode(Move(aNodeInfo))
 {
   NS_ABORT_IF_FALSE(mNodeInfo->NodeType() ==
                       nsIDOMNode::PROCESSING_INSTRUCTION_NODE,
                     "Bad NodeType in aNodeInfo");
 
   SetTextInternal(0, mText.GetLength(),
                   aData.BeginReading(), aData.Length(),
                   false);  // Don't notify (bug 420429).
--- a/content/xml/content/src/ProcessingInstruction.h
+++ b/content/xml/content/src/ProcessingInstruction.h
@@ -13,17 +13,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class ProcessingInstruction : public nsGenericDOMDataNode,
                               public nsIDOMProcessingInstruction
 {
 public:
-  ProcessingInstruction(already_AddRefed<nsINodeInfo> aNodeInfo,
+  ProcessingInstruction(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                         const nsAString& aData);
   virtual ~ProcessingInstruction();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
--- a/content/xml/content/src/XMLStylesheetProcessingInstruction.h
+++ b/content/xml/content/src/XMLStylesheetProcessingInstruction.h
@@ -13,19 +13,19 @@
 namespace mozilla {
 namespace dom {
 
 class XMLStylesheetProcessingInstruction MOZ_FINAL
 : public ProcessingInstruction
 , public nsStyleLinkElement
 {
 public:
-  XMLStylesheetProcessingInstruction(already_AddRefed<nsINodeInfo> aNodeInfo,
+  XMLStylesheetProcessingInstruction(already_AddRefed<nsINodeInfo>&& aNodeInfo,
                                      const nsAString& aData)
-    : ProcessingInstruction(aNodeInfo, aData)
+    : ProcessingInstruction(Move(aNodeInfo), aData)
   {
   }
 
   XMLStylesheetProcessingInstruction(nsNodeInfoManager* aNodeInfoManager,
                                      const nsAString& aData)
     : ProcessingInstruction(aNodeInfoManager->GetNodeInfo(
                                        nsGkAtoms::processingInstructionTagName,
                                        nullptr, kNameSpaceID_None,
--- a/content/xml/content/src/nsXMLElement.cpp
+++ b/content/xml/content/src/nsXMLElement.cpp
@@ -7,17 +7,17 @@
 #include "mozilla/dom/ElementBinding.h"
 #include "mozilla/dom/ElementInlines.h"
 #include "nsContentUtils.h" // nsAutoScriptBlocker
 
 using namespace mozilla::dom;
 
 nsresult
 NS_NewXMLElement(Element** aInstancePtrResult,
-                 already_AddRefed<nsINodeInfo> aNodeInfo)
+                 already_AddRefed<nsINodeInfo>&& aNodeInfo)
 {
   nsXMLElement* it = new nsXMLElement(aNodeInfo);
   NS_ADDREF(*aInstancePtrResult = it);
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS_INHERITED2(nsXMLElement, Element,
                              nsIDOMNode, nsIDOMElement)
--- a/content/xml/content/src/nsXMLElement.h
+++ b/content/xml/content/src/nsXMLElement.h
@@ -10,17 +10,17 @@
 #include "nsIDOMElement.h"
 #include "mozilla/dom/ElementInlines.h"
 #include "mozilla/dom/DOMRect.h"
 
 class nsXMLElement : public mozilla::dom::Element,
                      public nsIDOMElement
 {
 public:
-  nsXMLElement(already_AddRefed<nsINodeInfo> aNodeInfo)
+  nsXMLElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
     : mozilla::dom::Element(aNodeInfo)
   {
   }
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -288,38 +288,41 @@ nsXULElement::Create(nsXULPrototypeEleme
     }
 
     element.forget(aResult);
 
     return NS_OK;
 }
 
 nsresult
-NS_NewXULElement(Element** aResult, already_AddRefed<nsINodeInfo> aNodeInfo)
+NS_NewXULElement(Element** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo)
 {
-    NS_PRECONDITION(aNodeInfo.get(), "need nodeinfo for non-proto Create");
+    nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
 
-    nsIDocument* doc = aNodeInfo.get()->GetDocument();
+    NS_PRECONDITION(ni, "need nodeinfo for non-proto Create");
+
+    nsIDocument* doc = ni->GetDocument();
     if (doc && !doc->AllowXULXBL()) {
-        nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
         return NS_ERROR_NOT_AVAILABLE;
     }
 
-    NS_ADDREF(*aResult = new nsXULElement(aNodeInfo));
+    NS_ADDREF(*aResult = new nsXULElement(ni.forget()));
 
     return NS_OK;
 }
 
 void
-NS_TrustedNewXULElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo)
+NS_TrustedNewXULElement(nsIContent** aResult,
+                        already_AddRefed<nsINodeInfo>&& aNodeInfo)
 {
-    NS_PRECONDITION(aNodeInfo.get(), "need nodeinfo for non-proto Create");
+    nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
+    NS_PRECONDITION(ni, "need nodeinfo for non-proto Create");
 
     // Create an nsXULElement with the specified namespace and tag.
-    NS_ADDREF(*aResult = new nsXULElement(aNodeInfo));
+    NS_ADDREF(*aResult = new nsXULElement(ni.forget()));
 }
 
 //----------------------------------------------------------------------
 // nsISupports interface
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULElement)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULElement,
@@ -411,17 +414,17 @@ nsXULElement::Clone(nsINodeInfo *aNodeIn
 
 //----------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
                                      const nsAString& aValue,
                                      nsIDOMNodeList** aReturn)
 {
-    *aReturn = GetElementsByAttribute(aAttribute, aValue).get();
+    *aReturn = GetElementsByAttribute(aAttribute, aValue).take();
     return NS_OK;
 }
 
 already_AddRefed<nsINodeList>
 nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
                                      const nsAString& aValue)
 {
     nsCOMPtr<nsIAtom> attrAtom(do_GetAtom(aAttribute));
@@ -440,17 +443,17 @@ nsXULElement::GetElementsByAttribute(con
 NS_IMETHODIMP
 nsXULElement::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
                                        const nsAString& aAttribute,
                                        const nsAString& aValue,
                                        nsIDOMNodeList** aReturn)
 {
     ErrorResult rv;
     *aReturn =
-        GetElementsByAttributeNS(aNamespaceURI, aAttribute, aValue, rv).get();
+        GetElementsByAttributeNS(aNamespaceURI, aAttribute, aValue, rv).take();
     return rv.ErrorCode();
 }
 
 already_AddRefed<nsINodeList>
 nsXULElement::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
                                        const nsAString& aAttribute,
                                        const nsAString& aValue,
                                        ErrorResult& rv)
@@ -1217,17 +1220,17 @@ nsXULElement::PreHandleEvent(nsEventChai
     return nsStyledElement::PreHandleEvent(aVisitor);
 }
 
 // XXX This _should_ be an implementation method, _not_ publicly exposed :-(
 NS_IMETHODIMP
 nsXULElement::GetResource(nsIRDFResource** aResource)
 {
     ErrorResult rv;
-    *aResource = GetResource(rv).get();
+    *aResource = GetResource(rv).take();
     return rv.ErrorCode();
 }
 
 already_AddRefed<nsIRDFResource>
 nsXULElement::GetResource(ErrorResult& rv)
 {
     nsAutoString id;
     GetAttr(kNameSpaceID_None, nsGkAtoms::ref, id);
@@ -1243,17 +1246,17 @@ nsXULElement::GetResource(ErrorResult& r
     rv = nsXULContentUtils::RDFService()->
         GetUnicodeResource(id, getter_AddRefs(resource));
     return resource.forget();
 }
 
 NS_IMETHODIMP
 nsXULElement::GetDatabase(nsIRDFCompositeDataSource** aDatabase)
 {
-    *aDatabase = GetDatabase().get();
+    *aDatabase = GetDatabase().take();
     return NS_OK;
 }
 
 already_AddRefed<nsIRDFCompositeDataSource>
 nsXULElement::GetDatabase()
 {
     nsCOMPtr<nsIXULTemplateBuilder> builder = GetBuilder();
     if (!builder) {
@@ -1264,17 +1267,17 @@ nsXULElement::GetDatabase()
     builder->GetDatabase(getter_AddRefs(database));
     return database.forget();
 }
 
 
 NS_IMETHODIMP
 nsXULElement::GetBuilder(nsIXULTemplateBuilder** aBuilder)
 {
-    *aBuilder = GetBuilder().get();
+    *aBuilder = GetBuilder().take();
     return NS_OK;
 }
 
 already_AddRefed<nsIXULTemplateBuilder>
 nsXULElement::GetBuilder()
 {
     // XXX sXBL/XBL2 issue! Owner or current document?
     nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(GetCurrentDoc());
@@ -1358,17 +1361,17 @@ nsXULElement::GetControllers(ErrorResult
 
     return Controllers();
 }
 
 NS_IMETHODIMP
 nsXULElement::GetBoxObject(nsIBoxObject** aResult)
 {
     ErrorResult rv;
-    *aResult = GetBoxObject(rv).get();
+    *aResult = GetBoxObject(rv).take();
     return rv.ErrorCode();
 }
 
 already_AddRefed<nsIBoxObject>
 nsXULElement::GetBoxObject(ErrorResult& rv)
 {
     // XXX sXBL/XBL2 issue! Owner or current document?
     return OwnerDoc()->GetBoxObjectFor(this, rv);
@@ -1461,17 +1464,17 @@ nsXULElement::LoadSrc()
     }
 
     return slots->mFrameLoader->LoadFrame();
 }
 
 nsresult
 nsXULElement::GetFrameLoader(nsIFrameLoader **aFrameLoader)
 {
-    *aFrameLoader = GetFrameLoader().get();
+    *aFrameLoader = GetFrameLoader().take();
     return NS_OK;
 }
 
 already_AddRefed<nsFrameLoader>
 nsXULElement::GetFrameLoader()
 {
     nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingSlots());
     if (!slots)
@@ -2239,17 +2242,19 @@ nsXULPrototypeElement::Deserialize(nsIOb
                 }
                 if (! script->mOutOfLine) {
                     tmp = script->Deserialize(aStream, aProtoDoc, aDocumentURI,
                                               aNodeInfos);
                     if (NS_FAILED(tmp)) {
                       rv = tmp;
                     }
                 } else {
-                    tmp = aStream->ReadObject(true, getter_AddRefs(script->mSrcURI));
+                    nsCOMPtr<nsISupports> supports;
+                    tmp = aStream->ReadObject(true, getter_AddRefs(supports));
+                    script->mSrcURI = do_QueryInterface(supports);
                     if (NS_FAILED(tmp)) {
                       rv = tmp;
                     }
 
                     tmp = script->DeserializeOutOfLine(aStream, aProtoDoc);
                     if (NS_FAILED(tmp)) {
                       rv = tmp;
                     }
--- a/content/xul/document/src/XULDocument.cpp
+++ b/content/xul/document/src/XULDocument.cpp
@@ -1215,17 +1215,17 @@ XULDocument::ResolveForwardReferences()
 // nsIDOMDocument interface
 //
 
 NS_IMETHODIMP
 XULDocument::GetElementsByAttribute(const nsAString& aAttribute,
                                     const nsAString& aValue,
                                     nsIDOMNodeList** aReturn)
 {
-    *aReturn = GetElementsByAttribute(aAttribute, aValue).get();
+    *aReturn = GetElementsByAttribute(aAttribute, aValue).take();
     return NS_OK;
 }
 
 already_AddRefed<nsINodeList>
 XULDocument::GetElementsByAttribute(const nsAString& aAttribute,
                                     const nsAString& aValue)
 {
     nsCOMPtr<nsIAtom> attrAtom(do_GetAtom(aAttribute));
@@ -1244,17 +1244,17 @@ XULDocument::GetElementsByAttribute(cons
 NS_IMETHODIMP
 XULDocument::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
                                       const nsAString& aAttribute,
                                       const nsAString& aValue,
                                       nsIDOMNodeList** aReturn)
 {
     ErrorResult rv;
     *aReturn = GetElementsByAttributeNS(aNamespaceURI, aAttribute,
-                                        aValue, rv).get();
+                                        aValue, rv).take();
     return rv.ErrorCode();
 }
 
 already_AddRefed<nsINodeList>
 XULDocument::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
                                       const nsAString& aAttribute,
                                       const nsAString& aValue,
                                       ErrorResult& aRv)
@@ -4773,17 +4773,17 @@ XULDocument::GetDocumentLWTheme()
     return mDocLWTheme;
 }
 
 NS_IMETHODIMP
 XULDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
 {
     ErrorResult rv;
     nsCOMPtr<Element> el = do_QueryInterface(aElement);
-    *aResult = GetBoxObjectFor(el, rv).get();
+    *aResult = GetBoxObjectFor(el, rv).take();
     return rv.ErrorCode();
 }
 
 JSObject*
 XULDocument::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
 {
   return XULDocumentBinding::Wrap(aCx, aScope, this);
 }
--- a/content/xul/document/src/nsXULPrototypeDocument.cpp
+++ b/content/xul/document/src/nsXULPrototypeDocument.cpp
@@ -224,41 +224,45 @@ nsXULPrototypeDocument::NewXULPDGlobalOb
 // nsISerializable methods
 //
 
 NS_IMETHODIMP
 nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
 {
     nsresult rv;
 
-    rv = aStream->ReadObject(true, getter_AddRefs(mURI));
+    nsCOMPtr<nsISupports> supports;
+    rv = aStream->ReadObject(true, getter_AddRefs(supports));
+    mURI = do_QueryInterface(supports);
 
     uint32_t count, i;
     nsCOMPtr<nsIURI> styleOverlayURI;
 
     nsresult tmp = aStream->Read32(&count);
     if (NS_FAILED(tmp)) {
       return tmp;
     }
     if (NS_FAILED(rv)) {
       return rv;
     }
 
     for (i = 0; i < count; ++i) {
-        tmp = aStream->ReadObject(true, getter_AddRefs(styleOverlayURI));
+        tmp = aStream->ReadObject(true, getter_AddRefs(supports));
         if (NS_FAILED(tmp)) {
           rv = tmp;
         }
+        styleOverlayURI = do_QueryInterface(supports);
         mStyleSheetReferences.AppendObject(styleOverlayURI);
     }
 
 
     // nsIPrincipal mNodeInfoManager->mPrincipal
     nsCOMPtr<nsIPrincipal> principal;
-    tmp = aStream->ReadObject(true, getter_AddRefs(principal));
+    tmp = aStream->ReadObject(true, getter_AddRefs(supports));
+    principal = do_QueryInterface(supports);
     if (NS_FAILED(tmp)) {
       rv = tmp;
     }
     // Better safe than sorry....
     mNodeInfoManager->SetDocumentPrincipal(principal);
 
 
     // nsIScriptGlobalObject mGlobalObject
--- a/content/xul/templates/src/nsXULTemplateBuilder.cpp
+++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp
@@ -2113,17 +2113,17 @@ nsXULTemplateBuilder::DetermineRDFQueryR
 
         if (!uri.IsEmpty())
             mRefVariable = do_GetAtom(uri);
 
         nsAutoString tag;
         content->GetAttr(kNameSpaceID_None, nsGkAtoms::tag, tag);
 
         if (!tag.IsEmpty())
-            *aTag = NS_NewAtom(tag).get();
+            *aTag = NS_NewAtom(tag).take();
     }
 }
 
 nsresult
 nsXULTemplateBuilder::CompileSimpleQuery(nsIContent* aRuleElement,
                                          nsTemplateQuerySet* aQuerySet,
                                          bool* aCanUseTemplate)
 {
--- a/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp
+++ b/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp
@@ -311,20 +311,22 @@ nsXULTemplateQueryProcessorXML::Generate
         return NS_ERROR_INVALID_ARG;
 
     mGenerationStarted = true;
 
     nsCOMPtr<nsXMLQuery> xmlquery = do_QueryInterface(aQuery);
     if (!xmlquery)
         return NS_ERROR_INVALID_ARG;
 
+    nsCOMPtr<nsISupports> supports;
     nsCOMPtr<nsIDOMNode> context;
     if (aRef)
       aRef->GetBindingObjectFor(xmlquery->GetMemberVariable(),
-                                getter_AddRefs(context));
+                                getter_AddRefs(supports));
+    context = do_QueryInterface(supports);
     if (!context)
         context = mRoot;
 
     nsIDOMXPathExpression* expr = xmlquery->GetResultsExpression();
     if (!expr)
         return NS_ERROR_FAILURE;
 
     nsCOMPtr<nsISupports> exprsupportsresults;
--- a/docshell/base/nsDocShellEnumerator.cpp
+++ b/docshell/base/nsDocShellEnumerator.cpp
@@ -121,17 +121,18 @@ nsresult nsDocShellEnumerator::BuildDocS
 
 nsresult nsDocShellForwardsEnumerator::BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray)
 {
   nsresult rv;
 
   // add this item to the array
   if (mDocShellType == nsIDocShellTreeItem::typeAll ||
       inItem->ItemType() == mDocShellType) {
-    if (!inItemArray.AppendElement(do_GetWeakReference(inItem)))
+    nsWeakPtr weakItem = do_GetWeakReference(inItem);
+    if (!inItemArray.AppendElement(weakItem))
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
   int32_t   numChildren;
   rv = inItem->GetChildCount(&numChildren);
   if (NS_FAILED(rv)) return rv;
   
   for (int32_t i = 0; i < numChildren; ++i)
@@ -164,14 +165,15 @@ nsresult nsDocShellBackwardsEnumerator::
       
     rv = BuildArrayRecursive(curChild, inItemArray);
     if (NS_FAILED(rv)) return rv;
   }
 
   // add this item to the array
   if (mDocShellType == nsIDocShellTreeItem::typeAll ||
       inItem->ItemType() == mDocShellType) {
-    if (!inItemArray.AppendElement(do_GetWeakReference(inItem)))
+    nsWeakPtr weakItem = do_GetWeakReference(inItem);
+    if (!inItemArray.AppendElement(weakItem))
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return NS_OK;
 }
--- a/dom/apps/src/AppsUtils.jsm
+++ b/dom/apps/src/AppsUtils.jsm
@@ -203,17 +203,17 @@ this.AppsUtils = {
     // so we can't use the 'removable' property for isCoreApp
     // Instead, we check if the app is installed under /system/b2g
     let isCoreApp = false;
 
 #ifdef MOZ_WIDGET_GONK
     isCoreApp = app.basePath == this.getCoreAppsBasePath();
 #endif
     debug(app.basePath + " isCoreApp: " + isCoreApp);
-    return { "path":  WebappOSUtils.getInstallPath(app),
+    return { "path": WebappOSUtils.getPackagePath(app),
              "isCoreApp": isCoreApp };
   },
 
   /**
     * Remove potential HTML tags from displayable fields in the manifest.
     * We check name, description, developer name, and permission description
     */
   sanitizeManifest: function(aManifest) {
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -72,16 +72,18 @@ function supportSystemMessages() {
   return Services.prefs.getBoolPref("dom.sysmsg.enabled");
 }
 
 // Minimum delay between two progress events while downloading, in ms.
 const MIN_PROGRESS_EVENT_DELAY = 1500;
 
 const WEBAPP_RUNTIME = Services.appinfo.ID == "webapprt@mozilla.org";
 
+const chromeWindowType = WEBAPP_RUNTIME ? "webapprt:webapp" : "navigator:browser";
+
 XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
   Cu.import("resource://gre/modules/NetUtil.jsm");
   return NetUtil;
 });
 
 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
                                    "@mozilla.org/parentprocessmessagemanager;1",
                                    "nsIMessageBroadcaster");
@@ -128,16 +130,17 @@ XPCOMUtils.defineLazyGetter(this, "updat
 const STORE_ID_PENDING_PREFIX = "#unknownID#";
 
 this.DOMApplicationRegistry = {
   // Path to the webapps.json file where we store the registry data.
   appsFile: null,
   webapps: { },
   children: [ ],
   allAppsLaunchable: false,
+  _updateHandlers: [ ],
 
   init: function() {
     this.messages = ["Webapps:Install", "Webapps:Uninstall",
                      "Webapps:GetSelf", "Webapps:CheckInstalled",
                      "Webapps:GetInstalled", "Webapps:GetNotInstalled",
                      "Webapps:Launch", "Webapps:GetAll",
                      "Webapps:InstallPackage",
                      "Webapps:GetList", "Webapps:RegisterForMessages",
@@ -1191,16 +1194,33 @@ this.DOMApplicationRegistry = {
     if (!(aMsgName in this.children)) {
       return;
     }
     this.children[aMsgName].forEach(function(mmRef) {
       mmRef.mm.sendAsyncMessage(aMsgName, aContent);
     });
   },
 
+  registerUpdateHandler: function(aHandler) {
+    this._updateHandlers.push(aHandler);
+  },
+
+  unregisterUpdateHandler: function(aHandler) {
+    let index = this._updateHandlers.indexOf(aHandler);
+    if (index != -1) {
+      this._updateHandlers.splice(index, 1);
+    }
+  },
+
+  notifyUpdateHandlers: function(aApp, aManifest, aZipPath) {
+    for (let updateHandler of this._updateHandlers) {
+      updateHandler(aApp, aManifest, aZipPath);
+    }
+  },
+
   _getAppDir: function(aId) {
     return FileUtils.getDir(DIRECTORY_NAME, ["webapps", aId], true, true);
   },
 
   _writeFile: function(aPath, aData) {
     debug("Saving " + aPath);
 
     return OS.File.writeAtomic(aPath,
@@ -1482,16 +1502,23 @@ this.DOMApplicationRegistry = {
           delete app.staged;
         }
 
         delete app.retryingDownload;
 
         this._saveApps().then(() => {
           // Update the handlers and permissions for this app.
           this.updateAppHandlers(aOldManifest, aData, app);
+
+          this._loadJSONAsync(staged.path).then((aUpdateManifest) => {
+            let appObject = AppsUtils.cloneAppObject(app);
+            appObject.updateManifest = aUpdateManifest;
+            this.notifyUpdateHandlers(appObject, aData, appFile.path);
+          });
+
           if (supportUseCurrentProfile()) {
             PermissionsInstaller.installPermissions(
               { manifest: aData,
                 origin: app.origin,
                 manifestURL: app.manifestURL },
               true);
           }
           this.updateDataStore(this.webapps[id].localId, app.origin,
@@ -1892,16 +1919,18 @@ this.DOMApplicationRegistry = {
     }
 
     aApp.manifest = aNewManifest || aOldManifest;
 
     let manifest;
     if (aNewManifest) {
       this.updateAppHandlers(aOldManifest, aNewManifest, aApp);
 
+      this.notifyUpdateHandlers(AppsUtils.cloneAppObject(aApp), aNewManifest);
+
       // Store the new manifest.
       let dir = this._getAppDir(aId).path;
       let manFile = OS.Path.join(dir, "manifest.webapp");
       this._writeFile(manFile, JSON.stringify(aNewManifest));
       manifest = new ManifestHelper(aNewManifest, aApp.origin);
 
       if (supportUseCurrentProfile()) {
         // Update the permissions for this app.
@@ -2664,17 +2693,17 @@ onInstallSuccessAck: function onInstallS
       aOnSuccess,
       this._revertDownloadPackage.bind(this, id, oldApp, aNewApp, aIsUpdate)
     );
   },
 
   _ensureSufficientStorage: function(aNewApp) {
     let deferred = Promise.defer();
 
-    let navigator = Services.wm.getMostRecentWindow("navigator:browser")
+    let navigator = Services.wm.getMostRecentWindow(chromeWindowType)
                             .navigator;
     let deviceStorage = null;
 
     if (navigator.getDeviceStorage) {
       deviceStorage = navigator.getDeviceStorage("apps");
     }
 
     if (deviceStorage) {
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -3955,17 +3955,17 @@ NS_IMPL_RELEASE(nsEventListenerThisTrans
 NS_IMETHODIMP
 nsEventListenerThisTranslator::TranslateThis(nsISupports *aInitialThis,
                                              nsISupports **_retval)
 {
   nsCOMPtr<nsIDOMEvent> event(do_QueryInterface(aInitialThis));
   NS_ENSURE_TRUE(event, NS_ERROR_UNEXPECTED);
 
   nsCOMPtr<EventTarget> target = event->InternalDOMEvent()->GetCurrentTarget();
-  *_retval = target.forget().get();
+  target.forget(_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMConstructorSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
                               JSObject *aGlobalObj, JSObject **parentObj)
 {
   JS::Rooted<JSObject*> globalObj(cx, aGlobalObj);
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -43,16 +43,17 @@
 #include "js/OldDebugAPI.h"     // for JS_ClearWatchPointsForObject
 #include "jswrapper.h"
 #include "nsReadableUtils.h"
 #include "nsDOMClassInfo.h"
 #include "nsJSEnvironment.h"
 #include "ScriptSettings.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Likely.h"
+#include "mozilla/unused.h"
 
 // Other Classes
 #include "nsEventListenerManager.h"
 #include "mozilla/dom/BarProps.h"
 #include "nsContentCID.h"
 #include "nsLayoutStatics.h"
 #include "nsCCUncollectableMarker.h"
 #include "mozilla/dom/workers/Workers.h"
@@ -3937,17 +3938,17 @@ nsGlobalWindow::GetContentInternal(Error
   domWindow = do_GetInterface(primaryContent);
   return domWindow.forget();
 }
 
 NS_IMETHODIMP
 nsGlobalWindow::GetContent(nsIDOMWindow** aContent)
 {
   ErrorResult rv;
-  *aContent = GetContentInternal(rv).get();
+  *aContent = GetContentInternal(rv).take();
 
   return rv.ErrorCode();
 }
 
 NS_IMETHODIMP
 nsGlobalWindow::GetScriptableContent(JSContext* aCx, JS::MutableHandle<JS::Value> aVal)
 {
   ErrorResult rv;
@@ -11662,17 +11663,17 @@ nsGlobalWindow::SetTimeoutOrInterval(nsI
     nsRefPtr<nsTimeout> copy = timeout;
 
     rv = timeout->InitTimer(TimerCallback, realInterval);
     if (NS_FAILED(rv)) {
       return rv;
     }
 
     // The timeout is now also held in the timer's closure.
-    copy.forget();
+    unused << copy.forget();
   } else {
     // If we are frozen, however, then we instead simply set
     // timeout->mTimeRemaining to be the "time remaining" in the timeout (i.e.,
     // the interval itself). We don't create a timer for it, since that will
     // happen when we are thawed and the timeout will then get a timer and run
     // to completion.
 
     timeout->mTimeRemaining = delta;
--- a/dom/base/nsLocation.cpp
+++ b/dom/base/nsLocation.cpp
@@ -891,17 +891,17 @@ nsLocation::GetSourceBaseURL(JSContext* 
   if (!sgo && GetDocShell()) {
     sgo = do_GetInterface(GetDocShell());
   }
   NS_ENSURE_TRUE(sgo, NS_OK);
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(sgo);
   NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED);
   nsIDocument* doc = window->GetDoc();
   NS_ENSURE_TRUE(doc, NS_OK);
-  *sourceURL = doc->GetBaseURI().get();
+  *sourceURL = doc->GetBaseURI().take();
   return NS_OK;
 }
 
 bool
 nsLocation::CallerSubsumes()
 {
   // Get the principal associated with the location object.
   nsCOMPtr<nsIDOMWindow> outer = do_QueryReferent(mOuter);
--- a/dom/camera/GonkCameraControl.cpp
+++ b/dom/camera/GonkCameraControl.cpp
@@ -1062,17 +1062,18 @@ nsresult