1998-07-18 21:43:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2000-03-08 00:40:49 +00:00
|
|
|
* vi:tw=2:ts=2:et:sw=2:
|
1998-07-18 21:43:02 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* 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/
|
1998-07-18 21:43:02 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* 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.
|
1998-07-18 21:43:02 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 03:43:54 +00:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2000-03-11 01:05:08 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* Travis Bogard <travis@netscape.com>
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1998-07-18 21:43:02 +00:00
|
|
|
*/
|
2000-02-03 03:44:22 +00:00
|
|
|
|
2000-02-28 14:51:35 +00:00
|
|
|
#ifdef XP_OS2_VACPP
|
|
|
|
// XXX every other file that pulls in _os2.h has no problem with HTMX there;
|
|
|
|
// this one does; the problem may lie with the order of the headers below,
|
|
|
|
// which is why this fix is here instead of in _os2.h
|
|
|
|
typedef unsigned long HMTX;
|
|
|
|
#endif
|
1999-12-18 02:29:57 +00:00
|
|
|
#include "nsDocShell.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#include "nsIWebShell.h"
|
2000-02-14 09:16:26 +00:00
|
|
|
#include "nsIWebBrowserChrome.h"
|
1999-11-13 04:06:23 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#include "nsIDocumentLoader.h"
|
2000-01-29 06:06:25 +00:00
|
|
|
#include "nsIDocumentLoaderObserver.h"
|
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#include "nsIContentViewer.h"
|
1998-08-12 04:56:40 +00:00
|
|
|
#include "nsIDocumentViewer.h"
|
1999-11-19 07:35:27 +00:00
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
1998-11-04 08:48:22 +00:00
|
|
|
#include "nsIClipboardCommands.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIStreamListener.h"
|
2000-01-11 23:11:32 +00:00
|
|
|
#include "nsIPrompt.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1999-07-30 04:20:34 +00:00
|
|
|
#include "nsIProtocolHandler.h"
|
|
|
|
#include "nsIDNSService.h"
|
1999-08-03 21:48:40 +00:00
|
|
|
#include "nsIRefreshURI.h"
|
1998-07-21 04:46:55 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
1999-12-03 09:24:22 +00:00
|
|
|
#include "nsIScriptGlobalObjectOwner.h"
|
1999-10-13 10:24:12 +00:00
|
|
|
#include "nsIProgressEventSink.h"
|
1998-08-12 04:56:40 +00:00
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsIPresContext.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-01-05 09:46:33 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "plevent.h"
|
1998-08-14 23:08:54 +00:00
|
|
|
#include "prprf.h"
|
1998-07-27 23:08:52 +00:00
|
|
|
#include "nsIPluginHost.h"
|
1998-08-01 22:19:05 +00:00
|
|
|
#include "nsplugin.h"
|
1999-02-04 00:03:18 +00:00
|
|
|
//#include "nsPluginsCID.h"
|
|
|
|
#include "nsIPluginManager.h"
|
1998-07-31 06:02:06 +00:00
|
|
|
#include "nsIPref.h"
|
1998-08-18 23:25:17 +00:00
|
|
|
#include "nsITimer.h"
|
1998-09-25 22:25:21 +00:00
|
|
|
#include "nsITimerCallback.h"
|
1998-11-14 00:21:19 +00:00
|
|
|
#include "nsIContent.h"
|
1998-07-27 18:17:07 +00:00
|
|
|
#include "prlog.h"
|
1999-02-12 05:43:46 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-05-06 01:58:48 +00:00
|
|
|
#include "nsIWebShellServices.h"
|
1999-05-18 05:21:37 +00:00
|
|
|
#include "nsIGlobalHistory.h"
|
1999-06-28 10:35:57 +00:00
|
|
|
#include "prmem.h"
|
1999-07-03 03:41:34 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2000-02-11 04:48:09 +00:00
|
|
|
#include "nsDOMError.h"
|
1999-09-01 20:14:02 +00:00
|
|
|
#include "nsIDOMHTMLElement.h"
|
|
|
|
#include "nsIDOMHTMLDocument.h"
|
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsIDOMRange.h"
|
1999-11-18 07:06:39 +00:00
|
|
|
#include "nsIURIContentListener.h"
|
1999-11-12 00:19:00 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
1999-11-10 03:41:09 +00:00
|
|
|
#include "nsTimer.h"
|
1999-11-27 02:14:40 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
1999-11-30 04:32:09 +00:00
|
|
|
#include "nsIDocShell.h"
|
1999-12-03 10:57:59 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIDocShellTreeNode.h"
|
1999-12-12 10:16:15 +00:00
|
|
|
#include "nsIDocShellTreeOwner.h"
|
1999-11-30 04:32:09 +00:00
|
|
|
#include "nsCURILoader.h"
|
2000-02-08 13:40:10 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
2000-02-29 07:07:36 +00:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsIPlatformCharset.h"
|
|
|
|
#include "nsICharsetConverterManager.h"
|
2000-02-26 01:04:50 +00:00
|
|
|
#include "nsISocketTransportService.h"
|
1998-07-27 18:17:07 +00:00
|
|
|
|
2000-01-29 06:06:25 +00:00
|
|
|
#include "nsIHTTPChannel.h" // add this to the ick include list...we need it to QI for post data interface
|
|
|
|
#include "nsHTTPEnums.h"
|
|
|
|
|
|
|
|
|
1999-09-13 18:38:02 +00:00
|
|
|
#include "nsILocaleService.h"
|
2000-01-11 23:11:32 +00:00
|
|
|
#include "nsIStringBundle.h"
|
1999-09-13 18:38:02 +00:00
|
|
|
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
|
1999-12-02 07:00:17 +00:00
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
2000-01-11 23:11:32 +00:00
|
|
|
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
2000-02-29 07:07:36 +00:00
|
|
|
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
|
|
|
|
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
1999-08-29 14:31:08 +00:00
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
2000-01-12 22:54:07 +00:00
|
|
|
#include "nsIProtocolHandler.h"
|
1998-08-20 06:17:47 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
//XXX for nsIPostData; this is wrong; we shouldn't see the nsIDocument type
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
1998-11-26 18:06:47 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#undef NOISY_LINKS
|
1999-10-05 00:08:41 +00:00
|
|
|
#undef NOISY_WEBSHELL_LEAKS
|
1998-11-26 18:06:47 +00:00
|
|
|
#else
|
|
|
|
#undef NOISY_LINKS
|
1999-10-05 00:08:41 +00:00
|
|
|
#undef NOISY_WEBSHELL_LEAKS
|
|
|
|
#endif
|
|
|
|
|
1999-12-09 07:21:34 +00:00
|
|
|
#define NOISY_WEBSHELL_LEAKS
|
1999-10-05 00:08:41 +00:00
|
|
|
#ifdef NOISY_WEBSHELL_LEAKS
|
|
|
|
#undef DETECT_WEBSHELL_LEAKS
|
|
|
|
#define DETECT_WEBSHELL_LEAKS
|
1998-11-26 18:06:47 +00:00
|
|
|
#endif
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
/**
|
|
|
|
* Note: the log module is created during initialization which
|
|
|
|
* means that you cannot perform logging before then.
|
|
|
|
*/
|
1998-09-15 00:18:10 +00:00
|
|
|
static PRLogModuleInfo* gLogModule = PR_NewLogModule("webshell");
|
1998-07-18 21:43:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define WEB_TRACE_CALLS 0x1
|
|
|
|
#define WEB_TRACE_HISTORY 0x2
|
1999-07-04 23:40:15 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
#define WEB_LOG_TEST(_lm,_bit) (PRIntn((_lm)->level) & (_bit))
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#define WEB_TRACE(_bit,_args) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (WEB_LOG_TEST(gLogModule,_bit)) { \
|
|
|
|
PR_LogPrint _args; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
#else
|
|
|
|
#define WEB_TRACE(_bit,_args)
|
|
|
|
#endif
|
|
|
|
|
1998-08-12 19:54:39 +00:00
|
|
|
|
1999-01-23 00:52:01 +00:00
|
|
|
#if OLD_EVENT_QUEUE
|
|
|
|
/* The following is not used for the GTK version of the browser.
|
1999-09-06 22:59:11 +00:00
|
|
|
* It is still lurking around for Motif
|
1999-01-23 00:52:01 +00:00
|
|
|
*/
|
1998-08-12 19:54:39 +00:00
|
|
|
PLEventQueue* gWebShell_UnixEventQueue;
|
|
|
|
|
|
|
|
void nsWebShell_SetUnixEventQueue(PLEventQueue* aEventQueue)
|
|
|
|
{
|
|
|
|
gWebShell_UnixEventQueue = aEventQueue;
|
|
|
|
}
|
1999-01-23 00:52:01 +00:00
|
|
|
#endif /* OLD_EVENT_QUEUE */
|
1999-04-12 22:49:38 +00:00
|
|
|
|
1998-08-12 19:54:39 +00:00
|
|
|
|
1999-06-07 21:26:10 +00:00
|
|
|
static NS_DEFINE_CID(kGlobalHistoryCID, NS_GLOBALHISTORY_CID);
|
1999-06-18 17:34:08 +00:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
1999-06-07 21:26:10 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-09-23 03:27:53 +00:00
|
|
|
typedef enum {
|
|
|
|
eCharsetReloadInit,
|
|
|
|
eCharsetReloadRequested,
|
1999-09-23 21:30:07 +00:00
|
|
|
eCharsetReloadStopOrigional
|
1999-09-23 03:27:53 +00:00
|
|
|
} eCharsetReloadState;
|
|
|
|
|
1999-12-18 02:29:57 +00:00
|
|
|
class nsWebShell : public nsDocShell,
|
|
|
|
public nsIWebShell,
|
1998-07-18 21:43:02 +00:00
|
|
|
public nsIWebShellContainer,
|
1999-05-06 01:58:48 +00:00
|
|
|
public nsIWebShellServices,
|
1998-07-21 04:46:55 +00:00
|
|
|
public nsILinkHandler,
|
1998-08-18 23:25:17 +00:00
|
|
|
public nsIDocumentLoaderObserver,
|
1999-10-13 10:24:12 +00:00
|
|
|
public nsIProgressEventSink, // should go away (nsIDocLoaderObs)
|
1999-08-03 21:48:40 +00:00
|
|
|
public nsIRefreshURI,
|
1999-11-18 07:06:39 +00:00
|
|
|
public nsIURIContentListener,
|
1999-12-18 02:29:57 +00:00
|
|
|
public nsIClipboardCommands
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsWebShell();
|
|
|
|
virtual ~nsWebShell();
|
|
|
|
|
1999-02-26 20:02:06 +00:00
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
1998-07-18 21:43:02 +00:00
|
|
|
|
|
|
|
// nsISupports
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1999-11-18 07:06:39 +00:00
|
|
|
NS_DECL_NSIURICONTENTLISTENER
|
|
|
|
|
1999-11-13 04:06:23 +00:00
|
|
|
// nsIInterfaceRequestor
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
|
2000-01-29 06:06:25 +00:00
|
|
|
NS_DECL_NSIDOCUMENTLOADEROBSERVER
|
|
|
|
|
2000-02-29 22:35:33 +00:00
|
|
|
NS_IMETHOD SetupNewViewer(nsIContentViewer* aViewer);
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
// nsIContentViewerContainer
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_IMETHOD Embed(nsIContentViewer* aDocViewer,
|
1998-07-18 21:43:02 +00:00
|
|
|
const char* aCommand,
|
|
|
|
nsISupports* aExtraInfo);
|
|
|
|
|
|
|
|
// nsIWebShell
|
|
|
|
NS_IMETHOD SetContainer(nsIWebShellContainer* aContainer);
|
|
|
|
NS_IMETHOD GetContainer(nsIWebShellContainer*& aResult);
|
1999-11-16 20:06:12 +00:00
|
|
|
NS_IMETHOD GetTopLevelWindow(nsIWebShellContainer** aWebShellWindow);
|
1998-07-19 01:18:40 +00:00
|
|
|
NS_IMETHOD GetRootWebShell(nsIWebShell*& aResult);
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IMETHOD SetParent(nsIWebShell* aParent);
|
|
|
|
NS_IMETHOD GetParent(nsIWebShell*& aParent);
|
1999-10-25 22:20:10 +00:00
|
|
|
NS_IMETHOD GetReferrer(nsIURI **aReferrer);
|
1999-04-16 08:15:04 +00:00
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
// Document load api's
|
|
|
|
NS_IMETHOD GetDocumentLoader(nsIDocumentLoader*& aResult);
|
|
|
|
NS_IMETHOD LoadURL(const PRUnichar *aURLSpec,
|
1999-09-06 22:59:11 +00:00
|
|
|
nsIInputStream* aPostDataStream=nsnull,
|
1998-08-19 23:01:52 +00:00
|
|
|
PRBool aModifyHistory=PR_TRUE,
|
1999-07-01 19:30:20 +00:00
|
|
|
nsLoadFlags aType = nsIChannel::LOAD_NORMAL,
|
1999-09-02 21:39:01 +00:00
|
|
|
const PRUint32 localIP = 0,
|
1999-09-17 04:26:02 +00:00
|
|
|
nsISupports * aHistoryState = nsnull,
|
|
|
|
const PRUnichar* aReferrer=nsnull);
|
1998-11-11 20:31:45 +00:00
|
|
|
NS_IMETHOD LoadURL(const PRUnichar *aURLSpec,
|
|
|
|
const char* aCommand,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream=nsnull,
|
1998-11-11 20:31:45 +00:00
|
|
|
PRBool aModifyHistory=PR_TRUE,
|
1999-07-01 19:30:20 +00:00
|
|
|
nsLoadFlags aType = nsIChannel::LOAD_NORMAL,
|
1999-09-02 21:39:01 +00:00
|
|
|
const PRUint32 localIP = 0,
|
1999-09-17 04:26:02 +00:00
|
|
|
nsISupports * aHistoryState=nsnull,
|
2000-02-16 07:30:17 +00:00
|
|
|
const PRUnichar* aReferrer=nsnull,
|
|
|
|
const char * aWindowTarget = nsnull);
|
1998-11-11 20:31:45 +00:00
|
|
|
|
1999-09-08 03:59:21 +00:00
|
|
|
NS_IMETHOD LoadURI(nsIURI * aUri,
|
|
|
|
const char * aCommand,
|
|
|
|
nsIInputStream* aPostDataStream=nsnull,
|
|
|
|
PRBool aModifyHistory=PR_TRUE,
|
|
|
|
nsLoadFlags aType = nsIChannel::LOAD_NORMAL,
|
|
|
|
const PRUint32 aLocalIP=0,
|
2000-02-16 07:30:17 +00:00
|
|
|
nsISupports * aHistoryState=nsnull,
|
|
|
|
const PRUnichar* aReferrer=nsnull,
|
|
|
|
const char * aWindowTarget = nsnull);
|
1999-09-08 03:59:21 +00:00
|
|
|
|
2000-03-11 12:02:06 +00:00
|
|
|
NS_IMETHOD GetCanGoBack(PRBool* aCanGoBack);
|
|
|
|
NS_IMETHOD GetCanGoForward(PRBool* aCanGoForward);
|
|
|
|
NS_IMETHOD GoBack();
|
|
|
|
NS_IMETHOD GoForward();
|
2000-02-29 22:35:33 +00:00
|
|
|
NS_IMETHOD LoadURI(const PRUnichar* aURI);
|
2000-02-24 04:16:17 +00:00
|
|
|
NS_IMETHOD InternalLoad(nsIURI* aURI, nsIURI* aReferrer,
|
|
|
|
nsIInputStream* aPostData, loadType aLoadType);
|
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
NS_IMETHOD Stop(void);
|
1999-08-09 00:03:12 +00:00
|
|
|
|
2000-02-24 04:16:17 +00:00
|
|
|
void SetReferrer(const PRUnichar* aReferrer);
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
// History api's
|
1998-07-22 11:24:50 +00:00
|
|
|
NS_IMETHOD GoTo(PRInt32 aHistoryIndex);
|
1999-01-28 23:13:48 +00:00
|
|
|
NS_IMETHOD GetHistoryLength(PRInt32& aResult);
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IMETHOD GetHistoryIndex(PRInt32& aResult);
|
1999-02-14 06:35:01 +00:00
|
|
|
NS_IMETHOD GetURL(PRInt32 aHistoryIndex, const PRUnichar** aURLResult);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
|
|
|
// nsIWebShellContainer
|
1998-08-14 23:08:54 +00:00
|
|
|
NS_IMETHOD WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason);
|
|
|
|
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL);
|
|
|
|
NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax);
|
1999-08-05 01:28:30 +00:00
|
|
|
NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsresult aStatus);
|
1999-08-30 22:45:46 +00:00
|
|
|
NS_IMETHOD GetHistoryState(nsISupports** aLayoutHistoryState);
|
1999-08-31 14:49:21 +00:00
|
|
|
NS_IMETHOD SetHistoryState(nsISupports* aLayoutHistoryState);
|
2000-02-15 22:55:36 +00:00
|
|
|
NS_IMETHOD FireUnloadEvent(void);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1999-05-06 01:58:48 +00:00
|
|
|
// nsIWebShellServices
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_IMETHOD LoadDocument(const char* aURL,
|
|
|
|
const char* aCharset= nsnull ,
|
1999-05-19 00:23:03 +00:00
|
|
|
nsCharsetSource aSource = kCharsetUninitialized);
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_IMETHOD ReloadDocument(const char* aCharset= nsnull ,
|
1999-09-16 14:15:16 +00:00
|
|
|
nsCharsetSource aSource = kCharsetUninitialized,
|
|
|
|
const char* aCmd=nsnull);
|
1999-05-06 01:58:48 +00:00
|
|
|
NS_IMETHOD StopDocumentLoad(void);
|
|
|
|
NS_IMETHOD SetRendering(PRBool aRender);
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
// nsILinkHandler
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_IMETHOD OnLinkClick(nsIContent* aContent,
|
1998-11-14 00:21:19 +00:00
|
|
|
nsLinkVerb aVerb,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aURLSpec,
|
|
|
|
const PRUnichar* aTargetSpec,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream = 0);
|
1998-11-14 00:21:19 +00:00
|
|
|
NS_IMETHOD OnOverLink(nsIContent* aContent,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aURLSpec,
|
|
|
|
const PRUnichar* aTargetSpec);
|
|
|
|
NS_IMETHOD GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1999-05-28 21:32:29 +00:00
|
|
|
NS_IMETHOD RefreshURL(const char* aURL, PRInt32 millis, PRBool repeat);
|
1998-08-18 23:25:17 +00:00
|
|
|
|
1999-08-03 21:48:40 +00:00
|
|
|
// nsIRefreshURL interface methods...
|
|
|
|
NS_IMETHOD RefreshURI(nsIURI* aURI, PRInt32 aMillis, PRBool aRepeat);
|
|
|
|
NS_IMETHOD CancelRefreshURITimers(void);
|
1999-04-06 21:01:04 +00:00
|
|
|
|
1999-10-13 10:24:12 +00:00
|
|
|
// nsIProgressEventSink
|
|
|
|
NS_DECL_NSIPROGRESSEVENTSINK
|
|
|
|
|
1999-09-06 22:59:11 +00:00
|
|
|
// nsIClipboardCommands
|
1998-11-04 08:48:22 +00:00
|
|
|
NS_IMETHOD CanCutSelection (PRBool* aResult);
|
|
|
|
NS_IMETHOD CanCopySelection (PRBool* aResult);
|
|
|
|
NS_IMETHOD CanPasteSelection(PRBool* aResult);
|
|
|
|
|
|
|
|
NS_IMETHOD CutSelection (void);
|
|
|
|
NS_IMETHOD CopySelection (void);
|
|
|
|
NS_IMETHOD PasteSelection(void);
|
|
|
|
|
|
|
|
NS_IMETHOD SelectAll(void);
|
|
|
|
NS_IMETHOD SelectNone(void);
|
|
|
|
|
1998-10-23 20:47:57 +00:00
|
|
|
NS_IMETHOD FindNext(const PRUnichar * aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
|
|
|
|
|
1999-11-27 02:14:40 +00:00
|
|
|
// nsIBaseWindow
|
2000-03-11 01:05:08 +00:00
|
|
|
NS_IMETHOD Create();
|
|
|
|
NS_IMETHOD Destroy();
|
|
|
|
NS_IMETHOD SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy,
|
|
|
|
PRBool fRepaint);
|
|
|
|
NS_IMETHOD GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx,
|
|
|
|
PRInt32* cy);
|
1999-11-27 02:14:40 +00:00
|
|
|
|
1999-11-30 04:32:09 +00:00
|
|
|
// nsIDocShell
|
2000-03-11 01:05:08 +00:00
|
|
|
NS_IMETHOD SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode);
|
1999-11-30 04:32:09 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
// nsWebShell
|
1999-05-04 23:34:10 +00:00
|
|
|
nsIEventQueue* GetEventQueue(void);
|
1998-11-14 00:21:19 +00:00
|
|
|
void HandleLinkClickEvent(nsIContent *aContent,
|
|
|
|
nsLinkVerb aVerb,
|
|
|
|
const PRUnichar* aURLSpec,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aTargetSpec,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream = 0);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
|
|
|
void ShowHistory();
|
|
|
|
|
1998-08-18 23:25:17 +00:00
|
|
|
static void RefreshURLCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent);
|
|
|
|
|
1998-09-15 03:46:05 +00:00
|
|
|
nsresult CreatePluginHost(PRBool aAllowPlugins);
|
|
|
|
nsresult DestroyPluginHost(void);
|
1998-07-27 23:08:52 +00:00
|
|
|
|
1999-06-14 22:11:47 +00:00
|
|
|
NS_IMETHOD SetSessionHistory(nsISessionHistory * aSHist);
|
|
|
|
NS_IMETHOD GetSessionHistory(nsISessionHistory *& aResult);
|
|
|
|
NS_IMETHOD SetIsInSHist(PRBool aIsFrame);
|
|
|
|
NS_IMETHOD GetIsInSHist(PRBool& aIsFrame);
|
|
|
|
NS_IMETHOD SetURL(const PRUnichar* aURL);
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
protected:
|
1999-11-16 20:06:12 +00:00
|
|
|
void GetRootWebShellEvenIfChrome(nsIWebShell** aResult);
|
2000-02-29 06:51:48 +00:00
|
|
|
void InitFrameData();
|
1999-06-23 03:29:44 +00:00
|
|
|
nsresult CheckForTrailingSlash(nsIURI* aURL);
|
2000-01-11 23:11:32 +00:00
|
|
|
nsresult InitDialogVars(void);
|
1999-01-19 17:26:06 +00:00
|
|
|
|
1999-05-04 23:34:10 +00:00
|
|
|
nsIEventQueue* mThreadEventQueue;
|
1998-07-21 04:46:55 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
nsIWebShellContainer* mContainer;
|
|
|
|
nsIDocumentLoader* mDocLoader;
|
|
|
|
|
2000-01-11 23:11:32 +00:00
|
|
|
nsCOMPtr<nsIPrompt> mPrompter;
|
|
|
|
nsCOMPtr<nsIStringBundle> mStringBundle;
|
|
|
|
|
1999-03-22 22:21:22 +00:00
|
|
|
nsString mDefaultCharacterSet;
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1999-08-09 00:03:12 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
nsVoidArray mHistory;
|
|
|
|
PRInt32 mHistoryIndex;
|
1999-08-09 00:03:12 +00:00
|
|
|
|
2000-02-15 22:55:36 +00:00
|
|
|
PRBool mFiredUnloadEvent;
|
1999-08-09 00:03:12 +00:00
|
|
|
|
1999-06-07 21:26:10 +00:00
|
|
|
nsIGlobalHistory* mHistoryService;
|
1999-06-14 22:11:47 +00:00
|
|
|
nsISessionHistory * mSHist;
|
1998-07-18 21:43:02 +00:00
|
|
|
|
2000-03-11 01:05:08 +00:00
|
|
|
nsRect mBounds;
|
1998-07-18 21:43:02 +00:00
|
|
|
nsString mOverURL;
|
|
|
|
nsString mOverTarget;
|
1999-08-24 18:20:30 +00:00
|
|
|
|
|
|
|
PRPackedBool mIsInSHist;
|
|
|
|
PRPackedBool mFailedToLoadHistoryService;
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1998-07-27 05:59:37 +00:00
|
|
|
nsScrollPreference mScrollPref;
|
1999-11-19 07:35:27 +00:00
|
|
|
|
1998-08-18 23:25:17 +00:00
|
|
|
nsVoidArray mRefreshments;
|
1998-07-27 05:59:37 +00:00
|
|
|
|
1999-09-23 03:27:53 +00:00
|
|
|
eCharsetReloadState mCharsetReloadState;
|
|
|
|
|
1999-08-31 14:49:21 +00:00
|
|
|
nsISupports* mHistoryState; // Weak reference. Session history owns this.
|
1999-04-16 08:15:04 +00:00
|
|
|
|
2000-02-15 22:55:36 +00:00
|
|
|
nsresult FireUnloadForChildren();
|
1999-09-08 03:59:21 +00:00
|
|
|
nsresult DoLoadURL(nsIURI * aUri,
|
1999-02-12 17:32:17 +00:00
|
|
|
const char* aCommand,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream,
|
1999-07-01 19:30:20 +00:00
|
|
|
nsLoadFlags aType,
|
1999-09-17 04:26:02 +00:00
|
|
|
const PRUint32 aLocalIP,
|
1999-11-18 07:06:39 +00:00
|
|
|
const PRUnichar* aReferrer,
|
2000-02-16 07:30:17 +00:00
|
|
|
const char * aWindowTarget,
|
1999-11-18 07:06:39 +00:00
|
|
|
PRBool aKickOffLoad = PR_TRUE);
|
|
|
|
|
|
|
|
nsresult PrepareToLoadURI(nsIURI * aUri,
|
|
|
|
nsIInputStream * aPostStream,
|
|
|
|
PRBool aModifyHistory,
|
|
|
|
nsLoadFlags aType,
|
|
|
|
const PRUint32 aLocalIP,
|
|
|
|
nsISupports * aHistoryState,
|
|
|
|
const PRUnichar * aReferrer);
|
1999-12-28 09:18:47 +00:00
|
|
|
|
|
|
|
nsresult CreateViewer(nsIChannel* aChannel,
|
|
|
|
const char* aContentType,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIStreamListener** aResult);
|
1998-07-27 23:08:52 +00:00
|
|
|
static nsIPluginHost *mPluginHost;
|
|
|
|
static nsIPluginManager *mPluginManager;
|
1998-09-15 03:46:05 +00:00
|
|
|
static PRUint32 mPluginInitCnt;
|
1999-05-03 23:04:50 +00:00
|
|
|
PRBool mProcessedEndDocumentLoad;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-11-19 07:35:27 +00:00
|
|
|
PRBool mViewSource;
|
|
|
|
|
1999-11-11 21:35:34 +00:00
|
|
|
MOZ_TIMER_DECLARE(mTotalTime)
|
1999-09-24 07:13:39 +00:00
|
|
|
|
1999-09-22 01:24:20 +00:00
|
|
|
#ifdef DETECT_WEBSHELL_LEAKS
|
1999-08-27 12:32:20 +00:00
|
|
|
private:
|
1999-09-06 22:59:11 +00:00
|
|
|
// We're counting the number of |nsWebShells| to help find leaks
|
|
|
|
static unsigned long gNumberOfWebShells;
|
1999-08-27 12:32:20 +00:00
|
|
|
|
1999-08-27 12:56:52 +00:00
|
|
|
public:
|
1999-09-06 22:59:11 +00:00
|
|
|
static unsigned long TotalWebShellsInExistence() { return gNumberOfWebShells; }
|
1999-08-27 12:32:20 +00:00
|
|
|
#endif
|
1998-07-18 21:43:02 +00:00
|
|
|
};
|
|
|
|
|
1999-09-22 01:24:20 +00:00
|
|
|
#ifdef DETECT_WEBSHELL_LEAKS
|
1999-08-27 12:32:20 +00:00
|
|
|
unsigned long nsWebShell::gNumberOfWebShells = 0;
|
|
|
|
|
1999-08-27 14:01:44 +00:00
|
|
|
extern "C" NS_WEB
|
1999-08-27 12:32:20 +00:00
|
|
|
unsigned long
|
|
|
|
NS_TotalWebShellsInExistence()
|
1999-09-22 01:24:20 +00:00
|
|
|
{
|
|
|
|
return nsWebShell::TotalWebShellsInExistence();
|
|
|
|
}
|
1999-08-27 12:32:20 +00:00
|
|
|
#endif
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Class IID's
|
1999-01-05 09:46:33 +00:00
|
|
|
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
1998-09-25 22:25:21 +00:00
|
|
|
static NS_DEFINE_IID(kChildCID, NS_CHILD_CID);
|
1999-01-17 11:48:58 +00:00
|
|
|
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
|
1998-09-25 22:25:21 +00:00
|
|
|
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
|
|
|
// IID's
|
|
|
|
static NS_DEFINE_IID(kIContentViewerContainerIID,
|
|
|
|
NS_ICONTENT_VIEWER_CONTAINER_IID);
|
1999-10-13 10:24:12 +00:00
|
|
|
static NS_DEFINE_IID(kIProgressEventSinkIID, NS_IPROGRESSEVENTSINK_IID);
|
1998-09-25 22:25:21 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID);
|
|
|
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
1999-05-07 19:25:58 +00:00
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
1999-08-03 21:48:40 +00:00
|
|
|
static NS_DEFINE_IID(kRefreshURIIID, NS_IREFRESHURI_IID);
|
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
|
|
|
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
|
|
|
|
static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID);
|
1999-02-04 00:03:18 +00:00
|
|
|
static NS_DEFINE_IID(kCPluginManagerCID, NS_PLUGINMANAGER_CID);
|
1998-09-25 22:25:21 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
|
|
|
|
static NS_DEFINE_IID(kITimerCallbackIID, NS_ITIMERCALLBACK_IID);
|
|
|
|
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
|
1998-11-04 08:48:22 +00:00
|
|
|
static NS_DEFINE_IID(kIClipboardCommandsIID, NS_ICLIPBOARDCOMMANDS_IID);
|
1999-01-05 09:46:33 +00:00
|
|
|
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
1999-10-12 04:37:43 +00:00
|
|
|
static NS_DEFINE_IID(kISessionHistoryIID, NS_ISESSIONHISTORY_IID);
|
1999-09-01 20:14:02 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID);
|
1998-07-18 21:43:02 +00:00
|
|
|
// XXX not sure
|
1998-09-25 22:25:21 +00:00
|
|
|
static NS_DEFINE_IID(kILinkHandlerIID, NS_ILINKHANDLER_IID);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1998-07-27 23:08:52 +00:00
|
|
|
nsIPluginHost *nsWebShell::mPluginHost = nsnull;
|
|
|
|
nsIPluginManager *nsWebShell::mPluginManager = nsnull;
|
1998-09-15 03:46:05 +00:00
|
|
|
PRUint32 nsWebShell::mPluginInitCnt = 0;
|
1998-07-27 23:08:52 +00:00
|
|
|
|
1998-09-15 03:46:05 +00:00
|
|
|
nsresult nsWebShell::CreatePluginHost(PRBool aAllowPlugins)
|
1998-07-27 23:08:52 +00:00
|
|
|
{
|
1998-09-15 03:46:05 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-07-27 23:08:52 +00:00
|
|
|
|
1998-09-15 03:46:05 +00:00
|
|
|
if ((PR_TRUE == aAllowPlugins) && (0 == mPluginInitCnt))
|
1998-07-27 23:08:52 +00:00
|
|
|
{
|
1998-09-15 03:46:05 +00:00
|
|
|
if (nsnull == mPluginManager)
|
1998-07-27 23:08:52 +00:00
|
|
|
{
|
1999-03-08 00:01:02 +00:00
|
|
|
// use the service manager to obtain the plugin manager.
|
|
|
|
rv = nsServiceManager::GetService(kCPluginManagerCID, kIPluginManagerIID,
|
1999-09-06 22:59:11 +00:00
|
|
|
(nsISupports**)&mPluginManager);
|
1998-09-15 03:46:05 +00:00
|
|
|
if (NS_OK == rv)
|
1998-07-27 23:08:52 +00:00
|
|
|
{
|
1998-09-15 03:46:05 +00:00
|
|
|
if (NS_OK == mPluginManager->QueryInterface(kIPluginHostIID,
|
|
|
|
(void **)&mPluginHost))
|
|
|
|
{
|
|
|
|
mPluginHost->Init();
|
|
|
|
}
|
1998-07-27 23:08:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-15 03:46:05 +00:00
|
|
|
mPluginInitCnt++;
|
|
|
|
|
1998-07-27 23:08:52 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-09-15 03:46:05 +00:00
|
|
|
nsresult nsWebShell::DestroyPluginHost(void)
|
|
|
|
{
|
|
|
|
mPluginInitCnt--;
|
|
|
|
|
|
|
|
NS_ASSERTION(!(mPluginInitCnt < 0), "underflow in plugin host destruction");
|
|
|
|
|
|
|
|
if (0 == mPluginInitCnt)
|
|
|
|
{
|
1999-03-08 00:01:02 +00:00
|
|
|
if (nsnull != mPluginHost) {
|
1998-09-15 03:46:05 +00:00
|
|
|
mPluginHost->Destroy();
|
1999-03-08 00:01:02 +00:00
|
|
|
mPluginHost->Release();
|
|
|
|
mPluginHost = NULL;
|
|
|
|
}
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-03-08 00:01:02 +00:00
|
|
|
// use the service manager to release the plugin manager.
|
|
|
|
if (nsnull != mPluginManager) {
|
|
|
|
nsServiceManager::ReleaseService(kCPluginManagerCID, mPluginManager);
|
|
|
|
mPluginManager = NULL;
|
|
|
|
}
|
1998-09-15 03:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Note: operator new zeros our memory
|
1999-12-18 02:29:57 +00:00
|
|
|
nsWebShell::nsWebShell() : nsDocShell()
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1999-09-22 01:24:20 +00:00
|
|
|
#ifdef DETECT_WEBSHELL_LEAKS
|
1999-09-06 22:59:11 +00:00
|
|
|
// We're counting the number of |nsWebShells| to help find leaks
|
|
|
|
++gNumberOfWebShells;
|
1999-08-27 12:32:20 +00:00
|
|
|
#endif
|
1999-10-05 00:08:41 +00:00
|
|
|
#ifdef NOISY_WEBSHELL_LEAKS
|
1999-12-21 23:03:29 +00:00
|
|
|
printf("WEBSHELL+ = %ld\n", gNumberOfWebShells);
|
1999-10-05 00:08:41 +00:00
|
|
|
#endif
|
1999-08-27 12:32:20 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_INIT_REFCNT();
|
|
|
|
mHistoryIndex = -1;
|
1998-07-27 05:59:37 +00:00
|
|
|
mScrollPref = nsScrollPreference_kAuto;
|
1999-09-06 22:59:11 +00:00
|
|
|
mThreadEventQueue = nsnull;
|
2000-02-29 06:51:48 +00:00
|
|
|
InitFrameData();
|
1999-12-08 04:57:23 +00:00
|
|
|
mItemType = typeContent;
|
1999-06-14 22:11:47 +00:00
|
|
|
mSHist = nsnull;
|
|
|
|
mIsInSHist = PR_FALSE;
|
1999-08-24 18:20:30 +00:00
|
|
|
mFailedToLoadHistoryService = PR_FALSE;
|
1999-07-14 20:57:57 +00:00
|
|
|
mDefaultCharacterSet = "";
|
1999-05-03 23:04:50 +00:00
|
|
|
mProcessedEndDocumentLoad = PR_FALSE;
|
1999-09-23 03:27:53 +00:00
|
|
|
mCharsetReloadState = eCharsetReloadInit;
|
1999-09-16 14:15:16 +00:00
|
|
|
mViewSource=PR_FALSE;
|
1999-06-07 21:26:10 +00:00
|
|
|
mHistoryService = nsnull;
|
1999-08-31 14:49:21 +00:00
|
|
|
mHistoryState = nsnull;
|
2000-02-15 22:55:36 +00:00
|
|
|
mFiredUnloadEvent = PR_FALSE;
|
2000-03-11 01:05:08 +00:00
|
|
|
mBounds.SetRect(0, 0, 0, 0);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWebShell::~nsWebShell()
|
|
|
|
{
|
1999-06-07 21:26:10 +00:00
|
|
|
if (nsnull != mHistoryService) {
|
|
|
|
nsServiceManager::ReleaseService(kGlobalHistoryCID, mHistoryService);
|
|
|
|
mHistoryService = nsnull;
|
|
|
|
}
|
|
|
|
|
1998-07-23 04:24:36 +00:00
|
|
|
// Stop any pending document loads and destroy the loader...
|
1998-08-01 06:45:43 +00:00
|
|
|
if (nsnull != mDocLoader) {
|
|
|
|
mDocLoader->Stop();
|
1998-08-12 04:56:40 +00:00
|
|
|
mDocLoader->RemoveObserver((nsIDocumentLoaderObserver*)this);
|
1999-01-14 06:44:23 +00:00
|
|
|
mDocLoader->SetContainer(nsnull);
|
1998-08-01 06:45:43 +00:00
|
|
|
NS_RELEASE(mDocLoader);
|
|
|
|
}
|
1998-08-18 23:25:17 +00:00
|
|
|
// Cancel any timers that were set for this loader.
|
1999-08-03 21:48:40 +00:00
|
|
|
CancelRefreshURITimers();
|
1998-07-23 04:24:36 +00:00
|
|
|
|
1999-06-01 23:02:15 +00:00
|
|
|
++mRefCnt; // following releases can cause this destructor to be called
|
|
|
|
// recursively if the refcount is allowed to remain 0
|
|
|
|
|
1999-10-12 04:37:43 +00:00
|
|
|
NS_IF_RELEASE(mSHist);
|
1999-05-04 23:34:10 +00:00
|
|
|
NS_IF_RELEASE(mThreadEventQueue);
|
1999-12-18 02:29:57 +00:00
|
|
|
mContentViewer=nsnull;
|
2000-03-11 01:05:08 +00:00
|
|
|
mDeviceContext=nsnull;
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IF_RELEASE(mContainer);
|
|
|
|
|
2000-02-14 06:48:39 +00:00
|
|
|
if (mScriptGlobal) {
|
2000-02-08 13:40:10 +00:00
|
|
|
mScriptGlobal->SetDocShell(nsnull);
|
2000-02-14 06:48:39 +00:00
|
|
|
mScriptGlobal = nsnull;
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
2000-02-14 06:48:39 +00:00
|
|
|
if (mScriptContext) {
|
1999-09-08 23:16:49 +00:00
|
|
|
mScriptContext->SetOwner(nsnull);
|
2000-02-14 06:48:39 +00:00
|
|
|
mScriptContext = nsnull;
|
1999-09-08 23:16:49 +00:00
|
|
|
}
|
1998-07-25 01:53:54 +00:00
|
|
|
|
2000-02-29 06:51:48 +00:00
|
|
|
InitFrameData();
|
1999-01-19 17:26:06 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
// Free up history memory
|
|
|
|
PRInt32 i, n = mHistory.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsString* s = (nsString*) mHistory.ElementAt(i);
|
|
|
|
delete s;
|
|
|
|
}
|
1998-09-15 03:46:05 +00:00
|
|
|
|
1999-08-09 00:03:12 +00:00
|
|
|
|
1998-09-15 03:46:05 +00:00
|
|
|
DestroyPluginHost();
|
1999-08-27 12:32:20 +00:00
|
|
|
|
1999-09-22 01:24:20 +00:00
|
|
|
#ifdef DETECT_WEBSHELL_LEAKS
|
1999-09-06 22:59:11 +00:00
|
|
|
// We're counting the number of |nsWebShells| to help find leaks
|
|
|
|
--gNumberOfWebShells;
|
1999-08-27 12:32:20 +00:00
|
|
|
#endif
|
1999-10-05 00:08:41 +00:00
|
|
|
#ifdef NOISY_WEBSHELL_LEAKS
|
1999-12-21 23:03:29 +00:00
|
|
|
printf("WEBSHELL- = %ld\n", gNumberOfWebShells);
|
1999-10-05 00:08:41 +00:00
|
|
|
#endif
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
2000-02-29 06:51:48 +00:00
|
|
|
void nsWebShell::InitFrameData()
|
1999-01-19 17:26:06 +00:00
|
|
|
{
|
2000-02-29 06:51:48 +00:00
|
|
|
SetMarginWidth(-1);
|
|
|
|
SetMarginHeight(-1);
|
1999-01-19 17:26:06 +00:00
|
|
|
}
|
|
|
|
|
2000-02-15 22:55:36 +00:00
|
|
|
nsresult
|
|
|
|
nsWebShell::FireUnloadForChildren()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
PRInt32 i, n = mChildren.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIDocShell* shell = (nsIDocShell*) mChildren.ElementAt(i);
|
|
|
|
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(shell));
|
|
|
|
rv = webShell->FireUnloadEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::FireUnloadEvent()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (mScriptGlobal) {
|
|
|
|
nsIDocumentViewer* docViewer;
|
|
|
|
if (mContentViewer && NS_SUCCEEDED(mContentViewer->QueryInterface(kIDocumentViewerIID, (void**)&docViewer))) {
|
|
|
|
nsIPresContext *presContext;
|
|
|
|
if (NS_SUCCEEDED(docViewer->GetPresContext(presContext))) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_PAGE_UNLOAD;
|
|
|
|
rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
|
|
|
|
NS_RELEASE(presContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(docViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Fire child unloads now while our data is intact.
|
|
|
|
rv = FireUnloadForChildren();
|
|
|
|
|
|
|
|
mFiredUnloadEvent = PR_TRUE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsWebShell, nsDocShell)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsWebShell, nsDocShell)
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1999-11-23 10:08:32 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsWebShell)
|
2000-03-05 21:26:01 +00:00
|
|
|
#if 0 // inherits from nsDocShell:
|
1999-11-23 10:08:32 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebShell)
|
2000-03-05 21:26:01 +00:00
|
|
|
#endif
|
1999-11-23 10:08:32 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebShell)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebShellServices)
|
1999-12-18 02:29:57 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIContentViewerContainer, nsIWebShell)
|
1999-11-23 10:08:32 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocumentLoaderObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebShellContainer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsILinkHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRefreshURI)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIClipboardCommands)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
|
2000-03-05 21:26:01 +00:00
|
|
|
#if 0 // inherits from nsDocShell:
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
1999-11-27 02:14:40 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
|
1999-11-30 04:32:09 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShell)
|
1999-12-03 10:57:59 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode)
|
2000-02-14 06:48:39 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebNavigation)
|
2000-02-29 06:51:48 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollable)
|
2000-03-05 21:26:01 +00:00
|
|
|
#endif
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDocShell)
|
1998-07-18 21:43:02 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-13 04:06:23 +00:00
|
|
|
nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1999-11-13 04:06:23 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
2000-01-11 20:59:24 +00:00
|
|
|
nsresult rv = NS_OK;
|
2000-02-19 02:05:52 +00:00
|
|
|
*aInstancePtr = nsnull;
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1999-11-13 04:06:23 +00:00
|
|
|
if(aIID.Equals(NS_GET_IID(nsILinkHandler)))
|
|
|
|
{
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsILinkHandler*, this);
|
1999-12-03 09:24:22 +00:00
|
|
|
NS_ADDREF((nsISupports*)*aInstancePtr);
|
1999-11-13 04:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-12-03 09:24:22 +00:00
|
|
|
else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObjectOwner)))
|
1999-11-13 04:06:23 +00:00
|
|
|
{
|
1999-12-03 09:24:22 +00:00
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this);
|
|
|
|
NS_ADDREF((nsISupports*)*aInstancePtr);
|
1999-11-13 04:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-30 00:09:00 +00:00
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIURIContentListener)))
|
|
|
|
{
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIURIContentListener*, this);
|
1999-12-03 09:24:22 +00:00
|
|
|
NS_ADDREF((nsISupports*)*aInstancePtr);
|
1999-11-30 00:09:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-12-03 09:24:22 +00:00
|
|
|
else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)))
|
|
|
|
{
|
2000-02-14 06:48:39 +00:00
|
|
|
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
|
1999-12-03 09:24:22 +00:00
|
|
|
*aInstancePtr = mScriptGlobal;
|
|
|
|
NS_ADDREF((nsISupports*)*aInstancePtr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-08 13:40:10 +00:00
|
|
|
else if(aIID.Equals(NS_GET_IID(nsIDOMWindow)))
|
|
|
|
{
|
2000-02-14 06:48:39 +00:00
|
|
|
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
|
2000-02-08 13:40:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindow),
|
|
|
|
aInstancePtr), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-13 04:06:23 +00:00
|
|
|
else if(mPluginManager) //XXX this seems a little wrong. MMP
|
2000-01-11 20:59:24 +00:00
|
|
|
rv = mPluginManager->QueryInterface(aIID, aInstancePtr);
|
1998-07-27 23:08:52 +00:00
|
|
|
|
2000-01-11 20:59:24 +00:00
|
|
|
if (!*aInstancePtr || NS_FAILED(rv))
|
2000-03-08 00:40:49 +00:00
|
|
|
return nsDocShell::GetInterface(aIID,aInstancePtr);
|
2000-01-11 20:59:24 +00:00
|
|
|
else
|
|
|
|
return rv;
|
1999-11-13 04:06:23 +00:00
|
|
|
}
|
1998-07-27 23:08:52 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IMETHODIMP
|
2000-02-29 22:35:33 +00:00
|
|
|
nsWebShell::SetupNewViewer(nsIContentViewer* aViewer)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
2000-02-29 22:35:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(nsDocShell::SetupNewViewer(aViewer), NS_ERROR_FAILURE);
|
1999-08-31 14:49:21 +00:00
|
|
|
// If the history state has been set by session history,
|
|
|
|
// set it on the pres shell now that we have a content
|
|
|
|
// viewer.
|
2000-02-29 22:35:33 +00:00
|
|
|
if(mContentViewer && mHistoryState)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
|
|
|
|
if(docv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
docv->GetPresShell(*getter_AddRefs(shell));
|
|
|
|
if(shell)
|
|
|
|
shell->SetHistoryState((nsILayoutHistoryState*)mHistoryState);
|
|
|
|
}
|
1999-08-31 14:49:21 +00:00
|
|
|
}
|
2000-02-29 22:35:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-18 21:43:02 +00:00
|
|
|
|
2000-02-29 22:35:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::Embed(nsIContentViewer* aContentViewer,
|
|
|
|
const char* aCommand,
|
|
|
|
nsISupports* aExtraInfo)
|
|
|
|
{
|
|
|
|
return SetupNewViewer(aContentViewer);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::SetContainer(nsIWebShellContainer* aContainer)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mContainer);
|
|
|
|
mContainer = aContainer;
|
1999-11-18 07:06:39 +00:00
|
|
|
NS_IF_ADDREF(mContainer);
|
|
|
|
|
|
|
|
// uri dispatching change.....if you set a container for a webshell
|
|
|
|
// and that container is a content listener itself....then use
|
|
|
|
// it as our parent container.
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIURIContentListener> contentListener = do_QueryInterface(mContainer, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && contentListener)
|
2000-01-29 06:06:25 +00:00
|
|
|
SetParentContentListener(contentListener);
|
1999-11-18 07:06:39 +00:00
|
|
|
|
|
|
|
// if the container is getting set to null, then our parent must be going away
|
|
|
|
// so clear out our knowledge of the content listener represented by the container
|
|
|
|
if (!aContainer)
|
2000-01-29 06:06:25 +00:00
|
|
|
SetParentContentListener(nsnull);
|
1999-11-18 07:06:39 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetContainer(nsIWebShellContainer*& aResult)
|
|
|
|
{
|
|
|
|
aResult = mContainer;
|
|
|
|
NS_IF_ADDREF(mContainer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-16 20:06:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetTopLevelWindow(nsIWebShellContainer** aTopLevelWindow)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTopLevelWindow);
|
1999-11-17 04:19:39 +00:00
|
|
|
*aTopLevelWindow = nsnull;
|
1999-11-16 20:06:12 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWebShell> rootWebShell;
|
|
|
|
|
|
|
|
GetRootWebShellEvenIfChrome(getter_AddRefs(rootWebShell));
|
1999-11-17 04:19:39 +00:00
|
|
|
if(!rootWebShell)
|
|
|
|
return NS_OK;
|
1999-11-16 20:06:12 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWebShellContainer> rootContainer;
|
|
|
|
rootWebShell->GetContainer(*aTopLevelWindow);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-14 22:11:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::SetSessionHistory(nsISessionHistory* aSHist)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mSHist);
|
|
|
|
mSHist = aSHist;
|
|
|
|
NS_IF_ADDREF(aSHist);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetSessionHistory(nsISessionHistory *& aResult)
|
|
|
|
{
|
|
|
|
aResult = mSHist;
|
|
|
|
NS_IF_ADDREF(mSHist);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
nsEventStatus PR_CALLBACK
|
|
|
|
nsWebShell::HandleEvent(nsGUIEvent *aEvent)
|
1999-09-06 22:59:11 +00:00
|
|
|
{
|
1998-07-18 21:43:02 +00:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
1998-10-02 18:44:56 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-19 01:18:40 +00:00
|
|
|
nsWebShell::GetRootWebShell(nsIWebShell*& aResult)
|
|
|
|
{
|
1999-12-18 02:29:57 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> top;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(top));
|
|
|
|
nsCOMPtr<nsIWebShell> topAsWebShell(do_QueryInterface(top));
|
|
|
|
aResult = topAsWebShell;
|
|
|
|
NS_IF_ADDREF(aResult);
|
|
|
|
return NS_OK;
|
1998-07-19 01:18:40 +00:00
|
|
|
}
|
|
|
|
|
1999-11-16 20:06:12 +00:00
|
|
|
void
|
|
|
|
nsWebShell::GetRootWebShellEvenIfChrome(nsIWebShell** aResult)
|
1999-04-16 08:15:04 +00:00
|
|
|
{
|
1999-12-18 02:29:57 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> top;
|
|
|
|
GetRootTreeItem(getter_AddRefs(top));
|
|
|
|
nsCOMPtr<nsIWebShell> topAsWebShell(do_QueryInterface(top));
|
|
|
|
*aResult = topAsWebShell;
|
1999-11-16 20:06:12 +00:00
|
|
|
NS_IF_ADDREF(*aResult);
|
1999-04-16 08:15:04 +00:00
|
|
|
}
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::SetParent(nsIWebShell* aParent)
|
|
|
|
{
|
1999-12-03 10:57:59 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsTreeItem(do_QueryInterface(aParent));
|
|
|
|
|
|
|
|
mParent = parentAsTreeItem.get();
|
1999-11-30 04:32:09 +00:00
|
|
|
return NS_OK;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetParent(nsIWebShell*& aParent)
|
1999-04-16 08:15:04 +00:00
|
|
|
{
|
1999-12-08 04:57:23 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parent)), NS_ERROR_FAILURE);
|
1999-04-16 08:15:04 +00:00
|
|
|
|
1999-12-08 04:57:23 +00:00
|
|
|
if(parent)
|
|
|
|
parent->QueryInterface(NS_GET_IID(nsIWebShell), (void**)&aParent);
|
|
|
|
else
|
|
|
|
aParent = nsnull;
|
|
|
|
return NS_OK;
|
1999-04-16 08:15:04 +00:00
|
|
|
}
|
|
|
|
|
1999-10-25 22:20:10 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetReferrer(nsIURI **aReferrer)
|
|
|
|
{
|
2000-02-24 04:16:17 +00:00
|
|
|
*aReferrer = mReferrerURI;
|
|
|
|
NS_IF_ADDREF(*aReferrer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWebShell::SetReferrer(const PRUnichar* aReferrer)
|
|
|
|
{
|
|
|
|
NS_NewURI(getter_AddRefs(mReferrerURI), aReferrer, nsnull);
|
1999-10-25 22:20:10 +00:00
|
|
|
}
|
|
|
|
|
1999-06-14 22:11:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::SetURL(const PRUnichar* aURL)
|
|
|
|
{
|
2000-03-03 22:55:40 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), aURL, nsnull),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
SetCurrentURI(uri);
|
1999-06-14 22:11:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-14 22:11:47 +00:00
|
|
|
nsWebShell::GetIsInSHist(PRBool& aResult)
|
|
|
|
{
|
|
|
|
aResult = mIsInSHist;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::SetIsInSHist(PRBool aIsInSHist)
|
1999-09-06 22:59:11 +00:00
|
|
|
{
|
1999-06-14 22:11:47 +00:00
|
|
|
mIsInSHist = aIsInSHist;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
/**
|
|
|
|
* Document Load methods
|
|
|
|
*/
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsWebShell::GetDocumentLoader(nsIDocumentLoader*& aResult)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1998-08-14 23:08:54 +00:00
|
|
|
aResult = mDocLoader;
|
|
|
|
NS_IF_ADDREF(mDocLoader);
|
|
|
|
return (nsnull != mDocLoader) ? NS_OK : NS_ERROR_FAILURE;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
2000-02-03 03:44:22 +00:00
|
|
|
#define FILE_PROTOCOL "file://"
|
1998-08-14 23:08:54 +00:00
|
|
|
|
1998-12-15 01:34:36 +00:00
|
|
|
static void convertFileToURL(const nsString &aIn, nsString &aOut)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
2000-02-29 07:07:36 +00:00
|
|
|
aOut = aIn;
|
2000-02-03 03:44:22 +00:00
|
|
|
#ifdef XP_PC
|
|
|
|
// Check for \ in the url-string (PC)
|
2000-02-29 07:07:36 +00:00
|
|
|
if(kNotFound != aIn.FindChar(PRUnichar('\\'))) {
|
2000-02-03 03:44:22 +00:00
|
|
|
#else
|
|
|
|
#if XP_UNIX
|
|
|
|
// Check if it starts with / or \ (UNIX)
|
2000-02-29 07:07:36 +00:00
|
|
|
const PRUnichar * up = aIn.GetUnicode();
|
|
|
|
if((PRUnichar('/') == *up) ||
|
|
|
|
(PRUnichar('\\') == *up)) {
|
2000-02-03 03:44:22 +00:00
|
|
|
#else
|
|
|
|
if (0) {
|
|
|
|
// Do nothing (All others for now)
|
|
|
|
#endif
|
|
|
|
#endif
|
1999-09-06 22:59:11 +00:00
|
|
|
|
2000-02-03 03:44:22 +00:00
|
|
|
#ifdef XP_PC
|
1998-08-14 23:08:54 +00:00
|
|
|
// Translate '\' to '/'
|
2000-02-29 07:07:36 +00:00
|
|
|
aOut.ReplaceChar(PRUnichar('\\'), PRUnichar('/'));
|
|
|
|
aOut.ReplaceChar(PRUnichar(':'), PRUnichar('|'));
|
2000-02-03 03:44:22 +00:00
|
|
|
#endif
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
// Build the file URL
|
2000-02-29 07:07:36 +00:00
|
|
|
aOut.Insert(FILE_PROTOCOL,0);
|
1998-08-14 23:08:54 +00:00
|
|
|
}
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsWebShell::LoadURL(const PRUnichar *aURLSpec,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream,
|
1998-08-19 23:01:52 +00:00
|
|
|
PRBool aModifyHistory,
|
1999-07-01 19:30:20 +00:00
|
|
|
nsLoadFlags aType,
|
1999-09-02 21:39:01 +00:00
|
|
|
const PRUint32 aLocalIP,
|
1999-09-17 04:26:02 +00:00
|
|
|
nsISupports * aHistoryState,
|
|
|
|
const PRUnichar* aReferrer)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1999-09-16 14:15:16 +00:00
|
|
|
const char *cmd = mViewSource ? "view-source" : "view" ;
|
2000-02-23 01:48:22 +00:00
|
|
|
|
1999-09-21 00:04:31 +00:00
|
|
|
return LoadURL(aURLSpec, cmd, aPostDataStream,
|
1999-09-17 04:26:02 +00:00
|
|
|
aModifyHistory,aType, aLocalIP, aHistoryState,
|
|
|
|
aReferrer);
|
1998-11-11 20:31:45 +00:00
|
|
|
}
|
|
|
|
|
1999-10-15 03:50:47 +00:00
|
|
|
|
1999-07-03 01:14:51 +00:00
|
|
|
static PRBool EqualBaseURLs(nsIURI* url1, nsIURI* url2)
|
|
|
|
{
|
1999-10-15 03:50:47 +00:00
|
|
|
nsXPIDLCString spec1;
|
|
|
|
nsXPIDLCString spec2;
|
|
|
|
char * anchor1 = nsnull, * anchor2=nsnull;
|
|
|
|
PRBool rv = PR_FALSE;
|
|
|
|
|
|
|
|
if (url1 && url2) {
|
|
|
|
// XXX We need to make these strcmps case insensitive.
|
|
|
|
url1->GetSpec(getter_Copies(spec1));
|
|
|
|
url2->GetSpec(getter_Copies(spec2));
|
|
|
|
|
|
|
|
/* Don't look at the ref-part */
|
|
|
|
anchor1 = PL_strrchr(spec1, '#');
|
|
|
|
anchor2 = PL_strrchr(spec2, '#');
|
|
|
|
|
|
|
|
if (anchor1)
|
|
|
|
*anchor1 = '\0';
|
|
|
|
if (anchor2)
|
|
|
|
*anchor2 = '\0';
|
|
|
|
|
|
|
|
if (0 == PL_strcmp(spec1,spec2)) {
|
|
|
|
rv = PR_TRUE;
|
|
|
|
}
|
|
|
|
} // url1 && url2
|
1999-07-03 01:14:51 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-12 17:32:17 +00:00
|
|
|
nsresult
|
1999-09-08 03:59:21 +00:00
|
|
|
nsWebShell::DoLoadURL(nsIURI * aUri,
|
1999-02-12 17:32:17 +00:00
|
|
|
const char* aCommand,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream,
|
1999-07-01 19:30:20 +00:00
|
|
|
nsLoadFlags aType,
|
1999-09-17 04:26:02 +00:00
|
|
|
const PRUint32 aLocalIP,
|
1999-11-18 07:06:39 +00:00
|
|
|
const PRUnichar* aReferrer,
|
2000-02-16 07:30:17 +00:00
|
|
|
const char * aWindowTarget,
|
1999-11-18 07:06:39 +00:00
|
|
|
PRBool aKickOffLoad)
|
1999-02-12 17:32:17 +00:00
|
|
|
{
|
1999-09-08 03:59:21 +00:00
|
|
|
if (!aUri)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsXPIDLCString urlSpec;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
rv = aUri->GetSpec(getter_Copies(urlSpec));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-05 04:49:58 +00:00
|
|
|
|
1999-02-12 17:32:17 +00:00
|
|
|
// If it's a normal reload that uses the cache, look at the destination anchor
|
|
|
|
// and see if it's an element within the current document
|
1999-09-06 22:59:11 +00:00
|
|
|
// We don't have a reload loadtype yet in necko. So, check for just history
|
|
|
|
// loadtype
|
1999-10-12 04:37:43 +00:00
|
|
|
if ((aType == nsISessionHistory::LOAD_HISTORY || aType == nsIChannel::LOAD_NORMAL) && (nsnull != mContentViewer) &&
|
1999-09-06 22:59:11 +00:00
|
|
|
(nsnull == aPostDataStream))
|
2000-02-24 04:16:17 +00:00
|
|
|
{
|
1999-02-12 17:32:17 +00:00
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer;
|
|
|
|
if (NS_SUCCEEDED(mContentViewer->QueryInterface(kIDocumentViewerIID,
|
2000-02-24 04:16:17 +00:00
|
|
|
getter_AddRefs(docViewer))))
|
|
|
|
{
|
1999-02-12 17:32:17 +00:00
|
|
|
// Get the document object
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
docViewer->GetDocument(*getter_AddRefs(doc));
|
|
|
|
|
|
|
|
// Get the URL for the document
|
1999-06-23 03:29:44 +00:00
|
|
|
nsCOMPtr<nsIURI> docURL = nsDontAddRef<nsIURI>(doc->GetDocumentURL());
|
1999-02-12 17:32:17 +00:00
|
|
|
|
2000-02-24 04:16:17 +00:00
|
|
|
if (aUri && docURL && EqualBaseURLs(docURL, aUri))
|
|
|
|
{
|
|
|
|
// See if there's a destination anchor
|
|
|
|
nsXPIDLCString ref;
|
|
|
|
nsCOMPtr<nsIURL> aUrl = do_QueryInterface(aUri);
|
|
|
|
if (aUrl)
|
|
|
|
rv = aUrl->GetRef(getter_Copies(ref));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
rv = docViewer->GetPresShell(*getter_AddRefs(presShell));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && presShell)
|
|
|
|
{
|
|
|
|
/* Pass OnStartDocument notifications to the docloaderobserver
|
1999-10-28 20:29:43 +00:00
|
|
|
* so that urlbar, forward/back buttons will
|
|
|
|
* behave properly when going to named anchors
|
|
|
|
*/
|
2000-02-24 04:16:17 +00:00
|
|
|
nsIInterfaceRequestor * interfaceRequestor = NS_STATIC_CAST(nsIInterfaceRequestor *, this);
|
|
|
|
nsCOMPtr<nsIChannel> dummyChannel;
|
|
|
|
// creating a channel is expensive...don't create it unless we know we have to
|
|
|
|
// so move the creation down into each of the if clauses...
|
|
|
|
if (nsnull != (const char *) ref)
|
|
|
|
{
|
|
|
|
rv = NS_OpenURI(getter_AddRefs(dummyChannel), aUri, nsnull, interfaceRequestor);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!mProcessedEndDocumentLoad)
|
|
|
|
rv = OnStartDocumentLoad(mDocLoader, aUri, "load");
|
|
|
|
// Go to the anchor in the current document
|
|
|
|
rv = presShell->GoToAnchor(nsAutoString(ref));
|
|
|
|
// Set the URL & referrer if the anchor was successfully visited
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
SetCurrentURI(aUri);
|
|
|
|
SetReferrer(aReferrer);
|
|
|
|
}
|
|
|
|
// Pass on status of scrolling/anchor visit to docloaderobserver
|
|
|
|
if (!mProcessedEndDocumentLoad)
|
|
|
|
{
|
|
|
|
rv = OnEndDocumentLoad(mDocLoader, dummyChannel, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else if (aType == nsISessionHistory::LOAD_HISTORY)
|
|
|
|
{
|
|
|
|
rv = NS_OpenURI(getter_AddRefs(dummyChannel), aUri, nsnull, interfaceRequestor);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = OnStartDocumentLoad(mDocLoader, aUri, "load");
|
|
|
|
// Go to the top of the current document
|
|
|
|
nsCOMPtr<nsIViewManager> viewMgr;
|
|
|
|
rv = presShell->GetViewManager(getter_AddRefs(viewMgr));
|
|
|
|
if (NS_SUCCEEDED(rv) && viewMgr)
|
|
|
|
{
|
|
|
|
nsIScrollableView* view;
|
|
|
|
rv = viewMgr->GetRootScrollableView(&view);
|
|
|
|
if (NS_SUCCEEDED(rv) && view)
|
|
|
|
rv = view->ScrollTo(0, 0, NS_VMREFRESH_IMMEDIATE);
|
|
|
|
if(NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
SetCurrentURI(aUri);
|
|
|
|
SetReferrer(aReferrer);
|
|
|
|
}
|
|
|
|
mProcessedEndDocumentLoad = PR_FALSE;
|
|
|
|
// Pass on status of scrolling/anchor visit to docloaderobserver
|
|
|
|
rv = OnEndDocumentLoad(mDocLoader, dummyChannel, rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2000-02-16 07:30:17 +00:00
|
|
|
#if 0
|
2000-02-24 04:16:17 +00:00
|
|
|
mProcessedEndDocumentLoad = PR_FALSE;
|
|
|
|
// Pass on status of scrolling/anchor visit to docloaderobserver
|
|
|
|
rv = OnEndDocumentLoad(mDocLoader, dummyChannel, rv);
|
|
|
|
return rv;
|
1999-10-18 19:09:27 +00:00
|
|
|
#endif /* 0 */
|
2000-02-24 04:16:17 +00:00
|
|
|
} // NS_SUCCEEDED(rv) && presShell
|
|
|
|
} // EqualBaseURLs(docURL, url)
|
|
|
|
}
|
|
|
|
}
|
1999-02-12 17:32:17 +00:00
|
|
|
|
|
|
|
// Stop loading the current document (if any...). This call may result in
|
|
|
|
// firing an EndLoadURL notification for the old document...
|
1999-11-30 00:09:00 +00:00
|
|
|
if (aKickOffLoad)
|
2000-03-11 01:05:08 +00:00
|
|
|
StopLoad();
|
1999-11-18 07:06:39 +00:00
|
|
|
|
1999-04-06 21:01:04 +00:00
|
|
|
|
1999-02-12 17:32:17 +00:00
|
|
|
// Tell web-shell-container we are loading a new url
|
|
|
|
if (nsnull != mContainer) {
|
1999-09-08 03:59:21 +00:00
|
|
|
nsAutoString uniSpec (urlSpec);
|
1999-09-14 21:49:21 +00:00
|
|
|
rv = mContainer->BeginLoadURL(this, uniSpec.GetUnicode());
|
1999-02-12 17:32:17 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1999-04-06 21:01:04 +00:00
|
|
|
|
1999-05-03 23:04:50 +00:00
|
|
|
mProcessedEndDocumentLoad = PR_FALSE;
|
|
|
|
|
1999-04-06 21:01:04 +00:00
|
|
|
/* WebShell was primarily passing the buck when it came to streamObserver.
|
|
|
|
* So, pass on the observer which is already a streamObserver to DocLoder.
|
|
|
|
*/
|
2000-01-23 02:31:52 +00:00
|
|
|
if (aKickOffLoad) {
|
|
|
|
|
|
|
|
#ifdef MOZ_PERF_METRICS
|
|
|
|
{
|
|
|
|
char* url;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
rv = aUri->GetSpec(&url);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
MOZ_TIMER_LOG(("*** Timing layout processes on url: '%s', webshell: %p\n", url, this));
|
|
|
|
delete [] url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Reset and start: nsWebShell::DoLoadURL(), this=%p\n", this));
|
|
|
|
MOZ_TIMER_RESET(mTotalTime);
|
|
|
|
MOZ_TIMER_START(mTotalTime);
|
|
|
|
#endif
|
1999-11-04 22:09:46 +00:00
|
|
|
|
2000-01-29 06:06:25 +00:00
|
|
|
nsCOMPtr<nsIURILoader> pURILoader = do_GetService(NS_URI_LOADER_PROGID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsXPIDLCString aUrlScheme;
|
|
|
|
aUri->GetScheme(getter_Copies(aUrlScheme));
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
pURILoader->GetLoadGroupForContext(NS_STATIC_CAST(nsISupports *, (nsIWebShell *) this), getter_AddRefs(loadGroup));
|
|
|
|
|
|
|
|
// first, create a channel for the protocol....
|
|
|
|
nsCOMPtr<nsIIOService> pNetService = do_GetService(kIOServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIChannel> pChannel;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> requestor (do_QueryInterface(NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this)));
|
|
|
|
|
|
|
|
// Create a referrer URI
|
|
|
|
nsCOMPtr<nsIURI> referrer;
|
|
|
|
if (aReferrer) {
|
|
|
|
nsAutoString tempReferrer(aReferrer);
|
|
|
|
char* referrerStr = tempReferrer.ToNewCString();
|
|
|
|
pNetService->NewURI(referrerStr, nsnull, getter_AddRefs(referrer));
|
|
|
|
Recycle(referrerStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = pNetService->NewChannelFromURI(aCommand, aUri, loadGroup, requestor,
|
2000-02-23 21:17:17 +00:00
|
|
|
aType, referrer /* referring uri */,
|
|
|
|
0, 0,
|
2000-01-29 06:06:25 +00:00
|
|
|
getter_AddRefs(pChannel));
|
2000-02-11 04:48:09 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2000-02-16 07:30:17 +00:00
|
|
|
if (rv == NS_ERROR_DOM_RETVAL_UNDEFINED) // if causing the channel changed the
|
|
|
|
return NS_OK; // dom and there is nothing else to do
|
|
|
|
else
|
|
|
|
return rv; // uhoh we were unable to get a channel to handle the url!!!
|
|
|
|
}
|
2000-01-29 06:06:25 +00:00
|
|
|
// Mark the channel as being a document URI...
|
|
|
|
nsLoadFlags loadAttribs = 0;
|
|
|
|
pChannel->GetLoadAttributes(&loadAttribs);
|
|
|
|
loadAttribs |= nsIChannel::LOAD_DOCUMENT_URI;
|
|
|
|
|
|
|
|
pChannel->SetLoadAttributes(loadAttribs);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(pChannel));
|
2000-02-23 21:17:17 +00:00
|
|
|
if (httpChannel)
|
2000-01-29 06:06:25 +00:00
|
|
|
{
|
2000-02-23 21:17:17 +00:00
|
|
|
// figure out if we need to set the post data stream on the channel...
|
|
|
|
// right now, this is only done for http channels.....
|
|
|
|
if (aPostDataStream)
|
|
|
|
{
|
|
|
|
httpChannel->SetRequestMethod(HM_POST);
|
|
|
|
httpChannel->SetPostDataStream(aPostDataStream);
|
|
|
|
}
|
|
|
|
// Set the referrer explicitly
|
|
|
|
if (referrer)
|
|
|
|
{
|
|
|
|
// Referrer is currenly only set for link clicks here.
|
|
|
|
httpChannel->SetReferrer(referrer,
|
|
|
|
nsIHTTPChannel::REFERRER_LINK_CLICK);
|
|
|
|
}
|
2000-01-29 06:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now let's pass the channel into the uri loader
|
|
|
|
nsURILoadCommand loadCmd = nsIURILoader::viewNormal;
|
|
|
|
if (nsCRT::strcasecmp(aCommand, "view-link-click") == 0)
|
|
|
|
loadCmd = nsIURILoader::viewUserClick;
|
|
|
|
else if (nsCRT::strcasecmp(aCommand, "view-source") == 0)
|
|
|
|
loadCmd = nsIURILoader::viewSource;
|
|
|
|
|
2000-02-16 07:30:17 +00:00
|
|
|
rv = pURILoader->OpenURI(pChannel, loadCmd, aWindowTarget /* window target */,
|
2000-01-29 06:06:25 +00:00
|
|
|
NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this));
|
|
|
|
}
|
2000-01-23 02:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fix for bug 1646. Change the notion of current url and referrer only after
|
1999-11-04 22:09:46 +00:00
|
|
|
// the document load succeeds.
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-02-24 04:16:17 +00:00
|
|
|
SetCurrentURI(aUri);
|
|
|
|
SetReferrer(aReferrer);
|
1999-11-04 22:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-02-12 17:32:17 +00:00
|
|
|
}
|
|
|
|
|
2000-03-11 12:02:06 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::GetCanGoBack(PRBool* aCanGoBack)
|
|
|
|
{
|
|
|
|
#ifdef DOCSHELL_LOAD
|
|
|
|
return nsDocShell::GetCanGoBack(aCanGoBack);
|
|
|
|
#else /*!DOCSHELL_LOAD*/
|
|
|
|
*aCanGoBack = (mHistoryIndex - 1) > - 1 ? PR_TRUE : PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
#endif /*!DOCSHELL_LOAD*/
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::GetCanGoForward(PRBool* aCanGoForward)
|
|
|
|
{
|
|
|
|
#ifdef DOCSHELL_LOAD
|
|
|
|
return nsDocShell::GetCanGoForward(aCanGoForward);
|
|
|
|
#else /*!DOCSHELL_LOAD*/
|
|
|
|
*aCanGoForward = mHistoryIndex < mHistory.Count() - 1 ? PR_TRUE : PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
#endif /*!DOCSHELL_LOAD*/
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::GoBack()
|
|
|
|
{
|
|
|
|
#ifdef DOCSHELL_LOAD
|
|
|
|
return nsDocShell::GoBack();
|
|
|
|
#else /*!DOCSHELL_LOAD*/
|
|
|
|
NS_ENSURE_SUCCESS(GoTo(mHistoryIndex - 1), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
#endif /*!DOCSHELL_LOAD*/
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::GoForward()
|
|
|
|
{
|
|
|
|
#ifdef DOCSHELL_LOAD
|
|
|
|
return nsDocShell::GoForward();
|
|
|
|
#else /*!DOCSHELL_LOAD*/
|
|
|
|
NS_ENSURE_SUCCESS(GoTo(mHistoryIndex + 1), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
#endif /*!DOCSHELL_LOAD*/
|
|
|
|
}
|
|
|
|
|
2000-02-29 22:35:33 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::LoadURI(const PRUnichar* aURI)
|
|
|
|
{
|
|
|
|
#ifdef DOCSHELL_LOAD
|
|
|
|
return nsDocShell::LoadURI(aURI);
|
|
|
|
#else /*!DOCSHELL_LOAD*/
|
|
|
|
return LoadURL(aURI);
|
|
|
|
#endif /*!DOCSHELL_LOAD*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-24 04:16:17 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer,
|
|
|
|
nsIInputStream* aPostData, loadType aLoadType)
|
|
|
|
{
|
|
|
|
nsXPIDLCString url;
|
|
|
|
aURI->GetSpec(getter_Copies(url));
|
|
|
|
|
|
|
|
nsXPIDLCString referrer;
|
|
|
|
if(aReferrer)
|
|
|
|
aReferrer->GetSpec(getter_Copies(referrer));
|
|
|
|
|
|
|
|
|
|
|
|
return LoadURL(nsAutoString(url).GetUnicode(), nsnull, PR_FALSE, 0, 0,
|
|
|
|
nsnull, nsAutoString(referrer).GetUnicode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-11-18 07:06:39 +00:00
|
|
|
// nsIURIContentListener support
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetProtocolHandler(nsIURI *aURI, nsIProtocolHandler **aProtocolHandler)
|
|
|
|
{
|
Removed GetWebShellType as it is no longer in the nsIWebShell API. Rely on the docshell implementation of accessing the ChromeEventHandler, the parentContentListener, GetProtocolHandler(), GetTitle(), LoadURI(), LoadURIVia(), GetDocument(), GetCurrentURI(), GetPresContext(), GetPresShell(), and GetContentViewer(). Fixed a leak in SetTitle() when in frames. Introduced when I removed the passing along of the title to the parent (comPtrs would have prevented this leak).
1999-12-21 00:19:59 +00:00
|
|
|
// Farm this off to our content listener
|
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
return mContentListener->GetProtocolHandler(aURI, aProtocolHandler);
|
1999-11-18 07:06:39 +00:00
|
|
|
}
|
|
|
|
|
2000-02-04 08:44:46 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::IsPreferred(const char * aContentType,
|
|
|
|
nsURILoadCommand aCommand,
|
|
|
|
const char * aWindowTarget,
|
|
|
|
char ** aDesiredContentType,
|
|
|
|
PRBool * aCanHandleContent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
return mContentListener->IsPreferred(aContentType, aCommand, aWindowTarget, aDesiredContentType,
|
|
|
|
aCanHandleContent);
|
|
|
|
}
|
|
|
|
|
1999-11-18 07:06:39 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::CanHandleContent(const char * aContentType,
|
1999-12-02 07:00:17 +00:00
|
|
|
nsURILoadCommand aCommand,
|
1999-11-18 07:06:39 +00:00
|
|
|
const char * aWindowTarget,
|
|
|
|
char ** aDesiredContentType,
|
|
|
|
PRBool * aCanHandleContent)
|
|
|
|
|
|
|
|
{
|
2000-02-04 08:44:46 +00:00
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
return mContentListener->CanHandleContent(aContentType, aCommand, aWindowTarget, aDesiredContentType,
|
|
|
|
aCanHandleContent);
|
1999-11-18 07:06:39 +00:00
|
|
|
}
|
|
|
|
|
1999-09-08 03:59:21 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-18 07:06:39 +00:00
|
|
|
nsWebShell::DoContent(const char * aContentType,
|
1999-12-02 07:00:17 +00:00
|
|
|
nsURILoadCommand aCommand,
|
|
|
|
const char * aWindowTarget,
|
|
|
|
nsIChannel * aOpenedChannel,
|
|
|
|
nsIStreamListener ** aContentHandler,
|
|
|
|
PRBool * aAbortProcess)
|
1999-11-18 07:06:39 +00:00
|
|
|
{
|
2000-01-29 06:06:25 +00:00
|
|
|
NS_ENSURE_ARG(aOpenedChannel);
|
1999-12-06 22:32:06 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-11-18 07:06:39 +00:00
|
|
|
if (aAbortProcess)
|
|
|
|
*aAbortProcess = PR_FALSE;
|
|
|
|
|
1999-12-06 22:32:06 +00:00
|
|
|
nsXPIDLCString strCommand;
|
|
|
|
// go to the uri loader and ask it to convert the uri load command into a old
|
|
|
|
// world style string
|
|
|
|
NS_WITH_SERVICE(nsIURILoader, pURILoader, NS_URI_LOADER_PROGID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
pURILoader->GetStringForCommand(aCommand, getter_Copies(strCommand));
|
|
|
|
|
2000-02-03 03:44:22 +00:00
|
|
|
|
2000-01-29 06:06:25 +00:00
|
|
|
// determine if the channel has just been retargeted to us...
|
|
|
|
nsLoadFlags loadAttribs = 0;
|
|
|
|
aOpenedChannel->GetLoadAttributes(&loadAttribs);
|
2000-02-24 04:16:17 +00:00
|
|
|
// first, run any uri preparation stuff that we would have run normally
|
|
|
|
// had we gone through OpenURI
|
|
|
|
nsCOMPtr<nsIURI> aUri;
|
|
|
|
aOpenedChannel->GetURI(getter_AddRefs(aUri));
|
2000-01-29 06:06:25 +00:00
|
|
|
if (loadAttribs & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI)
|
|
|
|
{
|
2000-03-14 08:53:46 +00:00
|
|
|
PrepareToLoadURI(aUri, nsnull, PR_TRUE, nsIChannel::LOAD_NORMAL, 0, nsnull, nsnull);
|
2000-01-29 06:06:25 +00:00
|
|
|
// mscott: when I called DoLoadURL I found that we ran into problems because
|
|
|
|
// we currently don't have channel retargeting yet. Basically, what happens is that
|
|
|
|
// DoLoadURL calls StopBeforeRequestingURL and this cancels the current load group
|
|
|
|
// however since we can't retarget yet, we were basically canceling our very
|
|
|
|
// own load group!!! So the request would get canceled out from under us...
|
|
|
|
// after retargeting we may be able to safely call DoLoadURL.
|
2000-02-16 07:30:17 +00:00
|
|
|
DoLoadURL(aUri, strCommand, nsnull, nsIChannel::LOAD_NORMAL, 0, nsnull, nsnull, PR_FALSE);
|
2000-01-29 06:06:25 +00:00
|
|
|
SetFocus(); // force focus to get set on the retargeted window...
|
|
|
|
}
|
1999-12-29 05:10:21 +00:00
|
|
|
|
2000-02-24 04:16:17 +00:00
|
|
|
OnLoadingSite(aUri);
|
|
|
|
|
2000-02-29 22:35:33 +00:00
|
|
|
return CreateContentViewer(aContentType, aCommand, aOpenedChannel,
|
|
|
|
aContentHandler);
|
1999-12-28 09:18:47 +00:00
|
|
|
}
|
|
|
|
|
1999-11-18 07:06:39 +00:00
|
|
|
nsresult nsWebShell::PrepareToLoadURI(nsIURI * aUri,
|
|
|
|
nsIInputStream * aPostStream,
|
|
|
|
PRBool aModifyHistory,
|
|
|
|
nsLoadFlags aType,
|
|
|
|
const PRUint32 aLocalIP,
|
|
|
|
nsISupports * aHistoryState,
|
|
|
|
const PRUnichar * aReferrer)
|
1998-11-11 20:31:45 +00:00
|
|
|
{
|
1998-07-18 21:43:02 +00:00
|
|
|
nsresult rv;
|
1999-08-03 21:48:40 +00:00
|
|
|
CancelRefreshURITimers();
|
1999-09-08 03:59:21 +00:00
|
|
|
nsXPIDLCString scheme, CUriSpec;
|
1999-01-09 02:00:42 +00:00
|
|
|
|
1999-10-13 10:24:12 +00:00
|
|
|
if (!aUri) return NS_ERROR_NULL_POINTER;
|
1999-09-28 22:11:26 +00:00
|
|
|
|
1999-09-08 03:59:21 +00:00
|
|
|
rv = aUri->GetScheme(getter_Copies(scheme));
|
1999-08-04 21:18:24 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-08 03:59:21 +00:00
|
|
|
rv = aUri->GetSpec(getter_Copies(CUriSpec));
|
1999-08-04 21:18:24 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsAutoString uriSpec(CUriSpec);
|
|
|
|
|
1999-09-08 03:59:21 +00:00
|
|
|
nsXPIDLCString spec;
|
|
|
|
rv = aUri->GetSpec(getter_Copies(spec));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-04 21:18:24 +00:00
|
|
|
|
|
|
|
nsString* url = new nsString(uriSpec);
|
1998-08-13 04:36:42 +00:00
|
|
|
if (aModifyHistory) {
|
|
|
|
// Discard part of history that is no longer reachable
|
|
|
|
PRInt32 i, n = mHistory.Count();
|
|
|
|
i = mHistoryIndex + 1;
|
|
|
|
while (--n >= i) {
|
|
|
|
nsString* u = (nsString*) mHistory.ElementAt(n);
|
|
|
|
delete u;
|
|
|
|
mHistory.RemoveElementAt(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tack on new url
|
|
|
|
mHistory.AppendElement(url);
|
|
|
|
mHistoryIndex++;
|
|
|
|
}
|
|
|
|
else {
|
2000-02-16 07:30:17 +00:00
|
|
|
|
1998-08-13 04:36:42 +00:00
|
|
|
// Replace the current history index with this URL
|
|
|
|
nsString* u = (nsString*) mHistory.ElementAt(mHistoryIndex);
|
|
|
|
if (nsnull != u) {
|
|
|
|
delete u;
|
|
|
|
}
|
|
|
|
mHistory.ReplaceElementAt(url, mHistoryIndex);
|
|
|
|
}
|
1998-07-18 21:43:02 +00:00
|
|
|
ShowHistory();
|
|
|
|
|
1999-06-15 23:29:38 +00:00
|
|
|
// Give web-shell-container right of refusal
|
|
|
|
if (nsnull != mContainer) {
|
1999-09-17 06:54:58 +00:00
|
|
|
nsAutoString str(spec);
|
|
|
|
rv = mContainer->WillLoadURL(this, str.GetUnicode(), nsLoadURL);
|
1999-06-15 23:29:38 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-11-18 07:06:39 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-15 23:29:38 +00:00
|
|
|
|
1999-11-18 07:06:39 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::LoadURI(nsIURI * aUri,
|
|
|
|
const char * aCommand,
|
|
|
|
nsIInputStream* aPostDataStream,
|
|
|
|
PRBool aModifyHistory,
|
|
|
|
nsLoadFlags aType,
|
|
|
|
const PRUint32 aLocalIP,
|
2000-02-16 07:30:17 +00:00
|
|
|
nsISupports * aHistoryState,
|
|
|
|
const PRUnichar* aReferrer,
|
|
|
|
const char * aWindowTarget)
|
1999-11-18 07:06:39 +00:00
|
|
|
{
|
2000-03-14 08:53:46 +00:00
|
|
|
nsresult rv = PrepareToLoadURI(aUri, aPostDataStream,
|
1999-11-18 07:06:39 +00:00
|
|
|
aModifyHistory, aType, aLocalIP,
|
|
|
|
aHistoryState, aReferrer);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2000-02-16 07:30:17 +00:00
|
|
|
rv = DoLoadURL(aUri, aCommand, aPostDataStream, aType, aLocalIP, aReferrer, aWindowTarget);
|
1999-11-18 07:06:39 +00:00
|
|
|
return rv;
|
1999-09-08 03:59:21 +00:00
|
|
|
}
|
|
|
|
|
2000-02-29 07:07:36 +00:00
|
|
|
|
|
|
|
static nsresult convertURLToFileCharset(nsString& aIn, nsCString& aOut)
|
|
|
|
{
|
|
|
|
nsresult rv=NS_OK;
|
|
|
|
aOut = "";
|
|
|
|
// for file url, we need to convert the nsString to the file system
|
|
|
|
// charset before we pass to NS_NewURI
|
|
|
|
static nsAutoString fsCharset("");
|
|
|
|
// find out the file system charset first
|
|
|
|
if(0 == fsCharset.Length()) {
|
|
|
|
fsCharset = "ISO-8859-1"; // set the fallback first.
|
|
|
|
NS_WITH_SERVICE(nsIPlatformCharset, plat, kPlatformCharsetCID, &rv);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "cannot get nsIPlatformCharset");
|
|
|
|
if(NS_SUCCEEDED(rv)) {
|
|
|
|
rv = plat->GetCharset(kPlatformCharsetSel_FileName, fsCharset);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "nsIPlatformCharset GetCharset failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We probably should cache ccm here.
|
|
|
|
// get a charset converter from the manager
|
|
|
|
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &rv);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "cannot get CharsetConverterManager");
|
|
|
|
nsCOMPtr<nsIUnicodeEncoder> fsEncoder;
|
|
|
|
if(NS_SUCCEEDED(rv)){
|
|
|
|
rv = ccm->GetUnicodeEncoder(&fsCharset, getter_AddRefs(fsEncoder));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "cannot get encoder");
|
|
|
|
if(NS_SUCCEEDED(rv)){
|
|
|
|
PRInt32 bufLen = 0;
|
|
|
|
rv = fsEncoder->GetMaxLength(aIn.GetUnicode(), aIn.Length(), &bufLen);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "GetMaxLength failed");
|
|
|
|
aOut.SetCapacity(bufLen+1);
|
|
|
|
PRInt32 srclen = aIn.Length();
|
|
|
|
rv = fsEncoder->Convert(aIn.GetUnicode(), &srclen,
|
|
|
|
(char*)aOut.GetBuffer(), &bufLen);
|
|
|
|
if(NS_SUCCEEDED(rv)) {
|
|
|
|
((char*)aOut.GetBuffer())[bufLen]='\0';
|
|
|
|
aOut.SetLength(bufLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1999-09-08 03:59:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::LoadURL(const PRUnichar *aURLSpec,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIInputStream* aPostDataStream,
|
|
|
|
PRBool aModifyHistory,
|
|
|
|
nsLoadFlags aType,
|
|
|
|
const PRUint32 aLocalIP,
|
1999-09-17 04:26:02 +00:00
|
|
|
nsISupports * aHistoryState,
|
2000-02-16 07:30:17 +00:00
|
|
|
const PRUnichar* aReferrer,
|
|
|
|
const char * aWindowTarget)
|
1999-09-08 03:59:21 +00:00
|
|
|
{
|
2000-01-12 22:54:07 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool isMail= PR_FALSE; // XXX mailto: hack
|
|
|
|
PRBool keywordsEnabled = PR_FALSE;
|
1999-09-08 03:59:21 +00:00
|
|
|
|
1999-10-13 10:24:12 +00:00
|
|
|
/*
|
|
|
|
TODO This doesnt belong here... The app should be doing all this
|
|
|
|
URL play. The webshell should not have a clue about whats "mailto"
|
|
|
|
If you insist that this should be here, then put in URL parsing
|
|
|
|
optimizations here. -Gagan
|
|
|
|
*/
|
2000-02-23 01:48:22 +00:00
|
|
|
|
|
|
|
mViewSource = (0==PL_strcmp("view-source", aCommand));
|
|
|
|
|
1999-09-08 03:59:21 +00:00
|
|
|
nsAutoString urlStr(aURLSpec);
|
|
|
|
// first things first. try to create a uri out of the string.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
1999-10-05 04:49:58 +00:00
|
|
|
nsXPIDLCString spec;
|
2000-02-29 07:07:36 +00:00
|
|
|
if(0==urlStr.Find("file:",0)) {
|
|
|
|
// if this is file url, we need to convert the URI
|
|
|
|
// from Unicode to the FS charset
|
|
|
|
nsCAutoString inFSCharset;
|
|
|
|
rv = convertURLToFileCharset(urlStr, inFSCharset);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "convertURLToFielCharset failed");
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), inFSCharset.GetBuffer(), nsnull);
|
|
|
|
} else {
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), urlStr, nsnull);
|
|
|
|
}
|
1999-09-08 03:59:21 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// no dice.
|
|
|
|
nsAutoString urlSpec;
|
2000-01-13 23:23:20 +00:00
|
|
|
urlStr.Trim(" ");
|
1999-09-08 03:59:21 +00:00
|
|
|
|
|
|
|
// see if we've got a file url.
|
|
|
|
convertFileToURL(urlStr, urlSpec);
|
2000-02-29 07:07:36 +00:00
|
|
|
nsCAutoString inFSCharset;
|
|
|
|
rv = convertURLToFileCharset(urlSpec, inFSCharset);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "convertURLToFielCharset failed");
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), inFSCharset.GetBuffer(), nsnull);
|
|
|
|
|
1999-09-08 03:59:21 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2000-01-12 22:54:07 +00:00
|
|
|
NS_ASSERTION(mPrefs, "the webshell's pref service wasn't initialized");
|
|
|
|
|
|
|
|
rv = mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRInt32 qMarkLoc = -1, spaceLoc = -1;
|
|
|
|
|
2000-02-29 20:38:16 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2000-01-12 22:54:07 +00:00
|
|
|
if (keywordsEnabled) {
|
|
|
|
// These are keyword formatted strings
|
|
|
|
// "what is mozilla"
|
|
|
|
// "what is mozilla?"
|
|
|
|
// "?mozilla"
|
|
|
|
// "?What is mozilla"
|
|
|
|
|
|
|
|
// These are not keyword formatted strings
|
|
|
|
// "www.blah.com" - anything with a dot in it
|
|
|
|
// "nonQualifiedHost:80" - anything with a colon in it
|
|
|
|
// "nonQualifiedHost?"
|
|
|
|
// "nonQualifiedHost?args"
|
|
|
|
// "nonQualifiedHost?some args"
|
|
|
|
|
|
|
|
if (urlStr.FindChar('.') == -1 && urlStr.FindChar(':') == -1) {
|
|
|
|
qMarkLoc = urlStr.FindChar('?');
|
|
|
|
spaceLoc = urlStr.FindChar(' ');
|
|
|
|
|
|
|
|
PRBool keyword = PR_FALSE;
|
2000-02-02 02:22:36 +00:00
|
|
|
if (qMarkLoc == 0) {
|
2000-01-12 22:54:07 +00:00
|
|
|
keyword = PR_TRUE;
|
|
|
|
} else if ( (spaceLoc > 0) &&
|
|
|
|
( (qMarkLoc == -1) || (spaceLoc < qMarkLoc) )) {
|
|
|
|
keyword = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyword) {
|
2000-02-29 07:07:36 +00:00
|
|
|
nsCAutoString keywordSpec("keyword:");
|
|
|
|
char *utf8Spec = urlStr.ToNewUTF8String();
|
|
|
|
if(utf8Spec) {
|
|
|
|
char* escapedUTF8Spec = nsEscape(utf8Spec, url_Path);
|
|
|
|
if(escapedUTF8Spec) {
|
|
|
|
keywordSpec.Append(escapedUTF8Spec);
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), keywordSpec.GetBuffer(), nsnull);
|
|
|
|
nsAllocator::Free(escapedUTF8Spec);
|
|
|
|
} // escapedUTF8Spec
|
|
|
|
nsAllocator::Free(utf8Spec);
|
|
|
|
} // utf8Spec
|
|
|
|
} // keyword
|
|
|
|
} // FindChar
|
|
|
|
} // keywordEnable
|
|
|
|
|
1999-09-08 03:59:21 +00:00
|
|
|
|
2000-01-11 23:11:32 +00:00
|
|
|
PRInt32 colon = -1;
|
1999-11-02 04:22:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2000-01-11 23:11:32 +00:00
|
|
|
PRInt32 fSlash = urlSpec.FindChar('/');
|
1999-11-02 04:22:12 +00:00
|
|
|
PRUnichar port;
|
|
|
|
// if no scheme (protocol) is found, assume http.
|
|
|
|
if ( ((colon=urlSpec.FindChar(':')) == -1) // no colon at all
|
|
|
|
|| ( (fSlash > -1) && (colon > fSlash) ) // the only colon comes after the first slash
|
|
|
|
|| ( (colon < urlSpec.Length()-1) // the first char after the first colon is a digit (i.e. a port)
|
|
|
|
&& ((port=urlSpec.CharAt(colon+1)) <= '9')
|
|
|
|
&& (port > '0') )) {
|
|
|
|
// find host name
|
|
|
|
PRInt32 hostPos = urlSpec.FindCharInSet("./:");
|
|
|
|
if (hostPos == -1) {
|
|
|
|
hostPos = urlSpec.Length();
|
|
|
|
}
|
1999-09-08 03:59:21 +00:00
|
|
|
|
1999-11-02 04:22:12 +00:00
|
|
|
// extract host name
|
|
|
|
nsAutoString hostSpec;
|
|
|
|
urlSpec.Left(hostSpec, hostPos);
|
1999-09-08 03:59:21 +00:00
|
|
|
|
1999-11-02 04:22:12 +00:00
|
|
|
// insert url spec corresponding to host name
|
|
|
|
if (hostSpec.EqualsIgnoreCase("ftp")) {
|
|
|
|
urlSpec.Insert("ftp://", 0, 6);
|
|
|
|
} else {
|
|
|
|
urlSpec.Insert("http://", 0, 7);
|
|
|
|
}
|
|
|
|
} // end if colon
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
// XXX mailto: hack
|
|
|
|
if ((urlSpec.Find("mailto:", PR_TRUE)) >= 0)
|
|
|
|
isMail = PR_TRUE;
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
if (!isMail) {
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nsnull);
|
|
|
|
if (NS_ERROR_UNKNOWN_PROTOCOL == rv) {
|
|
|
|
// we weren't able to find a protocol handler
|
|
|
|
rv = InitDialogVars();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
nsXPIDLString messageStr;
|
|
|
|
nsAutoString name("protocolNotFound");
|
|
|
|
rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
NS_ASSERTION(colon != -1, "we shouldn't have gotten this far if we didn't have a colon");
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
// extract the scheme
|
|
|
|
nsAutoString scheme;
|
|
|
|
urlSpec.Left(scheme, colon);
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-25 02:47:58 +00:00
|
|
|
nsAutoString dnsMsg(scheme);
|
|
|
|
dnsMsg.Append(' ');
|
|
|
|
dnsMsg.Append(messageStr);
|
1999-09-15 19:33:46 +00:00
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
(void)mPrompter->Alert(dnsMsg.GetUnicode());
|
|
|
|
} // end unknown protocol
|
|
|
|
} // end !isMail
|
1999-09-08 03:59:21 +00:00
|
|
|
}
|
2000-01-12 22:54:07 +00:00
|
|
|
}
|
1999-09-08 03:59:21 +00:00
|
|
|
}
|
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
if (!uri) return rv;
|
1999-09-15 19:33:46 +00:00
|
|
|
|
2000-01-12 22:54:07 +00:00
|
|
|
rv = uri->GetSpec(getter_Copies(spec));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-02-29 07:07:36 +00:00
|
|
|
|
1999-10-05 04:49:58 +00:00
|
|
|
// Get hold of Root webshell
|
1999-09-15 19:33:46 +00:00
|
|
|
nsCOMPtr<nsIWebShell> root;
|
1999-10-05 04:49:58 +00:00
|
|
|
nsCOMPtr<nsISessionHistory> shist;
|
1999-11-03 22:30:44 +00:00
|
|
|
PRBool isLoadingHistory=PR_FALSE; // Is SH currently loading an entry from history?
|
1999-09-15 19:33:46 +00:00
|
|
|
rv = GetRootWebShell(*getter_AddRefs(root));
|
1999-10-05 04:49:58 +00:00
|
|
|
// Get hold of session History
|
|
|
|
if (NS_SUCCEEDED(rv) && root) {
|
|
|
|
root->GetSessionHistory(*getter_AddRefs(shist));
|
|
|
|
}
|
1999-11-03 22:30:44 +00:00
|
|
|
if (shist)
|
2000-02-16 07:30:17 +00:00
|
|
|
shist->GetLoadingFlag(&isLoadingHistory);
|
1999-09-15 19:33:46 +00:00
|
|
|
|
|
|
|
|
1999-10-28 20:29:43 +00:00
|
|
|
/*
|
|
|
|
* Save the history state for the current index iff this loadurl() request
|
|
|
|
* is not from SH. When the request comes from SH, aModifyHistory will
|
|
|
|
* be false and nsSessionHistory.cpp takes of this.
|
1999-10-05 04:49:58 +00:00
|
|
|
*/
|
1999-10-28 20:29:43 +00:00
|
|
|
if (shist) {
|
2000-02-16 07:30:17 +00:00
|
|
|
PRInt32 indix;
|
1999-10-28 20:29:43 +00:00
|
|
|
shist->GetCurrentIndex(&indix);
|
|
|
|
if (indix >= 0 && (aModifyHistory)) {
|
|
|
|
nsCOMPtr<nsISupports> historyState;
|
|
|
|
rv = GetHistoryState(getter_AddRefs(historyState));
|
2000-02-16 07:30:17 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && historyState)
|
1999-10-28 20:29:43 +00:00
|
|
|
shist->SetHistoryObjectForIndex(indix, historyState);
|
2000-02-16 07:30:17 +00:00
|
|
|
}
|
1999-10-28 20:29:43 +00:00
|
|
|
}
|
1999-10-05 04:49:58 +00:00
|
|
|
/* Set the History state object for the current page in the
|
|
|
|
* presentation shell. If it is a new page being visited,
|
|
|
|
* aHistoryState is null. If the load is coming from
|
|
|
|
* session History, it will be set to the cached history object by
|
|
|
|
* session History.
|
|
|
|
*/
|
1999-11-01 21:47:54 +00:00
|
|
|
SetHistoryState(aHistoryState);
|
1999-10-05 04:49:58 +00:00
|
|
|
|
|
|
|
/* Add the page to session history */
|
1999-12-22 21:35:18 +00:00
|
|
|
if (aModifyHistory && shist && (!isMail)) {
|
1999-10-05 04:49:58 +00:00
|
|
|
PRInt32 ret;
|
2000-02-10 04:56:56 +00:00
|
|
|
nsCAutoString referrer(aReferrer);
|
|
|
|
ret = shist->Add(spec, referrer, this);
|
1999-10-05 04:49:58 +00:00
|
|
|
}
|
|
|
|
|
1999-11-03 22:30:44 +00:00
|
|
|
nsCOMPtr<nsIWebShell> parent;
|
|
|
|
nsresult res = GetParent(*getter_AddRefs(parent));
|
2000-03-11 02:57:39 +00:00
|
|
|
nsCOMPtr<nsIURI> newURI;
|
1999-11-03 22:30:44 +00:00
|
|
|
|
|
|
|
if ((isLoadingHistory)) {
|
2000-02-16 07:30:17 +00:00
|
|
|
/* if LoadURL() got called from SH, AND If we are going "Back/Forward"
|
2000-03-11 02:57:39 +00:00
|
|
|
* to a frame page,SH will change the current uri to the right value
|
|
|
|
* for smoother redraw.
|
2000-02-16 07:30:17 +00:00
|
|
|
*/
|
2000-03-11 02:57:39 +00:00
|
|
|
res = GetCurrentURI(getter_AddRefs(newURI));
|
1999-11-03 22:30:44 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-02-16 07:30:17 +00:00
|
|
|
/* If the call is not from SH, use the url passed by the caller
|
|
|
|
* so that things like JS will work right. This is for bug # 1646.
|
|
|
|
* May regress in other situations.
|
|
|
|
* What a hack
|
|
|
|
*/
|
2000-03-11 03:20:25 +00:00
|
|
|
nsAutoString urlstr = (const char *) spec;
|
2000-03-11 02:57:39 +00:00
|
|
|
res = NS_NewURI(getter_AddRefs(newURI), urlstr, nsnull);
|
1999-11-03 22:30:44 +00:00
|
|
|
}
|
|
|
|
|
1999-10-05 04:49:58 +00:00
|
|
|
|
1999-11-03 22:30:44 +00:00
|
|
|
if (NS_SUCCEEDED(res)) {
|
1999-10-05 04:49:58 +00:00
|
|
|
// now that we have a uri, call the REAL LoadURI method which requires a nsIURI.
|
2000-02-16 07:30:17 +00:00
|
|
|
return LoadURI(newURI, aCommand, aPostDataStream, aModifyHistory, aType, aLocalIP, aHistoryState, aReferrer, aWindowTarget);
|
1999-10-05 04:49:58 +00:00
|
|
|
}
|
|
|
|
return rv;
|
1999-09-15 19:33:46 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
1999-09-02 21:39:01 +00:00
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::Stop(void)
|
|
|
|
{
|
1998-09-25 22:25:21 +00:00
|
|
|
// Cancel any timers that were set for this loader.
|
1999-08-03 21:48:40 +00:00
|
|
|
CancelRefreshURITimers();
|
1998-09-25 22:25:21 +00:00
|
|
|
|
2000-02-24 04:16:17 +00:00
|
|
|
return nsDocShell::Stop();
|
1998-08-14 23:08:54 +00:00
|
|
|
}
|
1998-08-13 04:49:16 +00:00
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// History methods
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 11:24:50 +00:00
|
|
|
nsWebShell::GoTo(PRInt32 aHistoryIndex)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
if ((aHistoryIndex >= 0) &&
|
1998-08-14 23:08:54 +00:00
|
|
|
(aHistoryIndex < mHistory.Count())) {
|
1998-07-18 21:43:02 +00:00
|
|
|
nsString* s = (nsString*) mHistory.ElementAt(aHistoryIndex);
|
|
|
|
|
|
|
|
// Give web-shell-container right of refusal
|
|
|
|
nsAutoString urlSpec(*s);
|
|
|
|
if (nsnull != mContainer) {
|
1999-04-22 00:05:59 +00:00
|
|
|
rv = mContainer->WillLoadURL(this, urlSpec.GetUnicode(), nsLoadHistory);
|
1999-01-08 00:32:55 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-07-18 21:43:02 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1999-04-06 21:01:04 +00:00
|
|
|
|
1999-12-21 23:03:29 +00:00
|
|
|
#ifdef DEBUG
|
1998-07-18 21:43:02 +00:00
|
|
|
printf("Goto %d\n", aHistoryIndex);
|
1999-12-21 23:03:29 +00:00
|
|
|
#endif
|
1998-07-18 21:43:02 +00:00
|
|
|
mHistoryIndex = aHistoryIndex;
|
|
|
|
ShowHistory();
|
|
|
|
|
1999-09-08 03:59:21 +00:00
|
|
|
// convert the uri spec into a url and then pass it to DoLoadURL
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nsnull);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = DoLoadURL(uri, // URL string
|
1999-02-12 17:32:17 +00:00
|
|
|
"view", // Command
|
|
|
|
nsnull, // Post Data
|
2000-02-16 07:30:17 +00:00
|
|
|
nsISessionHistory::LOAD_HISTORY, // the reload type
|
1999-09-17 04:26:02 +00:00
|
|
|
0, // load attributes
|
2000-02-16 07:30:17 +00:00
|
|
|
nsnull,nsnull); // referrer
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
return rv;
|
1999-08-09 00:03:12 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
1999-01-28 23:13:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetHistoryLength(PRInt32& aResult)
|
|
|
|
{
|
|
|
|
aResult = mHistory.Count();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetHistoryIndex(PRInt32& aResult)
|
|
|
|
{
|
|
|
|
aResult = mHistoryIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-22 23:40:54 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-14 06:35:01 +00:00
|
|
|
nsWebShell::GetURL(PRInt32 aHistoryIndex, const PRUnichar** aURLResult)
|
1998-07-22 23:40:54 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_ILLEGAL_VALUE;
|
1999-10-12 04:37:43 +00:00
|
|
|
|
1999-09-21 05:27:35 +00:00
|
|
|
// XXX Ownership rules for the string passed back from this
|
|
|
|
// method are not XPCOM compliant. If they were correct,
|
|
|
|
// the caller would deallocate the string.
|
1998-07-22 23:40:54 +00:00
|
|
|
if ((aHistoryIndex >= 0) &&
|
|
|
|
(aHistoryIndex <= mHistory.Count() - 1)) {
|
|
|
|
nsString* s = (nsString*) mHistory.ElementAt(aHistoryIndex);
|
|
|
|
if (nsnull != s) {
|
1999-04-22 00:05:59 +00:00
|
|
|
*aURLResult = s->GetUnicode();
|
1998-07-22 23:40:54 +00:00
|
|
|
}
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
void
|
|
|
|
nsWebShell::ShowHistory()
|
|
|
|
{
|
1999-10-12 04:37:43 +00:00
|
|
|
#if defined(NS_DEBUG)
|
1998-07-18 21:43:02 +00:00
|
|
|
if (WEB_LOG_TEST(gLogModule, WEB_TRACE_HISTORY)) {
|
|
|
|
PRInt32 i, n = mHistory.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (i == mHistoryIndex) {
|
|
|
|
printf("**");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
nsString* u = (nsString*) mHistory.ElementAt(i);
|
|
|
|
fputs(*u, stdout);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-08-09 00:03:12 +00:00
|
|
|
|
1998-07-19 01:18:40 +00:00
|
|
|
//----------------------------------------
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// WebShell container implementation
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsWebShell::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1999-03-13 03:31:55 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-07-18 21:43:02 +00:00
|
|
|
if (nsnull != mContainer) {
|
1999-03-13 03:31:55 +00:00
|
|
|
rv = mContainer->WillLoadURL(aShell, aURL, aReason);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
1999-03-13 03:31:55 +00:00
|
|
|
return rv;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsWebShell::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
|
|
|
if (nsnull != mContainer) {
|
1998-08-20 06:17:47 +00:00
|
|
|
// XXX: do not propagate this notification up from any frames...
|
1999-04-06 21:01:04 +00:00
|
|
|
return mContainer->BeginLoadURL(aShell, aURL);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::ProgressLoadURL(nsIWebShell* aShell,
|
|
|
|
const PRUnichar* aURL,
|
|
|
|
PRInt32 aProgress,
|
1998-08-14 23:08:54 +00:00
|
|
|
PRInt32 aProgressMax)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1999-03-13 03:31:55 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-07-18 21:43:02 +00:00
|
|
|
if (nsnull != mContainer) {
|
1999-03-13 03:31:55 +00:00
|
|
|
rv = mContainer->ProgressLoadURL(aShell, aURL, aProgress, aProgressMax);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
1999-03-13 03:31:55 +00:00
|
|
|
return rv;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
NS_IMETHODIMP
|
1999-08-05 01:28:30 +00:00
|
|
|
nsWebShell::EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsresult aStatus)
|
1998-08-14 23:08:54 +00:00
|
|
|
{
|
1999-03-13 03:31:55 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-08-14 23:08:54 +00:00
|
|
|
if (nsnull != mContainer) {
|
1998-08-20 06:17:47 +00:00
|
|
|
// XXX: do not propagate this notification up from any frames...
|
1999-01-27 03:50:10 +00:00
|
|
|
return mContainer->EndLoadURL(aShell, aURL, aStatus);
|
1998-08-14 23:08:54 +00:00
|
|
|
}
|
1999-03-13 03:31:55 +00:00
|
|
|
return rv;
|
1998-08-14 23:08:54 +00:00
|
|
|
}
|
|
|
|
|
1999-08-30 22:45:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::GetHistoryState(nsISupports** aLayoutHistoryState)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// XXX Need to think about what to do for framesets.
|
1999-09-06 22:59:11 +00:00
|
|
|
// For now, return an error if this webshell
|
1999-08-30 22:45:46 +00:00
|
|
|
// contains a frame or a frameset document.
|
1999-09-06 22:59:11 +00:00
|
|
|
// The main content area will always have a parent. It is
|
1999-09-02 21:39:01 +00:00
|
|
|
// enough to check the children count to verify frames.
|
|
|
|
if (mChildren.Count() > 0) {
|
1999-08-30 22:45:46 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ask the pres shell for the history state
|
|
|
|
if (mContentViewer) {
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv = do_QueryInterface(mContentViewer);
|
|
|
|
if (nsnull != docv) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = docv->GetPresShell(*getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = shell->GetHistoryState((nsILayoutHistoryState**) aLayoutHistoryState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
1999-05-06 01:58:48 +00:00
|
|
|
|
1999-08-31 14:49:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::SetHistoryState(nsISupports* aLayoutHistoryState)
|
|
|
|
{
|
|
|
|
mHistoryState = aLayoutHistoryState;
|
1999-09-06 22:59:11 +00:00
|
|
|
return NS_OK;
|
1999-08-31 14:49:21 +00:00
|
|
|
}
|
|
|
|
|
1999-05-06 01:58:48 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Web Shell Services API
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::LoadDocument(const char* aURL,
|
|
|
|
const char* aCharset,
|
1999-05-06 03:54:40 +00:00
|
|
|
nsCharsetSource aSource)
|
1999-05-06 01:58:48 +00:00
|
|
|
{
|
1999-05-19 00:23:03 +00:00
|
|
|
// XXX hack. kee the aCharset and aSource wait to pick it up
|
1999-11-19 07:35:27 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
|
|
|
|
if (cv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
|
|
|
|
if (muDV)
|
1999-09-23 03:27:53 +00:00
|
|
|
{
|
1999-11-19 07:35:27 +00:00
|
|
|
nsCharsetSource hint;
|
|
|
|
muDV->GetHintCharacterSetSource((PRInt32 *)(&hint));
|
|
|
|
if( aSource > hint )
|
|
|
|
{
|
|
|
|
nsAutoString inputCharSet(aCharset);
|
|
|
|
muDV->SetHintCharacterSet(inputCharSet.GetUnicode());
|
|
|
|
muDV->SetHintCharacterSetSource((PRInt32)aSource);
|
|
|
|
if(eCharsetReloadRequested != mCharsetReloadState)
|
|
|
|
{
|
|
|
|
mCharsetReloadState = eCharsetReloadRequested;
|
|
|
|
nsAutoString url(aURL);
|
|
|
|
LoadURL(url.GetUnicode());
|
|
|
|
}
|
|
|
|
}
|
1999-09-23 03:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-06 01:58:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::ReloadDocument(const char* aCharset,
|
1999-09-16 14:15:16 +00:00
|
|
|
nsCharsetSource aSource,
|
|
|
|
const char* aCmd)
|
1999-09-06 22:59:11 +00:00
|
|
|
{
|
1999-05-28 21:32:29 +00:00
|
|
|
|
1999-09-06 22:59:11 +00:00
|
|
|
// XXX hack. kee the aCharset and aSource wait to pick it up
|
1999-11-19 07:35:27 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
|
|
|
|
if (cv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
|
|
|
|
if (muDV)
|
|
|
|
{
|
|
|
|
nsCharsetSource hint;
|
|
|
|
muDV->GetHintCharacterSetSource((PRInt32 *)(&hint));
|
|
|
|
if( aSource > hint )
|
|
|
|
{
|
|
|
|
nsAutoString inputCharSet(aCharset);
|
|
|
|
muDV->SetHintCharacterSet(inputCharSet.GetUnicode());
|
|
|
|
muDV->SetHintCharacterSetSource((PRInt32)aSource);
|
|
|
|
if(eCharsetReloadRequested != mCharsetReloadState)
|
|
|
|
{
|
|
|
|
mCharsetReloadState = eCharsetReloadRequested;
|
|
|
|
return Reload(nsIChannel::LOAD_NORMAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-23 03:27:53 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-05-19 00:23:03 +00:00
|
|
|
}
|
|
|
|
|
1999-08-18 01:39:20 +00:00
|
|
|
|
1999-05-06 01:58:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::StopDocumentLoad(void)
|
|
|
|
{
|
1999-09-23 03:27:53 +00:00
|
|
|
if(eCharsetReloadRequested != mCharsetReloadState)
|
|
|
|
{
|
|
|
|
Stop();
|
|
|
|
}
|
1999-05-06 01:58:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::SetRendering(PRBool aRender)
|
|
|
|
{
|
1999-09-23 03:27:53 +00:00
|
|
|
if(eCharsetReloadRequested != mCharsetReloadState)
|
|
|
|
{
|
|
|
|
if (mContentViewer) {
|
|
|
|
mContentViewer->SetEnableRendering(aRender);
|
|
|
|
}
|
1999-05-07 19:25:58 +00:00
|
|
|
}
|
1999-05-06 01:58:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// WebShell link handling
|
|
|
|
|
|
|
|
struct OnLinkClickEvent : public PLEvent {
|
1998-11-14 00:21:19 +00:00
|
|
|
OnLinkClickEvent(nsWebShell* aHandler, nsIContent* aContent,
|
|
|
|
nsLinkVerb aVerb, const PRUnichar* aURLSpec,
|
1999-08-03 20:51:41 +00:00
|
|
|
const PRUnichar* aTargetSpec, nsIInputStream* aPostDataStream = 0);
|
1998-07-18 21:43:02 +00:00
|
|
|
~OnLinkClickEvent();
|
|
|
|
|
|
|
|
void HandleEvent() {
|
1999-09-06 22:59:11 +00:00
|
|
|
mHandler->HandleLinkClickEvent(mContent, mVerb, mURLSpec->GetUnicode(),
|
1999-08-03 20:51:41 +00:00
|
|
|
mTargetSpec->GetUnicode(), mPostDataStream);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWebShell* mHandler;
|
|
|
|
nsString* mURLSpec;
|
|
|
|
nsString* mTargetSpec;
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* mPostDataStream;
|
|
|
|
nsIContent* mContent;
|
|
|
|
nsLinkVerb mVerb;
|
1998-07-18 21:43:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void PR_CALLBACK HandlePLEvent(OnLinkClickEvent* aEvent)
|
|
|
|
{
|
|
|
|
aEvent->HandleEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK DestroyPLEvent(OnLinkClickEvent* aEvent)
|
|
|
|
{
|
|
|
|
delete aEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
OnLinkClickEvent::OnLinkClickEvent(nsWebShell* aHandler,
|
1998-11-14 00:21:19 +00:00
|
|
|
nsIContent *aContent,
|
|
|
|
nsLinkVerb aVerb,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aURLSpec,
|
|
|
|
const PRUnichar* aTargetSpec,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1999-05-04 23:34:10 +00:00
|
|
|
nsIEventQueue* eventQueue;
|
1999-01-05 09:46:33 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
mHandler = aHandler;
|
|
|
|
NS_ADDREF(aHandler);
|
|
|
|
mURLSpec = new nsString(aURLSpec);
|
|
|
|
mTargetSpec = new nsString(aTargetSpec);
|
1999-08-03 20:51:41 +00:00
|
|
|
mPostDataStream = aPostDataStream;
|
|
|
|
NS_IF_ADDREF(mPostDataStream);
|
1998-11-14 00:21:19 +00:00
|
|
|
mContent = aContent;
|
|
|
|
NS_IF_ADDREF(mContent);
|
|
|
|
mVerb = aVerb;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
PL_InitEvent(this, nsnull,
|
|
|
|
(PLHandleEventProc) ::HandlePLEvent,
|
|
|
|
(PLDestroyEventProc) ::DestroyPLEvent);
|
|
|
|
|
1999-01-23 00:52:01 +00:00
|
|
|
eventQueue = aHandler->GetEventQueue();
|
1999-09-06 22:59:11 +00:00
|
|
|
eventQueue->PostEvent(this);
|
|
|
|
NS_RELEASE(eventQueue);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OnLinkClickEvent::~OnLinkClickEvent()
|
|
|
|
{
|
1998-11-14 00:21:19 +00:00
|
|
|
NS_IF_RELEASE(mContent);
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IF_RELEASE(mHandler);
|
1999-08-03 20:51:41 +00:00
|
|
|
NS_IF_RELEASE(mPostDataStream);
|
1998-07-18 21:43:02 +00:00
|
|
|
if (nsnull != mURLSpec) delete mURLSpec;
|
|
|
|
if (nsnull != mTargetSpec) delete mTargetSpec;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::OnLinkClick(nsIContent* aContent,
|
1998-11-14 00:21:19 +00:00
|
|
|
nsLinkVerb aVerb,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aURLSpec,
|
|
|
|
const PRUnichar* aTargetSpec,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1998-07-24 21:03:33 +00:00
|
|
|
OnLinkClickEvent* ev;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-09-06 22:59:11 +00:00
|
|
|
ev = new OnLinkClickEvent(this, aContent, aVerb, aURLSpec,
|
1999-08-03 20:51:41 +00:00
|
|
|
aTargetSpec, aPostDataStream);
|
1998-07-24 21:03:33 +00:00
|
|
|
if (nsnull == ev) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return rv;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
1999-05-04 23:34:10 +00:00
|
|
|
nsIEventQueue* nsWebShell::GetEventQueue(void)
|
1999-01-05 09:46:33 +00:00
|
|
|
{
|
1999-05-04 23:34:10 +00:00
|
|
|
NS_PRECONDITION(nsnull != mThreadEventQueue, "EventQueue for thread is null");
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_ADDREF(mThreadEventQueue);
|
1999-01-05 09:46:33 +00:00
|
|
|
return mThreadEventQueue;
|
|
|
|
}
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
void
|
1998-11-14 00:21:19 +00:00
|
|
|
nsWebShell::HandleLinkClickEvent(nsIContent *aContent,
|
|
|
|
nsLinkVerb aVerb,
|
|
|
|
const PRUnichar* aURLSpec,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aTargetSpec,
|
1999-08-03 20:51:41 +00:00
|
|
|
nsIInputStream* aPostDataStream)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1998-11-14 00:21:19 +00:00
|
|
|
nsAutoString target(aTargetSpec);
|
|
|
|
|
1999-08-04 22:46:49 +00:00
|
|
|
|
1998-11-14 00:21:19 +00:00
|
|
|
switch(aVerb) {
|
|
|
|
case eLinkVerb_New:
|
2000-03-12 09:14:14 +00:00
|
|
|
target.Assign("_blank");
|
1998-11-14 00:21:19 +00:00
|
|
|
// Fall into replace case
|
1999-09-06 22:59:11 +00:00
|
|
|
case eLinkVerb_Replace:
|
1998-11-14 00:21:19 +00:00
|
|
|
{
|
2000-02-15 04:05:04 +00:00
|
|
|
// for now, just hack the verb to be view-link-clicked
|
|
|
|
// and down in the load document code we'll detect this and
|
|
|
|
// set the correct uri loader command
|
2000-03-11 02:57:39 +00:00
|
|
|
nsXPIDLCString spec;
|
|
|
|
mCurrentURI->GetSpec(getter_Copies(spec));
|
|
|
|
nsAutoString specString(spec);
|
2000-02-15 04:05:04 +00:00
|
|
|
LoadURL(aURLSpec, "view-link-click", aPostDataStream,
|
|
|
|
PR_TRUE, nsIChannel::LOAD_NORMAL,
|
2000-03-11 02:57:39 +00:00
|
|
|
0, nsnull, specString.GetUnicode(), nsCAutoString(aTargetSpec));
|
1998-11-14 00:21:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eLinkVerb_Embed:
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
// XXX Need to do this
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-14 00:21:19 +00:00
|
|
|
nsWebShell::OnOverLink(nsIContent* aContent,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aURLSpec,
|
|
|
|
const PRUnichar* aTargetSpec)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1998-08-14 23:08:54 +00:00
|
|
|
if (!mOverURL.Equals(aURLSpec) || !mOverTarget.Equals(aTargetSpec)) {
|
1998-11-26 18:06:47 +00:00
|
|
|
#ifdef NOISY_LINKS
|
1999-09-06 22:59:11 +00:00
|
|
|
fputs("Was '", stdout);
|
|
|
|
fputs(mOverURL, stdout);
|
|
|
|
fputs("' '", stdout);
|
|
|
|
fputs(mOverTarget, stdout);
|
|
|
|
fputs("'\n", stdout);
|
1998-07-18 21:43:02 +00:00
|
|
|
fputs("Over link '", stdout);
|
|
|
|
fputs(aURLSpec, stdout);
|
|
|
|
fputs("' '", stdout);
|
|
|
|
fputs(aTargetSpec, stdout);
|
|
|
|
fputs("'\n", stdout);
|
1998-10-02 18:44:56 +00:00
|
|
|
#endif /* NS_DEBUG */
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
mOverURL = aURLSpec;
|
|
|
|
mOverTarget = aTargetSpec;
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1998-10-02 18:44:56 +00:00
|
|
|
|
2000-02-14 09:16:26 +00:00
|
|
|
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner));
|
|
|
|
|
|
|
|
if (browserChrome)
|
2000-03-16 01:02:23 +00:00
|
|
|
browserChrome->SetOverLink(aURLSpec);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-24 18:20:30 +00:00
|
|
|
nsWebShell::GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
|
|
|
aState = eLinkState_Unvisited;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-05-18 05:21:37 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-06-07 21:26:10 +00:00
|
|
|
// XXX: GlobalHistory is going to be moved out of the webshell into a more appropriate place.
|
1999-08-24 18:20:30 +00:00
|
|
|
if ((nsnull == mHistoryService) && !mFailedToLoadHistoryService) {
|
1999-06-07 21:26:10 +00:00
|
|
|
rv = nsServiceManager::GetService(kGlobalHistoryCID,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIGlobalHistory),
|
1999-06-07 21:26:10 +00:00
|
|
|
(nsISupports**) &mHistoryService);
|
1999-05-18 05:21:37 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mFailedToLoadHistoryService = PR_TRUE;
|
|
|
|
}
|
1999-05-19 07:22:57 +00:00
|
|
|
}
|
1999-05-18 05:21:37 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
if (mHistoryService) {
|
|
|
|
// XXX aURLSpec should really be a char*, not a PRUnichar*.
|
|
|
|
nsAutoString urlStr(aURLSpec);
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
char buf[256];
|
|
|
|
char* url = buf;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
if (urlStr.Length() >= PRInt32(sizeof buf)) {
|
|
|
|
url = new char[urlStr.Length() + 1];
|
|
|
|
}
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
PRInt64 lastVisitDate;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
if (url) {
|
|
|
|
urlStr.ToCString(url, urlStr.Length() + 1);
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
rv = mHistoryService->GetLastVisitDate(url, &lastVisitDate);
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
if (url != buf)
|
|
|
|
delete[] url;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
//XXX: Moved to destructor nsServiceManager::ReleaseService(kGlobalHistoryCID, mHistoryService);
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
// a last-visit-date of zero means we've never seen it before; so
|
|
|
|
// if it's not zero, we must've seen it.
|
|
|
|
if (! LL_IS_ZERO(lastVisitDate))
|
|
|
|
aState = eLinkState_Visited;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-08-24 18:20:30 +00:00
|
|
|
// XXX how to tell if eLinkState_OutOfDate?
|
1999-05-19 07:22:57 +00:00
|
|
|
}
|
1999-05-18 05:21:37 +00:00
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
1999-03-29 09:21:01 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::OnStartDocumentLoad(nsIDocumentLoader* loader,
|
|
|
|
nsIURI* aURL,
|
1999-04-28 06:47:40 +00:00
|
|
|
const char* aCommand)
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
1999-03-29 23:01:13 +00:00
|
|
|
nsIDocumentViewer* docViewer;
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
1999-05-06 03:54:40 +00:00
|
|
|
|
2000-02-14 06:48:39 +00:00
|
|
|
if ((mScriptGlobal) &&
|
1999-05-17 22:14:16 +00:00
|
|
|
(loader == mDocLoader)) {
|
1999-09-06 22:59:11 +00:00
|
|
|
if (nsnull != mContentViewer &&
|
1999-03-29 23:01:13 +00:00
|
|
|
NS_OK == mContentViewer->QueryInterface(kIDocumentViewerIID, (void**)&docViewer)) {
|
|
|
|
nsIPresContext *presContext;
|
|
|
|
if (NS_OK == docViewer->GetPresContext(presContext)) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_PAGE_UNLOAD;
|
1999-11-24 06:03:41 +00:00
|
|
|
rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
1999-03-29 23:01:13 +00:00
|
|
|
|
|
|
|
NS_RELEASE(presContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(docViewer);
|
|
|
|
}
|
|
|
|
}
|
1999-04-06 21:01:04 +00:00
|
|
|
|
1999-09-14 21:49:21 +00:00
|
|
|
if (loader == mDocLoader) {
|
|
|
|
nsCOMPtr<nsIDocumentLoaderObserver> dlObserver;
|
|
|
|
|
|
|
|
if (!mDocLoaderObserver && mParent) {
|
|
|
|
/* If this is a frame (in which case it would have a parent && doesn't
|
|
|
|
* have a documentloaderObserver, get it from the rootWebShell
|
|
|
|
*/
|
2000-03-11 01:05:08 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
|
|
|
|
nsCOMPtr<nsIDocShell> rootDocShell(do_QueryInterface(rootItem));
|
1999-04-06 21:01:04 +00:00
|
|
|
|
2000-03-11 01:05:08 +00:00
|
|
|
if (rootDocShell)
|
|
|
|
rootDocShell->GetDocLoaderObserver(getter_AddRefs(dlObserver));
|
1999-09-14 21:49:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dlObserver = do_QueryInterface(mDocLoaderObserver); // we need this to addref
|
|
|
|
}
|
|
|
|
/*
|
1999-10-13 10:24:12 +00:00
|
|
|
* Fire the OnStartDocumentLoad of the webshell observer
|
1999-09-14 21:49:21 +00:00
|
|
|
*/
|
|
|
|
if ((nsnull != mContainer) && (nsnull != dlObserver))
|
1999-09-17 04:26:02 +00:00
|
|
|
{
|
1999-09-14 21:49:21 +00:00
|
|
|
dlObserver->OnStartDocumentLoad(mDocLoader, aURL, aCommand);
|
1999-09-17 04:26:02 +00:00
|
|
|
}
|
1999-09-14 21:49:21 +00:00
|
|
|
}
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-03-29 23:01:13 +00:00
|
|
|
return rv;
|
1999-03-29 09:21:01 +00:00
|
|
|
}
|
|
|
|
|
1999-04-06 21:01:04 +00:00
|
|
|
|
|
|
|
|
1999-03-29 09:21:01 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
|
|
|
nsIChannel* channel,
|
1999-12-29 07:32:59 +00:00
|
|
|
nsresult aStatus)
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
1999-10-19 22:27:20 +00:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsWebShell::OnEndDocumentLoad(), this=%p\n", this));
|
|
|
|
MOZ_TIMER_STOP(mTotalTime);
|
|
|
|
MOZ_TIMER_LOG(("Total (Layout + Page Load) Time (webshell=%p): ", this));
|
|
|
|
MOZ_TIMER_PRINT(mTotalTime);
|
1999-09-24 07:13:39 +00:00
|
|
|
#endif
|
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
1999-09-15 00:23:40 +00:00
|
|
|
if (!channel) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-06-28 10:35:57 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-12-15 21:26:12 +00:00
|
|
|
|
|
|
|
// clean up reload state for meta charset
|
|
|
|
if(eCharsetReloadRequested == mCharsetReloadState)
|
|
|
|
mCharsetReloadState = eCharsetReloadStopOrigional;
|
|
|
|
else
|
|
|
|
mCharsetReloadState = eCharsetReloadInit;
|
1999-06-28 10:35:57 +00:00
|
|
|
|
1999-12-15 02:18:52 +00:00
|
|
|
/* one of many safeguards that prevent death and destruction if
|
|
|
|
someone is so very very rude as to bring this window down
|
|
|
|
during this load handler. */
|
|
|
|
nsCOMPtr<nsIWebShell> kungFuDeathGrip(this);
|
|
|
|
|
1999-08-26 22:45:55 +00:00
|
|
|
//if (!mProcessedEndDocumentLoad) {
|
|
|
|
if (loader == mDocLoader) {
|
1999-09-06 22:59:11 +00:00
|
|
|
mProcessedEndDocumentLoad = PR_TRUE;
|
1999-05-03 23:04:50 +00:00
|
|
|
|
2000-03-07 06:02:04 +00:00
|
|
|
if (mScriptGlobal && !mEODForCurrentDocument) {
|
1999-05-03 23:04:50 +00:00
|
|
|
nsIDocumentViewer* docViewer;
|
1999-09-06 22:59:11 +00:00
|
|
|
if (nsnull != mContentViewer &&
|
1999-05-03 23:04:50 +00:00
|
|
|
NS_OK == mContentViewer->QueryInterface(kIDocumentViewerIID, (void**)&docViewer)) {
|
|
|
|
nsIPresContext *presContext;
|
|
|
|
if (NS_OK == docViewer->GetPresContext(presContext)) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_PAGE_LOAD;
|
1999-11-24 06:03:41 +00:00
|
|
|
rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
1999-05-03 23:04:50 +00:00
|
|
|
|
|
|
|
NS_RELEASE(presContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(docViewer);
|
1999-04-06 21:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-07 06:02:04 +00:00
|
|
|
mEODForCurrentDocument = PR_TRUE;
|
|
|
|
|
1999-05-03 23:04:50 +00:00
|
|
|
// Fire the EndLoadURL of the web shell container
|
|
|
|
if (nsnull != aURL) {
|
|
|
|
nsAutoString urlString;
|
1999-06-28 10:35:57 +00:00
|
|
|
char* spec;
|
1999-05-03 23:04:50 +00:00
|
|
|
rv = aURL->GetSpec(&spec);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
urlString = spec;
|
|
|
|
if (nsnull != mContainer) {
|
|
|
|
rv = mContainer->EndLoadURL(this, urlString.GetUnicode(), 0);
|
1999-09-06 22:59:11 +00:00
|
|
|
}
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(spec);
|
1999-05-03 23:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
1999-04-06 21:01:04 +00:00
|
|
|
|
1999-06-21 22:17:14 +00:00
|
|
|
|
1999-09-06 22:59:11 +00:00
|
|
|
nsCOMPtr<nsIDocumentLoaderObserver> dlObserver;
|
1999-06-21 22:17:14 +00:00
|
|
|
|
1999-06-14 22:11:47 +00:00
|
|
|
if (!mDocLoaderObserver && mParent) {
|
|
|
|
/* If this is a frame (in which case it would have a parent && doesn't
|
|
|
|
* have a documentloaderObserver, get it from the rootWebShell
|
|
|
|
*/
|
2000-03-11 01:05:08 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
|
|
|
|
nsCOMPtr<nsIDocShell> rootDocShell(do_QueryInterface(rootItem));
|
1999-09-06 22:59:11 +00:00
|
|
|
|
2000-03-11 01:05:08 +00:00
|
|
|
if (rootDocShell)
|
|
|
|
rootDocShell->GetDocLoaderObserver(getter_AddRefs(dlObserver));
|
1999-06-14 22:11:47 +00:00
|
|
|
}
|
|
|
|
else
|
1999-06-19 22:06:35 +00:00
|
|
|
{
|
1999-09-06 22:59:11 +00:00
|
|
|
/* Take care of the Trailing slash situation */
|
|
|
|
if (mSHist)
|
|
|
|
CheckForTrailingSlash(aURL);
|
|
|
|
dlObserver = do_QueryInterface(mDocLoaderObserver); // we need this to addref
|
1999-06-19 22:06:35 +00:00
|
|
|
}
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-05-03 23:04:50 +00:00
|
|
|
/*
|
|
|
|
* Fire the OnEndDocumentLoad of the DocLoaderobserver
|
|
|
|
*/
|
1999-06-19 22:06:35 +00:00
|
|
|
if (dlObserver && (nsnull != aURL)) {
|
1999-12-29 07:32:59 +00:00
|
|
|
dlObserver->OnEndDocumentLoad(mDocLoader, channel, aStatus);
|
1999-05-03 23:04:50 +00:00
|
|
|
}
|
1999-06-14 22:11:47 +00:00
|
|
|
|
2000-01-25 02:47:58 +00:00
|
|
|
if (mDocLoader == loader && NS_FAILED(aStatus)) {
|
|
|
|
nsAutoString errorMsg;
|
2000-01-12 22:54:07 +00:00
|
|
|
nsXPIDLCString host;
|
|
|
|
rv = aURL->GetHost(getter_Copies(host));
|
1999-11-11 03:26:18 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-02-01 22:31:20 +00:00
|
|
|
CBufDescriptor buf((const char *)host, PR_TRUE, PL_strlen(host) + 1);
|
|
|
|
nsCAutoString hostStr(buf);
|
|
|
|
PRInt32 dotLoc = hostStr.FindChar('.');
|
|
|
|
|
|
|
|
|
2000-02-12 01:22:25 +00:00
|
|
|
if (aStatus == NS_ERROR_UNKNOWN_HOST
|
|
|
|
|| aStatus == NS_ERROR_CONNECTION_REFUSED
|
|
|
|
|| aStatus == NS_ERROR_NET_TIMEOUT) {
|
|
|
|
// First see if we should throw it to the keyword server.
|
|
|
|
NS_ASSERTION(mPrefs, "the webshell's pref service wasn't initialized");
|
|
|
|
PRBool keywordsEnabled = PR_FALSE;
|
|
|
|
rv = mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (keywordsEnabled && (-1 == dotLoc)) {
|
|
|
|
// only send non-qualified hosts to the keyword server
|
|
|
|
nsAutoString keywordSpec("keyword:");
|
|
|
|
keywordSpec.Append(host);
|
|
|
|
return LoadURL(keywordSpec.GetUnicode(), "view");
|
|
|
|
} // end keywordsEnabled
|
|
|
|
}
|
2000-02-01 22:31:20 +00:00
|
|
|
|
2000-01-25 02:47:58 +00:00
|
|
|
// Doc failed to load because the host was not found.
|
|
|
|
if (aStatus == NS_ERROR_UNKNOWN_HOST) {
|
|
|
|
// Try our www.*.com trick.
|
|
|
|
nsCAutoString retryHost;
|
2000-01-31 22:47:40 +00:00
|
|
|
nsXPIDLCString scheme;
|
|
|
|
rv = aURL->GetScheme(getter_Copies(scheme));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRUint32 schemeLen = PL_strlen((const char*)scheme);
|
|
|
|
CBufDescriptor schemeBuf((const char*)scheme, PR_TRUE, schemeLen+1, schemeLen);
|
|
|
|
nsCAutoString schemeStr(schemeBuf);
|
|
|
|
|
|
|
|
if (schemeStr.Find("http") == 0) {
|
|
|
|
if (-1 == dotLoc) {
|
2000-01-25 02:47:58 +00:00
|
|
|
retryHost = "www.";
|
|
|
|
retryHost += hostStr;
|
2000-01-31 22:47:40 +00:00
|
|
|
retryHost += ".com";
|
|
|
|
} else {
|
|
|
|
PRInt32 hostLen = hostStr.Length();
|
|
|
|
if ( ((hostLen - dotLoc) == 3) || ((hostLen - dotLoc) == 4) ) {
|
|
|
|
retryHost = "www.";
|
|
|
|
retryHost += hostStr;
|
|
|
|
}
|
2000-01-25 02:47:58 +00:00
|
|
|
}
|
2000-01-13 23:23:20 +00:00
|
|
|
}
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-25 02:47:58 +00:00
|
|
|
if (!retryHost.IsEmpty()) {
|
|
|
|
rv = aURL->SetHost(retryHost.GetBuffer());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsXPIDLCString aSpec;
|
|
|
|
rv = aURL->GetSpec(getter_Copies(aSpec));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsAutoString newURL(aSpec);
|
|
|
|
// reload the url
|
|
|
|
return LoadURL(newURL.GetUnicode(), "view");
|
|
|
|
} // retry
|
|
|
|
|
|
|
|
// throw a DNS failure dialog
|
|
|
|
rv = InitDialogVars();
|
2000-01-12 22:54:07 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-25 02:47:58 +00:00
|
|
|
|
|
|
|
nsXPIDLString messageStr;
|
|
|
|
nsAutoString name("dnsNotFound");
|
|
|
|
rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr));
|
2000-01-11 23:11:32 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-12 22:54:07 +00:00
|
|
|
|
2000-01-25 02:47:58 +00:00
|
|
|
errorMsg = host;
|
|
|
|
errorMsg.Append(' ');
|
|
|
|
errorMsg.Append(messageStr);
|
2000-01-12 22:54:07 +00:00
|
|
|
|
2000-01-25 02:47:58 +00:00
|
|
|
(void)mPrompter->Alert(errorMsg.GetUnicode());
|
|
|
|
} else // unknown host
|
|
|
|
|
|
|
|
// Doc failed to load because we couldn't connect to the server.
|
|
|
|
if (aStatus == NS_ERROR_CONNECTION_REFUSED) {
|
|
|
|
// throw a connection failure dialog
|
|
|
|
PRInt32 port = -1;
|
|
|
|
rv = aURL->GetPort(&port);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = InitDialogVars();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsXPIDLString messageStr;
|
|
|
|
nsAutoString name("connectionFailure");
|
|
|
|
rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
errorMsg = messageStr;
|
|
|
|
errorMsg.Append(' ');
|
|
|
|
errorMsg.Append(host);
|
|
|
|
if (port > 0) {
|
|
|
|
errorMsg.Append(':');
|
|
|
|
errorMsg.Append(port);
|
|
|
|
}
|
|
|
|
errorMsg.Append('.');
|
|
|
|
|
|
|
|
(void)mPrompter->Alert(errorMsg.GetUnicode());
|
|
|
|
} else // end NS_ERROR_CONNECTION_REFUSED
|
|
|
|
|
|
|
|
// Doc failed to load because the socket function timed out.
|
|
|
|
if (aStatus == NS_ERROR_NET_TIMEOUT) {
|
|
|
|
// throw a timeout dialog
|
|
|
|
rv = InitDialogVars();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsXPIDLString messageStr;
|
|
|
|
nsAutoString name("netTimeout");
|
|
|
|
rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-25 02:47:58 +00:00
|
|
|
errorMsg = messageStr;
|
|
|
|
errorMsg.Append(' ');
|
|
|
|
errorMsg.Append(host);
|
|
|
|
errorMsg.Append('.');
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2000-01-25 02:47:58 +00:00
|
|
|
(void)mPrompter->Alert(errorMsg.GetUnicode());
|
|
|
|
} // end NS_ERROR_NET_TIMEOUT
|
|
|
|
} // end mDocLoader == loader
|
1999-06-14 22:11:47 +00:00
|
|
|
} //!mProcessedEndDocumentLoad
|
1999-05-03 23:04:50 +00:00
|
|
|
else {
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-06 21:01:04 +00:00
|
|
|
return rv;
|
1999-03-29 09:21:01 +00:00
|
|
|
}
|
|
|
|
|
1999-01-14 06:44:23 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::OnStartURLLoad(nsIDocumentLoader* loader,
|
1999-12-29 07:32:59 +00:00
|
|
|
nsIChannel* channel)
|
1999-01-14 06:44:23 +00:00
|
|
|
{
|
1999-06-28 10:35:57 +00:00
|
|
|
nsresult rv;
|
1999-09-15 00:23:40 +00:00
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-06 21:01:04 +00:00
|
|
|
|
1999-09-15 19:33:46 +00:00
|
|
|
|
1999-07-07 10:47:35 +00:00
|
|
|
// Stop loading of the earlier document completely when the document url
|
|
|
|
// load starts. Now we know that this url is valid and available.
|
2000-03-11 02:57:39 +00:00
|
|
|
PRBool equals = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(aURL->Equals(mCurrentURI, &equals)) && equals)
|
2000-03-11 01:05:08 +00:00
|
|
|
Stop();
|
1999-07-07 10:47:35 +00:00
|
|
|
|
1999-04-06 21:01:04 +00:00
|
|
|
/*
|
|
|
|
*Fire the OnStartDocumentLoad of the webshell observer
|
|
|
|
*/
|
|
|
|
if ((nsnull != mContainer) && (nsnull != mDocLoaderObserver))
|
|
|
|
{
|
1999-12-29 07:32:59 +00:00
|
|
|
mDocLoaderObserver->OnStartURLLoad(mDocLoader, channel);
|
1999-04-06 21:01:04 +00:00
|
|
|
}
|
1999-01-14 06:44:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-29 09:21:01 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::OnProgressURLLoad(nsIDocumentLoader* loader,
|
|
|
|
nsIChannel* channel,
|
|
|
|
PRUint32 aProgress,
|
1999-03-29 09:21:01 +00:00
|
|
|
PRUint32 aProgressMax)
|
|
|
|
{
|
1999-04-06 21:01:04 +00:00
|
|
|
/*
|
|
|
|
*Fire the OnStartDocumentLoad of the webshell observer and container...
|
|
|
|
*/
|
|
|
|
if ((nsnull != mContainer) && (nsnull != mDocLoaderObserver))
|
|
|
|
{
|
1999-06-28 10:35:57 +00:00
|
|
|
mDocLoaderObserver->OnProgressURLLoad(mDocLoader, channel, aProgress, aProgressMax);
|
1999-04-06 21:01:04 +00:00
|
|
|
}
|
|
|
|
|
1999-03-29 09:21:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::OnStatusURLLoad(nsIDocumentLoader* loader,
|
|
|
|
nsIChannel* channel,
|
1999-04-28 06:47:40 +00:00
|
|
|
nsString& aMsg)
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
1999-04-06 21:01:04 +00:00
|
|
|
/*
|
|
|
|
*Fire the OnStartDocumentLoad of the webshell observer and container...
|
|
|
|
*/
|
|
|
|
if ((nsnull != mContainer) && (nsnull != mDocLoaderObserver))
|
|
|
|
{
|
1999-06-28 10:35:57 +00:00
|
|
|
mDocLoaderObserver->OnStatusURLLoad(mDocLoader, channel, aMsg);
|
1999-04-06 21:01:04 +00:00
|
|
|
}
|
|
|
|
|
1999-03-29 09:21:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::OnEndURLLoad(nsIDocumentLoader* loader,
|
1999-08-05 01:28:30 +00:00
|
|
|
nsIChannel* channel,
|
|
|
|
nsresult aStatus)
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
1999-04-30 00:09:52 +00:00
|
|
|
#if 0
|
1999-12-19 18:32:21 +00:00
|
|
|
const char* spec;
|
1999-04-30 00:09:52 +00:00
|
|
|
aURL->GetSpec(&spec);
|
|
|
|
printf("nsWebShell::OnEndURLLoad:%p: loader=%p url=%s status=%d\n", this, loader, spec, aStatus);
|
|
|
|
#endif
|
1999-04-06 21:01:04 +00:00
|
|
|
/*
|
1999-10-13 10:24:12 +00:00
|
|
|
*Fire the OnEndDocumentLoad of the webshell observer
|
1999-04-06 21:01:04 +00:00
|
|
|
*/
|
|
|
|
if ((nsnull != mContainer) && (nsnull != mDocLoaderObserver))
|
|
|
|
{
|
1999-06-28 10:35:57 +00:00
|
|
|
mDocLoaderObserver->OnEndURLLoad(mDocLoader, channel, aStatus);
|
1999-04-06 21:01:04 +00:00
|
|
|
}
|
1999-03-29 09:21:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-14 06:44:23 +00:00
|
|
|
|
1998-08-18 23:25:17 +00:00
|
|
|
/* For use with redirect/refresh url api */
|
1999-09-06 22:59:11 +00:00
|
|
|
class refreshData : public nsITimerCallback
|
1998-09-25 22:25:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
refreshData();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsITimerCallback interface
|
2000-01-21 21:56:09 +00:00
|
|
|
NS_IMETHOD_(void) Notify(nsITimer *timer);
|
1998-09-25 22:25:21 +00:00
|
|
|
|
|
|
|
nsIWebShell* mShell;
|
|
|
|
nsString mUrlSpec;
|
|
|
|
PRBool mRepeat;
|
|
|
|
PRInt32 mDelay;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~refreshData();
|
1998-08-18 23:25:17 +00:00
|
|
|
};
|
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
refreshData::refreshData()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
mShell = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshData::~refreshData()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(refreshData, kITimerCallbackIID);
|
|
|
|
|
2000-01-21 21:56:09 +00:00
|
|
|
NS_IMETHODIMP_(void) refreshData::Notify(nsITimer *aTimer)
|
1998-09-25 22:25:21 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION((nsnull != mShell), "Null pointer...");
|
|
|
|
if (nsnull != mShell) {
|
1999-06-28 10:35:57 +00:00
|
|
|
mShell->LoadURL(mUrlSpec.GetUnicode(), nsnull, PR_TRUE, nsIChannel::LOAD_NORMAL);
|
1998-09-25 22:25:21 +00:00
|
|
|
}
|
1999-09-06 22:59:11 +00:00
|
|
|
/*
|
1998-09-25 22:25:21 +00:00
|
|
|
* LoadURL(...) will cancel all refresh timers... This causes the Timer and
|
|
|
|
* its refreshData instance to be released...
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-18 23:25:17 +00:00
|
|
|
NS_IMETHODIMP
|
1999-08-03 21:48:40 +00:00
|
|
|
nsWebShell::RefreshURI(nsIURI* aURI, PRInt32 millis, PRBool repeat)
|
1999-05-28 21:32:29 +00:00
|
|
|
{
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-05-28 21:32:29 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-08-03 21:48:40 +00:00
|
|
|
if (nsnull == aURI) {
|
|
|
|
NS_PRECONDITION((aURI != nsnull), "Null pointer");
|
1999-05-28 21:32:29 +00:00
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
char* spec;
|
1999-08-03 21:48:40 +00:00
|
|
|
aURI->GetSpec(&spec);
|
1999-05-28 21:32:29 +00:00
|
|
|
rv = RefreshURL(spec, millis, repeat);
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(spec);
|
1999-09-15 00:23:40 +00:00
|
|
|
|
1999-05-28 21:32:29 +00:00
|
|
|
done:
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-03 21:48:40 +00:00
|
|
|
nsWebShell::RefreshURL(const char* aURI, PRInt32 millis, PRBool repeat)
|
1998-08-18 23:25:17 +00:00
|
|
|
{
|
1998-09-25 22:25:21 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsITimer *timer=nsnull;
|
|
|
|
refreshData *data;
|
|
|
|
|
1999-08-03 21:48:40 +00:00
|
|
|
if (nsnull == aURI) {
|
|
|
|
NS_PRECONDITION((aURI != nsnull), "Null pointer");
|
1998-09-25 22:25:21 +00:00
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto done;
|
|
|
|
}
|
1998-08-18 23:25:17 +00:00
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
NS_NEWXPCOM(data, refreshData);
|
|
|
|
if (nsnull == data) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
1998-08-18 23:25:17 +00:00
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
// Set the reference count to one...
|
|
|
|
NS_ADDREF(data);
|
1998-08-18 23:25:17 +00:00
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
data->mShell = this;
|
|
|
|
NS_ADDREF(data->mShell);
|
|
|
|
|
1999-08-03 21:48:40 +00:00
|
|
|
data->mUrlSpec = aURI;
|
1998-09-25 22:25:21 +00:00
|
|
|
data->mDelay = millis;
|
|
|
|
data->mRepeat = repeat;
|
|
|
|
|
|
|
|
/* Create the timer. */
|
|
|
|
if (NS_OK == NS_NewTimer(&timer)) {
|
|
|
|
/* Add the timer to our array. */
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
mRefreshments.AppendElement(timer);
|
|
|
|
timer->Init(data, millis);
|
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(data);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return rv;
|
1998-08-18 23:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-03 21:48:40 +00:00
|
|
|
nsWebShell::CancelRefreshURITimers(void)
|
1999-05-07 19:25:58 +00:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
1998-09-25 22:25:21 +00:00
|
|
|
nsITimer* timer;
|
1998-08-18 23:25:17 +00:00
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
/* Right now all we can do is cancel all the timers for this webshell. */
|
|
|
|
NS_LOCK_INSTANCE();
|
1998-08-18 23:25:17 +00:00
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
/* Walk the list backwards to avoid copying the array as it shrinks.. */
|
1999-05-07 19:25:58 +00:00
|
|
|
for (i = mRefreshments.Count()-1; (0 <= i); i--) {
|
|
|
|
timer=(nsITimer*)mRefreshments.ElementAt(i);
|
1998-09-25 22:25:21 +00:00
|
|
|
/* Remove the entry from the list before releasing the timer.*/
|
1999-05-07 19:25:58 +00:00
|
|
|
mRefreshments.RemoveElementAt(i);
|
1998-08-18 23:25:17 +00:00
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
if (timer) {
|
|
|
|
timer->Cancel();
|
|
|
|
NS_RELEASE(timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_UNLOCK_INSTANCE();
|
1998-08-20 06:17:47 +00:00
|
|
|
|
1998-09-25 22:25:21 +00:00
|
|
|
return NS_OK;
|
1998-08-18 23:25:17 +00:00
|
|
|
}
|
|
|
|
|
1999-03-18 01:07:22 +00:00
|
|
|
|
1998-07-21 04:46:55 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-03-18 01:07:22 +00:00
|
|
|
/*
|
|
|
|
* There are cases where netlib does things like add a trailing slash
|
|
|
|
* to the url being retrieved. We need to watch out for such
|
|
|
|
* changes and update the currently loading url's entry in the history
|
|
|
|
* list. UpdateHistoryEntry() does this.
|
|
|
|
*
|
1999-09-06 22:59:11 +00:00
|
|
|
* Assumptions:
|
1999-03-18 01:07:22 +00:00
|
|
|
*
|
|
|
|
* 1) aURL is the URL that was inserted into the history list in LoadURL()
|
|
|
|
* 2) The load of aURL is in progress and this function is being called
|
|
|
|
* from one of the functions in nsIStreamListener implemented by nsWebShell.
|
|
|
|
*/
|
1999-06-23 03:29:44 +00:00
|
|
|
nsresult nsWebShell::CheckForTrailingSlash(nsIURI* aURL)
|
1999-03-18 01:07:22 +00:00
|
|
|
{
|
1999-06-15 23:29:38 +00:00
|
|
|
|
1999-06-21 22:17:14 +00:00
|
|
|
PRInt32 curIndex=0;
|
1999-08-28 23:51:12 +00:00
|
|
|
nsresult rv;
|
1999-06-21 22:17:14 +00:00
|
|
|
|
|
|
|
/* Get current history index and url for it */
|
1999-10-12 04:37:43 +00:00
|
|
|
rv = mSHist->GetCurrentIndex(&curIndex);
|
1999-06-21 22:17:14 +00:00
|
|
|
|
|
|
|
/* Get the url that netlib passed us */
|
1999-06-28 10:35:57 +00:00
|
|
|
char* spec;
|
1999-06-21 22:17:14 +00:00
|
|
|
aURL->GetSpec(&spec);
|
1999-10-22 20:48:07 +00:00
|
|
|
|
1999-10-12 04:37:43 +00:00
|
|
|
//Set it in session history
|
1999-11-27 02:14:40 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !mTitle.IsEmpty()) {
|
|
|
|
mSHist->SetTitleForIndex(curIndex, mTitle.GetUnicode());
|
1999-09-06 22:59:11 +00:00
|
|
|
// Replace the top most history entry with the new url
|
1999-10-22 20:48:07 +00:00
|
|
|
mSHist->SetURLForIndex(curIndex, spec);
|
1999-06-21 22:17:14 +00:00
|
|
|
}
|
1999-10-22 20:48:07 +00:00
|
|
|
nsCRT::free(spec);
|
1999-09-21 01:02:29 +00:00
|
|
|
|
1999-10-12 04:37:43 +00:00
|
|
|
|
1999-03-18 01:07:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-23 20:47:57 +00:00
|
|
|
//----------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::CanCutSelection(PRBool* aResult)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
1998-11-04 08:48:22 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
*aResult = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::CanCopySelection(PRBool* aResult)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
1998-11-04 08:48:22 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
*aResult = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::CanPasteSelection(PRBool* aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
*aResult = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::CutSelection(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::CopySelection(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::PasteSelection(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::SelectAll(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
1999-09-01 20:14:02 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer;
|
|
|
|
rv = mContentViewer->QueryInterface(kIDocumentViewerIID,
|
|
|
|
getter_AddRefs(docViewer));
|
|
|
|
if (NS_FAILED(rv) || !docViewer) return rv;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-09-01 20:14:02 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
rv = docViewer->GetPresShell(*getter_AddRefs(presShell));
|
|
|
|
if (NS_FAILED(rv) || !presShell) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMSelection> selection;
|
|
|
|
rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
|
|
|
|
if (NS_FAILED(rv) || !selection) return rv;
|
|
|
|
|
|
|
|
// Get the document object
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
rv = docViewer->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (NS_FAILED(rv) || !doc) return rv;
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmldoc;
|
|
|
|
rv = doc->QueryInterface(kIDOMHTMLDocumentIID, (void**)&htmldoc);
|
|
|
|
if (NS_FAILED(rv) || !htmldoc) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement>bodyElement;
|
|
|
|
rv = htmldoc->GetBody(getter_AddRefs(bodyElement));
|
|
|
|
if (NS_FAILED(rv) || !bodyElement) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
|
|
|
|
if (!bodyNode) return NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
rv = selection->Collapse(bodyNode, 0);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-06 22:59:11 +00:00
|
|
|
|
1999-09-01 20:14:02 +00:00
|
|
|
nsCOMPtr<nsIDOMRange>range;
|
|
|
|
rv = selection->GetRangeAt(0, getter_AddRefs(range));
|
|
|
|
if (NS_FAILED(rv) || !range) return rv;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rv = selection->ClearSelection();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMRange),
|
1999-09-01 20:14:02 +00:00
|
|
|
getter_AddRefs(range));
|
|
|
|
|
|
|
|
rv = range->SelectNodeContents(bodyNode);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = selection->AddRange(range);
|
|
|
|
return rv;
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::SelectNone(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-05-19 00:23:03 +00:00
|
|
|
|
1998-10-23 20:47:57 +00:00
|
|
|
//----------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::FindNext(const PRUnichar * aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-10-13 10:24:12 +00:00
|
|
|
// Methods from nsIProgressEventSink
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::OnProgress(nsIChannel* channel, nsISupports* ctxt,
|
|
|
|
PRUint32 aProgress,
|
|
|
|
PRUint32 aProgressMax)
|
|
|
|
{
|
|
|
|
if (nsnull != mDocLoaderObserver)
|
|
|
|
{
|
|
|
|
return mDocLoaderObserver->OnProgressURLLoad(
|
|
|
|
mDocLoader,
|
|
|
|
channel,
|
|
|
|
aProgress,
|
|
|
|
aProgressMax);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::OnStatus(nsIChannel* channel, nsISupports* ctxt,
|
|
|
|
const PRUnichar* aMsg)
|
|
|
|
{
|
|
|
|
if (nsnull != mDocLoaderObserver)
|
|
|
|
{
|
|
|
|
nsAutoString temp(aMsg);
|
|
|
|
nsresult rv = mDocLoaderObserver->OnStatusURLLoad(
|
|
|
|
mDocLoader,
|
|
|
|
channel,
|
|
|
|
temp);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-23 20:47:57 +00:00
|
|
|
|
2000-01-11 23:11:32 +00:00
|
|
|
#define DIALOG_STRING_URI "chrome://global/locale/appstrings.properties"
|
|
|
|
|
|
|
|
nsresult nsWebShell::InitDialogVars(void)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!mPrompter) {
|
|
|
|
// Get an nsIPrompt so we can throw dialogs.
|
|
|
|
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
|
|
|
|
GetTopLevelWindow(getter_AddRefs(topLevelWindow));
|
|
|
|
if (topLevelWindow)
|
|
|
|
mPrompter = do_QueryInterface(topLevelWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mStringBundle) {
|
|
|
|
// Get a string bundle so we can retrieve dialog strings
|
|
|
|
nsCOMPtr<nsILocale> locale;
|
|
|
|
NS_WITH_SERVICE(nsILocaleService, localeServ, kLocaleServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = localeServ->GetSystemLocale(getter_AddRefs(locale));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIStringBundleService, service, kCStringBundleServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = service->CreateBundle(DIALOG_STRING_URI, locale, getter_AddRefs(mStringBundle));
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-27 02:14:40 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsWebShell::nsIBaseWindow
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::Create()
|
|
|
|
{
|
2000-03-11 01:05:08 +00:00
|
|
|
// Cache the PL_EventQueue of the current UI thread...
|
|
|
|
//
|
|
|
|
// Since this call must be made on the UI thread, we know the Event Queue
|
|
|
|
// will be associated with the current thread...
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIEventQueueService> eventService(do_GetService(kEventQueueServiceCID));
|
|
|
|
NS_ENSURE_TRUE(eventService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(eventService->GetThreadEventQueue(NS_CURRENT_THREAD,
|
|
|
|
&mThreadEventQueue), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
//XXX make sure plugins have started up. this really needs to
|
|
|
|
//be associated with the nsIContentViewerContainer interfaces,
|
|
|
|
//not the nsIWebShell interfaces. this is a hack. MMP
|
|
|
|
CreatePluginHost(mAllowPlugins);
|
|
|
|
|
|
|
|
WEB_TRACE(WEB_TRACE_CALLS,
|
|
|
|
("nsWebShell::Init: this=%p", this));
|
|
|
|
|
|
|
|
// HACK....force the uri loader to give us a load cookie for this webshell...then get it's
|
|
|
|
// doc loader and store it...as more of the docshell lands, we'll be able to get rid
|
|
|
|
// of this hack...
|
|
|
|
nsCOMPtr<nsIURILoader> uriLoader = do_GetService(NS_URI_LOADER_PROGID);
|
|
|
|
uriLoader->GetDocumentLoaderForContext(NS_STATIC_CAST( nsISupports*, (nsIWebShell *) this), &mDocLoader);
|
|
|
|
|
|
|
|
// Set the webshell as the default IContentViewerContainer for the loader...
|
|
|
|
mDocLoader->SetContainer(NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this));
|
|
|
|
|
|
|
|
//Register ourselves as an observer for the new doc loader
|
|
|
|
mDocLoader->AddObserver((nsIDocumentLoaderObserver*)this);
|
|
|
|
|
2000-02-14 06:48:39 +00:00
|
|
|
return nsDocShell::Create();
|
1999-11-27 02:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::Destroy()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-02-15 22:55:36 +00:00
|
|
|
if (!mFiredUnloadEvent) {
|
|
|
|
//Fire unload event before we blow anything away.
|
|
|
|
rv = FireUnloadEvent();
|
1999-11-27 02:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop any URLs that are currently being loaded...
|
|
|
|
Stop();
|
|
|
|
mDocLoader->Destroy();
|
|
|
|
|
|
|
|
SetContainer(nsnull);
|
|
|
|
SetDocLoaderObserver(nsnull);
|
|
|
|
|
2000-03-11 01:05:08 +00:00
|
|
|
// Remove this docshell from its parent's child list
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellParentAsNode(do_QueryInterface(mParent));
|
1999-11-30 04:32:09 +00:00
|
|
|
|
2000-03-11 01:05:08 +00:00
|
|
|
if (docShellParentAsNode) {
|
|
|
|
docShellParentAsNode->RemoveChild(this);
|
1999-11-27 02:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mDocLoader) {
|
|
|
|
mDocLoader->SetContainer(nsnull);
|
|
|
|
}
|
|
|
|
|
1999-12-18 02:29:57 +00:00
|
|
|
mContentViewer = nsnull;
|
1999-11-27 02:14:40 +00:00
|
|
|
|
|
|
|
// Destroy our child web shells and release references to them
|
|
|
|
DestroyChildren();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx,
|
|
|
|
PRInt32 cy, PRBool fRepaint)
|
|
|
|
{
|
2000-03-11 01:05:08 +00:00
|
|
|
mBounds.SetRect(x, y, cx, cy);
|
|
|
|
return nsDocShell::SetPositionAndSize(x, y, cx, cy, fRepaint);
|
1999-12-02 09:43:07 +00:00
|
|
|
}
|
2000-03-11 02:57:39 +00:00
|
|
|
|
2000-03-11 01:05:08 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::GetPositionAndSize(PRInt32* x, PRInt32* y,
|
|
|
|
PRInt32* cx, PRInt32* cy)
|
1999-11-27 02:14:40 +00:00
|
|
|
{
|
2000-03-11 01:05:08 +00:00
|
|
|
if(x)
|
|
|
|
*x = mBounds.x;
|
|
|
|
if(y)
|
|
|
|
*y = mBounds.y;
|
|
|
|
if(cx)
|
|
|
|
*cx = mBounds.width;
|
|
|
|
if(cy)
|
|
|
|
*cy = mBounds.height;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-27 02:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-30 04:32:09 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsWebShell::nsIDocShell
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::SetDocument(nsIDOMDocument *aDOMDoc,
|
|
|
|
nsIDOMElement *aRootNode)
|
|
|
|
{
|
|
|
|
// The tricky part is bypassing the normal load process and just putting a document into
|
|
|
|
// the webshell. This is particularly nasty, since webshells don't normally even know
|
|
|
|
// about their documents
|
|
|
|
|
|
|
|
// (1) Create a document viewer
|
|
|
|
nsCOMPtr<nsIContentViewer> documentViewer;
|
|
|
|
nsCOMPtr<nsIDocumentLoaderFactory> docFactory;
|
|
|
|
static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID);
|
|
|
|
NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDocumentLoaderFactory),
|
1999-11-30 04:32:09 +00:00
|
|
|
(void**)getter_AddRefs(docFactory)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
|
|
|
|
if (!doc) { return NS_ERROR_NULL_POINTER; }
|
|
|
|
|
1999-12-18 02:29:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(docFactory->CreateInstanceForDocument(NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this),
|
1999-11-30 04:32:09 +00:00
|
|
|
doc,
|
|
|
|
"view",
|
|
|
|
getter_AddRefs(documentViewer)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// (2) Feed the webshell to the content viewer
|
|
|
|
NS_ENSURE_SUCCESS(documentViewer->SetContainer((nsIWebShell*)this), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// (3) Tell the content viewer container to embed the content viewer.
|
|
|
|
// (This step causes everything to be set up for an initial flow.)
|
2000-03-11 01:05:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(SetupNewViewer(documentViewer), NS_ERROR_FAILURE);
|
1999-11-30 04:32:09 +00:00
|
|
|
|
|
|
|
// XXX: It would be great to get rid of this dummy channel!
|
|
|
|
const nsAutoString uriString = "about:blank";
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), uriString), NS_ERROR_FAILURE);
|
|
|
|
if (!uri) { return NS_ERROR_OUT_OF_MEMORY; }
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> dummyChannel;
|
|
|
|
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// (4) fire start document load notification
|
1999-12-09 07:21:34 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> outStreamListener; // a valid pointer is required for the returned stream listener
|
|
|
|
// XXX: warning: magic cookie! should get string "view delayedContentLoad"
|
|
|
|
// from somewhere, maybe nsIHTMLDocument?
|
1999-12-18 02:29:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(doc->StartDocumentLoad("view delayedContentLoad", dummyChannel, nsnull, NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this),
|
1999-12-09 07:21:34 +00:00
|
|
|
getter_AddRefs(outStreamListener)),
|
1999-11-30 04:32:09 +00:00
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(OnStartDocumentLoad(mDocLoader, uri, "load"), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// (5) hook up the document and its content
|
|
|
|
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(aRootNode);
|
|
|
|
if (!doc) { return NS_ERROR_OUT_OF_MEMORY; }
|
|
|
|
NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE), NS_ERROR_FAILURE);
|
|
|
|
doc->SetRootContent(rootContent);
|
|
|
|
rootContent->SetDocument(doc, PR_TRUE);
|
|
|
|
|
|
|
|
// (6) reflow the document
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 ns = doc->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> shell(dont_AddRef(doc->GetShellAt(i)));
|
|
|
|
if (shell)
|
|
|
|
{
|
|
|
|
// Make shell an observer for next time
|
|
|
|
NS_ENSURE_SUCCESS(shell->BeginObservingDocument(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Resize-reflow this time
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(documentViewer);
|
|
|
|
if (!docViewer) { return NS_ERROR_OUT_OF_MEMORY; }
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE);
|
|
|
|
if (!presContext) { return NS_ERROR_OUT_OF_MEMORY; }
|
|
|
|
float p2t;
|
|
|
|
presContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
|
|
|
|
nsRect r;
|
1999-12-18 02:29:57 +00:00
|
|
|
GetPositionAndSize(&r.x, &r.y, &r.width, &r.height);
|
1999-11-30 04:32:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(shell->InitialReflow(NSToCoordRound(r.width * p2t), NSToCoordRound(r.height * p2t)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Now trigger a refresh
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE);
|
|
|
|
if (vm)
|
|
|
|
{
|
|
|
|
PRBool enabled;
|
|
|
|
documentViewer->GetEnableRendering(&enabled);
|
|
|
|
if (enabled) {
|
2000-02-09 15:48:01 +00:00
|
|
|
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
|
1999-11-30 04:32:09 +00:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(vm->SetWindowDimensions(NSToCoordRound(r.width * p2t),
|
|
|
|
NSToCoordRound(r.height * p2t)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// (7) fire end document load notification
|
2000-02-16 07:30:17 +00:00
|
|
|
mProcessedEndDocumentLoad = PR_FALSE;
|
1999-11-30 04:32:09 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-12-29 07:32:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(OnEndDocumentLoad(mDocLoader, dummyChannel, rv), NS_ERROR_FAILURE);
|
1999-11-30 04:32:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // test the resulting out-param separately
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-29 06:06:25 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::GetParentContentListener(nsIURIContentListener** aParent)
|
|
|
|
{
|
|
|
|
return GetParentURIContentListener(aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::SetParentContentListener(nsIURIContentListener* aParent)
|
|
|
|
{
|
|
|
|
return SetParentURIContentListener(aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::GetLoadCookie(nsISupports ** aLoadCookie)
|
1999-11-30 04:32:09 +00:00
|
|
|
{
|
2000-01-29 06:06:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
return mContentListener->GetLoadCookie(aLoadCookie);
|
1999-11-30 04:32:09 +00:00
|
|
|
}
|
|
|
|
|
2000-01-29 06:06:25 +00:00
|
|
|
NS_IMETHODIMP nsWebShell::SetLoadCookie(nsISupports * aLoadCookie)
|
1999-11-30 04:32:09 +00:00
|
|
|
{
|
2000-01-29 06:06:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
return mContentListener->SetLoadCookie(aLoadCookie);
|
1999-11-30 04:32:09 +00:00
|
|
|
}
|
|
|
|
|
1998-08-20 06:17:47 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
// Factory code for creating nsWebShell's
|
|
|
|
|
|
|
|
class nsWebShellFactory : public nsIFactory
|
1998-07-19 01:18:40 +00:00
|
|
|
{
|
1998-07-18 21:43:02 +00:00
|
|
|
public:
|
1998-07-19 01:18:40 +00:00
|
|
|
nsWebShellFactory();
|
1998-07-24 21:03:33 +00:00
|
|
|
virtual ~nsWebShellFactory();
|
1998-07-19 01:18:40 +00:00
|
|
|
|
1999-12-01 03:41:43 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
1998-07-18 21:43:02 +00:00
|
|
|
|
|
|
|
// nsIFactory methods
|
|
|
|
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult);
|
|
|
|
|
|
|
|
NS_IMETHOD LockFactory(PRBool aLock);
|
1998-07-19 01:18:40 +00:00
|
|
|
};
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1998-07-19 01:18:40 +00:00
|
|
|
nsWebShellFactory::nsWebShellFactory()
|
|
|
|
{
|
1999-12-01 03:41:43 +00:00
|
|
|
NS_INIT_REFCNT();
|
1998-07-19 01:18:40 +00:00
|
|
|
}
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1998-07-19 01:18:40 +00:00
|
|
|
nsWebShellFactory::~nsWebShellFactory()
|
|
|
|
{
|
|
|
|
}
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1999-10-08 01:49:06 +00:00
|
|
|
NS_IMPL_ADDREF(nsWebShellFactory);
|
|
|
|
NS_IMPL_RELEASE(nsWebShellFactory);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1999-11-24 09:40:56 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsWebShellFactory)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFactory)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
nsresult
|
|
|
|
nsWebShellFactory::CreateInstance(nsISupports *aOuter,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
1998-07-19 01:18:40 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsWebShell *inst;
|
|
|
|
|
1999-12-01 03:41:43 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_NO_AGGREGATION(aOuter);
|
1998-07-18 21:43:02 +00:00
|
|
|
*aResult = NULL;
|
|
|
|
|
1998-09-17 21:27:22 +00:00
|
|
|
NS_NEWXPCOM(inst, nsWebShell);
|
1999-12-01 03:41:43 +00:00
|
|
|
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1998-07-19 01:18:40 +00:00
|
|
|
NS_ADDREF(inst);
|
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(inst);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
1998-07-19 01:18:40 +00:00
|
|
|
return rv;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsWebShellFactory::LockFactory(PRBool aLock)
|
|
|
|
{
|
|
|
|
// Not implemented in simplest case.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_WEB nsresult
|
1998-07-19 01:18:40 +00:00
|
|
|
NS_NewWebShellFactory(nsIFactory** aFactory)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1998-07-19 01:18:40 +00:00
|
|
|
nsIFactory* inst = new nsWebShellFactory();
|
|
|
|
if (nsnull == inst) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
1998-07-19 01:18:40 +00:00
|
|
|
else {
|
|
|
|
NS_ADDREF(inst);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
1998-07-19 01:18:40 +00:00
|
|
|
*aFactory = inst;
|
1998-07-18 21:43:02 +00:00
|
|
|
return rv;
|
|
|
|
}
|