Bug 1572349 - Add Document::ResolveWithBaseURI r=bzbarsky
☠☠ backed out by 8b8878633443 ☠ ☠
authorKagami Sascha Rosylight <saschanaz@outlook.com>
Thu, 15 Aug 2019 14:49:19 +0000
changeset 488284 8e9d1223d391da60c16ea3e4087123f6c3b9f3a4
parent 488283 6b4a203e3a5567e117999b454cb408f7f5707393
child 488285 1b097ae05490a3b2c5e1c125160b0adea3515fe2
push id36440
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 03:57:48 +0000
treeherdermozilla-central@a58b7dc85887 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1572349
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1572349 - Add Document::ResolveWithBaseURI r=bzbarsky This adds a helper method that enables simpler code in D41047 and D36714. Differential Revision: https://phabricator.services.mozilla.com/D41902
dom/base/Document.cpp
dom/base/Document.h
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -326,16 +326,17 @@
 #include "mozilla/MediaManager.h"
 
 #include "AutoplayPolicy.h"
 #include "nsIURIMutator.h"
 #include "mozilla/DocumentStyleRootIterator.h"
 #include "mozilla/PendingFullscreenEvent.h"
 #include "mozilla/RestyleManager.h"
 #include "mozilla/ClearOnShutdown.h"
+#include "mozilla/ResultExtensions.h"
 #include "nsHTMLTags.h"
 #include "MobileViewportManager.h"
 #include "NodeUbiReporting.h"
 #include "nsICookieService.h"
 #include "mozilla/net/ChannelEventQueue.h"
 #include "mozilla/net/RequestContextService.h"
 #include "StorageAccessPermissionRequest.h"
 #include "mozilla/dom/WindowProxyHolder.h"
@@ -5745,16 +5746,24 @@ void Document::SetBaseURI(nsIURI* aURI) 
       return;
     }
   }
 
   mDocumentBaseURI = aURI;
   RefreshLinkHrefs();
 }
 
+Result<nsCOMPtr<nsIURI>, nsresult> Document::ResolveWithBaseURI(
+    const nsAString& aURI) {
+  nsCOMPtr<nsIURI> resolvedUri;
+  MOZ_TRY(
+      NS_NewURI(getter_AddRefs(resolvedUri), aURI, nullptr, GetDocBaseURI()));
+  return std::move(resolvedURI);
+}
+
 URLExtraData* Document::DefaultStyleAttrURLData() {
   MOZ_ASSERT(NS_IsMainThread());
   nsIURI* baseURI = GetDocBaseURI();
   nsIPrincipal* principal = NodePrincipal();
   bool equals;
   if (!mCachedURLData || mCachedURLData->BaseURI() != baseURI ||
       mCachedURLData->Principal() != principal || !mCachedReferrerInfo ||
       NS_FAILED(mCachedURLData->ReferrerInfo()->Equals(mCachedReferrerInfo,
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -906,16 +906,21 @@ class Document : public nsINode,
     return GetFallbackBaseURI();
   }
 
   nsIURI* GetBaseURI(bool aTryUseXHRDocBaseURI = false) const final;
 
   void SetBaseURI(nsIURI* aURI);
 
   /**
+   * Resolves a URI based on the document's base URI.
+   */
+  Result<nsCOMPtr<nsIURI>, nsresult> ResolveWithBaseURI(const nsAString& aURI);
+
+  /**
    * Return the URL data which style system needs for resolving url value.
    * This method attempts to use the cached object in mCachedURLData, but
    * if the base URI, document URI, or principal has changed since last
    * call to this function, or the function is called the first time for
    * the document, a new one is created.
    */
   URLExtraData* DefaultStyleAttrURLData();