diff --git a/mozilla/content/base/public/nsIDiskDocument.idl b/mozilla/content/base/public/nsIDiskDocument.idl new file mode 100644 index 00000000000..06c5d70bb40 --- /dev/null +++ b/mozilla/content/base/public/nsIDiskDocument.idl @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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. + * + * Original Author: Simon Fraser (sfraser@netscape.com) + * + * Contributor(s): + */ + +#include "nsISupports.idl" +#include "nsIFile.idl" + +// {dd038282-d5a2-11d4-aedb-e1c4b1c8b9fc} +[scriptable, uuid(dd038282-d5a2-11d4-aedb-e1c4b1c8b9fc)] +interface nsIDiskDocument : nsISupports +{ + /** An nsIFile pointing to the location of the file on disk. May be null if + * this document has not been saved yet + */ + readonly attribute nsIFile fileSpec; + + /** The modification count for the document. A +ve mod count indicates + * that the document is dirty, and needs saving. + */ + readonly attribute long modificationCount; + + /** Initialize the document output. This may be called on document + * creation, or lazily before the first save. For a document read + * in from disk, it should be called on document instantiation. + * + * @param aFile nsIFile for the file, if a disk version + * of the file exists already. Otherwise nsnull. + */ + void InitDiskDocument(in nsIFile aFile); + + + /** Save the file to disk. This will be called after the caller has + * displayed a put file dialog, which the user confirmed. The internal + * fileSpec of the document is only updated with the given fileSpec if inSaveCopy == PR_FALSE. + * + * @param aFile File to which to stream the document. + * @param aReplaceExisting true if replacing an existing file, otherwise false. + * If false and aFile exists, SaveFile returns an error. + * @param aSaveCopy True to save a copy of the file, without changing the file + * referenced internally. + * @param aFileType Mime type to save (text/plain or text/html) + * @param aFileCharset Charset to save the document in. If this is an empty + * string, or "UCS2", then the doc will be saved as Unicode. + * @param aSaveFlags Flags used by the document encoder (see nsIDocumentEncoder). + * @param inWrapColumn Wrap column, assuming that flags specify wrapping. + */ + void SaveFile(in nsIFile aFile, in boolean aReplaceExisting, in boolean aSaveCopy, + in wstring aFileType, in wstring aFileCharset, in unsigned long aSaveFlags, + in unsigned long aWrapColumn); + + /** Reset the modification count for the document. This marks the documents as + * 'clean' and not in need of saving. + */ + void ResetModificationCount(); + + /** Increment the modification count for the document by the given + * amount (which may be -ve). + */ + void IncrementModificationCount(in long aNumMods); + +}; + + diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index c39ddae1db4..d0acf44a551 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -74,8 +74,7 @@ #include "nsIHTMLContentSink.h" #include "nsIParser.h" #include "nsParserCIID.h" -#include "nsFileSpec.h" -#include "nsFileStream.h" +#include "nsIFileStreams.h" #include "nsRange.h" #include "nsIDOMText.h" @@ -624,7 +623,6 @@ nsDocument::nsDocument() mChildNodes = nsnull; mWordBreaker = nsnull; mModCount = 0; - mFileSpec = nsnull; mPrincipal = nsnull; mNextContentID = NS_CONTENT_ID_COUNTER_BASE; mDTD = 0; @@ -711,9 +709,7 @@ nsDocument::~nsDocument() NS_IF_RELEASE(mWordBreaker); NS_IF_RELEASE(mDTD); - - delete mFileSpec; - + delete mBoxObjectTable; } @@ -3365,20 +3361,19 @@ NS_IMETHODIMP nsDocument::FindNext(const nsAReadableString& aSearchStr, PRBool a return NS_ERROR_FAILURE; } -/** - * nsIDiskDocument methods - */ NS_IMETHODIMP -nsDocument::InitDiskDocument(nsFileSpec* aFileSpec) +nsDocument::InitDiskDocument(nsIFile *aFile) { - mFileSpec = nsnull; + // aFile may be nsnull here + mFileSpec = nsnull; // delete if we have one - if (aFileSpec) + if (aFile) { - mFileSpec = new nsFileSpec(*aFileSpec); - if (!mFileSpec) - return NS_ERROR_OUT_OF_MEMORY; + // we clone the nsIFile here, rather than just holding onto a ref, + // in case the caller does something to aFile later + nsresult rv = aFile->Clone(getter_AddRefs(mFileSpec)); + if (NS_FAILED(rv)) return rv; } mModCount = 0; @@ -3388,55 +3383,53 @@ nsDocument::InitDiskDocument(nsFileSpec* aFileSpec) NS_IMETHODIMP -nsDocument::SaveFile(nsFileSpec* aFileSpec, - PRBool aReplaceExisting, - PRBool aSaveCopy, - const nsString& aFormatType, - const nsString& aSaveCharset, - PRUint32 aFlags, - PRUint32 aWrapColumn) +nsDocument::SaveFile( nsIFile* aFile, + PRBool aReplaceExisting, + PRBool aSaveCopy, + const PRUnichar* aFileType, // MIME type of file to save + const PRUnichar* aFileCharset, + PRUint32 aSaveFlags, + PRUint32 aWrapColumn) { - if (!aFileSpec) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aFile); + NS_ENSURE_ARG_POINTER(aFileType); + NS_ENSURE_ARG_POINTER(aFileCharset); nsresult rv = NS_OK; // if we're not replacing an existing file but the file // exists, somethine is wrong - if (!aReplaceExisting && aFileSpec->Exists()) + PRBool fileExists; + rv = aFile->Exists(&fileExists); + if (NS_FAILED(rv)) return rv; + + if (!aReplaceExisting && fileExists) return NS_ERROR_FAILURE; // where are the file I/O errors? - nsOutputFileStream stream(*aFileSpec); - // if the stream didn't open, something went wrong - if (!stream.is_open()) - return NS_BASE_STREAM_CLOSED; - - // Get a document encoder instance: - nsCOMPtr encoder; - char* contractid = (char *)nsMemory::Alloc(strlen(NS_DOC_ENCODER_CONTRACTID_BASE) - + aFormatType.Length() + 1); - if (! contractid) - return NS_ERROR_OUT_OF_MEMORY; - strcpy(contractid, NS_DOC_ENCODER_CONTRACTID_BASE); - char* type = aFormatType.ToNewCString(); - strcat(contractid, type); - nsCRT::free(type); - rv = nsComponentManager::CreateInstance(contractid, - nsnull, - NS_GET_IID(nsIDocumentEncoder), - getter_AddRefs(encoder)); - nsCRT::free(contractid); + + nsCOMPtr outputStream = do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = outputStream->Init(aFile, -1, -1); + if (NS_FAILED(rv)) return rv; + + // Get a document encoder instance + nsCAutoString contractID(NS_DOC_ENCODER_CONTRACTID_BASE); + contractID.AppendWithConversion(aFileType); + + nsCOMPtr encoder = do_CreateInstance(contractID, &rv); + if (NS_FAILED(rv)) + return rv; + + nsAutoString fileType(aFileType); // sucky copy + rv = encoder->Init(this, fileType, aSaveFlags); if (NS_FAILED(rv)) return rv; - rv = encoder->Init(this, aFormatType, aFlags); - if (NS_FAILED(rv)) - return rv; - - if (aFlags & nsIDocumentEncoder::OutputWrap) + if (aSaveFlags & nsIDocumentEncoder::OutputWrap) encoder->SetWrapColumn(aWrapColumn); - nsAutoString charsetStr(aSaveCharset); + nsAutoString charsetStr(aFileCharset); if (charsetStr.Length() == 0) { rv = GetDocumentCharacterSet(charsetStr); @@ -3446,7 +3439,7 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec, } encoder->SetCharset(charsetStr); - rv = encoder->EncodeToStream(stream.GetIStream()); + rv = encoder->EncodeToStream(outputStream); if (NS_SUCCEEDED(rv)) { @@ -3454,13 +3447,13 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec, // store the new fileSpec in the doc if (!aSaveCopy) { - delete mFileSpec; - mFileSpec = new nsFileSpec(*aFileSpec); - if (!mFileSpec) - return NS_ERROR_OUT_OF_MEMORY; + // we clone the nsIFile here, rather than just holding onto a ref, + // in case the caller does something to aFile later + nsresult rv = aFile->Clone(getter_AddRefs(mFileSpec)); + if (NS_FAILED(rv)) return rv; // and mark the document as clean - ResetModCount(); + ResetModificationCount(); } } @@ -3468,15 +3461,15 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec, } NS_IMETHODIMP -nsDocument::GetFileSpec(nsFileSpec& aFileSpec) +nsDocument::GetFileSpec(nsIFile * *aFileSpec) { - if (mFileSpec) - { - aFileSpec = *mFileSpec; - return NS_OK; - } + NS_ENSURE_ARG_POINTER(aFileSpec); - return NS_ERROR_NOT_INITIALIZED; + if (!mFileSpec) + return NS_ERROR_NOT_INITIALIZED; + + NS_IF_ADDREF(*aFileSpec = mFileSpec); + return NS_OK; } NS_IMETHODIMP @@ -3518,7 +3511,7 @@ nsDocument::GetBindingManager(nsIBindingManager** aResult) NS_IMETHODIMP -nsDocument::GetModCount(PRInt32 *outModCount) +nsDocument::GetModificationCount(PRInt32 *outModCount) { if (!outModCount) return NS_ERROR_NULL_POINTER; @@ -3529,14 +3522,14 @@ nsDocument::GetModCount(PRInt32 *outModCount) NS_IMETHODIMP -nsDocument::ResetModCount() +nsDocument::ResetModificationCount() { mModCount = 0; return NS_OK; } NS_IMETHODIMP -nsDocument::IncrementModCount(PRInt32 aNumMods) +nsDocument::IncrementModificationCount(PRInt32 aNumMods) { mModCount += aNumMods; //NS_ASSERTION(mModCount >= 0, "Modification count went negative"); diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index abd11fd06be..eb6cb91b248 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -411,19 +411,7 @@ public: NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent); // nsIDiskDocument inteface - NS_IMETHOD InitDiskDocument(nsFileSpec *aFileSpec); - NS_IMETHOD SaveFile(nsFileSpec* aFileSpec, - PRBool aReplaceExisting, - PRBool aSaveCopy, - const nsString& aSaveFileType, - const nsString& aSaveCharset, - PRUint32 aFlags, - PRUint32 aWrapColumn); - - NS_IMETHOD GetFileSpec(nsFileSpec& aFileSpec); - NS_IMETHOD GetModCount(PRInt32 *outModCount); - NS_IMETHOD ResetModCount(); - NS_IMETHOD IncrementModCount(PRInt32 aNumMods); + NS_DECL_NSIDISKDOCUMENT // nsIDOMEventTarget interface NS_IMETHOD AddEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, @@ -503,8 +491,8 @@ protected: PRInt32 mNextContentID; // disk file members - nsFileSpec* mFileSpec; - PRInt32 mModCount; + nsCOMPtr mFileSpec; + PRInt32 mModCount; nsIDTD* mDTD; diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index f64b1c48f14..0f8fac17c1d 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -1530,7 +1530,7 @@ nsEditor::GetDocumentModified(PRBool *outDocModified) if (NS_FAILED(rv)) return rv; PRInt32 modCount = 0; - diskDoc->GetModCount(&modCount); + diskDoc->GetModificationCount(&modCount); *outDocModified = (modCount != 0); return NS_OK; @@ -1602,7 +1602,7 @@ nsEditor::GetWrapWidth(PRInt32 *aWrapColumn) } NS_IMETHODIMP -nsEditor::SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting, +nsEditor::SaveFile(nsIFile *aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormat) { if (!aFileSpec) @@ -1633,9 +1633,8 @@ nsEditor::SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting, PRInt32 wrapColumn = 72; GetWrapWidth(&wrapColumn); - nsAutoString useDocCharset; rv = diskDoc->SaveFile(aFileSpec, aReplaceExisting, aSaveCopy, - aFormat, useDocCharset, flags, wrapColumn); + aFormat.GetUnicode(), NS_LITERAL_STRING(""), flags, wrapColumn); if (NS_SUCCEEDED(rv)) DoAfterDocumentSave(); @@ -4288,7 +4287,7 @@ NS_IMETHODIMP nsEditor::IncDocModCount(PRInt32 inNumMods) if (!doc) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr diskDoc = do_QueryInterface(doc); if (diskDoc) - diskDoc->IncrementModCount(inNumMods); + diskDoc->IncrementModificationCount(inNumMods); NotifyDocumentListeners(eDocumentStateChanged); return NS_OK; @@ -4305,7 +4304,7 @@ NS_IMETHODIMP nsEditor::GetDocModCount(PRInt32 &outModCount) if (!doc) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr diskDoc = do_QueryInterface(doc); if (diskDoc) - diskDoc->GetModCount(&outModCount); + diskDoc->GetModificationCount(&outModCount); return NS_OK; } @@ -4319,7 +4318,7 @@ NS_IMETHODIMP nsEditor::ResetDocModCount() if (!doc) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr diskDoc = do_QueryInterface(doc); if (diskDoc) - diskDoc->ResetModCount(); + diskDoc->ResetModificationCount(); NotifyDocumentListeners(eDocumentStateChanged); return NS_OK; diff --git a/mozilla/editor/base/nsEditor.h b/mozilla/editor/base/nsEditor.h index 37441a75107..9c2ed1ca15c 100644 --- a/mozilla/editor/base/nsEditor.h +++ b/mozilla/editor/base/nsEditor.h @@ -41,7 +41,6 @@ #include "nsIComponentManager.h" #include "nsISupportsArray.h" #include "nsIEditProperty.h" -#include "nsIFileSpec.h" #include "nsIDOMCharacterData.h" #include "nsICSSStyleSheet.h" #include "nsIDTD.h" @@ -69,7 +68,7 @@ class nsILocale; class IMETextTxn; class AddStyleSheetTxn; class RemoveStyleSheetTxn; -class nsFileSpec; +class nsIFile; class nsISelectionController; @@ -246,7 +245,7 @@ public: NS_IMETHOD GetDocumentModified(PRBool *outDocModified); NS_IMETHOD GetDocumentCharacterSet(PRUnichar** characterSet); NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet); - NS_IMETHOD SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormat); + NS_IMETHOD SaveFile(nsIFile *aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormat); // these are pure virtual in this base class NS_IMETHOD Cut() = 0; diff --git a/mozilla/editor/base/nsHTMLEditorLog.cpp b/mozilla/editor/base/nsHTMLEditorLog.cpp index 66e7445c024..5108a87c663 100644 --- a/mozilla/editor/base/nsHTMLEditorLog.cpp +++ b/mozilla/editor/base/nsHTMLEditorLog.cpp @@ -40,9 +40,10 @@ nsHTMLEditorLog::nsHTMLEditorLog() { - mRefCnt = 0; mLocked = -1; mEditorTxnLog = 0; + + NS_INIT_ISUPPORTS(); } nsHTMLEditorLog::~nsHTMLEditorLog() @@ -50,32 +51,14 @@ nsHTMLEditorLog::~nsHTMLEditorLog() StopLogging(); } -NS_IMPL_ADDREF_INHERITED(nsHTMLEditorLog, nsHTMLEditor); -NS_IMPL_RELEASE_INHERITED(nsHTMLEditorLog, nsHTMLEditor); - -NS_IMETHODIMP -nsHTMLEditorLog::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (!aInstancePtr) - return NS_ERROR_NULL_POINTER; - - *aInstancePtr = nsnull; - - if (aIID.Equals(NS_GET_IID(nsIEditorLogging))) { - *aInstancePtr = (void*)(nsIEditorLogging*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - - return nsHTMLEditor::QueryInterface(aIID, aInstancePtr); -} +NS_IMPL_ISUPPORTS_INHERITED(nsHTMLEditorLog, nsHTMLEditor, nsIEditorLogging); NS_IMETHODIMP nsHTMLEditorLog::SetInlineProperty(nsIAtom *aProperty, const nsString *aAttribute, const nsString *aValue) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { nsAutoString propStr; @@ -103,7 +86,7 @@ nsHTMLEditorLog::SetParagraphFormat(const nsString& aParagraphFormat) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.SetParagraphFormat(\""); @@ -121,7 +104,7 @@ nsHTMLEditorLog::RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttri { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { nsAutoString propStr; @@ -146,7 +129,7 @@ nsHTMLEditorLog::DeleteSelection(nsIEditor::EDirection aAction) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.DeleteSelection("); @@ -164,7 +147,7 @@ nsHTMLEditorLog::InsertText(const PRUnichar* aStringToInsert) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); @@ -184,7 +167,7 @@ nsHTMLEditorLog::InsertLineBreak() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.InsertBreak();\n"); @@ -199,7 +182,7 @@ nsHTMLEditorLog::Undo(PRUint32 aCount) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.Undo();\n"); Flush(); @@ -213,7 +196,7 @@ nsHTMLEditorLog::Redo(PRUint32 aCount) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.Redo();\n"); Flush(); @@ -227,7 +210,7 @@ nsHTMLEditorLog::BeginTransaction() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.BeginBatchChanges();\n"); Flush(); @@ -241,7 +224,7 @@ nsHTMLEditorLog::EndTransaction() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.EndBatchChanges();\n"); Flush(); @@ -255,7 +238,7 @@ nsHTMLEditorLog::SelectAll() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SelectAll();\n"); Flush(); @@ -269,7 +252,7 @@ nsHTMLEditorLog::BeginningOfDocument() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.BeginningOfDocument();\n"); Flush(); @@ -283,7 +266,7 @@ nsHTMLEditorLog::EndOfDocument() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.EndOfDocument();\n"); Flush(); @@ -297,7 +280,7 @@ nsHTMLEditorLog::Cut() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.Cut();\n"); @@ -312,7 +295,7 @@ nsHTMLEditorLog::Copy() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.Copy();\n"); @@ -327,7 +310,7 @@ nsHTMLEditorLog::Paste(PRInt32 aSelectionType) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.Paste();\n"); @@ -342,7 +325,7 @@ nsHTMLEditorLog::PasteAsQuotation(PRInt32 aSelectionType) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.PasteAsQuotation();\n"); @@ -357,7 +340,7 @@ nsHTMLEditorLog::PasteAsPlaintextQuotation(PRInt32 aSelectionType) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.PasteAsQuotation();\n"); @@ -373,7 +356,7 @@ nsHTMLEditorLog::PasteAsCitedQuotation(const nsString& aCitation, { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.PasteAsCitedQuotation(\""); @@ -391,7 +374,7 @@ nsHTMLEditorLog::InsertAsQuotation(const nsString& aQuotedText, { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.InsertAsQuotation(\""); @@ -409,7 +392,7 @@ nsHTMLEditorLog::InsertAsPlaintextQuotation(const nsString& aQuotedText, { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.InsertAsQuotation(\""); @@ -430,7 +413,7 @@ nsHTMLEditorLog::InsertAsCitedQuotation(const nsString& aQuotedText, { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.InsertAsCitedQuotation(\""); @@ -450,7 +433,7 @@ nsHTMLEditorLog::SetBackgroundColor(const nsString& aColor) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SetBackgroundColor(\""); PrintUnicode(aColor); @@ -466,7 +449,7 @@ nsHTMLEditorLog::SetBodyAttribute(const nsString& aAttr, const nsString& aValue) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SetBodyAttribute(\""); PrintUnicode(aAttr); @@ -484,7 +467,7 @@ nsHTMLEditorLog:: InsertTableCell(PRInt32 aNumber, PRBool aAfter) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.InsertTableCell(\""); Write("\");\n"); @@ -500,7 +483,7 @@ nsHTMLEditorLog:: InsertTableColumn(PRInt32 aNumber, PRBool aAfter) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.InsertTableColumn(\""); Write("\");\n"); @@ -516,7 +499,7 @@ nsHTMLEditorLog:: InsertTableRow(PRInt32 aNumber, PRBool aAfter) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.InsertTableRow(\""); Write("\");\n"); @@ -531,7 +514,7 @@ nsHTMLEditorLog:: DeleteTable() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTable();\n"); Flush(); @@ -545,7 +528,7 @@ nsHTMLEditorLog:: DeleteTableCell(PRInt32 aNumber) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTableCell(\""); Write("\");\n"); @@ -560,7 +543,7 @@ nsHTMLEditorLog:: DeleteTableCellContents() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTableCellContents();\n"); Flush(); @@ -575,7 +558,7 @@ nsHTMLEditorLog:: DeleteTableColumn(PRInt32 aNumber) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTableColumn(\""); Write("\");\n"); @@ -591,7 +574,7 @@ nsHTMLEditorLog:: DeleteTableRow(PRInt32 aNumber) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTableRow(\""); Write("\");\n"); @@ -606,7 +589,7 @@ nsHTMLEditorLog:: JoinTableCells(PRBool aMergeNonContiguousContents) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.JoinTableCells();\n"); Flush(); @@ -620,7 +603,7 @@ nsHTMLEditorLog:: SplitTableCell() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SplitTableCell();\n"); Flush(); @@ -635,7 +618,7 @@ nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.NormalizeTable(\""); Write("\");\n"); @@ -650,7 +633,7 @@ nsHTMLEditorLog::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMEle { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SwitchTableCellHeaderType(\""); Write("\");\n"); @@ -665,7 +648,7 @@ nsHTMLEditorLog::MakeOrChangeList(const nsString& aListType, PRBool entireList) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); @@ -683,7 +666,7 @@ nsHTMLEditorLog::Indent(const nsString& aIndent) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); @@ -701,7 +684,7 @@ nsHTMLEditorLog::Align(const nsString& aAlign) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); @@ -719,7 +702,7 @@ nsHTMLEditorLog::InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDelet { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { if (!aElement) return NS_ERROR_NULL_POINTER; @@ -745,7 +728,7 @@ nsHTMLEditorLog::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { if (!aAnchorElement) return NS_ERROR_NULL_POINTER; @@ -769,7 +752,7 @@ nsHTMLEditorLog::ApplyStyleSheet(const nsString& aURL, nsICSSStyleSheet **aStyle { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { // Note that the editorShell (IDL) method does // not return the style sheet created from aURL @@ -786,14 +769,14 @@ nsHTMLEditorLog::ApplyStyleSheet(const nsString& aURL, nsICSSStyleSheet **aStyle } NS_IMETHODIMP -nsHTMLEditorLog::StartLogging(nsIFileSpec *aLogFile) +nsHTMLEditorLog::StartLogging(nsIFile *aLogFile) { nsresult result = NS_ERROR_FAILURE; if (!aLogFile) return NS_ERROR_NULL_POINTER; - if (mFileSpec) + if (mFileStream) { result = StopLogging(); @@ -801,16 +784,13 @@ nsHTMLEditorLog::StartLogging(nsIFileSpec *aLogFile) return result; } - mFileSpec = do_QueryInterface(aLogFile); - - if (!mFileSpec) - result = NS_ERROR_NULL_POINTER; - - result = mFileSpec->OpenStreamForWriting(); + mFileStream = do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &result); + if (NS_FAILED(result)) return result; + result = mFileStream->Init(aLogFile, -1, -1); if (NS_FAILED(result)) { - mFileSpec = nsCOMPtr(); + mFileStream = nsnull; return result; } @@ -842,10 +822,10 @@ nsHTMLEditorLog::StopLogging() mEditorTxnLog = 0; } - if (mFileSpec) + if (mFileStream) { - mFileSpec->CloseStream(); - mFileSpec = nsCOMPtr(); + mFileStream->Close(); + mFileStream = nsnull; } return NS_OK; @@ -862,18 +842,18 @@ nsHTMLEditorLog::Write(const char *aBuffer) PRInt32 len = strlen(aBuffer); - if (mFileSpec) + if (mFileStream) { - PRInt32 retval; + PRUint32 retval; - result = mFileSpec->Write(aBuffer, len, &retval); + result = mFileStream->Write(aBuffer, len, &retval); if (NS_FAILED(result)) return result; #ifdef VERY_SLOW - result = mFileSpec->Flush(); + result = mFileStream->Flush(); if (NS_FAILED(result)) return result; @@ -904,8 +884,8 @@ nsHTMLEditorLog::Flush() { nsresult result = NS_OK; - if (mFileSpec) - result = mFileSpec->Flush(); + if (mFileStream) + result = mFileStream->Flush(); else fflush(stdout); diff --git a/mozilla/editor/base/nsHTMLEditorLog.h b/mozilla/editor/base/nsHTMLEditorLog.h index 17c6963de04..6157e15168c 100644 --- a/mozilla/editor/base/nsHTMLEditorLog.h +++ b/mozilla/editor/base/nsHTMLEditorLog.h @@ -25,9 +25,10 @@ #include "nsHTMLEditor.h" #include "nsIEditorLogging.h" -#include "nsIFileSpec.h" +#include "nsIFileStreams.h" #include "nsCOMPtr.h" +class nsIFile; class nsEditorTxnLog; /** implementation of a transaction listener object. @@ -38,7 +39,7 @@ class nsHTMLEditorLog : public nsHTMLEditor, { private: - nsCOMPtr mFileSpec; + nsCOMPtr mFileStream; nsEditorTxnLog *mEditorTxnLog; PRInt32 mLocked; PRInt32 mDepth; @@ -103,7 +104,7 @@ public: NS_IMETHOD NormalizeTable(nsIDOMElement *aTable); NS_IMETHOD SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell); - NS_IMETHOD StartLogging(nsIFileSpec *aLogFile); + NS_IMETHOD StartLogging(nsIFile *aLogFile); NS_IMETHOD StopLogging(); /* nsHTMLEditorLog public methods. */ diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index c809cef0194..9c8ec67520a 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -22,7 +22,7 @@ #include "nsISupports.idl" #include "domstubs.idl" -#include "nsIFileSpec.idl" +#include "nsIFile.idl" #include "nsISupportsArray.idl" #include "nsIDocumentStateListener.idl" #include "nsISelectionController.idl" @@ -37,7 +37,6 @@ class nsIDOMNode; %} -interface nsIFileSpec; interface nsIEditor; [scriptable, uuid(9afff72b-ca9a-11d2-96c9-0060b0fb9956)] @@ -612,7 +611,7 @@ interface nsIEditorShell : nsISupports void EndBatchChanges(); void RunUnitTests(); - void StartLogging(in nsIFileSpec logFile); + void StartLogging(in nsIFile logFile); void StopLogging(); void CloseWindowWithoutSaving(); diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index f64b1c48f14..0f8fac17c1d 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -1530,7 +1530,7 @@ nsEditor::GetDocumentModified(PRBool *outDocModified) if (NS_FAILED(rv)) return rv; PRInt32 modCount = 0; - diskDoc->GetModCount(&modCount); + diskDoc->GetModificationCount(&modCount); *outDocModified = (modCount != 0); return NS_OK; @@ -1602,7 +1602,7 @@ nsEditor::GetWrapWidth(PRInt32 *aWrapColumn) } NS_IMETHODIMP -nsEditor::SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting, +nsEditor::SaveFile(nsIFile *aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormat) { if (!aFileSpec) @@ -1633,9 +1633,8 @@ nsEditor::SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting, PRInt32 wrapColumn = 72; GetWrapWidth(&wrapColumn); - nsAutoString useDocCharset; rv = diskDoc->SaveFile(aFileSpec, aReplaceExisting, aSaveCopy, - aFormat, useDocCharset, flags, wrapColumn); + aFormat.GetUnicode(), NS_LITERAL_STRING(""), flags, wrapColumn); if (NS_SUCCEEDED(rv)) DoAfterDocumentSave(); @@ -4288,7 +4287,7 @@ NS_IMETHODIMP nsEditor::IncDocModCount(PRInt32 inNumMods) if (!doc) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr diskDoc = do_QueryInterface(doc); if (diskDoc) - diskDoc->IncrementModCount(inNumMods); + diskDoc->IncrementModificationCount(inNumMods); NotifyDocumentListeners(eDocumentStateChanged); return NS_OK; @@ -4305,7 +4304,7 @@ NS_IMETHODIMP nsEditor::GetDocModCount(PRInt32 &outModCount) if (!doc) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr diskDoc = do_QueryInterface(doc); if (diskDoc) - diskDoc->GetModCount(&outModCount); + diskDoc->GetModificationCount(&outModCount); return NS_OK; } @@ -4319,7 +4318,7 @@ NS_IMETHODIMP nsEditor::ResetDocModCount() if (!doc) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr diskDoc = do_QueryInterface(doc); if (diskDoc) - diskDoc->ResetModCount(); + diskDoc->ResetModificationCount(); NotifyDocumentListeners(eDocumentStateChanged); return NS_OK; diff --git a/mozilla/editor/libeditor/base/nsEditor.h b/mozilla/editor/libeditor/base/nsEditor.h index 37441a75107..9c2ed1ca15c 100644 --- a/mozilla/editor/libeditor/base/nsEditor.h +++ b/mozilla/editor/libeditor/base/nsEditor.h @@ -41,7 +41,6 @@ #include "nsIComponentManager.h" #include "nsISupportsArray.h" #include "nsIEditProperty.h" -#include "nsIFileSpec.h" #include "nsIDOMCharacterData.h" #include "nsICSSStyleSheet.h" #include "nsIDTD.h" @@ -69,7 +68,7 @@ class nsILocale; class IMETextTxn; class AddStyleSheetTxn; class RemoveStyleSheetTxn; -class nsFileSpec; +class nsIFile; class nsISelectionController; @@ -246,7 +245,7 @@ public: NS_IMETHOD GetDocumentModified(PRBool *outDocModified); NS_IMETHOD GetDocumentCharacterSet(PRUnichar** characterSet); NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet); - NS_IMETHOD SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormat); + NS_IMETHOD SaveFile(nsIFile *aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormat); // these are pure virtual in this base class NS_IMETHOD Cut() = 0; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp b/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp index 66e7445c024..5108a87c663 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp @@ -40,9 +40,10 @@ nsHTMLEditorLog::nsHTMLEditorLog() { - mRefCnt = 0; mLocked = -1; mEditorTxnLog = 0; + + NS_INIT_ISUPPORTS(); } nsHTMLEditorLog::~nsHTMLEditorLog() @@ -50,32 +51,14 @@ nsHTMLEditorLog::~nsHTMLEditorLog() StopLogging(); } -NS_IMPL_ADDREF_INHERITED(nsHTMLEditorLog, nsHTMLEditor); -NS_IMPL_RELEASE_INHERITED(nsHTMLEditorLog, nsHTMLEditor); - -NS_IMETHODIMP -nsHTMLEditorLog::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (!aInstancePtr) - return NS_ERROR_NULL_POINTER; - - *aInstancePtr = nsnull; - - if (aIID.Equals(NS_GET_IID(nsIEditorLogging))) { - *aInstancePtr = (void*)(nsIEditorLogging*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - - return nsHTMLEditor::QueryInterface(aIID, aInstancePtr); -} +NS_IMPL_ISUPPORTS_INHERITED(nsHTMLEditorLog, nsHTMLEditor, nsIEditorLogging); NS_IMETHODIMP nsHTMLEditorLog::SetInlineProperty(nsIAtom *aProperty, const nsString *aAttribute, const nsString *aValue) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { nsAutoString propStr; @@ -103,7 +86,7 @@ nsHTMLEditorLog::SetParagraphFormat(const nsString& aParagraphFormat) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.SetParagraphFormat(\""); @@ -121,7 +104,7 @@ nsHTMLEditorLog::RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttri { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { nsAutoString propStr; @@ -146,7 +129,7 @@ nsHTMLEditorLog::DeleteSelection(nsIEditor::EDirection aAction) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.DeleteSelection("); @@ -164,7 +147,7 @@ nsHTMLEditorLog::InsertText(const PRUnichar* aStringToInsert) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); @@ -184,7 +167,7 @@ nsHTMLEditorLog::InsertLineBreak() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.InsertBreak();\n"); @@ -199,7 +182,7 @@ nsHTMLEditorLog::Undo(PRUint32 aCount) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.Undo();\n"); Flush(); @@ -213,7 +196,7 @@ nsHTMLEditorLog::Redo(PRUint32 aCount) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.Redo();\n"); Flush(); @@ -227,7 +210,7 @@ nsHTMLEditorLog::BeginTransaction() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.BeginBatchChanges();\n"); Flush(); @@ -241,7 +224,7 @@ nsHTMLEditorLog::EndTransaction() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.EndBatchChanges();\n"); Flush(); @@ -255,7 +238,7 @@ nsHTMLEditorLog::SelectAll() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SelectAll();\n"); Flush(); @@ -269,7 +252,7 @@ nsHTMLEditorLog::BeginningOfDocument() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.BeginningOfDocument();\n"); Flush(); @@ -283,7 +266,7 @@ nsHTMLEditorLog::EndOfDocument() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.EndOfDocument();\n"); Flush(); @@ -297,7 +280,7 @@ nsHTMLEditorLog::Cut() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.Cut();\n"); @@ -312,7 +295,7 @@ nsHTMLEditorLog::Copy() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.Copy();\n"); @@ -327,7 +310,7 @@ nsHTMLEditorLog::Paste(PRInt32 aSelectionType) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.Paste();\n"); @@ -342,7 +325,7 @@ nsHTMLEditorLog::PasteAsQuotation(PRInt32 aSelectionType) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.PasteAsQuotation();\n"); @@ -357,7 +340,7 @@ nsHTMLEditorLog::PasteAsPlaintextQuotation(PRInt32 aSelectionType) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.PasteAsQuotation();\n"); @@ -373,7 +356,7 @@ nsHTMLEditorLog::PasteAsCitedQuotation(const nsString& aCitation, { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.PasteAsCitedQuotation(\""); @@ -391,7 +374,7 @@ nsHTMLEditorLog::InsertAsQuotation(const nsString& aQuotedText, { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.InsertAsQuotation(\""); @@ -409,7 +392,7 @@ nsHTMLEditorLog::InsertAsPlaintextQuotation(const nsString& aQuotedText, { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.InsertAsQuotation(\""); @@ -430,7 +413,7 @@ nsHTMLEditorLog::InsertAsCitedQuotation(const nsString& aQuotedText, { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); Write("window.editorShell.InsertAsCitedQuotation(\""); @@ -450,7 +433,7 @@ nsHTMLEditorLog::SetBackgroundColor(const nsString& aColor) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SetBackgroundColor(\""); PrintUnicode(aColor); @@ -466,7 +449,7 @@ nsHTMLEditorLog::SetBodyAttribute(const nsString& aAttr, const nsString& aValue) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SetBodyAttribute(\""); PrintUnicode(aAttr); @@ -484,7 +467,7 @@ nsHTMLEditorLog:: InsertTableCell(PRInt32 aNumber, PRBool aAfter) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.InsertTableCell(\""); Write("\");\n"); @@ -500,7 +483,7 @@ nsHTMLEditorLog:: InsertTableColumn(PRInt32 aNumber, PRBool aAfter) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.InsertTableColumn(\""); Write("\");\n"); @@ -516,7 +499,7 @@ nsHTMLEditorLog:: InsertTableRow(PRInt32 aNumber, PRBool aAfter) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.InsertTableRow(\""); Write("\");\n"); @@ -531,7 +514,7 @@ nsHTMLEditorLog:: DeleteTable() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTable();\n"); Flush(); @@ -545,7 +528,7 @@ nsHTMLEditorLog:: DeleteTableCell(PRInt32 aNumber) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTableCell(\""); Write("\");\n"); @@ -560,7 +543,7 @@ nsHTMLEditorLog:: DeleteTableCellContents() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTableCellContents();\n"); Flush(); @@ -575,7 +558,7 @@ nsHTMLEditorLog:: DeleteTableColumn(PRInt32 aNumber) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTableColumn(\""); Write("\");\n"); @@ -591,7 +574,7 @@ nsHTMLEditorLog:: DeleteTableRow(PRInt32 aNumber) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.DeleteTableRow(\""); Write("\");\n"); @@ -606,7 +589,7 @@ nsHTMLEditorLog:: JoinTableCells(PRBool aMergeNonContiguousContents) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.JoinTableCells();\n"); Flush(); @@ -620,7 +603,7 @@ nsHTMLEditorLog:: SplitTableCell() { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SplitTableCell();\n"); Flush(); @@ -635,7 +618,7 @@ nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.NormalizeTable(\""); Write("\");\n"); @@ -650,7 +633,7 @@ nsHTMLEditorLog::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMEle { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { Write("window.editorShell.SwitchTableCellHeaderType(\""); Write("\");\n"); @@ -665,7 +648,7 @@ nsHTMLEditorLog::MakeOrChangeList(const nsString& aListType, PRBool entireList) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); @@ -683,7 +666,7 @@ nsHTMLEditorLog::Indent(const nsString& aIndent) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); @@ -701,7 +684,7 @@ nsHTMLEditorLog::Align(const nsString& aAlign) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { PrintSelection(); @@ -719,7 +702,7 @@ nsHTMLEditorLog::InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDelet { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { if (!aElement) return NS_ERROR_NULL_POINTER; @@ -745,7 +728,7 @@ nsHTMLEditorLog::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { if (!aAnchorElement) return NS_ERROR_NULL_POINTER; @@ -769,7 +752,7 @@ nsHTMLEditorLog::ApplyStyleSheet(const nsString& aURL, nsICSSStyleSheet **aStyle { nsAutoHTMLEditorLogLock logLock(this); - if (!mLocked && mFileSpec) + if (!mLocked && mFileStream) { // Note that the editorShell (IDL) method does // not return the style sheet created from aURL @@ -786,14 +769,14 @@ nsHTMLEditorLog::ApplyStyleSheet(const nsString& aURL, nsICSSStyleSheet **aStyle } NS_IMETHODIMP -nsHTMLEditorLog::StartLogging(nsIFileSpec *aLogFile) +nsHTMLEditorLog::StartLogging(nsIFile *aLogFile) { nsresult result = NS_ERROR_FAILURE; if (!aLogFile) return NS_ERROR_NULL_POINTER; - if (mFileSpec) + if (mFileStream) { result = StopLogging(); @@ -801,16 +784,13 @@ nsHTMLEditorLog::StartLogging(nsIFileSpec *aLogFile) return result; } - mFileSpec = do_QueryInterface(aLogFile); - - if (!mFileSpec) - result = NS_ERROR_NULL_POINTER; - - result = mFileSpec->OpenStreamForWriting(); + mFileStream = do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &result); + if (NS_FAILED(result)) return result; + result = mFileStream->Init(aLogFile, -1, -1); if (NS_FAILED(result)) { - mFileSpec = nsCOMPtr(); + mFileStream = nsnull; return result; } @@ -842,10 +822,10 @@ nsHTMLEditorLog::StopLogging() mEditorTxnLog = 0; } - if (mFileSpec) + if (mFileStream) { - mFileSpec->CloseStream(); - mFileSpec = nsCOMPtr(); + mFileStream->Close(); + mFileStream = nsnull; } return NS_OK; @@ -862,18 +842,18 @@ nsHTMLEditorLog::Write(const char *aBuffer) PRInt32 len = strlen(aBuffer); - if (mFileSpec) + if (mFileStream) { - PRInt32 retval; + PRUint32 retval; - result = mFileSpec->Write(aBuffer, len, &retval); + result = mFileStream->Write(aBuffer, len, &retval); if (NS_FAILED(result)) return result; #ifdef VERY_SLOW - result = mFileSpec->Flush(); + result = mFileStream->Flush(); if (NS_FAILED(result)) return result; @@ -904,8 +884,8 @@ nsHTMLEditorLog::Flush() { nsresult result = NS_OK; - if (mFileSpec) - result = mFileSpec->Flush(); + if (mFileStream) + result = mFileStream->Flush(); else fflush(stdout); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditorLog.h b/mozilla/editor/libeditor/html/nsHTMLEditorLog.h index 17c6963de04..6157e15168c 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditorLog.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditorLog.h @@ -25,9 +25,10 @@ #include "nsHTMLEditor.h" #include "nsIEditorLogging.h" -#include "nsIFileSpec.h" +#include "nsIFileStreams.h" #include "nsCOMPtr.h" +class nsIFile; class nsEditorTxnLog; /** implementation of a transaction listener object. @@ -38,7 +39,7 @@ class nsHTMLEditorLog : public nsHTMLEditor, { private: - nsCOMPtr mFileSpec; + nsCOMPtr mFileStream; nsEditorTxnLog *mEditorTxnLog; PRInt32 mLocked; PRInt32 mDepth; @@ -103,7 +104,7 @@ public: NS_IMETHOD NormalizeTable(nsIDOMElement *aTable); NS_IMETHOD SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell); - NS_IMETHOD StartLogging(nsIFileSpec *aLogFile); + NS_IMETHOD StartLogging(nsIFile *aLogFile); NS_IMETHOD StopLogging(); /* nsHTMLEditorLog public methods. */ diff --git a/mozilla/editor/public/nsIEditor.h b/mozilla/editor/public/nsIEditor.h index 8489ce7cce3..be7379b6d1c 100644 --- a/mozilla/editor/public/nsIEditor.h +++ b/mozilla/editor/public/nsIEditor.h @@ -24,7 +24,6 @@ #define nsIEditor_h__ #include "nsISupports.h" #include "nscore.h" -#include "nsIDiskDocument.h" #include "nsString.h" #define NS_IEDITOR_IID \ @@ -41,10 +40,10 @@ class nsISelection; class nsITransaction; class nsITransactionManager; class nsIOutputStream; +class nsIFile; class nsIEditActionListener; class nsIEditorObserver; class nsIDocumentStateListener; -class nsFileSpec; class nsISelectionController; class nsIContent; class nsIDOMEvent; @@ -171,7 +170,7 @@ public: * @param aFormat * Mime type to save (text/plain or text/html) */ - NS_IMETHOD SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormat)=0; + NS_IMETHOD SaveFile(nsIFile *aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormat)=0; /* ------------ Transaction methods -------------- */ diff --git a/mozilla/editor/public/nsIEditorLogging.h b/mozilla/editor/public/nsIEditorLogging.h index 2743fd66c04..3f176758cd5 100644 --- a/mozilla/editor/public/nsIEditorLogging.h +++ b/mozilla/editor/public/nsIEditorLogging.h @@ -41,7 +41,7 @@ public: /* Start logging */ - NS_IMETHOD StartLogging(nsIFileSpec *aLogFile)=0; + NS_IMETHOD StartLogging(nsIFile *aLogFile)=0; /* Stop logging */ NS_IMETHOD StopLogging()=0; diff --git a/mozilla/editor/ui/composer/content/EditorCommandsDebug.js b/mozilla/editor/ui/composer/content/EditorCommandsDebug.js index 3dfb80b1c74..02ac4fbcecd 100644 --- a/mozilla/editor/ui/composer/content/EditorCommandsDebug.js +++ b/mozilla/editor/ui/composer/content/EditorCommandsDebug.js @@ -252,20 +252,29 @@ function EditorTestDocument() // --------------------------- Logging stuff --------------------------- -function EditorExecuteScript(fileSpec) +function EditorExecuteScript(theFile) { - fileSpec.openStreamForReading(); + var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(); + inputStream = inputStream.QueryInterface(Components.interfaces.nsIFileInputStream); + inputStream.init(theFile, 1, 0); // open read only + + var scriptableInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(); + scriptableInputStream = scriptableInputStream.QueryInterface(Components.interfaces.nsIScriptableInputStream); + + scriptableInputStream.init(inputStream); // open read only + var buf = { value:null }; var tmpBuf = { value:null }; var didTruncate = { value:false }; var lineNum = 0; var ex; +/* // Log files can be quite huge, so read in a line // at a time and execute it: - while (!fileSpec.eof()) + while (!inputStream.eof()) { buf.value = ""; didTruncate.value = true; @@ -273,7 +282,7 @@ function EditorExecuteScript(fileSpec) // Keep looping until we get a complete line of // text, or we hit the end of file: - while (didTruncate.value && !fileSpec.eof()) + while (didTruncate.value && !inputStream.eof()) { didTruncate.value = false; fileSpec.readLine(tmpBuf, 1024, didTruncate); @@ -288,8 +297,15 @@ function EditorExecuteScript(fileSpec) } ++lineNum; - - try { eval(buf.value); } +*/ + { + // suck in the entire file + var fileSize = scriptableInputStream.available(); + var fileContents = scriptableInputStream.read(fileSize); + + dump(fileContents); + + try { eval(fileContents); } catch(ex) { dump("Playback ERROR: Line " + lineNum + " " + ex + "\n"); return; } } @@ -298,10 +314,11 @@ function EditorExecuteScript(fileSpec) function EditorGetScriptFileSpec() { - var fs = Components.classes["@mozilla.org/filespec;1"].createInstance(); - fs = fs.QueryInterface(Components.interfaces.nsIFileSpec); - fs.unixStyleFilePath = "journal.js"; - return fs; + var dirServ = Components.classes['@mozilla.org/file/directory_service;1'].createInstance(); + dirServ = dirServ.QueryInterface(Components.interfaces.nsIProperties); + var processDir = dirServ.get("Home", Components.interfaces.nsIFile); + processDir.append("journal.js"); + return processDir; } function EditorStartLog() diff --git a/mozilla/editor/ui/composer/content/editor.js b/mozilla/editor/ui/composer/content/editor.js index 2c373d1ebd4..406617e489a 100644 --- a/mozilla/editor/ui/composer/content/editor.js +++ b/mozilla/editor/ui/composer/content/editor.js @@ -1798,7 +1798,7 @@ function EditorSetSelectionFromOffsets(selRanges) var rangeArr, start, end, node, offset; var selection = editorShell.editorSelection; - selection.clearSelection(); + selection.removeAllRanges(); for (var i = 0; i < selRanges.length; i++) { diff --git a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js index fff1bb2b673..47bd4f8e34d 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js +++ b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js @@ -774,10 +774,11 @@ function GetPrefs() function GetScriptFileSpec() { - var fs = Components.classes["@mozilla.org/filespec;1"].createInstance(); - fs = fs.QueryInterface(Components.interfaces.nsIFileSpec); - fs.unixStyleFilePath = "journal.js"; - return fs; + var dirServ = Components.classes['@mozilla.org/file/directory_service;1'].createInstance(); + dirServ = dirServ.QueryInterface(Components.interfaces.nsIProperties); + var processDir = dirServ.get("CurProcD", Components.interfaces.nsIFile); + processDir.append("journal.js"); + return processDir; } const nsIFilePicker = Components.interfaces.nsIFilePicker; diff --git a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp index 3c0959755a5..d800e9c5ea2 100644 --- a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp +++ b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp @@ -524,8 +524,14 @@ LRESULT CMozillaBrowser::OnSaveAs(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL } // Create an nsFilelSpec from the selected file path. - nsFileSpec fileSpec(szFile, PR_FALSE); - + nsCOMPtr theFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &hr); + if (FAILED(hr)) + return hr; + + hr = theFile->InitWithPath(szFile); + if (FAILED(hr)) + return hr; + // Figure out the mime type from the selection nsAutoString mimeType; switch (SaveFileName.nFilterIndex) @@ -540,8 +546,7 @@ LRESULT CMozillaBrowser::OnSaveAs(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL } // Save the file. - nsAutoString useDocCharset; - hr = diskDoc->SaveFile(&fileSpec, PR_TRUE, PR_TRUE, mimeType, useDocCharset, 0, 72); + hr = diskDoc->SaveFile(theFile, PR_TRUE, PR_TRUE, mimeType.GetUnicode(), NS_LITERAL_STRING(""), 0, 72); } return hr; diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowserPersist.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowserPersist.cpp index 97f806ea113..ab255d48733 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowserPersist.cpp +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowserPersist.cpp @@ -22,8 +22,13 @@ #include "nspr.h" +#define NO_XPCOM_FILE_STREAMS +#include "nsIFileStream.h" // Old XPCOM file streams +#undef NO_XPCOM_FILE_STREAMS + +#include "nsIFileStreams.h" // New Necko file streams + #include "nsNetUtil.h" -#include "nsFileStream.h" #include "nsIFileTransportService.h" #include "nsIHTTPChannel.h" #include "nsEscape.h" @@ -252,6 +257,18 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveDocument(nsIDOMDocument *aDocument, const // Store the base URI doc->GetBaseURL(*getter_AddRefs(mBaseURI)); + nsCOMPtr fileSpec(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); + if (NS_FAILED(rv)) { + OnEndDownload(); + return rv; + } + + rv = fileSpec->InitWithPath(aFileName); + if (NS_FAILED(rv)) { + OnEndDownload(); + return rv; + } + // Does the caller want to fixup the referenced URIs and save those too? if (aDataPath) { @@ -286,20 +303,19 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveDocument(nsIDOMDocument *aDocument, const nsCOMPtr diskDoc = do_QueryInterface(docAsNode); nsString contentType; contentType.AssignWithConversion("text/html"); // TODO nsString charType; // Empty - nsFileSpec fileSpec(aFileName); - + nsEncoderNodeFixup *nodeFixup; nodeFixup = new nsEncoderNodeFixup; nodeFixup->mWebBrowserPersist = this; // Set the document base to ensure relative links still work SetDocumentBase(aDocument, mBaseURI); - + // Save the document, fixing up the links as it goes out rv = SaveDocumentToFileWithFixup( doc, nodeFixup, - &fileSpec, + fileSpec, PR_TRUE /* replace existing file */, PR_TRUE, /* save as a copy */ contentType, @@ -318,13 +334,13 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveDocument(nsIDOMDocument *aDocument, const nsCOMPtr diskDoc = do_QueryInterface(docAsNode); nsString contentType; contentType.AssignWithConversion("text/html"); // TODO nsString charType; // Empty - nsFileSpec fileSpec(aFileName); + rv = diskDoc->SaveFile( - &fileSpec, + fileSpec, PR_TRUE /* replace existing file */, PR_TRUE, /* save as a copy */ - contentType, - charType, + contentType.GetUnicode(), + charType.GetUnicode(), 0, 72); } @@ -775,7 +791,7 @@ nsresult nsWebBrowserPersist::SaveDocumentToFileWithFixup( nsIDocument *aDocument, nsIDocumentEncoderNodeFixup *aNodeFixup, - nsFileSpec* aFileSpec, + nsIFile* aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormatType, @@ -795,39 +811,26 @@ nsWebBrowserPersist::SaveDocumentToFileWithFixup( // if we're not replacing an existing file but the file // exists, somethine is wrong - if (!aReplaceExisting && aFileSpec->Exists()) - { - return NS_ERROR_FAILURE; // where are the file I/O errors? - } + PRBool fileExists; + rv = aFileSpec->Exists(&fileExists); + if (NS_FAILED(rv)) return rv; + + if (!aReplaceExisting && fileExists) + return NS_ERROR_FAILURE; // where are the file I/O errors? - nsOutputFileStream stream(*aFileSpec); - // if the stream didn't open, something went wrong - if (!stream.is_open()) - { - return NS_BASE_STREAM_CLOSED; - } + nsCOMPtr outputStream = do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = outputStream->Init(aFileSpec, -1, -1); + if (NS_FAILED(rv)) return rv; - // Get a document encoder instance: - nsCOMPtr encoder; - char* contractid = (char *)nsMemory::Alloc(strlen(NS_DOC_ENCODER_CONTRACTID_BASE) - + aFormatType.Length() + 1); - if (! contractid) - { - return NS_ERROR_OUT_OF_MEMORY; - } - strcpy(contractid, NS_DOC_ENCODER_CONTRACTID_BASE); - char* type = aFormatType.ToNewCString(); - strcat(contractid, type); - nsCRT::free(type); - rv = nsComponentManager::CreateInstance(contractid, - nsnull, - NS_GET_IID(nsIDocumentEncoder), - getter_AddRefs(encoder)); - nsCRT::free(contractid); + // Get a document encoder instance + nsCAutoString contractID(NS_DOC_ENCODER_CONTRACTID_BASE); + contractID.AppendWithConversion(aFormatType); + + nsCOMPtr encoder = do_CreateInstance(contractID, &rv); if (NS_FAILED(rv)) - { - return rv; - } + return rv; rv = encoder->Init(aDocument, aFormatType, aFlags); if (NS_FAILED(rv)) @@ -850,7 +853,7 @@ nsWebBrowserPersist::SaveDocumentToFileWithFixup( } encoder->SetCharset(charsetStr); - rv = encoder->EncodeToStream(stream.GetIStream()); + rv = encoder->EncodeToStream(outputStream); return rv; } diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowserPersist.h b/mozilla/embedding/browser/webBrowser/nsWebBrowserPersist.h index 11850c72b6b..20584876067 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowserPersist.h +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowserPersist.h @@ -29,7 +29,6 @@ #include "nsIStreamListener.h" #include "nsIOutputStream.h" #include "nsIInputStream.h" -#include "nsIFileStream.h" #include "nsIChannel.h" #include "nsIStyleSheet.h" #include "nsIDocumentEncoder.h" @@ -74,7 +73,7 @@ private: nsresult SaveDocumentToFileWithFixup( nsIDocument *pDocument, nsIDocumentEncoderNodeFixup *pFixup, - nsFileSpec* aFileSpec, + nsIFile* aFileSpec, PRBool aReplaceExisting, PRBool aSaveCopy, const nsString& aFormatType, diff --git a/mozilla/layout/base/public/MANIFEST b/mozilla/layout/base/public/MANIFEST index 0f34f97dd93..fd64cd330cb 100644 --- a/mozilla/layout/base/public/MANIFEST +++ b/mozilla/layout/base/public/MANIFEST @@ -8,7 +8,6 @@ nsICaret.h nsIContent.h nsIContentIterator.h nsContentPolicyUtils.h -nsIDiskDocument.h nsIDocument.h nsIDocumentContainer.h nsIDocumentEncoder.h diff --git a/mozilla/layout/base/public/MANIFEST_IDL b/mozilla/layout/base/public/MANIFEST_IDL index 644779527fa..04e62244824 100644 --- a/mozilla/layout/base/public/MANIFEST_IDL +++ b/mozilla/layout/base/public/MANIFEST_IDL @@ -8,3 +8,4 @@ nsISelection.idl nsISelectionPrivate.idl nsISelectionListener.idl nsIContentPolicy.idl +nsIDiskDocument.idl diff --git a/mozilla/layout/base/public/Makefile.in b/mozilla/layout/base/public/Makefile.in index 935a4c7ec7e..587f7c78b4d 100644 --- a/mozilla/layout/base/public/Makefile.in +++ b/mozilla/layout/base/public/Makefile.in @@ -37,7 +37,6 @@ nsICaret.h \ nsIContent.h \ nsIContentIterator.h \ nsContentPolicyUtils.h \ -nsIDiskDocument.h \ nsIDocument.h \ nsIDocumentContainer.h \ nsIDocumentEncoder.h \ @@ -98,6 +97,7 @@ $(NULL) XPIDLSRCS = \ nsIChromeEventHandler.idl \ nsIContentPolicy.idl \ + nsIDiskDocument.idl \ nsISelectionController.idl \ nsISelectionListener.idl \ nsISelection.idl \ diff --git a/mozilla/layout/base/public/makefile.win b/mozilla/layout/base/public/makefile.win index 723c1aabcdf..df197d125a0 100644 --- a/mozilla/layout/base/public/makefile.win +++ b/mozilla/layout/base/public/makefile.win @@ -29,7 +29,6 @@ EXPORTS = \ nsICaret.h \ nsIContent.h \ nsIContentIterator.h \ - nsIDiskDocument.h \ nsIDocument.h \ nsIDocumentContainer.h \ nsIDocumentEncoder.h \ @@ -92,6 +91,7 @@ MODULE=layout_base XPIDLSRCS= \ .\nsIChromeEventHandler.idl \ .\nsIContentPolicy.idl \ + .\nsIDiskDocument.idl \ .\nsISelectionController.idl \ .\nsISelectionListener.idl \ .\nsISelection.idl \ diff --git a/mozilla/layout/base/public/nsIDiskDocument.idl b/mozilla/layout/base/public/nsIDiskDocument.idl new file mode 100644 index 00000000000..06c5d70bb40 --- /dev/null +++ b/mozilla/layout/base/public/nsIDiskDocument.idl @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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. + * + * Original Author: Simon Fraser (sfraser@netscape.com) + * + * Contributor(s): + */ + +#include "nsISupports.idl" +#include "nsIFile.idl" + +// {dd038282-d5a2-11d4-aedb-e1c4b1c8b9fc} +[scriptable, uuid(dd038282-d5a2-11d4-aedb-e1c4b1c8b9fc)] +interface nsIDiskDocument : nsISupports +{ + /** An nsIFile pointing to the location of the file on disk. May be null if + * this document has not been saved yet + */ + readonly attribute nsIFile fileSpec; + + /** The modification count for the document. A +ve mod count indicates + * that the document is dirty, and needs saving. + */ + readonly attribute long modificationCount; + + /** Initialize the document output. This may be called on document + * creation, or lazily before the first save. For a document read + * in from disk, it should be called on document instantiation. + * + * @param aFile nsIFile for the file, if a disk version + * of the file exists already. Otherwise nsnull. + */ + void InitDiskDocument(in nsIFile aFile); + + + /** Save the file to disk. This will be called after the caller has + * displayed a put file dialog, which the user confirmed. The internal + * fileSpec of the document is only updated with the given fileSpec if inSaveCopy == PR_FALSE. + * + * @param aFile File to which to stream the document. + * @param aReplaceExisting true if replacing an existing file, otherwise false. + * If false and aFile exists, SaveFile returns an error. + * @param aSaveCopy True to save a copy of the file, without changing the file + * referenced internally. + * @param aFileType Mime type to save (text/plain or text/html) + * @param aFileCharset Charset to save the document in. If this is an empty + * string, or "UCS2", then the doc will be saved as Unicode. + * @param aSaveFlags Flags used by the document encoder (see nsIDocumentEncoder). + * @param inWrapColumn Wrap column, assuming that flags specify wrapping. + */ + void SaveFile(in nsIFile aFile, in boolean aReplaceExisting, in boolean aSaveCopy, + in wstring aFileType, in wstring aFileCharset, in unsigned long aSaveFlags, + in unsigned long aWrapColumn); + + /** Reset the modification count for the document. This marks the documents as + * 'clean' and not in need of saving. + */ + void ResetModificationCount(); + + /** Increment the modification count for the document by the given + * amount (which may be -ve). + */ + void IncrementModificationCount(in long aNumMods); + +}; + + diff --git a/mozilla/layout/base/src/nsDocument.cpp b/mozilla/layout/base/src/nsDocument.cpp index c39ddae1db4..d0acf44a551 100644 --- a/mozilla/layout/base/src/nsDocument.cpp +++ b/mozilla/layout/base/src/nsDocument.cpp @@ -74,8 +74,7 @@ #include "nsIHTMLContentSink.h" #include "nsIParser.h" #include "nsParserCIID.h" -#include "nsFileSpec.h" -#include "nsFileStream.h" +#include "nsIFileStreams.h" #include "nsRange.h" #include "nsIDOMText.h" @@ -624,7 +623,6 @@ nsDocument::nsDocument() mChildNodes = nsnull; mWordBreaker = nsnull; mModCount = 0; - mFileSpec = nsnull; mPrincipal = nsnull; mNextContentID = NS_CONTENT_ID_COUNTER_BASE; mDTD = 0; @@ -711,9 +709,7 @@ nsDocument::~nsDocument() NS_IF_RELEASE(mWordBreaker); NS_IF_RELEASE(mDTD); - - delete mFileSpec; - + delete mBoxObjectTable; } @@ -3365,20 +3361,19 @@ NS_IMETHODIMP nsDocument::FindNext(const nsAReadableString& aSearchStr, PRBool a return NS_ERROR_FAILURE; } -/** - * nsIDiskDocument methods - */ NS_IMETHODIMP -nsDocument::InitDiskDocument(nsFileSpec* aFileSpec) +nsDocument::InitDiskDocument(nsIFile *aFile) { - mFileSpec = nsnull; + // aFile may be nsnull here + mFileSpec = nsnull; // delete if we have one - if (aFileSpec) + if (aFile) { - mFileSpec = new nsFileSpec(*aFileSpec); - if (!mFileSpec) - return NS_ERROR_OUT_OF_MEMORY; + // we clone the nsIFile here, rather than just holding onto a ref, + // in case the caller does something to aFile later + nsresult rv = aFile->Clone(getter_AddRefs(mFileSpec)); + if (NS_FAILED(rv)) return rv; } mModCount = 0; @@ -3388,55 +3383,53 @@ nsDocument::InitDiskDocument(nsFileSpec* aFileSpec) NS_IMETHODIMP -nsDocument::SaveFile(nsFileSpec* aFileSpec, - PRBool aReplaceExisting, - PRBool aSaveCopy, - const nsString& aFormatType, - const nsString& aSaveCharset, - PRUint32 aFlags, - PRUint32 aWrapColumn) +nsDocument::SaveFile( nsIFile* aFile, + PRBool aReplaceExisting, + PRBool aSaveCopy, + const PRUnichar* aFileType, // MIME type of file to save + const PRUnichar* aFileCharset, + PRUint32 aSaveFlags, + PRUint32 aWrapColumn) { - if (!aFileSpec) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aFile); + NS_ENSURE_ARG_POINTER(aFileType); + NS_ENSURE_ARG_POINTER(aFileCharset); nsresult rv = NS_OK; // if we're not replacing an existing file but the file // exists, somethine is wrong - if (!aReplaceExisting && aFileSpec->Exists()) + PRBool fileExists; + rv = aFile->Exists(&fileExists); + if (NS_FAILED(rv)) return rv; + + if (!aReplaceExisting && fileExists) return NS_ERROR_FAILURE; // where are the file I/O errors? - nsOutputFileStream stream(*aFileSpec); - // if the stream didn't open, something went wrong - if (!stream.is_open()) - return NS_BASE_STREAM_CLOSED; - - // Get a document encoder instance: - nsCOMPtr encoder; - char* contractid = (char *)nsMemory::Alloc(strlen(NS_DOC_ENCODER_CONTRACTID_BASE) - + aFormatType.Length() + 1); - if (! contractid) - return NS_ERROR_OUT_OF_MEMORY; - strcpy(contractid, NS_DOC_ENCODER_CONTRACTID_BASE); - char* type = aFormatType.ToNewCString(); - strcat(contractid, type); - nsCRT::free(type); - rv = nsComponentManager::CreateInstance(contractid, - nsnull, - NS_GET_IID(nsIDocumentEncoder), - getter_AddRefs(encoder)); - nsCRT::free(contractid); + + nsCOMPtr outputStream = do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = outputStream->Init(aFile, -1, -1); + if (NS_FAILED(rv)) return rv; + + // Get a document encoder instance + nsCAutoString contractID(NS_DOC_ENCODER_CONTRACTID_BASE); + contractID.AppendWithConversion(aFileType); + + nsCOMPtr encoder = do_CreateInstance(contractID, &rv); + if (NS_FAILED(rv)) + return rv; + + nsAutoString fileType(aFileType); // sucky copy + rv = encoder->Init(this, fileType, aSaveFlags); if (NS_FAILED(rv)) return rv; - rv = encoder->Init(this, aFormatType, aFlags); - if (NS_FAILED(rv)) - return rv; - - if (aFlags & nsIDocumentEncoder::OutputWrap) + if (aSaveFlags & nsIDocumentEncoder::OutputWrap) encoder->SetWrapColumn(aWrapColumn); - nsAutoString charsetStr(aSaveCharset); + nsAutoString charsetStr(aFileCharset); if (charsetStr.Length() == 0) { rv = GetDocumentCharacterSet(charsetStr); @@ -3446,7 +3439,7 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec, } encoder->SetCharset(charsetStr); - rv = encoder->EncodeToStream(stream.GetIStream()); + rv = encoder->EncodeToStream(outputStream); if (NS_SUCCEEDED(rv)) { @@ -3454,13 +3447,13 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec, // store the new fileSpec in the doc if (!aSaveCopy) { - delete mFileSpec; - mFileSpec = new nsFileSpec(*aFileSpec); - if (!mFileSpec) - return NS_ERROR_OUT_OF_MEMORY; + // we clone the nsIFile here, rather than just holding onto a ref, + // in case the caller does something to aFile later + nsresult rv = aFile->Clone(getter_AddRefs(mFileSpec)); + if (NS_FAILED(rv)) return rv; // and mark the document as clean - ResetModCount(); + ResetModificationCount(); } } @@ -3468,15 +3461,15 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec, } NS_IMETHODIMP -nsDocument::GetFileSpec(nsFileSpec& aFileSpec) +nsDocument::GetFileSpec(nsIFile * *aFileSpec) { - if (mFileSpec) - { - aFileSpec = *mFileSpec; - return NS_OK; - } + NS_ENSURE_ARG_POINTER(aFileSpec); - return NS_ERROR_NOT_INITIALIZED; + if (!mFileSpec) + return NS_ERROR_NOT_INITIALIZED; + + NS_IF_ADDREF(*aFileSpec = mFileSpec); + return NS_OK; } NS_IMETHODIMP @@ -3518,7 +3511,7 @@ nsDocument::GetBindingManager(nsIBindingManager** aResult) NS_IMETHODIMP -nsDocument::GetModCount(PRInt32 *outModCount) +nsDocument::GetModificationCount(PRInt32 *outModCount) { if (!outModCount) return NS_ERROR_NULL_POINTER; @@ -3529,14 +3522,14 @@ nsDocument::GetModCount(PRInt32 *outModCount) NS_IMETHODIMP -nsDocument::ResetModCount() +nsDocument::ResetModificationCount() { mModCount = 0; return NS_OK; } NS_IMETHODIMP -nsDocument::IncrementModCount(PRInt32 aNumMods) +nsDocument::IncrementModificationCount(PRInt32 aNumMods) { mModCount += aNumMods; //NS_ASSERTION(mModCount >= 0, "Modification count went negative"); diff --git a/mozilla/layout/base/src/nsDocument.h b/mozilla/layout/base/src/nsDocument.h index abd11fd06be..eb6cb91b248 100644 --- a/mozilla/layout/base/src/nsDocument.h +++ b/mozilla/layout/base/src/nsDocument.h @@ -411,19 +411,7 @@ public: NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent); // nsIDiskDocument inteface - NS_IMETHOD InitDiskDocument(nsFileSpec *aFileSpec); - NS_IMETHOD SaveFile(nsFileSpec* aFileSpec, - PRBool aReplaceExisting, - PRBool aSaveCopy, - const nsString& aSaveFileType, - const nsString& aSaveCharset, - PRUint32 aFlags, - PRUint32 aWrapColumn); - - NS_IMETHOD GetFileSpec(nsFileSpec& aFileSpec); - NS_IMETHOD GetModCount(PRInt32 *outModCount); - NS_IMETHOD ResetModCount(); - NS_IMETHOD IncrementModCount(PRInt32 aNumMods); + NS_DECL_NSIDISKDOCUMENT // nsIDOMEventTarget interface NS_IMETHOD AddEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, @@ -503,8 +491,8 @@ protected: PRInt32 mNextContentID; // disk file members - nsFileSpec* mFileSpec; - PRInt32 mModCount; + nsCOMPtr mFileSpec; + PRInt32 mModCount; nsIDTD* mDTD; diff --git a/mozilla/layout/macbuild/layoutIDL.mcp b/mozilla/layout/macbuild/layoutIDL.mcp index 9c56fca9b74..1d8a9dbcd02 100644 Binary files a/mozilla/layout/macbuild/layoutIDL.mcp and b/mozilla/layout/macbuild/layoutIDL.mcp differ diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.cpp b/mozilla/mailnews/compose/src/nsMsgCompose.cpp index 7f83868cff9..4fc90079142 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompose.cpp @@ -28,6 +28,7 @@ #include "nsIDOMNodeList.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMDocument.h" +#include "nsIDiskDocument.h" #include "nsISelection.h" #include "nsISelectionController.h" #include "nsIDOMNamedNodeMap.h" @@ -942,12 +943,12 @@ nsresult nsMsgCompose::SetBodyModified(PRBool modified) if (modified) { PRInt32 modCount = 0; - diskDoc->GetModCount(&modCount); + diskDoc->GetModificationCount(&modCount); if (modCount == 0) - diskDoc->IncrementModCount(1); + diskDoc->IncrementModificationCount(1); } else - diskDoc->ResetModCount(); + diskDoc->ResetModificationCount(); } } diff --git a/mozilla/xpcom/io/nsIFileStream.h b/mozilla/xpcom/io/nsIFileStream.h index 232137b2524..809d27b6516 100644 --- a/mozilla/xpcom/io/nsIFileStream.h +++ b/mozilla/xpcom/io/nsIFileStream.h @@ -73,6 +73,10 @@ public: NS_IMETHOD SetAtEOF(PRBool inAtEOF) = 0; }; // class nsIRandomAccessStore + +#ifndef NO_XPCOM_FILE_STREAMS // hack to work around duplicate class definitions in here + // and mozilla/netwerks/base/nsIFileStreams.idl + /* a6cf90e6-15b3-11d2-932e-00805f8add32 */ #define NS_IFILEINPUTSTREAM_IID \ { 0xa6cf90e6, 0x15b3, 0x11d2, \ @@ -107,6 +111,8 @@ public: static const nsIID& GetIID() { static nsIID iid = NS_IFILEOUTPUTSTREAM_IID; return iid; } }; // class nsIFileOutputStream +#endif // NO_XPCOM_FILE_STREAMS + //---------------------------------------------------------------------------------------- extern "C" NS_COM nsresult NS_NewTypicalInputFileStream( nsISupports** aStreamResult,