Bug 1190450 - TP shield shows up incorrectly when pressing back while loading a page with tracking elements r=mcmanus

This commit is contained in:
Valentin Gosu 2015-08-13 11:14:36 +02:00
parent 4bf9aa2b08
commit 66e6a2979d
2 changed files with 34 additions and 0 deletions

View File

@ -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);

View File

@ -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