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