Bug 629535 - Add navigator.doNotTrack. r=sicking

--HG--
extra : rebase_source : 48631ff375196045de1c2865ab4ee9b9c219c736
This commit is contained in:
Justin Lebar 2011-09-19 15:59:22 -04:00
Родитель aa90a2cfee
Коммит 29d1d79b9d
4 изменённых файлов: 59 добавлений и 1 удалений

Просмотреть файл

@ -274,6 +274,7 @@ static PRPackedBool gDragServiceDisabled = PR_FALSE;
static FILE *gDumpFile = nsnull;
static PRUint64 gNextWindowID = 0;
static PRUint32 gSerialCounter = 0;
static PRBool gDoNotTrackEnabled = PR_FALSE;
#ifdef DEBUG_jst
PRInt32 gTimeoutCnt = 0;
@ -962,6 +963,10 @@ nsGlobalWindow::Init()
NS_ASSERTION(gEntropyCollector,
"gEntropyCollector should have been initialized!");
mozilla::Preferences::AddBoolVarCache(&gDoNotTrackEnabled,
"privacy.donottrackheader.enabled",
PR_FALSE);
#ifdef PR_LOGGING
gDOMLeakPRLog = PR_NewLogModule("DOMLeak");
NS_ASSERTION(gDOMLeakPRLog, "gDOMLeakPRLog should have been initialized!");
@ -11116,6 +11121,18 @@ nsNavigator::GetBuildID(nsAString& aBuildID)
return NS_OK;
}
NS_IMETHODIMP
nsNavigator::GetDoNotTrack(nsAString &aResult)
{
if (gDoNotTrackEnabled) {
aResult.AssignLiteral("yes");
}
else {
aResult.AssignLiteral("unspecified");
}
return NS_OK;
}
NS_IMETHODIMP
nsNavigator::JavaEnabled(PRBool *aReturn)
{

Просмотреть файл

@ -39,7 +39,7 @@
#include "domstubs.idl"
[scriptable, uuid(5dd9f1f5-3347-4945-a350-4eedeb97d24c)]
[scriptable, uuid(B8EE0374-5F47-4ED0-B9B0-BDE3E6D81FF5)]
interface nsIDOMNavigator : nsISupports
{
readonly attribute DOMString appCodeName;
@ -58,6 +58,7 @@ interface nsIDOMNavigator : nsISupports
readonly attribute boolean cookieEnabled;
readonly attribute boolean onLine;
readonly attribute DOMString buildID;
readonly attribute DOMString doNotTrack;
boolean javaEnabled();
};

Просмотреть файл

@ -55,6 +55,7 @@ _TEST_FILES = \
file_bug628069.html \
test_bug631440.html \
test_bug653364.html \
test_bug629535.html \
test_consoleAPI.html \
test_domWindowUtils.html \
test_domWindowUtils_scrollXY.html \

Просмотреть файл

@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=629535
-->
<head>
<title>Test for Bug 629535</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629535">Mozilla Bug 629535</a>
<script type="application/javascript">
const dntPref = 'privacy.donottrackheader.enabled';
const oldDNT = SpecialPowers.getBoolPref(dntPref);
is(SpecialPowers.getBoolPref(dntPref), false,
'DNT should be disabled by default');
is(navigator.doNotTrack, 'unspecified',
'navigator.doNotTrack should initially be "unspecified".');
SpecialPowers.clearUserPref(dntPref);
is(navigator.doNotTrack, "unspecified", 'after clearing pref');
SpecialPowers.setBoolPref(dntPref, true);
is(navigator.doNotTrack, "yes", 'after setting pref to true');
SpecialPowers.setBoolPref(dntPref, false);
is(navigator.doNotTrack, "unspecified", 'after setting pref to false');
SpecialPowers.setBoolPref(dntPref, oldDNT);
</script>
</body>
</html>