nsOperaProfileMigrator.h
Go to the documentation of this file.
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
4  *
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/
9  *
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.
14  *
15  * The Original Code is The Browser Profile Migrator.
16  *
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.
20  *
21  * Contributor(s):
22  * Ben Goodger <ben@bengoodger.com>
23  *
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.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 #ifndef operaprofilemigrator___h___
39 #define operaprofilemigrator___h___
40 
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 "nsTArray.h"
48 #include "nsINavHistoryService.h"
49 
50 class nsICookieManager2;
51 class nsILineInputStream;
52 class nsILocalFile;
53 class nsINIParser;
55 class nsIPrefBranch;
56 class nsINavBookmarksService;
57 class nsIRDFResource;
58 
60  public nsINavHistoryBatchCallback
61 {
62 public:
63  NS_DECL_NSIBROWSERPROFILEMIGRATOR
64  NS_DECL_NSINAVHISTORYBATCHCALLBACK
66 
68  virtual ~nsOperaProfileMigrator();
69 
70 public:
71 
72  typedef enum { STRING, INT, BOOL, COLOR } PrefType;
73 
74  typedef nsresult(*prefConverter)(void*, nsIPrefBranch*);
75 
76  struct PrefTransform {
77  const char* sectionName;
78  const char* keyName;
80  const char* targetPrefName;
82  PRBool prefHasValue;
83  union {
84  PRInt32 intValue;
85  PRBool boolValue;
86  char* stringValue;
87  };
88  };
89 
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);
98 
99 protected:
100  nsresult CopyPreferences(PRBool aReplace);
101  nsresult ParseColor(nsINIParser &aParser, const char* aSectionName,
102  char** aResult);
103  nsresult CopyUserContentSheet(nsINIParser &aParser);
104  nsresult CopyProxySettings(nsINIParser &aParser, nsIPrefBranch* aBranch);
105  nsresult GetInteger(nsINIParser &aParser, const char* aSectionName,
106  const char* aKeyName, PRInt32* aResult);
107 
108  nsresult CopyCookies(PRBool aReplace);
117  nsresult CopyHistory(PRBool aReplace);
118  nsresult CopyHistoryBatched(PRBool aReplace);
128  nsresult CopyBookmarks(PRBool aReplace);
129  nsresult CopyBookmarksBatched(PRBool aReplace);
130  void ClearToolbarFolder(nsINavBookmarksService * aBookmarksService,
131  PRInt64 aToolbarFolder);
132  nsresult ParseBookmarksFolder(nsILineInputStream* aStream,
133  PRInt64 aFolder,
134  PRInt64 aToolbar,
135  nsINavBookmarksService* aBMS);
136 #if defined(XP_WIN) || (defined(XP_UNIX) && !defined(XP_MACOSX))
137  nsresult CopySmartKeywords(nsINavBookmarksService* aBMS,
138  nsIStringBundle* aBundle,
139  PRInt64 aParentFolder);
140 #endif // defined(XP_WIN) || (defined(XP_UNIX) && !defined(XP_MACOSX))
141 
142  void GetOperaProfile(const PRUnichar* aProfile, nsILocalFile** aFile);
143 
144 private:
145  nsCOMPtr<nsILocalFile> mOperaProfile;
146  nsCOMPtr<nsISupportsArray> mProfiles;
147  nsCOMPtr<nsIObserverService> mObserverService;
148 };
149 
151 {
152 public:
153  nsOperaCookieMigrator(nsIInputStream* aSourceStream);
154  virtual ~nsOperaCookieMigrator();
155 
156  nsresult Migrate();
157 
158  typedef enum { BEGIN_DOMAIN_SEGMENT = 0x01,
160  END_DOMAIN_SEGMENT = 0x84 | 0x80, // 0x04 | (1 << 8)
161 
164  END_PATH_SEGMENT = 0x05 | 0x80, // 0x05 | (1 << 8)
165 
169 
171  COOKIE_ID = 0x10,
172  COOKIE_DATA = 0x11,
180  COOKIE_SECURE = 0x19 | 0x80,
182  COOKIE_OTHERFLAG_1 = 0x1B | 0x80,
183  COOKIE_OTHERFLAG_2 = 0x1C | 0x80,
184  COOKIE_OTHERFLAG_3 = 0x20 | 0x80,
185  COOKIE_OTHERFLAG_4 = 0x22 | 0x80,
186  COOKIE_OTHERFLAG_5 = 0x23 | 0x80,
187  COOKIE_OTHERFLAG_6 = 0x24 | 0x80
188  } TAG;
189 
190 protected:
192 
193  nsresult ReadHeader();
194 
195  void SynthesizePath(char** aResult);
196  void SynthesizeDomain(char** aResult);
197  nsresult AddCookieOverride(nsIPermissionManager* aManager);
198  nsresult AddCookie(nsICookieManager2* aManager);
199 
200 private:
201  nsCOMPtr<nsIBinaryInputStream> mStream;
202 
203  nsTArray<char*> mDomainStack;
204  nsTArray<char*> mPathStack;
205 
206  struct Cookie {
207  nsCString id;
208  nsCString data;
209  PRInt32 expiryTime;
210  PRBool isSecure;
211  };
212 
213  PRUint32 mAppVersion;
214  PRUint32 mFileVersion;
215  PRUint16 mTagTypeLength;
216  PRUint16 mPayloadTypeLength;
217  PRBool mCookieOpen;
218  Cookie mCurrCookie;
219  PRUint8 mCurrHandlingInfo;
220 };
221 
222 #endif
223 
static nsresult SetCookieLifetime(void *aTransform, nsIPrefBranch *aBranch)
nsresult CopyCookies(PRBool aReplace)
static nsresult SetWString(void *aTransform, nsIPrefBranch *aBranch)
menuItem id
Definition: FeedWriter.js:971
nsresult(* prefConverter)(void *, nsIPrefBranch *)
nsresult CopyUserContentSheet(nsINIParser &aParser)
nsresult CopyPreferences(PRBool aReplace)
const nsIPrefBranch
static nsresult SetCookieBehavior(void *aTransform, nsIPrefBranch *aBranch)
nsresult CopyBookmarks(PRBool aReplace)
void ClearToolbarFolder(nsINavBookmarksService *aBookmarksService, PRInt64 aToolbarFolder)
nsresult CopyHistory(PRBool aReplace)
static nsresult SetInt(void *aTransform, nsIPrefBranch *aBranch)
nsresult ParseBookmarksFolder(nsILineInputStream *aStream, PRInt64 aFolder, PRInt64 aToolbar, nsINavBookmarksService *aBMS)
static nsresult SetString(void *aTransform, nsIPrefBranch *aBranch)
void GetOperaProfile(const PRUnichar *aProfile, nsILocalFile **aFile)
nsresult ParseColor(nsINIParser &aParser, const char *aSectionName, char **aResult)
const nsIPermissionManager
Definition: pageInfo.js:202
static nsresult SetFile(void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetImageBehavior(void *aTransform, nsIPrefBranch *aBranch)
nsresult GetInteger(nsINIParser &aParser, const char *aSectionName, const char *aKeyName, PRInt32 *aResult)
nsresult CopyHistoryBatched(PRBool aReplace)
nsresult CopyProxySettings(nsINIParser &aParser, nsIPrefBranch *aBranch)
static nsresult SetBool(void *aTransform, nsIPrefBranch *aBranch)
nsresult CopyBookmarksBatched(PRBool aReplace)
observe data
Definition: FeedWriter.js:1329
NS_DECL_NSIBROWSERPROFILEMIGRATOR NS_DECL_NSINAVHISTORYBATCHCALLBACK NS_DECL_ISUPPORTS nsOperaProfileMigrator()