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 | /** |
michael@0 | 6 | * This dialog builds its content based on arguments passed into it. |
michael@0 | 7 | * window.arguments[0]: |
michael@0 | 8 | * The title of the dialog. |
michael@0 | 9 | * window.arguments[1]: |
michael@0 | 10 | * The url of the image that appears to the left of the description text |
michael@0 | 11 | * window.arguments[2]: |
michael@0 | 12 | * The text of the description that will appear above the choices the user |
michael@0 | 13 | * can choose from. |
michael@0 | 14 | * window.arguments[3]: |
michael@0 | 15 | * The text of the label directly above the choices the user can choose from. |
michael@0 | 16 | * window.arguments[4]: |
michael@0 | 17 | * This is the text to be placed in the label for the checkbox. If no text is |
michael@0 | 18 | * passed (ie, it's an empty string), the checkbox will be hidden. |
michael@0 | 19 | * window.arguments[5]: |
michael@0 | 20 | * The accesskey for the checkbox |
michael@0 | 21 | * window.arguments[6]: |
michael@0 | 22 | * This is the text that is displayed below the checkbox when it is checked. |
michael@0 | 23 | * window.arguments[7]: |
michael@0 | 24 | * This is the nsIHandlerInfo that gives us all our precious information. |
michael@0 | 25 | * window.arguments[8]: |
michael@0 | 26 | * This is the nsIURI that we are being brought up for in the first place. |
michael@0 | 27 | * window.arguments[9]: |
michael@0 | 28 | * The nsIInterfaceRequestor of the parent window; may be null |
michael@0 | 29 | */ |
michael@0 | 30 | |
michael@0 | 31 | const Cc = Components.classes; |
michael@0 | 32 | const Ci = Components.interfaces; |
michael@0 | 33 | const Cr = Components.results; |
michael@0 | 34 | |
michael@0 | 35 | var dialog = { |
michael@0 | 36 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 37 | //// Member Variables |
michael@0 | 38 | |
michael@0 | 39 | _handlerInfo: null, |
michael@0 | 40 | _URI: null, |
michael@0 | 41 | _itemChoose: null, |
michael@0 | 42 | _okButton: null, |
michael@0 | 43 | _windowCtxt: null, |
michael@0 | 44 | |
michael@0 | 45 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 46 | //// Methods |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * This function initializes the content of the dialog. |
michael@0 | 50 | */ |
michael@0 | 51 | initialize: function initialize() |
michael@0 | 52 | { |
michael@0 | 53 | this._handlerInfo = window.arguments[7].QueryInterface(Ci.nsIHandlerInfo); |
michael@0 | 54 | this._URI = window.arguments[8].QueryInterface(Ci.nsIURI); |
michael@0 | 55 | this._windowCtxt = window.arguments[9]; |
michael@0 | 56 | if (this._windowCtxt) |
michael@0 | 57 | this._windowCtxt.QueryInterface(Ci.nsIInterfaceRequestor); |
michael@0 | 58 | this._itemChoose = document.getElementById("item-choose"); |
michael@0 | 59 | this._okButton = document.documentElement.getButton("accept"); |
michael@0 | 60 | |
michael@0 | 61 | this.updateOKButton(); |
michael@0 | 62 | |
michael@0 | 63 | var description = { |
michael@0 | 64 | image: document.getElementById("description-image"), |
michael@0 | 65 | text: document.getElementById("description-text") |
michael@0 | 66 | }; |
michael@0 | 67 | var options = document.getElementById("item-action-text"); |
michael@0 | 68 | var checkbox = { |
michael@0 | 69 | desc: document.getElementById("remember"), |
michael@0 | 70 | text: document.getElementById("remember-text") |
michael@0 | 71 | }; |
michael@0 | 72 | |
michael@0 | 73 | // Setting values |
michael@0 | 74 | document.title = window.arguments[0]; |
michael@0 | 75 | description.image.src = window.arguments[1]; |
michael@0 | 76 | description.text.textContent = window.arguments[2]; |
michael@0 | 77 | options.value = window.arguments[3]; |
michael@0 | 78 | checkbox.desc.label = window.arguments[4]; |
michael@0 | 79 | checkbox.desc.accessKey = window.arguments[5]; |
michael@0 | 80 | checkbox.text.textContent = window.arguments[6]; |
michael@0 | 81 | |
michael@0 | 82 | // Hide stuff that needs to be hidden |
michael@0 | 83 | if (!checkbox.desc.label) |
michael@0 | 84 | checkbox.desc.hidden = true; |
michael@0 | 85 | |
michael@0 | 86 | // UI is ready, lets populate our list |
michael@0 | 87 | this.populateList(); |
michael@0 | 88 | }, |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Populates the list that a user can choose from. |
michael@0 | 92 | */ |
michael@0 | 93 | populateList: function populateList() |
michael@0 | 94 | { |
michael@0 | 95 | var items = document.getElementById("items"); |
michael@0 | 96 | var possibleHandlers = this._handlerInfo.possibleApplicationHandlers; |
michael@0 | 97 | var preferredHandler = this._handlerInfo.preferredApplicationHandler; |
michael@0 | 98 | var ios = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 99 | getService(Ci.nsIIOService); |
michael@0 | 100 | for (let i = possibleHandlers.length - 1; i >= 0; --i) { |
michael@0 | 101 | let app = possibleHandlers.queryElementAt(i, Ci.nsIHandlerApp); |
michael@0 | 102 | let elm = document.createElement("richlistitem"); |
michael@0 | 103 | elm.setAttribute("type", "handler"); |
michael@0 | 104 | elm.setAttribute("name", app.name); |
michael@0 | 105 | elm.obj = app; |
michael@0 | 106 | |
michael@0 | 107 | if (app instanceof Ci.nsILocalHandlerApp) { |
michael@0 | 108 | // See if we have an nsILocalHandlerApp and set the icon |
michael@0 | 109 | let uri = ios.newFileURI(app.executable); |
michael@0 | 110 | elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32"); |
michael@0 | 111 | } |
michael@0 | 112 | else if (app instanceof Ci.nsIWebHandlerApp) { |
michael@0 | 113 | let uri = ios.newURI(app.uriTemplate, null, null); |
michael@0 | 114 | if (/^https?/.test(uri.scheme)) { |
michael@0 | 115 | // Unfortunately we can't use the favicon service to get the favicon, |
michael@0 | 116 | // because the service looks for a record with the exact URL we give |
michael@0 | 117 | // it, and users won't have such records for URLs they don't visit, |
michael@0 | 118 | // and users won't visit the handler's URL template, they'll only |
michael@0 | 119 | // visit URLs derived from that template (i.e. with %s in the template |
michael@0 | 120 | // replaced by the URL of the content being handled). |
michael@0 | 121 | elm.setAttribute("image", uri.prePath + "/favicon.ico"); |
michael@0 | 122 | } |
michael@0 | 123 | elm.setAttribute("description", uri.prePath); |
michael@0 | 124 | } |
michael@0 | 125 | else if (app instanceof Ci.nsIDBusHandlerApp){ |
michael@0 | 126 | elm.setAttribute("description", app.method); |
michael@0 | 127 | } |
michael@0 | 128 | else |
michael@0 | 129 | throw "unknown handler type"; |
michael@0 | 130 | |
michael@0 | 131 | items.insertBefore(elm, this._itemChoose); |
michael@0 | 132 | if (preferredHandler && app == preferredHandler) |
michael@0 | 133 | this.selectedItem = elm; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | if (this._handlerInfo.hasDefaultHandler) { |
michael@0 | 137 | let elm = document.createElement("richlistitem"); |
michael@0 | 138 | elm.setAttribute("type", "handler"); |
michael@0 | 139 | elm.id = "os-default-handler"; |
michael@0 | 140 | elm.setAttribute("name", this._handlerInfo.defaultDescription); |
michael@0 | 141 | |
michael@0 | 142 | items.insertBefore(elm, items.firstChild); |
michael@0 | 143 | if (this._handlerInfo.preferredAction == |
michael@0 | 144 | Ci.nsIHandlerInfo.useSystemDefault) |
michael@0 | 145 | this.selectedItem = elm; |
michael@0 | 146 | } |
michael@0 | 147 | items.ensureSelectedElementIsVisible(); |
michael@0 | 148 | }, |
michael@0 | 149 | |
michael@0 | 150 | /** |
michael@0 | 151 | * Brings up a filepicker and allows a user to choose an application. |
michael@0 | 152 | */ |
michael@0 | 153 | chooseApplication: function chooseApplication() |
michael@0 | 154 | { |
michael@0 | 155 | var bundle = document.getElementById("base-strings"); |
michael@0 | 156 | var title = bundle.getString("choose.application.title"); |
michael@0 | 157 | |
michael@0 | 158 | var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); |
michael@0 | 159 | fp.init(window, title, Ci.nsIFilePicker.modeOpen); |
michael@0 | 160 | fp.appendFilters(Ci.nsIFilePicker.filterApps); |
michael@0 | 161 | |
michael@0 | 162 | if (fp.show() == Ci.nsIFilePicker.returnOK && fp.file) { |
michael@0 | 163 | let uri = Cc["@mozilla.org/network/util;1"]. |
michael@0 | 164 | getService(Ci.nsIIOService). |
michael@0 | 165 | newFileURI(fp.file); |
michael@0 | 166 | |
michael@0 | 167 | let handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"]. |
michael@0 | 168 | createInstance(Ci.nsILocalHandlerApp); |
michael@0 | 169 | handlerApp.executable = fp.file; |
michael@0 | 170 | |
michael@0 | 171 | // if this application is already in the list, select it and don't add it again |
michael@0 | 172 | let parent = document.getElementById("items"); |
michael@0 | 173 | for (let i = 0; i < parent.childNodes.length; ++i) { |
michael@0 | 174 | let elm = parent.childNodes[i]; |
michael@0 | 175 | if (elm.obj instanceof Ci.nsILocalHandlerApp && elm.obj.equals(handlerApp)) { |
michael@0 | 176 | parent.selectedItem = elm; |
michael@0 | 177 | parent.ensureSelectedElementIsVisible(); |
michael@0 | 178 | return; |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | let elm = document.createElement("richlistitem"); |
michael@0 | 183 | elm.setAttribute("type", "handler"); |
michael@0 | 184 | elm.setAttribute("name", fp.file.leafName); |
michael@0 | 185 | elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32"); |
michael@0 | 186 | elm.obj = handlerApp; |
michael@0 | 187 | |
michael@0 | 188 | parent.selectedItem = parent.insertBefore(elm, parent.firstChild); |
michael@0 | 189 | parent.ensureSelectedElementIsVisible(); |
michael@0 | 190 | } |
michael@0 | 191 | }, |
michael@0 | 192 | |
michael@0 | 193 | /** |
michael@0 | 194 | * Function called when the OK button is pressed. |
michael@0 | 195 | */ |
michael@0 | 196 | onAccept: function onAccept() |
michael@0 | 197 | { |
michael@0 | 198 | var checkbox = document.getElementById("remember"); |
michael@0 | 199 | if (!checkbox.hidden) { |
michael@0 | 200 | // We need to make sure that the default is properly set now |
michael@0 | 201 | if (this.selectedItem.obj) { |
michael@0 | 202 | // default OS handler doesn't have this property |
michael@0 | 203 | this._handlerInfo.preferredAction = Ci.nsIHandlerInfo.useHelperApp; |
michael@0 | 204 | this._handlerInfo.preferredApplicationHandler = this.selectedItem.obj; |
michael@0 | 205 | } |
michael@0 | 206 | else |
michael@0 | 207 | this._handlerInfo.preferredAction = Ci.nsIHandlerInfo.useSystemDefault; |
michael@0 | 208 | } |
michael@0 | 209 | this._handlerInfo.alwaysAskBeforeHandling = !checkbox.checked; |
michael@0 | 210 | |
michael@0 | 211 | var hs = Cc["@mozilla.org/uriloader/handler-service;1"]. |
michael@0 | 212 | getService(Ci.nsIHandlerService); |
michael@0 | 213 | hs.store(this._handlerInfo); |
michael@0 | 214 | |
michael@0 | 215 | this._handlerInfo.launchWithURI(this._URI, this._windowCtxt); |
michael@0 | 216 | |
michael@0 | 217 | return true; |
michael@0 | 218 | }, |
michael@0 | 219 | |
michael@0 | 220 | /** |
michael@0 | 221 | * Determines if the OK button should be disabled or not |
michael@0 | 222 | */ |
michael@0 | 223 | updateOKButton: function updateOKButton() |
michael@0 | 224 | { |
michael@0 | 225 | this._okButton.disabled = this._itemChoose.selected; |
michael@0 | 226 | }, |
michael@0 | 227 | |
michael@0 | 228 | /** |
michael@0 | 229 | * Updates the UI based on the checkbox being checked or not. |
michael@0 | 230 | */ |
michael@0 | 231 | onCheck: function onCheck() |
michael@0 | 232 | { |
michael@0 | 233 | if (document.getElementById("remember").checked) |
michael@0 | 234 | document.getElementById("remember-text").setAttribute("visible", "true"); |
michael@0 | 235 | else |
michael@0 | 236 | document.getElementById("remember-text").removeAttribute("visible"); |
michael@0 | 237 | }, |
michael@0 | 238 | |
michael@0 | 239 | /** |
michael@0 | 240 | * Function called when the user double clicks on an item of the list |
michael@0 | 241 | */ |
michael@0 | 242 | onDblClick: function onDblClick() |
michael@0 | 243 | { |
michael@0 | 244 | if (this.selectedItem == this._itemChoose) |
michael@0 | 245 | this.chooseApplication(); |
michael@0 | 246 | else |
michael@0 | 247 | document.documentElement.acceptDialog(); |
michael@0 | 248 | }, |
michael@0 | 249 | |
michael@0 | 250 | ///////////////////////////////////////////////////////////////////////////// |
michael@0 | 251 | //// Getters / Setters |
michael@0 | 252 | |
michael@0 | 253 | /** |
michael@0 | 254 | * Returns/sets the selected element in the richlistbox |
michael@0 | 255 | */ |
michael@0 | 256 | get selectedItem() |
michael@0 | 257 | { |
michael@0 | 258 | return document.getElementById("items").selectedItem; |
michael@0 | 259 | }, |
michael@0 | 260 | set selectedItem(aItem) |
michael@0 | 261 | { |
michael@0 | 262 | return document.getElementById("items").selectedItem = aItem; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | }; |