Implement "replace" argument for document.open(). bug 164821, r+sr=jst

This commit is contained in:
bzbarsky%mit.edu 2004-04-28 01:40:39 +00:00
Родитель e5c7f93521
Коммит f4439f7df0
4 изменённых файлов: 45 добавлений и 10 удалений

Просмотреть файл

@ -1986,7 +1986,7 @@ nsHTMLDocument::GetSourceDocumentURI(nsIURI** sourceURI)
// XXX TBI: accepting arguments to the open method.
nsresult
nsHTMLDocument::OpenCommon(nsIURI* aSourceURI)
nsHTMLDocument::OpenCommon(nsIURI* aSourceURI, PRBool aReplace)
{
// If we already have a parser we ignore the document.open call.
if (mParser) {
@ -2128,6 +2128,24 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURI)
// out of band document.write()
if (docshell) {
docshell->PrepareForNewContentModel();
// Now check whether we were opened with a "replace" argument. If
// so, we need to tell the docshell to not create a new history
// entry for this load.
// XXXbz we're basically duplicating the MAKE_LOAD_TYPE macro from
// nsDocShell.h. All this stuff needs better apis.
PRUint32 loadType;
if (aReplace) {
loadType = nsIDocShell::LOAD_CMD_NORMAL |
(nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY << 16);
} else {
// Make sure that we're doing a normal load, not whatever type
// of load was previously done on this docshell.
loadType = nsIDocShell::LOAD_CMD_NORMAL |
(nsIWebNavigation::LOAD_FLAGS_NONE << 16);
}
docshell->SetLoadType(loadType);
nsCOMPtr<nsIContentViewer> cv;
docshell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(cv);
@ -2147,11 +2165,11 @@ NS_IMETHODIMP
nsHTMLDocument::Open()
{
nsCOMPtr<nsIDOMDocument> doc;
return Open(getter_AddRefs(doc));
return Open(PR_FALSE, getter_AddRefs(doc));
}
NS_IMETHODIMP
nsHTMLDocument::Open(nsIDOMDocument** aReturn)
nsHTMLDocument::Open(PRBool aReplace, nsIDOMDocument** aReturn)
{
// XXX The URI of the newly created document will match
// that of the source document. Is this right?
@ -2167,7 +2185,7 @@ nsHTMLDocument::Open(nsIDOMDocument** aReturn)
}
NS_ENSURE_SUCCESS(rv, rv);
rv = OpenCommon(sourceURI);
rv = OpenCommon(sourceURI, aReplace);
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(this, aReturn);

Просмотреть файл

@ -246,7 +246,7 @@ protected:
nsresult WriteCommon(const nsAString& aText,
PRBool aNewlineTerminate);
nsresult ScriptWriteCommon(PRBool aNewlineTerminate);
nsresult OpenCommon(nsIURI* aUrl);
nsresult OpenCommon(nsIURI* aUrl, PRBool aReplace);
nsresult CreateAndAddWyciwygChannel(void);
nsresult RemoveWyciwygChannel(void);

Просмотреть файл

@ -39,7 +39,7 @@
#include "domstubs.idl"
[scriptable, uuid(a6cf90c5-15b3-11d2-932e-00805f8add32)]
[scriptable, uuid(79beb289-3644-4b54-9432-9fb993945629)]
interface nsIDOMNSHTMLDocument : nsISupports
{
readonly attribute long width;
@ -55,8 +55,13 @@ interface nsIDOMNSHTMLDocument : nsISupports
DOMString getSelection();
// Scriptable versions of open(), write(), writeln().
nsIDOMDocument open();
// This is the internal version of open(); note that the version
// scriptable with JS is defined entirely in classinfo.
// Pass aReplace = true to trigger a replacement of the previous
// document in session history; pass false for normal history handling.
nsIDOMDocument open(in boolean aReplace);
// Scriptable versions of write(), writeln(), clear().
void write();
void writeln();
void clear();

Просмотреть файл

@ -5391,9 +5391,21 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
nsCOMPtr<nsIDOMNSHTMLDocument> doc(do_QueryInterface(native));
NS_ENSURE_TRUE(doc, JS_FALSE);
nsCOMPtr<nsIDOMDocument> retval;
PRBool replace = PR_FALSE;
if (argc > 1) {
JSString* jsstr = JS_ValueToString(cx, argv[1]);
if (!jsstr) {
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
return JS_FALSE;
}
rv = doc->Open(getter_AddRefs(retval));
replace = NS_LITERAL_STRING("replace").
Equals(NS_REINTERPRET_CAST(const PRUnichar*,
::JS_GetStringChars(jsstr)));
}
nsCOMPtr<nsIDOMDocument> retval;
rv = doc->Open(replace, getter_AddRefs(retval));
if (NS_FAILED(rv)) {
nsDOMClassInfo::ThrowJSException(cx, rv);