Backed out 2 changesets (bug 1635094) for build bustages on nsMacShellService.cpp. CLOSED TREE
authorCosmin Sabou <csabou@mozilla.com>
Mon, 04 May 2020 20:04:06 +0300
changeset 527899 34d71b4a00863e7615463592662dfe362c4a993e
parent 527898 b26756cf1d8f763202b82e0cde3a64ade5ddecad
child 527900 9bdbb81bd05b3744614fa7bd4617e8eee007c551
push id114855
push usercsabou@mozilla.com
push dateMon, 04 May 2020 17:05:17 +0000
treeherderautoland@34d71b4a0086 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1635094
milestone78.0a1
backs out0a2b0c6ea19a775b664d06ab159ac447c8b0ff1f
ead4f26f76ee2ef0783ddda5362c37d6f9d6b7eb
first release with
nightly linux32
34d71b4a0086 / 78.0a1 / 20200504205324 / files
nightly linux64
34d71b4a0086 / 78.0a1 / 20200504205324 / files
nightly mac
34d71b4a0086 / 78.0a1 / 20200504205324 / files
nightly win32
34d71b4a0086 / 78.0a1 / 20200504205324 / files
nightly win64
34d71b4a0086 / 78.0a1 / 20200504205324 / 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
Backed out 2 changesets (bug 1635094) for build bustages on nsMacShellService.cpp. CLOSED TREE Backed out changeset 0a2b0c6ea19a (bug 1635094) Backed out changeset ead4f26f76ee (bug 1635094)
browser/actors/ClickHandlerChild.jsm
browser/actors/ContextMenuChild.jsm
browser/base/content/browser.js
browser/components/shell/nsMacShellService.cpp
docshell/base/nsDocShell.cpp
dom/base/Element.cpp
dom/base/Element.h
dom/base/EventSource.cpp
dom/base/Navigator.cpp
dom/base/nsContentSink.cpp
dom/base/nsFrameLoader.cpp
dom/base/nsImageLoadingContent.cpp
dom/base/nsObjectLoadingContent.cpp
dom/clients/manager/ClientNavigateOpChild.cpp
dom/html/HTMLLinkElement.cpp
dom/html/HTMLMediaElement.cpp
dom/html/HTMLStyleElement.cpp
dom/interfaces/security/nsIReferrerInfo.idl
dom/ipc/ContentChild.cpp
dom/security/ReferrerInfo.cpp
dom/security/ReferrerInfo.h
dom/svg/SVGStyleElement.cpp
dom/svg/SVGUseElement.cpp
dom/xml/XMLStylesheetProcessingInstruction.cpp
layout/xul/nsImageBoxFrame.cpp
layout/xul/tree/nsTreeBodyFrame.cpp
toolkit/components/windowwatcher/nsWindowWatcher.cpp
xpcom/idl-parser/xpidl/xpidl.py
--- a/browser/actors/ClickHandlerChild.jsm
+++ b/browser/actors/ClickHandlerChild.jsm
@@ -70,17 +70,17 @@ class ClickHandlerChild extends JSWindow
     if (csp) {
       csp = E10SUtils.serializeCSP(csp);
     }
 
     let referrerInfo = Cc["@mozilla.org/referrer-info;1"].createInstance(
       Ci.nsIReferrerInfo
     );
     if (node) {
-      referrerInfo.initWithElement(node);
+      referrerInfo.initWithNode(node);
     } else {
       referrerInfo.initWithDocument(ownerDoc);
     }
     referrerInfo = E10SUtils.serializeReferrerInfo(referrerInfo);
     let frameOuterWindowID = WebNavigationFrames.getFrameId(
       ownerDoc.defaultView
     );
 
--- a/browser/actors/ContextMenuChild.jsm
+++ b/browser/actors/ContextMenuChild.jsm
@@ -624,27 +624,27 @@ class ContextMenuChild extends JSWindowA
     let spellInfo = null;
     let editFlags = null;
     let principal = null;
     let customMenuItems = null;
 
     let referrerInfo = Cc["@mozilla.org/referrer-info;1"].createInstance(
       Ci.nsIReferrerInfo
     );
