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: C; 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 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 8 | |
michael@0 | 9 | const C = Components.classes; |
michael@0 | 10 | const I = Components.interfaces; |
michael@0 | 11 | |
michael@0 | 12 | const ToolkitProfileService = "@mozilla.org/toolkit/profile-service;1"; |
michael@0 | 13 | |
michael@0 | 14 | var gDialogParams; |
michael@0 | 15 | var gProfileManagerBundle; |
michael@0 | 16 | var gBrandBundle; |
michael@0 | 17 | var gProfileService; |
michael@0 | 18 | |
michael@0 | 19 | function startup() |
michael@0 | 20 | { |
michael@0 | 21 | try { |
michael@0 | 22 | gDialogParams = window.arguments[0]. |
michael@0 | 23 | QueryInterface(I.nsIDialogParamBlock); |
michael@0 | 24 | |
michael@0 | 25 | gProfileService = C[ToolkitProfileService].getService(I.nsIToolkitProfileService); |
michael@0 | 26 | |
michael@0 | 27 | gProfileManagerBundle = document.getElementById("bundle_profileManager"); |
michael@0 | 28 | gBrandBundle = document.getElementById("bundle_brand"); |
michael@0 | 29 | |
michael@0 | 30 | document.documentElement.centerWindowOnScreen(); |
michael@0 | 31 | |
michael@0 | 32 | var profilesElement = document.getElementById("profiles"); |
michael@0 | 33 | |
michael@0 | 34 | var profileList = gProfileService.profiles; |
michael@0 | 35 | while (profileList.hasMoreElements()) { |
michael@0 | 36 | var profile = profileList.getNext().QueryInterface(I.nsIToolkitProfile); |
michael@0 | 37 | |
michael@0 | 38 | var listitem = profilesElement.appendItem(profile.name, ""); |
michael@0 | 39 | |
michael@0 | 40 | var tooltiptext = |
michael@0 | 41 | gProfileManagerBundle.getFormattedString("profileTooltip", [profile.name, profile.rootDir.path]); |
michael@0 | 42 | listitem.setAttribute("tooltiptext", tooltiptext); |
michael@0 | 43 | listitem.setAttribute("class", "listitem-iconic"); |
michael@0 | 44 | listitem.profile = profile; |
michael@0 | 45 | try { |
michael@0 | 46 | if (profile === gProfileService.selectedProfile) { |
michael@0 | 47 | setTimeout(function(a) { |
michael@0 | 48 | profilesElement.ensureElementIsVisible(a); |
michael@0 | 49 | profilesElement.selectItem(a); |
michael@0 | 50 | }, 0, listitem); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | catch(e) { } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | var autoSelectLastProfile = document.getElementById("autoSelectLastProfile"); |
michael@0 | 57 | autoSelectLastProfile.checked = gProfileService.startWithLastProfile; |
michael@0 | 58 | profilesElement.focus(); |
michael@0 | 59 | } |
michael@0 | 60 | catch(e) { |
michael@0 | 61 | window.close(); |
michael@0 | 62 | throw (e); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function acceptDialog() |
michael@0 | 67 | { |
michael@0 | 68 | var appName = gBrandBundle.getString("brandShortName"); |
michael@0 | 69 | |
michael@0 | 70 | var profilesElement = document.getElementById("profiles"); |
michael@0 | 71 | var selectedProfile = profilesElement.selectedItem; |
michael@0 | 72 | if (!selectedProfile) { |
michael@0 | 73 | var pleaseSelectTitle = gProfileManagerBundle.getString("pleaseSelectTitle"); |
michael@0 | 74 | var pleaseSelect = |
michael@0 | 75 | gProfileManagerBundle.getFormattedString("pleaseSelect", [appName]); |
michael@0 | 76 | Services.prompt.alert(window, pleaseSelectTitle, pleaseSelect); |
michael@0 | 77 | |
michael@0 | 78 | return false; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | var profileLock; |
michael@0 | 82 | |
michael@0 | 83 | try { |
michael@0 | 84 | profileLock = selectedProfile.profile.lock({ value: null }); |
michael@0 | 85 | } |
michael@0 | 86 | catch (e) { |
michael@0 | 87 | if (!selectedProfile.profile.rootDir.exists()) { |
michael@0 | 88 | var missingTitle = gProfileManagerBundle.getString("profileMissingTitle"); |
michael@0 | 89 | var missing = |
michael@0 | 90 | gProfileManagerBundle.getFormattedString("profileMissing", [appName]); |
michael@0 | 91 | Services.prompt.alert(window, missingTitle, missing); |
michael@0 | 92 | return false; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | var lockedTitle = gProfileManagerBundle.getString("profileLockedTitle"); |
michael@0 | 96 | var locked = |
michael@0 | 97 | gProfileManagerBundle.getFormattedString("profileLocked2", [appName, selectedProfile.profile.name, appName]); |
michael@0 | 98 | Services.prompt.alert(window, lockedTitle, locked); |
michael@0 | 99 | |
michael@0 | 100 | return false; |
michael@0 | 101 | } |
michael@0 | 102 | gDialogParams.objects.insertElementAt(profileLock.nsIProfileLock, 0, false); |
michael@0 | 103 | |
michael@0 | 104 | gProfileService.selectedProfile = selectedProfile.profile; |
michael@0 | 105 | updateStartupPrefs(); |
michael@0 | 106 | |
michael@0 | 107 | gDialogParams.SetInt(0, 1); |
michael@0 | 108 | |
michael@0 | 109 | gDialogParams.SetString(0, selectedProfile.profile.name); |
michael@0 | 110 | |
michael@0 | 111 | return true; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function exitDialog() |
michael@0 | 115 | { |
michael@0 | 116 | updateStartupPrefs(); |
michael@0 | 117 | |
michael@0 | 118 | return true; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | function updateStartupPrefs() |
michael@0 | 122 | { |
michael@0 | 123 | var autoSelectLastProfile = document.getElementById("autoSelectLastProfile"); |
michael@0 | 124 | gProfileService.startWithLastProfile = autoSelectLastProfile.checked; |
michael@0 | 125 | |
michael@0 | 126 | /* Bug 257777 */ |
michael@0 | 127 | gProfileService.startOffline = document.getElementById("offlineState").checked; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | // handle key event on listboxes |
michael@0 | 131 | function onProfilesKey(aEvent) |
michael@0 | 132 | { |
michael@0 | 133 | switch( aEvent.keyCode ) |
michael@0 | 134 | { |
michael@0 | 135 | case KeyEvent.DOM_VK_DELETE: |
michael@0 | 136 | ConfirmDelete(); |
michael@0 | 137 | break; |
michael@0 | 138 | case KeyEvent.DOM_VK_F2: |
michael@0 | 139 | RenameProfile(); |
michael@0 | 140 | break; |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | function onProfilesDblClick(aEvent) |
michael@0 | 145 | { |
michael@0 | 146 | if(aEvent.target.localName == "listitem") |
michael@0 | 147 | document.documentElement.acceptDialog(); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | // invoke the createProfile Wizard |
michael@0 | 151 | function CreateProfileWizard() |
michael@0 | 152 | { |
michael@0 | 153 | window.openDialog('chrome://mozapps/content/profile/createProfileWizard.xul', |
michael@0 | 154 | '', 'centerscreen,chrome,modal,titlebar', gProfileService); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | /** |
michael@0 | 158 | * Called from createProfileWizard to update the display. |
michael@0 | 159 | */ |
michael@0 | 160 | function CreateProfile(aProfile) |
michael@0 | 161 | { |
michael@0 | 162 | var profilesElement = document.getElementById("profiles"); |
michael@0 | 163 | |
michael@0 | 164 | var listitem = profilesElement.appendItem(aProfile.name, ""); |
michael@0 | 165 | |
michael@0 | 166 | var tooltiptext = |
michael@0 | 167 | gProfileManagerBundle.getFormattedString("profileTooltip", [aProfile.name, aProfile.rootDir.path]); |
michael@0 | 168 | listitem.setAttribute("tooltiptext", tooltiptext); |
michael@0 | 169 | listitem.setAttribute("class", "listitem-iconic"); |
michael@0 | 170 | listitem.profile = aProfile; |
michael@0 | 171 | |
michael@0 | 172 | profilesElement.ensureElementIsVisible(listitem); |
michael@0 | 173 | profilesElement.selectItem(listitem); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | // rename the selected profile |
michael@0 | 177 | function RenameProfile() |
michael@0 | 178 | { |
michael@0 | 179 | var profilesElement = document.getElementById("profiles"); |
michael@0 | 180 | var selectedItem = profilesElement.selectedItem; |
michael@0 | 181 | if (!selectedItem) { |
michael@0 | 182 | return false; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | var selectedProfile = selectedItem.profile; |
michael@0 | 186 | |
michael@0 | 187 | var oldName = selectedProfile.name; |
michael@0 | 188 | var newName = {value: oldName}; |
michael@0 | 189 | |
michael@0 | 190 | var dialogTitle = gProfileManagerBundle.getString("renameProfileTitle"); |
michael@0 | 191 | var msg = |
michael@0 | 192 | gProfileManagerBundle.getFormattedString("renameProfilePrompt", [oldName]); |
michael@0 | 193 | |
michael@0 | 194 | if (Services.prompt.prompt(window, dialogTitle, msg, newName, null, {value:0})) { |
michael@0 | 195 | newName = newName.value; |
michael@0 | 196 | |
michael@0 | 197 | // User hasn't changed the profile name. Treat as if cancel was pressed. |
michael@0 | 198 | if (newName == oldName) |
michael@0 | 199 | return false; |
michael@0 | 200 | |
michael@0 | 201 | try { |
michael@0 | 202 | selectedProfile.name = newName; |
michael@0 | 203 | } |
michael@0 | 204 | catch (e) { |
michael@0 | 205 | var alTitle = gProfileManagerBundle.getString("profileNameInvalidTitle"); |
michael@0 | 206 | var alMsg = gProfileManagerBundle.getFormattedString("profileNameInvalid", [newName]); |
michael@0 | 207 | Services.prompt.alert(window, alTitle, alMsg); |
michael@0 | 208 | return false; |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | selectedItem.label = newName; |
michael@0 | 212 | var tiptext = gProfileManagerBundle. |
michael@0 | 213 | getFormattedString("profileTooltip", |
michael@0 | 214 | [newName, selectedProfile.rootDir.path]); |
michael@0 | 215 | selectedItem.setAttribute("tooltiptext", tiptext); |
michael@0 | 216 | |
michael@0 | 217 | return true; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | return false; |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | function ConfirmDelete() |
michael@0 | 224 | { |
michael@0 | 225 | var deleteButton = document.getElementById("delbutton"); |
michael@0 | 226 | var profileList = document.getElementById( "profiles" ); |
michael@0 | 227 | |
michael@0 | 228 | var selectedItem = profileList.selectedItem; |
michael@0 | 229 | if (!selectedItem) { |
michael@0 | 230 | return false; |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | var selectedProfile = selectedItem.profile; |
michael@0 | 234 | var deleteFiles = false; |
michael@0 | 235 | |
michael@0 | 236 | if (selectedProfile.rootDir.exists()) { |
michael@0 | 237 | var dialogTitle = gProfileManagerBundle.getString("deleteTitle"); |
michael@0 | 238 | var dialogText = |
michael@0 | 239 | gProfileManagerBundle.getFormattedString("deleteProfileConfirm", |
michael@0 | 240 | [selectedProfile.rootDir.path]); |
michael@0 | 241 | |
michael@0 | 242 | var buttonPressed = Services.prompt.confirmEx(window, dialogTitle, dialogText, |
michael@0 | 243 | (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0) + |
michael@0 | 244 | (Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1) + |
michael@0 | 245 | (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_2), |
michael@0 | 246 | gProfileManagerBundle.getString("dontDeleteFiles"), |
michael@0 | 247 | null, |
michael@0 | 248 | gProfileManagerBundle.getString("deleteFiles"), |
michael@0 | 249 | null, {value:0}); |
michael@0 | 250 | if (buttonPressed == 1) |
michael@0 | 251 | return false; |
michael@0 | 252 | |
michael@0 | 253 | if (buttonPressed == 2) |
michael@0 | 254 | deleteFiles = true; |
michael@0 | 255 | } |
michael@0 | 256 | |
michael@0 | 257 | selectedProfile.remove(deleteFiles); |
michael@0 | 258 | profileList.removeChild(selectedItem); |
michael@0 | 259 | if (profileList.firstChild != undefined) { |
michael@0 | 260 | profileList.selectItem(profileList.firstChild); |
michael@0 | 261 | } |
michael@0 | 262 | |
michael@0 | 263 | return true; |
michael@0 | 264 | } |