Bring migration branch to trunk. This is not turned on yet!

This commit is contained in:
ben%bengoodger.com 2004-02-15 00:54:42 +00:00
Родитель ce04728b4d
Коммит 004a88f079
30 изменённых файлов: 7157 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,47 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is The Browser Profile Migrator.
#
# The Initial Developer of the Original Code is Ben Goodger.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Goodger <ben@bengoodger.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,318 @@
const nsIBPM = Components.interfaces.nsIBrowserProfileMigrator;
function MigrationItem(aID, aKey)
{
this._id = aID;
this._key = aKey;
}
var MigrationWizard = {
_items: [new MigrationItem(nsIBPM.SETTINGS, "settings"),
new MigrationItem(nsIBPM.COOKIES, "cookies"),
new MigrationItem(nsIBPM.HISTORY, "history"),
new MigrationItem(nsIBPM.FORMDATA, "formdata"),
new MigrationItem(nsIBPM.PASSWORDS, "passwords"),
new MigrationItem(nsIBPM.BOOKMARKS, "bookmarks"),
new MigrationItem(nsIBPM.OTHERDATA, "otherdata")],
_dataSources: {
#ifdef XP_WIN
"ie": { _migrate: [nsIBPM.SETTINGS, nsIBPM.COOKIES, nsIBPM.HISTORY, nsIBPM.FORMDATA, nsIBPM.PASSWORDS, nsIBPM.BOOKMARKS],
_import: [0, 1, 2, 3, 4, 5] },
#endif
#ifdef XP_MACOSX
"safari": { _migrate: [],
_import: [] },
"omniweb": { _migrate: [],
_import: [] },
"macie": { _migrate: [],
_import: [] },
#endif
"opera": { _migrate: [nsIBPM.SETTINGS, nsIBPM.COOKIES, nsIBPM.HISTORY, nsIBPM.BOOKMARKS, nsIBPM.OTHERDATA],
_import: [0, 1, 2, 5, 6] },
"dogbert": { _migrate: [nsIBPM.SETTINGS, nsIBPM.COOKIES, nsIBPM.BOOKMARKS],
_import: [1, 5] },
"seamonkey":{ _migrate: [nsIBPM.SETTINGS, nsIBPM.COOKIES, nsIBPM.HISTORY, nsIBPM.PASSWORDS, nsIBPM.BOOKMARKS, nsIBPM.OTHERDATA],
_import: [1, 4, 5] },
},
_source: "",
_itemsFlags: 0,
_selectedIndices: [],
_selectedProfile: null,
_wiz: null,
_migrator: null,
_autoMigrate: false,
init: function ()
{
var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
os.addObserver(this, "Migration:Started", false);
os.addObserver(this, "Migration:ItemBeforeMigrate", false);
os.addObserver(this, "Migration:ItemAfterMigrate", false);
os.addObserver(this, "Migration:Ended", false);
this._wiz = document.documentElement;
if ("arguments" in window) {
this._source = window.arguments[0];
this._migrator = window.arguments[1].QueryInterface(nsIBPM);
this._automigrate = true;
// Advance past the first page
this._wiz.advance();
}
},
uninit: function ()
{
var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
os.removeObserver(this, "Migration:Started");
os.removeObserver(this, "Migration:ItemBeforeMigrate");
os.removeObserver(this, "Migration:ItemAfterMigrate");
os.removeObserver(this, "Migration:Ended");
},
// 1 - Import Source
onImportSourcePageShow: function ()
{
document.documentElement.getButton("back").disabled = true;
var importSourceGroup = document.getElementById("importSourceGroup");
importSourceGroup.selectedItem = document.getElementById(this._source == "" ? "ie" : this._source);
},
onImportSourcePageAdvanced: function ()
{
if (!this._automigrate)
this._source = document.getElementById("importSourceGroup").selectedItem.id;
// Create the migrator for the selected source.
if (!this._migrator) {
var contractID = "@mozilla.org/profile/migrator;1?app=browser&type=" + this._source;
this._migrator = Components.classes[contractID].createInstance(nsIBPM);
}
switch (this._source) {
case "opera":
case "dogbert":
case "seamonkey":
// check for more than one Opera profile
this._wiz.currentPage.next = this._migrator.sourceHasMultipleProfiles ? "selectProfile" : "importItems";
break;
default:
// Don't show the Select Profile page for sources that don't support
// multiple profiles
this._wiz.currentPage.next = "importItems";
break;
}
},
// 2 - [Profile Selection]
onSelectProfilePageShow: function ()
{
if (this._automigrate)
document.documentElement.getButton("back").disabled = true;
var profiles = document.getElementById("profiles");
while (profiles.hasChildNodes())
profiles.removeChild(profiles.firstChild);
var sourceProfiles = this._migrator.sourceProfiles;
var count = sourceProfiles.Count();
for (var i = 0; i < count; ++i) {
var item = document.createElement("radio");
var str = sourceProfiles.QueryElementAt(i, Components.interfaces.nsISupportsString);
item.id = str.data;
item.setAttribute("label", str.data);
profiles.appendChild(item);
}
profiles.selectedItem = this._selectedProfile ? document.getElementById(this._selectedProfile) : profiles.firstChild;
},
onSelectProfilePageRewound: function ()
{
var profiles = document.getElementById("profiles");
this._selectedProfile = profiles.selectedItem.id;
},
onSelectProfilePageAdvanced: function ()
{
var profiles = document.getElementById("profiles");
this._selectedProfile = profiles.selectedItem.id;
// If we're automigrating, don't show the item selection page, just grab everything.
if (this._automigrate) {
this._itemsFlags = nsIBPM.ALL;
this._selectedIndices = this._dataSources[this._source]._migrate;
this._wiz.currentPage.next = "migrating";
}
},
// 3 - ImportItems
onImportItemsPageShow: function ()
{
var dataSources = document.getElementById("dataSources");
while (dataSources.hasChildNodes())
dataSources.removeChild(dataSources.firstChild);
var bundle = document.getElementById("bundle");
var ds = this._dataSources[this._source]._import;
for (var i = 0; i < ds.length; ++i) {
var item = this._items[ds[i]];
var checkbox = document.createElement("checkbox");
checkbox.id = item._id;
checkbox.setAttribute("label", bundle.getString(item._key + "_" + this._source));
dataSources.appendChild(checkbox);
if (!this._itemsFlags || this._itemsFlags & item._id)
checkbox.checked = true;
}
},
onImportItemsPageAdvanced: function ()
{
var dataSources = document.getElementById("dataSources");
var params = 0;
this._selectedIndices = [];
for (var i = 0; i < dataSources.childNodes.length; ++i) {
var checkbox = dataSources.childNodes[i];
if (checkbox.localName == "checkbox") {
if (checkbox.checked) {
params |= parseInt(checkbox.id);
this._selectedIndices.push(parseInt(checkbox.id));
}
}
}
this._itemsFlags = params;
},
onImportItemCommand: function (aEvent)
{
var items = document.getElementById("dataSources");
var checkboxes = items.getElementsByTagName("checkbox");
var oneChecked = false;
for (var i = 0; i < checkboxes.length; ++i)
oneChecked = checkboxes[i].checked;
this._wiz.getButton("next").disabled = !oneChecked;
},
// 4 - Migrating
onMigratingPageShow: function ()
{
this._wiz.getButton("cancel").disabled = true;
this._wiz.getButton("back").disabled = true;
this._wiz.getButton("next").disabled = true;
this._listItems("migratingItems");
setTimeout(this.onMigratingMigrate, 0, this);
},
onMigratingMigrate: function (aOuter)
{
aOuter._migrator.migrate(aOuter._itemsFlags, aOuter._automigrate, aOuter._selectedProfile);
},
_listItems: function (aID)
{
var items = document.getElementById(aID);
while (items.hasChildNodes())
items.removeChild(items.firstChild);
var idToIndex = { "1": 0, "2": 1, "4": 2, "8": 3, "16": 4, "32": 5, "64": 6 };
var bundle = document.getElementById("bundle");
for (var i = 0; i < this._selectedIndices.length; ++i) {
var index = this._selectedIndices[i];
var label = document.createElement("label");
var item = this._items[idToIndex[index.toString()]];
label.id = item._key;
label.setAttribute("value", bundle.getString(item._key + "_" + this._source));
items.appendChild(label);
}
},
observe: function (aSubject, aTopic, aData)
{
var itemToIndex = { "settings": 0, "cookies": 1, "history": 2, "formdata": 3, "passwords": 4, "bookmarks": 5, "otherdata": 6 };
switch (aTopic) {
case "Migration:Started":
dump("*** started\n");
break;
case "Migration:ItemBeforeMigrate":
dump("*** before " + aData + "\n");
var index = itemToIndex[aData];
var item = this._items[index];
var label = document.getElementById(item._key);
if (label)
label.setAttribute("style", "font-weight: bold");
break;
case "Migration:ItemAfterMigrate":
dump("*** after " + aData + "\n");
var index = itemToIndex[aData];
var item = this._items[index];
var label = document.getElementById(item._key);
if (label)
label.removeAttribute("style");
break;
case "Migration:Ended":
dump("*** done\n");
if (this._automigrate) {
// We're done now.
window.close();
}
else {
var nextButton = this._wiz.getButton("next");
nextButton.disabled = false;
nextButton.click();
}
break;
}
},
onDonePageShow: function ()
{
this._wiz.getButton("cancel").disabled = true;
this._wiz.getButton("back").disabled = true;
this._wiz.getButton("finish").disabled = false;
this._listItems("doneItems");
}
};
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is The Browser Profile Migrator.
#
# The Initial Developer of the Original Code is Ben Goodger.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Goodger <ben@bengoodger.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

Просмотреть файл

@ -0,0 +1,105 @@
<?xml version="1.0"?>
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is The Browser Profile Migrator.
#
# The Initial Developer of the Original Code is Ben Goodger.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Goodger <ben@bengoodger.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://browser/locale/migration/migration.dtd" >
<wizard id="migrationWizard"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&migrationWizard.title;"
onload="MigrationWizard.init()"
onunload="MigrationWizard.uninit()"
style="width: 40em;"
buttons="accept,cancel">
<script type="application/x-javascript" src="chrome://browser/content/migration/migration.js"/>
<stringbundle id="bundle" src="chrome://browser/locale/migration/migration.properties"/>
<wizardpage id="importSource" pageid="importSource" next="selectProfile"
label="&importSource.title;"
onpageshow="MigrationWizard.onImportSourcePageShow();"
onpageadvanced="MigrationWizard.onImportSourcePageAdvanced();">
<description>&importFrom.label;</description>
<radiogroup id="importSourceGroup">
<radio id="ie" label="&importFromIE.label;" accesskey="&importFromIE.accesskey;"/>
<radio id="seamonkey" label="&importFromSeamonkey.label;" accesskey="&importFromSeamonkey.accesskey;"/>
<radio id="dogbert" label="&importFromNetscape4.label;" accesskey="&importFromNetscape4.accesskey;"/>
<radio id="opera" label="&importFromOpera.label;" accesskey="&importFromOpera.accesskey;"/>
</radiogroup>
</wizardpage>
<wizardpage id="selectProfile" pageid="selectProfile" label="&selectProfile.title;"
next="importItems"
onpageshow="return MigrationWizard.onSelectProfilePageShow();"
onpagerewound="return MigrationWizard.onSelectProfilePageRewound();"
onpageadvanced="return MigrationWizard.onSelectProfilePageAdvanced();">
<description>&selectProfile.label;</description>
<radiogroup id="profiles" align="left"/>
</wizardpage>
<wizardpage id="importItems" pageid="importItems" label="&importItems.title;"
next="migrating"
onpageshow="return MigrationWizard.onImportItemsPageShow();"
onpagerewound="return MigrationWizard.onImportItemsPageAdvanced();"
onpageadvanced="return MigrationWizard.onImportItemsPageAdvanced();"
oncommand="MigrationWizard.onImportItemCommand();">
<description>&importItems.label;</description>
<vbox id="dataSources" style="overflow: auto; -moz-appearance: listbox" align="left" flex="1"/>
</wizardpage>
<wizardpage id="migrating" pageid="migrating" label="&migrating.title;"
next="done"
onpageshow="MigrationWizard.onMigratingPageShow();">
<description>&migrating.label;</description>
<vbox id="migratingItems" style="overflow: auto;" align="left"/>
</wizardpage>
<wizardpage id="done" pageid="done" label="&done.title;"
onpageshow="MigrationWizard.onDonePageShow();">
<description>&done.label;</description>
<vbox id="doneItems" style="overflow: auto;" align="left"/>
</wizardpage>
</wizard>

Просмотреть файл

@ -0,0 +1,27 @@
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
browser.jar:
* content/browser/migration/migration.xul (content/migration.xul)
* content/browser/migration/migration.js (content/migration.js)
en-US.jar:
locale/en-US/browser/migration/migration.dtd (locale/migration.dtd)
locale/en-US/browser/migration/migration.properties (locale/migration.properties)

Просмотреть файл

@ -0,0 +1,27 @@
<!ENTITY migrationWizard.title "Import Wizard">
<!ENTITY importFrom.label "Import Options, Bookmarks, History, Passwords and other data from:">
<!ENTITY importFromIE.label "Microsoft Internet Explorer">
<!ENTITY importFromIE.accesskey "M">
<!ENTITY importFromSeamonkey.label "Netscape 6, 7 or Mozilla 1.x">
<!ENTITY importFromSeamonkey.accesskey "N">
<!ENTITY importFromNetscape4.label "Netscape 4.x">
<!ENTITY importFromNetscape4.accesskey "4">
<!ENTITY importFromOpera.label "Opera">
<!ENTITY importFromOpera.accesskey "O">
<!ENTITY importSource.title "Import Settings and Data From">
<!ENTITY importItems.title "Items to Import">
<!ENTITY importItems.label "Select which items to import:">
<!ENTITY migrating.title "Importing...">
<!ENTITY migrating.label "The following items are currently being imported...">
<!ENTITY selectProfile.title "Select Profile">
<!ENTITY selectProfile.label "The following profiles are available to import from:">
<!ENTITY done.title "Import Complete">
<!ENTITY done.label "The following items were successfully imported:">

