Index: layout/html/document/src/nsHTMLDocument.cpp
===================================================================
RCS file: /cvsroot/mozilla/layout/html/document/src/nsHTMLDocument.cpp,v
retrieving revision 3.276
diff -u -r3.276 nsHTMLDocument.cpp
--- nsHTMLDocument.cpp 2000/09/09 05:46:10 3.276
+++ nsHTMLDocument.cpp 2000/09/13 00:59:11
@@ -107,8 +107,9 @@
#include "nsICachedNetData.h"
#include "nsIXMLContent.h" //for createelementNS
#include "nsHTMLParts.h" //for createelementNS
+#include "nsISHistory.h"
+#include "nsIOutputStream.h"
-
#define DETECTOR_PROGID_MAX 127
static char g_detector_progid[DETECTOR_PROGID_MAX + 1];
static PRBool gInitDetector = PR_FALSE;
@@ -124,7 +125,7 @@
#include "prmem.h"
#include "prtime.h"
-// Find/Serach Includes
+// Find/Search Includes
const PRInt32 kForward = 0;
const PRInt32 kBackward = 1;
@@ -245,7 +246,8 @@
mBaseTarget(nsnull),
mLastModified(nsnull),
mReferrer(nsnull),
- mIsWriting(0)
+ mIsWriting(0),
+ mWyciwygSessionId(0)
{
mImages = nsnull;
mApplets = nsnull;
@@ -2069,6 +2071,7 @@
if (NS_OK == result) {
nsCOMPtr sink;
+ nsCOMPtr container;
nsCOMPtr webShell;
// Get the webshell of our primary presentation shell
@@ -2076,7 +2079,6 @@
if (shell) {
nsCOMPtr cx;
shell->GetPresContext(getter_AddRefs(cx));
- nsCOMPtr container;
if (NS_OK == cx->GetContainer(getter_AddRefs(container))) {
if (container) {
webShell = do_QueryInterface(container);
@@ -2090,7 +2092,74 @@
nsCOMPtr theDTD;
NS_NewNavHTMLDTD(getter_AddRefs(theDTD));
mParser->RegisterDTD(theDTD);
- mParser->SetContentSink(sink);
+ mParser->SetContentSink(sink);
+
+ // Generate URL of the form wyciwyg://4/http://mozilla.org
+ nsCOMPtr uri;
+ if (NS_FAILED(GetBaseURL(*getter_AddRefs(uri))))
+ return NS_ERROR_FAILURE;
+ nsXPIDLCString spec;
+ if (NS_FAILED(uri->GetSpec(getter_Copies(spec))))
+ return NS_ERROR_FAILURE;
+
+ nsAutoString newURIString; newURIString.AssignWithConversion( "wyciwyg://" );
+ newURIString.AppendInt(mWyciwygSessionId++, 10);
+ newURIString.AppendWithConversion("/");
+ newURIString.AppendWithConversion(spec);
+
+ nsCOMPtr newURI;
+ if (NS_FAILED(NS_NewURI(getter_AddRefs(newURI), newURIString)))
+ return NS_ERROR_FAILURE;
+
+ // Create a cache entry to write the document to
+ nsCOMPtr serv = do_GetService(kIOServiceCID, &result);
+ if (NS_FAILED(result)) return result;
+
+ nsCOMPtr wyciwygCacheChannel;
+ result = NS_OpenURI(getter_AddRefs(wyciwygCacheChannel), newURI, serv);
+ if (NS_FAILED(result)) {
+ return result;
+ }
+
+ // Set the originalURI so that this is what appears in the URL bar
+ wyciwygCacheChannel->SetOriginalURI(uri);
+
+ // Get an output stream for use in WriteCommon and Close
+ result = wyciwygCacheChannel->OpenOutputStream(getter_AddRefs(mWyciwygToCacheStream));
+
+ // Call docShell's AddToSessionHistory to add entry to SH
+ if (container) {
+ nsCOMPtr docShell;
+ docShell = do_QueryInterface(container);
+
+// XXX Protected docShell->AddToSessionHistory(uri, nsnull, entry);
+
+ // Get session history
+ nsCOMPtr webNav(do_QueryInterface(container));
+ nsCOMPtr hist;
+ webNav->GetSessionHistory(getter_AddRefs(hist));
+
+ // Get current entry
+ nsCOMPtr entry;
+ if (hist) {
+ PRInt32 index = 0;
+ hist->GetIndex(&index);
+ hist->GetEntryAtIndex(index, PR_FALSE, getter_AddRefs(entry));
+
+ // Create a new entry if necessary.
+ if (!entry) {
+ entry = do_CreateInstance(NS_SHENTRY_PROGID);
+
+ if (!entry) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+ }
+ entry->Create(newURI, nsnull, nsnull, nsnull, nsnull);
+
+ // Add entry to session history
+ hist->AddEntry(entry, PR_TRUE);
+ }
+ }
}
}
}
@@ -2162,6 +2231,11 @@
NS_IF_RELEASE(mParser);
}
+ if (mWyciwygToCacheStream) {
+ mWyciwygToCacheStream->Close();
+ mWyciwygToCacheStream = nsnull;
+ }
+
return NS_OK;
}
@@ -2184,13 +2258,19 @@
str.AppendWithConversion('\n');
}
+ // Parse the buffer to the document
mWriteLevel++;
result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(),
NS_ConvertASCIItoUCS2("text/html"), PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
mWriteLevel--;
- if (NS_OK != result) {
- return result;
+
+ // Also write the buffer out to cache
+ if (mWyciwygToCacheStream) {
+ PRUint32 numWritten;
+ char *buffer = NS_ConvertUCS2toUTF8(str); // We don't own this buffer
+ mWyciwygToCacheStream->Write(buffer, sizeof(buffer), &numWritten);
+ mWyciwygToCacheStream->Flush();
}
return result;
@@ -2216,7 +2296,6 @@
{
nsresult result = NS_OK;
-
nsXPIDLCString spec;
if (!mDocumentURL ||
(NS_SUCCEEDED(mDocumentURL->GetSpec(getter_Copies(spec))) &&
@@ -2278,13 +2357,20 @@
str.AppendWithConversion('\n');
}
+ // Parse the buffer to the document
mWriteLevel++;
result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(),
NS_ConvertASCIItoUCS2("text/html"), PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
+
mWriteLevel--;
- if (NS_OK != result) {
- return result;
+
+ // Also write the buffer out to cache
+ if (mWyciwygToCacheStream) {
+ PRUint32 numWritten;
+ char *buffer = NS_ConvertUCS2toUTF8(str); // We don't own this buffer
+ mWyciwygToCacheStream->Write(buffer, sizeof(buffer), &numWritten);
+ mWyciwygToCacheStream->Flush();
}
}
Index: layout/html/document/src/nsHTMLDocument.h
===================================================================
RCS file: /cvsroot/mozilla/layout/html/document/src/nsHTMLDocument.h,v
retrieving revision 3.78
diff -u -r3.78 nsHTMLDocument.h
--- nsHTMLDocument.h 2000/08/28 23:47:09 3.78
+++ nsHTMLDocument.h 2000/09/13 00:59:11
@@ -37,6 +37,7 @@
#include "rdf.h"
#include "nsRDFCID.h"
#include "nsIRDFService.h"
+#include "nsIOutputStream.h"
class nsContentList;
class nsIHTMLStyleSheet;
@@ -253,6 +254,9 @@
PRUint32 mIsWriting : 1;
PRUint32 mWriteLevel : 31;
+
+ PRUint32 mWyciwygSessionId;
+ nsCOMPtr mWyciwygToCacheStream;
};
#endif /* nsHTMLDocument_h___ */