Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 7 | |
michael@0 | 8 | var gPrivacyPane = { |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * Whether the use has selected the auto-start private browsing mode in the UI. |
michael@0 | 12 | */ |
michael@0 | 13 | _autoStartPrivateBrowsing: false, |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * Whether the prompt to restart Firefox should appear when changing the autostart pref. |
michael@0 | 17 | */ |
michael@0 | 18 | _shouldPromptForRestart: true, |
michael@0 | 19 | |
michael@0 | 20 | /** |
michael@0 | 21 | * Sets up the UI for the number of days of history to keep, and updates the |
michael@0 | 22 | * label of the "Clear Now..." button. |
michael@0 | 23 | */ |
michael@0 | 24 | init: function () |
michael@0 | 25 | { |
michael@0 | 26 | this._updateSanitizeSettingsButton(); |
michael@0 | 27 | this.initializeHistoryMode(); |
michael@0 | 28 | this.updateHistoryModePane(); |
michael@0 | 29 | this.updatePrivacyMicroControls(); |
michael@0 | 30 | this.initAutoStartPrivateBrowsingReverter(); |
michael@0 | 31 | }, |
michael@0 | 32 | |
michael@0 | 33 | // HISTORY MODE |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * The list of preferences which affect the initial history mode settings. |
michael@0 | 37 | * If the auto start private browsing mode pref is active, the initial |
michael@0 | 38 | * history mode would be set to "Don't remember anything". |
michael@0 | 39 | * If all of these preferences have their default values, and the auto-start |
michael@0 | 40 | * private browsing mode is not active, the initial history mode would be |
michael@0 | 41 | * set to "Remember everything". |
michael@0 | 42 | * Otherwise, the initial history mode would be set to "Custom". |
michael@0 | 43 | * |
michael@0 | 44 | * Extensions adding their own preferences can append their IDs to this array if needed. |
michael@0 | 45 | */ |
michael@0 | 46 | prefsForDefault: [ |
michael@0 | 47 | "places.history.enabled", |
michael@0 | 48 | "browser.formfill.enable", |
michael@0 | 49 | "network.cookie.cookieBehavior", |
michael@0 | 50 | "network.cookie.lifetimePolicy", |
michael@0 | 51 | "privacy.sanitize.sanitizeOnShutdown" |
michael@0 | 52 | ], |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * The list of control IDs which are dependent on the auto-start private |
michael@0 | 56 | * browsing setting, such that in "Custom" mode they would be disabled if |
michael@0 | 57 | * the auto-start private browsing checkbox is checked, and enabled otherwise. |
michael@0 | 58 | * |
michael@0 | 59 | * Extensions adding their own controls can append their IDs to this array if needed. |
michael@0 | 60 | */ |
michael@0 | 61 | dependentControls: [ |
michael@0 | 62 | "rememberHistory", |
michael@0 | 63 | "rememberForms", |
michael@0 | 64 | "keepUntil", |
michael@0 | 65 | "keepCookiesUntil", |
michael@0 | 66 | "alwaysClear", |
michael@0 | 67 | "clearDataSettings" |
michael@0 | 68 | ], |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Check whether all the preferences values are set to their default values |
michael@0 | 72 | * |
michael@0 | 73 | * @param aPrefs an array of pref names to check for |
michael@0 | 74 | * @returns boolean true if all of the prefs are set to their default values, |
michael@0 | 75 | * false otherwise |
michael@0 | 76 | */ |
michael@0 | 77 | _checkDefaultValues: function(aPrefs) { |
michael@0 | 78 | for (let i = 0; i < aPrefs.length; ++i) { |
michael@0 | 79 | let pref = document.getElementById(aPrefs[i]); |
michael@0 | 80 | if (pref.value != pref.defaultValue) |
michael@0 | 81 | return false; |
michael@0 | 82 | } |
michael@0 | 83 | return true; |
michael@0 | 84 | }, |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * Initialize the history mode menulist based on the privacy preferences |
michael@0 | 88 | */ |
michael@0 | 89 | initializeHistoryMode: function PPP_initializeHistoryMode() |
michael@0 | 90 | { |
michael@0 | 91 | let mode; |
michael@0 | 92 | let getVal = function (aPref) |
michael@0 | 93 | document.getElementById(aPref).value; |
michael@0 | 94 | |
michael@0 | 95 | if (this._checkDefaultValues(this.prefsForDefault)) { |
michael@0 | 96 | if (getVal("browser.privatebrowsing.autostart")) |
michael@0 | 97 | mode = "dontremember"; |
michael@0 | 98 | else |
michael@0 | 99 | mode = "remember"; |
michael@0 | 100 | } |
michael@0 | 101 | else |
michael@0 | 102 | mode = "custom"; |
michael@0 | 103 | |
michael@0 | 104 | document.getElementById("historyMode").value = mode; |
michael@0 | 105 | }, |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Update the selected pane based on the history mode menulist |
michael@0 | 109 | */ |
michael@0 | 110 | updateHistoryModePane: function PPP_updateHistoryModePane() |
michael@0 | 111 | { |
michael@0 | 112 | let selectedIndex = -1; |
michael@0 | 113 | switch (document.getElementById("historyMode").value) { |
michael@0 | 114 | case "remember": |
michael@0 | 115 | selectedIndex = 0; |
michael@0 | 116 | break; |
michael@0 | 117 | case "dontremember": |
michael@0 | 118 | selectedIndex = 1; |
michael@0 | 119 | break; |
michael@0 | 120 | case "custom": |
michael@0 | 121 | selectedIndex = 2; |
michael@0 | 122 | break; |
michael@0 | 123 | } |
michael@0 | 124 | document.getElementById("historyPane").selectedIndex = selectedIndex; |
michael@0 | 125 | }, |
michael@0 | 126 | |
michael@0 | 127 | /** |
michael@0 | 128 | * Update the Tracking preferences based on controls. |
michael@0 | 129 | */ |
michael@0 | 130 | setTrackingPrefs: function PPP_setTrackingPrefs() |
michael@0 | 131 | { |
michael@0 | 132 | let dntRadioGroup = document.getElementById("doNotTrackSelection"), |
michael@0 | 133 | dntValuePref = document.getElementById("privacy.donottrackheader.value"), |
michael@0 | 134 | dntEnabledPref = document.getElementById("privacy.donottrackheader.enabled"); |
michael@0 | 135 | |
michael@0 | 136 | // if the selected radio button says "no preference", set on/off pref to |
michael@0 | 137 | // false and don't change the value pref. |
michael@0 | 138 | if (dntRadioGroup.selectedItem.value == -1) { |
michael@0 | 139 | dntEnabledPref.value = false; |
michael@0 | 140 | return dntValuePref.value; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | dntEnabledPref.value = true; |
michael@0 | 144 | return dntRadioGroup.selectedItem.value; |
michael@0 | 145 | }, |
michael@0 | 146 | |
michael@0 | 147 | /** |
michael@0 | 148 | * Obtain the tracking preference value and reflect it in the UI. |
michael@0 | 149 | */ |
michael@0 | 150 | getTrackingPrefs: function PPP_getTrackingPrefs() |
michael@0 | 151 | { |
michael@0 | 152 | let dntValuePref = document.getElementById("privacy.donottrackheader.value"), |
michael@0 | 153 | dntEnabledPref = document.getElementById("privacy.donottrackheader.enabled"); |
michael@0 | 154 | |
michael@0 | 155 | // if DNT is enbaled, select the value from the selected radio |
michael@0 | 156 | // button, otherwise choose the "no preference" radio button |
michael@0 | 157 | if (dntEnabledPref.value) |
michael@0 | 158 | return dntValuePref.value; |
michael@0 | 159 | |
michael@0 | 160 | return document.getElementById("dntnopref").value; |
michael@0 | 161 | }, |
michael@0 | 162 | |
michael@0 | 163 | /** |
michael@0 | 164 | * Update the private browsing auto-start pref and the history mode |
michael@0 | 165 | * micro-management prefs based on the history mode menulist |
michael@0 | 166 | */ |
michael@0 | 167 | updateHistoryModePrefs: function PPP_updateHistoryModePrefs() |
michael@0 | 168 | { |
michael@0 | 169 | let pref = document.getElementById("browser.privatebrowsing.autostart"); |
michael@0 | 170 | switch (document.getElementById("historyMode").value) { |
michael@0 | 171 | case "remember": |
michael@0 | 172 | if (pref.value) |
michael@0 | 173 | pref.value = false; |
michael@0 | 174 | |
michael@0 | 175 | // select the remember history option if needed |
michael@0 | 176 | let rememberHistoryCheckbox = document.getElementById("rememberHistory"); |
michael@0 | 177 | if (!rememberHistoryCheckbox.checked) |
michael@0 | 178 | rememberHistoryCheckbox.checked = true; |
michael@0 | 179 | |
michael@0 | 180 | // select the remember forms history option |
michael@0 | 181 | document.getElementById("browser.formfill.enable").value = true; |
michael@0 | 182 | |
michael@0 | 183 | #ifdef RELEASE_BUILD |
michael@0 | 184 | // select the accept cookies option |
michael@0 | 185 | document.getElementById("network.cookie.cookieBehavior").value = 0; |
michael@0 | 186 | #else |
michael@0 | 187 | // select the limit cookies option |
michael@0 | 188 | document.getElementById("network.cookie.cookieBehavior").value = 3; |
michael@0 | 189 | #endif |
michael@0 | 190 | // select the cookie lifetime policy option |
michael@0 | 191 | document.getElementById("network.cookie.lifetimePolicy").value = 0; |
michael@0 | 192 | |
michael@0 | 193 | // select the clear on close option |
michael@0 | 194 | document.getElementById("privacy.sanitize.sanitizeOnShutdown").value = false; |
michael@0 | 195 | break; |
michael@0 | 196 | case "dontremember": |
michael@0 | 197 | if (!pref.value) |
michael@0 | 198 | pref.value = true; |
michael@0 | 199 | break; |
michael@0 | 200 | } |
michael@0 | 201 | }, |
michael@0 | 202 | |
michael@0 | 203 | /** |
michael@0 | 204 | * Update the privacy micro-management controls based on the |
michael@0 | 205 | * value of the private browsing auto-start checkbox. |
michael@0 | 206 | */ |
michael@0 | 207 | updatePrivacyMicroControls: function PPP_updatePrivacyMicroControls() |
michael@0 | 208 | { |
michael@0 | 209 | if (document.getElementById("historyMode").value == "custom") { |
michael@0 | 210 | let disabled = this._autoStartPrivateBrowsing = |
michael@0 | 211 | document.getElementById("privateBrowsingAutoStart").checked; |
michael@0 | 212 | this.dependentControls |
michael@0 | 213 | .forEach(function (aElement) |
michael@0 | 214 | document.getElementById(aElement).disabled = disabled); |
michael@0 | 215 | |
michael@0 | 216 | // adjust the cookie controls status |
michael@0 | 217 | this.readAcceptCookies(); |
michael@0 | 218 | document.getElementById("keepCookiesUntil").value = disabled ? 2 : |
michael@0 | 219 | document.getElementById("network.cookie.lifetimePolicy").value; |
michael@0 | 220 | |
michael@0 | 221 | // adjust the checked state of the sanitizeOnShutdown checkbox |
michael@0 | 222 | document.getElementById("alwaysClear").checked = disabled ? false : |
michael@0 | 223 | document.getElementById("privacy.sanitize.sanitizeOnShutdown").value; |
michael@0 | 224 | |
michael@0 | 225 | // adjust the checked state of the remember history checkboxes |
michael@0 | 226 | document.getElementById("rememberHistory").checked = disabled ? false : |
michael@0 | 227 | document.getElementById("places.history.enabled").value; |
michael@0 | 228 | document.getElementById("rememberForms").checked = disabled ? false : |
michael@0 | 229 | document.getElementById("browser.formfill.enable").value; |
michael@0 | 230 | |
michael@0 | 231 | if (!disabled) { |
michael@0 | 232 | // adjust the Settings button for sanitizeOnShutdown |
michael@0 | 233 | this._updateSanitizeSettingsButton(); |
michael@0 | 234 | } |
michael@0 | 235 | } |
michael@0 | 236 | }, |
michael@0 | 237 | |
michael@0 | 238 | // PRIVATE BROWSING |
michael@0 | 239 | |
michael@0 | 240 | /** |
michael@0 | 241 | * Initialize the starting state for the auto-start private browsing mode pref reverter. |
michael@0 | 242 | */ |
michael@0 | 243 | initAutoStartPrivateBrowsingReverter: function PPP_initAutoStartPrivateBrowsingReverter() |
michael@0 | 244 | { |
michael@0 | 245 | let mode = document.getElementById("historyMode"); |
michael@0 | 246 | let autoStart = document.getElementById("privateBrowsingAutoStart"); |
michael@0 | 247 | this._lastMode = mode.selectedIndex; |
michael@0 | 248 | this._lastCheckState = autoStart.hasAttribute('checked'); |
michael@0 | 249 | }, |
michael@0 | 250 | |
michael@0 | 251 | _lastMode: null, |
michael@0 | 252 | _lastCheckState: null, |
michael@0 | 253 | updateAutostart: function PPP_updateAutostart() { |
michael@0 | 254 | let mode = document.getElementById("historyMode"); |
michael@0 | 255 | let autoStart = document.getElementById("privateBrowsingAutoStart"); |
michael@0 | 256 | let pref = document.getElementById("browser.privatebrowsing.autostart"); |
michael@0 | 257 | if ((mode.value == "custom" && this._lastCheckState == autoStart.checked) || |
michael@0 | 258 | (mode.value == "remember" && !this._lastCheckState) || |
michael@0 | 259 | (mode.value == "dontremember" && this._lastCheckState)) { |
michael@0 | 260 | // These are all no-op changes, so we don't need to prompt. |
michael@0 | 261 | this._lastMode = mode.selectedIndex; |
michael@0 | 262 | this._lastCheckState = autoStart.hasAttribute('checked'); |
michael@0 | 263 | return; |
michael@0 | 264 | } |
michael@0 | 265 | |
michael@0 | 266 | if (!this._shouldPromptForRestart) { |
michael@0 | 267 | // We're performing a revert. Just let it happen. |
michael@0 | 268 | return; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | const Cc = Components.classes, Ci = Components.interfaces; |
michael@0 | 272 | let brandName = document.getElementById("bundleBrand").getString("brandShortName"); |
michael@0 | 273 | let bundle = document.getElementById("bundlePreferences"); |
michael@0 | 274 | let msg = bundle.getFormattedString(autoStart.checked ? |
michael@0 | 275 | "featureEnableRequiresRestart" : "featureDisableRequiresRestart", |
michael@0 | 276 | [brandName]); |
michael@0 | 277 | let title = bundle.getFormattedString("shouldRestartTitle", [brandName]); |
michael@0 | 278 | let prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService); |
michael@0 | 279 | let shouldProceed = prompts.confirm(window, title, msg) |
michael@0 | 280 | if (shouldProceed) { |
michael@0 | 281 | let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"] |
michael@0 | 282 | .createInstance(Ci.nsISupportsPRBool); |
michael@0 | 283 | Services.obs.notifyObservers(cancelQuit, "quit-application-requested", |
michael@0 | 284 | "restart"); |
michael@0 | 285 | shouldProceed = !cancelQuit.data; |
michael@0 | 286 | |
michael@0 | 287 | if (shouldProceed) { |
michael@0 | 288 | pref.value = autoStart.hasAttribute('checked'); |
michael@0 | 289 | document.documentElement.acceptDialog(); |
michael@0 | 290 | let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"] |
michael@0 | 291 | .getService(Ci.nsIAppStartup); |
michael@0 | 292 | appStartup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart); |
michael@0 | 293 | return; |
michael@0 | 294 | } |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | this._shouldPromptForRestart = false; |
michael@0 | 298 | |
michael@0 | 299 | if (this._lastCheckState) { |
michael@0 | 300 | autoStart.checked = "checked"; |
michael@0 | 301 | } else { |
michael@0 | 302 | autoStart.removeAttribute('checked'); |
michael@0 | 303 | } |
michael@0 | 304 | pref.value = autoStart.hasAttribute('checked'); |
michael@0 | 305 | mode.selectedIndex = this._lastMode; |
michael@0 | 306 | mode.doCommand(); |
michael@0 | 307 | |
michael@0 | 308 | this._shouldPromptForRestart = true; |
michael@0 | 309 | }, |
michael@0 | 310 | |
michael@0 | 311 | // HISTORY |
michael@0 | 312 | |
michael@0 | 313 | /** |
michael@0 | 314 | * Read the location bar enabled and suggestion prefs |
michael@0 | 315 | * @return Int value for suggestion menulist |
michael@0 | 316 | */ |
michael@0 | 317 | readSuggestionPref: function PPP_readSuggestionPref() |
michael@0 | 318 | { |
michael@0 | 319 | let getVal = function(aPref) |
michael@0 | 320 | document.getElementById("browser.urlbar." + aPref).value; |
michael@0 | 321 | |
michael@0 | 322 | // Suggest nothing if autocomplete is not enabled |
michael@0 | 323 | if (!getVal("autocomplete.enabled")) |
michael@0 | 324 | return -1; |
michael@0 | 325 | |
michael@0 | 326 | // Bottom 2 bits of default.behavior specify history/bookmark |
michael@0 | 327 | return getVal("default.behavior") & 3; |
michael@0 | 328 | }, |
michael@0 | 329 | |
michael@0 | 330 | /** |
michael@0 | 331 | * Write the location bar enabled and suggestion prefs when necessary |
michael@0 | 332 | * @return Bool value for enabled pref |
michael@0 | 333 | */ |
michael@0 | 334 | writeSuggestionPref: function PPP_writeSuggestionPref() |
michael@0 | 335 | { |
michael@0 | 336 | let menuVal = document.getElementById("locationBarSuggestion").value; |
michael@0 | 337 | let enabled = menuVal != -1; |
michael@0 | 338 | |
michael@0 | 339 | // Only update default.behavior if we're giving suggestions |
michael@0 | 340 | if (enabled) { |
michael@0 | 341 | // Put the selected menu item's value directly into the bottom 2 bits |
michael@0 | 342 | let behavior = document.getElementById("browser.urlbar.default.behavior"); |
michael@0 | 343 | behavior.value = behavior.value >> 2 << 2 | menuVal; |
michael@0 | 344 | } |
michael@0 | 345 | |
michael@0 | 346 | // Always update the enabled pref |
michael@0 | 347 | return enabled; |
michael@0 | 348 | }, |
michael@0 | 349 | |
michael@0 | 350 | /* |
michael@0 | 351 | * Preferences: |
michael@0 | 352 | * |
michael@0 | 353 | * places.history.enabled |
michael@0 | 354 | * - whether history is enabled or not |
michael@0 | 355 | * browser.formfill.enable |
michael@0 | 356 | * - true if entries in forms and the search bar should be saved, false |
michael@0 | 357 | * otherwise |
michael@0 | 358 | */ |
michael@0 | 359 | |
michael@0 | 360 | // COOKIES |
michael@0 | 361 | |
michael@0 | 362 | /* |
michael@0 | 363 | * Preferences: |
michael@0 | 364 | * |
michael@0 | 365 | * network.cookie.cookieBehavior |
michael@0 | 366 | * - determines how the browser should handle cookies: |
michael@0 | 367 | * 0 means enable all cookies |
michael@0 | 368 | * 1 means reject all third party cookies |
michael@0 | 369 | * 2 means disable all cookies |
michael@0 | 370 | * 3 means reject third party cookies unless at least one is already set for the eTLD |
michael@0 | 371 | * see netwerk/cookie/src/nsCookieService.cpp for details |
michael@0 | 372 | * network.cookie.lifetimePolicy |
michael@0 | 373 | * - determines how long cookies are stored: |
michael@0 | 374 | * 0 means keep cookies until they expire |
michael@0 | 375 | * 1 means ask how long to keep each cookie |
michael@0 | 376 | * 2 means keep cookies until the browser is closed |
michael@0 | 377 | */ |
michael@0 | 378 | |
michael@0 | 379 | /** |
michael@0 | 380 | * Reads the network.cookie.cookieBehavior preference value and |
michael@0 | 381 | * enables/disables the rest of the cookie UI accordingly, returning true |
michael@0 | 382 | * if cookies are enabled. |
michael@0 | 383 | */ |
michael@0 | 384 | readAcceptCookies: function () |
michael@0 | 385 | { |
michael@0 | 386 | var pref = document.getElementById("network.cookie.cookieBehavior"); |
michael@0 | 387 | var acceptThirdPartyLabel = document.getElementById("acceptThirdPartyLabel"); |
michael@0 | 388 | var acceptThirdPartyMenu = document.getElementById("acceptThirdPartyMenu"); |
michael@0 | 389 | var keepUntil = document.getElementById("keepUntil"); |
michael@0 | 390 | var menu = document.getElementById("keepCookiesUntil"); |
michael@0 | 391 | |
michael@0 | 392 | // enable the rest of the UI for anything other than "disable all cookies" |
michael@0 | 393 | var acceptCookies = (pref.value != 2); |
michael@0 | 394 | |
michael@0 | 395 | acceptThirdPartyLabel.disabled = acceptThirdPartyMenu.disabled = !acceptCookies; |
michael@0 | 396 | keepUntil.disabled = menu.disabled = this._autoStartPrivateBrowsing || !acceptCookies; |
michael@0 | 397 | |
michael@0 | 398 | return acceptCookies; |
michael@0 | 399 | }, |
michael@0 | 400 | |
michael@0 | 401 | /** |
michael@0 | 402 | * Enables/disables the "keep until" label and menulist in response to the |
michael@0 | 403 | * "accept cookies" checkbox being checked or unchecked. |
michael@0 | 404 | */ |
michael@0 | 405 | writeAcceptCookies: function () |
michael@0 | 406 | { |
michael@0 | 407 | var accept = document.getElementById("acceptCookies"); |
michael@0 | 408 | var acceptThirdPartyMenu = document.getElementById("acceptThirdPartyMenu"); |
michael@0 | 409 | |
michael@0 | 410 | #ifdef RELEASE_BUILD |
michael@0 | 411 | // if we're enabling cookies, automatically select 'accept third party always' |
michael@0 | 412 | if (accept.checked) |
michael@0 | 413 | acceptThirdPartyMenu.selectedIndex = 0; |
michael@0 | 414 | |
michael@0 | 415 | return accept.checked ? 0 : 2; |
michael@0 | 416 | #else |
michael@0 | 417 | // if we're enabling cookies, automatically select 'accept third party from visited' |
michael@0 | 418 | if (accept.checked) |
michael@0 | 419 | acceptThirdPartyMenu.selectedIndex = 1; |
michael@0 | 420 | |
michael@0 | 421 | return accept.checked ? 3 : 2; |
michael@0 | 422 | #endif |
michael@0 | 423 | }, |
michael@0 | 424 | |
michael@0 | 425 | /** |
michael@0 | 426 | * Converts between network.cookie.cookieBehavior and the third-party cookie UI |
michael@0 | 427 | */ |
michael@0 | 428 | readAcceptThirdPartyCookies: function () |
michael@0 | 429 | { |
michael@0 | 430 | var pref = document.getElementById("network.cookie.cookieBehavior"); |
michael@0 | 431 | switch (pref.value) |
michael@0 | 432 | { |
michael@0 | 433 | case 0: |
michael@0 | 434 | return "always"; |
michael@0 | 435 | case 1: |
michael@0 | 436 | return "never"; |
michael@0 | 437 | case 2: |
michael@0 | 438 | return "never"; |
michael@0 | 439 | case 3: |
michael@0 | 440 | return "visited"; |
michael@0 | 441 | default: |
michael@0 | 442 | return undefined; |
michael@0 | 443 | } |
michael@0 | 444 | }, |
michael@0 | 445 | |
michael@0 | 446 | writeAcceptThirdPartyCookies: function () |
michael@0 | 447 | { |
michael@0 | 448 | var accept = document.getElementById("acceptThirdPartyMenu").selectedItem; |
michael@0 | 449 | switch (accept.value) |
michael@0 | 450 | { |
michael@0 | 451 | case "always": |
michael@0 | 452 | return 0; |
michael@0 | 453 | case "visited": |
michael@0 | 454 | return 3; |
michael@0 | 455 | case "never": |
michael@0 | 456 | return 1; |
michael@0 | 457 | default: |
michael@0 | 458 | return undefined; |
michael@0 | 459 | } |
michael@0 | 460 | }, |
michael@0 | 461 | |
michael@0 | 462 | /** |
michael@0 | 463 | * Displays fine-grained, per-site preferences for cookies. |
michael@0 | 464 | */ |
michael@0 | 465 | showCookieExceptions: function () |
michael@0 | 466 | { |
michael@0 | 467 | var bundlePreferences = document.getElementById("bundlePreferences"); |
michael@0 | 468 | var params = { blockVisible : true, |
michael@0 | 469 | sessionVisible : true, |
michael@0 | 470 | allowVisible : true, |
michael@0 | 471 | prefilledHost : "", |
michael@0 | 472 | permissionType : "cookie", |
michael@0 | 473 | windowTitle : bundlePreferences.getString("cookiepermissionstitle"), |
michael@0 | 474 | introText : bundlePreferences.getString("cookiepermissionstext") }; |
michael@0 | 475 | document.documentElement.openWindow("Browser:Permissions", |
michael@0 | 476 | "chrome://browser/content/preferences/permissions.xul", |
michael@0 | 477 | "", params); |
michael@0 | 478 | }, |
michael@0 | 479 | |
michael@0 | 480 | /** |
michael@0 | 481 | * Displays all the user's cookies in a dialog. |
michael@0 | 482 | */ |
michael@0 | 483 | showCookies: function (aCategory) |
michael@0 | 484 | { |
michael@0 | 485 | document.documentElement.openWindow("Browser:Cookies", |
michael@0 | 486 | "chrome://browser/content/preferences/cookies.xul", |
michael@0 | 487 | "", null); |
michael@0 | 488 | }, |
michael@0 | 489 | |
michael@0 | 490 | // CLEAR PRIVATE DATA |
michael@0 | 491 | |
michael@0 | 492 | /* |
michael@0 | 493 | * Preferences: |
michael@0 | 494 | * |
michael@0 | 495 | * privacy.sanitize.sanitizeOnShutdown |
michael@0 | 496 | * - true if the user's private data is cleared on startup according to the |
michael@0 | 497 | * Clear Private Data settings, false otherwise |
michael@0 | 498 | */ |
michael@0 | 499 | |
michael@0 | 500 | /** |
michael@0 | 501 | * Displays the Clear Private Data settings dialog. |
michael@0 | 502 | */ |
michael@0 | 503 | showClearPrivateDataSettings: function () |
michael@0 | 504 | { |
michael@0 | 505 | document.documentElement.openSubDialog("chrome://browser/content/preferences/sanitize.xul", |
michael@0 | 506 | "", null); |
michael@0 | 507 | }, |
michael@0 | 508 | |
michael@0 | 509 | |
michael@0 | 510 | /** |
michael@0 | 511 | * Displays a dialog from which individual parts of private data may be |
michael@0 | 512 | * cleared. |
michael@0 | 513 | */ |
michael@0 | 514 | clearPrivateDataNow: function (aClearEverything) |
michael@0 | 515 | { |
michael@0 | 516 | var ts = document.getElementById("privacy.sanitize.timeSpan"); |
michael@0 | 517 | var timeSpanOrig = ts.value; |
michael@0 | 518 | if (aClearEverything) |
michael@0 | 519 | ts.value = 0; |
michael@0 | 520 | |
michael@0 | 521 | const Cc = Components.classes, Ci = Components.interfaces; |
michael@0 | 522 | var glue = Cc["@mozilla.org/browser/browserglue;1"] |
michael@0 | 523 | .getService(Ci.nsIBrowserGlue); |
michael@0 | 524 | glue.sanitize(window); |
michael@0 | 525 | |
michael@0 | 526 | // reset the timeSpan pref |
michael@0 | 527 | if (aClearEverything) |
michael@0 | 528 | ts.value = timeSpanOrig; |
michael@0 | 529 | }, |
michael@0 | 530 | |
michael@0 | 531 | /** |
michael@0 | 532 | * Enables or disables the "Settings..." button depending |
michael@0 | 533 | * on the privacy.sanitize.sanitizeOnShutdown preference value |
michael@0 | 534 | */ |
michael@0 | 535 | _updateSanitizeSettingsButton: function () { |
michael@0 | 536 | var settingsButton = document.getElementById("clearDataSettings"); |
michael@0 | 537 | var sanitizeOnShutdownPref = document.getElementById("privacy.sanitize.sanitizeOnShutdown"); |
michael@0 | 538 | |
michael@0 | 539 | settingsButton.disabled = !sanitizeOnShutdownPref.value; |
michael@0 | 540 | } |
michael@0 | 541 | |
michael@0 | 542 | }; |