Просмотреть файл

@ -0,0 +1,40 @@
settings_ie=Internet Options
settings_opera=Preferences
settings_dogbert=Preferences
settings_seamonkey=Preferences
cookies_ie=Cookies
cookies_opera=Cookies
cookies_dogbert=Cookies
cookies_seamonkey=Cookies
history_ie=Browsing History
history_opera=Browsing History
history_dogbert=Browsing History
history_seamonkey=Browsing History
formdata_ie=Saved Form History
formdata_opera=Saved Form History
formdata_dogbert=Saved Form History
formdata_seamonkey=Saved Form History
passwords_ie=Saved Passwords
passwords_opera=Saved Passwords
passwords_dogbert=Saved Passwords
passwords_seamonkey=Saved Passwords
bookmarks_ie=Favorites
bookmarks_opera=Bookmarks
bookmarks_dogbert=Bookmarks
bookmarks_seamonkey=Bookmarks
otherdata_ie=Other Data
otherdata_opera=Other Data
otherdata_dogbert=Other Data
otherdata_seamonkey=Other Data
profileName_format=%S %S
importedIEFavsTitle=From Internet Explorer
importedIESearchUrls=Keyword Searches (From Internet Explorer)
importedIESearchUrlTitle=Search on %S
importedDogbertBookmarksTitle=From Netscape 4
importedSeamonkeyBookmarksTitle=From Netscape 6/7/Mozilla
importedOperaHotlistTitle=From Opera
importedOperaSearchUrls=Keyword Searches (From Opera)
importedSearchUrlDesc=Type "%S <search query>" in the Location Bar to perform a search on %S.

Просмотреть файл

@ -0,0 +1,50 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is The Browser Profile Migrator.
#
# The Initial Developer of the Original Code is Ben Goodger.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Goodger <ben@bengoodger.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = migration
XPIDL_MODULE = migration
XPIDLSRCS = nsIBrowserProfileMigrator.idl
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,76 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsISupportsArray;
[scriptable, uuid(6c64bc4a-881f-4fd8-8f19-3b4125dcee50)]
interface nsIBrowserProfileMigrator : nsISupports
{
/**
* profile items to migrate. use with migrate().
*/
const unsigned long ALL = 0x0000;
const unsigned long SETTINGS = 0x0001;
const unsigned long COOKIES = 0x0002;
const unsigned long HISTORY = 0x0004;
const unsigned long FORMDATA = 0x0008;
const unsigned long PASSWORDS = 0x0010;
const unsigned long BOOKMARKS = 0x0020;
const unsigned long OTHERDATA = 0x0040;
/**
* Copy user profile information to the current active profile.
* @param aItems list of data items to migrate. see above for values.
* @param aReplace replace or append current data where applicable.
* @param aProfile profile to migrate from, if there is more than one.
*/
void migrate(in unsigned long aItems, in boolean aReplace, in wstring aProfile);
/**
* Whether or not the import source implementing this interface
* has multiple user profiles configured.
*/
readonly attribute boolean sourceHasMultipleProfiles;
/**
* An enumeration of available profiles. If the import source does
* not support profiles, this attribute is null.
*/
readonly attribute nsISupportsArray sourceProfiles;
};

Просмотреть файл

@ -0,0 +1,94 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is The Browser Profile Migrator.
#
# The Initial Developer of the Original Code is Ben Goodger.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Goodger <ben@bengoodger.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = migration
LIBRARY_NAME = migration_s
REQUIRES = \
xpcom \
xpcom_obsolete \
string \
necko \
history \
browsercomps \
profile \
pref \
rdf \
satchel \
bookmarks \
intl \
unicharutil \
windowwatcher \
dom \
cookie \
$(NULL)
CPPSRCS = nsProfileMigrator.cpp \
nsNetscapeProfileMigratorBase.cpp \
nsDogbertProfileMigrator.cpp \
nsSeamonkeyProfileMigrator.cpp \
nsINIParser.cpp \
nsOperaProfileMigrator.cpp \
$(NULL)
ifeq ($(OS_ARCH),WINNT)
DEFINES += -DPSTOREC_DLL=\"$(WINDIR)\\system32\\pstorec.dll\"
CPPSRCS += nsIEProfileMigrator.cpp \
$(NULL)
endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
CPPSRCS += nsSafariProfileMigrator.cpp \
nsMacIEProfileMigrator.cpp \
nsOmniWebProfileMigrator.cpp \
nsCaminoProfileMigrator.cpp \
$(NULL)
endif
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef browserprofilemigratorutils___h___
#define browserprofilemigratorutils___h___
#define MIGRATION_ITEMBEFOREMIGRATE "Migration:ItemBeforeMigrate"
#define MIGRATION_ITEMAFTERMIGRATE "Migration:ItemAfterMigrate"
#define MIGRATION_STARTED "Migration:Started"
#define MIGRATION_ENDED "Migration:Ended"
#define NOTIFY_OBSERVERS(message, item) \
if (sObserverService) \
sObserverService->NotifyObservers(nsnull, message, item)
#define COPY_DATA(func, replace, itemIndex, itemString) \
if (NS_SUCCEEDED(rv) && (aItems & itemIndex || !aItems)) { \
NOTIFY_OBSERVERS(MIGRATION_ITEMBEFOREMIGRATE, itemString); \
rv = func(replace); \
NOTIFY_OBSERVERS(MIGRATION_ITEMAFTERMIGRATE, itemString); \
}
#include "nsIPrefBranch.h"
#include "nsString.h"
// Proxy utilities shared by the Opera and IE migrators
void ParseOverrideServers(char* aServers, nsIPrefBranch* aBranch);
void SetProxyPref(const nsACString& aHostPort, const char* aPref,
const char* aPortPref, nsIPrefBranch* aPrefs);
#endif

Просмотреть файл

