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 | const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; |
michael@0 | 8 | const kDialog = "dialog"; |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * This dialog can be initialized from parameters supplied via window.arguments |
michael@0 | 12 | * or it can be used to display blocklist notification and blocklist blocked |
michael@0 | 13 | * installs via nsIDialogParamBlock as is done by nsIExtensionManager. |
michael@0 | 14 | * |
michael@0 | 15 | * When using this dialog with window.arguments it must be opened modally, the |
michael@0 | 16 | * caller can inspect the user action after the dialog closes by inspecting the |
michael@0 | 17 | * value of the |result| parameter on this object which is set to the dlgtype |
michael@0 | 18 | * of the button used to close the dialog. |
michael@0 | 19 | * |
michael@0 | 20 | * window.arguments[0] is an array of strings to display in the tree. If the |
michael@0 | 21 | * array is empty the tree will not be displayed. |
michael@0 | 22 | * window.arguments[1] a JS Object with the following properties: |
michael@0 | 23 | * |
michael@0 | 24 | * title: A title string, to be displayed in the title bar of the dialog. |
michael@0 | 25 | * message1: A message string, displayed above the addon list |
michael@0 | 26 | * message2: A message string, displayed below the addon list |
michael@0 | 27 | * message3: A bolded message string, displayed below the addon list |
michael@0 | 28 | * moreInfoURL: An url for displaying more information |
michael@0 | 29 | * iconClass : Can be one of the following values (default is alert-icon) |
michael@0 | 30 | * alert-icon, error-icon, or question-icon |
michael@0 | 31 | * |
michael@0 | 32 | * If no value is supplied for message1, message2, message3, or moreInfoURL, |
michael@0 | 33 | * the element is not displayed. |
michael@0 | 34 | * |
michael@0 | 35 | * buttons: { |
michael@0 | 36 | * accept: { label: "A Label for the Accept button", |
michael@0 | 37 | * focused: true }, |
michael@0 | 38 | * cancel: { label: "A Label for the Cancel button" }, |
michael@0 | 39 | * ... |
michael@0 | 40 | * }, |
michael@0 | 41 | * |
michael@0 | 42 | * result: The dlgtype of button that was used to dismiss the dialog. |
michael@0 | 43 | */ |
michael@0 | 44 | |
michael@0 | 45 | "use strict"; |
michael@0 | 46 | |
michael@0 | 47 | var gButtons = { }; |
michael@0 | 48 | |
michael@0 | 49 | function init() { |
michael@0 | 50 | var de = document.documentElement; |
michael@0 | 51 | var items = []; |
michael@0 | 52 | if (window.arguments[0] instanceof Components.interfaces.nsIDialogParamBlock) { |
michael@0 | 53 | // This is a warning about a blocklisted item the user is trying to install |
michael@0 | 54 | var args = window.arguments[0]; |
michael@0 | 55 | var softblocked = args.GetInt(0) == 1 ? true : false; |
michael@0 | 56 | |
michael@0 | 57 | var extensionsBundle = document.getElementById("extensionsBundle"); |
michael@0 | 58 | try { |
michael@0 | 59 | var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"] |
michael@0 | 60 | .getService(Components.interfaces.nsIURLFormatter); |
michael@0 | 61 | var url = formatter.formatURLPref("extensions.blocklist.detailsURL"); |
michael@0 | 62 | } |
michael@0 | 63 | catch (e) { } |
michael@0 | 64 | |
michael@0 | 65 | var params = { |
michael@0 | 66 | moreInfoURL: url, |
michael@0 | 67 | }; |
michael@0 | 68 | |
michael@0 | 69 | if (softblocked) { |
michael@0 | 70 | params.title = extensionsBundle.getString("softBlockedInstallTitle"); |
michael@0 | 71 | params.message1 = extensionsBundle.getFormattedString("softBlockedInstallMsg", |
michael@0 | 72 | [args.GetString(0)]); |
michael@0 | 73 | var accept = de.getButton("accept"); |
michael@0 | 74 | accept.label = extensionsBundle.getString("softBlockedInstallAcceptLabel"); |
michael@0 | 75 | accept.accessKey = extensionsBundle.getString("softBlockedInstallAcceptKey"); |
michael@0 | 76 | de.getButton("cancel").focus(); |
michael@0 | 77 | document.addEventListener("dialogaccept", allowInstall, false); |
michael@0 | 78 | } |
michael@0 | 79 | else { |
michael@0 | 80 | params.title = extensionsBundle.getString("blocklistedInstallTitle2"); |
michael@0 | 81 | params.message1 = extensionsBundle.getFormattedString("blocklistedInstallMsg2", |
michael@0 | 82 | [args.GetString(0)]); |
michael@0 | 83 | de.buttons = "accept"; |
michael@0 | 84 | de.getButton("accept").focus(); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | else { |
michael@0 | 88 | items = window.arguments[0]; |
michael@0 | 89 | params = window.arguments[1]; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | var addons = document.getElementById("addonsChildren"); |
michael@0 | 93 | if (items.length > 0) |
michael@0 | 94 | document.getElementById("addonsTree").hidden = false; |
michael@0 | 95 | |
michael@0 | 96 | // Fill the addons list |
michael@0 | 97 | for (var item of items) { |
michael@0 | 98 | var treeitem = document.createElementNS(kXULNS, "treeitem"); |
michael@0 | 99 | var treerow = document.createElementNS(kXULNS, "treerow"); |
michael@0 | 100 | var treecell = document.createElementNS(kXULNS, "treecell"); |
michael@0 | 101 | treecell.setAttribute("label", item); |
michael@0 | 102 | treerow.appendChild(treecell); |
michael@0 | 103 | treeitem.appendChild(treerow); |
michael@0 | 104 | addons.appendChild(treeitem); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | // Set the messages |
michael@0 | 108 | var messages = ["message1", "message2", "message3"]; |
michael@0 | 109 | for (let messageEntry of messages) { |
michael@0 | 110 | if (messageEntry in params) { |
michael@0 | 111 | var message = document.getElementById(messageEntry); |
michael@0 | 112 | message.hidden = false; |
michael@0 | 113 | message.appendChild(document.createTextNode(params[messageEntry])); |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | document.getElementById("infoIcon").className = |
michael@0 | 118 | params["iconClass"] ? "spaced " + params["iconClass"] : "spaced alert-icon"; |
michael@0 | 119 | |
michael@0 | 120 | if ("moreInfoURL" in params && params["moreInfoURL"]) { |
michael@0 | 121 | message = document.getElementById("moreInfo"); |
michael@0 | 122 | message.value = extensionsBundle.getString("moreInfoText"); |
michael@0 | 123 | message.setAttribute("href", params["moreInfoURL"]); |
michael@0 | 124 | document.getElementById("moreInfoBox").hidden = false; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | // Set the window title |
michael@0 | 128 | if ("title" in params) |
michael@0 | 129 | document.title = params.title; |
michael@0 | 130 | |
michael@0 | 131 | // Set up the buttons |
michael@0 | 132 | if ("buttons" in params) { |
michael@0 | 133 | gButtons = params.buttons; |
michael@0 | 134 | var buttonString = ""; |
michael@0 | 135 | for (var buttonType in gButtons) |
michael@0 | 136 | buttonString += "," + buttonType; |
michael@0 | 137 | de.buttons = buttonString.substr(1); |
michael@0 | 138 | for (buttonType in gButtons) { |
michael@0 | 139 | var button = de.getButton(buttonType); |
michael@0 | 140 | button.label = gButtons[buttonType].label; |
michael@0 | 141 | if (gButtons[buttonType].focused) |
michael@0 | 142 | button.focus(); |
michael@0 | 143 | document.addEventListener(kDialog + buttonType, handleButtonCommand, true); |
michael@0 | 144 | } |
michael@0 | 145 | } |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | function shutdown() { |
michael@0 | 149 | for (var buttonType in gButtons) |
michael@0 | 150 | document.removeEventListener(kDialog + buttonType, handleButtonCommand, true); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | function allowInstall() { |
michael@0 | 154 | var args = window.arguments[0]; |
michael@0 | 155 | args.SetInt(1, 1); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | /** |
michael@0 | 159 | * Watch for the user hitting one of the buttons to dismiss the dialog |
michael@0 | 160 | * and report the result back to the caller through the |result| property on |
michael@0 | 161 | * the arguments object. |
michael@0 | 162 | */ |
michael@0 | 163 | function handleButtonCommand(event) { |
michael@0 | 164 | window.arguments[1].result = event.type.substr(kDialog.length); |
michael@0 | 165 | } |