bug 313529 - Support migrating home pages and multiple versions of Firefox Start, r=vlad

This commit is contained in:
mconnor%steelgryphon.com 2005-10-25 07:54:58 +00:00
Родитель 5a0a09ce73
Коммит 907438b7c8
12 изменённых файлов: 366 добавлений и 68 удалений

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

@ -54,14 +54,14 @@ var MigrationWizard = {
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 && window.arguments.length > 1) {
this._source = window.arguments[0];
this._migrator = window.arguments[1].QueryInterface(kIMig);
this._autoMigrate = window.arguments[2].QueryInterface(kIPStartup);
if (this._autoMigrate) {
// Show the "nothing" option in the automigrate case to provide an
// easily identifiable way to avoid migration and create a new profile.
@ -69,10 +69,10 @@ var MigrationWizard = {
nothing.hidden = false;
}
}
this.onImportSourcePageShow();
},
uninit: function ()
{
var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
@ -81,7 +81,7 @@ var MigrationWizard = {
os.removeObserver(this, "Migration:ItemAfterMigrate");
os.removeObserver(this, "Migration:Ended");
},
// 1 - Import Source
onImportSourcePageShow: function ()
{
@ -167,7 +167,13 @@ var MigrationWizard = {
if (this._migrator.sourceHasMultipleProfiles)
this._wiz.currentPage.next = "selectProfile";
else {
this._wiz.currentPage.next = (this._autoMigrate || this._bookmarks) ? "migrating" : "importItems";
if (this._autoMigrate)
this._wiz.currentPage.next = "homePageImport";
else if (this._bookmarks)
this._wiz.currentPage.next = "migrating"
else
this._wiz.currentPage.next = "importItems";
var sourceProfiles = this._migrator.sourceProfiles;
if (sourceProfiles && sourceProfiles.Count() == 1) {
var profileName = sourceProfiles.QueryElementAt(0, Components.interfaces.nsISupportsString);
@ -215,8 +221,10 @@ var MigrationWizard = {
this._selectedProfile = profiles.selectedItem.id;
// If we're automigrating or just doing bookmarks don't show the item selection page
if (this._autoMigrate || this._bookmarks)
this._wiz.currentPage.next = "migrating";
if (this._autoMigrate)
this._wiz.currentPage.next = "homePageImport";
else if (this._bookmarks)
this._wiz.currentPage.next = "migrating"
},
// 3 - ImportItems
@ -274,8 +282,117 @@ var MigrationWizard = {
this._wiz.canAdvance = oneChecked;
},
// 4 - Migrating
// 4 - Home Page Selection
onHomePageMigrationPageShow: function ()
{
// only want this on the first run
if (!this._autoMigrate)
this._wiz.advance();
var numberOfChoices = 0;
try {
var bundle = document.getElementById("browserconfigBundle");
var pageTitle = bundle.getString("homePageMigrationPageTitle");
var pageDesc = bundle.getString("homePageMigrationDescription");
var startPages = bundle.getString("homePageOptionCount");
} catch(ex) {}
if (!pageTitle || !pageDesc || !startPages || startPages < 1)
this._wiz.advance();
document.getElementById("homePageImport").setAttribute("label", pageTitle);
document.getElementById("homePageImportDesc").setAttribute("value", pageDesc);
this._wiz._adjustWizardHeader();
var singleStart = document.getElementById("homePageSingleStart");
var i, mainStr, radioItem, radioItemId, radioItemLabel, radioItemValue;
if (startPages > 1) {
numberOfChoices += startPages;
this._multipleStartOptions = true;
mainStr = bundle.getString("homePageMultipleStartMain");
var multipleStart = document.getElementById("homePageMultipleStartMain");
multipleStart.setAttribute("label", mainStr);
multipleStart.hidden = false;
multipleStart.setAttribute("selected", true);
singleStart.hidden = true;
for (i = 1; i <= startPages; i++) {
radioItemId = "homePageMultipleStart" + i;
radioItemLabel = bundle.getString(radioItemId + "Label");
radioItemValue = bundle.getString(radioItemId + "URL");
radioItem = document.getElementById(radioItemId);
radioItem.hidden = false;
radioItem.setAttribute("label", radioItemLabel);
radioItem.setAttribute("value", radioItemValue);
}
}
else {
numberOfChoices++;
mainStr = bundle.getString("homePageSingleStartMain");
radioItemValue = bundle.getString("homePageSingleStartMainURL");
singleStart.setAttribute("label", mainStr);
singleStart.setAttribute("value", radioItemValue);
singleStart.setAttribute("selected", true);
}
var source = null;
switch (this._source) {
case "ie":
case "macie":
source = "sourceNameIE";
break;
case "opera":
source = "sourceNameOpera";
break;
case "dogbert":
source = "sourceNameDogbert";
break;
case "safari":
source = "sourceNameSafari";
break;
case "seamonkey":
source = "sourceNameSeamonkey";
break;
}
// semi-wallpaper for crash when multiple profiles exist, since we haven't initialized mSourceProfile in places
this._migrator.getMigrateData(this._selectedProfile, this._autoMigrate);
var oldHomePageURL = this._migrator.sourceHomePageURL;
if (oldHomePageURL && source) {
numberOfChoices++;
var bundle2 = document.getElementById("bundle");
var appName = bundle2.getString(source);
var oldHomePageLabel = bundle.getFormattedString("homePageImport",
[appName]);
var oldHomePage = document.getElementById("oldHomePage");
oldHomePage.setAttribute("label", oldHomePageLabel);
oldHomePage.setAttribute("value", oldHomePageURL);
oldHomePage.removeAttribute("hidden");
}
// if we don't have at least two options, just advance
if (numberOfChoices < 2)
this._wiz.advance();
},
onHomePageMigrationPageAdvanced: function ()
{
// we might not have a selectedItem if we're in fallback mode
try {
var radioGroup = document.getElementById("homePageRadiogroup");
if (radioGroup.selectedItem.id == "homePageMultipleStartMain")
radioGroup = document.getElementById("multipleStartRadiogroup");
this._newHomePage = radioGroup.selectedItem.value;
} catch(ex) {}
},
// 5 - Migrating
onMigratingPageShow: function ()
{
this._wiz.getButton("cancel").disabled = true;
@ -298,7 +415,7 @@ var MigrationWizard = {
{
aOuter._migrator.migrate(aOuter._itemsFlags, aOuter._autoMigrate, aOuter._selectedProfile);
},
_listItems: function (aID)
{
var items = document.getElementById(aID);
@ -343,9 +460,40 @@ var MigrationWizard = {
break;
case "Migration:Ended":
if (this._autoMigrate) {
if (this._newHomePage) {
try {
var prefSvc2 = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
const nsIDirectoryServiceContractID = "@mozilla.org/file/directory_service;1";
const nsIProperties = Components.interfaces.nsIProperties;
var directoryService = Components.classes[nsIDirectoryServiceContractID]
.getService(nsIProperties);
var prefFile = directoryService.get("ProfDS", Components.interfaces.nsIFile);
prefFile.append("prefs.js");
prefSvc2.resetPrefs();
prefSvc2.readUserPrefs(prefFile);
// set homepage properly
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
str.data = this._newHomePage;
prefSvc.setComplexValue("browser.startup.homepage",
Components.interfaces.nsISupportsString, str);
prefSvc2.savePrefFile(prefFile);
} catch(ex) {
dump(ex);
}
}
// We're done now.
this._wiz.canAdvance = true;
this._wiz.advance();
setTimeout(close, 5000);
}
else {
@ -356,7 +504,7 @@ var MigrationWizard = {
break;
}
},
onDonePageShow: function ()
{
this._wiz.getButton("cancel").disabled = true;

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

@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
@ -38,7 +38,7 @@
<?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"
windowtype="Browser:MigrationWizard"
@ -51,10 +51,11 @@
xmlns:wairole="http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy#">
<script type="application/x-javascript" src="chrome://browser/content/migration/migration.js"/>
<stringbundle id="bundle" src="chrome://browser/locale/migration/migration.properties"/>
<stringbundle id="brandBundle" src="chrome://branding/locale/brand.properties"/>
<stringbundle id="browserconfigBundle" src="resource:///browserconfig.properties"/>
<wizardpage id="importSource" pageid="importSource" next="selectProfile"
label="&importSource.title;"
onpageadvanced="MigrationWizard.onImportSourcePageAdvanced();">
@ -64,7 +65,7 @@
<description id="importAll" control="importSourceGroup">&importFromUnix.label;</description>
#endif
<description id="importBookmarks" control="importSourceGroup" hidden="true">&importFromBookmarks.label;</description>
<radiogroup id="importSourceGroup" align="start">
<radio id="phoenix" label="&importFromPhoenix.label;" accesskey="&importFromPhoenix.accesskey;"/>
#ifdef XP_UNIX
@ -87,7 +88,7 @@
<radio id="konqueror" label="&importFromKonqueror.label;" accesskey="&importFromKonqueror.accesskey;"/>
<radio id="epiphany" label="&importFromEpiphany.label;" accesskey="&importFromEpiphany.accesskey;"/>
<radio id="galeon" label="&importFromGaleon.label;" accesskey="&importFromGaleon.accesskey;"/>
-->
-->
#endif
#endif
#ifdef XP_WIN
@ -115,27 +116,45 @@
onpagerewound="return MigrationWizard.onSelectProfilePageRewound();"
onpageadvanced="return MigrationWizard.onSelectProfilePageAdvanced();">
<description control="profiles">&selectProfile.label;</description>
<radiogroup id="profiles" align="left"/>
</wizardpage>
<wizardpage id="importItems" pageid="importItems" label="&importItems.title;"
next="migrating"
next="homePageImport"
onpageshow="return MigrationWizard.onImportItemsPageShow();"
onpagerewound="return MigrationWizard.onImportItemsPageRewound();"
onpageadvanced="return MigrationWizard.onImportItemsPageAdvanced();"
oncommand="MigrationWizard.onImportItemCommand();">
oncommand="MigrationWizard.onImportItemCommand();">
<description control="dataSources">&importItems.label;</description>
<vbox id="dataSources" style="overflow: auto; -moz-appearance: listbox" align="left" flex="1"
xhtml2:role="wairole:groupbox"/>
</wizardpage>
<wizardpage id="homePageImport" pageid="homePageImport"
next="migrating"
onpageshow="return MigrationWizard.onHomePageMigrationPageShow();"
onpageadvanced="return MigrationWizard.onHomePageMigrationPageAdvanced();">
<description id="homePageImportDesc" control="homePageRadioGroup"/>
<radiogroup id="homePageRadiogroup">
<radio id="homePageSingleStart"/>
<radio id="homePageMultipleStartMain" hidden="true"/>
<radiogroup id="multipleStartRadiogroup" class="indent">
<radio id="homePageMultipleStart1" hidden="true" selected="true"/>
<radio id="homePageMultipleStart2" hidden="true"/>
<radio id="homePageMultipleStart3" hidden="true"/>
</radiogroup>
<radio id="oldHomePage" hidden="true"/>
</radiogroup>
</wizardpage>
<wizardpage id="migrating" pageid="migrating" label="&migrating.title;"
next="done"
onpageshow="MigrationWizard.onMigratingPageShow();">
<description control="migratingItems">&migrating.label;</description>
<vbox id="migratingItems" style="overflow: auto;" align="left"
xhtml2:role="wairole:groupbox"/>
</wizardpage>
@ -143,7 +162,7 @@
<wizardpage id="done" pageid="done" label="&done.title;"
onpageshow="MigrationWizard.onDonePageShow();">
<description control="doneItems">&done.label;</description>
<vbox id="doneItems" style="overflow: auto;" align="left"
xhtml2:role="wairole:groupbox"/>
</wizardpage>

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

@ -90,5 +90,9 @@ interface nsIBrowserProfileMigrator : nsISupports
* not support profiles, this attribute is null.
*/
readonly attribute nsISupportsArray sourceProfiles;
};
/**
* The import source homepage. Returns null if not present/available
*/
readonly attribute AUTF8String sourceHomePageURL;
};

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

@ -381,6 +381,12 @@ nsDogbertProfileMigrator::GetSourceProfile(const PRUnichar* aProfile)
}
#endif // GetSourceProfiles
NS_IMETHODIMP
nsDogbertProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
{
aResult.Truncate();
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsDogbertProfileMigrator
#define F(a) nsDogbertProfileMigrator::a

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

@ -490,6 +490,40 @@ nsIEProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsIEProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
{
HKEY regKey;
DWORD regType;
DWORD regLength;
unsigned char regValue[MAX_PATH];
nsresult rv;
if (::RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Internet Explorer\\Main",
0, KEY_READ, &regKey) != ERROR_SUCCESS)
return NS_OK;
// read registry data
regLength = MAX_PATH;
if (::RegQueryValueEx(regKey, "Start Page", 0,
&regType, regValue, &regLength) == ERROR_SUCCESS) {
if (regType == REG_SZ) {
regValue[MAX_PATH] = '\0';
nsCAutoString homePageURL;
nsCOMPtr<nsIURI> homePageURI;
NS_NewURI(getter_AddRefs(homePageURI), NS_REINTERPRET_CAST(char *, regValue), nsnull, nsnull);
rv = homePageURI->GetSpec(homePageURL);
if (NS_SUCCEEDED(rv) && !homePageURL.IsEmpty())
aResult.Assign(homePageURL);
}
}
::RegCloseKey(regKey);
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsIEProfileMigrator

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

@ -158,6 +158,13 @@ nsMacIEProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsMacIEProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
{
aResult.Truncate();
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsMacIEProfileMigrator

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

@ -282,6 +282,37 @@ nsOperaProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsOperaProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
{
nsresult rv;
nsCAutoString val;
nsCOMPtr<nsIFile> operaPrefs;
mOperaProfile->Clone(getter_AddRefs(operaPrefs));
operaPrefs->Append(OPERA_PREFERENCES_FILE_NAME);
nsCOMPtr<nsILocalFile> lf(do_QueryInterface(operaPrefs));
NS_ENSURE_TRUE(lf, NS_ERROR_UNEXPECTED);
nsINIParser parser;
rv = parser.Init(lf);
NS_ENSURE_SUCCESS(rv, rv);
rv = parser.GetString("User Prefs",
"Home URL",
val);
if (NS_SUCCEEDED(rv))
aResult.Assign(val);
if (aResult.Length() > 0)
printf(val.get());
return NS_OK;
}
#define _OPM(type) nsOperaProfileMigrator::type
static
@ -293,7 +324,6 @@ nsOperaProfileMigrator::PrefTransform gTransforms[] = {
{ nsnull, "Allow script to move window", _OPM(BOOL), "dom.disable_window_move_resize", _OPM(SetBool), PR_FALSE, -1 },
{ nsnull, "Allow script to raise window", _OPM(BOOL), "dom.disable_window_flip", _OPM(SetBool), PR_FALSE, -1 },
{ nsnull, "Allow script to change status", _OPM(BOOL), "dom.disable_window_status_change", _OPM(SetBool), PR_FALSE, -1 },
{ nsnull, "Home URL", _OPM(STRING), "browser.startup.homepage", _OPM(SetWString), PR_FALSE, -1 },
{ nsnull, "Ignore Unrequested Popups", _OPM(BOOL), "dom.disable_open_during_load", _OPM(SetBool), PR_FALSE, -1 },
{ nsnull, "Load Figures", _OPM(BOOL), "permissions.default.image", _OPM(SetImageBehavior), PR_FALSE, -1 },

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

@ -243,7 +243,12 @@ nsPhoenixProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
NS_IF_ADDREF(*aResult = mProfileNames);
return NS_OK;
}
NS_IMETHODIMP
nsPhoenixProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
{
aResult.Truncate();
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsPhoenixProfileMigrator

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

@ -204,6 +204,33 @@ nsSafariProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsSafariProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
{
aResult.Truncate();
ICInstance internetConfig;
OSStatus error = ::ICStart(&internetConfig, 'FRFX');
if (error != noErr)
return NS_ERROR_FAILURE;
ICAttr dummy;
Str255 homePagePValue;
long prefSize = sizeof(homePagePValue);
error = ::ICGetPref(internetConfig, kICWWWHomePage, &dummy,
homePagePValue, &prefSize);
if (error != noErr)
return NS_ERROR_FAILURE;
char homePageValue[256] = "";
CopyPascalStringToC((ConstStr255Param)homePagePValue, homePageValue);
aResult.Assign(homePageValue);
::ICStop(internetConfig);
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsSafariProfileMigrator
@ -717,43 +744,6 @@ nsSafariProfileMigrator::CopyPreferences(PRBool aReplace)
::CFRelease(safariPrefs);
#if 0
// XXXmano 7/9/2005: I'm keeping this code for reference. For the time being,
// importing the homepage setting isn't a desired feature.
// Now get some of the stuff that only InternetConfig has for us, such as
// the default home page.
ICInstance internetConfig;
OSStatus error = ::ICStart(&internetConfig, 'FRFX');
if (error == noErr) {
ICAttr dummy;
char* buf = nsnull;
SInt32 size = 256;
do {
buf = (char*)malloc((unsigned int)size+1);
if (!buf)
break;
error = ::ICGetPref(internetConfig, kICWWWHomePage, &dummy, buf, &size);
if (error != noErr && error != icTruncatedErr)
FreeNullTerminatedString(buf);
size *= 2;
}
while (error == icTruncatedErr);
if (buf && *buf != 0) {
CopyPascalStringToC((ConstStr255Param)buf, buf);
branch->SetCharPref("browser.startup.homepage", buf);
}
if (buf)
FreeNullTerminatedString(buf);
::ICStop(internetConfig);
}
#endif
// Safari stores the Cookie "Accept/Don't Accept/Don't Accept Foreign" cookie
// setting in a separate WebFoundation preferences PList.
nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));

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

@ -231,6 +231,46 @@ nsSeamonkeyProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsSeamonkeyProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
{
// 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(FILE_NAME_PREFS);
psvc->ReadUserPrefs(sourcePrefsFile);
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
PRBool hasUserValue;
nsCOMPtr<nsIPrefLocalizedString> prefValue;
nsresult rv = branch->PrefHasUserValue("browser.startup.homepage", &hasUserValue);
if (NS_SUCCEEDED(rv) && hasUserValue) {
rv = branch->GetComplexValue("browser.startup.homepage",
NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(prefValue));
if (NS_SUCCEEDED(rv) && prefValue) {
nsXPIDLString data;
prefValue->ToString(getter_Copies(data));
nsCAutoString val;
val = ToNewCString(NS_ConvertUCS2toUTF8(data));
aResult.Assign(val);
}
}
psvc->ResetPrefs();
psvc->ReadUserPrefs(nsnull);
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsSeamonkeyProfileMigrator
@ -295,7 +335,6 @@ nsSeamonkeyProfileMigrator::FillProfileDataFromSeamonkeyRegistry()
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),

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

@ -18,8 +18,6 @@ importedSearchURLsFolder=Keyword Searches (From %S)
importedSearchURLsTitle=Search on %S
importedSearchUrlDesc=Type "%S <search query>" in the Location Bar to perform a search on %S.
importedHomePage=Previous Home Page (From %S)
importedDogbertBookmarksTitle=From Netscape 4
importedSeamonkeyBookmarksTitle=From Netscape 6/7/Mozilla
importedSafariBookmarks=From Safari

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

@ -2,3 +2,21 @@
#expand browser.startup.homepage=http://start.mozilla.org/firefox?client=firefox-a&rls=__MOZ_DISTRIBUTION_ID_UNQUOTED__:__AB_CD__:official
#expand browser.startup.homepage_reset=http://start.mozilla.org/firefox?client=firefox-a&rls=__MOZ_DISTRIBUTION_ID_UNQUOTED__:__AB_CD__:official
# the following section is used in the first-time migration wizard
# new and scary, however if these strings are not present, we will simply
# skip this wizard page
homePageOptionCount=1
homePageSingleStartMain=Firefox Start, a fast search page with search results by Google
#expand homePageSingleStartMainURL=http://start.mozilla.org/firefox?client=firefox-a&rls=__MOZ_DISTRIBUTION_ID_UNQUOTED__:__AB_CD__:official
homePageMultipleStartMain=Firefox Start, a fast search page
homePageMultipleStart1Label=with search results by Google
homePageMultipleStart1URL=http://start.en-US.mozilla.org/firefox/
homePageMultipleStart2Label=
homePageMultipleStart2URL=
homePageMultipleStart3Label=
homePageMultipleStart3URL=
homePageImport=Import your home page from %S
homePageMigrationPageTitle=Home Page Selection
homePageMigrationDescription=Please select the home page you wish to use:
# end safe-to-not-have section