@ -0,0 +1,498 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsAppDirectoryServiceDefs.h"
#include "nsBrowserProfileMigratorUtils.h"
#include "nsCRT.h"
#include "nsDogbertProfileMigrator.h"
#include "nsICookieManager2.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsILineInputStream.h"
#include "nsIObserverService.h"
#include "nsIOutputStream.h"
#include "nsIPrefBranch.h"
#include "nsIPrefLocalizedString.h"
#include "nsIPrefService.h"
#include "nsIProfile.h"
#include "nsIProfileInternal.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsReadableUtils.h"
#include "prprf.h"
#if defined(XP_MAC) || defined(XP_MACOSX)
#define NEED_TO_FIX_4X_COOKIES 1
#define SECONDS_BETWEEN_1900_AND_1970 2208988800UL
#endif /* XP_MAC */
#define PREF_FILE_HEADER_STRING "# Mozilla User Preferences "
#if defined(XP_UNIX) && !defined(XP_MACOSX)
#define PREF_FILE_NAME_IN_4x NS_LITERAL_STRING("preferences.js")
#define COOKIES_FILE_NAME_IN_4x NS_LITERAL_STRING("cookies")
#define BOOKMARKS_FILE_NAME_IN_4x NS_LITERAL_STRING("bookmarks.html")
#define PSM_CERT7_DB NS_LITERAL_STRING("cert7.db")
#define PSM_KEY3_DB NS_LITERAL_STRING("key3.db")
#define PSM_SECMODULE_DB NS_LITERAL_STRING("secmodule.db")
#elif defined(XP_MAC) || defined(XP_MACOSX)
#define PREF_FILE_NAME_IN_4x NS_LITERAL_STRING("Netscape Preferences")
#define COOKIES_FILE_NAME_IN_4x NS_LITERAL_STRING("MagicCookie")
#define BOOKMARKS_FILE_NAME_IN_4x NS_LITERAL_STRING("Bookmarks.html")
#define SECURITY_PATH "Security"
#define PSM_CERT7_DB NS_LITERAL_STRING("Certificates7")
#define PSM_KEY3_DB NS_LITERAL_STRING("Key Database3")
#define PSM_SECMODULE_DB NS_LITERAL_STRING("Security Modules")
#else /* XP_WIN || XP_OS2 */
#define PREF_FILE_NAME_IN_4x NS_LITERAL_STRING("prefs.js")
#define COOKIES_FILE_NAME_IN_4x NS_LITERAL_STRING("cookies.txt")
#define BOOKMARKS_FILE_NAME_IN_4x NS_LITERAL_STRING("bookmark.htm")
#define PSM_CERT7_DB NS_LITERAL_STRING("cert7.db")
#define PSM_KEY3_DB NS_LITERAL_STRING("key3.db")
#define PSM_SECMODULE_DB NS_LITERAL_STRING("secmod.db")
#endif /* XP_UNIX */
#define COOKIES_FILE_NAME_IN_5x NS_LITERAL_STRING("cookies.txt")
#define BOOKMARKS_FILE_NAME_IN_5x NS_LITERAL_STRING("bookmarks.html")
#define PREF_FILE_NAME_IN_5x NS_LITERAL_STRING("prefs.js")
///////////////////////////////////////////////////////////////////////////////
// nsDogbertProfileMigrator
NS_IMPL_ISUPPORTS1(nsDogbertProfileMigrator, nsIBrowserProfileMigrator)
static nsIObserverService* sObserverService = nsnull;
nsDogbertProfileMigrator::nsDogbertProfileMigrator()
{
CallGetService("@mozilla.org/observer-service;1", &sObserverService);
}
nsDogbertProfileMigrator::~nsDogbertProfileMigrator()
{
NS_IF_RELEASE(sObserverService);
}
///////////////////////////////////////////////////////////////////////////////
// nsIBrowserProfileMigrator
NS_IMETHODIMP
nsDogbertProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar* aProfile)
{
nsresult rv = NS_OK;
NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
if (aReplace)
CreateTemplateProfile(aProfile);
else {
nsCOMPtr<nsIProfileInternal> pmi(do_GetService("@mozilla.org/profile/manager;1"));
nsXPIDLString currProfile;
pmi->GetCurrentProfile(getter_Copies(currProfile));
nsCOMPtr<nsIFile> dir;
pmi->GetProfileDir(currProfile.get(), getter_AddRefs(dir));
mTargetProfile = do_QueryInterface(dir);
}
nsCOMPtr<nsIProfileInternal> pmi(do_GetService("@mozilla.org/profile/manager;1"));
pmi->GetOriginalProfileDir(aProfile, getter_AddRefs(mSourceProfile));
COPY_DATA(CopyPreferences, aReplace, nsIBrowserProfileMigrator::SETTINGS, NS_LITERAL_STRING("settings").get());
COPY_DATA(CopyCookies, aReplace, nsIBrowserProfileMigrator::COOKIES, NS_LITERAL_STRING("cookies").get());
COPY_DATA(CopyBookmarks, aReplace, nsIBrowserProfileMigrator::BOOKMARKS, NS_LITERAL_STRING("bookmarks").get());
NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
return rv;
}
NS_IMETHODIMP
nsDogbertProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
{
nsCOMPtr<nsISupportsArray> profiles;
GetSourceProfiles(getter_AddRefs(profiles));
if (profiles) {
PRUint32 count;
profiles->Count(&count);
*aResult = count > 1;
}
else
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsDogbertProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
{
if (!mProfiles) {
nsresult rv = NS_NewISupportsArray(getter_AddRefs(mProfiles));
if (NS_FAILED(rv)) return rv;
// Our profile manager stores information about the set of Dogbert Profiles we have.
nsCOMPtr<nsIProfileInternal> pmi(do_CreateInstance("@mozilla.org/profile/manager;1"));
PRUnichar** profileNames = nsnull;
PRUint32 profileCount = 0;
// Lordy, this API sucketh.
rv = pmi->GetProfileListX(nsIProfileInternal::LIST_FOR_IMPORT, &profileCount, &profileNames);
if (NS_FAILED(rv)) return rv;
for (PRUint32 i = 0; i < profileCount; ++i) {
nsCOMPtr<nsISupportsString> string(do_CreateInstance("@mozilla.org/supports-string;1"));
string->SetData(nsDependentString(profileNames[i]));
mProfiles->AppendElement(string);
}
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(profileCount, profileNames);
}
NS_IF_ADDREF(*aResult = mProfiles);
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsDogbertProfileMigrator
#define F(a) nsDogbertProfileMigrator::a
static
nsDogbertProfileMigrator::PREFTRANSFORM gTransforms[] = {
// Simple Copy Prefs
{ "browser.anchor_color", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "browser.visited_color", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "browser.startup.homepage", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "security.enable_java", 0, F(GetBool), F(SetBool), PR_FALSE, -1 },
{ "network.cookie.cookieBehavior", 0, F(GetInt), F(SetInt), PR_FALSE, -1 },
{ "network.cookie.warnAboutCookies",0, F(GetBool), F(SetBool), PR_FALSE, -1 },
{ "javascript.enabled", 0, F(GetBool), F(SetBool), PR_FALSE, -1 },
{ "network.proxy.type", 0, F(GetInt), F(SetInt), PR_FALSE, -1 },
{ "network.proxy.no_proxies_on", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "network.proxy.autoconfig_url", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "network.proxy.ftp", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "network.proxy.ftp_port", 0, F(GetInt), F(SetInt), PR_FALSE, -1 },
{ "network.proxy.gopher", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "network.proxy.gopher_port", 0, F(GetInt), F(SetInt), PR_FALSE, -1 },
{ "network.proxy.http", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "network.proxy.http_port", 0, F(GetInt), F(SetInt), PR_FALSE, -1 },
{ "network.proxy.ssl", 0, F(GetString), F(SetString), PR_FALSE, -1 },
{ "network.proxy.ssl_port", 0, F(GetInt), F(SetInt), PR_FALSE, -1 },
// Prefs with Different Names
{ "network.hosts.socks_server", "network.proxy.socks", F(GetString), F(SetString), PR_FALSE, -1 },
{ "network.hosts.socks_serverport", "network.proxy.socks_port", F(GetInt), F(SetInt), PR_FALSE, -1 },
{ "browser.background_color", "browser.display.background_color", F(GetString), F(SetString), PR_FALSE, -1 },
{ "browser.foreground_color", "browser.display.foreground_color", F(GetString), F(SetString), PR_FALSE, -1 },
{ "browser.wfe.use_windows_colors", "browser.display.use_system_colors", F(GetBool), F(SetBool), PR_FALSE, -1 },
{ "browser.use_document_colors", "browser.display.use_document_colors",F(GetBool), F(SetBool), PR_FALSE, -1 },
{ "browser.use_document.fonts", "browser.display.use_document_fonts", F(GetInt), F(SetInt), PR_FALSE, -1 },
{ "browser.link_expiration", "browser.history_expire_days", F(GetInt), F(SetInt), PR_FALSE, -1 },
{ "browser.startup.page", "browser.startup.homepage", F(GetHomepage), F(SetWStringFromASCII), PR_FALSE, -1 },
{ "general.always_load_images", "network.image.imageBehavior", F(GetImagePref),F(SetInt), PR_FALSE, -1 },
};
nsresult
nsDogbertProfileMigrator::TransformPreferences(const nsAString& aSourcePrefFileName,
const nsAString& aTargetPrefFileName)
{
PREFTRANSFORM* transform;
PREFTRANSFORM* end = gTransforms + sizeof(gTransforms)/sizeof(PREFTRANSFORM);
// Load the source pref file
nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
psvc->ResetPrefs();
nsCOMPtr<nsIFile> sourcePrefsFile;
mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile));
sourcePrefsFile->Append(aSourcePrefFileName);
psvc->ReadUserPrefs(sourcePrefsFile);
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
for (transform = gTransforms; transform < end; ++transform)
transform->prefGetterFunc(transform, branch);
// Now that we have all the pref data in memory, load the target pref file,
// and write it back out
psvc->ResetPrefs();
for (transform = gTransforms; transform < end; ++transform)
transform->prefSetterFunc(transform, branch);
nsCOMPtr<nsIFile> targetPrefsFile;
mTargetProfile->Clone(getter_AddRefs(targetPrefsFile));
targetPrefsFile->Append(aTargetPrefFileName);
psvc->SavePrefFile(targetPrefsFile);
return NS_OK;
}
nsresult
nsDogbertProfileMigrator::CopyPreferences(PRBool aReplace)
{
nsresult rv = NS_OK;
if (!aReplace)
return rv;
// 1) Copy Preferences
TransformPreferences(PREF_FILE_NAME_IN_4x, PREF_FILE_NAME_IN_5x);
// 2) Copy Certficates
rv |= CopyFile(PSM_CERT7_DB, PSM_CERT7_DB);
rv |= CopyFile(PSM_KEY3_DB, PSM_KEY3_DB);
rv |= CopyFile(PSM_SECMODULE_DB, PSM_SECMODULE_DB);
return rv;
}
nsresult
nsDogbertProfileMigrator::GetHomepage(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
PRInt32 val;
nsresult rv = aBranch->GetIntPref(xform->sourcePrefName, &val);
if (NS_SUCCEEDED(rv) && val == 0) {
xform->stringValue = "about:blank";
xform->prefHasValue = PR_TRUE;
}
return rv;
}
nsresult
nsDogbertProfileMigrator::GetImagePref(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
PRBool loadImages;
nsresult rv = aBranch->GetBoolPref(xform->sourcePrefName, &loadImages);
if (NS_SUCCEEDED(rv)) {
xform->intValue = loadImages ? 0 : 2;
xform->prefHasValue = PR_TRUE;
}
return rv;
}
nsresult
nsDogbertProfileMigrator::CopyCookies(PRBool aReplace)
{
nsresult rv;
if (aReplace) {
#ifdef NEED_TO_FIX_4X_COOKIES
nsresult rv = CopyFile(COOKIES_FILE_NAME_IN_4x, COOKIES_FILE_NAME_IN_5x);
if (NS_FAILED(rv)) return rv;
rv = FixDogbertCookies();
#else
rv = CopyFile(COOKIES_FILE_NAME_IN_4x, COOKIES_FILE_NAME_IN_5x);
#endif
}
else {
nsCOMPtr<nsICookieManager2> cookieManager(do_GetService(NS_COOKIEMANAGER_CONTRACTID));
if (!cookieManager)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFile> dogbertCookiesFile;
mSourceProfile->Clone(getter_AddRefs(dogbertCookiesFile));
dogbertCookiesFile->Append(COOKIES_FILE_NAME_IN_4x);
rv = cookieManager->ReadCookies(dogbertCookiesFile);
}
return rv;
}
#ifdef NEED_TO_FIX_4X_COOKIES
// XXXben need to rewrite this to downconvert buffers properly, right now this is pretty broken.
nsresult
nsDogbertProfileMigrator::FixDogbertCookies()
{
nsCOMPtr<nsIFile> dogbertCookiesFile;
mSourceProfile->Clone(getter_AddRefs(dogbertCookiesFile));
dogbertCookiesFile->Append(COOKIES_FILE_NAME_IN_4x);
nsCOMPtr<nsIInputStream> fileInputStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), dogbertCookiesFile);
if (!fileInputStream) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFile> firebirdCookiesFile;
mTargetProfile->Clone(getter_AddRefs(firebirdCookiesFile));
firebirdCookiesFile->Append(COOKIES_FILE_NAME_IN_5x);
nsCOMPtr<nsIOutputStream> fileOutputStream;
NS_NewLocalFileOutputStream(getter_AddRefs(fileOutputStream), firebirdCookiesFile);
if (!fileOutputStream) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsILineInputStream> lineInputStream(do_QueryInterface(fileInputStream));
nsAutoString buffer, outBuffer;
PRBool moreData = PR_FALSE;
PRUint32 written = 0;
do {
nsresult rv = lineInputStream->ReadLine(buffer, &moreData);
if (NS_FAILED(rv)) return rv;
// skip line if it is a comment or null line
if (buffer.IsEmpty() || buffer.CharAt(0) == '#' ||
buffer.CharAt(0) == nsCRT::CR || buffer.CharAt(0) == nsCRT::LF) {
fileOutputStream->Write((const char*)buffer.get(), buffer.Length(), &written);
continue;
}
// locate expire field, skip line if it does not contain all its fields
int hostIndex, isDomainIndex, pathIndex, xxxIndex, expiresIndex, nameIndex, cookieIndex;
hostIndex = 0;
if ((isDomainIndex = buffer.FindChar('\t', hostIndex)+1) == 0 ||
(pathIndex = buffer.FindChar('\t', isDomainIndex)+1) == 0 ||
(xxxIndex = buffer.FindChar('\t', pathIndex)+1) == 0 ||
(expiresIndex = buffer.FindChar('\t', xxxIndex)+1) == 0 ||
(nameIndex = buffer.FindChar('\t', expiresIndex)+1) == 0 ||
(cookieIndex = buffer.FindChar('\t', nameIndex)+1) == 0 )
continue;
// separate the expires field from the rest of the cookie line
nsAutoString prefix, expiresString, suffix;
buffer.Mid(prefix, hostIndex, expiresIndex-hostIndex-1);
buffer.Mid(expiresString, expiresIndex, nameIndex-expiresIndex-1);
buffer.Mid(suffix, nameIndex, buffer.Length()-nameIndex);
// correct the expires field
char* expiresCString = ToNewCString(expiresString);
unsigned long expires = strtoul(expiresCString, nsnull, 10);
nsCRT::free(expiresCString);
// if the cookie is supposed to expire at the end of the session
// expires == 0. don't adjust those cookies.
if (expires)
expires -= SECONDS_BETWEEN_1900_AND_1970;
char dateString[36];
PR_snprintf(dateString, sizeof(dateString), "%lu", expires);
// generate the output buffer and write it to file
outBuffer = prefix;
outBuffer.Append(PRUnichar('\t'));
outBuffer.AppendWithConversion(dateString);
outBuffer.Append(PRUnichar('\t'));
outBuffer.Append(suffix);
fileOutputStream->Write((const char*)outBuffer.get(), outBuffer.Length(), &written);
}
while (moreData);
}
#endif // NEED_TO_FIX_4X_COOKIES
nsresult
nsDogbertProfileMigrator::CopyBookmarks(PRBool aReplace)
{
// If we're blowing away existing content, just copy the file, don't do fancy importing.
if (aReplace)
return MigrateDogbertBookmarks();
return ImportNetscapeBookmarks(BOOKMARKS_FILE_NAME_IN_4x,
NS_LITERAL_STRING("importedDogbertBookmarksTitle").get());
}
nsresult
nsDogbertProfileMigrator::MigrateDogbertBookmarks()
{
nsresult rv;
// Find out what the personal toolbar folder was called, this is stored in a pref
// in 4.x
nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
psvc->ResetPrefs();
nsCOMPtr<nsIFile> dogbertPrefsFile;
mSourceProfile->Clone(getter_AddRefs(dogbertPrefsFile));
dogbertPrefsFile->Append(PREF_FILE_NAME_IN_4x);
psvc->ReadUserPrefs(dogbertPrefsFile);
nsXPIDLCString toolbarName;
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
rv = branch->GetCharPref("custtoolbar.personal_toolbar_folder", getter_Copies(toolbarName));
// If the pref wasn't set in the user's 4.x preferences, there's no way we can "Fix" the
// file when importing it to set the personal toolbar folder correctly, so don't bother
// with the more involved file correction procedure and just copy the file over.
if (NS_FAILED(rv))
return CopyFile(BOOKMARKS_FILE_NAME_IN_4x, BOOKMARKS_FILE_NAME_IN_5x);
// Now read the 4.x bookmarks file, correcting the Personal Toolbar Folder line
// and writing to the new location.
nsCOMPtr<nsIFile> sourceBookmarksFile;
mSourceProfile->Clone(getter_AddRefs(sourceBookmarksFile));
sourceBookmarksFile->Append(BOOKMARKS_FILE_NAME_IN_4x);
nsCOMPtr<nsIInputStream> fileInputStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), sourceBookmarksFile);
if (!fileInputStream) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFile> targetBookmarksFile;
mTargetProfile->Clone(getter_AddRefs(targetBookmarksFile));
targetBookmarksFile->Append(BOOKMARKS_FILE_NAME_IN_5x);
nsCOMPtr<nsIOutputStream> outputStream;
NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), targetBookmarksFile);
if (!outputStream) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsILineInputStream> lineInputStream(do_QueryInterface(fileInputStream));
nsAutoString sourceBuffer;
nsCAutoString targetBuffer;
PRBool moreData = PR_FALSE;
PRUint32 bytesWritten = 0;
do {
nsresult rv = lineInputStream->ReadLine(sourceBuffer, &moreData);
if (NS_FAILED(rv)) return rv;
if (!moreData)
break;
PRInt32 nameOffset = sourceBuffer.Find(toolbarName);
if (nameOffset >= 0) {
// Found the personal toolbar name on a line, check to make sure it's actually a folder.
NS_NAMED_LITERAL_STRING(folderPrefix, "<DT><H3 ");
PRInt32 folderPrefixOffset = sourceBuffer.Find(folderPrefix);
if (folderPrefixOffset >= 0)
sourceBuffer.Insert(NS_LITERAL_STRING("PERSONAL_TOOLBAR_FOLDER=\"true\" "),
folderPrefixOffset + folderPrefix.Length());
}
targetBuffer.Assign(NS_ConvertUCS2toUTF8(sourceBuffer));
targetBuffer.Append("\r\n");
outputStream->Write(targetBuffer.get(), targetBuffer.Length(), &bytesWritten);
}
while (moreData);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,80 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dogbertprofilemigrator___h___
#define dogbertprofilemigrator___h___
#include "nsIBrowserProfileMigrator.h"
#include "nsILocalFile.h"
#include "nsISupportsArray.h"
#include "nsNetscapeProfileMigratorBase.h"
#include "nsString.h"
class nsIFile;
class nsDogbertProfileMigrator : public nsNetscapeProfileMigratorBase,
public nsIBrowserProfileMigrator
{
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsDogbertProfileMigrator();
virtual ~nsDogbertProfileMigrator();
public:
static nsresult GetHomepage(void* aTransform, nsIPrefBranch* aBranch);
static nsresult GetImagePref(void* aTransform, nsIPrefBranch* aBranch);
protected:
nsresult CopyPreferences(PRBool aReplace);
nsresult TransformPreferences(const nsAString& aSourcePrefFileName,
const nsAString& aTargetPrefFileName);
nsresult CopyCookies(PRBool aReplace);
#ifdef NEED_TO_FIX_4X_COOKIES
nsresult FixDogbertCookies();
#endif
nsresult CopyBookmarks(PRBool aReplace);
nsresult MigrateDogbertBookmarks();
private:
nsCOMPtr<nsISupportsArray> mProfiles;
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,103 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* Private header describing the class to migrate preferences from
Windows Trident to Gecko. This is a virtual class. */
#ifndef ieprofilemigrator___h___
#define ieprofilemigrator___h___
#include <time.h>
#include <windows.h>
#include "nsIBrowserProfileMigrator.h"
#include "nsVoidArray.h"
class nsIFile;
class nsICookieManager2;
class nsIRDFResource;
class nsIBookmarksService;
class nsIPrefBranch;
#import PSTOREC_DLL
using namespace PSTORECLib;
class nsIEProfileMigrator : public nsIBrowserProfileMigrator {
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsIEProfileMigrator();
virtual ~nsIEProfileMigrator();
private:
nsresult CopyPreferences(PRBool aReplace);
nsresult CopyStyleSheet(PRBool aReplace);
nsresult CopyCookies(PRBool aReplace);
nsresult CopyProxyPreferences(nsIPrefBranch* aPrefs);
nsresult CopySecurityPrefs(nsIPrefBranch* aPrefs);
nsresult CopyHistory(PRBool aReplace);
PRBool KeyIsURI(const nsAString& aKey, char** aRealm);
nsresult CopyPasswords(PRBool aReplace);
nsresult GetSignonsListFromPStore(IPStore* aPStore, nsVoidArray* aSignonsFound);
nsresult ResolveAndMigrateSignons(IPStore* aPStore, nsVoidArray* aSignonsFound);
void EnumerateUsernames(const nsAString& aKey, PRUnichar* aData, unsigned long aCount, nsVoidArray* aSignonsFound);
void GetUserNameAndPass(unsigned char* data, unsigned long len, unsigned char** username, unsigned char** pass);
nsresult CopyFormData(PRBool aReplace);
nsresult AddDataToFormHistory(const nsAString& aKey, PRUnichar* data, unsigned long len);
nsresult CopyFavorites(PRBool aReplace);
void ResolveShortcut(const nsAFlatString &aFileName, char** aOutURL);
nsresult ParseFavoritesFolder(nsIFile* aDirectory,
nsIRDFResource* aParentResource,
nsIBookmarksService* aBookmarksService,
const nsAString& aPersonalToolbarFolderName,
PRBool aIsAtRootLevel);
nsresult CopySmartKeywords(nsIRDFResource* aParentFolder);
nsresult CopyCookiesFromBuffer(char *aBuffer, PRUint32 aBufferLength,
nsICookieManager2 *aCookieManager);
void DelimitField(char **aBuffer, const char *aBufferEnd, char **aField);
time_t FileTimeToTimeT(const char *aLowDateIntString,
const char *aHighDateIntString);
void GetUserStyleSheetFile(nsIFile **aUserFile);
};
#endif

Просмотреть файл

@ -0,0 +1,311 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Samir Gehani <sgehani@netscape.com>
*/
#include "nsINIParser.h"
nsINIParser::nsINIParser(char *aFilename)
{
FILE *fd = NULL;
long eofpos = 0;
int rd = 0;
mFileBuf = NULL;
mFileBufSize = 0;
mError = OK;
DUMP("nsINIParser");
/* param check */
if (!aFilename)
{
mError = E_PARAM;
return;
}
/* open the file */
fd = fopen(aFilename, "r");
if (!fd)
goto bail;
/* get file size */
if (fseek(fd, 0, SEEK_END) != 0)
goto bail;
eofpos = ftell(fd);
if (eofpos == 0)
goto bail;
/* malloc an internal buf the size of the file */
mFileBuf = (char *) malloc(eofpos * sizeof(char));
if (!mFileBuf)
{
mError = E_MEM;
return;
}
mFileBufSize = eofpos;
/* read the file in one swoop */
if (fseek(fd, 0, SEEK_SET) != 0)
goto bail;
rd = fread((void *)mFileBuf, 1, eofpos, fd);
if (!rd)
goto bail;
/* close file */
fclose(fd);
return;
bail:
mError = E_READ;
return;
}
nsINIParser::~nsINIParser()
{
DUMP("~nsINIParser");
}
int
nsINIParser::GetString( char *aSection, char *aKey,
char *aValBuf, int *aIOValBufSize )
{
char *secPtr = NULL;
mError = OK;
DUMP("GetString");
/* param check */
if ( !aSection || !aKey || !aValBuf ||
!aIOValBufSize || (*aIOValBufSize <= 0) )
return E_PARAM;
/* find the section if it exists */
mError = FindSection(aSection, &secPtr);
if (mError != OK)
return mError;
/* find the key if it exists in the valid section we found */
mError = FindKey(secPtr, aKey, aValBuf, aIOValBufSize);
return mError;
}
int
nsINIParser::GetStringAlloc( char *aSection, char *aKey,
char **aOutBuf, int *aOutBufSize )
{
char buf[MAX_VAL_SIZE];
int bufsize = MAX_VAL_SIZE;
mError = OK;
DUMP("GetStringAlloc");
mError = GetString(aSection, aKey, buf, &bufsize);
if (mError != OK)
return mError;
*aOutBuf = (char *) malloc(bufsize + 1);
strncpy(*aOutBuf, buf, bufsize);
*(*aOutBuf + bufsize) = 0;
*aOutBufSize = bufsize + 1;
return mError;
}
int
nsINIParser::GetError()
{
DUMP("GetError");
return mError;
}
char *
nsINIParser::ResolveName(char *aINIRoot)
{
char *resolved = NULL;
char *locale = NULL;
struct stat st_exists;
/* param check */
if (!aINIRoot)
return NULL;
locale = setlocale(LC_CTYPE, NULL);
if (!locale)
return NULL;
/* resolved string: "<root>.ini.<locale>\0" */
resolved = (char *) malloc(strlen(aINIRoot) + 5 + strlen(locale) + 1);
if (!resolved)
return NULL;
/* locale specific ini file name */
sprintf(resolved, "%s.ini.%s", aINIRoot, locale);
if (0 == stat(resolved, &st_exists))
return resolved;
/* fallback to general ini file name */
sprintf(resolved, "%s.ini", aINIRoot);
if (0 == stat(resolved, &st_exists))
return resolved;
/* neither existed so error returned */
return NULL;
}
int
nsINIParser::FindSection(char *aSection, char **aOutSecPtr)
{
char *currChar = mFileBuf;
char *nextSec = NULL;
char *secClose = NULL;
char *nextNL = NULL;
mError = E_NO_SEC;
DUMP("FindSection");
// param check
if (!aSection || !aOutSecPtr)
{
mError = E_PARAM;
return mError;
}
while (currChar < (mFileBuf + mFileBufSize))
{
// look for first '['
nextSec = NULL;
nextSec = strchr(currChar, '[');
if (!nextSec)
break;
currChar = nextSec + 1;
// extract section name till first ']'
secClose = NULL; nextNL = NULL;
secClose = strchr(currChar, ']');
nextNL = strchr(currChar, NL);
if ((!nextNL) || (nextNL < secClose))
{
currChar = nextNL;
continue;
}
// if section name matches we succeeded
if (strncmp(aSection, currChar, strlen(aSection)) == 0)
{
*aOutSecPtr = secClose + 1;
mError = OK;
break;
}
}
return mError;
}
int
nsINIParser::FindKey(char *aSecPtr, char *aKey, char *aVal, int *aIOValSize)
{
char *nextNL = NULL;
char *secEnd = NULL;
char *currLine = aSecPtr;
char *nextEq = NULL;
mError = E_NO_KEY;
DUMP("FindKey");
// param check
if (!aSecPtr || !aKey || !aVal || !aIOValSize || (*aIOValSize <= 0))
{
mError = E_PARAM;
return mError;
}
// determine the section end
secEnd = aSecPtr;
find_end:
if (secEnd)
secEnd = strchr(secEnd, '['); // search for next sec start
if (!secEnd)
{
secEnd = strchr(aSecPtr, '\0'); // else search for file end
if (!secEnd)
{
mError = E_SEC_CORRUPT; // else this data is corrupt
return mError;
}
}
// handle start section token ('[') in values for i18n
if (*secEnd == '[' && !(secEnd == aSecPtr || *(secEnd-1) == NL))
{
secEnd++;
goto find_end;
}
while (currLine < secEnd)
{
nextNL = NULL;
nextNL = strchr(currLine, NL);
if (!nextNL)
nextNL = mFileBuf + mFileBufSize;
// ignore commented lines (starting with ;)
if (currLine == strchr(currLine, ';'))
{
currLine = nextNL + 1;
continue;
}
// extract key before '='
nextEq = NULL;
nextEq = strchr(currLine, '=');
if (!nextEq || nextEq > nextNL)
{
currLine = nextNL + 1;
continue;
}
// if key matches we succeeded
if (strncmp(currLine, aKey, strlen(aKey)) == 0)
{
// extract the value and return
if (*aIOValSize < nextNL - nextEq)
{
mError = E_SMALL_BUF;
*aVal = '\0';
*aIOValSize = 0;
return mError;
}
*aIOValSize = nextNL - (nextEq + 1);
strncpy(aVal, (nextEq + 1), *aIOValSize);
*(aVal + *aIOValSize) = 0; // null terminate
mError = OK;
return mError;
}
else
{
currLine = nextNL + 1;
}
}
return mError;
}

Просмотреть файл

@ -0,0 +1,148 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Samir Gehani <sgehani@netscape.com>
*/
#ifndef _NS_INIPARSER_H_
#define _NS_INIPARSER_H_
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <sys/stat.h>
#include <locale.h>
class nsINIParser
{
public:
/**
* nsINIParser
*
* Construct a new INI parser for the file specified.
*
* @param aFilename path to INI file
*/
nsINIParser(char *aFilename);
~nsINIParser();
/**
* GetString
*
* Gets the value of the specified key in the specified section
* of the INI file represented by this instance. The value is stored
* in the supplied buffer. The buffer size is provided as input and
* the actual bytes used by the value is set in the in/out size param.
*
* @param aSection section name
* @param aKey key name
* @param aValBuf user supplied buffer
* @param aIOValBufSize buf size on input; actual buf used on output
*
* @return mError operation success code
*/
int GetString( char *aSection, char *aKey,
char *aValBuf, int *aIOValBufSize );
/**
* GetStringAlloc
*
* Same as GetString() except the buffer is allocated to the exact
* size of the value. Useful when the buffer is allocated everytime
* rather than reusing the same buffer when calling this function
* multiple times.
*
* @param aSection section name
* @param aKey key name
* @param aOutBuf buffer to be allocated
* @param aOutBufSize size of newly allocated buffer
*
* @return mError operation success code
*/
int GetStringAlloc( char *aSection, char *aKey,
char **aOutBuf, int *aOutBufSize );
/**
* GetError
*
* Exposes the last error on this instance. Useful for checking
* the state of the object after construction since the INI file
* is parsed once at object-allocation time.
*
* @return mError last error on ops on this object
*/
int GetError();
/**
* ResolveName
*
* Given a "root" name we append the runtime locale of the
* current system to the <root>.ini. If such a file exists we
* return this as the name else simply return <root>.ini.
*
* NOTE: Returned string is allocated and caller is responsible
* ---- for its deallocation.
*
* @param aINIRoot the "root" of the INI file name
* @return resolved the resolved INI file name
* (NULL if neither exist)
*/
static char *ResolveName(char *aINIRoot);
/*--------------------------------------------------------------------*
* Errors
*--------------------------------------------------------------------*/
enum
{
OK = 0,
E_READ = -701,
E_MEM = -702,
E_PARAM = -703,
E_NO_SEC = -704,
E_NO_KEY = -705,
E_SEC_CORRUPT = -706,
E_SMALL_BUF = -707
};
private:
int FindSection(char *aSection, char **aOutSecPtr);
int FindKey(char *aSecPtr, char *aKey, char *aVal, int *aIOValSize);
char *mFileBuf;
int mFileBufSize;
int mError;
};
#define NL '\n'
#define MAX_VAL_SIZE 512
#if defined(DUMP)
#undef DUMP
#endif
#if defined(DEBUG_sgehani) || defined(DEBUG_druidd) || defined(DEBUG_root)
#define DUMP(_msg) printf("%s %d: %s \n", __FILE__, __LINE__, _msg);
#else
#define DUMP(_msg)
#endif
#endif /*_NS_INIPARSER_H_ */

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsBrowserProfileMigratorUtils.h"
#include "nsMacIEProfileMigrator.h"
#include "nsIObserverService.h"
#include "nsIProfile.h"
#include "nsIProfileInternal.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
///////////////////////////////////////////////////////////////////////////////
// nsMacIEProfileMigrator
NS_IMPL_ISUPPORTS1(nsMacIEProfileMigrator, nsIBrowserProfileMigrator)
static nsIObserverService* sObserverService = nsnull;
nsMacIEProfileMigrator::nsMacIEProfileMigrator()
{
CallGetService("@mozilla.org/observer-service;1", &sObserverService);
}
nsMacIEProfileMigrator::~nsMacIEProfileMigrator()
{
NS_IF_RELEASE(sObserverService);
}
///////////////////////////////////////////////////////////////////////////////
// nsIBrowserProfileMigrator
NS_IMETHODIMP
nsMacIEProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar* aProfile)
{
nsresult rv = NS_OK;
NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
return rv;
}
NS_IMETHODIMP
nsMacIEProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
{
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsMacIEProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
{
*aResult = nsnull;
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsMacIEProfileMigrator

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef macieprofilemigrator___h___
#define maciebprofilemigrator___h___
#include "nsIBrowserProfileMigrator.h"
#include "nsISupportsArray.h"
#include "nsString.h"
class nsMacIEProfileMigrator : public nsIBrowserProfileMigrator
{
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsMacIEProfileMigrator();
virtual ~nsMacIEProfileMigrator();
protected:
private:
};
#endif

Просмотреть файл

@ -0,0 +1,302 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsAppDirectoryServiceDefs.h"
#include "nsCRT.h"
#include "nsIBookmarksService.h"
#include "nsIFile.h"
#include "nsIPrefBranch.h"
#include "nsIPrefLocalizedString.h"
#include "nsIPrefService.h"
#include "nsIProfile.h"
#include "nsIProfileInternal.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsNetscapeProfileMigratorBase.h"
#include "nsReadableUtils.h"
#include "nsXPIDLString.h"
#include "prprf.h"
#if defined(XP_MAC) || defined(XP_MACOSX)
#define NEED_TO_FIX_4X_COOKIES 1
#define SECONDS_BETWEEN_1900_AND_1970 2208988800UL
#endif /* XP_MAC */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
///////////////////////////////////////////////////////////////////////////////
// nsNetscapeProfileMigratorBase
nsNetscapeProfileMigratorBase::nsNetscapeProfileMigratorBase()
{
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(kStringBundleServiceCID));
bundleService->CreateBundle(MIGRATION_BUNDLE, getter_AddRefs(mBundle));
}
nsresult
nsNetscapeProfileMigratorBase::CreateTemplateProfile(const PRUnichar* aSuggestedName)
{
nsCOMPtr<nsIFile> profilesDir;
NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, getter_AddRefs(profilesDir));
nsXPIDLString profileName;
GetUniqueProfileName(profilesDir, aSuggestedName, getter_Copies(profileName));
nsAutoString profilesDirPath;
profilesDir->GetPath(profilesDirPath);
nsCOMPtr<nsIProfile> pm(do_GetService("@mozilla.org/profile/manager;1"));
pm->CreateNewProfile(profileName.get(), profilesDirPath.get(), nsnull, PR_TRUE);
nsCOMPtr<nsIProfileInternal> pmi(do_QueryInterface(pm));
nsCOMPtr<nsIFile> target;
pmi->GetProfileDir(profileName.get(), getter_AddRefs(target));
mTargetProfile = do_QueryInterface(target);
return NS_OK;
}
void
nsNetscapeProfileMigratorBase::GetUniqueProfileName(nsIFile* aProfilesDir,
const PRUnichar* aSuggestedName,
PRUnichar** aUniqueName)
{
PRBool exists = PR_FALSE;
PRUint32 count = 1;
nsXPIDLString profileName;
nsAutoString profileNameStr(aSuggestedName);
nsCOMPtr<nsIFile> newProfileDir;
aProfilesDir->Clone(getter_AddRefs(newProfileDir));
newProfileDir->Append(profileNameStr);
newProfileDir->Exists(&exists);
while (exists) {
nsAutoString countString;
countString.AppendInt(count);
const PRUnichar* strings[2] = { aSuggestedName, countString.get() };
mBundle->FormatStringFromName(NS_LITERAL_STRING("profileName_format").get(), strings, 2, getter_Copies(profileName));
nsCOMPtr<nsIFile> newProfileDir;
aProfilesDir->Clone(getter_AddRefs(newProfileDir));
newProfileDir->Append(profileName);
newProfileDir->Exists(&exists);
profileNameStr = profileName.get();
++count;
}
*aUniqueName = ToNewUnicode(profileNameStr);
}
#define GETPREF(xform, method, value) \
nsresult rv = aBranch->method(xform->sourcePrefName, value); \
if (NS_SUCCEEDED(rv)) \
xform->prefHasValue = PR_TRUE; \
return rv;
#define SETPREF(xform, method, value) \
if (xform->prefHasValue) { \
return aBranch->method(xform->targetPrefName ? xform->targetPrefName : xform->sourcePrefName, value); \
} \
return NS_OK;
nsresult
nsNetscapeProfileMigratorBase::GetString(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
GETPREF(xform, GetCharPref, &xform->stringValue);
}
nsresult
nsNetscapeProfileMigratorBase::SetString(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
SETPREF(xform, SetCharPref, xform->stringValue);
}
nsresult
nsNetscapeProfileMigratorBase::GetWString(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
nsCOMPtr<nsIPrefLocalizedString> prefValue;
nsresult rv = aBranch->GetComplexValue(xform->sourcePrefName,
NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(prefValue));
if (NS_SUCCEEDED(rv) && prefValue) {
nsXPIDLString data;
prefValue->ToString(getter_Copies(data));
xform->stringValue = ToNewCString(NS_ConvertUCS2toUTF8(data));
xform->prefHasValue = PR_TRUE;
}
return rv;
}
nsresult
nsNetscapeProfileMigratorBase::SetWStringFromASCII(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
if (xform->prefHasValue) {
nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
nsAutoString data; data.AssignWithConversion(xform->stringValue);
pls->SetData(data.get());
return aBranch->SetComplexValue(xform->targetPrefName ? xform->targetPrefName : xform->sourcePrefName, NS_GET_IID(nsIPrefLocalizedString), pls);
}
return NS_OK;
}
nsresult
nsNetscapeProfileMigratorBase::SetWString(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
if (xform->prefHasValue) {
nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
nsAutoString data = NS_ConvertUTF8toUCS2(xform->stringValue);
pls->SetData(data.get());
return aBranch->SetComplexValue(xform->targetPrefName ? xform->targetPrefName : xform->sourcePrefName, NS_GET_IID(nsIPrefLocalizedString), pls);
}
return NS_OK;
}
nsresult
nsNetscapeProfileMigratorBase::GetBool(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
GETPREF(xform, GetBoolPref, &xform->boolValue);
}
nsresult
nsNetscapeProfileMigratorBase::SetBool(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
SETPREF(xform, SetBoolPref, xform->boolValue);
}
nsresult
nsNetscapeProfileMigratorBase::GetInt(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
GETPREF(xform, GetIntPref, &xform->intValue);
}
nsresult
nsNetscapeProfileMigratorBase::SetInt(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
SETPREF(xform, SetIntPref, xform->intValue);
}
nsresult
nsNetscapeProfileMigratorBase::CopyFile(const nsAString& aSourceFileName, const nsAString& aTargetFileName)
{
nsCOMPtr<nsIFile> sourceFile;
mSourceProfile->Clone(getter_AddRefs(sourceFile));
sourceFile->Append(aSourceFileName);
PRBool exists = PR_FALSE;
sourceFile->Exists(&exists);
if (!exists)
return NS_OK;
nsCOMPtr<nsIFile> targetFile;
mTargetProfile->Clone(getter_AddRefs(targetFile));
targetFile->Append(aTargetFileName);
targetFile->Exists(&exists);
if (exists)
targetFile->Remove(PR_FALSE);
return sourceFile->CopyTo(mTargetProfile, aTargetFileName);
}
nsresult
nsNetscapeProfileMigratorBase::ImportNetscapeBookmarks(const nsAString& aBookmarksFileName,
const PRUnichar* aImportFolderTitleKey)
{
nsCOMPtr<nsIFile> bookmarksFile;
mSourceProfile->Clone(getter_AddRefs(bookmarksFile));
bookmarksFile->Append(aBookmarksFileName);
nsCOMPtr<nsIBookmarksService> bms(do_GetService("@mozilla.org/browser/bookmarks-service;1"));
nsCOMPtr<nsISupportsArray> params;
NS_NewISupportsArray(getter_AddRefs(params));
nsCOMPtr<nsIRDFService> rdfs(do_GetService("@mozilla.org/rdf/rdf-service;1"));
nsCOMPtr<nsIRDFResource> prop;
rdfs->GetResource(NS_LITERAL_CSTRING("http://home.netscape.com/NC-rdf#URL"),
getter_AddRefs(prop));
nsCOMPtr<nsIRDFLiteral> url;
nsAutoString path;
bookmarksFile->GetPath(path);
rdfs->GetLiteral(path.get(), getter_AddRefs(url));
params->AppendElement(prop);
params->AppendElement(url);
nsCOMPtr<nsIRDFResource> importCmd;
rdfs->GetResource(NS_LITERAL_CSTRING("http://home.netscape.com/NC-rdf#command?cmd=import"),
getter_AddRefs(importCmd));
nsCOMPtr<nsIRDFResource> root;
rdfs->GetResource(NS_LITERAL_CSTRING("NC:BookmarksRoot"), getter_AddRefs(root));
nsXPIDLString importedDogbertBookmarksTitle;
mBundle->GetStringFromName(aImportFolderTitleKey, getter_Copies(importedDogbertBookmarksTitle));
nsCOMPtr<nsIRDFResource> folder;
bms->CreateFolderInContainer(importedDogbertBookmarksTitle.get(), root, -1, getter_AddRefs(folder));
nsCOMPtr<nsIRDFResource> folderProp;
rdfs->GetResource(NS_LITERAL_CSTRING("http://home.netscape.com/NC-rdf#Folder"),
getter_AddRefs(folderProp));
params->AppendElement(folderProp);
params->AppendElement(folder);
nsCOMPtr<nsISupportsArray> sources;
NS_NewISupportsArray(getter_AddRefs(sources));
sources->AppendElement(folder);
nsCOMPtr<nsIRDFDataSource> ds(do_QueryInterface(bms));
return ds->DoCommand(sources, importCmd, params);
}

