Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsWebBrowserPersist_h__ |
michael@0 | 8 | #define nsWebBrowserPersist_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsWeakReference.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsIInterfaceRequestor.h" |
michael@0 | 14 | #include "nsIMIMEService.h" |
michael@0 | 15 | #include "nsIStreamListener.h" |
michael@0 | 16 | #include "nsIOutputStream.h" |
michael@0 | 17 | #include "nsIInputStream.h" |
michael@0 | 18 | #include "nsIChannel.h" |
michael@0 | 19 | #include "nsIStyleSheet.h" |
michael@0 | 20 | #include "nsIDocumentEncoder.h" |
michael@0 | 21 | #include "nsITransport.h" |
michael@0 | 22 | #include "nsIProgressEventSink.h" |
michael@0 | 23 | #include "nsIFile.h" |
michael@0 | 24 | #include "nsIWebProgressListener2.h" |
michael@0 | 25 | |
michael@0 | 26 | #include "nsClassHashtable.h" |
michael@0 | 27 | #include "nsHashKeys.h" |
michael@0 | 28 | #include "nsTArray.h" |
michael@0 | 29 | |
michael@0 | 30 | #include "nsCWebBrowserPersist.h" |
michael@0 | 31 | |
michael@0 | 32 | class nsEncoderNodeFixup; |
michael@0 | 33 | class nsIStorageStream; |
michael@0 | 34 | |
michael@0 | 35 | struct CleanupData; |
michael@0 | 36 | struct DocData; |
michael@0 | 37 | struct OutputData; |
michael@0 | 38 | struct UploadData; |
michael@0 | 39 | struct URIData; |
michael@0 | 40 | |
michael@0 | 41 | class nsWebBrowserPersist : public nsIInterfaceRequestor, |
michael@0 | 42 | public nsIWebBrowserPersist, |
michael@0 | 43 | public nsIStreamListener, |
michael@0 | 44 | public nsIProgressEventSink, |
michael@0 | 45 | public nsSupportsWeakReference |
michael@0 | 46 | { |
michael@0 | 47 | friend class nsEncoderNodeFixup; |
michael@0 | 48 | |
michael@0 | 49 | // Public members |
michael@0 | 50 | public: |
michael@0 | 51 | nsWebBrowserPersist(); |
michael@0 | 52 | |
michael@0 | 53 | NS_DECL_ISUPPORTS |
michael@0 | 54 | NS_DECL_NSIINTERFACEREQUESTOR |
michael@0 | 55 | NS_DECL_NSICANCELABLE |
michael@0 | 56 | NS_DECL_NSIWEBBROWSERPERSIST |
michael@0 | 57 | NS_DECL_NSIREQUESTOBSERVER |
michael@0 | 58 | NS_DECL_NSISTREAMLISTENER |
michael@0 | 59 | NS_DECL_NSIPROGRESSEVENTSINK |
michael@0 | 60 | |
michael@0 | 61 | // Protected members |
michael@0 | 62 | protected: |
michael@0 | 63 | virtual ~nsWebBrowserPersist(); |
michael@0 | 64 | nsresult CloneNodeWithFixedUpAttributes( |
michael@0 | 65 | nsIDOMNode *aNodeIn, bool *aSerializeCloneKids, nsIDOMNode **aNodeOut); |
michael@0 | 66 | nsresult SaveURIInternal( |
michael@0 | 67 | nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer, |
michael@0 | 68 | nsIInputStream *aPostData, const char *aExtraHeaders, nsIURI *aFile, |
michael@0 | 69 | bool aCalcFileExt, bool aIsPrivate); |
michael@0 | 70 | nsresult SaveChannelInternal( |
michael@0 | 71 | nsIChannel *aChannel, nsIURI *aFile, bool aCalcFileExt); |
michael@0 | 72 | nsresult SaveDocumentInternal( |
michael@0 | 73 | nsIDOMDocument *aDocument, nsIURI *aFile, nsIURI *aDataPath); |
michael@0 | 74 | nsresult SaveDocuments(); |
michael@0 | 75 | nsresult GetDocEncoderContentType( |
michael@0 | 76 | nsIDOMDocument *aDocument, const char16_t *aContentType, |
michael@0 | 77 | char16_t **aRealContentType); |
michael@0 | 78 | nsresult GetExtensionForContentType( |
michael@0 | 79 | const char16_t *aContentType, char16_t **aExt); |
michael@0 | 80 | nsresult GetDocumentExtension(nsIDOMDocument *aDocument, char16_t **aExt); |
michael@0 | 81 | |
michael@0 | 82 | // Private members |
michael@0 | 83 | private: |
michael@0 | 84 | void Cleanup(); |
michael@0 | 85 | void CleanupLocalFiles(); |
michael@0 | 86 | nsresult GetValidURIFromObject(nsISupports *aObject, nsIURI **aURI) const; |
michael@0 | 87 | nsresult GetLocalFileFromURI(nsIURI *aURI, nsIFile **aLocalFile) const; |
michael@0 | 88 | nsresult AppendPathToURI(nsIURI *aURI, const nsAString & aPath) const; |
michael@0 | 89 | nsresult MakeAndStoreLocalFilenameInURIMap( |
michael@0 | 90 | nsIURI *aURI, bool aNeedsPersisting, URIData **aData); |
michael@0 | 91 | nsresult MakeOutputStream( |
michael@0 | 92 | nsIURI *aFile, nsIOutputStream **aOutputStream); |
michael@0 | 93 | nsresult MakeOutputStreamFromFile( |
michael@0 | 94 | nsIFile *aFile, nsIOutputStream **aOutputStream); |
michael@0 | 95 | nsresult MakeOutputStreamFromURI(nsIURI *aURI, nsIOutputStream **aOutStream); |
michael@0 | 96 | nsresult CreateChannelFromURI(nsIURI *aURI, nsIChannel **aChannel); |
michael@0 | 97 | nsresult StartUpload(nsIStorageStream *aOutStream, nsIURI *aDestinationURI, |
michael@0 | 98 | const nsACString &aContentType); |
michael@0 | 99 | nsresult StartUpload(nsIInputStream *aInputStream, nsIURI *aDestinationURI, |
michael@0 | 100 | const nsACString &aContentType); |
michael@0 | 101 | nsresult CalculateAndAppendFileExt(nsIURI *aURI, nsIChannel *aChannel, |
michael@0 | 102 | nsIURI *aOriginalURIWithExtension); |
michael@0 | 103 | nsresult CalculateUniqueFilename(nsIURI *aURI); |
michael@0 | 104 | nsresult MakeFilenameFromURI( |
michael@0 | 105 | nsIURI *aURI, nsString &aFilename); |
michael@0 | 106 | nsresult StoreURI( |
michael@0 | 107 | const char *aURI, |
michael@0 | 108 | bool aNeedsPersisting = true, |
michael@0 | 109 | URIData **aData = nullptr); |
michael@0 | 110 | nsresult StoreURI( |
michael@0 | 111 | nsIURI *aURI, |
michael@0 | 112 | bool aNeedsPersisting = true, |
michael@0 | 113 | URIData **aData = nullptr); |
michael@0 | 114 | nsresult StoreURIAttributeNS( |
michael@0 | 115 | nsIDOMNode *aNode, const char *aNamespaceURI, const char *aAttribute, |
michael@0 | 116 | bool aNeedsPersisting = true, |
michael@0 | 117 | URIData **aData = nullptr); |
michael@0 | 118 | nsresult StoreURIAttribute( |
michael@0 | 119 | nsIDOMNode *aNode, const char *aAttribute, |
michael@0 | 120 | bool aNeedsPersisting = true, |
michael@0 | 121 | URIData **aData = nullptr) |
michael@0 | 122 | { |
michael@0 | 123 | return StoreURIAttributeNS(aNode, "", aAttribute, aNeedsPersisting, aData); |
michael@0 | 124 | } |
michael@0 | 125 | bool DocumentEncoderExists(const char16_t *aContentType); |
michael@0 | 126 | |
michael@0 | 127 | nsresult GetNodeToFixup(nsIDOMNode *aNodeIn, nsIDOMNode **aNodeOut); |
michael@0 | 128 | nsresult FixupURI(nsAString &aURI); |
michael@0 | 129 | nsresult FixupNodeAttributeNS(nsIDOMNode *aNode, const char *aNamespaceURI, const char *aAttribute); |
michael@0 | 130 | nsresult FixupNodeAttribute(nsIDOMNode *aNode, const char *aAttribute) |
michael@0 | 131 | { |
michael@0 | 132 | return FixupNodeAttributeNS(aNode, "", aAttribute); |
michael@0 | 133 | } |
michael@0 | 134 | nsresult FixupAnchor(nsIDOMNode *aNode); |
michael@0 | 135 | nsresult FixupXMLStyleSheetLink(nsIDOMProcessingInstruction *aPI, const nsAString &aHref); |
michael@0 | 136 | nsresult GetXMLStyleSheetLink(nsIDOMProcessingInstruction *aPI, nsAString &aHref); |
michael@0 | 137 | |
michael@0 | 138 | nsresult StoreAndFixupStyleSheet(nsIStyleSheet *aStyleSheet); |
michael@0 | 139 | nsresult SaveDocumentWithFixup( |
michael@0 | 140 | nsIDOMDocument *pDocument, nsIDocumentEncoderNodeFixup *pFixup, |
michael@0 | 141 | nsIURI *aFile, bool aReplaceExisting, const nsACString &aFormatType, |
michael@0 | 142 | const nsCString &aSaveCharset, uint32_t aFlags); |
michael@0 | 143 | nsresult SaveSubframeContent( |
michael@0 | 144 | nsIDOMDocument *aFrameContent, URIData *aData); |
michael@0 | 145 | nsresult SetDocumentBase(nsIDOMDocument *aDocument, nsIURI *aBaseURI); |
michael@0 | 146 | nsresult SendErrorStatusChange( |
michael@0 | 147 | bool aIsReadError, nsresult aResult, nsIRequest *aRequest, nsIURI *aURI); |
michael@0 | 148 | nsresult OnWalkDOMNode(nsIDOMNode *aNode); |
michael@0 | 149 | |
michael@0 | 150 | nsresult FixRedirectedChannelEntry(nsIChannel *aNewChannel); |
michael@0 | 151 | |
michael@0 | 152 | void EndDownload(nsresult aResult = NS_OK); |
michael@0 | 153 | nsresult SaveGatheredURIs(nsIURI *aFileAsURI); |
michael@0 | 154 | bool SerializeNextFile(); |
michael@0 | 155 | void CalcTotalProgress(); |
michael@0 | 156 | |
michael@0 | 157 | void SetApplyConversionIfNeeded(nsIChannel *aChannel); |
michael@0 | 158 | |
michael@0 | 159 | // Hash table enumerators |
michael@0 | 160 | static PLDHashOperator EnumPersistURIs( |
michael@0 | 161 | const nsACString &aKey, URIData *aData, void* aClosure); |
michael@0 | 162 | static PLDHashOperator EnumCleanupOutputMap( |
michael@0 | 163 | nsISupports *aKey, OutputData *aData, void* aClosure); |
michael@0 | 164 | static PLDHashOperator EnumCleanupUploadList( |
michael@0 | 165 | nsISupports *aKey, UploadData *aData, void* aClosure); |
michael@0 | 166 | static PLDHashOperator EnumCalcProgress( |
michael@0 | 167 | nsISupports *aKey, OutputData *aData, void* aClosure); |
michael@0 | 168 | static PLDHashOperator EnumCalcUploadProgress( |
michael@0 | 169 | nsISupports *aKey, UploadData *aData, void* aClosure); |
michael@0 | 170 | static PLDHashOperator EnumFixRedirect( |
michael@0 | 171 | nsISupports *aKey, OutputData *aData, void* aClosure); |
michael@0 | 172 | static PLDHashOperator EnumCountURIsToPersist( |
michael@0 | 173 | const nsACString &aKey, URIData *aData, void* aClosure); |
michael@0 | 174 | |
michael@0 | 175 | nsCOMPtr<nsIURI> mCurrentDataPath; |
michael@0 | 176 | bool mCurrentDataPathIsRelative; |
michael@0 | 177 | nsCString mCurrentRelativePathToData; |
michael@0 | 178 | nsCOMPtr<nsIURI> mCurrentBaseURI; |
michael@0 | 179 | nsCString mCurrentCharset; |
michael@0 | 180 | nsCOMPtr<nsIURI> mTargetBaseURI; |
michael@0 | 181 | uint32_t mCurrentThingsToPersist; |
michael@0 | 182 | |
michael@0 | 183 | nsCOMPtr<nsIMIMEService> mMIMEService; |
michael@0 | 184 | nsCOMPtr<nsIURI> mURI; |
michael@0 | 185 | nsCOMPtr<nsIWebProgressListener> mProgressListener; |
michael@0 | 186 | /** |
michael@0 | 187 | * Progress listener for 64-bit values; this is the same object as |
michael@0 | 188 | * mProgressListener, but is a member to avoid having to qi it for each |
michael@0 | 189 | * progress notification. |
michael@0 | 190 | */ |
michael@0 | 191 | nsCOMPtr<nsIWebProgressListener2> mProgressListener2; |
michael@0 | 192 | nsCOMPtr<nsIProgressEventSink> mEventSink; |
michael@0 | 193 | nsClassHashtable<nsISupportsHashKey, OutputData> mOutputMap; |
michael@0 | 194 | nsClassHashtable<nsISupportsHashKey, UploadData> mUploadList; |
michael@0 | 195 | nsClassHashtable<nsCStringHashKey, URIData> mURIMap; |
michael@0 | 196 | nsTArray<DocData*> mDocList; |
michael@0 | 197 | nsTArray<CleanupData*> mCleanupList; |
michael@0 | 198 | nsTArray<nsCString> mFilenameList; |
michael@0 | 199 | bool mFirstAndOnlyUse; |
michael@0 | 200 | bool mCancel; |
michael@0 | 201 | bool mJustStartedLoading; |
michael@0 | 202 | bool mCompleted; |
michael@0 | 203 | bool mStartSaving; |
michael@0 | 204 | bool mReplaceExisting; |
michael@0 | 205 | bool mSerializingOutput; |
michael@0 | 206 | bool mIsPrivate; |
michael@0 | 207 | uint32_t mPersistFlags; |
michael@0 | 208 | nsresult mPersistResult; |
michael@0 | 209 | int64_t mTotalCurrentProgress; |
michael@0 | 210 | int64_t mTotalMaxProgress; |
michael@0 | 211 | int16_t mWrapColumn; |
michael@0 | 212 | uint32_t mEncodingFlags; |
michael@0 | 213 | nsString mContentType; |
michael@0 | 214 | }; |
michael@0 | 215 | |
michael@0 | 216 | // Helper class does node fixup during persistence |
michael@0 | 217 | class nsEncoderNodeFixup : public nsIDocumentEncoderNodeFixup |
michael@0 | 218 | { |
michael@0 | 219 | public: |
michael@0 | 220 | nsEncoderNodeFixup(); |
michael@0 | 221 | |
michael@0 | 222 | NS_DECL_ISUPPORTS |
michael@0 | 223 | NS_IMETHOD FixupNode(nsIDOMNode *aNode, bool *aSerializeCloneKids, nsIDOMNode **aOutNode); |
michael@0 | 224 | |
michael@0 | 225 | nsWebBrowserPersist *mWebBrowserPersist; |
michael@0 | 226 | |
michael@0 | 227 | protected: |
michael@0 | 228 | virtual ~nsEncoderNodeFixup(); |
michael@0 | 229 | }; |
michael@0 | 230 | |
michael@0 | 231 | #endif |