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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function closeWindow(aClose, aPromptFunction) |
michael@0 | 6 | { |
michael@0 | 7 | # Closing the last window doesn't quit the application on OS X. |
michael@0 | 8 | #ifndef XP_MACOSX |
michael@0 | 9 | var windowCount = 0; |
michael@0 | 10 | var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] |
michael@0 | 11 | .getService(Components.interfaces.nsIWindowMediator); |
michael@0 | 12 | var e = wm.getEnumerator(null); |
michael@0 | 13 | |
michael@0 | 14 | while (e.hasMoreElements()) { |
michael@0 | 15 | var w = e.getNext(); |
michael@0 | 16 | if (w.closed) { |
michael@0 | 17 | continue; |
michael@0 | 18 | } |
michael@0 | 19 | if (++windowCount == 2) |
michael@0 | 20 | break; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | // If we're down to the last window and someone tries to shut down, check to make sure we can! |
michael@0 | 24 | if (windowCount == 1 && !canQuitApplication("lastwindow")) |
michael@0 | 25 | return false; |
michael@0 | 26 | else if (windowCount != 1) |
michael@0 | 27 | #endif |
michael@0 | 28 | if (typeof(aPromptFunction) == "function" && !aPromptFunction()) |
michael@0 | 29 | return false; |
michael@0 | 30 | |
michael@0 | 31 | if (aClose) |
michael@0 | 32 | window.close(); |
michael@0 | 33 | |
michael@0 | 34 | return true; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function canQuitApplication(aData) |
michael@0 | 38 | { |
michael@0 | 39 | var os = Components.classes["@mozilla.org/observer-service;1"] |
michael@0 | 40 | .getService(Components.interfaces.nsIObserverService); |
michael@0 | 41 | if (!os) return true; |
michael@0 | 42 | |
michael@0 | 43 | try { |
michael@0 | 44 | var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"] |
michael@0 | 45 | .createInstance(Components.interfaces.nsISupportsPRBool); |
michael@0 | 46 | os.notifyObservers(cancelQuit, "quit-application-requested", aData || null); |
michael@0 | 47 | |
michael@0 | 48 | // Something aborted the quit process. |
michael@0 | 49 | if (cancelQuit.data) |
michael@0 | 50 | return false; |
michael@0 | 51 | } |
michael@0 | 52 | catch (ex) { } |
michael@0 | 53 | return true; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function goQuitApplication() |
michael@0 | 57 | { |
michael@0 | 58 | if (!canQuitApplication()) |
michael@0 | 59 | return false; |
michael@0 | 60 | |
michael@0 | 61 | var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1']. |
michael@0 | 62 | getService(Components.interfaces.nsIAppStartup); |
michael@0 | 63 | |
michael@0 | 64 | appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); |
michael@0 | 65 | return true; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | // |
michael@0 | 69 | // Command Updater functions |
michael@0 | 70 | // |
michael@0 | 71 | function goUpdateCommand(aCommand) |
michael@0 | 72 | { |
michael@0 | 73 | try { |
michael@0 | 74 | var controller = top.document.commandDispatcher |
michael@0 | 75 | .getControllerForCommand(aCommand); |
michael@0 | 76 | |
michael@0 | 77 | var enabled = false; |
michael@0 | 78 | if (controller) |
michael@0 | 79 | enabled = controller.isCommandEnabled(aCommand); |
michael@0 | 80 | |
michael@0 | 81 | goSetCommandEnabled(aCommand, enabled); |
michael@0 | 82 | } |
michael@0 | 83 | catch (e) { |
michael@0 | 84 | Components.utils.reportError("An error occurred updating the " + |
michael@0 | 85 | aCommand + " command: " + e); |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function goDoCommand(aCommand) |
michael@0 | 90 | { |
michael@0 | 91 | try { |
michael@0 | 92 | var controller = top.document.commandDispatcher |
michael@0 | 93 | .getControllerForCommand(aCommand); |
michael@0 | 94 | if (controller && controller.isCommandEnabled(aCommand)) |
michael@0 | 95 | controller.doCommand(aCommand); |
michael@0 | 96 | } |
michael@0 | 97 | catch (e) { |
michael@0 | 98 | Components.utils.reportError("An error occurred executing the " + |
michael@0 | 99 | aCommand + " command: " + e); |
michael@0 | 100 | } |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | |
michael@0 | 104 | function goSetCommandEnabled(aID, aEnabled) |
michael@0 | 105 | { |
michael@0 | 106 | var node = document.getElementById(aID); |
michael@0 | 107 | |
michael@0 | 108 | if (node) { |
michael@0 | 109 | if (aEnabled) |
michael@0 | 110 | node.removeAttribute("disabled"); |
michael@0 | 111 | else |
michael@0 | 112 | node.setAttribute("disabled", "true"); |
michael@0 | 113 | } |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function goSetMenuValue(aCommand, aLabelAttribute) |
michael@0 | 117 | { |
michael@0 | 118 | var commandNode = top.document.getElementById(aCommand); |
michael@0 | 119 | if (commandNode) { |
michael@0 | 120 | var label = commandNode.getAttribute(aLabelAttribute); |
michael@0 | 121 | if (label) |
michael@0 | 122 | commandNode.setAttribute("label", label); |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | function goSetAccessKey(aCommand, aValueAttribute) |
michael@0 | 127 | { |
michael@0 | 128 | var commandNode = top.document.getElementById(aCommand); |
michael@0 | 129 | if (commandNode) { |
michael@0 | 130 | var value = commandNode.getAttribute(aValueAttribute); |
michael@0 | 131 | if (value) |
michael@0 | 132 | commandNode.setAttribute("accesskey", value); |
michael@0 | 133 | } |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | // this function is used to inform all the controllers attached to a node that an event has occurred |
michael@0 | 137 | // (e.g. the tree controllers need to be informed of blur events so that they can change some of the |
michael@0 | 138 | // menu items back to their default values) |
michael@0 | 139 | function goOnEvent(aNode, aEvent) |
michael@0 | 140 | { |
michael@0 | 141 | var numControllers = aNode.controllers.getControllerCount(); |
michael@0 | 142 | var controller; |
michael@0 | 143 | |
michael@0 | 144 | for (var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++) { |
michael@0 | 145 | controller = aNode.controllers.getControllerAt(controllerIndex); |
michael@0 | 146 | if (controller) |
michael@0 | 147 | controller.onEvent(aEvent); |
michael@0 | 148 | } |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | function visitLink(aEvent) { |
michael@0 | 152 | var node = aEvent.target; |
michael@0 | 153 | while (node.nodeType != Node.ELEMENT_NODE) |
michael@0 | 154 | node = node.parentNode; |
michael@0 | 155 | var url = node.getAttribute("link"); |
michael@0 | 156 | if (!url) |
michael@0 | 157 | return; |
michael@0 | 158 | |
michael@0 | 159 | var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"] |
michael@0 | 160 | .getService(Components.interfaces.nsIExternalProtocolService); |
michael@0 | 161 | var ioService = Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 162 | .getService(Components.interfaces.nsIIOService); |
michael@0 | 163 | var uri = ioService.newURI(url, null, null); |
michael@0 | 164 | |
michael@0 | 165 | // if the scheme is not an exposed protocol, then opening this link |
michael@0 | 166 | // should be deferred to the system's external protocol handler |
michael@0 | 167 | if (protocolSvc.isExposedProtocol(uri.scheme)) { |
michael@0 | 168 | var win = window.top; |
michael@0 | 169 | if (win instanceof Components.interfaces.nsIDOMChromeWindow) { |
michael@0 | 170 | while (win.opener && !win.opener.closed) |
michael@0 | 171 | win = win.opener; |
michael@0 | 172 | } |
michael@0 | 173 | win.open(uri.spec); |
michael@0 | 174 | } |
michael@0 | 175 | else |
michael@0 | 176 | protocolSvc.loadUrl(uri); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | function setTooltipText(aID, aTooltipText) |
michael@0 | 180 | { |
michael@0 | 181 | var element = document.getElementById(aID); |
michael@0 | 182 | if (element) |
michael@0 | 183 | element.setAttribute("tooltiptext", aTooltipText); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | this.__defineGetter__("NS_ASSERT", function() { |
michael@0 | 187 | delete this.NS_ASSERT; |
michael@0 | 188 | var tmpScope = {}; |
michael@0 | 189 | Components.utils.import("resource://gre/modules/debug.js", tmpScope); |
michael@0 | 190 | return this.NS_ASSERT = tmpScope.NS_ASSERT; |
michael@0 | 191 | }); |