Просмотреть файл

@ -0,0 +1,96 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef netscapeprofilemigratorbase___h___
#define netscapeprofilemigratorbase___h___
#include "nsILocalFile.h"
#include "nsIStringBundle.h"
#include "nsString.h"
class nsIFile;
class nsIPrefBranch;
class nsNetscapeProfileMigratorBase
{
public:
nsNetscapeProfileMigratorBase();
virtual ~nsNetscapeProfileMigratorBase() { };
public:
typedef nsresult(*prefConverter)(void*, nsIPrefBranch*);
typedef struct {
char* sourcePrefName;
char* targetPrefName;
prefConverter prefGetterFunc;
prefConverter prefSetterFunc;
PRBool prefHasValue;
union {
PRInt32 intValue;
PRBool boolValue;
char* stringValue;
};
} PREFTRANSFORM;
static nsresult GetString(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetString(void* aTransform, nsIPrefBranch* aBranch);
static nsresult GetWString(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetWString(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetWStringFromASCII(void* aTransform, nsIPrefBranch* aBranch);
static nsresult GetBool(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetBool(void* aTransform, nsIPrefBranch* aBranch);
static nsresult GetInt(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetInt(void* aTransform, nsIPrefBranch* aBranch);
protected:
nsresult CreateTemplateProfile(const PRUnichar* aSuggestedName);
void GetUniqueProfileName(nsIFile* aProfilesDir, const PRUnichar* aSuggestedName, PRUnichar** aUniqueName);
nsresult CopyFile(const nsAString& aSourceFileName, const nsAString& aTargetFileName);
nsresult ImportNetscapeBookmarks(const nsAString& aBookmarksFileName,
const PRUnichar* aImportFolderTitleKey);
protected:
nsCOMPtr<nsILocalFile> mSourceProfile;
nsCOMPtr<nsILocalFile> mTargetProfile;
nsCOMPtr<nsIStringBundle> mBundle;
};
#endif

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsBrowserProfileMigratorUtils.h"
#include "nsOmniWebProfileMigrator.h"
#include "nsIObserverService.h"
#include "nsIProfile.h"
#include "nsIProfileInternal.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
///////////////////////////////////////////////////////////////////////////////
// nsOmniWebProfileMigrator
NS_IMPL_ISUPPORTS1(nsOmniWebProfileMigrator, nsIBrowserProfileMigrator)
static nsIObserverService* sObserverService = nsnull;
nsOmniWebProfileMigrator::nsOmniWebProfileMigrator()
{
CallGetService("@mozilla.org/observer-service;1", &sObserverService);
}
nsOmniWebProfileMigrator::~nsOmniWebProfileMigrator()
{
NS_IF_RELEASE(sObserverService);
}
///////////////////////////////////////////////////////////////////////////////
// nsIBrowserProfileMigrator
NS_IMETHODIMP
nsOmniWebProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar* aProfile)
{
nsresult rv = NS_OK;
NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
return rv;
}
NS_IMETHODIMP
nsOmniWebProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
{
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsOmniWebProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
{
*aResult = nsnull;
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsOmniWebProfileMigrator

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef omniwebprofilemigrator___h___
#define omniwebprofilemigrator___h___
#include "nsIBrowserProfileMigrator.h"
#include "nsISupportsArray.h"
#include "nsString.h"
class nsOmniWebProfileMigrator : public nsIBrowserProfileMigrator
{
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsOmniWebProfileMigrator();
virtual ~nsOmniWebProfileMigrator();
protected:
private:
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,194 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef operaprofilemigrator___h___
#define operaprofilemigrator___h___
#include "nsCOMPtr.h"
#include "nsIBinaryInputStream.h"
#include "nsIBrowserProfileMigrator.h"
#include "nsISupportsArray.h"
#include "nsString.h"
#include "nsVoidArray.h"
class nsICookieManager2;
class nsILineInputStream;
class nsILocalFile;
class nsINIParser;
class nsIPermissionManager;
class nsIPrefBranch;
class nsOperaProfileMigrator : public nsIBrowserProfileMigrator
{
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsOperaProfileMigrator();
virtual ~nsOperaProfileMigrator();
public:
typedef enum { STRING, INT, BOOL, COLOR } PrefType;
typedef nsresult(*prefConverter)(void*, nsIPrefBranch*);
typedef struct {
char* sectionName;
char* keyName;
PrefType type;
char* targetPrefName;
prefConverter prefSetterFunc;
PRBool prefHasValue;
union {
PRInt32 intValue;
PRBool boolValue;
char* stringValue;
};
} PREFTRANSFORM;
static nsresult SetFile(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetCookieBehavior(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetImageBehavior(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetBool(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetWString(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetInt(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetString(void* aTransform, nsIPrefBranch* aBranch);
protected:
nsresult CopyPreferences(PRBool aReplace);
nsresult ParseColor(nsINIParser* aParser, char* aSectionName, char** aResult);
nsresult CopyUserContentSheet(nsINIParser* aParser);
nsresult CopyProxySettings(nsINIParser* aParser, nsIPrefBranch* aBranch);
nsresult GetInteger(nsINIParser* aParser, char* aSectionName,
char* aKeyName, PRInt32* aResult);
nsresult CopyCookies(PRBool aReplace);
nsresult CopyHistory(PRBool aReplace);
nsresult CopyBookmarks(PRBool aReplace);
void ClearToolbarFolder(nsIBookmarksService* aBookmarksService, nsIRDFResource* aToolbarFolder);
nsresult ParseBookmarksFolder(nsILineInputStream* aStream,
nsIRDFResource* aFolder,
nsIRDFResource* aToolbar,
nsIBookmarksService* aBMS);
nsresult CopySmartKeywords(nsIBookmarksService* aBMS,
nsIStringBundle* aBundle,
nsIRDFResource* aParentFolder);
void GetOperaProfile(const PRUnichar* aProfile, nsILocalFile** aFile);
private:
nsCOMPtr<nsILocalFile> mOperaProfile;
nsCOMPtr<nsISupportsArray> mProfiles;
};
class nsOperaCookieMigrator
{
public:
nsOperaCookieMigrator(nsIInputStream* aSourceStream);
virtual ~nsOperaCookieMigrator() { };
nsresult Migrate();
typedef enum { BEGIN_DOMAIN_SEGMENT = 0x01,
DOMAIN_COMPONENT = 0x1E,
END_DOMAIN_SEGMENT = 0x84 | 0x80, // 0x04 | (1 << 8)
BEGIN_PATH_SEGMENT = 0x02,
PATH_COMPONENT = 0x1D,
END_PATH_SEGMENT = 0x05 | 0x80, // 0x05 | (1 << 8)
FILTERING_INFO = 0x1F,
PATH_HANDLING_INFO = 0x21,
THIRD_PARTY_HANDLING_INFO = 0x25,
BEGIN_COOKIE_SEGMENT = 0x03,
COOKIE_ID = 0x10,
COOKIE_DATA = 0x11,
COOKIE_EXPIRY = 0x12,
COOKIE_LASTUSED = 0x13,
COOKIE_COMMENT = 0x14,
COOKIE_COMMENT_URL = 0x15,
COOKIE_V1_DOMAIN = 0x16,
COOKIE_V1_PATH = 0x17,
COOKIE_V1_PORT_LIMITATIONS = 0x18,
COOKIE_SECURE = 0x19 | 0x80,
COOKIE_VERSION = 0x1A,
COOKIE_OTHERFLAG_1 = 0x1B | 0x80,
COOKIE_OTHERFLAG_2 = 0x1C | 0x80,
COOKIE_OTHERFLAG_3 = 0x20 | 0x80,
COOKIE_OTHERFLAG_4 = 0x22 | 0x80,
COOKIE_OTHERFLAG_5 = 0x23 | 0x80,
COOKIE_OTHERFLAG_6 = 0x24 | 0x80
} TAG;
protected:
nsOperaCookieMigrator() { };
nsresult ReadHeader();
void SynthesizePath(char** aResult);
void SynthesizeDomain(char** aResult);
nsresult AddCookieOverride(nsIPermissionManager* aManager);
nsresult AddCookie(nsICookieManager2* aManager);
private:
nsCOMPtr<nsIBinaryInputStream> mStream;
nsVoidArray mDomainStack;
nsVoidArray mPathStack;
typedef struct {
nsCString id;
nsCString data;
PRInt32 expiryTime;
PRBool isSecure;
} COOKIE;
COOKIE mCurrCookie;
PRUint8 mCurrHandlingInfo;
PRUint32 mAppVersion;
PRUint32 mFileVersion;
PRUint16 mTagTypeLength;
PRUint16 mPayloadTypeLength;
PRBool mCookieOpen;
};
#endif

Просмотреть файл

@ -0,0 +1,251 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsBrowserCompsCID.h"
#include "nsIBookmarksService.h"
#include "nsIBrowserProfileMigrator.h"
#include "nsIComponentManager.h"
#include "nsIDOMWindowInternal.h"
#include "nsIObserverService.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsIWindowWatcher.h"
#include "nsProfileMigrator.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#ifdef XP_WIN
#include <windows.h>
#endif
///////////////////////////////////////////////////////////////////////////////
// nsIProfileMigrator
#define MIGRATION_WIZARD_FE_URL "chrome://browser/content/migration/migration.xul"
#define MIGRATION_WIZARD_FE_FEATURES "chrome,dialog,modal,centerscreen"
NS_IMETHODIMP
nsProfileMigrator::Migrate()
{
PRBool needsActiveProfile = PR_TRUE;
GetDefaultBrowserMigratorKey(getter_AddRefs(mMigrator),
getter_AddRefs(mSourceKey),
&needsActiveProfile);
nsresult rv = NS_OK;
if (!needsActiveProfile)
rv = OpenMigrationWizard();
else {
nsCOMPtr<nsIObserverService> obs(do_GetService("@mozilla.org/observer-service;1"));
rv = obs->AddObserver(this, "browser-window-before-show", PR_FALSE);
}
return rv;
}
///////////////////////////////////////////////////////////////////////////////
// nsIObserver
NS_IMETHODIMP
nsProfileMigrator::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData)
{
if (nsCRT::strcmp(aTopic, "browser-window-before-show") == 0) {
// Remove ourselves so we only run the migration wizard once.
nsCOMPtr<nsIObserverService> obs(do_GetService("@mozilla.org/observer-service;1"));
obs->RemoveObserver(this, "browser-window-before-show");
// Spin up Bookmarks
nsCOMPtr<nsIBookmarksService> bms(do_GetService("@mozilla.org/browser/bookmarks-service;1"));
if (bms) {
PRBool loaded;
bms->ReadBookmarks(&loaded);
}
return OpenMigrationWizard();
}
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsProfileMigrator
NS_IMPL_ISUPPORTS2(nsProfileMigrator, nsIProfileMigrator, nsIObserver)
nsresult
nsProfileMigrator::OpenMigrationWizard()
{
if (mSourceKey && mMigrator) {
// By opening the Migration FE with a supplied bpm, it will automatically
// migrate from it.
nsCOMPtr<nsIWindowWatcher> ww(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
nsCOMPtr<nsISupportsArray> params;
NS_NewISupportsArray(getter_AddRefs(params));
params->AppendElement(mSourceKey);
params->AppendElement(mMigrator);
nsCOMPtr<nsIDOMWindow> migrateWizard;
return ww->OpenWindow(nsnull,
MIGRATION_WIZARD_FE_URL,
"_blank",
MIGRATION_WIZARD_FE_FEATURES,
params,
getter_AddRefs(migrateWizard));
}
return NS_OK;
}
#ifdef XP_WIN
typedef struct {
WORD wLanguage;
WORD wCodePage;
} LANGANDCODEPAGE;
#define INTERNAL_NAME_FIREBIRD "Firebird"
#define INTERNAL_NAME_IEXPLORE "iexplore"
#define INTERNAL_NAME_SEAMONKEY "apprunner"
#define INTERNAL_NAME_DOGBERT "NETSCAPE"
#define INTERNAL_NAME_OPERA "Opera"
#endif
nsresult
nsProfileMigrator::GetDefaultBrowserMigratorKey(nsIBrowserProfileMigrator** aMigrator,
nsISupportsString** aKey,
PRBool* aNeedsActiveProfile)
{
*aMigrator = nsnull;
*aKey = nsnull;
#ifdef XP_WIN
HKEY hkey;
const char* kCommandKey = "SOFTWARE\\Classes\\HTTP\\shell\\open\\command";
if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, kCommandKey, 0, KEY_READ, &hkey) == ERROR_SUCCESS) {
DWORD type;
DWORD length = MAX_PATH;
unsigned char value[MAX_PATH];
if (::RegQueryValueEx(hkey, NULL, 0, &type, value, &length) == ERROR_SUCCESS) {
nsCAutoString str; str.Assign((char*)value);
PRInt32 lastIndex = str.Find(".exe", PR_TRUE);
nsCAutoString filePath;
if (str.CharAt(1) == ':')
filePath = Substring(str, 0, lastIndex + 4);
else
filePath = Substring(str, 1, lastIndex + 3);
char* strCpy = ToNewCString(filePath);
// We want to find out what the default browser is but the path in and of itself
// isn't enough. Why? Because sometimes on Windows paths get truncated like so:
// C:\PROGRA~1\MOZILL~2\MOZILL~1.EXE
// How do we know what product that is? Mozilla or Mozilla Firebird? etc. Mozilla's
// file objects do nothing to 'normalize' the path so we need to attain an actual
// product descriptor from the file somehow, and in this case it means getting
// the "InternalName" field of the file's VERSIONINFO resource.
//
// In the file's resource segment there is a VERSIONINFO section that is laid
// out like this:
//
// VERSIONINFO
// StringFileInfo
// <TranslationID>
// InternalName "iexplore"
// VarFileInfo
// Translation <TranslationID>
//
// By Querying the VERSIONINFO section for its Tranlations, we can find out where
// the InternalName lives. (A file can have more than one translation of its
// VERSIONINFO segment, but we just assume the first one).
DWORD dummy;
DWORD size = ::GetFileVersionInfoSize(strCpy, &dummy);
if (size) {
void* ver = malloc(size);
memset(ver, 0, size);
if (::GetFileVersionInfo(strCpy, 0, size, ver)) {
LANGANDCODEPAGE* translate;
UINT pageCount;
::VerQueryValue(ver, TEXT("\\VarFileInfo\\Translation"), (void**)&translate, &pageCount);
if (pageCount > 0) {
TCHAR subBlock[MAX_PATH];
wsprintf(subBlock, TEXT("\\StringFileInfo\\%04x%04x\\InternalName"), translate[0].wLanguage, translate[0].wCodePage);
LPVOID internalName = NULL;
UINT size;
::VerQueryValue(ver, subBlock, (void**)&internalName, &size);
nsCOMPtr<nsISupportsString> key(do_CreateInstance("@mozilla.org/supports-string;1"));
nsCOMPtr<nsIBrowserProfileMigrator> bpm;
if (!nsCRT::strcasecmp((char*)internalName, INTERNAL_NAME_IEXPLORE)) {
*aNeedsActiveProfile = PR_TRUE;
key->SetData(NS_LITERAL_STRING("ie"));
bpm = do_CreateInstance(NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX "ie");
}
else if (!nsCRT::strcasecmp((char*)internalName, INTERNAL_NAME_SEAMONKEY)) {
*aNeedsActiveProfile = PR_FALSE;
key->SetData(NS_LITERAL_STRING("seamonkey"));
bpm = do_CreateInstance(NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX "seamonkey");
}
else if (!nsCRT::strcasecmp((char*)internalName, INTERNAL_NAME_DOGBERT)) {
*aNeedsActiveProfile = PR_FALSE;
key->SetData(NS_LITERAL_STRING("dogbert"));
bpm = do_CreateInstance(NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX "dogbert");
}
else if (!nsCRT::strcasecmp((char*)internalName, INTERNAL_NAME_FIREBIRD)) {
*aNeedsActiveProfile = PR_TRUE;
key->SetData(NS_LITERAL_STRING("ie"));
bpm = do_CreateInstance(NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX "ie");
}
else if (!nsCRT::strcasecmp((char*)internalName, INTERNAL_NAME_OPERA)) {
*aNeedsActiveProfile = PR_TRUE;
key->SetData(NS_LITERAL_STRING("opera"));
bpm = do_CreateInstance(NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX "opera");
}
NS_IF_ADDREF(*aKey = key);
NS_IF_ADDREF(*aMigrator = bpm);
}
}
}
}
}
#endif
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef profilemigrator___h___
#define profilemigrator___h___
#include "nsIBrowserProfileMigrator.h"
#include "nsIObserver.h"
#include "nsIProfileMigrator.h"
#include "nsISupportsPrimitives.h"
class nsProfileMigrator : public nsIProfileMigrator,
public nsIObserver
{
public:
NS_DECL_NSIOBSERVER
NS_DECL_NSIPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsProfileMigrator() { };
virtual ~nsProfileMigrator() { };
protected:
nsresult OpenMigrationWizard();
nsresult GetDefaultBrowserMigratorKey(nsIBrowserProfileMigrator** aMigrator,
nsISupportsString** aKey,
PRBool* aNeedsActiveProfile);
private:
nsCOMPtr<nsIBrowserProfileMigrator> mMigrator;
nsCOMPtr<nsISupportsString> mSourceKey;
};
#endif

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsBrowserProfileMigratorUtils.h"
#include "nsSafariProfileMigrator.h"
#include "nsIObserverService.h"
#include "nsIProfile.h"
#include "nsIProfileInternal.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
///////////////////////////////////////////////////////////////////////////////
// nsSafariProfileMigrator
NS_IMPL_ISUPPORTS1(nsSafariProfileMigrator, nsIBrowserProfileMigrator)
static nsIObserverService* sObserverService = nsnull;
nsSafariProfileMigrator::nsSafariProfileMigrator()
{
CallGetService("@mozilla.org/observer-service;1", &sObserverService);
}
nsSafariProfileMigrator::~nsSafariProfileMigrator()
{
NS_IF_RELEASE(sObserverService);
}
///////////////////////////////////////////////////////////////////////////////
// nsIBrowserProfileMigrator
NS_IMETHODIMP
nsSafariProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar* aProfile)
{
nsresult rv = NS_OK;
NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
return rv;
}
NS_IMETHODIMP
nsSafariProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
{
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSafariProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
{
*aResult = nsnull;
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsSafariProfileMigrator

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef safariprofilemigrator___h___
#define safariprofilemigrator___h___
#include "nsIBrowserProfileMigrator.h"
#include "nsISupportsArray.h"
#include "nsString.h"
class nsSafariProfileMigrator : public nsIBrowserProfileMigrator
{
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsSafariProfileMigrator();
virtual ~nsSafariProfileMigrator();
protected:
private:
};
#endif

Просмотреть файл

@ -0,0 +1,687 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsBrowserProfileMigratorUtils.h"
#include "nsCRT.h"
#include "nsDirectoryServiceDefs.h"
#include "nsICookieManager2.h"
#include "nsIObserverService.h"
#include "nsIPasswordManagerInternal.h"
#include "nsIPrefLocalizedString.h"
#include "nsIPrefService.h"
#include "nsIProfile.h"
#include "nsIProfileInternal.h"
#include "nsIRegistry.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsIURL.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsSeamonkeyProfileMigrator.h"
#include "nsVoidArray.h"
///////////////////////////////////////////////////////////////////////////////
// nsSeamonkeyProfileMigrator
#define FILE_NAME_BOOKMARKS NS_LITERAL_STRING("bookmarks.html")
#define FILE_NAME_COOKIES NS_LITERAL_STRING("cookies.txt")
#define FILE_NAME_CERT8DB NS_LITERAL_STRING("cert8.db")
#define FILE_NAME_KEY3DB NS_LITERAL_STRING("key3.db")
#define FILE_NAME_SECMODDB NS_LITERAL_STRING("secmod.db")
#define FILE_NAME_HISTORY NS_LITERAL_STRING("history.dat")
#define FILE_NAME_MIMETYPES NS_LITERAL_STRING("mimeTypes.rdf")
#define FILE_NAME_DOWNLOADS NS_LITERAL_STRING("downloads.rdf")
#define FILE_NAME_PREFS NS_LITERAL_STRING("prefs.js")
#define FILE_NAME_SEARCH NS_LITERAL_STRING("search.rdf")
#define FILE_NAME_USERCONTENT NS_LITERAL_STRING("userContent.css")
#define DIR_NAME_CHROME NS_LITERAL_STRING("chrome")
NS_IMPL_ISUPPORTS1(nsSeamonkeyProfileMigrator, nsIBrowserProfileMigrator)
static nsIObserverService* sObserverService = nsnull;
nsSeamonkeyProfileMigrator::nsSeamonkeyProfileMigrator()
{
CallGetService("@mozilla.org/observer-service;1", &sObserverService);
}
nsSeamonkeyProfileMigrator::~nsSeamonkeyProfileMigrator()
{
NS_IF_RELEASE(sObserverService);
}
///////////////////////////////////////////////////////////////////////////////
// nsIBrowserProfileMigrator
NS_IMETHODIMP
nsSeamonkeyProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar* aProfile)
{
nsresult rv = NS_OK;
NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
if (aReplace)
CreateTemplateProfile(aProfile);
else {
nsCOMPtr<nsIProfileInternal> pmi(do_GetService("@mozilla.org/profile/manager;1"));
nsXPIDLString currProfile;
pmi->GetCurrentProfile(getter_Copies(currProfile));
nsCOMPtr<nsIFile> dir;
pmi->GetProfileDir(currProfile.get(), getter_AddRefs(dir));
mTargetProfile = do_QueryInterface(dir);
}
GetSourceProfile(aProfile);
COPY_DATA(CopyPreferences, aReplace, nsIBrowserProfileMigrator::SETTINGS, NS_LITERAL_STRING("settings").get());
COPY_DATA(CopyCookies, aReplace, nsIBrowserProfileMigrator::COOKIES, NS_LITERAL_STRING("cookies").get());
COPY_DATA(CopyHistory, aReplace, nsIBrowserProfileMigrator::HISTORY, NS_LITERAL_STRING("history").get());
COPY_DATA(CopyPasswords, aReplace, nsIBrowserProfileMigrator::PASSWORDS, NS_LITERAL_STRING("passwords").get());
COPY_DATA(CopyOtherData, aReplace, nsIBrowserProfileMigrator::OTHERDATA, NS_LITERAL_STRING("otherdata").get());
COPY_DATA(CopyBookmarks, aReplace, nsIBrowserProfileMigrator::BOOKMARKS, NS_LITERAL_STRING("bookmarks").get());
NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
return rv;
}
NS_IMETHODIMP
nsSeamonkeyProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
{
nsCOMPtr<nsISupportsArray> profiles;
GetSourceProfiles(getter_AddRefs(profiles));
if (profiles) {
PRUint32 count;
profiles->Count(&count);
*aResult = count > 1;
}
else
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSeamonkeyProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
{
if (!mProfileNames && !mProfileLocations) {
nsresult rv = NS_NewISupportsArray(getter_AddRefs(mProfileNames));
if (NS_FAILED(rv)) return rv;
rv = NS_NewISupportsArray(getter_AddRefs(mProfileLocations));
if (NS_FAILED(rv)) return rv;
GetProfileDataFromSeamonkeyRegistry(mProfileNames, mProfileLocations);
}
NS_IF_ADDREF(*aResult = mProfileNames);
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsSeamonkeyProfileMigrator
nsresult
nsSeamonkeyProfileMigrator::GetSourceProfile(const PRUnichar* aProfile)
{
PRUint32 count;
mProfileNames->Count(&count);
for (PRUint32 i = 0; i < count; ++i) {
nsCOMPtr<nsISupportsString> str(do_QueryElementAt(mProfileNames, i));
nsXPIDLString profileName;
str->GetData(profileName);
if (profileName.Equals(aProfile)) {
mSourceProfile = do_QueryElementAt(mProfileLocations, i);
break;
}
}
return NS_OK;
}
nsresult
nsSeamonkeyProfileMigrator::GetProfileDataFromSeamonkeyRegistry(nsISupportsArray* aProfileNames,
nsISupportsArray* aProfileLocations)
{
nsresult rv = NS_OK;
// Find the Seamonkey Registry
nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1"));
nsCOMPtr<nsILocalFile> seamonkeyRegistry;
fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
seamonkeyRegistry->Append(NS_LITERAL_STRING("registry.dat"));
// Open It
nsCOMPtr<nsIRegistry> reg(do_CreateInstance("@mozilla.org/registry;1"));
reg->Open(seamonkeyRegistry);
nsRegistryKey profilesTree;
rv = reg->GetKey(nsIRegistry::Common, NS_LITERAL_STRING("Profiles").get(), &profilesTree);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIEnumerator> keys;
reg->EnumerateSubtrees(profilesTree, getter_AddRefs(keys));
keys->First();
while (keys->IsDone() != NS_OK) {
nsCOMPtr<nsISupports> key;
keys->CurrentItem(getter_AddRefs(key));
nsCOMPtr<nsIRegistryNode> node(do_QueryInterface(key));
nsRegistryKey profile;
node->GetKey(&profile);
// "migrated" is "yes" for all valid Seamonkey profiles. It is only "no"
// for 4.x profiles.
nsXPIDLString isMigrated;
reg->GetString(profile, NS_LITERAL_STRING("migrated").get(), getter_Copies(isMigrated));
if (isMigrated.Equals(NS_LITERAL_STRING("no"))) {
keys->Next();
continue;
}
// Get the profile name and add it to the names array
nsXPIDLString profileName;
node->GetName(getter_Copies(profileName));
nsCOMPtr<nsISupportsString> profileNameString(do_CreateInstance("@mozilla.org/supports-string;1"));
profileNameString->SetData(profileName);
mProfileNames->AppendElement(profileNameString);
// Get the profile location and add it to the locations array
nsXPIDLString directory;
reg->GetString(profile, NS_LITERAL_STRING("directory").get(), getter_Copies(directory));
nsCOMPtr<nsILocalFile> dir;
#ifdef XP_MACOSX
rv = NS_NewNativeLocalFile(nsCString(), PR_TRUE, getter_AddRefs(dir));
if (NS_FAILED(rv)) return rv;
dir->SetPersistentDescriptor(NS_LossyConvertUCS2toASCII(directory));
#else
rv = NS_NewLocalFile(directory, PR_TRUE, getter_AddRefs(dir));
if (NS_FAILED(rv)) return rv;
#endif
PRBool exists;
dir->Exists(&exists);
if (exists)
mProfileLocations->AppendElement(dir);
keys->Next();
}
}
#define F(a) nsSeamonkeyProfileMigrator::a
#define MAKEPREFTRANSFORM(pref, newpref, getmethod, setmethod) \
{ pref, newpref, F(Get##getmethod), F(Set##setmethod), PR_FALSE, -1 }
#define MAKESAMETYPEPREFTRANSFORM(pref, method) \
{ pref, 0, F(Get##method), F(Set##method), PR_FALSE, -1 }
static
nsSeamonkeyProfileMigrator::PREFTRANSFORM gTransforms[] = {
MAKESAMETYPEPREFTRANSFORM("signon.SignonFileName", String),
MAKESAMETYPEPREFTRANSFORM("browser.startup.homepage", WString),
MAKESAMETYPEPREFTRANSFORM("browser.history_expire_days", Int),
MAKESAMETYPEPREFTRANSFORM("browser.tabs.autoHide", Bool),
MAKESAMETYPEPREFTRANSFORM("browser.tabs.loadInBackground", Bool),
MAKESAMETYPEPREFTRANSFORM("browser.enable_automatic_image_resizing", Bool),
MAKESAMETYPEPREFTRANSFORM("network.cookie.warnAboutCookies", Bool),
MAKESAMETYPEPREFTRANSFORM("network.cookie.lifetime.enabled", Bool),
MAKESAMETYPEPREFTRANSFORM("network.cookie.lifetime.behavior", Int),
MAKESAMETYPEPREFTRANSFORM("dom.disable_open_during_load", Bool),
MAKESAMETYPEPREFTRANSFORM("signon.rememberSignons", Bool),
MAKESAMETYPEPREFTRANSFORM("security.enable_ssl2", Bool),
MAKESAMETYPEPREFTRANSFORM("security.enable_ssl3", Bool),
MAKESAMETYPEPREFTRANSFORM("security.enable_tls", Bool),
MAKESAMETYPEPREFTRANSFORM("security.warn_entering_secure", Bool),
MAKESAMETYPEPREFTRANSFORM("security.warn_entering_weak", Bool),
MAKESAMETYPEPREFTRANSFORM("security.warn_leaving_secure", Bool),
MAKESAMETYPEPREFTRANSFORM("security.warn_submit_insecure", Bool),
MAKESAMETYPEPREFTRANSFORM("security.warn_viewing_mixed", Bool),
MAKESAMETYPEPREFTRANSFORM("security.default_personal_cert", String),
MAKESAMETYPEPREFTRANSFORM("security.OSCP.enabled", Int),
MAKESAMETYPEPREFTRANSFORM("security.OSCP.signingCA", String),
MAKESAMETYPEPREFTRANSFORM("security.OSCP.URL", String),
MAKESAMETYPEPREFTRANSFORM("security.enable_java", Bool),
MAKESAMETYPEPREFTRANSFORM("javascript.enabled", Bool),
MAKESAMETYPEPREFTRANSFORM("dom.disable_window_move_resize", Bool),
MAKESAMETYPEPREFTRANSFORM("dom.disable_window_flip", Bool),
MAKESAMETYPEPREFTRANSFORM("dom.disable_window_open_feature.status", Bool),
MAKESAMETYPEPREFTRANSFORM("dom.disable_window_status_change", Bool),
MAKESAMETYPEPREFTRANSFORM("dom.disable_image_src_set", Bool),
MAKESAMETYPEPREFTRANSFORM("accessibility.typeaheadfind.autostart", Bool),
MAKESAMETYPEPREFTRANSFORM("accessibility.typeaheadfind.linksonly", Bool),
MAKESAMETYPEPREFTRANSFORM("network.proxy.type", Int),
MAKESAMETYPEPREFTRANSFORM("network.proxy.http", String),
MAKESAMETYPEPREFTRANSFORM("network.proxy.http_port", Int),
MAKESAMETYPEPREFTRANSFORM("network.proxy.ftp", String),
MAKESAMETYPEPREFTRANSFORM("network.proxy.ftp_port", Int),
MAKESAMETYPEPREFTRANSFORM("network.proxy.ssl", String),
MAKESAMETYPEPREFTRANSFORM("network.proxy.ssl_port", Int),
MAKESAMETYPEPREFTRANSFORM("network.proxy.socks", String),
MAKESAMETYPEPREFTRANSFORM("network.proxy.socks_port", Int),
MAKESAMETYPEPREFTRANSFORM("network.proxy.gopher", String),
MAKESAMETYPEPREFTRANSFORM("network.proxy.gopher_port", Int),
MAKESAMETYPEPREFTRANSFORM("network.proxy.no_proxies_on", String),
MAKESAMETYPEPREFTRANSFORM("network.proxy.autoconfig_url", String),
MAKESAMETYPEPREFTRANSFORM("browser.display.foreground_color", String),
MAKESAMETYPEPREFTRANSFORM("browser.display.background_color", String),
MAKESAMETYPEPREFTRANSFORM("browser.anchor_color", String),
MAKESAMETYPEPREFTRANSFORM("browser.visited_color", String),
MAKESAMETYPEPREFTRANSFORM("browser.underline_anchors", Bool),
MAKESAMETYPEPREFTRANSFORM("browser.display.use_system_colors", Bool),
MAKESAMETYPEPREFTRANSFORM("browser.display.use_document_colors", Bool),
MAKESAMETYPEPREFTRANSFORM("browser.display.screen_resolution", Int),
MAKESAMETYPEPREFTRANSFORM("browser.display.use_document_fonts", Bool),
MAKEPREFTRANSFORM("network.image.imageBehavior", 0, Int, Image),
MAKEPREFTRANSFORM("network.cookie.cookieBehavior", 0, Int, Cookie),
MAKEPREFTRANSFORM("browser.downloadmanager.behavior", 0, Int, DownloadManager),
MAKEPREFTRANSFORM("wallet.captureForms", "formfill.enabled", Bool, Bool)
};
nsresult
nsSeamonkeyProfileMigrator::SetImage(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
nsresult rv = NS_OK;
if (xform->prefHasValue)
rv = aBranch->SetIntPref("network.image.imageBehavior", xform->intValue == 1 ? 0 : xform->intValue);
return rv;
}
nsresult
nsSeamonkeyProfileMigrator::SetCookie(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
nsresult rv = NS_OK;
if (xform->prefHasValue)
rv = aBranch->SetIntPref("network.cookie.cookieBehavior", xform->intValue == 3 ? 0 : xform->intValue);
return rv;
}
nsresult
nsSeamonkeyProfileMigrator::SetDownloadManager(void* aTransform, nsIPrefBranch* aBranch)
{
PREFTRANSFORM* xform = (PREFTRANSFORM*)aTransform;
nsresult rv = NS_OK;
if (xform->prefHasValue) {
// Seamonkey's download manager uses a single pref to control behavior:
// 0 - show download manager window
// 1 - show individual progress dialogs
// 2 - show nothing
//
// Firebird has only a download manager window, but it can behave like a progress dialog, thus:
// 0 || 1 -> show downloads window when a download starts
// 2 -> don't show anything when a download starts
// 1 -> close the downloads window as if it were a progress window when downloads complete.
//
rv |= aBranch->SetBoolPref("browser.download.manager.showWhenStarting", xform->intValue != 2);
rv |= aBranch->SetBoolPref("browser.download.manager.closeWhenDone", xform->intValue == 1);
}
return NS_OK;
}
nsresult
nsSeamonkeyProfileMigrator::TransformPreferences(const nsAString& aSourcePrefFileName,
const nsAString& aTargetPrefFileName)
{
PREFTRANSFORM* transform;
PREFTRANSFORM* end = gTransforms + sizeof(gTransforms)/sizeof(PREFTRANSFORM);
// Load the source pref file
nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
psvc->ResetPrefs();
nsCOMPtr<nsIFile> sourcePrefsFile;
mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile));
sourcePrefsFile->Append(aSourcePrefFileName);
psvc->ReadUserPrefs(sourcePrefsFile);
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
for (transform = gTransforms; transform < end; ++transform)
transform->prefGetterFunc(transform, branch);
nsVoidArray* fontPrefs = new nsVoidArray();
if (!fontPrefs)
return NS_ERROR_OUT_OF_MEMORY;
ReadFontsBranch(psvc, fontPrefs);
// Now that we have all the pref data in memory, load the target pref file,
// and write it back out
psvc->ResetPrefs();
for (transform = gTransforms; transform < end; ++transform)
transform->prefSetterFunc(transform, branch);
WriteFontsBranch(psvc, fontPrefs);
delete fontPrefs;
fontPrefs = nsnull;
nsCOMPtr<nsIFile> targetPrefsFile;
mTargetProfile->Clone(getter_AddRefs(targetPrefsFile));
targetPrefsFile->Append(aTargetPrefFileName);
psvc->SavePrefFile(targetPrefsFile);
return NS_OK;
}
typedef struct {
char* prefName;
PRInt32 type;
union {
char* stringValue;
PRInt32 intValue;
PRBool boolValue;
PRUnichar* wstringValue;
};
} FontPref;
void
nsSeamonkeyProfileMigrator::ReadFontsBranch(nsIPrefService* aPrefService,
nsVoidArray* aPrefs)
{
// Enumerate the branch
nsCOMPtr<nsIPrefBranch> branch;
aPrefService->GetBranch("font.", getter_AddRefs(branch));
PRUint32 count;
char** prefs = nsnull;
nsresult rv = branch->GetChildList("", &count, &prefs);
if (NS_FAILED(rv)) return;
for (PRUint32 i = 0; i < count; ++i) {
// Save each pref's value into an array
char* currPref = prefs[i];
PRInt32 type;
branch->GetPrefType(currPref, &type);
FontPref* pref = new FontPref;
pref->prefName = currPref;
pref->type = type;
switch (type) {
case nsIPrefBranch::PREF_STRING:
rv = branch->GetCharPref(currPref, &pref->stringValue);
break;
case nsIPrefBranch::PREF_BOOL:
rv = branch->GetBoolPref(currPref, &pref->boolValue);
break;
case nsIPrefBranch::PREF_INT:
rv = branch->GetIntPref(currPref, &pref->intValue);
break;
case nsIPrefBranch::PREF_INVALID:
{
nsCOMPtr<nsIPrefLocalizedString> str;
rv = branch->GetComplexValue(currPref,
NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(str));
if (NS_SUCCEEDED(rv) && str)
str->ToString(&pref->wstringValue);
}
break;
}
if (NS_SUCCEEDED(rv))
aPrefs->AppendElement((void*)pref);
}
}
void
nsSeamonkeyProfileMigrator::WriteFontsBranch(nsIPrefService* aPrefService,
nsVoidArray* aPrefs)
{
nsresult rv;
// Enumerate the branch
nsCOMPtr<nsIPrefBranch> branch;
aPrefService->GetBranch("font.", getter_AddRefs(branch));
PRUint32 count = aPrefs->Count();
for (PRUint32 i = 0; i < count; ++i) {
FontPref* pref = (FontPref*)aPrefs->ElementAt(i);
switch (pref->type) {
case nsIPrefBranch::PREF_STRING:
rv = branch->SetCharPref(pref->prefName, pref->stringValue);
nsCRT::free(pref->stringValue);
pref->stringValue = nsnull;
break;
case nsIPrefBranch::PREF_BOOL:
rv = branch->SetBoolPref(pref->prefName, pref->boolValue);
break;
case nsIPrefBranch::PREF_INT:
rv = branch->SetIntPref(pref->prefName, pref->intValue);
break;
case nsIPrefBranch::PREF_INVALID:
nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
pls->SetData(pref->wstringValue);
rv = branch->SetComplexValue(pref->prefName,
NS_GET_IID(nsIPrefLocalizedString),
pls);
nsCRT::free(pref->wstringValue);
pref->wstringValue = nsnull;
break;
}
nsCRT::free(pref->prefName);
pref->prefName = nsnull;
delete pref;
pref = nsnull;
}
aPrefs->Clear();
}
nsresult
nsSeamonkeyProfileMigrator::CopyPreferences(PRBool aReplace)
{
nsresult rv = NS_OK;
if (!aReplace)
return rv;
rv |= TransformPreferences(FILE_NAME_PREFS, FILE_NAME_PREFS);
// Security Stuff
rv |= CopyFile(FILE_NAME_CERT8DB, FILE_NAME_CERT8DB);
rv |= CopyFile(FILE_NAME_KEY3DB, FILE_NAME_KEY3DB);
rv |= CopyFile(FILE_NAME_SECMODDB, FILE_NAME_SECMODDB);
// User MIME Type overrides
rv |= CopyFile(FILE_NAME_MIMETYPES, FILE_NAME_MIMETYPES);
rv |= CopyUserContentSheet();
return rv;
}
nsresult
nsSeamonkeyProfileMigrator::CopyUserContentSheet()
{
nsCOMPtr<nsIFile> sourceUserContent;
mSourceProfile->Clone(getter_AddRefs(sourceUserContent));
sourceUserContent->Append(DIR_NAME_CHROME);
sourceUserContent->Append(FILE_NAME_USERCONTENT);
PRBool exists = PR_FALSE;
sourceUserContent->Exists(&exists);
if (!exists)
return NS_OK;
nsCOMPtr<nsIFile> targetUserContent;
mTargetProfile->Clone(getter_AddRefs(targetUserContent));
targetUserContent->Append(DIR_NAME_CHROME);
nsCOMPtr<nsIFile> targetChromeDir;
targetUserContent->Clone(getter_AddRefs(targetChromeDir));
targetUserContent->Append(FILE_NAME_USERCONTENT);
targetUserContent->Exists(&exists);
if (exists)
targetUserContent->Remove(PR_FALSE);
return sourceUserContent->CopyTo(targetChromeDir, FILE_NAME_USERCONTENT);
}
nsresult
nsSeamonkeyProfileMigrator::CopyCookies(PRBool aReplace)
{
nsresult rv;
if (aReplace)
rv = CopyFile(FILE_NAME_COOKIES, FILE_NAME_COOKIES);
else {
nsCOMPtr<nsICookieManager2> cookieManager(do_GetService(NS_COOKIEMANAGER_CONTRACTID));
if (!cookieManager)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFile> seamonkeyCookiesFile;
mSourceProfile->Clone(getter_AddRefs(seamonkeyCookiesFile));
seamonkeyCookiesFile->Append(FILE_NAME_COOKIES);
rv = cookieManager->ReadCookies(seamonkeyCookiesFile);
}
return rv;
}
nsresult
nsSeamonkeyProfileMigrator::CopyHistory(PRBool aReplace)
{
return aReplace ? CopyFile(FILE_NAME_HISTORY, FILE_NAME_HISTORY) : NS_OK;
}
nsresult
nsSeamonkeyProfileMigrator::CopyPasswords(PRBool aReplace)
{
nsresult rv;
nsXPIDLCString signonsFileName;
if (aReplace) {
// Find out what the signons file was called, this is stored in a pref
// in Seamonkey.
nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
psvc->ResetPrefs();
nsCOMPtr<nsIFile> seamonkeyPrefsFile;
mSourceProfile->Clone(getter_AddRefs(seamonkeyPrefsFile));
seamonkeyPrefsFile->Append(FILE_NAME_PREFS);
psvc->ReadUserPrefs(seamonkeyPrefsFile);
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
rv = branch->GetCharPref("signon.SignonFileName", getter_Copies(signonsFileName));
}
else
LocateSignonsFile(getter_Copies(signonsFileName));
if (signonsFileName.IsEmpty())
return NS_ERROR_FILE_NOT_FOUND;
nsAutoString fileName; fileName.AssignWithConversion(signonsFileName);
if (aReplace)
rv = CopyFile(fileName, fileName);
else {
nsCOMPtr<nsIFile> seamonkeyPasswordsFile;
mSourceProfile->Clone(getter_AddRefs(seamonkeyPasswordsFile));
seamonkeyPasswordsFile->Append(fileName);
nsCOMPtr<nsIPasswordManagerInternal> pmi(do_GetService("@mozilla.org/passwordmanager;1"));
rv = pmi->ReadPasswords(seamonkeyPasswordsFile);
}
return rv;
}
nsresult
nsSeamonkeyProfileMigrator::LocateSignonsFile(char** aResult)
{
nsCOMPtr<nsISimpleEnumerator> entries;
nsresult rv = mSourceProfile->GetDirectoryEntries(getter_AddRefs(entries));
if (NS_FAILED(rv)) return rv;
nsCAutoString fileName;
do {
PRBool hasMore = PR_FALSE;
rv = entries->HasMoreElements(&hasMore);
if (NS_FAILED(rv) || !hasMore) break;
nsCOMPtr<nsISupports> supp;
rv = entries->GetNext(getter_AddRefs(supp));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIFile> currFile(do_QueryInterface(supp));
nsCOMPtr<nsIURI> uri;
rv = NS_NewFileURI(getter_AddRefs(uri), currFile);
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
nsCAutoString extn;
url->GetFileExtension(extn);
if (extn.EqualsIgnoreCase("s")) {
url->GetFileName(fileName);
break;
}
}
while (1);
*aResult = ToNewCString(fileName);
return NS_OK;
}
nsresult
nsSeamonkeyProfileMigrator::CopyBookmarks(PRBool aReplace)
{
if (aReplace)
return CopyFile(FILE_NAME_BOOKMARKS, FILE_NAME_BOOKMARKS);
return ImportNetscapeBookmarks(FILE_NAME_BOOKMARKS,
NS_LITERAL_STRING("importedSeamonkeyBookmarksTitle").get());
}
nsresult
nsSeamonkeyProfileMigrator::CopyOtherData(PRBool aReplace)
{
return aReplace ? CopyFile(FILE_NAME_DOWNLOADS, FILE_NAME_DOWNLOADS) : NS_OK;
}

Просмотреть файл

@ -0,0 +1,92 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef seamonkeyprofilemigrator___h___
#define seamonkeyprofilemigrator___h___
#include "nsIBrowserProfileMigrator.h"
#include "nsILocalFile.h"
#include "nsISupportsArray.h"
#include "nsNetscapeProfileMigratorBase.h"
#include "nsString.h"
class nsIFile;
class nsIPrefBranch;
class nsIPrefService;
class nsVoidArray;
class nsSeamonkeyProfileMigrator : public nsNetscapeProfileMigratorBase,
public nsIBrowserProfileMigrator
{
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsSeamonkeyProfileMigrator();
virtual ~nsSeamonkeyProfileMigrator();
public:
static nsresult SetImage(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetCookie(void* aTransform, nsIPrefBranch* aBranch);
static nsresult SetDownloadManager(void* aTransform, nsIPrefBranch* aBranch);
protected:
nsresult GetProfileDataFromSeamonkeyRegistry(nsISupportsArray* aProfileNames,
nsISupportsArray* aProfileLocations);
nsresult GetSourceProfile(const PRUnichar* aProfile);
nsresult CopyPreferences(PRBool aReplace);
nsresult TransformPreferences(const nsAString& aSourcePrefFileName,
const nsAString& aTargetPrefFileName);
void ReadFontsBranch(nsIPrefService* aPrefService, nsVoidArray* aPrefs);
void WriteFontsBranch(nsIPrefService* aPrefService, nsVoidArray* aPrefs);
nsresult CopyUserContentSheet();
nsresult CopyCookies(PRBool aReplace);
nsresult CopyHistory(PRBool aReplace);
nsresult CopyPasswords(PRBool aReplace);
nsresult LocateSignonsFile(char** aResult);
nsresult CopyBookmarks(PRBool aReplace);
nsresult CopyOtherData(PRBool aReplace);
private:
nsCOMPtr<nsISupportsArray> mProfileNames;
nsCOMPtr<nsISupportsArray> mProfileLocations;
};
#endif