1 : #ifndef nsPlacesImportExportService_h__
2 : #define nsPlacesImportExportService_h__
3 :
4 : #include "nsIPlacesImportExportService.h"
5 :
6 : #include "nsCOMPtr.h"
7 : #include "nsILocalFile.h"
8 : #include "nsIOutputStream.h"
9 : #include "nsIFaviconService.h"
10 : #include "nsIAnnotationService.h"
11 : #include "mozIAsyncLivemarks.h"
12 : #include "nsINavHistoryService.h"
13 : #include "nsINavBookmarksService.h"
14 : #include "nsIChannel.h"
15 :
16 : class nsPlacesImportExportService : public nsIPlacesImportExportService,
17 : public nsINavHistoryBatchCallback
18 : {
19 : public:
20 : NS_DECL_ISUPPORTS
21 : NS_DECL_NSIPLACESIMPORTEXPORTSERVICE
22 : NS_DECL_NSINAVHISTORYBATCHCALLBACK
23 : nsPlacesImportExportService();
24 :
25 : /**
26 : * Obtains the service's object.
27 : */
28 : static nsPlacesImportExportService* GetSingleton();
29 :
30 : /**
31 : * Initializes the service's object. This should only be called once.
32 : */
33 : nsresult Init();
34 :
35 : private:
36 : static nsPlacesImportExportService* gImportExportService;
37 : virtual ~nsPlacesImportExportService();
38 :
39 : protected:
40 : nsCOMPtr<nsIFaviconService> mFaviconService;
41 : nsCOMPtr<nsIAnnotationService> mAnnotationService;
42 : nsCOMPtr<nsINavBookmarksService> mBookmarksService;
43 : nsCOMPtr<nsINavHistoryService> mHistoryService;
44 : nsCOMPtr<mozIAsyncLivemarks> mLivemarkService;
45 :
46 : nsCOMPtr<nsIChannel> mImportChannel;
47 : bool mIsImportDefaults;
48 :
49 : nsresult ImportHTMLFromFileInternal(nsILocalFile* aFile, bool aAllowRootChanges,
50 : PRInt64 aFolder, bool aIsImportDefaults);
51 : nsresult ImportHTMLFromURIInternal(nsIURI* aURI, bool aAllowRootChanges,
52 : PRInt64 aFolder, bool aIsImportDefaults);
53 : nsresult WriteContainer(nsINavHistoryResultNode* aFolder, const nsACString& aIndent, nsIOutputStream* aOutput);
54 : nsresult WriteContainerHeader(nsINavHistoryResultNode* aFolder, const nsACString& aIndent, nsIOutputStream* aOutput);
55 : nsresult WriteTitle(nsINavHistoryResultNode* aItem, nsIOutputStream* aOutput);
56 : nsresult WriteItem(nsINavHistoryResultNode* aItem, const nsACString& aIndent, nsIOutputStream* aOutput);
57 : nsresult WriteLivemark(nsINavHistoryResultNode* aFolder, const nsACString& aIndent, nsIOutputStream* aOutput);
58 : nsresult WriteContainerContents(nsINavHistoryResultNode* aFolder, const nsACString& aIndent, nsIOutputStream* aOutput);
59 : nsresult WriteSeparator(nsINavHistoryResultNode* aItem, const nsACString& aIndent, nsIOutputStream* aOutput);
60 : nsresult WriteDescription(PRInt64 aId, PRInt32 aType, nsIOutputStream* aOutput);
61 :
62 40 : inline nsresult EnsureServiceState() {
63 40 : NS_ENSURE_STATE(mHistoryService);
64 40 : NS_ENSURE_STATE(mFaviconService);
65 40 : NS_ENSURE_STATE(mAnnotationService);
66 40 : NS_ENSURE_STATE(mBookmarksService);
67 40 : NS_ENSURE_STATE(mLivemarkService);
68 40 : return NS_OK;
69 : }
70 : };
71 :
72 : #endif // nsPlacesImportExportService_h__
|