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