Bug 628197. Implement do-not-track HTTP header to express user intent to halt tracking across site. r=dwitte, a=jst.

--HG--
extra : rebase_source : 29550c73f45bfefac311cdce4eef80e947869738
This commit is contained in:
Sid Stamm 2011-01-05 11:53:21 -08:00
parent cba19c676e
commit 0bbb185dcd
4 changed files with 29 additions and 0 deletions

View File

@ -586,6 +586,9 @@ pref("content.sink.pending_event_mode", 0);
// 2 = openAbused
pref("privacy.popups.disable_from_plugins", 2);
// "do not track" HTTP header, disabled by default
pref("privacy.donottrackheader.enabled", false);
pref("dom.event.contextmenu.enabled", true);
pref("javascript.enabled", true);

View File

@ -77,6 +77,7 @@ HTTP_ATOM(DAV, "DAV")
HTTP_ATOM(Depth, "Depth")
HTTP_ATOM(Derived_From, "Derived-From")
HTTP_ATOM(Destination, "Destination")
HTTP_ATOM(DoNotTrack, "DNT")
HTTP_ATOM(ETag, "Etag")
HTTP_ATOM(Expect, "Expect")
HTTP_ATOM(Expires, "Expires")

View File

@ -130,6 +130,7 @@ static NS_DEFINE_CID(kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID);
#define INTL_ACCEPT_CHARSET "intl.charset.default"
#define NETWORK_ENABLEIDN "network.enableIDN"
#define BROWSER_PREF_PREFIX "browser.cache."
#define DONOTTRACK_HEADER_ENABLED "privacy.donottrackheader.enabled"
#define UA_PREF(_pref) UA_PREF_PREFIX _pref
#define HTTP_PREF(_pref) HTTP_PREF_PREFIX _pref
@ -198,6 +199,7 @@ nsHttpHandler::nsHttpHandler()
, mPromptTempRedirect(PR_TRUE)
, mSendSecureXSiteReferrer(PR_TRUE)
, mEnablePersistentHttpsCaching(PR_FALSE)
, mDoNotTrackEnabled(PR_FALSE)
{
#if defined(PR_LOGGING)
gHttpLog = PR_NewLogModule("nsHttp");
@ -262,6 +264,7 @@ nsHttpHandler::Init()
prefBranch->AddObserver(INTL_ACCEPT_CHARSET, this, PR_TRUE);
prefBranch->AddObserver(NETWORK_ENABLEIDN, this, PR_TRUE);
prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, PR_TRUE);
prefBranch->AddObserver(DONOTTRACK_HEADER_ENABLED, this, PR_TRUE);
PrefsChanged(prefBranch, nsnull);
}
@ -406,6 +409,13 @@ nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request,
request->SetHeader(nsHttp::Connection, close);
}
// Add the "Do-Not-Track" header
if (mDoNotTrackEnabled) {
rv = request->SetHeader(nsHttp::DoNotTrack,
NS_LITERAL_CSTRING("1"));
if (NS_FAILED(rv)) return rv;
}
const nsHttpAtom &header = useProxy ? nsHttp::Proxy_Connection
: nsHttp::Connection;
return request->SetHeader(header, *connectionType);
@ -1126,6 +1136,18 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
mIDNConverter = nsnull;
}
//
// Tracking options
//
if (PREF_CHANGED(DONOTTRACK_HEADER_ENABLED)) {
cVar = PR_FALSE;
rv = prefs->GetBoolPref(DONOTTRACK_HEADER_ENABLED, &cVar);
if (NS_SUCCEEDED(rv)) {
mDoNotTrackEnabled = cVar;
}
}
#undef PREF_CHANGED
#undef MULTI_PREF_CHANGED
}

View File

@ -326,6 +326,9 @@ private:
// Persistent HTTPS caching flag
PRPackedBool mEnablePersistentHttpsCaching;
// For broadcasting the preference to not be tracked
PRPackedBool mDoNotTrackEnabled;
};
//-----------------------------------------------------------------------------