Bug 1572349 - Add Document::ResolveWithBaseURI. r=bzbarsky
authorKagami Sascha Rosylight <saschanaz@outlook.com>
Fri, 16 Aug 2019 03:38:31 +0300
changeset 488252 bd6df046c082cdab22dac956e16e357c1d9b5f4b
parent 488251 b283a7ef186c216d765631f6cb1260a3fa2ee42c
child 488384 d887276421d30c773431c006b0607cd30f4d9259
push id113905
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 00:41:58 +0000
treeherdermozilla-inbound@bd6df046c082 [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 Summary: This adds a helper method that enables simpler code in D41047 and D36714. Reviewers: bzbarsky, marcosc Reviewed By: bzbarsky Bug #: 1572349 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();