1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
14 # The Original Code is The Browser Profile Migrator.
16 # The Initial Developer of the Original Code is Ben Goodger.
17 # Portions created by the Initial Developer are Copyright (C) 2004
18 # the Initial Developer. All Rights Reserved.
21 # Ben Goodger <ben@bengoodger.com>
23 # Alternatively, the contents of this file may be used under the terms of
24 # either the GNU General Public License Version 2 or later (the "GPL"), or
25 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 # in which case the provisions of the GPL or the LGPL are applicable instead
27 # of those above. If you wish to allow use of your version of this file only
28 # under the terms of either the GPL or the LGPL, and not to allow others to
29 # use your version of this file under the terms of the MPL, indicate your
30 # decision by deleting the provisions above and replace them with the notice
31 # and other provisions required by the GPL or the LGPL. If you do not delete
32 # the provisions above, a recipient may use your version of this file under
33 # the terms of any one of the MPL, the GPL or the LGPL.
35 # ***** END LICENSE BLOCK *****
37 const kIMig = Components.interfaces.nsIBrowserProfileMigrator;
38 const kIPStartup = Components.interfaces.nsIProfileStartup;
43 _itemsFlags:
kIMig.ALL,
44 _selectedProfile:
null,
52 var
os = Components.classes[
"@mozilla.org/observer-service;1"]
53 .getService(Components.interfaces.nsIObserverService);
54 os.addObserver(
this,
"Migration:Started",
false);
55 os.addObserver(
this,
"Migration:ItemBeforeMigrate",
false);
56 os.addObserver(
this,
"Migration:ItemAfterMigrate",
false);
57 os.addObserver(
this,
"Migration:Ended",
false);
59 this._wiz = document.documentElement;
61 if (
"arguments" in
window &&
window.arguments.length > 1) {
62 this._source =
window.arguments[0];
63 this._migrator =
window.arguments[1].QueryInterface(
kIMig);
66 if (this._autoMigrate) {
69 var nothing = document.getElementById(
"nothing");
70 nothing.hidden =
false;
74 this.onImportSourcePageShow();
79 var
os = Components.classes[
"@mozilla.org/observer-service;1"]
80 .getService(Components.interfaces.nsIObserverService);
81 os.removeObserver(
this,
"Migration:Started");
82 os.removeObserver(
this,
"Migration:ItemBeforeMigrate");
83 os.removeObserver(
this,
"Migration:ItemAfterMigrate");
84 os.removeObserver(
this,
"Migration:Ended");
88 onImportSourcePageShow:
function ()
94 if (
"arguments" in
window &&
window.arguments[0] ==
"bookmarks") {
95 this._bookmarks =
true;
97 fromfile = document.getElementById(
"fromfile");
98 fromfile.hidden =
false;
100 var importBookmarks = document.getElementById(
"importBookmarks");
101 importBookmarks.hidden =
false;
103 var importAll = document.getElementById(
"importAll");
104 importAll.hidden =
true;
107 this._wiz.canRewind =
false;
111 var selectedMigrator = fromfile;
114 var
group = document.getElementById(
"importSourceGroup");
115 for (var
i = 0;
i < group.childNodes.length; ++
i) {
116 var suffix = group.childNodes[
i].id;
117 if (suffix !=
"nothing" && suffix !=
"fromfile") {
123 dump(
"*** invalid contractID =" + contractID +
"\n");
127 if (migrator.sourceExists &&
128 !(suffix ==
"phoenix" && !
this._autoMigrate)) {
131 if (!selectedMigrator || this._source == suffix)
132 selectedMigrator = group.childNodes[
i];
135 group.childNodes[
i].hidden =
true;
140 if (selectedMigrator)
141 group.selectedItem = selectedMigrator;
144 document.getElementById(
"noSources").hidden =
false;
146 this._wiz.canAdvance =
false;
148 document.getElementById(
"importBookmarks").hidden =
true;
149 document.getElementById(
"importAll").hidden =
true;
153 onImportSourcePageAdvanced:
function ()
155 var newSource = document.getElementById(
"importSourceGroup").selectedItem.id;
157 if (newSource ==
"nothing" || newSource ==
"fromfile") {
158 if(newSource ==
"fromfile")
159 window.opener.fromFile =
true;
160 document.documentElement.cancel();
164 if (!this._migrator || (newSource != this._source)) {
169 this._itemsFlags =
kIMig.ALL;
170 this._selectedProfile =
null;
172 this._source = newSource;
175 if (this._migrator.sourceHasMultipleProfiles)
176 this._wiz.currentPage.next =
"selectProfile";
178 if (this._autoMigrate)
179 this._wiz.currentPage.next =
"homePageImport";
180 else if (this._bookmarks)
181 this._wiz.currentPage.next =
"migrating"
183 this._wiz.currentPage.next =
"importItems";
185 var sourceProfiles = this._migrator.sourceProfiles;
186 if (sourceProfiles && sourceProfiles.Count() == 1) {
187 var profileName = sourceProfiles.QueryElementAt(0, Components.interfaces.nsISupportsString);
188 this._selectedProfile = profileName.data;
191 this._selectedProfile =
"";
196 onSelectProfilePageShow:
function ()
203 var profiles = document.getElementById(
"profiles");
204 while (profiles.hasChildNodes())
205 profiles.removeChild(profiles.firstChild);
209 if (this._migrator) {
210 var sourceProfiles = this._migrator.sourceProfiles;
211 var
count = sourceProfiles.Count();
213 var item = document.createElement(
"radio");
214 var
str = sourceProfiles.QueryElementAt(
i, Components.interfaces.nsISupportsString);
216 item.setAttribute(
"label", str.data);
217 profiles.appendChild(item);
221 profiles.selectedItem = this._selectedProfile ? document.getElementById(this._selectedProfile) : profiles.firstChild;
224 onSelectProfilePageRewound:
function ()
226 var profiles = document.getElementById(
"profiles");
227 this._selectedProfile = profiles.selectedItem.id;
230 onSelectProfilePageAdvanced:
function ()
232 var profiles = document.getElementById(
"profiles");
233 this._selectedProfile = profiles.selectedItem.id;
236 if (this._autoMigrate)
237 this._wiz.currentPage.next =
"homePageImport";
238 else if (this._bookmarks)
239 this._wiz.currentPage.next =
"migrating"
243 onImportItemsPageShow:
function ()
245 var dataSources = document.getElementById(
"dataSources");
246 while (dataSources.hasChildNodes())
247 dataSources.removeChild(dataSources.firstChild);
249 var
bundle = document.getElementById(
"bundle");
251 var items = this._migrator.getMigrateData(this._selectedProfile, this._autoMigrate);
252 for (var
i = 0;
i < 16; ++
i) {
253 var itemID = (items >>
i) & 0x1 ? Math.pow(2,
i) : 0;
255 var checkbox = document.createElement(
"checkbox");
256 checkbox.id = itemID;
257 checkbox.setAttribute(
"label", bundle.getString(itemID +
"_" +
this._source));
258 dataSources.appendChild(checkbox);
259 if (!this._itemsFlags || this._itemsFlags & itemID)
260 checkbox.checked =
true;
265 onImportItemsPageRewound:
function ()
267 this._wiz.canAdvance =
true;
268 this.onImportItemsPageAdvanced();
271 onImportItemsPageAdvanced:
function ()
273 var dataSources = document.getElementById(
"dataSources");
274 this._itemsFlags = 0;
275 for (var
i = 0;
i < dataSources.childNodes.length; ++
i) {
276 var checkbox = dataSources.childNodes[
i];
277 if (checkbox.localName ==
"checkbox" && checkbox.checked)
278 this._itemsFlags |= parseInt(checkbox.id);
282 onImportItemCommand:
function (aEvent)
284 var items = document.getElementById(
"dataSources");
285 var checkboxes = items.getElementsByTagName(
"checkbox");
287 var oneChecked =
false;
288 for (var
i = 0;
i < checkboxes.length; ++
i) {
289 if (checkboxes[
i].checked) {
295 this._wiz.canAdvance = oneChecked;
299 onHomePageMigrationPageShow:
function ()
302 if (!this._autoMigrate) {
307 var
bundle = document.getElementById(
"brandBundle");
311 var pageTitle = bundle.getString(
"homePageMigrationPageTitle");
312 var pageDesc = bundle.getString(
"homePageMigrationDescription");
313 var mainStr = bundle.getString(
"homePageSingleStartMain");
320 document.getElementById(
"homePageImport").setAttribute(
"label", pageTitle);
321 document.getElementById(
"homePageImportDesc").setAttribute(
"value", pageDesc);
323 this._wiz._adjustWizardHeader();
325 var singleStart = document.getElementById(
"homePageSingleStart");
326 singleStart.setAttribute(
"label", mainStr);
327 singleStart.setAttribute(
"value",
"DEFAULT");
330 switch (this._source) {
333 source =
"sourceNameIE";
336 source =
"sourceNameOpera";
339 source =
"sourceNameDogbert";
342 source =
"sourceNameSafari";
345 source =
"sourceNameSeamonkey";
350 this._migrator.getMigrateData(this._selectedProfile, this._autoMigrate);
352 var oldHomePageURL = this._migrator.sourceHomePageURL;
354 if (oldHomePageURL && source) {
355 var bundle2 = document.getElementById(
"bundle");
356 var appName = bundle2.getString(source);
357 var oldHomePageLabel = bundle.getFormattedString(
"homePageImport",
359 var oldHomePage = document.getElementById(
"oldHomePage");
360 oldHomePage.setAttribute(
"label", oldHomePageLabel);
361 oldHomePage.setAttribute(
"value", oldHomePageURL);
362 oldHomePage.removeAttribute(
"hidden");
370 onHomePageMigrationPageAdvanced:
function ()
374 var radioGroup = document.getElementById(
"homePageRadiogroup");
376 this._newHomePage = radioGroup.selectedItem.value;
381 onMigratingPageShow:
function ()
383 this._wiz.getButton(
"cancel").disabled =
true;
384 this._wiz.canRewind =
false;
385 this._wiz.canAdvance =
false;
388 if (this._autoMigrate)
389 this._itemsFlags = this._migrator.getMigrateData(this._selectedProfile, this._autoMigrate);
393 this._itemsFlags = 32;
395 this._listItems(
"migratingItems");
399 onMigratingMigrate:
function (aOuter)
401 aOuter._migrator.migrate(aOuter._itemsFlags, aOuter._autoMigrate, aOuter._selectedProfile);
404 _listItems:
function (aID)
406 var items = document.getElementById(aID);
407 while (items.hasChildNodes())
408 items.removeChild(items.firstChild);
410 var
bundle = document.getElementById(
"bundle");
411 var
brandBundle = document.getElementById(
"brandBundle");
413 for (var
i = 0;
i < 16; ++
i) {
414 var itemID = (this._itemsFlags >>
i) & 0x1 ? Math.pow(2,
i) : 0;
416 var
label = document.createElement(
"label");
417 label.id = itemID +
"_migrated";
419 label.setAttribute(
"value", bundle.getString(itemID +
"_" +
this._source));
420 items.appendChild(label);
434 case "Migration:Started":
436 case "Migration:ItemBeforeMigrate":
437 var
label = document.getElementById(
aData +
"_migrated");
439 label.setAttribute(
"style",
"font-weight: bold");
441 case "Migration:ItemAfterMigrate":
442 var label = document.getElementById(
aData +
"_migrated");
444 label.removeAttribute(
"style");
446 case "Migration:Ended":
447 if (this._autoMigrate) {
448 if (this._newHomePage) {
451 var
prefSvc = Components.classes[
"@mozilla.org/preferences-service;1"]
452 .getService(Components.interfaces.nsIPrefService);
453 var prefBranch = prefSvc.getBranch(
null);
455 if (this._newHomePage ==
"DEFAULT") {
457 prefBranch.clearUserPref(
"browser.startup.homepage");
462 var
str = Components.classes[
"@mozilla.org/supports-string;1"]
463 .createInstance(Components.interfaces.nsISupportsString);
464 str.data = this._newHomePage;
465 prefBranch.setComplexValue(
"browser.startup.homepage",
466 Components.interfaces.nsISupportsString,
470 var
dirSvc = Components.classes[
"@mozilla.org/file/directory_service;1"]
471 .getService(Components.interfaces.nsIProperties);
472 var prefFile = dirSvc.get(
"ProfDS", Components.interfaces.nsIFile);
473 prefFile.append(
"prefs.js");
474 prefSvc.savePrefFile(prefFile);
481 this._wiz.canAdvance =
true;
487 this._wiz.canAdvance =
true;
488 var nextButton = this._wiz.getButton(
"next");
495 onDonePageShow:
function ()
497 this._wiz.getButton(
"cancel").disabled =
true;
498 this._wiz.canRewind =
false;
499 this._listItems(
"doneItems");
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
this _contentSandbox label
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
const kProfileMigratorContractIDPrefix
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe