Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | var XPInstallConfirm = {}; |
michael@0 | 8 | |
michael@0 | 9 | XPInstallConfirm.init = function XPInstallConfirm_init() |
michael@0 | 10 | { |
michael@0 | 11 | var _installCountdown; |
michael@0 | 12 | var _installCountdownInterval; |
michael@0 | 13 | var _focused; |
michael@0 | 14 | var _timeout; |
michael@0 | 15 | |
michael@0 | 16 | // Default to cancelling the install when the window unloads |
michael@0 | 17 | XPInstallConfirm._installOK = false; |
michael@0 | 18 | |
michael@0 | 19 | var bundle = document.getElementById("xpinstallConfirmStrings"); |
michael@0 | 20 | |
michael@0 | 21 | let args = window.arguments[0].wrappedJSObject; |
michael@0 | 22 | |
michael@0 | 23 | var _installCountdownLength = 5; |
michael@0 | 24 | try { |
michael@0 | 25 | var prefs = Components.classes["@mozilla.org/preferences-service;1"] |
michael@0 | 26 | .getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 27 | var delay_in_milliseconds = prefs.getIntPref("security.dialog_enable_delay"); |
michael@0 | 28 | _installCountdownLength = Math.round(delay_in_milliseconds / 500); |
michael@0 | 29 | } catch (ex) { } |
michael@0 | 30 | |
michael@0 | 31 | var itemList = document.getElementById("itemList"); |
michael@0 | 32 | |
michael@0 | 33 | var numItemsToInstall = args.installs.length; |
michael@0 | 34 | for (let install of args.installs) { |
michael@0 | 35 | var installItem = document.createElement("installitem"); |
michael@0 | 36 | itemList.appendChild(installItem); |
michael@0 | 37 | |
michael@0 | 38 | installItem.name = install.addon.name; |
michael@0 | 39 | installItem.url = install.sourceURI.spec; |
michael@0 | 40 | var icon = install.iconURL; |
michael@0 | 41 | if (icon) |
michael@0 | 42 | installItem.icon = icon; |
michael@0 | 43 | var type = install.type; |
michael@0 | 44 | if (type) |
michael@0 | 45 | installItem.type = type; |
michael@0 | 46 | if (install.certName) { |
michael@0 | 47 | installItem.cert = bundle.getFormattedString("signed", [install.certName]); |
michael@0 | 48 | } |
michael@0 | 49 | else { |
michael@0 | 50 | installItem.cert = bundle.getString("unverified"); |
michael@0 | 51 | } |
michael@0 | 52 | installItem.signed = install.certName ? "true" : "false"; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | var introString = bundle.getString("itemWarnIntroSingle"); |
michael@0 | 56 | if (numItemsToInstall > 4) |
michael@0 | 57 | introString = bundle.getFormattedString("itemWarnIntroMultiple", [numItemsToInstall]); |
michael@0 | 58 | var textNode = document.createTextNode(introString); |
michael@0 | 59 | var introNode = document.getElementById("itemWarningIntro"); |
michael@0 | 60 | while (introNode.hasChildNodes()) |
michael@0 | 61 | introNode.removeChild(introNode.firstChild); |
michael@0 | 62 | introNode.appendChild(textNode); |
michael@0 | 63 | |
michael@0 | 64 | var okButton = document.documentElement.getButton("accept"); |
michael@0 | 65 | okButton.focus(); |
michael@0 | 66 | |
michael@0 | 67 | function okButtonCountdown() { |
michael@0 | 68 | _installCountdown -= 1; |
michael@0 | 69 | |
michael@0 | 70 | if (_installCountdown < 1) { |
michael@0 | 71 | okButton.label = bundle.getString("installButtonLabel"); |
michael@0 | 72 | okButton.disabled = false; |
michael@0 | 73 | clearInterval(_installCountdownInterval); |
michael@0 | 74 | } |
michael@0 | 75 | else |
michael@0 | 76 | okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function myfocus() { |
michael@0 | 80 | // Clear the timeout if it exists so only the last one will be used. |
michael@0 | 81 | if (_timeout) |
michael@0 | 82 | clearTimeout(_timeout); |
michael@0 | 83 | |
michael@0 | 84 | // Use setTimeout since the last focus or blur event to fire is the one we |
michael@0 | 85 | // want |
michael@0 | 86 | _timeout = setTimeout(setWidgetsAfterFocus, 0); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function setWidgetsAfterFocus() { |
michael@0 | 90 | if (_focused) |
michael@0 | 91 | return; |
michael@0 | 92 | |
michael@0 | 93 | _installCountdown = _installCountdownLength; |
michael@0 | 94 | _installCountdownInterval = setInterval(okButtonCountdown, 500); |
michael@0 | 95 | okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]); |
michael@0 | 96 | _focused = true; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function myblur() { |
michael@0 | 100 | // Clear the timeout if it exists so only the last one will be used. |
michael@0 | 101 | if (_timeout) |
michael@0 | 102 | clearTimeout(_timeout); |
michael@0 | 103 | |
michael@0 | 104 | // Use setTimeout since the last focus or blur event to fire is the one we |
michael@0 | 105 | // want |
michael@0 | 106 | _timeout = setTimeout(setWidgetsAfterBlur, 0); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function setWidgetsAfterBlur() { |
michael@0 | 110 | if (!_focused) |
michael@0 | 111 | return; |
michael@0 | 112 | |
michael@0 | 113 | // Set _installCountdown to the inital value set in setWidgetsAfterFocus |
michael@0 | 114 | // plus 1 so when the window is focused there is immediate ui feedback. |
michael@0 | 115 | _installCountdown = _installCountdownLength + 1; |
michael@0 | 116 | okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]); |
michael@0 | 117 | okButton.disabled = true; |
michael@0 | 118 | clearInterval(_installCountdownInterval); |
michael@0 | 119 | _focused = false; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | function myUnload() { |
michael@0 | 123 | if (_installCountdownLength > 0) { |
michael@0 | 124 | document.removeEventListener("focus", myfocus, true); |
michael@0 | 125 | document.removeEventListener("blur", myblur, true); |
michael@0 | 126 | } |
michael@0 | 127 | window.removeEventListener("unload", myUnload, false); |
michael@0 | 128 | |
michael@0 | 129 | // Now perform the desired action - either install the |
michael@0 | 130 | // addons or cancel the installations |
michael@0 | 131 | if (XPInstallConfirm._installOK) { |
michael@0 | 132 | for (let install of args.installs) |
michael@0 | 133 | install.install(); |
michael@0 | 134 | } |
michael@0 | 135 | else { |
michael@0 | 136 | for (let install of args.installs) |
michael@0 | 137 | install.cancel(); |
michael@0 | 138 | } |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | window.addEventListener("unload", myUnload, false); |
michael@0 | 142 | |
michael@0 | 143 | if (_installCountdownLength > 0) { |
michael@0 | 144 | document.addEventListener("focus", myfocus, true); |
michael@0 | 145 | document.addEventListener("blur", myblur, true); |
michael@0 | 146 | |
michael@0 | 147 | okButton.disabled = true; |
michael@0 | 148 | setWidgetsAfterFocus(); |
michael@0 | 149 | } |
michael@0 | 150 | else |
michael@0 | 151 | okButton.label = bundle.getString("installButtonLabel"); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | XPInstallConfirm.onOK = function XPInstallConfirm_onOk() |
michael@0 | 155 | { |
michael@0 | 156 | Components.classes["@mozilla.org/base/telemetry;1"]. |
michael@0 | 157 | getService(Components.interfaces.nsITelemetry). |
michael@0 | 158 | getHistogramById("SECURITY_UI"). |
michael@0 | 159 | add(Components.interfaces.nsISecurityUITelemetry.WARNING_CONFIRM_ADDON_INSTALL_CLICK_THROUGH); |
michael@0 | 160 | // Perform the install or cancel after the window has unloaded |
michael@0 | 161 | XPInstallConfirm._installOK = true; |
michael@0 | 162 | return true; |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | XPInstallConfirm.onCancel = function XPInstallConfirm_onCancel() |
michael@0 | 166 | { |
michael@0 | 167 | // Perform the install or cancel after the window has unloaded |
michael@0 | 168 | XPInstallConfirm._installOK = false; |
michael@0 | 169 | return true; |
michael@0 | 170 | } |