From 136c4d71dd6f1614bb6755f7a52d14ace885883f Mon Sep 17 00:00:00 2001 From: "ben%bengoodger.com" Date: Wed, 3 Mar 2004 07:51:09 +0000 Subject: [PATCH] 215094 - add new profile migrator interface, adapt password manager to support api for adding signons with details (235360) --- toolkit/components/Makefile.in | 1 + .../passwordmgr/base/nsPasswordManager.cpp | 36 +++++------- .../passwordmgr/base/nsPasswordManager.h | 5 +- toolkit/components/profile/Makefile.in | 32 +++++++++++ toolkit/components/profile/public/Makefile.in | 34 +++++++++++ .../profile/public/nsIProfileMigrator.idl | 56 +++++++++++++++++++ 6 files changed, 139 insertions(+), 25 deletions(-) create mode 100644 toolkit/components/profile/Makefile.in create mode 100644 toolkit/components/profile/public/Makefile.in create mode 100644 toolkit/components/profile/public/nsIProfileMigrator.idl diff --git a/toolkit/components/Makefile.in b/toolkit/components/Makefile.in index 6fabca6f8737..41e77e7ef952 100644 --- a/toolkit/components/Makefile.in +++ b/toolkit/components/Makefile.in @@ -57,6 +57,7 @@ DIRS = \ history \ passwordmgr \ printing \ + profile \ satchel \ viewconfig \ viewsource \ diff --git a/toolkit/components/passwordmgr/base/nsPasswordManager.cpp b/toolkit/components/passwordmgr/base/nsPasswordManager.cpp index 2748c72ce2fb..44545974f1bd 100644 --- a/toolkit/components/passwordmgr/base/nsPasswordManager.cpp +++ b/toolkit/components/passwordmgr/base/nsPasswordManager.cpp @@ -375,7 +375,7 @@ nsPasswordManager::AddUser(const nsACString& aHost, } AddSignonData(aHost, entry); - WriteSignonFile(); + WritePasswords(mSignonFile); return NS_OK; } @@ -408,7 +408,7 @@ nsPasswordManager::RemoveUser(const nsACString& aHost, const nsAString& aUser) if (!hashEnt->head) mSignonTable.Remove(aHost); // deletes hashEnt - WriteSignonFile(); + WritePasswords(mSignonFile); return NS_OK; } @@ -421,7 +421,7 @@ NS_IMETHODIMP nsPasswordManager::AddReject(const nsACString& aHost) { mRejectTable.Put(aHost, 1); - WriteSignonFile(); + WritePasswords(mSignonFile); return NS_OK; } @@ -429,7 +429,7 @@ NS_IMETHODIMP nsPasswordManager::RemoveReject(const nsACString& aHost) { mRejectTable.Remove(aHost); - WriteSignonFile(); + WritePasswords(mSignonFile); return NS_OK; } @@ -579,9 +579,8 @@ nsPasswordManager::FindPasswordEntry(const nsACString& aHostURI, return NS_OK; } -#ifdef MIGRATION_ENABLED NS_IMETHODIMP -nsPasswordManager::AddUserFull(const nsACString& aHost, +nsPasswordManager::AddUserFull(const nsACString& aKey, const nsAString& aUser, const nsAString& aPassword, const nsAString& aUserFieldName, @@ -593,9 +592,9 @@ nsPasswordManager::AddUserFull(const nsACString& aHost, return NS_OK; // Check for an existing entry for this host + user - if (!aHost.IsEmpty()) { + if (!aKey.IsEmpty()) { SignonHashEntry *hashEnt; - if (mSignonTable.Get(aHost, &hashEnt)) { + if (mSignonTable.Get(aKey, &hashEnt)) { nsString empty; SignonDataEntry *entry = nsnull; FindPasswordEntryInternal(hashEnt->head, aUser, empty, empty, &entry); @@ -616,18 +615,13 @@ nsPasswordManager::AddUserFull(const nsACString& aHost, EncryptDataUCS2(aUser, entry->userValue); EncryptDataUCS2(aPassword, entry->passValue); - AddSignonData(aHost, entry); - WriteSignonFile(); + AddSignonData(aKey, entry); + WritePasswords(mSignonFile); return NS_OK; } -#endif -#ifdef MIGRATION_ENABLED NS_IMETHODIMP -#else -nsresult -#endif nsPasswordManager::ReadPasswords(nsIFile* aPasswordFile) { nsCOMPtr fileStream; @@ -734,7 +728,7 @@ nsPasswordManager::ReadPasswords(nsIFile* aPasswordFile) if (writeOnFinish) { fileStream->Close(); - WriteSignonFile(); + WritePasswords(mSignonFile); } return NS_OK; @@ -1082,7 +1076,7 @@ nsPasswordManager::Notify(nsIContent* aFormNode, if (NS_FAILED(EncryptDataUCS2(passValue, entry->passValue))) return NS_ERROR_FAILURE; - WriteSignonFile(); + WritePasswords(mSignonFile); } return NS_OK; @@ -1120,7 +1114,7 @@ nsPasswordManager::Notify(nsIContent* aFormNode, } AddSignonData(realm, entry); - WriteSignonFile(); + WritePasswords(mSignonFile); } else if (selection == 2) { AddReject(realm); } @@ -1234,7 +1228,7 @@ nsPasswordManager::Notify(nsIContent* aFormNode, if (NS_FAILED(EncryptDataUCS2(newValue, changeEntry->passValue))) return NS_ERROR_FAILURE; - WriteSignonFile(); + WritePasswords(mSignonFile); } } break; @@ -1584,10 +1578,10 @@ nsPasswordManager::WriteSignonEntryEnumerator(const nsACString& aKey, } void -nsPasswordManager::WriteSignonFile() +nsPasswordManager::WritePasswords(nsIFile* aPasswordFile) { nsCOMPtr fileStream; - NS_NewLocalFileOutputStream(getter_AddRefs(fileStream), mSignonFile, -1, + NS_NewLocalFileOutputStream(getter_AddRefs(fileStream), aPasswordFile, -1, 0600, 0); if (!fileStream) diff --git a/toolkit/components/passwordmgr/base/nsPasswordManager.h b/toolkit/components/passwordmgr/base/nsPasswordManager.h index d82175eb78bb..a99bd2461c05 100644 --- a/toolkit/components/passwordmgr/base/nsPasswordManager.h +++ b/toolkit/components/passwordmgr/base/nsPasswordManager.h @@ -144,10 +144,7 @@ public: nsIAutoCompleteResult** aResult); protected: -#ifndef MIGRATION_ENABLED - nsresult ReadPasswords(nsIFile* aPasswordFile); -#endif - void WriteSignonFile(); + void WritePasswords(nsIFile* aPasswordFile); void AddSignonData(const nsACString& aRealm, SignonDataEntry* aEntry); nsresult FindPasswordEntryInternal(const SignonDataEntry* aEntry, diff --git a/toolkit/components/profile/Makefile.in b/toolkit/components/profile/Makefile.in new file mode 100644 index 000000000000..21385d997721 --- /dev/null +++ b/toolkit/components/profile/Makefile.in @@ -0,0 +1,32 @@ +# +# 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): +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = public + +include $(topsrcdir)/config/rules.mk + diff --git a/toolkit/components/profile/public/Makefile.in b/toolkit/components/profile/public/Makefile.in new file mode 100644 index 000000000000..36bcf21dd89c --- /dev/null +++ b/toolkit/components/profile/public/Makefile.in @@ -0,0 +1,34 @@ +# +# 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): +# + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = profile + +XPIDLSRCS = nsIProfileMigrator.idl + +include $(topsrcdir)/config/rules.mk + diff --git a/toolkit/components/profile/public/nsIProfileMigrator.idl b/toolkit/components/profile/public/nsIProfileMigrator.idl new file mode 100644 index 000000000000..51ae318ca249 --- /dev/null +++ b/toolkit/components/profile/public/nsIProfileMigrator.idl @@ -0,0 +1,56 @@ +/* -*- 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 + * + * 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" + +[scriptable, uuid(5d9c7f6a-4af4-4a3d-be48-da1e70600b9c)] +interface nsIProfileMigrator : nsISupports +{ + /** + * Copy user profile information to the current active profile. + */ + void migrate(); +}; + +%{C++ + +#define NS_PROFILEMIGRATOR_CONTRACTID "@mozilla.org/profile/migrator;1" + +#define NS_PROFILEMIGRATOR_CID \ +{ 0xc0f8241e, 0x3340, 0x431e, { 0xbe, 0xba, 0x7b, 0x82, 0xf8, 0x7d, 0xd1, 0x41 } } + +%}