2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-07-18 21:43:02 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +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
|
|
|
*
|
2001-09-28 20:14:13 +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.
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2000-03-11 01:05:08 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* Travis Bogard <travis@netscape.com>
|
2001-05-10 02:35:00 +00:00
|
|
|
* Dan Rosen <dr@netscape.com>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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
|
2000-07-19 13:36:35 +00:00
|
|
|
|
1999-12-18 02:29:57 +00:00
|
|
|
#include "nsDocShell.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#include "nsIWebShell.h"
|
2000-07-18 23:13:07 +00:00
|
|
|
#include "nsWebShell.h"
|
2000-02-14 09:16:26 +00:00
|
|
|
#include "nsIWebBrowserChrome.h"
|
1999-11-13 04:06:23 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-12-20 23:18:03 +00:00
|
|
|
#include "nsIWebProgress.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#include "nsIDocumentLoader.h"
|
2000-01-29 06:06:25 +00:00
|
|
|
#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 "nsIDNSService.h"
|
2001-12-11 23:01:08 +00:00
|
|
|
#include "nsISocketProvider.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"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
1998-08-12 04:56:40 +00:00
|
|
|
#include "nsIPresContext.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-01-05 09:46:33 +00:00
|
|
|
#include "nsIEventQueueService.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsString.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
#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 "nsIPluginManager.h"
|
2001-12-19 15:58:58 +00:00
|
|
|
#include "nsCDefaultURIFixup.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"
|
2001-06-19 00:28:10 +00:00
|
|
|
#include "prthread.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 "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-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-09-01 01:54:35 +00:00
|
|
|
#include "nsIDOMWindowInternal.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"
|
2000-04-02 01:19:27 +00:00
|
|
|
#include "nsILayoutHistoryState.h"
|
2000-05-18 21:52:23 +00:00
|
|
|
#include "nsTextFormatter.h"
|
2000-11-16 20:08:48 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2002-02-02 05:13:56 +00:00
|
|
|
#include "nsPICommandUpdater.h"
|
2000-11-16 20:08:48 +00:00
|
|
|
#include "nsIController.h"
|
|
|
|
#include "nsIFocusController.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
2001-04-13 22:20:33 +00:00
|
|
|
#include "nsIFileStream.h"
|
2001-09-22 00:10:58 +00:00
|
|
|
#include "nsISHistoryInternal.h"
|
1998-07-27 18:17:07 +00:00
|
|
|
|
2002-09-25 20:15:17 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIUploadChannel.h"
|
2000-01-29 06:06:25 +00:00
|
|
|
|
1999-09-13 18:38:02 +00:00
|
|
|
#include "nsILocaleService.h"
|
2000-01-11 23:11:32 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2000-01-12 22:54:07 +00:00
|
|
|
|
2001-04-13 22:20:33 +00:00
|
|
|
#include "nsICachingChannel.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"
|
2001-07-24 22:37:40 +00:00
|
|
|
#include "nsITextToSubURI.h"
|
1998-07-18 21:43:02 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
/**
|
|
|
|
* Note: the log module is created during initialization which
|
|
|
|
* means that you cannot perform logging before then.
|
|
|
|
*/
|
|
|
|
static PRLogModuleInfo* gLogModule = PR_NewLogModule("webshell");
|
|
|
|
#endif
|
1999-07-04 23:40:15 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#define WEB_TRACE_CALLS 0x1
|
|
|
|
#define WEB_TRACE_HISTORY 0x2
|
1998-07-18 21:43:02 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#define WEB_LOG_TEST(_lm,_bit) (PRIntn((_lm)->level) & (_bit))
|
2000-10-27 22:43:51 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#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-07-18 21:43:02 +00:00
|
|
|
|
2000-09-20 12:23:53 +00:00
|
|
|
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
1999-06-07 21:26:10 +00:00
|
|
|
|
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);
|
1999-09-01 20:14:02 +00:00
|
|
|
static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID);
|
1998-07-18 21:43:02 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2002-09-15 23:40:43 +00:00
|
|
|
static PRBool
|
|
|
|
IsOffline()
|
|
|
|
{
|
2002-09-16 06:51:28 +00:00
|
|
|
PRBool offline = PR_TRUE;
|
2002-09-15 23:40:43 +00:00
|
|
|
nsCOMPtr<nsIIOService> ios(do_GetIOService());
|
|
|
|
if (ios)
|
|
|
|
ios->GetOffline(&offline);
|
|
|
|
return offline;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
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
|
|
|
{
|
2000-09-11 22:06:52 +00:00
|
|
|
#ifdef DEBUG
|
1999-09-06 22:59:11 +00:00
|
|
|
// We're counting the number of |nsWebShells| to help find leaks
|
|
|
|
++gNumberOfWebShells;
|
2000-10-28 22:17:53 +00:00
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("WEBSHELL+ = %ld\n", gNumberOfWebShells);
|
2000-10-28 04:09:10 +00:00
|
|
|
#endif
|
1999-08-27 12:32:20 +00:00
|
|
|
|
2002-09-07 17:13:19 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
2001-06-19 00:28:10 +00:00
|
|
|
mThread = nsnull;
|
2000-02-29 06:51:48 +00:00
|
|
|
InitFrameData();
|
1999-12-08 04:57:23 +00:00
|
|
|
mItemType = typeContent;
|
1999-09-23 03:27:53 +00:00
|
|
|
mCharsetReloadState = eCharsetReloadInit;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWebShell::~nsWebShell()
|
|
|
|
{
|
2000-04-13 03:11:25 +00:00
|
|
|
Destroy();
|
1999-06-07 21:26:10 +00:00
|
|
|
|
1998-07-23 04:24:36 +00:00
|
|
|
// Stop any pending document loads and destroy the loader...
|
2002-09-24 00:35:51 +00:00
|
|
|
if (mDocLoader) {
|
1998-08-01 06:45:43 +00:00
|
|
|
mDocLoader->Stop();
|
1999-01-14 06:44:23 +00:00
|
|
|
mDocLoader->SetContainer(nsnull);
|
2000-06-19 05:54:37 +00:00
|
|
|
mDocLoader->Destroy();
|
2002-09-24 00:35:51 +00:00
|
|
|
mDocLoader = nsnull;
|
1998-08-01 06:45:43 +00:00
|
|
|
}
|
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-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
|
|
|
|
2000-09-11 22:06:52 +00:00
|
|
|
#ifdef DEBUG
|
1999-09-06 22:59:11 +00:00
|
|
|
// We're counting the number of |nsWebShells| to help find leaks
|
|
|
|
--gNumberOfWebShells;
|
2000-10-28 22:17:53 +00:00
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("WEBSHELL- = %ld\n", gNumberOfWebShells);
|
2000-10-28 04:09:10 +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
|
|
|
}
|
|
|
|
|
2002-02-02 05:13:56 +00:00
|
|
|
nsresult
|
|
|
|
nsWebShell::EnsureCommandHandler()
|
|
|
|
{
|
|
|
|
if (!mCommandManager)
|
|
|
|
{
|
|
|
|
mCommandManager = do_CreateInstance("@mozilla.org/embedcomp/command-manager;1");
|
|
|
|
if (!mCommandManager) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsCOMPtr<nsPICommandUpdater> commandUpdater = do_QueryInterface(mCommandManager);
|
|
|
|
if (!commandUpdater) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(NS_STATIC_CAST(nsIInterfaceRequestor *, this));
|
|
|
|
nsresult rv = commandUpdater->Init(domWindow);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Initting command manager failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return mCommandManager ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebShell)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebShellServices)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebShellContainer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsILinkHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIClipboardCommands)
|
2000-03-05 21:26:01 +00:00
|
|
|
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-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;
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
else if(aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) ||
|
|
|
|
aIID.Equals(NS_GET_IID(nsIDOMWindow)))
|
|
|
|
|
2000-02-08 13:40:10 +00:00
|
|
|
{
|
2000-02-14 06:48:39 +00:00
|
|
|
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(aIID, aInstancePtr),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-02-08 13:40:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-02-02 05:13:56 +00:00
|
|
|
else if(aIID.Equals(NS_GET_IID(nsICommandManager)))
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(EnsureCommandHandler(), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(mCommandManager->QueryInterface(NS_GET_IID(nsICommandManager),
|
|
|
|
aInstancePtr), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
|
nsWebShell::SetContainer(nsIWebShellContainer* aContainer)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mContainer);
|
|
|
|
mContainer = aContainer;
|
1999-11-18 07:06:39 +00:00
|
|
|
NS_IF_ADDREF(mContainer);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-06-14 22:11:47 +00:00
|
|
|
|
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;
|
2002-09-24 00:35:51 +00:00
|
|
|
if (!mDocLoader)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
NS_ADDREF(aResult);
|
|
|
|
return NS_OK;
|
1998-07-18 21:43:02 +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,
|
2001-12-26 03:17:59 +00:00
|
|
|
PRInt32 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
|
|
|
{
|
2001-12-26 03:17:59 +00:00
|
|
|
PRInt32 hint;
|
|
|
|
muDV->GetHintCharacterSetSource(&hint);
|
1999-11-19 07:35:27 +00:00
|
|
|
if( aSource > hint )
|
|
|
|
{
|
2001-06-30 11:02:25 +00:00
|
|
|
muDV->SetHintCharacterSet(NS_ConvertASCIItoUCS2(aCharset).get());
|
2001-12-26 03:17:59 +00:00
|
|
|
muDV->SetHintCharacterSetSource(aSource);
|
1999-11-19 07:35:27 +00:00
|
|
|
if(eCharsetReloadRequested != mCharsetReloadState)
|
|
|
|
{
|
|
|
|
mCharsetReloadState = eCharsetReloadRequested;
|
2001-11-30 22:35:33 +00:00
|
|
|
LoadURI(NS_ConvertASCIItoUCS2(aURL).get(), // URI string
|
|
|
|
LOAD_FLAGS_NONE, // Load flags
|
|
|
|
nsnull, // Refering URI
|
|
|
|
nsnull, // Post data stream
|
|
|
|
nsnull); // Header stream
|
1999-11-19 07:35:27 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-23 03:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-06 01:58:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-06-29 22:12:14 +00:00
|
|
|
//This functions is only called when a new charset is detected in loading a document.
|
|
|
|
//Its name should be changed to "CharsetReloadDocument"
|
1999-09-06 22:59:11 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::ReloadDocument(const char* aCharset,
|
2001-12-26 03:17:59 +00:00
|
|
|
PRInt32 aSource)
|
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)
|
|
|
|
{
|
2001-12-26 03:17:59 +00:00
|
|
|
PRInt32 hint;
|
|
|
|
muDV->GetHintCharacterSetSource(&hint);
|
1999-11-19 07:35:27 +00:00
|
|
|
if( aSource > hint )
|
|
|
|
{
|
2001-06-30 11:02:25 +00:00
|
|
|
muDV->SetHintCharacterSet(NS_ConvertASCIItoUCS2(aCharset).get());
|
2001-12-26 03:17:59 +00:00
|
|
|
muDV->SetHintCharacterSetSource(aSource);
|
2001-07-02 22:36:08 +00:00
|
|
|
if(eCharsetReloadRequested != mCharsetReloadState)
|
|
|
|
{
|
|
|
|
mCharsetReloadState = eCharsetReloadRequested;
|
|
|
|
return Reload(LOAD_FLAGS_CHARSET_CHANGE);
|
|
|
|
}
|
1999-11-19 07:35:27 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-23 03:27:53 +00:00
|
|
|
}
|
2001-09-21 02:38:37 +00:00
|
|
|
//return failer if this request is not accepted due to mCharsetReloadState
|
|
|
|
return NS_ERROR_WEBSHELL_REQUEST_REJECTED;
|
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)
|
|
|
|
{
|
2001-09-21 02:38:37 +00:00
|
|
|
Stop(nsIWebNavigation::STOP_ALL);
|
|
|
|
return NS_OK;
|
1999-09-23 03:27:53 +00:00
|
|
|
}
|
2001-09-21 02:38:37 +00:00
|
|
|
//return failer if this request is not accepted due to mCharsetReloadState
|
|
|
|
return NS_ERROR_WEBSHELL_REQUEST_REJECTED;
|
1999-05-06 01:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::SetRendering(PRBool aRender)
|
|
|
|
{
|
1999-09-23 03:27:53 +00:00
|
|
|
if(eCharsetReloadRequested != mCharsetReloadState)
|
|
|
|
{
|
|
|
|
if (mContentViewer) {
|
|
|
|
mContentViewer->SetEnableRendering(aRender);
|
2001-09-21 02:38:37 +00:00
|
|
|
return NS_OK;
|
1999-09-23 03:27:53 +00:00
|
|
|
}
|
1999-05-07 19:25:58 +00:00
|
|
|
}
|
2001-09-21 02:38:37 +00:00
|
|
|
//return failer if this request is not accepted due to mCharsetReloadState
|
|
|
|
return NS_ERROR_WEBSHELL_REQUEST_REJECTED;
|
1999-05-06 01:58:48 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2002-11-20 00:44:26 +00:00
|
|
|
nsLinkVerb aVerb, nsIURI* aURI,
|
2000-09-05 19:03:56 +00:00
|
|
|
const PRUnichar* aTargetSpec, nsIInputStream* aPostDataStream = 0,
|
|
|
|
nsIInputStream* aHeadersDataStream = 0);
|
1998-07-18 21:43:02 +00:00
|
|
|
~OnLinkClickEvent();
|
|
|
|
|
|
|
|
void HandleEvent() {
|
2002-11-20 00:44:26 +00:00
|
|
|
mHandler->OnLinkClickSync(mContent, mVerb, mURI,
|
2002-03-13 06:08:56 +00:00
|
|
|
mTargetSpec.get(), mPostDataStream,
|
|
|
|
mHeadersDataStream,
|
|
|
|
nsnull, nsnull);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
2002-11-20 00:44:26 +00:00
|
|
|
nsWebShell* mHandler;
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
nsString mTargetSpec;
|
2002-03-13 06:08:56 +00:00
|
|
|
nsCOMPtr<nsIInputStream> mPostDataStream;
|
|
|
|
nsCOMPtr<nsIInputStream> mHeadersDataStream;
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
2002-11-20 00:44:26 +00:00
|
|
|
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,
|
2002-11-20 00:44:26 +00:00
|
|
|
nsIURI* aURI,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aTargetSpec,
|
2000-09-05 19:03:56 +00:00
|
|
|
nsIInputStream* aPostDataStream,
|
|
|
|
nsIInputStream* aHeadersDataStream)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
|
|
|
mHandler = aHandler;
|
|
|
|
NS_ADDREF(aHandler);
|
2002-11-20 00:44:26 +00:00
|
|
|
mURI = aURI;
|
2002-03-13 06:08:56 +00:00
|
|
|
mTargetSpec.Assign(aTargetSpec);
|
1999-08-03 20:51:41 +00:00
|
|
|
mPostDataStream = aPostDataStream;
|
2000-09-05 19:03:56 +00:00
|
|
|
mHeadersDataStream = aHeadersDataStream;
|
1998-11-14 00:21:19 +00:00
|
|
|
mContent = aContent;
|
|
|
|
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);
|
|
|
|
|
2001-06-19 00:28:10 +00:00
|
|
|
nsCOMPtr<nsIEventQueue> eventQueue;
|
|
|
|
aHandler->GetEventQueue(getter_AddRefs(eventQueue));
|
|
|
|
NS_ASSERTION(eventQueue, "no event queue");
|
|
|
|
if (eventQueue)
|
|
|
|
eventQueue->PostEvent(this);
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OnLinkClickEvent::~OnLinkClickEvent()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-06 22:59:11 +00:00
|
|
|
nsWebShell::OnLinkClick(nsIContent* aContent,
|
1998-11-14 00:21:19 +00:00
|
|
|
nsLinkVerb aVerb,
|
2002-11-20 00:44:26 +00:00
|
|
|
nsIURI* aURI,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aTargetSpec,
|
2000-09-05 19:03:56 +00:00
|
|
|
nsIInputStream* aPostDataStream,
|
|
|
|
nsIInputStream* aHeadersDataStream)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
1998-07-24 21:03:33 +00:00
|
|
|
OnLinkClickEvent* ev;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-11-20 00:44:26 +00:00
|
|
|
ev = new OnLinkClickEvent(this, aContent, aVerb, aURI,
|
2000-09-05 19:03:56 +00:00
|
|
|
aTargetSpec, aPostDataStream, aHeadersDataStream);
|
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
|
|
|
}
|
|
|
|
|
2001-06-19 00:28:10 +00:00
|
|
|
nsresult
|
|
|
|
nsWebShell::GetEventQueue(nsIEventQueue **aQueue)
|
1999-01-05 09:46:33 +00:00
|
|
|
{
|
2001-06-19 00:28:10 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aQueue);
|
|
|
|
*aQueue = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEventQueueService> eventService(do_GetService(kEventQueueServiceCID));
|
|
|
|
if (eventService)
|
|
|
|
eventService->GetThreadEventQueue(mThread, aQueue);
|
|
|
|
return *aQueue ? NS_OK : NS_ERROR_FAILURE;
|
1999-01-05 09:46:33 +00:00
|
|
|
}
|
|
|
|
|
2002-03-13 06:08:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::OnLinkClickSync(nsIContent *aContent,
|
|
|
|
nsLinkVerb aVerb,
|
2002-11-20 00:44:26 +00:00
|
|
|
nsIURI* aURI,
|
2002-03-13 06:08:56 +00:00
|
|
|
const PRUnichar* aTargetSpec,
|
|
|
|
nsIInputStream* aPostDataStream,
|
|
|
|
nsIInputStream* aHeadersDataStream,
|
|
|
|
nsIDocShell** aDocShell,
|
|
|
|
nsIRequest** aRequest)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
2001-05-14 02:16:27 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsAutoString target(aTargetSpec);
|
1998-11-14 00:21:19 +00:00
|
|
|
|
2002-03-13 06:08:56 +00:00
|
|
|
// Initialize the DocShell / Request
|
|
|
|
if (aDocShell) {
|
|
|
|
*aDocShell = nsnull;
|
|
|
|
}
|
|
|
|
if (aRequest) {
|
|
|
|
*aRequest = nsnull;
|
|
|
|
}
|
|
|
|
|
1998-11-14 00:21:19 +00:00
|
|
|
switch(aVerb) {
|
|
|
|
case eLinkVerb_New:
|
2001-12-16 11:58:03 +00:00
|
|
|
target.Assign(NS_LITERAL_STRING("_blank"));
|
1998-11-14 00:21:19 +00:00
|
|
|
// Fall into replace case
|
2000-04-01 00:39:15 +00:00
|
|
|
case eLinkVerb_Undefined:
|
|
|
|
// Fall through, this seems like the most reasonable action
|
1999-09-06 22:59:11 +00:00
|
|
|
case eLinkVerb_Replace:
|
1998-11-14 00:21:19 +00:00
|
|
|
{
|
2002-11-20 00:44:26 +00:00
|
|
|
return InternalLoad(aURI, // New URI
|
2002-03-13 06:08:56 +00:00
|
|
|
mCurrentURI, // Referer URI
|
|
|
|
nsnull, // No onwer
|
|
|
|
PR_TRUE, // Inherit owner from document
|
|
|
|
target.get(), // Window target
|
|
|
|
aPostDataStream, // Post data stream
|
|
|
|
aHeadersDataStream, // Headers stream
|
|
|
|
LOAD_LINK, // Load type
|
|
|
|
nsnull, // No SHEntry
|
|
|
|
PR_TRUE, // first party site
|
|
|
|
aDocShell, // DocShell out-param
|
|
|
|
aRequest); // Request out-param
|
1998-11-14 00:21:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eLinkVerb_Embed:
|
2000-04-01 00:39:15 +00:00
|
|
|
// XXX TODO Should be similar to the HTML IMG ALT attribute handling
|
|
|
|
// in NS 4.x
|
1998-11-14 00:21:19 +00:00
|
|
|
default:
|
2000-04-01 00:39:15 +00:00
|
|
|
NS_ABORT_IF_FALSE(0,"unexpected link verb");
|
2002-03-13 06:08:56 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-14 00:21:19 +00:00
|
|
|
nsWebShell::OnOverLink(nsIContent* aContent,
|
2002-11-20 00:44:26 +00:00
|
|
|
nsIURI* aURI,
|
1998-08-14 23:08:54 +00:00
|
|
|
const PRUnichar* aTargetSpec)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
2002-11-20 00:44:26 +00:00
|
|
|
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner));
|
2001-07-24 22:37:40 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2002-11-20 00:44:26 +00:00
|
|
|
if (browserChrome) {
|
2001-07-24 22:37:40 +00:00
|
|
|
nsCOMPtr<nsITextToSubURI> textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-11-20 00:44:26 +00:00
|
|
|
// use url origin charset to unescape the URL
|
|
|
|
nsCAutoString charset;
|
|
|
|
rv = aURI->GetOriginCharset(charset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-16 17:41:48 +00:00
|
|
|
|
2002-11-20 00:44:26 +00:00
|
|
|
nsCAutoString spec;
|
|
|
|
rv = aURI->GetSpec(spec);
|
2002-09-16 17:41:48 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString uStr;
|
2002-11-20 00:44:26 +00:00
|
|
|
rv = textToSubURI->UnEscapeURIForUI(charset, spec, uStr);
|
2002-09-16 17:41:48 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_LINK, uStr.get());
|
2001-07-24 22:37:40 +00:00
|
|
|
}
|
|
|
|
return rv;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
2002-11-20 00:44:26 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::OnLeaveLink()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner));
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (browserChrome) {
|
|
|
|
rv = browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_LINK,
|
|
|
|
NS_LITERAL_STRING("").get());
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-08-15 22:21:40 +00:00
|
|
|
nsresult
|
|
|
|
nsWebShell::NormalizeURI(nsACString& aURLSpec)
|
|
|
|
{
|
|
|
|
nsIURI *uri = nsnull;
|
|
|
|
nsCAutoString scheme;
|
|
|
|
nsresult rv = mIOService->ExtractScheme(aURLSpec, scheme);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// keep tempUri up here to keep it in scope
|
|
|
|
nsCOMPtr<nsIURI> tempUri;
|
|
|
|
|
|
|
|
// used to avoid extra work later
|
|
|
|
PRBool clearUri(PR_TRUE);
|
|
|
|
|
|
|
|
if (scheme.Equals(NS_LITERAL_CSTRING("http"))) {
|
|
|
|
if (mCachedHttpUrl)
|
|
|
|
rv = mCachedHttpUrl->SetSpec(aURLSpec);
|
|
|
|
else
|
|
|
|
rv = NS_NewURI(getter_AddRefs(mCachedHttpUrl), aURLSpec);
|
|
|
|
|
|
|
|
uri = mCachedHttpUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (scheme.Equals(NS_LITERAL_CSTRING("https"))) {
|
|
|
|
if (mCachedHttpsUrl)
|
|
|
|
rv = mCachedHttpsUrl->SetSpec(aURLSpec);
|
|
|
|
else
|
|
|
|
rv = NS_NewURI(getter_AddRefs(mCachedHttpsUrl), aURLSpec);
|
|
|
|
|
|
|
|
uri = mCachedHttpsUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (scheme.Equals(NS_LITERAL_CSTRING("ftp"))) {
|
|
|
|
if (mCachedFtpUrl)
|
|
|
|
rv = mCachedFtpUrl->SetSpec(aURLSpec);
|
|
|
|
else
|
|
|
|
rv = NS_NewURI(getter_AddRefs(mCachedFtpUrl), aURLSpec);
|
|
|
|
|
|
|
|
uri = mCachedFtpUrl;
|
|
|
|
} else {
|
|
|
|
rv = NS_NewURI(getter_AddRefs(tempUri), aURLSpec);
|
|
|
|
uri = tempUri;
|
|
|
|
clearUri = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// covers all above failures
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = uri->GetSpec(aURLSpec);
|
|
|
|
|
|
|
|
// clear out the old spec, for security reasons - old data should
|
|
|
|
// not be floating around in cached URIs!
|
|
|
|
// (but avoid doing extra work if we're just destroying the uri)
|
|
|
|
if (clearUri)
|
|
|
|
uri->SetSpec(NS_LITERAL_CSTRING(""));
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-07-18 21:43:02 +00:00
|
|
|
NS_IMETHODIMP
|
2002-08-06 23:51:42 +00:00
|
|
|
nsWebShell::GetLinkState(const nsACString& aLinkURI, nsLinkState& aState)
|
1998-07-18 21:43:02 +00:00
|
|
|
{
|
2000-05-16 05:35:23 +00:00
|
|
|
aState = eLinkState_Unvisited;
|
1999-05-18 05:21:37 +00:00
|
|
|
|
2002-08-06 23:51:42 +00:00
|
|
|
// no history, leave state unchanged
|
|
|
|
if (!mGlobalHistory)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// default to the given URI
|
|
|
|
nsCAutoString resolvedPath(aLinkURI);
|
|
|
|
nsresult rv;
|
2002-08-15 22:21:40 +00:00
|
|
|
|
2002-08-06 23:51:42 +00:00
|
|
|
// get the cached IO service
|
2002-08-15 22:21:40 +00:00
|
|
|
if (!mIOService)
|
2002-08-15 01:44:51 +00:00
|
|
|
mIOService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
|
|
|
|
2002-08-15 22:21:40 +00:00
|
|
|
NormalizeURI(resolvedPath);
|
2002-08-15 01:44:51 +00:00
|
|
|
|
2002-08-06 23:51:42 +00:00
|
|
|
PRBool isVisited;
|
|
|
|
NS_ENSURE_SUCCESS(mGlobalHistory->IsVisited(resolvedPath.get(), &isVisited),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (isVisited)
|
|
|
|
aState = eLinkState_Visited;
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-07-18 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
2000-12-20 23:18:03 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
|
2001-02-21 20:38:08 +00:00
|
|
|
nsIChannel* channel,
|
2000-12-20 23:18:03 +00:00
|
|
|
nsresult aStatus)
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
2000-12-20 23:18:03 +00:00
|
|
|
nsresult rv = NS_OK;
|
2000-04-21 23:31:41 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
if(!channel)
|
2000-12-20 23:18:03 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2001-02-21 20:38:08 +00:00
|
|
|
|
2000-12-20 23:18:03 +00:00
|
|
|
nsCOMPtr<nsIURI> url;
|
2001-02-21 20:38:08 +00:00
|
|
|
rv = channel->GetURI(getter_AddRefs(url));
|
2000-12-20 23:18:03 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-12-15 21:26:12 +00:00
|
|
|
|
2000-12-20 23:18:03 +00:00
|
|
|
// clean up reload state for meta charset
|
|
|
|
if(eCharsetReloadRequested == mCharsetReloadState)
|
|
|
|
mCharsetReloadState = eCharsetReloadStopOrigional;
|
|
|
|
else
|
|
|
|
mCharsetReloadState = eCharsetReloadInit;
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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);
|
2001-02-21 20:38:08 +00:00
|
|
|
nsDocShell::EndPageLoad(aProgress, channel, aStatus);
|
1999-09-06 22:59:11 +00:00
|
|
|
|
2002-07-11 20:59:03 +00:00
|
|
|
// Test if this is the top frame or a subframe
|
|
|
|
PRBool isTopFrame = PR_TRUE;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> targetParentTreeItem;
|
|
|
|
rv = GetSameTypeParent(getter_AddRefs(targetParentTreeItem));
|
|
|
|
if (NS_SUCCEEDED(rv) && targetParentTreeItem)
|
|
|
|
{
|
|
|
|
isTopFrame = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-12-20 23:18:03 +00:00
|
|
|
//
|
|
|
|
// If the page load failed, then deal with the error condition...
|
|
|
|
// Errors are handled as follows:
|
2001-09-05 03:52:26 +00:00
|
|
|
// 1. Check to see if it a file not found error.
|
|
|
|
// 2. Send the URI to a keyword server (if enabled)
|
|
|
|
// 3. If the error was DNS failure, then add www and .com to the URI
|
2000-12-20 23:18:03 +00:00
|
|
|
// (if appropriate).
|
2001-09-05 03:52:26 +00:00
|
|
|
// 4. Throw an error dialog box...
|
2000-12-20 23:18:03 +00:00
|
|
|
//
|
2001-09-05 03:52:26 +00:00
|
|
|
|
2000-12-20 23:18:03 +00:00
|
|
|
if(url && NS_FAILED(aStatus)) {
|
2001-09-05 03:52:26 +00:00
|
|
|
if (aStatus == NS_ERROR_FILE_NOT_FOUND) {
|
2002-07-11 20:59:03 +00:00
|
|
|
DisplayLoadError(aStatus, url, nsnull);
|
2001-09-05 03:52:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-12-20 23:18:03 +00:00
|
|
|
|
2001-12-19 15:58:58 +00:00
|
|
|
// Create the fixup object if necessary
|
|
|
|
if (!mURIFixup)
|
|
|
|
{
|
|
|
|
mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID);
|
2000-12-20 23:18:03 +00:00
|
|
|
}
|
|
|
|
|
2001-12-19 15:58:58 +00:00
|
|
|
if (mURIFixup)
|
2000-12-20 23:18:03 +00:00
|
|
|
{
|
2001-12-19 15:58:58 +00:00
|
|
|
//
|
|
|
|
// Try and make an alternative URI from the old one
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIURI> newURI;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString oldSpec;
|
|
|
|
url->GetSpec(oldSpec);
|
2002-01-16 03:23:23 +00:00
|
|
|
|
2001-12-19 15:58:58 +00:00
|
|
|
//
|
|
|
|
// First try keyword fixup
|
|
|
|
//
|
|
|
|
if (aStatus == NS_ERROR_UNKNOWN_HOST ||
|
|
|
|
aStatus == NS_ERROR_CONNECTION_REFUSED ||
|
2002-03-14 20:24:15 +00:00
|
|
|
aStatus == NS_ERROR_NET_TIMEOUT ||
|
|
|
|
aStatus == NS_ERROR_NET_RESET)
|
2001-12-19 15:58:58 +00:00
|
|
|
{
|
2002-05-17 01:58:45 +00:00
|
|
|
PRBool keywordsEnabled = PR_FALSE;
|
|
|
|
|
|
|
|
if(mPrefs) {
|
|
|
|
rv = mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString host;
|
|
|
|
url->GetHost(host);
|
|
|
|
|
|
|
|
nsCAutoString scheme;
|
|
|
|
url->GetScheme(scheme);
|
|
|
|
|
|
|
|
PRInt32 dotLoc = host.FindChar('.');
|
|
|
|
|
|
|
|
// we should only perform a keyword search under the following conditions:
|
|
|
|
// (0) Pref keyword.enabled is true
|
|
|
|
// (1) the url scheme is http (or https)
|
|
|
|
// (2) the url does not have a protocol scheme
|
|
|
|
// If we don't enforce such a policy, then we end up doing keyword searchs on urls
|
|
|
|
// we don't intend like imap, file, mailbox, etc. This could lead to a security
|
|
|
|
// problem where we send data to the keyword server that we shouldn't be.
|
|
|
|
// Someone needs to clean up keywords in general so we can determine on a per url basis
|
|
|
|
// if we want keywords enabled...this is just a bandaid...
|
|
|
|
if (keywordsEnabled && !scheme.IsEmpty() &&
|
|
|
|
(scheme.Find("http") != 0)) {
|
|
|
|
keywordsEnabled = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(keywordsEnabled && (-1 == dotLoc)) {
|
|
|
|
// only send non-qualified hosts to the keyword server
|
|
|
|
nsAutoString keywordSpec; keywordSpec.AssignWithConversion("keyword:");
|
|
|
|
keywordSpec.Append(NS_ConvertUTF8toUCS2(host));
|
|
|
|
|
|
|
|
NS_NewURI(getter_AddRefs(newURI), keywordSpec, nsnull);
|
|
|
|
} // end keywordsEnabled
|
2000-04-21 23:31:41 +00:00
|
|
|
}
|
1999-09-06 22:59:11 +00:00
|
|
|
|
2001-12-19 15:58:58 +00:00
|
|
|
//
|
|
|
|
// Now try change the address, e.g. turn http://foo into http://www.foo.com
|
|
|
|
//
|
2002-03-14 20:24:15 +00:00
|
|
|
if (aStatus == NS_ERROR_UNKNOWN_HOST ||
|
|
|
|
aStatus == NS_ERROR_NET_RESET)
|
2001-12-19 15:58:58 +00:00
|
|
|
{
|
|
|
|
PRBool doCreateAlternate = PR_TRUE;
|
2002-07-11 20:59:03 +00:00
|
|
|
|
|
|
|
// Skip fixup for anything except a normal document load operation on
|
|
|
|
// the topframe.
|
|
|
|
|
|
|
|
if (mLoadType != LOAD_NORMAL || !isTopFrame)
|
2002-04-03 11:04:30 +00:00
|
|
|
{
|
|
|
|
doCreateAlternate = PR_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-07-11 20:59:03 +00:00
|
|
|
// Test if keyword lookup produced a new URI or not
|
|
|
|
if (newURI)
|
2002-04-03 11:04:30 +00:00
|
|
|
{
|
2002-07-11 20:59:03 +00:00
|
|
|
PRBool sameURI = PR_FALSE;
|
|
|
|
url->Equals(newURI, &sameURI);
|
|
|
|
if (!sameURI)
|
|
|
|
{
|
|
|
|
// Keyword lookup made a new URI so no need to try an
|
|
|
|
// alternate one.
|
|
|
|
doCreateAlternate = PR_FALSE;
|
|
|
|
}
|
2000-12-20 23:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-19 15:58:58 +00:00
|
|
|
if (doCreateAlternate)
|
|
|
|
{
|
|
|
|
newURI = nsnull;
|
2002-08-06 23:51:42 +00:00
|
|
|
mURIFixup->CreateFixupURI(NS_ConvertUTF8toUCS2(oldSpec),
|
2001-12-19 15:58:58 +00:00
|
|
|
nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI, getter_AddRefs(newURI));
|
|
|
|
}
|
2000-12-20 23:18:03 +00:00
|
|
|
}
|
2000-04-21 23:31:41 +00:00
|
|
|
|
2001-12-19 15:58:58 +00:00
|
|
|
//
|
|
|
|
// Did we make a new URI that is different to the old one? If so load it.
|
|
|
|
//
|
|
|
|
if (newURI)
|
|
|
|
{
|
|
|
|
// Make sure the new URI is different from the old one, otherwise
|
|
|
|
// there's little point trying to load it again.
|
|
|
|
PRBool sameURI = PR_FALSE;
|
|
|
|
url->Equals(newURI, &sameURI);
|
|
|
|
if (!sameURI)
|
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString newSpec;
|
|
|
|
newURI->GetSpec(newSpec);
|
|
|
|
NS_ConvertUTF8toUCS2 newSpecW(newSpec);
|
2001-12-19 15:58:58 +00:00
|
|
|
|
|
|
|
// This seems evil, since it is modifying the original URL
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = url->SetSpec(newSpec);
|
2001-12-19 15:58:58 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return LoadURI(newSpecW.get(), // URI string
|
|
|
|
LOAD_FLAGS_NONE, // Load flags
|
|
|
|
nsnull, // Refering URI
|
|
|
|
nsnull, // Post data stream
|
|
|
|
nsnull); // Headers stream
|
|
|
|
}
|
|
|
|
}
|
2000-12-20 23:18:03 +00:00
|
|
|
}
|
2000-04-21 23:31:41 +00:00
|
|
|
|
2000-12-20 23:18:03 +00:00
|
|
|
//
|
2001-12-19 15:58:58 +00:00
|
|
|
// Well, fixup didn't work :-(
|
2000-12-20 23:18:03 +00:00
|
|
|
// It is time to throw an error dialog box, and be done with it...
|
|
|
|
//
|
2000-01-11 23:11:32 +00:00
|
|
|
|
2002-07-11 20:59:03 +00:00
|
|
|
// Errors to be shown only on top-level frames
|
|
|
|
if ((aStatus == NS_ERROR_UNKNOWN_HOST ||
|
|
|
|
aStatus == NS_ERROR_CONNECTION_REFUSED) &&
|
|
|
|
(isTopFrame || mUseErrorPages)) {
|
|
|
|
DisplayLoadError(aStatus, url, nsnull);
|
2000-12-20 23:18:03 +00:00
|
|
|
}
|
2002-07-11 20:59:03 +00:00
|
|
|
// Errors to be shown for any frame
|
|
|
|
else if (aStatus == NS_ERROR_NET_TIMEOUT ||
|
|
|
|
aStatus == NS_ERROR_REDIRECT_LOOP ||
|
|
|
|
aStatus == NS_ERROR_UNKNOWN_SOCKET_TYPE ||
|
2002-10-14 14:34:40 +00:00
|
|
|
aStatus == NS_ERROR_NET_INTERRUPT ||
|
2002-07-11 20:59:03 +00:00
|
|
|
aStatus == NS_ERROR_NET_RESET) {
|
|
|
|
DisplayLoadError(aStatus, url, nsnull);
|
2000-12-20 23:18:03 +00:00
|
|
|
}
|
2001-04-13 22:20:33 +00:00
|
|
|
else if (aStatus == NS_ERROR_DOCUMENT_NOT_CACHED) {
|
|
|
|
/* A document that was requested to be fetched *only* from
|
|
|
|
* the cache is not in cache. May be this is one of those
|
|
|
|
* postdata results. Throw a dialog to the user,
|
|
|
|
* saying that the page has expired from cache and ask if
|
2002-09-15 23:40:43 +00:00
|
|
|
* they wish to refetch the page from the net. Do this only
|
|
|
|
* if the request is a form post.
|
2001-04-13 22:20:33 +00:00
|
|
|
*/
|
2002-09-15 23:40:43 +00:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
nsCAutoString method;
|
|
|
|
if (httpChannel)
|
|
|
|
httpChannel->GetRequestMethod(method);
|
|
|
|
if (method.Equals("POST") && !IsOffline()) {
|
|
|
|
nsCOMPtr<nsIPrompt> prompter;
|
|
|
|
PRBool repost;
|
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
|
|
|
GetPromptAndStringBundle(getter_AddRefs(prompter),
|
|
|
|
getter_AddRefs(stringBundle));
|
|
|
|
|
|
|
|
if (stringBundle && prompter) {
|
|
|
|
nsXPIDLString messageStr;
|
|
|
|
nsresult rv = stringBundle->GetStringFromName(NS_LITERAL_STRING("repost").get(),
|
|
|
|
getter_Copies(messageStr));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && messageStr) {
|
|
|
|
prompter->Confirm(nsnull, messageStr, &repost);
|
|
|
|
/* If the user pressed cancel in the dialog,
|
|
|
|
* return failure. Don't try to load the page with out
|
|
|
|
* the post data.
|
|
|
|
*/
|
|
|
|
if (!repost)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// The user wants to repost the data to the server.
|
|
|
|
// If the page was loaded due to a back/forward/go
|
|
|
|
// operation, update the session history index.
|
|
|
|
// This is similar to the updating done in
|
|
|
|
// nsDocShell::OnNewURI() for regular pages
|
|
|
|
nsCOMPtr<nsISHistory> rootSH=mSessionHistory;
|
|
|
|
if (!mSessionHistory) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
//Get the root docshell
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
if (root) {
|
|
|
|
// QI root to nsIWebNavigation
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsWebnav(do_QueryInterface(root));
|
|
|
|
if (rootAsWebnav) {
|
|
|
|
// Get the handle to SH from the root docshell
|
|
|
|
rootAsWebnav->GetSessionHistory(getter_AddRefs(rootSH));
|
|
|
|
}
|
2001-09-22 00:10:58 +00:00
|
|
|
}
|
2002-09-15 23:40:43 +00:00
|
|
|
} // mSessionHistory
|
2001-09-22 00:10:58 +00:00
|
|
|
|
2002-09-15 23:40:43 +00:00
|
|
|
if (rootSH && (mLoadType & LOAD_CMD_HISTORY)) {
|
|
|
|
nsCOMPtr<nsISHistoryInternal> shInternal(do_QueryInterface(rootSH));
|
|
|
|
if (shInternal)
|
|
|
|
shInternal->UpdateIndex();
|
2001-04-13 22:20:33 +00:00
|
|
|
}
|
2002-09-15 23:40:43 +00:00
|
|
|
/* The user does want to repost the data to the server.
|
|
|
|
* Initiate a new load again.
|
|
|
|
*/
|
|
|
|
/* Get the postdata if any from the channel */
|
|
|
|
nsCOMPtr<nsIInputStream> inputStream;
|
|
|
|
nsCOMPtr<nsIURI> referrer;
|
|
|
|
if (channel) {
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
|
|
|
|
if(httpChannel) {
|
|
|
|
httpChannel->GetReferrer(getter_AddRefs(referrer));
|
2002-09-25 20:15:17 +00:00
|
|
|
nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(channel));
|
|
|
|
if (uploadChannel) {
|
2002-09-25 20:49:29 +00:00
|
|
|
uploadChannel->GetUploadStream(getter_AddRefs(inputStream));
|
2002-09-25 20:15:17 +00:00
|
|
|
}
|
2002-09-15 23:40:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsISeekableStream> postDataSeekable(do_QueryInterface(inputStream));
|
|
|
|
if (postDataSeekable)
|
|
|
|
{
|
|
|
|
postDataSeekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
|
|
|
}
|
|
|
|
InternalLoad(url, // URI
|
|
|
|
referrer, // Refering URI
|
|
|
|
nsnull, // Owner
|
|
|
|
PR_TRUE, // Inherit owner
|
|
|
|
nsnull, // No window target
|
|
|
|
inputStream, // Post data stream
|
|
|
|
nsnull, // No headers stream
|
|
|
|
LOAD_RELOAD_BYPASS_PROXY_AND_CACHE,// Load type
|
|
|
|
nsnull, // No SHEntry
|
|
|
|
PR_TRUE, // first party site
|
|
|
|
nsnull, // No nsIDocShell
|
|
|
|
nsnull); // No nsIRequest
|
2001-04-13 22:20:33 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-15 23:40:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
DisplayLoadError(aStatus, url, nsnull);
|
|
|
|
}
|
2001-04-13 22:20:33 +00:00
|
|
|
}
|
2000-12-20 23:18:03 +00:00
|
|
|
} // if we have a host
|
1999-03-29 09:21:01 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-14 06:44:23 +00:00
|
|
|
|
2000-11-16 20:08:48 +00:00
|
|
|
//
|
|
|
|
// Routines for selection and clipboard
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
2002-07-15 22:04:13 +00:00
|
|
|
nsWebShell::GetControllerForCommand ( const char * inCommand, nsIController** outController )
|
2000-11-16 20:08:48 +00:00
|
|
|
{
|
2001-04-04 23:48:03 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(outController);
|
|
|
|
*outController = nsnull;
|
|
|
|
|
2000-11-16 20:08:48 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window ( do_QueryInterface(mScriptGlobal) );
|
|
|
|
if ( window ) {
|
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
|
|
|
rv = window->GetRootFocusController ( getter_AddRefs(focusController) );
|
|
|
|
if ( focusController )
|
2001-05-03 10:09:59 +00:00
|
|
|
rv = focusController->GetControllerForCommand ( inCommand, outController );
|
2000-11-16 20:08:48 +00:00
|
|
|
} // if window
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
} // GetControllerForCommand
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2002-07-15 22:04:13 +00:00
|
|
|
nsWebShell::IsCommandEnabled ( const char * inCommand, PRBool* outEnabled )
|
2000-11-16 20:08:48 +00:00
|
|
|
{
|
2001-04-04 23:48:03 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(outEnabled);
|
|
|
|
*outEnabled = PR_FALSE;
|
|
|
|
|
2000-11-16 20:08:48 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
rv = GetControllerForCommand ( inCommand, getter_AddRefs(controller) );
|
|
|
|
if ( controller )
|
2001-04-04 23:48:03 +00:00
|
|
|
rv = controller->IsCommandEnabled(inCommand, outEnabled);
|
2000-11-16 20:08:48 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2002-07-15 22:04:13 +00:00
|
|
|
nsWebShell::DoCommand ( const char * inCommand )
|
2000-11-16 20:08:48 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
rv = GetControllerForCommand ( inCommand, getter_AddRefs(controller) );
|
|
|
|
if ( controller )
|
2001-04-04 23:48:03 +00:00
|
|
|
rv = controller->DoCommand(inCommand);
|
2000-11-16 20:08:48 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return IsCommandEnabled ( "cmd_cut", aResult );
|
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
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return IsCommandEnabled ( "cmd_copy", aResult );
|
2001-05-10 02:35:00 +00:00
|
|
|
}
|
1998-11-04 08:48:22 +00:00
|
|
|
|
2001-05-10 02:35:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::CanCopyLinkLocation(PRBool* aResult)
|
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return IsCommandEnabled ( "cmd_copyLink", aResult );
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-10 02:35:00 +00:00
|
|
|
nsWebShell::CanCopyImageLocation(PRBool* aResult)
|
1998-11-04 08:48:22 +00:00
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return IsCommandEnabled ( "cmd_copyImageLocation",
|
2001-05-10 02:35:00 +00:00
|
|
|
aResult );
|
|
|
|
}
|
1998-11-04 08:48:22 +00:00
|
|
|
|
2001-05-10 02:35:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::CanCopyImageContents(PRBool* aResult)
|
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return IsCommandEnabled ( "cmd_copyImageContents",
|
2001-05-10 02:35:00 +00:00
|
|
|
aResult );
|
|
|
|
}
|
1998-11-04 08:48:22 +00:00
|
|
|
|
2001-05-10 02:35:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::CanPaste(PRBool* aResult)
|
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return IsCommandEnabled ( "cmd_paste", aResult );
|
1998-11-04 08:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::CutSelection(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return DoCommand ( "cmd_cut" );
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::CopySelection(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return DoCommand ( "cmd_copy" );
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-12-22 01:13:46 +00:00
|
|
|
nsWebShell::CopyLinkLocation(void)
|
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return DoCommand ( "cmd_copyLink" );
|
2001-05-10 02:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::CopyImageLocation(void)
|
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return DoCommand ( "cmd_copyImageLocation" );
|
2001-05-10 02:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::CopyImageContents(void)
|
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return DoCommand ( "cmd_copyImageContents" );
|
2000-12-22 01:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShell::Paste(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return DoCommand ( "cmd_paste" );
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-04 08:48:22 +00:00
|
|
|
nsWebShell::SelectAll(void)
|
1998-10-23 20:47:57 +00:00
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return DoCommand ( "cmd_selectAll" );
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
2000-12-22 01:13:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// SelectNone
|
|
|
|
//
|
|
|
|
// Collapses the current selection, insertion point ends up at beginning
|
|
|
|
// of previous selection.
|
|
|
|
//
|
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
|
|
|
{
|
2002-07-15 22:04:13 +00:00
|
|
|
return DoCommand ( "cmd_selectNone" );
|
1998-10-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
1999-05-19 00:23:03 +00:00
|
|
|
|
2000-11-16 20:08:48 +00:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
1999-11-27 02:14:40 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsWebShell::nsIBaseWindow
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::Create()
|
|
|
|
{
|
2001-06-19 00:28:10 +00:00
|
|
|
// Remember the current thread (in current and forseeable implementations,
|
|
|
|
// it'll just be the unique UI thread)
|
2000-03-11 01:05:08 +00:00
|
|
|
//
|
|
|
|
// Since this call must be made on the UI thread, we know the Event Queue
|
|
|
|
// will be associated with the current thread...
|
|
|
|
//
|
2001-06-19 00:28:10 +00:00
|
|
|
mThread = PR_GetCurrentThread();
|
2000-03-11 01:05:08 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
WEB_TRACE(WEB_TRACE_CALLS,
|
|
|
|
("nsWebShell::Init: this=%p", this));
|
2000-03-11 01:05:08 +00:00
|
|
|
|
|
|
|
// 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...
|
2000-09-13 23:57:52 +00:00
|
|
|
nsCOMPtr<nsIURILoader> uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID);
|
2002-09-24 00:35:51 +00:00
|
|
|
uriLoader->GetDocumentLoaderForContext(NS_STATIC_CAST(nsIWebShell*, this),
|
|
|
|
getter_AddRefs(mDocLoader));
|
2000-03-11 01:05:08 +00:00
|
|
|
|
2002-01-08 13:01:38 +00:00
|
|
|
nsCOMPtr<nsIContentViewerContainer> shellAsContainer = do_QueryInterface(NS_STATIC_CAST(nsIWebShell*, this));
|
2000-03-11 01:05:08 +00:00
|
|
|
// Set the webshell as the default IContentViewerContainer for the loader...
|
2002-01-08 13:01:38 +00:00
|
|
|
mDocLoader->SetContainer(shellAsContainer);
|
2000-03-11 01:05:08 +00:00
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
return nsDocShell::Create();
|
1999-11-27 02:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShell::Destroy()
|
|
|
|
{
|
2000-03-31 00:15:55 +00:00
|
|
|
nsDocShell::Destroy();
|
1999-11-27 02:14:40 +00:00
|
|
|
|
|
|
|
SetContainer(nsnull);
|
|
|
|
|
2000-03-31 00:15:55 +00:00
|
|
|
return NS_OK;
|
1999-11-27 02:14:40 +00:00
|
|
|
}
|
|
|
|
|
2000-09-11 22:06:52 +00:00
|
|
|
#ifdef DEBUG
|
2000-07-18 23:13:07 +00:00
|
|
|
unsigned long nsWebShell::gNumberOfWebShells = 0;
|
|
|
|
#endif
|