mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1190450 - TP shield shows up incorrectly when pressing back while loading a page with tracking elements r=mcmanus
This commit is contained in:
parent
4bf9aa2b08
commit
66e6a2979d
@ -450,6 +450,29 @@ nsChannelClassifier::HasBeenClassified(nsIChannel *aChannel)
|
||||
return tag.EqualsLiteral("1");
|
||||
}
|
||||
|
||||
//static
|
||||
bool
|
||||
nsChannelClassifier::SameLoadingURI(nsIDocument *aDoc, nsIChannel *aChannel)
|
||||
{
|
||||
nsCOMPtr<nsIURI> docURI = aDoc->GetDocumentURI();
|
||||
nsCOMPtr<nsILoadInfo> channelLoadInfo = aChannel->GetLoadInfo();
|
||||
if (!channelLoadInfo || !docURI) {
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<nsIPrincipal> channelLoadingPrincipal = channelLoadInfo->LoadingPrincipal();
|
||||
if (!channelLoadingPrincipal) {
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<nsIURI> channelLoadingURI;
|
||||
channelLoadingPrincipal->GetURI(getter_AddRefs(channelLoadingURI));
|
||||
if (!channelLoadingURI) {
|
||||
return false;
|
||||
}
|
||||
bool equals = false;
|
||||
nsresult rv = docURI->EqualsExceptRef(channelLoadingURI, &equals);
|
||||
return NS_SUCCEEDED(rv) && equals;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
nsChannelClassifier::SetBlockedTrackingContent(nsIChannel *channel)
|
||||
@ -480,6 +503,14 @@ nsChannelClassifier::SetBlockedTrackingContent(nsIChannel *channel)
|
||||
nsCOMPtr<nsIDocument> doc = do_GetInterface(docShell, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
|
||||
// This event might come after the user has navigated to another page.
|
||||
// To prevent showing the TrackingProtection UI on the wrong page, we need to
|
||||
// check that the loading URI for the channel is the same as the URI currently
|
||||
// loaded in the document.
|
||||
if (!SameLoadingURI(doc, channel)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Notify nsIWebProgressListeners of this security event.
|
||||
// Can be used to change the UI state.
|
||||
nsCOMPtr<nsISecurityEventSink> eventSink = do_QueryInterface(docShell, &rv);
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
class nsIChannel;
|
||||
class nsIHttpChannelInternal;
|
||||
class nsIDocument;
|
||||
|
||||
class nsChannelClassifier final : public nsIURIClassifierCallback
|
||||
{
|
||||
@ -43,6 +44,8 @@ private:
|
||||
nsresult StartInternal();
|
||||
// Helper function to check a tracking URI against the whitelist
|
||||
nsresult IsTrackerWhitelisted();
|
||||
// Checks that the channel was loaded by the URI currently loaded in aDoc
|
||||
static bool SameLoadingURI(nsIDocument *aDoc, nsIChannel *aChannel);
|
||||
|
||||
public:
|
||||
// If we are blocking tracking content, update the corresponding flag in
|
||||
|
Loading…
Reference in New Issue
Block a user