Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / browser / components / migration / src / nsOperaProfileMigrator.h
blob39e53affbfdc3b17fc05f25b60c4d2d06bc7238b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is The Browser Profile Migrator.
17 * The Initial Developer of the Original Code is Ben Goodger.
18 * Portions created by the Initial Developer are Copyright (C) 2004
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Ben Goodger <ben@bengoodger.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef operaprofilemigrator___h___
39 #define operaprofilemigrator___h___
41 #include "nsCOMPtr.h"
42 #include "nsIBinaryInputStream.h"
43 #include "nsIBrowserProfileMigrator.h"
44 #include "nsIObserverService.h"
45 #include "nsISupportsArray.h"
46 #include "nsStringAPI.h"
47 #include "nsVoidArray.h"
48 #include "nsINavHistoryService.h"
50 class nsICookieManager2;
51 class nsILineInputStream;
52 class nsILocalFile;
53 class nsINIParser;
54 class nsIPermissionManager;
55 class nsIPrefBranch;
56 class nsINavBookmarksService;
57 class nsIRDFResource;
59 class nsOperaProfileMigrator : public nsIBrowserProfileMigrator,
60 public nsINavHistoryBatchCallback
62 public:
63 NS_DECL_NSIBROWSERPROFILEMIGRATOR
64 NS_DECL_NSINAVHISTORYBATCHCALLBACK
65 NS_DECL_ISUPPORTS
67 nsOperaProfileMigrator();
68 virtual ~nsOperaProfileMigrator();
70 public:
72 typedef enum { STRING, INT, BOOL, COLOR } PrefType;
74 typedef nsresult(*prefConverter)(void*, nsIPrefBranch*);
76 struct PrefTransform {
77 char* sectionName;
78 char* keyName;
79 PrefType type;
80 char* targetPrefName;
81 prefConverter prefSetterFunc;
82 PRBool prefHasValue;
83 union {
84 PRInt32 intValue;
85 PRBool boolValue;
86 char* stringValue;
90 static nsresult SetFile(void* aTransform, nsIPrefBranch* aBranch);
91 static nsresult SetCookieBehavior(void* aTransform, nsIPrefBranch* aBranch);
92 static nsresult SetCookieLifetime(void* aTransform, nsIPrefBranch* aBranch);
93 static nsresult SetImageBehavior(void* aTransform, nsIPrefBranch* aBranch);
94 static nsresult SetBool(void* aTransform, nsIPrefBranch* aBranch);
95 static nsresult SetWString(void* aTransform, nsIPrefBranch* aBranch);
96 static nsresult SetInt(void* aTransform, nsIPrefBranch* aBranch);
97 static nsresult SetString(void* aTransform, nsIPrefBranch* aBranch);
99 protected:
100 nsresult CopyPreferences(PRBool aReplace);
101 nsresult ParseColor(nsINIParser &aParser, const char* aSectionName, char** aResult);
102 nsresult CopyUserContentSheet(nsINIParser &aParser);
103 nsresult CopyProxySettings(nsINIParser &aParser, nsIPrefBranch* aBranch);
104 nsresult GetInteger(nsINIParser &aParser, const char* aSectionName,
105 const char* aKeyName, PRInt32* aResult);
107 nsresult CopyCookies(PRBool aReplace);
108 nsresult CopyHistory(PRBool aReplace);
110 nsresult CopyBookmarks(PRBool aReplace);
111 void ClearToolbarFolder(nsINavBookmarksService * aBookmarksService, PRInt64 aToolbarFolder);
112 nsresult ParseBookmarksFolder(nsILineInputStream* aStream,
113 PRInt64 aFolder,
114 PRInt64 aToolbar,
115 nsINavBookmarksService* aBMS);
116 #if defined(XP_WIN) || (defined(XP_UNIX) && !defined(XP_MACOSX))
117 nsresult CopySmartKeywords(nsINavBookmarksService* aBMS,
118 nsIStringBundle* aBundle,
119 PRInt64 aParentFolder);
120 #endif // defined(XP_WIN) || (defined(XP_UNIX) && !defined(XP_MACOSX))
122 void GetOperaProfile(const PRUnichar* aProfile, nsILocalFile** aFile);
124 private:
125 nsCOMPtr<nsILocalFile> mOperaProfile;
126 nsCOMPtr<nsISupportsArray> mProfiles;
127 nsCOMPtr<nsIObserverService> mObserverService;
130 class nsOperaCookieMigrator
132 public:
133 nsOperaCookieMigrator(nsIInputStream* aSourceStream);
134 virtual ~nsOperaCookieMigrator();
136 nsresult Migrate();
138 typedef enum { BEGIN_DOMAIN_SEGMENT = 0x01,
139 DOMAIN_COMPONENT = 0x1E,
140 END_DOMAIN_SEGMENT = 0x84 | 0x80, // 0x04 | (1 << 8)
142 BEGIN_PATH_SEGMENT = 0x02,
143 PATH_COMPONENT = 0x1D,
144 END_PATH_SEGMENT = 0x05 | 0x80, // 0x05 | (1 << 8)
146 FILTERING_INFO = 0x1F,
147 PATH_HANDLING_INFO = 0x21,
148 THIRD_PARTY_HANDLING_INFO = 0x25,
150 BEGIN_COOKIE_SEGMENT = 0x03,
151 COOKIE_ID = 0x10,
152 COOKIE_DATA = 0x11,
153 COOKIE_EXPIRY = 0x12,
154 COOKIE_LASTUSED = 0x13,
155 COOKIE_COMMENT = 0x14,
156 COOKIE_COMMENT_URL = 0x15,
157 COOKIE_V1_DOMAIN = 0x16,
158 COOKIE_V1_PATH = 0x17,
159 COOKIE_V1_PORT_LIMITATIONS = 0x18,
160 COOKIE_SECURE = 0x19 | 0x80,
161 COOKIE_VERSION = 0x1A,
162 COOKIE_OTHERFLAG_1 = 0x1B | 0x80,
163 COOKIE_OTHERFLAG_2 = 0x1C | 0x80,
164 COOKIE_OTHERFLAG_3 = 0x20 | 0x80,
165 COOKIE_OTHERFLAG_4 = 0x22 | 0x80,
166 COOKIE_OTHERFLAG_5 = 0x23 | 0x80,
167 COOKIE_OTHERFLAG_6 = 0x24 | 0x80
168 } TAG;
170 protected:
171 nsOperaCookieMigrator() { }
173 nsresult ReadHeader();
175 void SynthesizePath(char** aResult);
176 void SynthesizeDomain(char** aResult);
177 nsresult AddCookieOverride(nsIPermissionManager* aManager);
178 nsresult AddCookie(nsICookieManager2* aManager);
180 private:
181 nsCOMPtr<nsIBinaryInputStream> mStream;
183 nsVoidArray mDomainStack;
184 nsVoidArray mPathStack;
186 struct Cookie {
187 nsCString id;
188 nsCString data;
189 PRInt32 expiryTime;
190 PRBool isSecure;
193 PRUint32 mAppVersion;
194 PRUint32 mFileVersion;
195 PRUint16 mTagTypeLength;
196 PRUint16 mPayloadTypeLength;
197 PRBool mCookieOpen;
198 Cookie mCurrCookie;
199 PRUint8 mCurrHandlingInfo;
203 #endif