From 245522302fd5a734f671a4e428defa9260fbdc59 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Tue, 3 Aug 1999 21:48:40 +0000 Subject: [PATCH] 10720 fix - we now do meta tag refreshes git-svn-id: svn://10.0.0.236/trunk@42028 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLContentSink.cpp | 25 +++++- mozilla/docshell/base/nsWebShell.cpp | 79 ++++++++++++++----- .../html/document/src/nsHTMLContentSink.cpp | 25 +++++- mozilla/webshell/public/MANIFEST | 1 + mozilla/webshell/public/Makefile.in | 3 + mozilla/webshell/public/makefile.win | 5 +- mozilla/webshell/public/nsIRefreshURI.h | 53 +++++++++++++ mozilla/webshell/src/nsWebShell.cpp | 79 ++++++++++++++----- 8 files changed, 225 insertions(+), 45 deletions(-) create mode 100644 mozilla/webshell/public/nsIRefreshURI.h diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 70e930990ea..373bca12f89 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -65,7 +65,9 @@ #include "nsStyleConsts.h" #include "nsINameSpaceManager.h" #include "nsIDOMHTMLMapElement.h" - +#ifdef NECKO +#include "nsIRefreshURI.h" +#endif //NECKO #include "nsVoidArray.h" #include "nsIScriptContextOwner.h" #include "nsHTMLIIDs.h" @@ -2879,7 +2881,26 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode) it->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::content, result); if (result.Length() > 0) { #ifdef NECKO - NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)"); + // XXX necko isn't going to process headers coming in from the parser + //NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)"); + + // parse out the content + nsIRefreshURI *reefer = nsnull; + rv = mWebShell->QueryInterface(nsCOMTypeInfo::GetIID(), (void**)&reefer); + if (NS_FAILED(rv)) return rv; + + const PRUnichar *uriStr = nsnull; + rv = mWebShell->GetURL(&uriStr); + if (NS_FAILED(rv)) return rv; + + nsIURI *uri = nsnull; + rv = NS_NewURI(&uri, uriStr, nsnull); + if (NS_FAILED(rv)) return rv; + + PRInt32 error; + PRInt32 millis = result.ToInteger(&error) * 1000; + rv = reefer->RefreshURI(uri, millis, PR_FALSE); + if (NS_FAILED(rv)) return rv; #else if (nsnull != httpUrl) { char* value = result.ToNewCString(), *csHeader; diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 2e1e8cb2379..c9bcee1bfa3 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -29,6 +29,7 @@ #include "nsNeckoUtil.h" #include "nsIProtocolHandler.h" #include "nsIDNSService.h" +#include "nsIRefreshURI.h" #else #include "nsINetSupport.h" #include "nsIRefreshUrl.h" @@ -143,6 +144,7 @@ class nsWebShell : public nsIWebShell, public nsIDocumentLoaderObserver, #ifdef NECKO public nsIPrompt, + public nsIRefreshURI, #else public nsIRefreshUrl, public nsINetSupport, @@ -354,11 +356,17 @@ public: #endif // NS_IMETHOD OnConnectionsComplete(); - // nsIRefreshURL interface methods... - NS_IMETHOD RefreshURL(nsIURI* aURL, PRInt32 millis, PRBool repeat); - NS_IMETHOD RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat); - NS_IMETHOD CancelRefreshURLTimers(void); + NS_IMETHOD RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat); + + // nsIRefreshURL interface methods... +#ifndef NECKO + NS_IMETHOD RefreshURL(nsIURI* aURL, PRInt32 aMillis, PRBool aRepeat); + NS_IMETHOD CancelRefreshURLTimers(void); +#else + NS_IMETHOD RefreshURI(nsIURI* aURI, PRInt32 aMillis, PRBool aRepeat); + NS_IMETHOD CancelRefreshURITimers(void); +#endif // NECKO #if 0 // nsIStreamObserver @@ -545,7 +553,10 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); #ifndef NECKO static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID); static NS_DEFINE_IID(kRefreshURLIID, NS_IREFRESHURL_IID); +#else +static NS_DEFINE_IID(kRefreshURIIID, NS_IREFRESHURI_IID); #endif + static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kIWebShellServicesIID, NS_IWEB_SHELL_SERVICES_IID); static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); @@ -664,7 +675,11 @@ nsWebShell::~nsWebShell() NS_RELEASE(mDocLoader); } // Cancel any timers that were set for this loader. +#ifndef NECKO CancelRefreshURLTimers(); +#else + CancelRefreshURITimers(); +#endif // NECKO ++mRefCnt; // following releases can cause this destructor to be called // recursively if the refcount is allowed to remain 0 @@ -813,26 +828,30 @@ nsWebShell::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } -#ifndef NECKO - if (aIID.Equals(kRefreshURLIID)) { - *aInstancePtr = (void*)(nsIRefreshUrl*)this; - NS_ADDREF_THIS(); - return NS_OK; - } -#endif + #ifdef NECKO if (aIID.Equals(nsIPrompt::GetIID())) { *aInstancePtr = (void*) ((nsIPrompt*)this); NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(kRefreshURIIID)) { + *aInstancePtr = (void*) ((nsIRefreshURI*)this); + NS_ADDREF_THIS(); + return NS_OK; + } #else if (aIID.Equals(kINetSupportIID)) { *aInstancePtr = (void*) ((nsINetSupport*)this); NS_ADDREF_THIS(); return NS_OK; } -#endif + if (aIID.Equals(kRefreshURLIID)) { + *aInstancePtr = (void*)((nsIRefreshUrl*)this); + NS_ADDREF_THIS(); + return NS_OK; + } +#endif // NECKO if (aIID.Equals(kIClipboardCommandsIID)) { *aInstancePtr = (void*) ((nsIClipboardCommands*)this); NS_ADDREF_THIS(); @@ -1976,6 +1995,10 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, urlStr.Trim(" ", PR_TRUE, PR_TRUE); convertFileToURL(urlStr, urlSpec); +#ifdef NECKO + CancelRefreshURITimers(); +#endif // NECKO + //#ifdef NECKO // nsCOMPtr url; // rv = NS_NewURI(getter_AddRefs(url), urlSpec); @@ -2131,7 +2154,11 @@ NS_IMETHODIMP nsWebShell::Stop(void) } // Cancel any timers that were set for this loader. +#ifndef NECKO CancelRefreshURLTimers(); +#else + CancelRefreshURITimers(); +#endif // NECKO if (mDocLoader) { // Stop any documents that are currently being loaded... @@ -2179,7 +2206,11 @@ nsWebShell::StopAfterURLAvailable() } // Cancel any timers that were set for this loader. +#ifndef NECKO CancelRefreshURLTimers(); +#else + CancelRefreshURITimers(); +#endif // NECKO // Recurse down the webshell hierarchy. PRInt32 i, n = mChildren.Count(); @@ -3223,12 +3254,16 @@ void refreshData::Notify(nsITimer *aTimer) NS_IMETHODIMP -nsWebShell::RefreshURL(nsIURI* aURL, PRInt32 millis, PRBool repeat) +#ifndef NECKO +nsWebShell::RefreshURL(nsIURI* aURI, PRInt32 millis, PRBool repeat) +#else +nsWebShell::RefreshURI(nsIURI* aURI, PRInt32 millis, PRBool repeat) +#endif // NECKO { nsresult rv = NS_OK; - if (nsnull == aURL) { - NS_PRECONDITION((aURL != nsnull), "Null pointer"); + if (nsnull == aURI) { + NS_PRECONDITION((aURI != nsnull), "Null pointer"); rv = NS_ERROR_NULL_POINTER; goto done; } @@ -3238,7 +3273,7 @@ nsWebShell::RefreshURL(nsIURI* aURL, PRInt32 millis, PRBool repeat) #else const char* spec; #endif - aURL->GetSpec(&spec); + aURI->GetSpec(&spec); rv = RefreshURL(spec, millis, repeat); #ifdef NECKO nsCRT::free(spec); @@ -3248,14 +3283,14 @@ done: } NS_IMETHODIMP -nsWebShell::RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat) +nsWebShell::RefreshURL(const char* aURI, PRInt32 millis, PRBool repeat) { nsresult rv = NS_OK; nsITimer *timer=nsnull; refreshData *data; - if (nsnull == aURL) { - NS_PRECONDITION((aURL != nsnull), "Null pointer"); + if (nsnull == aURI) { + NS_PRECONDITION((aURI != nsnull), "Null pointer"); rv = NS_ERROR_NULL_POINTER; goto done; } @@ -3272,7 +3307,7 @@ nsWebShell::RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat) data->mShell = this; NS_ADDREF(data->mShell); - data->mUrlSpec = aURL; + data->mUrlSpec = aURI; data->mDelay = millis; data->mRepeat = repeat; @@ -3292,7 +3327,11 @@ done: } NS_IMETHODIMP +#ifdef NECKO +nsWebShell::CancelRefreshURITimers(void) +#else nsWebShell::CancelRefreshURLTimers(void) +#endif // NECKO { PRInt32 i; nsITimer* timer; diff --git a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp index 70e930990ea..373bca12f89 100644 --- a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp @@ -65,7 +65,9 @@ #include "nsStyleConsts.h" #include "nsINameSpaceManager.h" #include "nsIDOMHTMLMapElement.h" - +#ifdef NECKO +#include "nsIRefreshURI.h" +#endif //NECKO #include "nsVoidArray.h" #include "nsIScriptContextOwner.h" #include "nsHTMLIIDs.h" @@ -2879,7 +2881,26 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode) it->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::content, result); if (result.Length() > 0) { #ifdef NECKO - NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)"); + // XXX necko isn't going to process headers coming in from the parser + //NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)"); + + // parse out the content + nsIRefreshURI *reefer = nsnull; + rv = mWebShell->QueryInterface(nsCOMTypeInfo::GetIID(), (void**)&reefer); + if (NS_FAILED(rv)) return rv; + + const PRUnichar *uriStr = nsnull; + rv = mWebShell->GetURL(&uriStr); + if (NS_FAILED(rv)) return rv; + + nsIURI *uri = nsnull; + rv = NS_NewURI(&uri, uriStr, nsnull); + if (NS_FAILED(rv)) return rv; + + PRInt32 error; + PRInt32 millis = result.ToInteger(&error) * 1000; + rv = reefer->RefreshURI(uri, millis, PR_FALSE); + if (NS_FAILED(rv)) return rv; #else if (nsnull != httpUrl) { char* value = result.ToNewCString(), *csHeader; diff --git a/mozilla/webshell/public/MANIFEST b/mozilla/webshell/public/MANIFEST index 69ed41f20cd..88bd0581cc3 100644 --- a/mozilla/webshell/public/MANIFEST +++ b/mozilla/webshell/public/MANIFEST @@ -15,3 +15,4 @@ nsIWebShellServices.h nsIClipboardCommands.h nsIUrlDispatcher.h nsweb.h +nsIRefreshURI.h diff --git a/mozilla/webshell/public/Makefile.in b/mozilla/webshell/public/Makefile.in index 0447af54c24..2fecf19e075 100644 --- a/mozilla/webshell/public/Makefile.in +++ b/mozilla/webshell/public/Makefile.in @@ -38,6 +38,9 @@ EXPORTS = \ nsweb.h \ nsIDocStreamLoaderFactory.h \ nsIUrlDispatcher.h \ +ifdef NECKO + nsIRefreshURI.h \ +endif $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/webshell/public/makefile.win b/mozilla/webshell/public/makefile.win index 586bb7338f1..854687624a7 100644 --- a/mozilla/webshell/public/makefile.win +++ b/mozilla/webshell/public/makefile.win @@ -31,10 +31,13 @@ EXPORTS = \ nsILinkHandler.h \ nsIThrobber.h \ nsIWebShell.h \ - nsIWebShellServices.h \ + nsIWebShellServices.h \ nsIClipboardCommands.h \ nsIUrlDispatcher.h \ nsweb.h \ +!ifdef NECKO + nsIRefreshURI.h \ +!endif $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/webshell/public/nsIRefreshURI.h b/mozilla/webshell/public/nsIRefreshURI.h new file mode 100644 index 00000000000..56dac2423c1 --- /dev/null +++ b/mozilla/webshell/public/nsIRefreshURI.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsIRefreshUri_h___ +#define nsIRefreshUri_h___ + +#include "nscore.h" +#include "nsISupports.h" +#include "nsIURI.h" + +#include "nspr.h" + +/* 69EFC430-2EFE-11d2-9E5D-006008BF092E */ +#define NS_IREFRESHURI_IID \ +{ 0x69efc430, 0x2efe, 0x11d2, \ + { 0x9e, 0x5d, 0x0, 0x60, 0x8, 0xbf, 0x9, 0x2e } } + +struct nsIRefreshURI : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IREFRESHURI_IID) + + /** + * Reloads a uri after waiting millis milliseconds. + * + * @param uri The uri to refresh. + * @param millis The number of milliseconds to wait. + * @param repeat Do you want the uri to be repeatedly refreshed every millis milliseconds. + */ + NS_IMETHOD RefreshURI(nsIURI *aURI, PRInt32 aMillis, PRBool aRepeat) = 0; + + /** + * Cancels all timer loads. + */ + NS_IMETHOD CancelRefreshURITimers(void) = 0; +}; + +#endif /* nsIRefreshUri_h___ */ diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 2e1e8cb2379..c9bcee1bfa3 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -29,6 +29,7 @@ #include "nsNeckoUtil.h" #include "nsIProtocolHandler.h" #include "nsIDNSService.h" +#include "nsIRefreshURI.h" #else #include "nsINetSupport.h" #include "nsIRefreshUrl.h" @@ -143,6 +144,7 @@ class nsWebShell : public nsIWebShell, public nsIDocumentLoaderObserver, #ifdef NECKO public nsIPrompt, + public nsIRefreshURI, #else public nsIRefreshUrl, public nsINetSupport, @@ -354,11 +356,17 @@ public: #endif // NS_IMETHOD OnConnectionsComplete(); - // nsIRefreshURL interface methods... - NS_IMETHOD RefreshURL(nsIURI* aURL, PRInt32 millis, PRBool repeat); - NS_IMETHOD RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat); - NS_IMETHOD CancelRefreshURLTimers(void); + NS_IMETHOD RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat); + + // nsIRefreshURL interface methods... +#ifndef NECKO + NS_IMETHOD RefreshURL(nsIURI* aURL, PRInt32 aMillis, PRBool aRepeat); + NS_IMETHOD CancelRefreshURLTimers(void); +#else + NS_IMETHOD RefreshURI(nsIURI* aURI, PRInt32 aMillis, PRBool aRepeat); + NS_IMETHOD CancelRefreshURITimers(void); +#endif // NECKO #if 0 // nsIStreamObserver @@ -545,7 +553,10 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); #ifndef NECKO static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID); static NS_DEFINE_IID(kRefreshURLIID, NS_IREFRESHURL_IID); +#else +static NS_DEFINE_IID(kRefreshURIIID, NS_IREFRESHURI_IID); #endif + static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kIWebShellServicesIID, NS_IWEB_SHELL_SERVICES_IID); static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); @@ -664,7 +675,11 @@ nsWebShell::~nsWebShell() NS_RELEASE(mDocLoader); } // Cancel any timers that were set for this loader. +#ifndef NECKO CancelRefreshURLTimers(); +#else + CancelRefreshURITimers(); +#endif // NECKO ++mRefCnt; // following releases can cause this destructor to be called // recursively if the refcount is allowed to remain 0 @@ -813,26 +828,30 @@ nsWebShell::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } -#ifndef NECKO - if (aIID.Equals(kRefreshURLIID)) { - *aInstancePtr = (void*)(nsIRefreshUrl*)this; - NS_ADDREF_THIS(); - return NS_OK; - } -#endif + #ifdef NECKO if (aIID.Equals(nsIPrompt::GetIID())) { *aInstancePtr = (void*) ((nsIPrompt*)this); NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(kRefreshURIIID)) { + *aInstancePtr = (void*) ((nsIRefreshURI*)this); + NS_ADDREF_THIS(); + return NS_OK; + } #else if (aIID.Equals(kINetSupportIID)) { *aInstancePtr = (void*) ((nsINetSupport*)this); NS_ADDREF_THIS(); return NS_OK; } -#endif + if (aIID.Equals(kRefreshURLIID)) { + *aInstancePtr = (void*)((nsIRefreshUrl*)this); + NS_ADDREF_THIS(); + return NS_OK; + } +#endif // NECKO if (aIID.Equals(kIClipboardCommandsIID)) { *aInstancePtr = (void*) ((nsIClipboardCommands*)this); NS_ADDREF_THIS(); @@ -1976,6 +1995,10 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, urlStr.Trim(" ", PR_TRUE, PR_TRUE); convertFileToURL(urlStr, urlSpec); +#ifdef NECKO + CancelRefreshURITimers(); +#endif // NECKO + //#ifdef NECKO // nsCOMPtr url; // rv = NS_NewURI(getter_AddRefs(url), urlSpec); @@ -2131,7 +2154,11 @@ NS_IMETHODIMP nsWebShell::Stop(void) } // Cancel any timers that were set for this loader. +#ifndef NECKO CancelRefreshURLTimers(); +#else + CancelRefreshURITimers(); +#endif // NECKO if (mDocLoader) { // Stop any documents that are currently being loaded... @@ -2179,7 +2206,11 @@ nsWebShell::StopAfterURLAvailable() } // Cancel any timers that were set for this loader. +#ifndef NECKO CancelRefreshURLTimers(); +#else + CancelRefreshURITimers(); +#endif // NECKO // Recurse down the webshell hierarchy. PRInt32 i, n = mChildren.Count(); @@ -3223,12 +3254,16 @@ void refreshData::Notify(nsITimer *aTimer) NS_IMETHODIMP -nsWebShell::RefreshURL(nsIURI* aURL, PRInt32 millis, PRBool repeat) +#ifndef NECKO +nsWebShell::RefreshURL(nsIURI* aURI, PRInt32 millis, PRBool repeat) +#else +nsWebShell::RefreshURI(nsIURI* aURI, PRInt32 millis, PRBool repeat) +#endif // NECKO { nsresult rv = NS_OK; - if (nsnull == aURL) { - NS_PRECONDITION((aURL != nsnull), "Null pointer"); + if (nsnull == aURI) { + NS_PRECONDITION((aURI != nsnull), "Null pointer"); rv = NS_ERROR_NULL_POINTER; goto done; } @@ -3238,7 +3273,7 @@ nsWebShell::RefreshURL(nsIURI* aURL, PRInt32 millis, PRBool repeat) #else const char* spec; #endif - aURL->GetSpec(&spec); + aURI->GetSpec(&spec); rv = RefreshURL(spec, millis, repeat); #ifdef NECKO nsCRT::free(spec); @@ -3248,14 +3283,14 @@ done: } NS_IMETHODIMP -nsWebShell::RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat) +nsWebShell::RefreshURL(const char* aURI, PRInt32 millis, PRBool repeat) { nsresult rv = NS_OK; nsITimer *timer=nsnull; refreshData *data; - if (nsnull == aURL) { - NS_PRECONDITION((aURL != nsnull), "Null pointer"); + if (nsnull == aURI) { + NS_PRECONDITION((aURI != nsnull), "Null pointer"); rv = NS_ERROR_NULL_POINTER; goto done; } @@ -3272,7 +3307,7 @@ nsWebShell::RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat) data->mShell = this; NS_ADDREF(data->mShell); - data->mUrlSpec = aURL; + data->mUrlSpec = aURI; data->mDelay = millis; data->mRepeat = repeat; @@ -3292,7 +3327,11 @@ done: } NS_IMETHODIMP +#ifdef NECKO +nsWebShell::CancelRefreshURITimers(void) +#else nsWebShell::CancelRefreshURLTimers(void) +#endif // NECKO { PRInt32 i; nsITimer* timer;