-    referrerInfo.initWithElement(aEvent.composedTarget);
+    referrerInfo.initWithNode(aEvent.composedTarget);
     referrerInfo = E10SUtils.serializeReferrerInfo(referrerInfo);
 
     // In the case "onLink" we may have to send link referrerInfo to use in
     // _openLinkInParameters
     let linkReferrerInfo = null;
     if (context.onLink) {
       linkReferrerInfo = Cc["@mozilla.org/referrer-info;1"].createInstance(
         Ci.nsIReferrerInfo
       );
-      linkReferrerInfo.initWithElement(context.link);
+      linkReferrerInfo.initWithNode(context.link);
     }
 
     let target = context.target;
     if (target) {
       this._cleanContext();
     }
 
     editFlags = SpellCheckHelper.isEditable(
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6849,17 +6849,17 @@ function handleLinkClick(event, href, li
     return false;
   }
 
   var doc = event.target.ownerDocument;
   let referrerInfo = Cc["@mozilla.org/referrer-info;1"].createInstance(
     Ci.nsIReferrerInfo
   );
   if (linkNode) {
-    referrerInfo.initWithElement(linkNode);
+    referrerInfo.initWithNode(linkNode);
   } else {
     referrerInfo.initWithDocument(doc);
   }
 
   if (where == "save") {
     saveURL(
       href,
       linkNode ? gatherTextUnder(linkNode) : "",
--- a/browser/components/shell/nsMacShellService.cpp
+++ b/browser/components/shell/nsMacShellService.cpp
@@ -147,17 +147,19 @@ nsMacShellService::SetDesktopBackground(
 
   nsCOMPtr<nsILoadContext> loadContext;
   nsCOMPtr<nsISupports> container = aElement->OwnerDoc()->GetContainer();
   nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
   if (docShell) {
     loadContext = do_QueryInterface(docShell);
   }
 
-  auto referrerInfo = MakeRefPtr<mozilla::dom::ReferrerInfo>(*aElement);
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new mozilla::dom::ReferrerInfo();
+  referrerInfo->InitWithNode(aElement);
+
   return wbp->SaveURI(imageURI, aElement->NodePrincipal(), 0, referrerInfo,
                       nullptr, nullptr, mBackgroundFile,
                       nsIContentPolicy::TYPE_IMAGE, loadContext);
 }
 
 NS_IMETHODIMP
 nsMacShellService::OnProgressChange(nsIWebProgress* aWebProgress,
                                     nsIRequest* aRequest,
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -11991,16 +11991,17 @@ nsresult nsDocShell::OnLinkClickSync(
   }
 
   // Get the owner document of the link that was clicked, this will be
   // the document that the link is in, or the last document that the
   // link was in. From that document, we'll get the URI to use as the
   // referrer, since the current URI in this docshell may be a
   // new document that we're in the process of loading.
   RefPtr<Document> referrerDoc = aContent->OwnerDoc();
+  NS_ENSURE_TRUE(referrerDoc, NS_ERROR_UNEXPECTED);
 
   // Now check that the referrerDoc's inner window is the current inner
   // window for mScriptGlobal.  If it's not, then we don't want to
   // follow this link.
   nsPIDOMWindowInner* referrerInner = referrerDoc->GetInnerWindow();
   NS_ENSURE_TRUE(referrerInner, NS_ERROR_UNEXPECTED);
   if (!mScriptGlobal ||
       mScriptGlobal->GetCurrentInnerWindow() != referrerInner) {
@@ -12023,19 +12024,22 @@ nsresult nsDocShell::OnLinkClickSync(
   }
 
   // Link click (or form submission) can be triggered inside an onload
   // handler, and we don't want to add history entry in this case.
   bool inOnLoadHandler = false;
   GetIsExecutingOnLoadHandler(&inOnLoadHandler);
   uint32_t loadType = inOnLoadHandler ? LOAD_NORMAL_REPLACE : LOAD_LINK;
 
-  nsCOMPtr<nsIReferrerInfo> referrerInfo =
-      isElementAnchorOrArea ? new ReferrerInfo(*aContent->AsElement())
-                            : new ReferrerInfo(*referrerDoc);
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  if (isElementAnchorOrArea) {
+    referrerInfo->InitWithNode(aContent);
+  } else {
+    referrerInfo->InitWithDocument(referrerDoc);
+  }
 
   RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(aURI);
   loadState->SetReferrerInfo(referrerInfo);
   loadState->SetTriggeringPrincipal(triggeringPrincipal);
   loadState->SetPrincipalToInherit(aContent->NodePrincipal());
   loadState->SetCsp(csp);
   loadState->SetLoadFlags(flags);
   loadState->SetTarget(aTargetSpec);
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -3693,25 +3693,25 @@ void Element::GetImplementedPseudoElemen
   MOZ_ASSERT(pseudo.Length() > 2 && pseudo[0] == ':' && pseudo[1] != ':');
 
   aPseudo.Truncate();
   aPseudo.SetCapacity(pseudo.Length() + 1);
   aPseudo.Append(':');
   aPseudo.Append(pseudo);
 }
 
-ReferrerPolicy Element::GetReferrerPolicyAsEnum() const {
+ReferrerPolicy Element::GetReferrerPolicyAsEnum() {
   if (IsHTMLElement()) {
-    return ReferrerPolicyFromAttr(GetParsedAttr(nsGkAtoms::referrerpolicy));
+    const nsAttrValue* referrerValue = GetParsedAttr(nsGkAtoms::referrerpolicy);
+    return ReferrerPolicyFromAttr(referrerValue);
   }
   return ReferrerPolicy::_empty;
 }
 
-ReferrerPolicy Element::ReferrerPolicyFromAttr(
-    const nsAttrValue* aValue) const {
+ReferrerPolicy Element::ReferrerPolicyFromAttr(const nsAttrValue* aValue) {
   if (aValue && aValue->Type() == nsAttrValue::eEnum) {
     return ReferrerPolicy(aValue->GetEnumValue());
   }
   return ReferrerPolicy::_empty;
 }
 
 already_AddRefed<nsDOMStringMap> Element::Dataset() {
   nsDOMSlots* slots = DOMSlots();
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -1611,18 +1611,18 @@ class Element : public FragmentOrElement
    * @note The font size inflation ratio that is returned is actually the
    *       font size inflation data for the element's _primary frame_, not the
    *       element itself, but for most purposes, this should be sufficient.
    */
   float FontSizeInflation();
 
   void GetImplementedPseudoElement(nsAString&) const;
 
-  ReferrerPolicy GetReferrerPolicyAsEnum() const;
-  ReferrerPolicy ReferrerPolicyFromAttr(const nsAttrValue* aValue) const;
+  ReferrerPolicy GetReferrerPolicyAsEnum();
+  ReferrerPolicy ReferrerPolicyFromAttr(const nsAttrValue* aValue);
 
   /*
    * Helpers for .dataset.  This is implemented on Element, though only some
    * sorts of elements expose it to JS as a .dataset property
    */
   // Getter, to be called from bindings.
   already_AddRefed<nsDOMStringMap> Dataset();
   // Callback for destructor of dataset to ensure to null out our weak pointer
--- a/dom/base/EventSource.cpp
+++ b/dom/base/EventSource.cpp
@@ -962,19 +962,20 @@ void EventSourceImpl::SetupHttpChannel()
   }
 #endif
   Unused << rv;
 }
 
 nsresult EventSourceImpl::SetupReferrerInfo() {
   AssertIsOnMainThread();
   MOZ_ASSERT(!IsShutDown());
-
-  if (nsCOMPtr<Document> doc = mEventSource->GetDocumentIfCurrent()) {
-    auto referrerInfo = MakeRefPtr<ReferrerInfo>(*doc);
+  nsCOMPtr<Document> doc = mEventSource->GetDocumentIfCurrent();
+  if (doc) {
+    nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+    referrerInfo->InitWithDocument(doc);
     nsresult rv = mHttpChannel->SetReferrerInfoWithoutClone(referrerInfo);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 nsresult EventSourceImpl::InitChannelAndRequestEventSource() {
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1174,17 +1174,18 @@ bool Navigator::SendBeaconInternal(const
 
   nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
   if (!httpChannel) {
     // Beacon spec only supports HTTP requests at this time
     aRv.Throw(NS_ERROR_DOM_BAD_URI);
     return false;
   }
 
-  auto referrerInfo = MakeRefPtr<ReferrerInfo>(*doc);
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithDocument(doc);
   rv = httpChannel->SetReferrerInfoWithoutClone(referrerInfo);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
   nsCOMPtr<nsIInputStream> in;
   nsAutoCString contentTypeWithCharset;
   nsAutoCString charset;
   uint64_t length = 0;
 
--- a/dom/base/nsContentSink.cpp
+++ b/dom/base/nsContentSink.cpp
@@ -781,18 +781,20 @@ void nsContentSink::PrefetchPreloadHref(
         nsAutoString notUsed;
         nsContentUtils::SplitMimeType(aType, mimeType, notUsed);
         if (!HTMLLinkElement::CheckPreloadAttrs(asAttr, mimeType, aMedia,
                                                 mDocument)) {
           policyType = nsIContentPolicy::TYPE_INVALID;
         }
       }
 
-      auto referrerInfo = MakeRefPtr<ReferrerInfo>(*mDocument);
-      referrerInfo = referrerInfo->CloneWithNewOriginalReferrer(mDocumentURI);
+      nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+      referrerInfo->InitWithDocument(mDocument);
+      referrerInfo = static_cast<ReferrerInfo*>(referrerInfo.get())
+                         ->CloneWithNewOriginalReferrer(mDocumentURI);
 
       if (preload) {
         prefetchService->PreloadURI(uri, referrerInfo, mDocument, policyType);
       } else {
         prefetchService->PrefetchURI(
             uri, referrerInfo, mDocument,
             aLinkTypes & nsStyleLinkElement::ePREFETCH);
       }
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -653,17 +653,18 @@ nsresult nsFrameLoader::ReallyStartLoadi
       mOwnerContent->IsHTMLElement(nsGkAtoms::iframe) &&
       mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::srcdoc, srcdoc);
 
   if (isSrcdoc) {
     loadState->SetSrcdocData(srcdoc);
     loadState->SetBaseURI(mOwnerContent->GetBaseURI());
   }
 
-  auto referrerInfo = MakeRefPtr<ReferrerInfo>(*mOwnerContent);
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithNode(mOwnerContent);
   loadState->SetReferrerInfo(referrerInfo);
 
   // Default flags:
   int32_t flags = nsIWebNavigation::LOAD_FLAGS_NONE;
 
   // Flags for browser frame:
   if (OwnerIsMozBrowserFrame()) {
     flags = nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -1140,39 +1140,48 @@ nsresult nsImageLoadingContent::LoadImag
 
   // From this point on, our image state could change. Watch it.
   AutoStateChanger changer(this, aNotify);
 
   // Sanity check.
   //
   // We use the principal of aDocument to avoid having to QI |this| an extra
   // time. It should always be the same as the principal of this node.
-  Element* element = AsContent()->AsElement();
-  MOZ_ASSERT(element->NodePrincipal() == aDocument->NodePrincipal(),
+#ifdef DEBUG
+  nsIContent* thisContent = AsContent();
+  MOZ_ASSERT(thisContent->NodePrincipal() == aDocument->NodePrincipal(),
              "Principal mismatch?");
+#endif
 
   nsLoadFlags loadFlags =
       aLoadFlags | nsContentUtils::CORSModeToLoadImageFlags(GetCORSMode());
 
   RefPtr<imgRequestProxy>& req = PrepareNextRequest(aImageLoadType);
+  nsCOMPtr<nsIContent> content =
+      do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
+
   nsCOMPtr<nsIPrincipal> triggeringPrincipal;
   bool result = nsContentUtils::QueryTriggeringPrincipal(
-      element, aTriggeringPrincipal, getter_AddRefs(triggeringPrincipal));
+      content, aTriggeringPrincipal, getter_AddRefs(triggeringPrincipal));
 
   // If result is true, which means this node has specified
   // 'triggeringprincipal' attribute on it, so we use favicon as the policy
   // type.
   nsContentPolicyType policyType =
       result ? nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON
              : PolicyTypeForLoad(aImageLoadType);
 
-  auto referrerInfo = MakeRefPtr<ReferrerInfo>(*element);
+  nsCOMPtr<nsINode> thisNode =
+      do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithNode(thisNode);
+
   nsresult rv = nsContentUtils::LoadImage(
-      aNewURI, element, aDocument, triggeringPrincipal, 0, referrerInfo, this,
-      loadFlags, element->LocalName(), getter_AddRefs(req), policyType,
+      aNewURI, thisNode, aDocument, triggeringPrincipal, 0, referrerInfo, this,
+      loadFlags, content->LocalName(), getter_AddRefs(req), policyType,
       mUseUrgentStartForChannel);
 
   // Reset the flag to avoid loading from XPCOM or somewhere again else without
   // initiated by user interaction.
   mUseUrgentStartForChannel = false;
 
   // Tell the document to forget about the image preload, if any, for
   // this URI, now that we might have another imgRequestProxy for it.
@@ -1318,16 +1327,17 @@ void nsImageLoadingContent::UpdateImageS
     if (NS_FAILED(rv) || (currentLoadStatus & imgIRequest::STATUS_ERROR)) {
       mBroken = true;
       RejectDecodePromises(NS_ERROR_DOM_IMAGE_BROKEN);
     } else if (!(currentLoadStatus & imgIRequest::STATUS_SIZE_AVAILABLE)) {
       mLoading = true;
     }
   }
 
+  NS_ASSERTION(thisContent->IsElement(), "Not an element?");
   thisContent->AsElement()->UpdateState(aNotify);
 }
 
 void nsImageLoadingContent::CancelImageRequests(bool aNotify) {
   RejectDecodePromises(NS_ERROR_DOM_IMAGE_INVALID_REQUEST);
   AutoStateChanger changer(this, aNotify);
   ClearPendingRequest(NS_BINDING_ABORTED, Some(OnNonvisible::DiscardImages));
   ClearCurrentRequest(NS_BINDING_ABORTED, Some(OnNonvisible::DiscardImages));
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -2316,17 +2316,18 @@ nsresult nsObjectLoadingContent::OpenCha
     cspToInherit->InitFromOther(static_cast<nsCSPContext*>(csp.get()));
     nsCOMPtr<nsILoadInfo> loadinfo = chan->LoadInfo();
     static_cast<LoadInfo*>(loadinfo.get())->SetCSPToInherit(cspToInherit);
   }
 
   // Referrer
   nsCOMPtr<nsIHttpChannel> httpChan(do_QueryInterface(chan));
   if (httpChan) {
-    auto referrerInfo = MakeRefPtr<ReferrerInfo>(*doc);
+    nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+    referrerInfo->InitWithDocument(doc);
 
     rv = httpChan->SetReferrerInfoWithoutClone(referrerInfo);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
 
     // Set the initiator type
     nsCOMPtr<nsITimedChannel> timedChannel(do_QueryInterface(httpChan));
     if (timedChannel) {
       timedChannel->SetInitiatorType(thisContent->LocalName());
--- a/dom/clients/manager/ClientNavigateOpChild.cpp
+++ b/dom/clients/manager/ClientNavigateOpChild.cpp
@@ -242,21 +242,22 @@ RefPtr<ClientOpPromise> ClientNavigateOp
   if (!docShell || !webProgress) {
     CopyableErrorResult result;
     result.ThrowInvalidStateError(
         "Document's browsing context has been discarded");
     return ClientOpPromise::CreateAndReject(result, __func__);
   }
 
   RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(url);
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithDocument(doc);
   loadState->SetTriggeringPrincipal(principal);
 
   loadState->SetCsp(doc->GetCsp());
 
-  auto referrerInfo = MakeRefPtr<ReferrerInfo>(*doc);
   loadState->SetReferrerInfo(referrerInfo);
   loadState->SetLoadType(LOAD_STOP_CONTENT);
   loadState->SetSourceBrowsingContext(docShell->GetBrowsingContext());
   loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_NONE);
   loadState->SetFirstParty(true);
   loadState->SetHasValidUserGestureActivation(
       doc->HasValidTransientUserGestureActivation());
   rv = docShell->LoadURI(loadState, false);
--- a/dom/html/HTMLLinkElement.cpp
+++ b/dom/html/HTMLLinkElement.cpp
@@ -464,29 +464,31 @@ Maybe<nsStyleLinkElement::SheetInfo> HTM
     return Nothing();
   }
 
   nsAutoString integrity;
   GetAttr(kNameSpaceID_None, nsGkAtoms::integrity, integrity);
 
   nsCOMPtr<nsIURI> uri = Link::GetURI();
   nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithNode(this);
 
   nsAutoString nonce;
   nsString* cspNonce = static_cast<nsString*>(GetProperty(nsGkAtoms::nonce));
   if (cspNonce) {
     nonce = *cspNonce;
   }
 
   return Some(SheetInfo{
       *OwnerDoc(),
       this,
       uri.forget(),
       prin.forget(),
-      MakeAndAddRef<ReferrerInfo>(*this),
+      referrerInfo.forget(),
       GetCORSMode(),
       title,
       media,
       integrity,
       nonce,
       alternate ? HasAlternateRel::Yes : HasAlternateRel::No,
       IsInline::No,
       mExplicitlyEnabled ? IsExplicitlyEnabled::Yes : IsExplicitlyEnabled::No,
@@ -612,17 +614,18 @@ void HTMLLinkElement::
             return;
           }
 
           if (!CheckPreloadAttrs(asAttr, mimeType, media, OwnerDoc())) {
             policyType = nsIContentPolicy::TYPE_INVALID;
           }
         }
 
-        auto referrerInfo = MakeRefPtr<ReferrerInfo>(*this);
+        nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+        referrerInfo->InitWithNode(this);
         if (preload) {
           prefetchService->PreloadURI(uri, referrerInfo, this, policyType);
         } else {
           prefetchService->PrefetchURI(uri, referrerInfo, this,
                                        linkTypes & ePREFETCH);
         }
         return;
       }
@@ -696,17 +699,18 @@ void HTMLLinkElement::UpdatePreload(nsAt
   }
 
   if (aName == nsGkAtoms::crossorigin) {
     CORSMode corsMode = AttrValueToCORSMode(aValue);
     CORSMode oldCorsMode = AttrValueToCORSMode(aOldValue);
     if (corsMode != oldCorsMode) {
       prefetchService->CancelPrefetchPreloadURI(uri, this);
 
-      auto referrerInfo = MakeRefPtr<ReferrerInfo>(*this);
+      nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+      referrerInfo->InitWithNode(this);
       prefetchService->PreloadURI(uri, referrerInfo, this, policyType);
     }
     return;
   }
 
   nsContentPolicyType oldPolicyType;
 
   if (aName == nsGkAtoms::as) {
@@ -753,17 +757,18 @@ void HTMLLinkElement::UpdatePreload(nsAt
     prefetchService->CancelPrefetchPreloadURI(uri, this);
   }
 
   // Trigger a new preload if the policy type has changed.
   // Also trigger load if the new policy type is invalid, this will only
   // trigger an error event.
   if ((policyType != oldPolicyType) ||
       (policyType == nsIContentPolicy::TYPE_INVALID)) {
-    auto referrerInfo = MakeRefPtr<ReferrerInfo>(*this);
+    nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+    referrerInfo->InitWithNode(this);
     prefetchService->PreloadURI(uri, referrerInfo, this, policyType);
   }
 }
 
 void HTMLLinkElement::CancelPrefetchOrPreload() {
   nsCOMPtr<nsIPrefetchService> prefetchService(components::Prefetch::Service());
   if (prefetchService) {
     if (nsCOMPtr<nsIURI> uri = GetURI()) {
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -6663,21 +6663,19 @@ void HTMLMediaElement::SetRequestHeaders
   // which prevents us from estimating the video length (if explicit
   // Content-Duration and a length spec in the container are not present either)
   // and from seeking. So, disable the standard "Accept-Encoding: gzip,deflate"
   // that we usually send. See bug 614760.
   DebugOnly<nsresult> rv = aChannel->SetRequestHeader(
       NS_LITERAL_CSTRING("Accept-Encoding"), EmptyCString(), false);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
-  // Set the Referrer header
-  //
-  // FIXME: Shouldn't this use the Element constructor? Though I guess it
-  // doesn't matter as no HTMLMediaElement supports the referrerinfo attribute.
-  auto referrerInfo = MakeRefPtr<ReferrerInfo>(*OwnerDoc());
+  // Set the Referer header
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithDocument(OwnerDoc());
   rv = aChannel->SetReferrerInfoWithoutClone(referrerInfo);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void HTMLMediaElement::FireTimeUpdate(bool aPeriodic) {
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
 
   TimeStamp now = TimeStamp::Now();
--- a/dom/html/HTMLStyleElement.cpp
+++ b/dom/html/HTMLStyleElement.cpp
@@ -167,22 +167,25 @@ Maybe<nsStyleLinkElement::SheetInfo> HTM
   if (!IsCSSMimeTypeAttributeForStyleElement(*this)) {
     return Nothing();
   }
 
   nsAutoString title;
   nsAutoString media;
   GetTitleAndMediaForElement(*this, title, media);
 
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithNode(this);
+
   return Some(SheetInfo{
       *OwnerDoc(),
       this,
       nullptr,
       do_AddRef(mTriggeringPrincipal),
-      MakeAndAddRef<ReferrerInfo>(*this),
+      referrerInfo.forget(),
       CORS_NONE,
       title,
       media,
       /* integrity = */ EmptyString(),
       /* nsStyleUtil::CSPAllowsInlineStyle takes care of nonce checking for
          inline styles. Bug 1607011 */
       /* nonce = */ EmptyString(),
       HasAlternateRel::No,
--- a/dom/interfaces/security/nsIReferrerInfo.idl
+++ b/dom/interfaces/security/nsIReferrerInfo.idl
@@ -6,17 +6,17 @@
 #include "nsISerializable.idl"
 
 %{C++
 #include "mozilla/dom/ReferrerPolicyBinding.h"
 %}
 
 interface nsIURI;
 webidl Document;
-webidl Element;
+webidl Node;
 
 native ReferrerPolicy(mozilla::dom::ReferrerPolicy);
 native URIRef(already_AddRefed<nsIURI>);
 
 [scriptable, builtinclass, uuid(081cdc36-f2e2-4f94-87bf-78578f06f1eb)]
 interface nsIReferrerInfo : nsISerializable
 {
   /**
@@ -127,19 +127,20 @@ interface nsIReferrerInfo : nsISerializa
   void init(in nsIReferrerInfo_ReferrerPolicyIDL aReferrerPolicy,
            [optional] in boolean aSendReferrer,
            [optional] in nsIURI aOriginalReferrer);
 
   /**
    * Initialize with a given document.
    * @param aDocument the document to init referrerInfo object
    */
-  void initWithDocument([const] in Document aDocument);
+  void initWithDocument(in Document aDocument);
 
   /**
    * Initialize with a given node. It you are working with node which supports
    * referrerpolicy attribute: <a>, <img>, <area>, <script>, <iframe>, please
    * try to use this init instead of initWithDocument, because referrer policy
    * from rel and attribute has a higher priority.
    * @param aNode the element to init referrerInfo object
    */
-  void initWithElement([const] in Element aNode);
+  void initWithNode(in Node aNode);
+
 };
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -844,17 +844,18 @@ static nsresult GetCreateWindowParams(ns
 
   nsCOMPtr<nsIURI> baseURI = doc->GetDocBaseURI();
   if (!baseURI) {
     NS_ERROR("Document didn't return a base URI");
     return NS_ERROR_FAILURE;
   }
 
   if (!referrerInfo) {
-    referrerInfo = new ReferrerInfo(*doc);
+    referrerInfo = new ReferrerInfo();
+    referrerInfo->InitWithDocument(doc);
   }
 
   referrerInfo.swap(*aReferrerInfo);
 
   *aFullZoom = parent->FullZoom();
   return NS_OK;
 }
 
--- a/dom/security/ReferrerInfo.cpp
+++ b/dom/security/ReferrerInfo.cpp
@@ -1,15 +1,14 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/dom/ReferrerPolicyBinding.h"
 #include "nsIClassInfoImpl.h"
 #include "nsIEffectiveTLDService.h"
 #include "nsIHttpChannel.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIOService.h"
 #include "nsIURL.h"
 
@@ -783,25 +782,18 @@ nsIReferrerInfo::ReferrerPolicyIDL Refer
   return nsIReferrerInfo::EMPTY;
 }
 
 ReferrerInfo::ReferrerInfo()
     : mOriginalReferrer(nullptr),
       mPolicy(ReferrerPolicy::_empty),
       mSendReferrer(true),
       mInitialized(false),
-      mOverridePolicyByDefault(false) {}
-
-ReferrerInfo::ReferrerInfo(const Document& aDoc) : ReferrerInfo() {
-  InitWithDocument(&aDoc);
-}
-
-ReferrerInfo::ReferrerInfo(const Element& aElement) : ReferrerInfo() {
-  InitWithElement(&aElement);
-}
+      mOverridePolicyByDefault(false),
+      mComputedReferrer(Maybe<nsCString>()) {}
 
 ReferrerInfo::ReferrerInfo(nsIURI* aOriginalReferrer,
                            ReferrerPolicyEnum aPolicy, bool aSendReferrer,
                            const Maybe<nsCString>& aComputedReferrer)
     : mOriginalReferrer(aOriginalReferrer),
       mPolicy(aPolicy),
       mSendReferrer(aSendReferrer),
       mInitialized(true),
@@ -811,36 +803,36 @@ ReferrerInfo::ReferrerInfo(nsIURI* aOrig
 ReferrerInfo::ReferrerInfo(const ReferrerInfo& rhs)
     : mOriginalReferrer(rhs.mOriginalReferrer),
       mPolicy(rhs.mPolicy),
       mSendReferrer(rhs.mSendReferrer),
       mInitialized(rhs.mInitialized),
       mOverridePolicyByDefault(rhs.mOverridePolicyByDefault),
       mComputedReferrer(rhs.mComputedReferrer) {}
 
-already_AddRefed<ReferrerInfo> ReferrerInfo::Clone() const {
+already_AddRefed<nsIReferrerInfo> ReferrerInfo::Clone() const {
   RefPtr<ReferrerInfo> copy(new ReferrerInfo(*this));
   return copy.forget();
 }
 
-already_AddRefed<ReferrerInfo> ReferrerInfo::CloneWithNewPolicy(
+already_AddRefed<nsIReferrerInfo> ReferrerInfo::CloneWithNewPolicy(
     ReferrerPolicyEnum aPolicy) const {
   RefPtr<ReferrerInfo> copy(new ReferrerInfo(*this));
   copy->mPolicy = aPolicy;
   return copy.forget();
 }
 
-already_AddRefed<ReferrerInfo> ReferrerInfo::CloneWithNewSendReferrer(
+already_AddRefed<nsIReferrerInfo> ReferrerInfo::CloneWithNewSendReferrer(
     bool aSendReferrer) const {
   RefPtr<ReferrerInfo> copy(new ReferrerInfo(*this));
   copy->mSendReferrer = aSendReferrer;
   return copy.forget();
 }
 
-already_AddRefed<ReferrerInfo> ReferrerInfo::CloneWithNewOriginalReferrer(
+already_AddRefed<nsIReferrerInfo> ReferrerInfo::CloneWithNewOriginalReferrer(
     nsIURI* aOriginalReferrer) const {
   RefPtr<ReferrerInfo> copy(new ReferrerInfo(*this));
   copy->mOriginalReferrer = aOriginalReferrer;
   return copy.forget();
 }
 
 NS_IMETHODIMP
 ReferrerInfo::GetOriginalReferrer(nsIURI** aOriginalReferrer) {
@@ -955,82 +947,47 @@ ReferrerInfo::Init(nsIReferrerInfo::Refe
   mPolicy = ReferrerPolicyIDLToReferrerPolicy(aReferrerPolicy);
   mSendReferrer = aSendReferrer;
   mOriginalReferrer = aOriginalReferrer;
   mInitialized = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-ReferrerInfo::InitWithDocument(const Document* aDocument) {
+ReferrerInfo::InitWithDocument(Document* aDocument) {
   MOZ_ASSERT(!mInitialized);
   if (mInitialized) {
     return NS_ERROR_ALREADY_INITIALIZED;
   };
 
   mPolicy = aDocument->GetReferrerPolicy();
   mSendReferrer = true;
   mOriginalReferrer = aDocument->GetDocumentURIAsReferrer();
   mInitialized = true;
   return NS_OK;
 }
 
-/**
- * Check whether the given node has referrerpolicy attribute and parse
- * referrer policy from the attribute.
- * Currently, referrerpolicy attribute is supported in a, area, img, iframe,
- * script, or link element.
- */
-static ReferrerPolicy ReferrerPolicyFromAttribute(const Element& aElement) {
-  if (!aElement.IsAnyOfHTMLElements(nsGkAtoms::a, nsGkAtoms::area,
-                                    nsGkAtoms::script, nsGkAtoms::iframe,
-                                    nsGkAtoms::link, nsGkAtoms::img)) {
-    return ReferrerPolicy::_empty;
-  }
-  return aElement.GetReferrerPolicyAsEnum();
-}
-
-static bool HasRelNoReferrer(const Element& aElement) {
-  // rel=noreferrer is only support in <a> and <area>
-  if (!aElement.IsAnyOfHTMLElements(nsGkAtoms::a, nsGkAtoms::area)) {
-    return false;
-  }
-
-  nsAutoString rel;
-  aElement.GetAttr(nsGkAtoms::rel, rel);
-  nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> tok(rel);
-
-  while (tok.hasMoreTokens()) {
-    const nsAString& token = tok.nextToken();
-    if (token.LowerCaseEqualsLiteral("noreferrer")) {
-      return true;
-    }
-  }
-
-  return false;
-}
-
 NS_IMETHODIMP
-ReferrerInfo::InitWithElement(const Element* aElement) {
+ReferrerInfo::InitWithNode(nsINode* aNode) {
   MOZ_ASSERT(!mInitialized);
   if (mInitialized) {
     return NS_ERROR_ALREADY_INITIALIZED;
   };
 
   // Referrer policy from referrerpolicy attribute will have a higher priority
   // than referrer policy from <meta> tag and Referrer-Policy header.
-  mPolicy = ReferrerPolicyFromAttribute(*aElement);
+  GetReferrerPolicyFromAtribute(aNode, mPolicy);
   if (mPolicy == ReferrerPolicy::_empty) {
     // Fallback to use document's referrer poicy if we don't have referrer
     // policy from attribute.
-    mPolicy = aElement->OwnerDoc()->GetReferrerPolicy();
+    mPolicy = aNode->OwnerDoc()->GetReferrerPolicy();
   }
 
-  mSendReferrer = !HasRelNoReferrer(*aElement);
-  mOriginalReferrer = aElement->OwnerDoc()->GetDocumentURIAsReferrer();
+  mSendReferrer = !HasRelNoReferrer(aNode);
+  mOriginalReferrer = aNode->OwnerDoc()->GetDocumentURIAsReferrer();
 
   mInitialized = true;
   return NS_OK;
 }
 
 /* static */
 already_AddRefed<nsIReferrerInfo>
 ReferrerInfo::CreateFromOtherAndPolicyOverride(
@@ -1133,16 +1090,53 @@ already_AddRefed<nsIReferrerInfo> Referr
   MOZ_ASSERT(aDocument);
   nsCOMPtr<nsIReferrerInfo> referrerInfo;
 
   referrerInfo = new ReferrerInfo(aDocument->GetDocumentURI(),
                                   aDocument->GetReferrerPolicy());
   return referrerInfo.forget();
 }
 
+void ReferrerInfo::GetReferrerPolicyFromAtribute(
+    nsINode* aNode, ReferrerPolicyEnum& aPolicy) const {
+  aPolicy = ReferrerPolicy::_empty;
+  mozilla::dom::Element* element = aNode->AsElement();
+
+  if (!element || !element->IsAnyOfHTMLElements(
+                      nsGkAtoms::a, nsGkAtoms::area, nsGkAtoms::script,
+                      nsGkAtoms::iframe, nsGkAtoms::link, nsGkAtoms::img)) {
+    return;
+  }
+
+  aPolicy = element->GetReferrerPolicyAsEnum();
+}
+
+bool ReferrerInfo::HasRelNoReferrer(nsINode* aNode) const {
+  mozilla::dom::Element* element = aNode->AsElement();
+
+  // rel=noreferrer is only support in <a> and <area>
+  if (!element ||
+      !element->IsAnyOfHTMLElements(nsGkAtoms::a, nsGkAtoms::area)) {
+    return false;
+  }
+
+  nsAutoString rel;
+  element->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
+  nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> tok(rel);
+
+  while (tok.hasMoreTokens()) {
+    const nsAString& token = tok.nextToken();
+    if (token.LowerCaseEqualsLiteral("noreferrer")) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 nsresult ReferrerInfo::ComputeReferrer(nsIHttpChannel* aChannel) {
   NS_ENSURE_ARG(aChannel);
   MOZ_ASSERT(NS_IsMainThread());
 
   // If the referrerInfo is passed around when redirect, just use the last
   // computedReferrer to recompute
   nsCOMPtr<nsIURI> referrer;
   nsresult rv = NS_OK;
--- a/dom/security/ReferrerInfo.h
+++ b/dom/security/ReferrerInfo.h
@@ -65,33 +65,29 @@ class ReferrerInfo : public nsIReferrerI
   ReferrerInfo();
 
   explicit ReferrerInfo(
       nsIURI* aOriginalReferrer,
       ReferrerPolicyEnum aPolicy = ReferrerPolicy::_empty,
       bool aSendReferrer = true,
       const Maybe<nsCString>& aComputedReferrer = Maybe<nsCString>());
 
-  // Creates already initialized ReferrerInfo from an element or a document.
-  explicit ReferrerInfo(const Element&);
-  explicit ReferrerInfo(const Document&);
-
   // create an exact copy of the ReferrerInfo
-  already_AddRefed<ReferrerInfo> Clone() const;
+  already_AddRefed<nsIReferrerInfo> Clone() const;
 
   // create an copy of the ReferrerInfo with new referrer policy
-  already_AddRefed<ReferrerInfo> CloneWithNewPolicy(
+  already_AddRefed<nsIReferrerInfo> CloneWithNewPolicy(
       ReferrerPolicyEnum aPolicy) const;
 
   // create an copy of the ReferrerInfo with new send referrer
-  already_AddRefed<ReferrerInfo> CloneWithNewSendReferrer(
+  already_AddRefed<nsIReferrerInfo> CloneWithNewSendReferrer(
       bool aSendReferrer) const;
 
   // create an copy of the ReferrerInfo with new original referrer
-  already_AddRefed<ReferrerInfo> CloneWithNewOriginalReferrer(
+  already_AddRefed<nsIReferrerInfo> CloneWithNewOriginalReferrer(
       nsIURI* aOriginalReferrer) const;
 
   /*
    * Helper function to create a new ReferrerInfo object from other. We will not
    * pass in any computed values and override referrer policy if needed
    *
    * @param aOther the other referrerInfo object to init from.
    * @param aPolicyOverride referrer policy to override if necessary.
@@ -312,16 +308,30 @@ class ReferrerInfo : public nsIReferrerI
    * be send when compare 2 origins. Order matters here.
    */
   enum XOriginSendingPolicy : uint32_t {
     ePolicyAlwaysSend = 0,
     ePolicySendWhenSameDomain = 1,
     ePolicySendWhenSameHost = 2,
   };
 
+  /**
+   * Check whether the given node has referrerpolicy attribute and parse
+   * referrer policy from the attribute.
+   * Currently, referrerpolicy attribute is supported in a, area, img, iframe,
+   * script, or link element.
+   */
+  void GetReferrerPolicyFromAtribute(nsINode* aNode,
+                                     ReferrerPolicyEnum& aPolicy) const;
+
+  /**
+   * Return true if node has a rel="noreferrer" attribute.
+   */
+  bool HasRelNoReferrer(nsINode* aNode) const;
+
   /*
    * Handle user controlled pref network.http.referer.XOriginPolicy
    */
   nsresult HandleUserXOriginSendingPolicy(nsIURI* aURI, nsIURI* aReferrer,
                                           bool& aAllowed) const;
 
   /*
    * Handle user controlled pref network.http.sendRefererHeader
--- a/dom/svg/SVGStyleElement.cpp
+++ b/dom/svg/SVGStyleElement.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/dom/SVGStyleElement.h"
 
-#include "mozilla/RefPtr.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/SVGStyleElementBinding.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 
 NS_IMPL_NS_NEW_SVG_ELEMENT(Style)
 
 namespace mozilla {
@@ -175,27 +174,29 @@ void SVGStyleElement::SetTitle(const nsA
 Maybe<nsStyleLinkElement::SheetInfo> SVGStyleElement::GetStyleSheetInfo() {
   if (!IsCSSMimeTypeAttributeForStyleElement(*this)) {
     return Nothing();
   }
 
   nsAutoString title;
   nsAutoString media;
   GetTitleAndMediaForElement(*this, title, media);
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithNode(this);
 
   return Some(SheetInfo{
       *OwnerDoc(),
       this,
       nullptr,
       // FIXME(bug 1459822): Why doesn't this need a principal, but
       // HTMLStyleElement does?
       nullptr,
       // FIXME(bug 1459822): Why does this need a crossorigin attribute, but
       // HTMLStyleElement doesn't?
-      MakeAndAddRef<ReferrerInfo>(*this),
+      referrerInfo.forget(),
       AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)),
       title,
       media,
       /* integrity = */ EmptyString(),
       /* nsStyleUtil::CSPAllowsInlineStyle takes care of nonce checking for
          inline styles. Bug 1607011 */
       /* nonce = */ EmptyString(),
       HasAlternateRel::No,
--- a/dom/svg/SVGUseElement.cpp
+++ b/dom/svg/SVGUseElement.cpp
@@ -353,17 +353,19 @@ void SVGUseElement::UpdateShadowTree() {
       newSVGElement->SetLength(nsGkAtoms::width, mLengthAttributes[ATTR_WIDTH]);
     if (mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet())
       newSVGElement->SetLength(nsGkAtoms::height,
                                mLengthAttributes[ATTR_HEIGHT]);
   }
 
   // Bug 1415044 the specs do not say which referrer information we should use.
   // This may change if there's any spec comes out.
-  auto referrerInfo = MakeRefPtr<ReferrerInfo>(*this);
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new mozilla::dom::ReferrerInfo();
+  referrerInfo->InitWithNode(this);
+
   mContentURLData = new URLExtraData(baseURI.forget(), referrerInfo.forget(),
                                      do_AddRef(NodePrincipal()));
 
   targetElement->AddMutationObserver(this);
 }
 
 nsIURI* SVGUseElement::GetSourceDocURI() {
   nsIContent* targetElement = mReferencedElementTracker.get();
--- a/dom/xml/XMLStylesheetProcessingInstruction.cpp
+++ b/dom/xml/XMLStylesheetProcessingInstruction.cpp
@@ -120,23 +120,25 @@ XMLStylesheetProcessingInstruction::GetS
   }
 
   Document* doc = OwnerDoc();
   nsIURI* baseURL =
       mOverriddenBaseURI ? mOverriddenBaseURI.get() : doc->GetDocBaseURI();
   auto encoding = doc->GetDocumentCharacterSet();
   nsCOMPtr<nsIURI> uri;
   NS_NewURI(getter_AddRefs(uri), href, encoding, baseURL);
+  nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+  referrerInfo->InitWithDocument(doc);
 
   return Some(SheetInfo{
       *doc,
       this,
       uri.forget(),
       nullptr,
-      MakeAndAddRef<ReferrerInfo>(*doc),
+      referrerInfo.forget(),
       CORS_NONE,
       title,
       media,
       /* integrity = */ EmptyString(),
       /* nonce = */ EmptyString(),
       alternate ? HasAlternateRel::Yes : HasAlternateRel::No,
       IsInline::No,
       IsExplicitlyEnabled::No,
--- a/layout/xul/nsImageBoxFrame.cpp
+++ b/layout/xul/nsImageBoxFrame.cpp
@@ -245,17 +245,19 @@ void nsImageBoxFrame::UpdateImage() {
     nsContentUtils::GetContentPolicyTypeForUIImageLoading(
         mContent, getter_AddRefs(triggeringPrincipal), contentPolicyType,
         &requestContextID);
 
     nsCOMPtr<nsIURI> uri;
     nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri), src, doc,
                                               mContent->GetBaseURI());
     if (uri) {
-      auto referrerInfo = MakeRefPtr<ReferrerInfo>(*mContent->AsElement());
+      nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+      referrerInfo->InitWithNode(mContent);
+
       nsresult rv = nsContentUtils::LoadImage(
           uri, mContent, doc, triggeringPrincipal, requestContextID,
           referrerInfo, mListener, mLoadFlags, EmptyString(),
           getter_AddRefs(mImageRequest), contentPolicyType);
 
       if (NS_SUCCEEDED(rv) && mImageRequest) {
         nsLayoutUtils::RegisterImageRequestIfAnimated(
             presContext, mImageRequest, &mRequestRegistered);
--- a/layout/xul/tree/nsTreeBodyFrame.cpp
+++ b/layout/xul/tree/nsTreeBodyFrame.cpp
@@ -1913,17 +1913,18 @@ nsresult nsTreeBodyFrame::GetImage(int32
       styleRequest->SyncClone(imgNotificationObserver, doc,
                               getter_AddRefs(imageRequest));
     } else {
       nsCOMPtr<nsIURI> srcURI;
       nsContentUtils::NewURIWithDocumentCharset(
           getter_AddRefs(srcURI), imageSrc, doc, mContent->GetBaseURI());
       if (!srcURI) return NS_ERROR_FAILURE;
 
-      auto referrerInfo = MakeRefPtr<mozilla::dom::ReferrerInfo>(*doc);
+      nsCOMPtr<nsIReferrerInfo> referrerInfo = new mozilla::dom::ReferrerInfo();
+      referrerInfo->InitWithDocument(doc);
 
       // XXXbz what's the origin principal for this stuff that comes from our
       // view?  I guess we should assume that it's the node's principal...
       nsresult rv = nsContentUtils::LoadImage(
           srcURI, mContent, doc, mContent->NodePrincipal(), 0, referrerInfo,
           imgNotificationObserver, nsIRequest::LOAD_NORMAL, EmptyString(),
           getter_AddRefs(imageRequest));
       NS_ENSURE_SUCCESS(rv, rv);
--- a/toolkit/components/windowwatcher/nsWindowWatcher.cpp
+++ b/toolkit/components/windowwatcher/nsWindowWatcher.cpp
@@ -1166,17 +1166,18 @@ nsresult nsWindowWatcher::OpenWindowInte
          Also using GetDocument to force document creation seems to
          screw up focus in the hidden window; see bug 36016.
       */
       RefPtr<Document> doc = GetEntryDocument();
       if (!doc && parentWindow) {
         doc = parentWindow->GetExtantDoc();
       }
       if (doc) {
-        auto referrerInfo = MakeRefPtr<ReferrerInfo>(*doc);
+        nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo();
+        referrerInfo->InitWithDocument(doc);
         loadState->SetReferrerInfo(referrerInfo);
       }
     }
   }
 
   if (loadState && cx) {
     nsGlobalWindowInner* win = xpc::CurrentWindowOrNull(cx);
     if (win) {
--- a/xpcom/idl-parser/xpidl/xpidl.py
+++ b/xpcom/idl-parser/xpidl/xpidl.py
@@ -629,23 +629,22 @@ class WebIDL(object):
         if self.native is None:
             self.native = "mozilla::dom::%s" % self.name
         self.headerFile = config.get('headerFile')
         if self.headerFile is None:
             self.headerFile = self.native.replace('::', '/') + '.h'
 
         parent.setName(self)
 
-    def nativeType(self, calltype, const=False):
+    def nativeType(self, calltype):
         if calltype == 'element':
-            return 'RefPtr<%s%s>' % ('const ' if const else '', self.native)
-        return "%s%s *%s" % ('const ' if const else '', self.native,
-                             '*' if 'out' in calltype else '')
+            return 'RefPtr<%s>' % self.native
+        return "%s *%s" % (self.native, '*' if 'out' in calltype else '')
 
-    def rustType(self, calltype, const=False):
+    def rustType(self, calltype):
         # Just expose the type as a void* - we can't do any better.
         return "%s*const libc::c_void" % ('*mut ' if 'out' in calltype else '')
 
     def __str__(self):
         return "webidl %s\n" % self.name
 
 
 class Interface(object):