commit 1f16ce85bc145032a6954a2b8ae81875c6ec1dbf Author: Arthur Edelstein arthuredelstein@gmail.com Date: Wed Apr 20 11:05:51 2016 -0700
fixup! Bug #5742: API allows you to get the url bar URI for a channel or nsIDocument.
See also: Bug 18741: Ensure that favicons and similar "content images in chrome" get the correct first-party assigned. --- dom/base/ThirdPartyUtil.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/dom/base/ThirdPartyUtil.cpp b/dom/base/ThirdPartyUtil.cpp index 762e2cf..26c95f5 100644 --- a/dom/base/ThirdPartyUtil.cpp +++ b/dom/base/ThirdPartyUtil.cpp @@ -543,24 +543,26 @@ ThirdPartyUtil::GetFirstPartyURIInternal(nsIChannel *aChannel,
// Favicons, or other items being loaded in chrome that belong // to a particular web site should be assigned that site's first party. - if (aNode && aNode->IsElement() && aNode->OwnerDoc() && - nsContentUtils::IsChromeDoc(aNode->OwnerDoc())) { - nsTArray<nsINode*> nodeAncestors; - nsContentUtils::GetAncestors(aNode, nodeAncestors); - for (nsINode* nodeAncestor : nodeAncestors) { - if (nodeAncestor->IsElement()) { - nsString firstparty; - nodeAncestor->AsElement()->GetAttribute(NS_LITERAL_STRING("firstparty"), firstparty); - if (!firstparty.IsEmpty()) { - nsCOMPtr<nsIURI> tempURI; - rv = NS_NewURI(getter_AddRefs(tempURI), firstparty); - if (rv != NS_OK) { - return rv; - } else { - NS_ADDREF(*aOutput = tempURI); - return NS_OK; - } - } + // If the originating node has a "firstparty" attribute + // containing a URI string, then it is returned. + nsCOMPtr<nsINode> node = aNode; + if (!node && aChannel) { + if (nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo()) { + node = loadInfo->LoadingNode(); + } + } + if (node && node->IsElement() && node->OwnerDoc() && + nsContentUtils::IsChromeDoc(node->OwnerDoc())) { + nsString firstparty; + node->AsElement()->GetAttribute(NS_LITERAL_STRING("firstparty"), firstparty); + if (!firstparty.IsEmpty()) { + nsCOMPtr<nsIURI> tempURI; + rv = NS_NewURI(getter_AddRefs(tempURI), firstparty); + if (rv != NS_OK) { + return rv; + } else { + NS_ADDREF(*aOutput = tempURI); + return NS_OK; } } }
tbb-commits@lists.torproject.org