2001-04-27 17:38:15 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1999-11-12 10:28:25 +03:00
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications, Inc. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Travis Bogard <travis@netscape.com>
|
2000-01-11 23:49:15 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-04-20 12:11:12 +04:00
|
|
|
* Peter Annema <disttsc@bart.nl>
|
2001-04-25 06:04:56 +04:00
|
|
|
* Dan Rosen <dr@netscape.com>
|
1999-11-12 10:28:25 +03:00
|
|
|
*/
|
2001-04-28 01:11:03 +04:00
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
2000-01-29 09:10:54 +03:00
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
2000-08-17 23:16:39 +04:00
|
|
|
#include "nsIPluginHost.h"
|
1999-11-12 10:28:25 +03:00
|
|
|
#include "nsCURILoader.h"
|
|
|
|
#include "nsLayoutCID.h"
|
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 20:46:42 +04:00
|
|
|
#include "nsDOMCID.h"
|
|
|
|
#include "nsIDOMScriptObjectFactory.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-11-12 10:28:25 +03:00
|
|
|
#include "nsRect.h"
|
1999-11-12 12:07:28 +03:00
|
|
|
#include "prprf.h"
|
1999-11-19 10:35:27 +03:00
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
1999-12-03 15:10:31 +03:00
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1999-12-21 03:11:33 +03:00
|
|
|
#include "nsIChromeEventHandler.h"
|
2000-09-01 05:54:35 +04:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
2000-02-11 04:09:12 +03:00
|
|
|
#include "nsIWebBrowserChrome.h"
|
2000-02-29 09:51:48 +03:00
|
|
|
#include "nsPoint.h"
|
2000-03-08 06:58:33 +03:00
|
|
|
#include "nsGfxCIID.h"
|
2000-04-15 05:56:47 +04:00
|
|
|
#include "nsIPrompt.h"
|
2001-04-10 22:30:25 +04:00
|
|
|
#include "nsIAuthPrompt.h"
|
2000-05-19 01:52:23 +04:00
|
|
|
#include "nsTextFormatter.h"
|
2001-05-12 01:05:08 +04:00
|
|
|
#include "nsIHttpEventSink.h"
|
2000-09-15 02:56:56 +04:00
|
|
|
#include "nsISecurityEventSink.h"
|
2000-09-12 01:16:58 +04:00
|
|
|
#include "nsScriptSecurityManager.h"
|
2000-11-17 00:33:34 +03:00
|
|
|
#include "nsDocumentCharsetInfoCID.h"
|
2001-06-21 06:07:25 +04:00
|
|
|
#include "nsICanvasFrame.h"
|
2001-06-21 05:04:29 +04:00
|
|
|
#include "nsIPluginViewer.h"
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-30 16:52:02 +04:00
|
|
|
// Local Includes
|
|
|
|
#include "nsDocShell.h"
|
|
|
|
#include "nsDocShellLoadInfo.h"
|
2000-11-09 00:00:37 +03:00
|
|
|
#include "nsCDefaultURIFixup.h"
|
2001-04-28 01:11:03 +04:00
|
|
|
#include "nsDocShellEnumerator.h"
|
2000-03-30 16:52:02 +04:00
|
|
|
|
2000-04-12 03:52:42 +04:00
|
|
|
// Helper Classes
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
// Interfaces Needed
|
2001-09-05 07:52:26 +04:00
|
|
|
#include "nsIUploadChannel.h"
|
2000-06-14 03:56:30 +04:00
|
|
|
#include "nsIDataChannel.h"
|
2000-04-23 03:18:18 +04:00
|
|
|
#include "nsIProgressEventSink.h"
|
2000-06-20 11:59:45 +04:00
|
|
|
#include "nsIWebProgress.h"
|
2000-04-03 04:47:15 +04:00
|
|
|
#include "nsILayoutHistoryState.h"
|
2000-04-13 07:11:44 +04:00
|
|
|
#include "nsITimer.h"
|
2000-05-23 04:52:59 +04:00
|
|
|
#include "nsIFileStream.h"
|
2001-03-28 07:35:38 +04:00
|
|
|
#include "nsISHistoryInternal.h"
|
2000-06-14 03:56:30 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2001-09-26 23:33:14 +04:00
|
|
|
#include "nsIHistoryEntry.h"
|
2000-06-14 03:56:30 +04:00
|
|
|
|
2000-09-08 12:04:53 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2001-03-28 06:08:06 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2001-04-14 02:20:33 +04:00
|
|
|
#include "nsICachingChannel.h"
|
2001-09-08 02:06:08 +04:00
|
|
|
#include "nsICacheEntryDescriptor.h"
|
2001-11-28 02:14:15 +03:00
|
|
|
#include "nsIMultiPartChannel.h"
|
2000-09-08 12:04:53 +04:00
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
// The following are for bug #13871: Prevent frameset spoofing
|
|
|
|
#include "nsICodebasePrincipal.h"
|
|
|
|
#include "nsIHTMLDocument.h"
|
|
|
|
|
2000-03-31 15:19:51 +04:00
|
|
|
// For reporting errors with the console service.
|
|
|
|
// These can go away if error reporting is propagated up past nsDocShell.
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
|
2000-06-23 08:44:36 +04:00
|
|
|
// used to dispatch urls to default protocol handlers
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "nsIExternalProtocolService.h"
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
#include "nsIFocusController.h"
|
2000-09-08 12:04:53 +04:00
|
|
|
|
2000-11-15 03:17:41 +03:00
|
|
|
#include "nsITextToSubURI.h"
|
|
|
|
|
2001-04-28 06:07:58 +04:00
|
|
|
#include "prlog.h"
|
|
|
|
|
2001-03-13 09:19:40 +03:00
|
|
|
// this is going away - see
|
|
|
|
// http://bugzilla.mozilla.org/show_bug.cgi?id=71482
|
|
|
|
#include "nsIBrowserHistory.h"
|
|
|
|
|
2001-04-18 10:18:10 +04:00
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
|
2001-04-24 05:01:16 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
|
2001-04-25 06:04:56 +04:00
|
|
|
// for embedding
|
|
|
|
#include "nsIWebBrowserChromeFocus.h"
|
|
|
|
|
2000-03-08 06:58:33 +03:00
|
|
|
static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
|
2001-04-27 17:38:15 +04:00
|
|
|
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
2000-08-05 04:07:03 +04:00
|
|
|
static NS_DEFINE_CID(kDocumentCharsetInfoCID, NS_DOCUMENTCHARSETINFO_CID);
|
2000-08-17 23:16:39 +04:00
|
|
|
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
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 20:46:42 +04:00
|
|
|
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
|
|
|
|
NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
|
2000-03-08 06:58:33 +03:00
|
|
|
|
2001-10-23 02:43:52 +04:00
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_bryner)
|
2001-05-23 03:52:17 +04:00
|
|
|
//#define DEBUG_DOCSHELL_FOCUS
|
|
|
|
#endif
|
2000-09-05 23:03:56 +04:00
|
|
|
//
|
|
|
|
// Local function prototypes
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Used in AddHeadersToChannel
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*/
|
2000-09-05 23:03:56 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
static NS_METHOD AHTC_WriteFunc(nsIInputStream * in,
|
|
|
|
void *closure,
|
|
|
|
const char *fromRawSegment,
|
2000-09-05 23:03:56 +04:00
|
|
|
PRUint32 toOffset,
|
2001-04-27 17:38:15 +04:00
|
|
|
PRUint32 count, PRUint32 * writeCount);
|
2000-09-05 23:03:56 +04:00
|
|
|
|
2001-04-28 06:07:58 +04:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gDocShellLog;
|
|
|
|
#endif
|
2000-09-05 23:03:56 +04:00
|
|
|
|
2001-05-23 03:52:17 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsDocShellFocusController
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
class nsDocShellFocusController
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
static nsDocShellFocusController* GetInstance() { return &mDocShellFocusControllerSingleton; }
|
|
|
|
virtual ~nsDocShellFocusController(){}
|
|
|
|
|
|
|
|
void Focus(nsIDocShell* aDS);
|
|
|
|
void ClosingDown(nsIDocShell* aDS);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsDocShellFocusController(){}
|
|
|
|
|
|
|
|
nsIDocShell* mFocusedDocShell; // very weak reference
|
|
|
|
|
|
|
|
private:
|
|
|
|
static nsDocShellFocusController mDocShellFocusControllerSingleton;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsDocShellFocusController nsDocShellFocusController::mDocShellFocusControllerSingleton;
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsDocShell: Object Management
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::nsDocShell():
|
|
|
|
mContentListener(nsnull),
|
|
|
|
mMarginWidth(0),
|
|
|
|
mMarginHeight(0),
|
|
|
|
mItemType(typeContent),
|
|
|
|
mCurrentScrollbarPref(-1, -1),
|
|
|
|
mDefaultScrollbarPref(-1, -1),
|
2001-06-26 05:19:11 +04:00
|
|
|
mAllowSubframes(PR_TRUE),
|
2001-04-27 17:38:15 +04:00
|
|
|
mAllowPlugins(PR_TRUE),
|
|
|
|
mAllowJavascript(PR_TRUE),
|
|
|
|
mAllowMetaRedirects(PR_TRUE),
|
2001-05-22 02:42:46 +04:00
|
|
|
mAllowImages(PR_TRUE),
|
2001-06-26 05:19:11 +04:00
|
|
|
mFocusDocFirst(PR_FALSE),
|
2001-12-11 05:41:22 +03:00
|
|
|
mCreatingDocument(PR_FALSE),
|
2001-04-27 17:38:15 +04:00
|
|
|
mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
|
|
|
|
mBusyFlags(BUSY_FLAGS_NONE),
|
2001-07-18 00:17:38 +04:00
|
|
|
mFiredUnloadEvent(PR_FALSE),
|
2001-04-27 17:38:15 +04:00
|
|
|
mEODForCurrentDocument(PR_FALSE),
|
|
|
|
mURIResultedInDocument(PR_FALSE),
|
|
|
|
mUseExternalProtocolHandler(PR_FALSE),
|
|
|
|
mDisallowPopupWindows(PR_FALSE),
|
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 20:46:42 +04:00
|
|
|
mIsBeingDestroyed(PR_FALSE),
|
2001-04-27 17:38:15 +04:00
|
|
|
mParent(nsnull),
|
|
|
|
mTreeOwner(nsnull),
|
|
|
|
mChromeEventHandler(nsnull)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
2001-04-28 06:07:58 +04:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (! gDocShellLog)
|
|
|
|
gDocShellLog = PR_NewLogModule("nsDocShell");
|
|
|
|
#endif
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDocShell::~nsDocShell()
|
|
|
|
{
|
2001-05-23 03:52:17 +04:00
|
|
|
nsDocShellFocusController* dsfc = nsDocShellFocusController::GetInstance();
|
|
|
|
if (dsfc) {
|
|
|
|
dsfc->ClosingDown(this);
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
Destroy();
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::DestroyChildren()
|
|
|
|
{
|
2001-05-02 02:54:11 +04:00
|
|
|
PRInt32 i, n = mChildren.Count();
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> shell;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
shell = dont_AddRef((nsIDocShellTreeItem *) mChildren.ElementAt(i));
|
|
|
|
if (!NS_WARN_IF_FALSE(shell, "docshell has null child"))
|
|
|
|
shell->SetParent(nsnull);
|
|
|
|
shell->SetTreeOwner(nsnull);
|
|
|
|
// just clear out the array. When the nsFrameFrame that holds the subshell is
|
|
|
|
// destroyed, then the Destroy() method of that subshell will actually get
|
|
|
|
// called.
|
|
|
|
}
|
|
|
|
mChildren.Clear();
|
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsISupports
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsDocShell)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsDocShell)
|
1999-11-16 02:48:27 +03:00
|
|
|
|
1999-11-23 13:15:10 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDocShell)
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShell)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShell)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShellHistory)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebNavigation)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollable)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITextScroll)
|
2001-05-17 06:12:51 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocCharset)
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRefreshURI)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2002-01-08 16:01:38 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentViewerContainer)
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-08 16:40:10 +03:00
|
|
|
///*****************************************************************************
|
|
|
|
// nsDocShell::nsIInterfaceRequestor
|
|
|
|
//*****************************************************************************
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink)
|
|
|
|
{
|
2001-11-17 08:19:10 +03:00
|
|
|
NS_PRECONDITION(aSink, "null out param");
|
2000-02-08 16:40:10 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIURIContentListener)) &&
|
|
|
|
NS_SUCCEEDED(EnsureContentListener())) {
|
|
|
|
*aSink = mContentListener;
|
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)) &&
|
|
|
|
NS_SUCCEEDED(EnsureScriptEnvironment())) {
|
|
|
|
*aSink = mScriptGlobal;
|
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) &&
|
|
|
|
NS_SUCCEEDED(EnsureScriptEnvironment())) {
|
|
|
|
NS_ENSURE_SUCCESS(mScriptGlobal->
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMWindowInternal),
|
|
|
|
aSink), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIDOMWindow)) &&
|
|
|
|
NS_SUCCEEDED(EnsureScriptEnvironment())) {
|
|
|
|
NS_ENSURE_SUCCESS(mScriptGlobal->
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMWindow), aSink),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIDOMDocument)) &&
|
|
|
|
NS_SUCCEEDED(EnsureContentViewer())) {
|
|
|
|
mContentViewer->GetDOMDocument((nsIDOMDocument **) aSink);
|
2001-11-17 08:19:10 +03:00
|
|
|
return NS_OK;
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIPrompt))) {
|
2000-03-08 03:38:58 +03:00
|
|
|
nsCOMPtr<nsIPrompt> prompter(do_GetInterface(mTreeOwner));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (prompter) {
|
2000-03-08 03:38:58 +03:00
|
|
|
*aSink = prompter;
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ADDREF((nsISupports *) * aSink);
|
2000-03-08 03:38:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_NOINTERFACE;
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIAuthPrompt))) {
|
2001-04-10 22:30:25 +04:00
|
|
|
nsCOMPtr<nsIAuthPrompt> authPrompter(do_GetInterface(mTreeOwner));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (authPrompter) {
|
2001-04-10 22:30:25 +04:00
|
|
|
*aSink = authPrompter;
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ADDREF((nsISupports *) * aSink);
|
2001-04-10 22:30:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_NOINTERFACE;
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIProgressEventSink))
|
2001-05-12 01:05:08 +04:00
|
|
|
|| aIID.Equals(NS_GET_IID(nsIHttpEventSink))
|
2001-04-27 17:38:15 +04:00
|
|
|
|| aIID.Equals(NS_GET_IID(nsIWebProgress))
|
|
|
|
|| aIID.Equals(NS_GET_IID(nsISecurityEventSink))) {
|
|
|
|
nsCOMPtr<nsIURILoader>
|
|
|
|
uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIDocumentLoader> docLoader;
|
|
|
|
NS_ENSURE_SUCCESS(uriLoader->
|
|
|
|
GetDocumentLoaderForContext(NS_STATIC_CAST
|
|
|
|
(nsIDocShell *, this),
|
|
|
|
getter_AddRefs
|
|
|
|
(docLoader)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (docLoader) {
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor>
|
|
|
|
requestor(do_QueryInterface(docLoader));
|
|
|
|
return requestor->GetInterface(aIID, aSink);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsISHistory))) {
|
|
|
|
nsCOMPtr<nsISHistory> shistory;
|
|
|
|
nsresult
|
|
|
|
rv =
|
|
|
|
GetSessionHistory(getter_AddRefs(shistory));
|
|
|
|
if (NS_SUCCEEDED(rv) && shistory) {
|
|
|
|
*aSink = shistory;
|
|
|
|
NS_ADDREF((nsISupports *) * aSink);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
2001-04-28 01:11:03 +04:00
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIWebBrowserFind))) {
|
|
|
|
nsresult rv = EnsureFind();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*aSink = mFind;
|
|
|
|
NS_ADDREF((nsISupports*)*aSink);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
else {
|
|
|
|
return QueryInterface(aIID, aSink);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(((nsISupports *) * aSink));
|
|
|
|
return NS_OK;
|
2000-10-12 03:17:02 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRUint32
|
|
|
|
nsDocShell::
|
|
|
|
ConvertDocShellLoadInfoToLoadType(nsDocShellInfoLoadType aDocShellLoadType)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
PRUint32 loadType = LOAD_NORMAL;
|
2000-09-20 16:23:53 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
switch (aDocShellLoadType) {
|
2000-09-20 16:23:53 +04:00
|
|
|
case nsIDocShellLoadInfo::loadNormal:
|
|
|
|
loadType = LOAD_NORMAL;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadNormalReplace:
|
|
|
|
loadType = LOAD_NORMAL_REPLACE;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadHistory:
|
|
|
|
loadType = LOAD_HISTORY;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadReloadNormal:
|
|
|
|
loadType = LOAD_RELOAD_NORMAL;
|
|
|
|
break;
|
2001-06-30 02:12:14 +04:00
|
|
|
case nsIDocShellLoadInfo::loadReloadCharsetChange:
|
|
|
|
loadType = LOAD_RELOAD_CHARSET_CHANGE;
|
|
|
|
break;
|
2000-09-20 16:23:53 +04:00
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassCache:
|
|
|
|
loadType = LOAD_RELOAD_BYPASS_CACHE;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxy:
|
|
|
|
loadType = LOAD_RELOAD_BYPASS_PROXY;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxyAndCache:
|
|
|
|
loadType = LOAD_RELOAD_BYPASS_PROXY_AND_CACHE;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadLink:
|
|
|
|
loadType = LOAD_LINK;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadRefresh:
|
|
|
|
loadType = LOAD_REFRESH;
|
|
|
|
break;
|
2001-08-17 03:49:50 +04:00
|
|
|
case nsIDocShellLoadInfo::loadBypassHistory:
|
|
|
|
loadType = LOAD_BYPASS_HISTORY;
|
|
|
|
break;
|
2000-09-20 16:23:53 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return loadType;
|
|
|
|
}
|
2000-06-22 11:22:23 +04:00
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
|
2001-12-01 01:35:33 +03:00
|
|
|
nsDocShellInfoLoadType
|
|
|
|
nsDocShell::ConvertLoadTypeToDocShellLoadInfo(PRUint32 aLoadType)
|
|
|
|
{
|
|
|
|
nsDocShellInfoLoadType docShellLoadType = nsIDocShellLoadInfo::loadNormal;
|
|
|
|
switch (aLoadType) {
|
|
|
|
case LOAD_NORMAL:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadNormal;
|
|
|
|
break;
|
|
|
|
case LOAD_NORMAL_REPLACE:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadNormalReplace;
|
|
|
|
break;
|
|
|
|
case LOAD_HISTORY:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadHistory;
|
|
|
|
break;
|
|
|
|
case LOAD_RELOAD_NORMAL:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadReloadNormal;
|
|
|
|
break;
|
|
|
|
case LOAD_RELOAD_CHARSET_CHANGE:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadReloadCharsetChange;
|
|
|
|
break;
|
|
|
|
case LOAD_RELOAD_BYPASS_CACHE:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadReloadBypassCache;
|
|
|
|
break;
|
|
|
|
case LOAD_RELOAD_BYPASS_PROXY:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadReloadBypassProxy;
|
|
|
|
break;
|
|
|
|
case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadReloadBypassProxyAndCache;
|
|
|
|
break;
|
|
|
|
case LOAD_LINK:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadLink;
|
|
|
|
break;
|
|
|
|
case LOAD_REFRESH:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadRefresh;
|
|
|
|
break;
|
|
|
|
case LOAD_BYPASS_HISTORY:
|
|
|
|
docShellLoadType = nsIDocShellLoadInfo::loadBypassHistory;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return docShellLoadType;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIDocShell
|
|
|
|
//*****************************************************************************
|
|
|
|
NS_IMETHODIMP
|
2001-05-14 06:16:27 +04:00
|
|
|
nsDocShell::LoadURI(nsIURI * aURI,
|
|
|
|
nsIDocShellLoadInfo * aLoadInfo,
|
|
|
|
PRUint32 aLoadFlags)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> referrer;
|
2001-05-14 06:16:27 +04:00
|
|
|
nsCOMPtr<nsIInputStream> postStream;
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
PRBool inheritOwner = PR_FALSE;
|
|
|
|
nsCOMPtr<nsISHEntry> shEntry;
|
2001-12-01 01:35:33 +03:00
|
|
|
nsXPIDLString target;
|
2001-08-17 03:49:50 +04:00
|
|
|
PRUint32 loadType = MAKE_LOAD_TYPE(LOAD_NORMAL, aLoadFlags);
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
|
|
|
// Extract the info from the DocShellLoadInfo struct...
|
|
|
|
if (aLoadInfo) {
|
|
|
|
aLoadInfo->GetReferrer(getter_AddRefs(referrer));
|
|
|
|
|
|
|
|
nsDocShellInfoLoadType lt = nsIDocShellLoadInfo::loadNormal;
|
|
|
|
aLoadInfo->GetLoadType(<);
|
2001-08-17 03:49:50 +04:00
|
|
|
// Get the appropriate loadType from nsIDocShellLoadInfo type
|
|
|
|
loadType = ConvertDocShellLoadInfoToLoadType(lt);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
aLoadInfo->GetOwner(getter_AddRefs(owner));
|
|
|
|
aLoadInfo->GetInheritOwner(&inheritOwner);
|
|
|
|
aLoadInfo->GetSHEntry(getter_AddRefs(shEntry));
|
|
|
|
aLoadInfo->GetTarget(getter_Copies(target));
|
2001-05-14 06:16:27 +04:00
|
|
|
aLoadInfo->GetPostDataStream(getter_AddRefs(postStream));
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-28 06:07:58 +04:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gDocShellLog, PR_LOG_DEBUG)) {
|
|
|
|
nsXPIDLCString uristr;
|
|
|
|
aURI->GetSpec(getter_Copies(uristr));
|
|
|
|
PR_LOG(gDocShellLog, PR_LOG_DEBUG,
|
|
|
|
("nsDocShell[%p]: loading %s with flags 0x%08x",
|
|
|
|
this, uristr.get(), aLoadFlags));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (!shEntry && loadType != LOAD_NORMAL_REPLACE && mCurrentURI == nsnull) {
|
2001-10-26 23:04:11 +04:00
|
|
|
/* OK. We are in the process of loading a subframe. Checkout the
|
|
|
|
* parent's loadtype. If the parent was loaded thro' a history
|
|
|
|
* mechanism, then get the SH entry for the child from the parent.
|
|
|
|
* This is done to restore frameset navigation while going back/forward.
|
|
|
|
* If the parent was not loaded thro' any history mechanism, we don't
|
|
|
|
* have to do this, since we have nothing to restore.
|
2001-04-27 17:38:15 +04:00
|
|
|
*/
|
2001-10-26 23:04:11 +04:00
|
|
|
|
|
|
|
// get the parent
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
|
|
|
GetSameTypeParent(getter_AddRefs(parentAsItem));
|
|
|
|
|
2001-10-26 23:04:11 +04:00
|
|
|
nsCOMPtr<nsIDocShell> parentDS(do_QueryInterface(parentAsItem));
|
|
|
|
PRUint32 parentLoadType;
|
|
|
|
|
|
|
|
if (parentDS) {
|
|
|
|
// Get the parent's load type
|
|
|
|
parentDS->GetLoadType(&parentLoadType);
|
|
|
|
|
|
|
|
/* Try to get the SHEntry for this subframe from the parent,
|
|
|
|
* only if the parent was loaded thro' a history mechanism,
|
|
|
|
* like back/forward/go/reload
|
|
|
|
*/
|
|
|
|
if (parentAsItem && (parentLoadType & LOAD_CMD_HISTORY) || (parentLoadType & LOAD_CMD_RELOAD)) {
|
|
|
|
nsCOMPtr<nsIDocShellHistory> parent(do_QueryInterface(parentAsItem));
|
|
|
|
if (parent) {
|
|
|
|
// Get the ShEntry for the child from the parent
|
|
|
|
parent->GetChildSHEntry(mChildOffset, getter_AddRefs(shEntry));
|
|
|
|
if (shEntry)
|
|
|
|
loadType = parentLoadType;
|
|
|
|
} // parent
|
|
|
|
}
|
|
|
|
} //parentDS
|
|
|
|
} // !shEntry
|
2001-07-03 09:27:22 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (shEntry) {
|
|
|
|
// Load is from SH. SH does normal load only
|
2001-04-28 06:07:58 +04:00
|
|
|
PR_LOG(gDocShellLog, PR_LOG_DEBUG,
|
|
|
|
("nsDocShell[%p]: loading from session history", this));
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
rv = LoadHistoryEntry(shEntry, loadType);
|
|
|
|
}
|
2001-05-14 06:16:27 +04:00
|
|
|
// Perform the load...
|
2001-04-27 17:38:15 +04:00
|
|
|
else {
|
2001-07-03 09:27:22 +04:00
|
|
|
// We need an owner (a referring principal). 3 possibilities:
|
|
|
|
// (1) If a principal was passed in, that's what we'll use.
|
|
|
|
// (2) If the caller has allowed inheriting from the current document,
|
|
|
|
// or if we're being called from chrome (if there's system JS on the stack),
|
|
|
|
// then inheritOwner should be true and InternalLoad will get an owner
|
|
|
|
// from the current document. If none of these things are true, then
|
|
|
|
// (3) we pass a null owner into the channel, and an owner will be
|
|
|
|
// created later from the URL.
|
|
|
|
if (!owner && !inheritOwner) {
|
|
|
|
// See if there's system or chrome JS code running
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan;
|
|
|
|
|
|
|
|
secMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIPrincipal> sysPrin;
|
|
|
|
nsCOMPtr<nsIPrincipal> subjectPrin;
|
|
|
|
|
|
|
|
// Just to compare, not to use!
|
|
|
|
rv = secMan->GetSystemPrincipal(getter_AddRefs(sysPrin));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subjectPrin));
|
|
|
|
}
|
|
|
|
// If there's no subject principal, there's no JS running, so we're in system code.
|
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
(!subjectPrin || sysPrin.get() == subjectPrin.get())) {
|
|
|
|
inheritOwner = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
rv = InternalLoad(aURI,
|
|
|
|
referrer,
|
|
|
|
owner,
|
|
|
|
inheritOwner,
|
2001-12-01 01:35:33 +03:00
|
|
|
target.get(),
|
2001-05-14 06:16:27 +04:00
|
|
|
postStream,
|
|
|
|
nsnull, // No headers stream
|
|
|
|
loadType,
|
|
|
|
nsnull); // No SHEntry
|
2000-07-06 03:10:29 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return rv;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::LoadStream(nsIInputStream * aStream, nsIURI * aURI,
|
|
|
|
const char *aContentType, PRInt32 aContentLen,
|
|
|
|
nsIDocShellLoadInfo * aLoadInfo)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aStream);
|
|
|
|
NS_ENSURE_ARG(aContentType);
|
|
|
|
NS_ENSURE_ARG(aContentLen);
|
|
|
|
|
|
|
|
// if the caller doesn't pass in a URI we need to create a dummy URI. necko
|
|
|
|
// currently requires a URI in various places during the load. Some consumers
|
|
|
|
// do as well.
|
|
|
|
nsCOMPtr<nsIURI> uri = aURI;
|
|
|
|
if (!uri) {
|
|
|
|
// HACK ALERT
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
uri = do_CreateInstance(kSimpleURICID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
// Make sure that the URI spec "looks" like a protocol and path...
|
|
|
|
// For now, just use a bogus protocol called "internal"
|
|
|
|
rv = uri->SetSpec("internal:load-stream");
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-08-17 03:49:50 +04:00
|
|
|
PRUint32 loadType = LOAD_NORMAL;
|
2001-04-27 17:38:15 +04:00
|
|
|
if (aLoadInfo) {
|
|
|
|
nsDocShellInfoLoadType lt = nsIDocShellLoadInfo::loadNormal;
|
|
|
|
(void) aLoadInfo->GetLoadType(<);
|
2001-08-17 03:49:50 +04:00
|
|
|
// Get the appropriate LoadType from nsIDocShellLoadInfo type
|
|
|
|
loadType = ConvertDocShellLoadInfoToLoadType(lt);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-07-06 03:10:29 +04:00
|
|
|
|
2001-08-14 08:46:20 +04:00
|
|
|
NS_ENSURE_SUCCESS(Stop(nsIWebNavigation::STOP_NETWORK), NS_ERROR_FAILURE);
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
mLoadType = loadType;
|
|
|
|
|
|
|
|
// build up a channel for this stream.
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
NS_ENSURE_SUCCESS(NS_NewInputStreamChannel
|
|
|
|
(getter_AddRefs(channel), uri, aStream, aContentType,
|
|
|
|
aContentLen), NS_ERROR_FAILURE);
|
1999-11-29 21:41:59 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIURILoader>
|
|
|
|
uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE);
|
1999-11-29 21:41:59 +03:00
|
|
|
|
2001-10-27 06:52:39 +04:00
|
|
|
NS_ENSURE_SUCCESS(DoChannelLoad(channel, uriLoader), NS_ERROR_FAILURE);
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-29 21:41:59 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::CreateLoadInfo(nsIDocShellLoadInfo ** aLoadInfo)
|
1999-11-16 01:54:47 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShellLoadInfo *loadInfo = new nsDocShellLoadInfo();
|
|
|
|
NS_ENSURE_TRUE(loadInfo, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> localRef(loadInfo);
|
1999-11-16 01:54:47 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aLoadInfo = localRef;
|
|
|
|
NS_ADDREF(*aLoadInfo);
|
|
|
|
return NS_OK;
|
1999-11-16 01:54:47 +03:00
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
|
2001-05-25 12:49:03 +04:00
|
|
|
/*
|
|
|
|
* Reset state to a new content model within the current document and the document
|
|
|
|
* viewer. Called by the document before initiating an out of band document.write().
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::PrepareForNewContentModel()
|
|
|
|
{
|
|
|
|
mEODForCurrentDocument = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-18 00:17:38 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::FireUnloadNotification()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (mContentViewer && !mFiredUnloadEvent) {
|
|
|
|
mFiredUnloadEvent = PR_TRUE;
|
|
|
|
|
|
|
|
rv = mContentViewer->Unload();
|
|
|
|
|
|
|
|
PRInt32 i, n = mChildren.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIDocShellTreeItem* item = (nsIDocShellTreeItem*) mChildren.ElementAt(i);
|
|
|
|
if(item) {
|
|
|
|
nsCOMPtr<nsIDocShell> shell(do_QueryInterface(item));
|
|
|
|
if (shell) {
|
|
|
|
rv = shell->FireUnloadNotification();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
//
|
|
|
|
// Bug 13871: Prevent frameset spoofing
|
|
|
|
// Check if origin document uri is the equivalent to target's principal.
|
|
|
|
// This takes into account subdomain checking if document.domain is set for
|
|
|
|
// Nav 4.x compatability.
|
|
|
|
//
|
|
|
|
// The following was derived from nsCodeBasePrincipal::Equals but in addition
|
|
|
|
// to the host PL_strcmp, it accepts a subdomain (nsHTMLDocument::SetDomain)
|
|
|
|
// if the document.domain was set.
|
|
|
|
//
|
|
|
|
static
|
|
|
|
PRBool SameOrSubdomainOfTarget(nsIURI* aOriginURI, nsIURI* aTargetURI, PRBool aDocumentDomainSet)
|
|
|
|
{
|
|
|
|
nsXPIDLCString targetScheme;
|
|
|
|
nsresult rv = aTargetURI->GetScheme(getter_Copies(targetScheme));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetScheme, PR_TRUE);
|
|
|
|
|
|
|
|
nsXPIDLCString originScheme;
|
|
|
|
rv = aOriginURI->GetScheme(getter_Copies(originScheme));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originScheme, PR_TRUE);
|
|
|
|
|
|
|
|
if (PL_strcmp(targetScheme, originScheme))
|
|
|
|
return PR_FALSE; // Different schemes - check fails
|
|
|
|
|
|
|
|
if (! PL_strcmp(targetScheme, "file"))
|
|
|
|
return PR_TRUE; // All file: urls are considered to have the same origin.
|
|
|
|
|
|
|
|
if (! PL_strcmp(targetScheme, "imap") ||
|
|
|
|
! PL_strcmp(targetScheme, "mailbox") ||
|
|
|
|
! PL_strcmp(targetScheme, "news"))
|
|
|
|
{
|
|
|
|
|
|
|
|
// Each message is a distinct trust domain; use the whole spec for comparison
|
|
|
|
nsXPIDLCString targetSpec;
|
|
|
|
rv =aTargetURI->GetSpec(getter_Copies(targetSpec));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetSpec, PR_TRUE);
|
|
|
|
|
|
|
|
nsXPIDLCString originSpec;
|
|
|
|
rv = aOriginURI->GetSpec(getter_Copies(originSpec));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originSpec, PR_TRUE);
|
|
|
|
|
|
|
|
return (! PL_strcmp(targetSpec, originSpec)); // True if full spec is same, false otherwise
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare ports.
|
|
|
|
int targetPort, originPort;
|
|
|
|
rv = aTargetURI->GetPort(&targetPort);
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv), PR_TRUE);
|
|
|
|
|
|
|
|
rv = aOriginURI->GetPort(&originPort);
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv), PR_TRUE);
|
|
|
|
|
|
|
|
if (targetPort != originPort)
|
|
|
|
return PR_FALSE; // Different port - check fails
|
|
|
|
|
|
|
|
// Need to check the hosts
|
|
|
|
nsXPIDLCString targetHost;
|
|
|
|
rv = aTargetURI->GetHost(getter_Copies(targetHost));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetHost, PR_TRUE);
|
|
|
|
|
|
|
|
nsXPIDLCString originHost;
|
|
|
|
rv = aOriginURI->GetHost(getter_Copies(originHost));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originHost, PR_TRUE);
|
|
|
|
|
|
|
|
if (!PL_strcmp(targetHost, originHost))
|
|
|
|
return PR_TRUE; // Hosts are the same - check passed
|
|
|
|
|
|
|
|
// If document.domain was set, do the relaxed check
|
|
|
|
// Right align hostnames and compare - ensure preceeding char is . or /
|
|
|
|
if (aDocumentDomainSet)
|
|
|
|
{
|
|
|
|
int targetHostLen = PL_strlen(targetHost);
|
|
|
|
int originHostLen = PL_strlen(originHost);
|
|
|
|
int prefixChar = originHostLen-targetHostLen-1;
|
|
|
|
|
|
|
|
return ((originHostLen > targetHostLen) &&
|
|
|
|
(! PL_strcmp((originHost+prefixChar+1), targetHost)) &&
|
|
|
|
(originHost[prefixChar] == '.' || originHost[prefixChar] == '/'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE; // document.domain not set and hosts not same - check failed
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Bug 13871: Prevent frameset spoofing
|
|
|
|
//
|
|
|
|
// This routine answers: 'Is origin's document from same domain as target's document?'
|
|
|
|
// Be optimistic that domain is same - error cases all answer 'yes'.
|
|
|
|
//
|
|
|
|
// We have to compare the URI of the actual document loaded in the origin,
|
|
|
|
// ignoring any document.domain that was set, with the principal URI of the
|
|
|
|
// target (including any document.domain that was set). This puts control
|
|
|
|
// of loading in the hands of the target, which is more secure. (per Nav 4.x)
|
|
|
|
//
|
|
|
|
static
|
|
|
|
PRBool ValidateOrigin(nsIDocShellTreeItem* aOriginTreeItem, nsIDocShellTreeItem* aTargetTreeItem)
|
|
|
|
{
|
|
|
|
// Get origin document uri (ignoring document.domain)
|
|
|
|
nsCOMPtr<nsIWebNavigation> originWebNav(do_QueryInterface(aOriginTreeItem));
|
|
|
|
NS_ENSURE_TRUE(originWebNav, PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> originDocumentURI;
|
|
|
|
nsresult rv = originWebNav->GetCurrentURI(getter_AddRefs(originDocumentURI));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originDocumentURI, PR_TRUE);
|
|
|
|
|
|
|
|
// Get target principal uri (including document.domain)
|
|
|
|
nsCOMPtr<nsIDOMDocument> targetDOMDocument(do_GetInterface(aTargetTreeItem));
|
|
|
|
NS_ENSURE_TRUE(targetDOMDocument, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> targetDocument(do_QueryInterface(targetDOMDocument));
|
|
|
|
NS_ENSURE_TRUE(targetDocument, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> targetPrincipal;
|
|
|
|
rv = targetDocument->GetPrincipal(getter_AddRefs(targetPrincipal));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetPrincipal, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsICodebasePrincipal> targetCodebasePrincipal(do_QueryInterface(targetPrincipal));
|
|
|
|
NS_ENSURE_TRUE(targetCodebasePrincipal, PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> targetPrincipalURI;
|
|
|
|
rv = targetCodebasePrincipal->GetURI(getter_AddRefs(targetPrincipalURI));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetPrincipalURI, PR_TRUE);
|
|
|
|
|
|
|
|
// Find out if document.domain was set for HTML documents
|
|
|
|
PRBool documentDomainSet = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIHTMLDocument> targetHTMLDocument(do_QueryInterface(targetDocument));
|
|
|
|
|
|
|
|
// If we don't have an HTML document, fall through with documentDomainSet false
|
|
|
|
if (targetHTMLDocument) {
|
|
|
|
targetHTMLDocument->WasDomainSet(&documentDomainSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is origin same principal or a subdomain of target's document.domain
|
|
|
|
// Compare actual URI of origin document, not origin principal's URI. (Per Nav 4.x)
|
|
|
|
return SameOrSubdomainOfTarget(originDocumentURI, targetPrincipalURI, documentDomainSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDocShell::FindTarget(const PRUnichar *aWindowTarget,
|
|
|
|
PRBool *aIsNewWindow,
|
|
|
|
nsIDocShell **aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoString name(aWindowTarget);
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem;
|
|
|
|
PRBool mustMakeNewWindow = PR_FALSE;
|
|
|
|
|
|
|
|
*aResult = nsnull;
|
|
|
|
*aIsNewWindow = PR_FALSE;
|
|
|
|
|
|
|
|
if(!name.Length() || name.EqualsIgnoreCase("_self"))
|
|
|
|
{
|
|
|
|
*aResult = this;
|
|
|
|
}
|
|
|
|
else if (name.EqualsIgnoreCase("_blank") || name.EqualsIgnoreCase("_new"))
|
|
|
|
{
|
|
|
|
mustMakeNewWindow = PR_TRUE;
|
2001-12-16 14:58:03 +03:00
|
|
|
name.Assign(NS_LITERAL_STRING(""));
|
2001-05-14 06:16:27 +04:00
|
|
|
}
|
|
|
|
else if(name.EqualsIgnoreCase("_parent"))
|
|
|
|
{
|
|
|
|
GetSameTypeParent(getter_AddRefs(treeItem));
|
|
|
|
if(!treeItem)
|
|
|
|
*aResult = this;
|
|
|
|
}
|
|
|
|
else if(name.EqualsIgnoreCase("_top"))
|
|
|
|
{
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(treeItem));
|
|
|
|
if(!treeItem)
|
|
|
|
*aResult = this;
|
|
|
|
}
|
|
|
|
else if(name.EqualsIgnoreCase("_content"))
|
|
|
|
{
|
2001-09-06 09:31:14 +04:00
|
|
|
if (mTreeOwner) {
|
2001-05-14 06:16:27 +04:00
|
|
|
mTreeOwner->FindItemWithName(name.get(), nsnull,
|
|
|
|
getter_AddRefs(treeItem));
|
2001-09-06 09:31:14 +04:00
|
|
|
} else {
|
2001-05-14 06:16:27 +04:00
|
|
|
NS_ERROR("Someone isn't setting up the tree owner. "
|
|
|
|
"You might like to try that. "
|
|
|
|
"Things will.....you know, work.");
|
|
|
|
}
|
2001-09-06 09:31:14 +04:00
|
|
|
// _content should always exist. If the nsIDocShellTreeOwner did
|
|
|
|
// not find one, then create one...
|
|
|
|
if (!treeItem) {
|
|
|
|
mustMakeNewWindow = PR_TRUE;
|
|
|
|
}
|
2001-05-14 06:16:27 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Try to locate the target window...
|
|
|
|
FindItemWithName(name.get(), nsnull, getter_AddRefs(treeItem));
|
|
|
|
|
|
|
|
// The named window cannot be found so it must be created to receive
|
|
|
|
// the channel data.
|
|
|
|
|
|
|
|
if (!treeItem) {
|
|
|
|
mustMakeNewWindow = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bug 13871: Prevent frameset spoofing
|
|
|
|
// See BugSplat 336170, 338737 and XP_FindNamedContextInList in
|
|
|
|
// the classic codebase
|
|
|
|
// Per Nav's behaviour:
|
|
|
|
// - pref controlled: "browser.frame.validate_origin"
|
|
|
|
// (mValidateOrigin)
|
|
|
|
// - allow load if host of target or target's parent is same
|
|
|
|
// as host of origin
|
|
|
|
// - allow load if target is a top level window
|
|
|
|
|
|
|
|
// Check to see if pref is true
|
|
|
|
if (mValidateOrigin && treeItem)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Is origin frame from the same domain as target frame?
|
|
|
|
if (! ValidateOrigin(this, treeItem))
|
|
|
|
{
|
|
|
|
|
|
|
|
// No. Is origin frame from the same domain as target's parent?
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> targetParentTreeItem;
|
|
|
|
|
|
|
|
rv = treeItem->GetSameTypeParent(getter_AddRefs(targetParentTreeItem));
|
|
|
|
if (NS_SUCCEEDED(rv) && targetParentTreeItem)
|
|
|
|
{
|
|
|
|
if (! ValidateOrigin(this, targetParentTreeItem))
|
|
|
|
{
|
|
|
|
|
|
|
|
// Neither is from the origin domain, send load to a new window (_blank)
|
|
|
|
mustMakeNewWindow = PR_TRUE;
|
2001-12-16 14:58:03 +03:00
|
|
|
name.Assign(NS_LITERAL_STRING(""));
|
2001-05-14 06:16:27 +04:00
|
|
|
} // else (target's parent from origin domain) allow this load
|
|
|
|
} // else (no parent) allow this load since shell is a toplevel window
|
|
|
|
} // else (target from origin domain) allow this load
|
|
|
|
} // else (pref is false) allow this load
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mustMakeNewWindow)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMWindow> newWindow;
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> parentWindow;
|
|
|
|
|
|
|
|
// This DocShell is the parent window
|
|
|
|
parentWindow = do_GetInterface(NS_STATIC_CAST(nsIDocShell*, this));
|
|
|
|
if (!parentWindow) {
|
|
|
|
NS_ASSERTION(0, "Cant get nsIDOMWindowInternal from nsDocShell!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = parentWindow->Open(NS_LITERAL_STRING(""), // URL to load
|
|
|
|
name, // Window name
|
2001-11-28 09:09:40 +03:00
|
|
|
NS_LITERAL_STRING(""), // Window features
|
2001-05-14 06:16:27 +04:00
|
|
|
getter_AddRefs(newWindow));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Get the DocShell from the new window...
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
sgo = do_QueryInterface(newWindow, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// This will AddRef() aResult...
|
|
|
|
rv = sgo->GetDocShell(aResult);
|
|
|
|
|
|
|
|
// If all went well, indicate that a new window has been created.
|
|
|
|
if (*aResult) {
|
|
|
|
*aIsNewWindow = PR_TRUE;
|
2001-08-23 08:24:25 +04:00
|
|
|
|
|
|
|
// if we just open a new window for this link, charset from current docshell
|
|
|
|
// should be kept, as what we did in js openNewWindowWith(url)
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muCV, target_muCV;
|
|
|
|
nsCOMPtr<nsIContentViewer> cv, target_cv;
|
|
|
|
this->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
(*aResult)->GetContentViewer(getter_AddRefs(target_cv));
|
|
|
|
if (cv && target_cv) {
|
|
|
|
muCV = do_QueryInterface(cv);
|
|
|
|
target_muCV = do_QueryInterface(target_cv);
|
|
|
|
if (muCV && target_muCV) {
|
|
|
|
nsXPIDLString defaultCharset;
|
|
|
|
rv = muCV->GetDefaultCharacterSet(getter_Copies(defaultCharset));
|
|
|
|
if(NS_SUCCEEDED(rv)) {
|
|
|
|
target_muCV->SetDefaultCharacterSet(defaultCharset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-14 06:16:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (treeItem)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!*aResult, "aResult should be null if treeItem is set!");
|
|
|
|
treeItem->QueryInterface(NS_GET_IID(nsIDocShell), (void **)aResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-22 01:18:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetEldestPresContext(nsIPresContext** aPresContext)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
|
|
|
*aPresContext = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer = mContentViewer;
|
|
|
|
while (viewer) {
|
|
|
|
nsCOMPtr<nsIContentViewer> prevViewer;
|
|
|
|
viewer->GetPreviousViewer(getter_AddRefs(prevViewer));
|
|
|
|
if (prevViewer)
|
|
|
|
viewer = prevViewer;
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(viewer));
|
|
|
|
if (docv)
|
|
|
|
rv = docv->GetPresContext(*aPresContext);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetPresContext(nsIPresContext ** aPresContext)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
|
|
|
*aPresContext = nsnull;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-08-16 00:41:20 +04:00
|
|
|
if (mContentViewer) {
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
|
|
|
|
|
|
|
|
if (docv) {
|
|
|
|
rv = docv->GetPresContext(*aPresContext);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fail silently, if no PresContext is available...
|
|
|
|
return rv;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetPresShell(nsIPresShell ** aPresShell)
|
2000-04-12 04:07:04 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresShell);
|
|
|
|
*aPresShell = nsnull;
|
2000-04-12 04:07:04 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
(void) GetPresContext(getter_AddRefs(presContext));
|
2000-08-05 04:07:03 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (presContext) {
|
|
|
|
rv = presContext->GetShell(aPresShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-08-22 01:18:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetEldestPresShell(nsIPresShell** aPresShell)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresShell);
|
|
|
|
*aPresShell = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
(void) GetEldestPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
if (presContext) {
|
|
|
|
rv = presContext->GetShell(aPresShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetContentViewer(nsIContentViewer ** aContentViewer)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aContentViewer);
|
|
|
|
|
|
|
|
*aContentViewer = mContentViewer;
|
|
|
|
NS_IF_ADDREF(*aContentViewer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-12 04:07:04 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetChromeEventHandler(nsIChromeEventHandler * aChromeEventHandler)
|
2000-04-12 04:07:04 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// Weak reference. Don't addref.
|
|
|
|
mChromeEventHandler = aChromeEventHandler;
|
|
|
|
return NS_OK;
|
2000-04-12 04:07:04 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetChromeEventHandler(nsIChromeEventHandler ** aChromeEventHandler)
|
2000-03-11 03:53:48 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aChromeEventHandler);
|
2000-03-11 03:53:48 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aChromeEventHandler = mChromeEventHandler;
|
|
|
|
NS_IF_ADDREF(*aChromeEventHandler);
|
|
|
|
return NS_OK;
|
2000-03-11 03:53:48 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetParentURIContentListener(nsIURIContentListener ** aParent)
|
2000-03-11 03:53:48 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return mContentListener->GetParentContentListener(aParent);
|
2000-03-11 03:53:48 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetParentURIContentListener(nsIURIContentListener * aParent)
|
2001-03-23 07:22:56 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return mContentListener->SetParentContentListener(aParent);
|
|
|
|
}
|
|
|
|
|
2002-01-08 16:01:38 +03:00
|
|
|
/* [noscript] void setCurrentURI (in nsIURI uri); */
|
|
|
|
NS_IMETHODIMP nsDocShell::SetCurrentURI(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
mCurrentURI = aURI; //This assignment addrefs
|
|
|
|
PRBool isRoot = PR_FALSE; // Is this the root docshell
|
|
|
|
PRBool isSubFrame=PR_FALSE; // Is this a subframe navigation?
|
|
|
|
|
|
|
|
if (!mLoadCookie)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentLoader> loader(do_GetInterface(mLoadCookie));
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
if (root.get() == NS_STATIC_CAST(nsIDocShellTreeItem *, this))
|
|
|
|
{
|
|
|
|
// This is the root docshell
|
|
|
|
isRoot = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (mLSHE) {
|
|
|
|
nsCOMPtr<nsIHistoryEntry> historyEntry(do_QueryInterface(mLSHE));
|
|
|
|
|
|
|
|
// Check if this is a subframe navigation
|
|
|
|
if (historyEntry) {
|
|
|
|
historyEntry->GetIsSubFrame(&isSubFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isSubFrame && !isRoot) {
|
|
|
|
/*
|
|
|
|
* We don't want to send OnLocationChange notifications when
|
|
|
|
* a subframe is being loaded for the first time, while
|
|
|
|
* visiting a frameset page
|
|
|
|
*/
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_ASSERTION(loader, "No document loader");
|
|
|
|
if (loader) {
|
|
|
|
loader->FireOnLocationChange(webProgress, nsnull, aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-17 06:12:51 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetCharset(PRUnichar** aCharset)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCharset);
|
|
|
|
*aCharset = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
GetPresShell(getter_AddRefs(presShell));
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
presShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
|
|
|
nsAutoString charset;
|
|
|
|
NS_ENSURE_SUCCESS(doc->GetDocumentCharacterSet(charset), NS_ERROR_FAILURE);
|
2001-09-29 12:28:41 +04:00
|
|
|
*aCharset = ToNewUnicode(charset);
|
2001-05-17 06:12:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetCharset(const PRUnichar* aCharset)
|
|
|
|
{
|
|
|
|
// set the default charset
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
GetContentViewer(getter_AddRefs(viewer));
|
|
|
|
if (viewer) {
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muDV(do_QueryInterface(viewer));
|
|
|
|
if (muDV) {
|
|
|
|
NS_ENSURE_SUCCESS(muDV->SetDefaultCharacterSet(aCharset),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the charset override
|
|
|
|
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo;
|
|
|
|
GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
|
|
|
|
if (dcInfo) {
|
|
|
|
nsCOMPtr<nsIAtom> csAtom;
|
|
|
|
csAtom = dont_AddRef(NS_NewAtom(aCharset));
|
|
|
|
dcInfo->SetForcedCharset(csAtom);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetDocumentCharsetInfo(nsIDocumentCharsetInfo **
|
|
|
|
aDocumentCharsetInfo)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDocumentCharsetInfo);
|
|
|
|
|
|
|
|
// if the mDocumentCharsetInfo does not exist already, we create it now
|
|
|
|
if (!mDocumentCharsetInfo) {
|
|
|
|
nsresult res =
|
|
|
|
nsComponentManager::CreateInstance(kDocumentCharsetInfoCID,
|
|
|
|
NULL,
|
|
|
|
NS_GET_IID
|
|
|
|
(nsIDocumentCharsetInfo),
|
|
|
|
getter_AddRefs
|
|
|
|
(mDocumentCharsetInfo));
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-03-23 07:22:56 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aDocumentCharsetInfo = mDocumentCharsetInfo;
|
|
|
|
NS_IF_ADDREF(*aDocumentCharsetInfo);
|
|
|
|
return NS_OK;
|
2001-03-23 07:22:56 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetDocumentCharsetInfo(nsIDocumentCharsetInfo *
|
|
|
|
aDocumentCharsetInfo)
|
2001-03-23 07:22:56 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mDocumentCharsetInfo = aDocumentCharsetInfo;
|
|
|
|
return NS_OK;
|
2001-03-23 07:22:56 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetAllowPlugins(PRBool * aAllowPlugins)
|
2001-03-24 04:23:42 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aAllowPlugins);
|
2001-03-24 04:23:42 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aAllowPlugins = mAllowPlugins;
|
|
|
|
return NS_OK;
|
2001-03-24 04:23:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::SetAllowPlugins(PRBool aAllowPlugins)
|
2001-03-24 04:23:42 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mAllowPlugins = aAllowPlugins;
|
|
|
|
//XXX should enable or disable a plugin host
|
|
|
|
return NS_OK;
|
2001-03-24 04:23:42 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetAllowJavascript(PRBool * aAllowJavascript)
|
2001-04-22 02:22:15 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aAllowJavascript);
|
2001-04-22 02:22:15 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aAllowJavascript = mAllowJavascript;
|
|
|
|
return NS_OK;
|
2001-04-22 02:22:15 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetAllowJavascript(PRBool aAllowJavascript)
|
2001-04-22 02:22:15 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mAllowJavascript = aAllowJavascript;
|
|
|
|
return NS_OK;
|
2001-04-22 02:22:15 +04:00
|
|
|
}
|
2001-03-24 04:23:42 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::GetAllowMetaRedirects(PRBool * aReturn)
|
2001-03-23 07:22:56 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
|
|
|
|
*aReturn = mAllowMetaRedirects;
|
|
|
|
return NS_OK;
|
2001-03-23 07:22:56 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::SetAllowMetaRedirects(PRBool aValue)
|
2001-03-23 07:22:56 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mAllowMetaRedirects = aValue;
|
|
|
|
return NS_OK;
|
2001-03-23 07:22:56 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::GetAllowSubframes(PRBool * aAllowSubframes)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aAllowSubframes);
|
|
|
|
|
|
|
|
*aAllowSubframes = mAllowSubframes;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::SetAllowSubframes(PRBool aAllowSubframes)
|
|
|
|
{
|
|
|
|
mAllowSubframes = aAllowSubframes;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-05-22 02:42:46 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::GetAllowImages(PRBool * aAllowImages)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAllowImages);
|
|
|
|
|
|
|
|
*aAllowImages = mAllowImages;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetAllowImages(PRBool aAllowImages)
|
|
|
|
{
|
|
|
|
mAllowImages = aAllowImages;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-28 01:11:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetDocShellEnumerator(PRInt32 aItemType, PRInt32 aDirection, nsISimpleEnumerator **outEnum)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outEnum);
|
|
|
|
*outEnum = nsnull;
|
|
|
|
|
|
|
|
nsDocShellEnumerator* docShellEnum;
|
|
|
|
if (aDirection == ENUMERATE_FORWARDS)
|
|
|
|
docShellEnum = new nsDocShellForwardsEnumerator;
|
|
|
|
else
|
|
|
|
docShellEnum = new nsDocShellBackwardsEnumerator;
|
|
|
|
|
|
|
|
if (!docShellEnum) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv = docShellEnum->SetEnumDocShellType(aItemType);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = docShellEnum->SetEnumerationRootItem((nsIDocShellTreeItem *)this);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = docShellEnum->First();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
docShellEnum->AddRef(); // ensure we don't lose the last ref inside the QueryInterface
|
|
|
|
rv = docShellEnum->QueryInterface(NS_GET_IID(nsISimpleEnumerator), (void **)outEnum);
|
|
|
|
docShellEnum->Release();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetAppType(PRUint32 * aAppType)
|
|
|
|
{
|
|
|
|
*aAppType = mAppType;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetAppType(PRUint32 aAppType)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mAppType = aAppType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetZoom(float *zoom)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(zoom);
|
|
|
|
NS_ENSURE_SUCCESS(EnsureDeviceContext(), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(mDeviceContext->GetZoom(*zoom), NS_ERROR_FAILURE);
|
2000-03-08 06:58:33 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetZoom(float zoom)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(EnsureDeviceContext(), NS_ERROR_FAILURE);
|
|
|
|
mDeviceContext->SetZoom(zoom);
|
|
|
|
|
|
|
|
// get the pres shell
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// get the view manager
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
NS_ENSURE_SUCCESS(presShell->GetViewManager(getter_AddRefs(vm)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// get the root scrollable view
|
|
|
|
nsIScrollableView *scrollableView = nsnull;
|
|
|
|
vm->GetRootScrollableView(&scrollableView);
|
|
|
|
if (scrollableView)
|
|
|
|
scrollableView->ComputeScrollOffsets();
|
|
|
|
|
|
|
|
// get the root view
|
|
|
|
nsIView *rootView = nsnull; // views are not ref counted
|
|
|
|
vm->GetRootView(rootView);
|
|
|
|
if (rootView)
|
|
|
|
vm->UpdateView(rootView, 0);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetMarginWidth(PRInt32 * aWidth)
|
1999-11-19 10:35:27 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
1999-11-19 10:35:27 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aWidth = mMarginWidth;
|
|
|
|
return NS_OK;
|
1999-11-19 10:35:27 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetMarginWidth(PRInt32 aWidth)
|
1999-11-19 10:35:27 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mMarginWidth = aWidth;
|
|
|
|
return NS_OK;
|
1999-11-19 10:35:27 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetMarginHeight(PRInt32 * aHeight)
|
1999-11-19 10:35:27 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
1999-11-19 10:35:27 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aHeight = mMarginHeight;
|
|
|
|
return NS_OK;
|
1999-11-19 10:35:27 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetMarginHeight(PRInt32 aHeight)
|
1999-11-19 10:35:27 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mMarginHeight = aHeight;
|
|
|
|
return NS_OK;
|
1999-11-19 10:35:27 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetBusyFlags(PRUint32 * aBusyFlags)
|
2001-01-26 15:35:32 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aBusyFlags);
|
2001-01-26 15:35:32 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aBusyFlags = mBusyFlags;
|
|
|
|
return NS_OK;
|
2001-01-26 15:35:32 +03:00
|
|
|
}
|
|
|
|
|
2001-10-23 02:43:52 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::TabToTreeOwner(PRBool aForward, PRBool* aTookFocus)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTookFocus);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebBrowserChromeFocus> chromeFocus = do_GetInterface(mTreeOwner);
|
|
|
|
if (chromeFocus) {
|
|
|
|
*aTookFocus = PR_TRUE;
|
|
|
|
if (aForward)
|
|
|
|
chromeFocus->FocusNextElement();
|
|
|
|
else
|
|
|
|
chromeFocus->FocusPrevElement();
|
|
|
|
} else
|
|
|
|
*aTookFocus = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIDocShellTreeItem
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetName(PRUnichar ** aName)
|
1999-12-03 13:29:08 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aName);
|
2001-09-29 12:28:41 +04:00
|
|
|
*aName = ToNewUnicode(mName);
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetName(const PRUnichar * aName)
|
1999-12-03 13:29:08 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mName = aName; // this does a copy of aName
|
|
|
|
return NS_OK;
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
2001-10-20 15:42:35 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::NameEquals(const PRUnichar *aName, PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aName);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = mName.Equals(aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetItemType(PRInt32 * aItemType)
|
1999-12-03 13:29:08 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aItemType);
|
1999-12-03 13:29:08 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aItemType = mItemType;
|
|
|
|
return NS_OK;
|
1999-12-08 07:57:23 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetItemType(PRInt32 aItemType)
|
1999-12-08 07:57:23 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG((aItemType == typeChrome) || (typeContent == aItemType));
|
|
|
|
NS_ENSURE_STATE(!mParent);
|
2000-02-11 04:09:12 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mItemType = aItemType;
|
2000-02-11 04:09:12 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-12-08 07:57:23 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetParent(nsIDocShellTreeItem ** aParent)
|
1999-12-08 07:57:23 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
1999-12-08 07:57:23 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aParent = mParent;
|
|
|
|
NS_IF_ADDREF(*aParent);
|
1999-12-03 13:29:08 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetParent(nsIDocShellTreeItem * aParent)
|
1999-12-03 13:29:08 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// null aParent is ok
|
|
|
|
/*
|
|
|
|
Note this doesn't do an addref on purpose. This is because the parent
|
|
|
|
is an implied lifetime. We don't want to create a cycle by refcounting
|
|
|
|
the parent.
|
|
|
|
*/
|
|
|
|
mParent = aParent;
|
2000-04-16 12:39:15 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIURIContentListener>
|
|
|
|
parentURIListener(do_GetInterface(aParent));
|
|
|
|
if (parentURIListener)
|
|
|
|
SetParentURIContentListener(parentURIListener);
|
|
|
|
return NS_OK;
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetSameTypeParent(nsIDocShellTreeItem ** aParent)
|
1999-12-08 07:57:23 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
*aParent = nsnull;
|
1999-12-08 07:57:23 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (!mParent)
|
|
|
|
return NS_OK;
|
1999-12-08 07:57:23 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 parentType;
|
|
|
|
NS_ENSURE_SUCCESS(mParent->GetItemType(&parentType), NS_ERROR_FAILURE);
|
1999-12-03 13:29:08 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (parentType == mItemType) {
|
|
|
|
*aParent = mParent;
|
|
|
|
NS_ADDREF(*aParent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-12-08 07:57:23 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetRootTreeItem(nsIDocShellTreeItem ** aRootTreeItem)
|
1999-12-08 07:57:23 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aRootTreeItem);
|
|
|
|
*aRootTreeItem = NS_STATIC_CAST(nsIDocShellTreeItem *, this);
|
1999-12-08 07:57:23 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
NS_ENSURE_SUCCESS(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE);
|
|
|
|
while (parent) {
|
|
|
|
*aRootTreeItem = parent;
|
|
|
|
NS_ENSURE_SUCCESS((*aRootTreeItem)->GetParent(getter_AddRefs(parent)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
NS_ADDREF(*aRootTreeItem);
|
|
|
|
return NS_OK;
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetSameTypeRootTreeItem(nsIDocShellTreeItem ** aRootTreeItem)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRootTreeItem);
|
|
|
|
*aRootTreeItem = NS_STATIC_CAST(nsIDocShellTreeItem *, this);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parent)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
while (parent) {
|
|
|
|
*aRootTreeItem = parent;
|
|
|
|
NS_ENSURE_SUCCESS((*aRootTreeItem)->
|
|
|
|
GetSameTypeParent(getter_AddRefs(parent)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
NS_ADDREF(*aRootTreeItem);
|
|
|
|
return NS_OK;
|
1999-12-03 13:35:43 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::FindItemWithName(const PRUnichar * aName,
|
|
|
|
nsISupports * aRequestor,
|
|
|
|
nsIDocShellTreeItem ** _retval)
|
2000-06-24 03:54:30 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG(aName);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2000-06-24 03:54:30 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*_retval = nsnull; // if we don't find one, we return NS_OK and a null result
|
2000-06-24 03:54:30 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// This QI may fail, but the places where we want to compare, comparing
|
|
|
|
// against nsnull serves the same purpose.
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem>
|
|
|
|
reqAsTreeItem(do_QueryInterface(aRequestor));
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// First we check our name.
|
|
|
|
if (mName.EqualsWithConversion(aName)) {
|
|
|
|
*_retval = NS_STATIC_CAST(nsIDocShellTreeItem *, this);
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-07-19 01:55:37 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Second we check our children making sure not to ask a child if it
|
|
|
|
// is the aRequestor.
|
|
|
|
NS_ENSURE_SUCCESS(FindChildWithName(aName, PR_TRUE, PR_TRUE, reqAsTreeItem,
|
|
|
|
_retval), NS_ERROR_FAILURE);
|
|
|
|
if (*_retval)
|
|
|
|
return NS_OK;
|
2000-01-14 11:19:19 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Third if we have a parent and it isn't the requestor then we should ask
|
|
|
|
// it to do the search. If it is the requestor we should just stop here
|
|
|
|
// and let the parent do the rest.
|
|
|
|
// If we don't have a parent, then we should ask the docShellTreeOwner to do
|
|
|
|
// the search.
|
|
|
|
if (mParent) {
|
|
|
|
if (mParent == reqAsTreeItem.get())
|
|
|
|
return NS_OK;
|
2000-06-24 03:54:30 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 parentType;
|
|
|
|
mParent->GetItemType(&parentType);
|
|
|
|
if (parentType == mItemType) {
|
|
|
|
NS_ENSURE_SUCCESS(mParent->FindItemWithName(aName,
|
|
|
|
NS_STATIC_CAST
|
|
|
|
(nsIDocShellTreeItem *,
|
|
|
|
this), _retval),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// If the parent isn't of the same type fall through and ask tree owner.
|
|
|
|
}
|
2000-01-14 11:19:19 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// This QI may fail, but comparing against null serves the same purpose
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner>
|
|
|
|
reqAsTreeOwner(do_QueryInterface(aRequestor));
|
1999-12-03 13:29:08 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mTreeOwner && (mTreeOwner != reqAsTreeOwner.get())) {
|
|
|
|
NS_ENSURE_SUCCESS(mTreeOwner->FindItemWithName(aName,
|
|
|
|
NS_STATIC_CAST
|
|
|
|
(nsIDocShellTreeItem *,
|
|
|
|
this), _retval),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
1999-12-03 13:29:08 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::GetTreeOwner(nsIDocShellTreeOwner ** aTreeOwner)
|
2000-07-06 03:10:29 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aTreeOwner);
|
|
|
|
|
|
|
|
*aTreeOwner = mTreeOwner;
|
|
|
|
NS_IF_ADDREF(*aTreeOwner);
|
|
|
|
return NS_OK;
|
2000-07-06 03:10:29 +04:00
|
|
|
}
|
|
|
|
|
2001-05-23 03:52:17 +04:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
static void
|
|
|
|
PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel)
|
|
|
|
{
|
|
|
|
for (PRInt32 i=0;i<aLevel;i++) printf(" ");
|
|
|
|
|
|
|
|
PRInt32 childWebshellCount;
|
|
|
|
aParentNode->GetChildCount(&childWebshellCount);
|
|
|
|
nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(aParentNode));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(aParentNode));
|
|
|
|
PRInt32 type;
|
|
|
|
parentAsItem->GetItemType(&type);
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
parentAsDocShell->GetPresShell(getter_AddRefs(presShell));
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
parentAsDocShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
presShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
doc->GetScriptGlobalObject(getter_AddRefs(sgo));
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domwin(do_QueryInterface(sgo));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
presShell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
if (vm) {
|
|
|
|
vm->GetWidget(getter_AddRefs(widget));
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
presContext->GetEventStateManager(getter_AddRefs(esm));
|
2001-06-20 07:27:48 +04:00
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
doc->GetRootContent(getter_AddRefs(rootContent));
|
2001-05-23 03:52:17 +04:00
|
|
|
|
|
|
|
printf("DS %p Ty %s Doc %p DW %p EM %p CN %p\n",
|
|
|
|
parentAsDocShell.get(),
|
|
|
|
type==nsIDocShellTreeItem::typeChrome?"Chr":"Con",
|
|
|
|
doc.get(), domwin.get(), esm.get(), rootContent.get());
|
|
|
|
|
|
|
|
if (childWebshellCount > 0) {
|
|
|
|
for (PRInt32 i=0;i<childWebshellCount;i++) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> child;
|
|
|
|
aParentNode->GetChildAt(i, getter_AddRefs(child));
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> childAsNode(do_QueryInterface(child));
|
|
|
|
PrintDocTree(childAsNode, aLevel+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
PrintDocTree(nsIDocShellTreeNode * aParentNode)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aParentNode, "Pointer is null!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(aParentNode));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
item->GetParent(getter_AddRefs(parentItem));
|
|
|
|
while (parentItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem>tmp;
|
|
|
|
parentItem->GetParent(getter_AddRefs(tmp));
|
|
|
|
if (!tmp) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parentItem = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parentItem) {
|
|
|
|
parentItem = do_QueryInterface(aParentNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parentItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(parentItem));
|
|
|
|
PrintDocTree(parentAsNode, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner)
|
2000-07-06 03:10:29 +04:00
|
|
|
{
|
2001-05-23 03:52:17 +04:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> node(do_QueryInterface(aTreeOwner));
|
|
|
|
if (node) {
|
|
|
|
PrintDocTree(node);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Don't automatically set the progress based on the tree owner for frames
|
|
|
|
if (!IsFrame()) {
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
|
|
|
|
|
|
|
if (webProgress) {
|
|
|
|
nsCOMPtr<nsIWebProgressListener>
|
|
|
|
oldListener(do_QueryInterface(mTreeOwner));
|
|
|
|
nsCOMPtr<nsIWebProgressListener>
|
|
|
|
newListener(do_QueryInterface(aTreeOwner));
|
2000-07-06 03:10:29 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (oldListener) {
|
|
|
|
webProgress->RemoveProgressListener(oldListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newListener) {
|
|
|
|
webProgress->AddProgressListener(newListener);
|
|
|
|
}
|
|
|
|
}
|
2000-07-06 03:10:29 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mTreeOwner = aTreeOwner; // Weak reference per API
|
|
|
|
|
|
|
|
PRInt32 i, n = mChildren.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIDocShellTreeItem *child = (nsIDocShellTreeItem *) mChildren.ElementAt(i); // doesn't addref the result
|
|
|
|
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
|
|
|
|
PRInt32 childType = ~mItemType; // Set it to not us in case the get fails
|
|
|
|
child->GetItemType(&childType); // We don't care if this fails, if it does we won't set the owner
|
|
|
|
if (childType == mItemType)
|
|
|
|
child->SetTreeOwner(aTreeOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-07-06 03:10:29 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetChildOffset(PRInt32 aChildOffset)
|
2000-07-19 01:55:37 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mChildOffset = aChildOffset;
|
2000-07-19 01:55:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetChildOffset(PRInt32 * aChildOffset)
|
2000-07-19 01:55:37 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aChildOffset);
|
|
|
|
*aChildOffset = mChildOffset;
|
2000-07-19 01:55:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-07-06 03:10:29 +04:00
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
//*****************************************************************************
|
2001-04-27 17:38:15 +04:00
|
|
|
// nsDocShell::nsIDocShellTreeNode
|
2000-02-14 09:40:28 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetChildCount(PRInt32 * aChildCount)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChildCount);
|
|
|
|
*aChildCount = mChildren.Count();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChild);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE);
|
|
|
|
mChildren.AppendElement(aChild);
|
|
|
|
NS_ADDREF(aChild);
|
|
|
|
|
|
|
|
// Set the child's index in the parent's children list
|
|
|
|
// XXX What if the parent had different types of children?
|
|
|
|
// XXX in that case docshell hierarchyand SH hierarchy won't match.
|
|
|
|
PRInt32 childCount = mChildren.Count();
|
|
|
|
aChild->SetChildOffset(childCount - 1);
|
|
|
|
|
|
|
|
/* Set the child's global history if the parent has one */
|
|
|
|
if (mGlobalHistory) {
|
|
|
|
nsCOMPtr<nsIDocShellHistory>
|
|
|
|
dsHistoryChild(do_QueryInterface(aChild));
|
|
|
|
if (dsHistoryChild)
|
|
|
|
dsHistoryChild->SetGlobalHistory(mGlobalHistory);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRInt32 childType = ~mItemType; // Set it to not us in case the get fails
|
|
|
|
aChild->GetItemType(&childType);
|
|
|
|
if (childType != mItemType)
|
|
|
|
return NS_OK;
|
|
|
|
// Everything below here is only done when the child is the same type.
|
|
|
|
|
|
|
|
|
|
|
|
aChild->SetTreeOwner(mTreeOwner);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> childAsDocShell(do_QueryInterface(aChild));
|
|
|
|
if (!childAsDocShell)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Do some docShell Specific stuff.
|
|
|
|
nsXPIDLString defaultCharset;
|
|
|
|
nsXPIDLString forceCharset;
|
|
|
|
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muDV =
|
|
|
|
do_QueryInterface(mContentViewer);
|
|
|
|
if (muDV) {
|
|
|
|
NS_ENSURE_SUCCESS(muDV->
|
|
|
|
GetDefaultCharacterSet(getter_Copies(defaultCharset)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(muDV->
|
|
|
|
GetForceCharacterSet(getter_Copies(forceCharset)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContentViewer> childCV;
|
|
|
|
NS_ENSURE_SUCCESS(childAsDocShell->
|
|
|
|
GetContentViewer(getter_AddRefs(childCV)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (childCV) {
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> childmuDV =
|
|
|
|
do_QueryInterface(childCV);
|
|
|
|
if (childmuDV) {
|
|
|
|
NS_ENSURE_SUCCESS(childmuDV->SetDefaultCharacterSet(defaultCharset),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(childmuDV->SetForceCharacterSet(forceCharset),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now take this document's charset and set the parentCharset field of the
|
|
|
|
// child's DocumentCharsetInfo to it. We'll later use that field, in the
|
|
|
|
// loading process, for the charset choosing algorithm.
|
|
|
|
// If we fail, at any point, we just return NS_OK.
|
|
|
|
// This code has some performance impact. But this will be reduced when
|
|
|
|
// the current charset will finally be stored as an Atom, avoiding the
|
|
|
|
// alias resolution extra look-up.
|
|
|
|
|
|
|
|
// we are NOT going to propagate the charset is this Chrome's docshell
|
|
|
|
if (mItemType == nsIDocShellTreeItem::typeChrome)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
|
|
|
// get the child's docCSInfo object
|
|
|
|
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo = NULL;
|
|
|
|
res = childAsDocShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
|
|
|
|
if (NS_FAILED(res) || (!dcInfo))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// get the parent's current charset
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
|
|
|
|
if (!docv)
|
|
|
|
return NS_OK;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
res = docv->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (NS_FAILED(res) || (!doc))
|
|
|
|
return NS_OK;
|
|
|
|
nsAutoString parentCS;
|
|
|
|
res = doc->GetDocumentCharacterSet(parentCS);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// set the child's parentCharset
|
|
|
|
nsCOMPtr<nsIAtom> parentCSAtom(dont_AddRef(NS_NewAtom(parentCS)));
|
|
|
|
res = dcInfo->SetParentCharset(parentCSAtom);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-12-26 06:17:59 +03:00
|
|
|
PRInt32 charsetSource;
|
|
|
|
res = doc->GetDocumentCharacterSetSource(&charsetSource);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// set the child's parentCharset
|
|
|
|
res = dcInfo->SetParentCharsetSource(charsetSource);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
// printf("### 1 >>> Adding child. Parent CS = %s. ItemType = %d.\n", NS_LossyConvertUCS2toASCII(parentCS).get(), mItemType);
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::RemoveChild(nsIDocShellTreeItem * aChild)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChild);
|
|
|
|
|
|
|
|
if (mChildren.RemoveElement(aChild)) {
|
|
|
|
aChild->SetParent(nsnull);
|
|
|
|
aChild->SetTreeOwner(nsnull);
|
|
|
|
NS_RELEASE(aChild);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShellTreeItem ** aChild)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChild);
|
|
|
|
|
2001-12-21 04:10:07 +03:00
|
|
|
NS_ASSERTION(aIndex >= 0 && aIndex < mChildren.Count(),"Bad docshell ChildAt index");
|
2001-04-27 17:38:15 +04:00
|
|
|
*aChild = (nsIDocShellTreeItem *) mChildren.ElementAt(aIndex);
|
|
|
|
NS_IF_ADDREF(*aChild);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::FindChildWithName(const PRUnichar * aName,
|
|
|
|
PRBool aRecurse, PRBool aSameType,
|
|
|
|
nsIDocShellTreeItem * aRequestor,
|
|
|
|
nsIDocShellTreeItem ** _retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aName);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
*_retval = nsnull; // if we don't find one, we return NS_OK and a null result
|
|
|
|
|
|
|
|
nsXPIDLString childName;
|
|
|
|
PRInt32 i, n = mChildren.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIDocShellTreeItem *child = (nsIDocShellTreeItem *) mChildren.ElementAt(i); // doesn't addref the result
|
|
|
|
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
|
|
|
|
PRInt32 childType;
|
|
|
|
child->GetItemType(&childType);
|
|
|
|
|
|
|
|
if (aSameType && (childType != mItemType))
|
|
|
|
continue;
|
|
|
|
|
2001-10-20 15:42:35 +04:00
|
|
|
PRBool childNameEquals = PR_FALSE;
|
|
|
|
child->NameEquals(aName, &childNameEquals);
|
|
|
|
if (childNameEquals) {
|
2001-04-27 17:38:15 +04:00
|
|
|
*_retval = child;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childType != mItemType) //Only ask it to check children if it is same type
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (aRecurse && (aRequestor != child)) // Only ask the child if it isn't the requestor
|
|
|
|
{
|
|
|
|
// See if child contains the shell with the given name
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode>
|
|
|
|
childAsNode(do_QueryInterface(child));
|
|
|
|
if (child) {
|
|
|
|
NS_ENSURE_SUCCESS(childAsNode->FindChildWithName(aName, PR_TRUE,
|
|
|
|
aSameType,
|
|
|
|
NS_STATIC_CAST
|
|
|
|
(nsIDocShellTreeItem
|
|
|
|
*, this),
|
|
|
|
_retval),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*_retval) // found it
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIDocShellHistory
|
|
|
|
//*****************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetChildSHEntry(PRInt32 aChildOffset, nsISHEntry ** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
2001-09-08 02:06:08 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// A nsISHEntry for a child is *only* available when the parent is in
|
|
|
|
// the progress of loading a document too...
|
2001-10-26 23:04:11 +04:00
|
|
|
|
2001-07-03 04:00:12 +04:00
|
|
|
if (mLSHE) {
|
2001-10-10 00:51:38 +04:00
|
|
|
/* Before looking for the subframe's url, check
|
|
|
|
* the expiration status of the parent. If the parent
|
|
|
|
* has expired from cache, then subframes will not be
|
2001-10-26 23:04:11 +04:00
|
|
|
* loaded from history in certain situations.
|
2001-10-10 00:51:38 +04:00
|
|
|
*/
|
|
|
|
PRBool parentExpired=PR_FALSE;
|
|
|
|
mLSHE->GetExpirationStatus(&parentExpired);
|
2001-10-26 23:04:11 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
/* Get the parent's Load Type so that it can be set on the child too.
|
|
|
|
* By default give a loadHistory value
|
|
|
|
*/
|
|
|
|
PRUint32 loadType = nsIDocShellLoadInfo::loadHistory;
|
2001-10-26 23:04:11 +04:00
|
|
|
mLSHE->GetLoadType(&loadType);
|
2001-09-08 02:06:08 +04:00
|
|
|
// If the user did a shift-reload on this frameset page,
|
|
|
|
// we don't want to load the subframes from history.
|
|
|
|
if (loadType == nsIDocShellLoadInfo::loadReloadBypassCache ||
|
|
|
|
loadType == nsIDocShellLoadInfo::loadReloadBypassProxy ||
|
|
|
|
loadType == nsIDocShellLoadInfo::loadReloadBypassProxyAndCache)
|
|
|
|
return rv;
|
2001-10-26 23:04:11 +04:00
|
|
|
|
|
|
|
/* If the user pressed reload and the parent frame has expired
|
|
|
|
* from cache, we do not want to load the child frame from history.
|
|
|
|
*/
|
|
|
|
if (parentExpired && (loadType == nsIDocShellLoadInfo::loadReloadNormal)) {
|
|
|
|
// The parent has expired. Return null.
|
|
|
|
*aResult = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-07-03 04:00:12 +04:00
|
|
|
nsCOMPtr<nsISHContainer> container(do_QueryInterface(mLSHE));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (container) {
|
2001-10-10 00:51:38 +04:00
|
|
|
// Get the child subframe from session history.
|
|
|
|
rv = container->GetChildAt(aChildOffset, aResult);
|
|
|
|
if (*aResult)
|
|
|
|
(*aResult)->SetLoadType(loadType);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry,
|
|
|
|
PRInt32 aChildOffset)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2001-07-03 04:00:12 +04:00
|
|
|
if (mLSHE) {
|
2001-04-27 17:38:15 +04:00
|
|
|
/* You get here if you are currently building a
|
|
|
|
* hierarchy ie.,you just visited a frameset page
|
|
|
|
*/
|
2001-07-03 04:00:12 +04:00
|
|
|
nsCOMPtr<nsISHContainer> container(do_QueryInterface(mLSHE, &rv));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (container) {
|
|
|
|
rv = container->AddChild(aNewEntry, aChildOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mSessionHistory) {
|
|
|
|
/* You are currently in the rootDocShell.
|
|
|
|
* You will get here when a subframe has a new url
|
|
|
|
* to load and you have walked up the tree all the
|
|
|
|
* way to the top to clone the current SHEntry hierarchy
|
|
|
|
* and replace the subframe where a new url was loaded with
|
|
|
|
* a new entry.
|
|
|
|
*/
|
|
|
|
PRInt32 index = -1;
|
|
|
|
nsCOMPtr<nsIHistoryEntry> currentHE;
|
|
|
|
mSessionHistory->GetIndex(&index);
|
|
|
|
if (index < 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = mSessionHistory->GetEntryAtIndex(index, PR_FALSE,
|
|
|
|
getter_AddRefs(currentHE));
|
|
|
|
NS_ENSURE_TRUE(currentHE, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHEntry> currentEntry(do_QueryInterface(currentHE));
|
|
|
|
if (currentEntry) {
|
|
|
|
PRUint32 cloneID = 0;
|
|
|
|
nsCOMPtr<nsISHEntry> nextEntry; //(do_CreateInstance(NS_SHENTRY_CONTRACTID));
|
|
|
|
// NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
|
|
|
|
if (aCloneRef)
|
|
|
|
aCloneRef->GetID(&cloneID);
|
|
|
|
rv = CloneAndReplace(currentEntry, cloneID, aNewEntry,
|
|
|
|
getter_AddRefs(nextEntry));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsISHistoryInternal>
|
|
|
|
shPrivate(do_QueryInterface(mSessionHistory));
|
|
|
|
NS_ENSURE_TRUE(shPrivate, NS_ERROR_FAILURE);
|
|
|
|
rv = shPrivate->AddEntry(nextEntry, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* You will get here when you are in a subframe and
|
|
|
|
* a new url has been loaded on you.
|
2001-07-03 04:00:12 +04:00
|
|
|
* The mOSHE in this subframe will be the previous url's
|
|
|
|
* mOSHE. This mOSHE will be used as the identification
|
2001-04-27 17:38:15 +04:00
|
|
|
* for this subframe in the CloneAndReplace function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellHistory> parent(do_QueryInterface(mParent, &rv));
|
|
|
|
if (parent) {
|
|
|
|
if (!aCloneRef) {
|
2001-07-03 04:00:12 +04:00
|
|
|
aCloneRef = mOSHE;
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
rv = parent->AddChildSHEntry(aCloneRef, aNewEntry, aChildOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetGlobalHistory(nsIGlobalHistory * aGlobalHistory)
|
|
|
|
{
|
|
|
|
mGlobalHistory = aGlobalHistory;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetGlobalHistory(nsIGlobalHistory ** aGlobalHistory)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aGlobalHistory);
|
|
|
|
|
|
|
|
*aGlobalHistory = mGlobalHistory;
|
|
|
|
NS_IF_ADDREF(*aGlobalHistory);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIWebNavigation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetCanGoBack(PRBool * aCanGoBack)
|
|
|
|
{
|
2001-11-20 23:14:02 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISHistory> rootSH;
|
|
|
|
rv = GetRootSessionHistory(getter_AddRefs(rootSH));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(rootSH));
|
|
|
|
NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE);
|
|
|
|
rv = webnav->GetCanGoBack(aCanGoBack);
|
|
|
|
return rv;
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2000-06-24 03:54:30 +04:00
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::GetCanGoForward(PRBool * aCanGoForward)
|
2000-06-24 03:54:30 +04:00
|
|
|
{
|
2001-11-20 23:14:02 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISHistory> rootSH;
|
|
|
|
rv = GetRootSessionHistory(getter_AddRefs(rootSH));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(rootSH));
|
|
|
|
NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE);
|
|
|
|
rv = webnav->GetCanGoForward(aCanGoForward);
|
|
|
|
return rv;
|
2000-06-24 03:54:30 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-07-13 03:31:31 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GoBack()
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2001-11-20 23:14:02 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISHistory> rootSH;
|
|
|
|
rv = GetRootSessionHistory(getter_AddRefs(rootSH));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(rootSH));
|
|
|
|
NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE);
|
|
|
|
rv = webnav->GoBack();
|
|
|
|
return rv;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-04-12 03:52:42 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GoForward()
|
|
|
|
{
|
2001-11-20 23:14:02 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISHistory> rootSH;
|
|
|
|
rv = GetRootSessionHistory(getter_AddRefs(rootSH));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(rootSH));
|
|
|
|
NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE);
|
|
|
|
rv = webnav->GoForward();
|
|
|
|
return rv;
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::GotoIndex(PRInt32 aIndex)
|
|
|
|
{
|
2001-11-20 23:14:02 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISHistory> rootSH;
|
|
|
|
rv = GetRootSessionHistory(getter_AddRefs(rootSH));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(rootSH));
|
|
|
|
NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE);
|
|
|
|
rv = webnav->GotoIndex(aIndex);
|
|
|
|
return rv;
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-04-13 07:11:44 +04:00
|
|
|
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
2001-12-01 01:35:33 +03:00
|
|
|
nsDocShell::LoadURI(const PRUnichar * aURI,
|
|
|
|
PRUint32 aLoadFlags,
|
|
|
|
nsIURI * aReferingURI,
|
|
|
|
nsIInputStream * aPostStream,
|
|
|
|
nsIInputStream * aHeaderStream)
|
2001-04-27 17:38:15 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv = CreateFixupURI(aURI, getter_AddRefs(uri));
|
|
|
|
|
|
|
|
if (NS_ERROR_UNKNOWN_PROTOCOL == rv) {
|
|
|
|
// we weren't able to find a protocol handler
|
|
|
|
nsCOMPtr<nsIPrompt> prompter;
|
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
|
|
|
GetPromptAndStringBundle(getter_AddRefs(prompter),
|
|
|
|
getter_AddRefs(stringBundle));
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(stringBundle, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsXPIDLString messageStr;
|
|
|
|
NS_ENSURE_SUCCESS(stringBundle->
|
2001-11-14 16:26:43 +03:00
|
|
|
GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("protocolNotFound").get(),
|
|
|
|
getter_Copies(messageStr)),
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsAutoString uriString(aURI);
|
|
|
|
PRInt32 colon = uriString.FindChar(':');
|
|
|
|
// extract the scheme
|
|
|
|
nsAutoString scheme;
|
|
|
|
uriString.Left(scheme, colon);
|
|
|
|
nsCAutoString cScheme;
|
|
|
|
cScheme.AssignWithConversion(scheme);
|
|
|
|
|
|
|
|
PRUnichar *msg = nsTextFormatter::smprintf(messageStr, cScheme.get());
|
|
|
|
if (!msg)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
prompter->Alert(nsnull, msg);
|
|
|
|
nsTextFormatter::smprintf_free(msg);
|
|
|
|
} // end unknown protocol
|
2001-11-14 16:26:43 +03:00
|
|
|
else if (NS_ERROR_MALFORMED_URI == rv) {
|
|
|
|
// malformed URI
|
|
|
|
nsCOMPtr<nsIPrompt> prompter;
|
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
|
|
|
GetPromptAndStringBundle(getter_AddRefs(prompter),
|
|
|
|
getter_AddRefs(stringBundle));
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(stringBundle, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsXPIDLString messageStr;
|
|
|
|
NS_ENSURE_SUCCESS(stringBundle->
|
|
|
|
GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("malformedURI").get(),
|
|
|
|
getter_Copies(messageStr)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
prompter->Alert(nsnull, messageStr.get());
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2001-11-18 10:45:14 +03:00
|
|
|
if (NS_FAILED(rv) || !uri)
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-12-01 01:35:33 +03:00
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
|
|
|
rv = CreateLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
loadInfo->SetLoadType(ConvertLoadTypeToDocShellLoadInfo(aLoadFlags));
|
|
|
|
loadInfo->SetPostDataStream(aPostStream);
|
|
|
|
|
|
|
|
// XXX: Need to pass in the extra headers stream too...
|
|
|
|
// XXX: Need to pass in referer...
|
|
|
|
|
|
|
|
rv = LoadURI(uri, loadInfo, 0);
|
|
|
|
return rv;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::Reload(PRUint32 aReloadFlags)
|
2000-09-20 16:23:53 +04:00
|
|
|
{
|
2001-06-30 02:12:14 +04:00
|
|
|
NS_ASSERTION(((aReloadFlags & 0xf) == 0),
|
|
|
|
"Reload command not updated to use load flags!");
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// XXXTAB Convert reload type to our type
|
2001-06-30 02:12:14 +04:00
|
|
|
LoadType type = LOAD_RELOAD_NORMAL;
|
2001-04-27 17:38:15 +04:00
|
|
|
if (aReloadFlags & LOAD_FLAGS_BYPASS_CACHE &&
|
2001-06-30 02:12:14 +04:00
|
|
|
aReloadFlags & LOAD_FLAGS_BYPASS_PROXY)
|
2001-04-27 17:38:15 +04:00
|
|
|
type = LOAD_RELOAD_BYPASS_PROXY_AND_CACHE;
|
2001-06-30 02:12:14 +04:00
|
|
|
else if (aReloadFlags & LOAD_FLAGS_CHARSET_CHANGE)
|
|
|
|
type = LOAD_RELOAD_CHARSET_CHANGE;
|
2000-07-18 00:12:27 +04:00
|
|
|
|
2001-03-24 03:45:56 +03:00
|
|
|
nsresult rv;
|
2001-04-27 17:38:15 +04:00
|
|
|
/* If you change this part of code, make sure bug 45297 does not re-occur */
|
2001-07-03 04:00:12 +04:00
|
|
|
if (mOSHE)
|
|
|
|
rv = LoadHistoryEntry(mOSHE, type);
|
|
|
|
else if (mLSHE) // In case a reload happened before the current load is done
|
|
|
|
rv = LoadHistoryEntry(mLSHE, type);
|
2001-04-27 17:38:15 +04:00
|
|
|
else
|
2001-05-14 06:16:27 +04:00
|
|
|
rv = InternalLoad(mCurrentURI,
|
|
|
|
mReferrerURI,
|
|
|
|
nsnull, // No owner
|
|
|
|
PR_TRUE, // Inherit owner from document
|
|
|
|
nsnull, // No window target
|
|
|
|
nsnull, // No post data
|
|
|
|
nsnull, // No headers data
|
|
|
|
type, // Load type
|
|
|
|
nsnull); // No SHEntry
|
2001-04-27 17:38:15 +04:00
|
|
|
return rv;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
2001-08-14 08:46:20 +04:00
|
|
|
nsDocShell::Stop(PRUint32 aStopFlags)
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2001-08-14 08:46:20 +04:00
|
|
|
if (nsIWebNavigation::STOP_CONTENT & aStopFlags) {
|
|
|
|
if (mContentViewer)
|
|
|
|
mContentViewer->Stop();
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-08-14 08:46:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsIWebNavigation::STOP_NETWORK & aStopFlags) {
|
|
|
|
// Cancel any timers that were set for this loader.
|
|
|
|
CancelRefreshURITimers();
|
2000-02-14 13:27:32 +03:00
|
|
|
|
2001-08-14 08:46:20 +04:00
|
|
|
if (mLoadCookie) {
|
|
|
|
nsCOMPtr<nsIURILoader> uriLoader;
|
|
|
|
|
|
|
|
uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID);
|
|
|
|
if (uriLoader)
|
|
|
|
uriLoader->Stop(mLoadCookie);
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-02-14 13:27:32 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 n;
|
|
|
|
PRInt32 count = mChildren.Count();
|
|
|
|
for (n = 0; n < count; n++) {
|
|
|
|
nsIDocShellTreeItem *shell =
|
|
|
|
(nsIDocShellTreeItem *) mChildren.ElementAt(n);
|
|
|
|
nsCOMPtr<nsIWebNavigation> shellAsNav(do_QueryInterface(shell));
|
|
|
|
if (shellAsNav)
|
2001-08-14 08:46:20 +04:00
|
|
|
shellAsNav->Stop(aStopFlags);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-02-14 13:27:32 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
/*
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::SetDocument(nsIDOMDocument* aDocument,
|
|
|
|
const PRUnichar* aContentType)
|
|
|
|
{
|
|
|
|
//XXX First Checkin
|
|
|
|
NS_ERROR("Not Yet Implemented");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-08-25 22:39:46 +04:00
|
|
|
*/
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetDocument(nsIDOMDocument ** aDocument)
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aDocument);
|
2002-01-05 05:22:45 +03:00
|
|
|
NS_ENSURE_SUCCESS(EnsureContentViewer(), NS_ERROR_FAILURE);
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return mContentViewer->GetDOMDocument(aDocument);
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
2000-08-30 15:32:30 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetCurrentURI(nsIURI ** aURI)
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2000-02-17 05:03:02 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aURI = mCurrentURI;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2001-12-01 01:35:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetReferingURI(nsIURI ** aURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
*aURI = mReferrerURI;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetSessionHistory(nsISHistory * aSessionHistory)
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2000-07-01 02:05:32 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_TRUE(aSessionHistory, NS_ERROR_FAILURE);
|
2000-09-02 01:29:48 +04:00
|
|
|
// make sure that we are the root docshell and
|
|
|
|
// set a handle to root docshell in SH.
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2000-09-02 01:29:48 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
/* Get the root docshell. If *this* is the root docshell
|
|
|
|
* then save a handle to *this* in SH. SH needs it to do
|
|
|
|
* traversions thro' its entries
|
|
|
|
*/
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
|
|
|
if (root.get() == NS_STATIC_CAST(nsIDocShellTreeItem *, this)) {
|
2001-04-27 17:38:15 +04:00
|
|
|
mSessionHistory = aSessionHistory;
|
|
|
|
nsCOMPtr<nsISHistoryInternal>
|
|
|
|
shPrivate(do_QueryInterface(mSessionHistory));
|
|
|
|
NS_ENSURE_TRUE(shPrivate, NS_ERROR_FAILURE);
|
|
|
|
shPrivate->SetRootDocShell(this);
|
|
|
|
return NS_OK;
|
2000-09-02 01:29:48 +04:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-07-01 02:05:32 +04:00
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2001-11-20 23:14:02 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetSessionHistory(nsISHistory ** aSessionHistory)
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aSessionHistory);
|
|
|
|
if (mSessionHistory) {
|
|
|
|
*aSessionHistory = mSessionHistory;
|
|
|
|
NS_IF_ADDREF(*aSessionHistory);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-09-02 01:29:48 +04:00
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
2000-08-25 22:39:46 +04:00
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
1999-11-17 11:45:28 +03:00
|
|
|
// nsDocShell::nsIBaseWindow
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::InitWindow(nativeWindow parentNativeWindow,
|
|
|
|
nsIWidget * parentWidget, PRInt32 x, PRInt32 y,
|
|
|
|
PRInt32 cx, PRInt32 cy)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG(parentWidget); // DocShells must get a widget for a parent
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
SetParentWidget(parentWidget);
|
|
|
|
SetPositionAndSize(x, y, cx, cy, PR_FALSE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::Create()
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_STATE(!mContentViewer);
|
|
|
|
mPrefs = do_GetService(NS_PREF_CONTRACTID);
|
|
|
|
//GlobalHistory is now set in SetGlobalHistory
|
|
|
|
// mGlobalHistory = do_GetService(NS_GLOBALHISTORY_CONTRACTID);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// i don't want to read this pref in every time we load a url
|
|
|
|
// so read it in once here and be done with it...
|
|
|
|
mPrefs->GetBoolPref("network.protocols.useSystemDefaults",
|
|
|
|
&mUseExternalProtocolHandler);
|
|
|
|
mPrefs->GetBoolPref("browser.target_new_blocked", &mDisallowPopupWindows);
|
|
|
|
mPrefs->GetBoolPref("browser.frames.enabled", &mAllowSubframes);
|
2000-06-23 08:44:36 +04:00
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
// Check pref to see if we should prevent frameset spoofing
|
|
|
|
mPrefs->GetBoolPref("browser.frame.validate_origin", &mValidateOrigin);
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::Destroy()
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-07-18 00:17:38 +04:00
|
|
|
//Fire unload event before we blow anything away.
|
|
|
|
(void) FireUnloadNotification();
|
|
|
|
|
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 20:46:42 +04:00
|
|
|
mIsBeingDestroyed = PR_TRUE;
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Stop any URLs that are currently being loaded...
|
2001-08-14 08:46:20 +04:00
|
|
|
Stop(nsIWebNavigation::STOP_ALL);
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mDocLoader) {
|
|
|
|
mDocLoader->Destroy();
|
|
|
|
mDocLoader->SetContainer(nsnull);
|
|
|
|
}
|
2000-03-31 04:15:17 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Save the state of the current document, before destroying the window.
|
|
|
|
// This is needed to capture the state of a frameset when the new document
|
|
|
|
// causes the frameset to be destroyed...
|
|
|
|
PersistLayoutHistoryState();
|
|
|
|
|
|
|
|
// Remove this docshell from its parent's child list
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode>
|
|
|
|
docShellParentAsNode(do_QueryInterface(mParent));
|
|
|
|
if (docShellParentAsNode)
|
|
|
|
docShellParentAsNode->RemoveChild(this);
|
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
if (mContentViewer) {
|
2001-08-01 07:15:50 +04:00
|
|
|
mContentViewer->Close();
|
2001-03-10 06:19:36 +03:00
|
|
|
mContentViewer->Destroy();
|
|
|
|
mContentViewer = nsnull;
|
|
|
|
}
|
2000-03-31 05:19:28 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
DestroyChildren();
|
2000-03-31 04:15:17 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mDocLoader = nsnull;
|
|
|
|
mParentWidget = nsnull;
|
|
|
|
mPrefs = nsnull;
|
|
|
|
mCurrentURI = nsnull;
|
2000-03-25 06:43:27 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mScriptGlobal) {
|
|
|
|
mScriptGlobal->SetDocShell(nsnull);
|
2001-05-25 12:49:03 +04:00
|
|
|
mScriptGlobal->SetGlobalObjectOwner(nsnull);
|
2001-04-27 17:38:15 +04:00
|
|
|
mScriptGlobal = nsnull;
|
|
|
|
}
|
|
|
|
if (mScriptContext) {
|
|
|
|
mScriptContext->SetOwner(nsnull);
|
|
|
|
mScriptContext = nsnull;
|
|
|
|
}
|
2000-03-25 06:43:27 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mSessionHistory = nsnull;
|
|
|
|
SetTreeOwner(nsnull);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
SetLoadCookie(nsnull);
|
2000-06-20 11:59:45 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mContentListener) {
|
|
|
|
mContentListener->DocShell(nsnull);
|
2001-12-03 15:42:49 +03:00
|
|
|
mContentListener->SetParentContentListener(nsnull);
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_RELEASE(mContentListener);
|
|
|
|
}
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetPosition(PRInt32 x, PRInt32 y)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2002-01-08 16:01:38 +03:00
|
|
|
mBounds.x = x;
|
|
|
|
mBounds.y = y;
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mContentViewer)
|
|
|
|
NS_ENSURE_SUCCESS(mContentViewer->Move(x, y), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetPosition(PRInt32 * aX, PRInt32 * aY)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 dummyHolder;
|
|
|
|
return GetPositionAndSize(aX, aY, &dummyHolder, &dummyHolder);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetSize(PRInt32 aCX, PRInt32 aCY, PRBool aRepaint)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 x = 0, y = 0;
|
|
|
|
GetPosition(&x, &y);
|
|
|
|
return SetPositionAndSize(x, y, aCX, aCY, aRepaint);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetSize(PRInt32 * aCX, PRInt32 * aCY)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 dummyHolder;
|
|
|
|
return GetPositionAndSize(&dummyHolder, &dummyHolder, aCX, aCY);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx,
|
|
|
|
PRInt32 cy, PRBool fRepaint)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2002-01-08 16:01:38 +03:00
|
|
|
mBounds.x = x;
|
|
|
|
mBounds.y = y;
|
|
|
|
mBounds.width = cx;
|
|
|
|
mBounds.height = cy;
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mContentViewer) {
|
|
|
|
//XXX Border figured in here or is that handled elsewhere?
|
2002-01-08 16:01:38 +03:00
|
|
|
NS_ENSURE_SUCCESS(mContentViewer->SetBounds(mBounds), NS_ERROR_FAILURE);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetPositionAndSize(PRInt32 * x, PRInt32 * y, PRInt32 * cx,
|
|
|
|
PRInt32 * cy)
|
1999-11-29 10:47:20 +03:00
|
|
|
{
|
2002-01-08 16:01:38 +03:00
|
|
|
if (x)
|
|
|
|
*x = mBounds.x;
|
|
|
|
if (y)
|
|
|
|
*y = mBounds.y;
|
|
|
|
if (cx)
|
|
|
|
*cx = mBounds.width;
|
|
|
|
if (cy)
|
|
|
|
*cy = mBounds.height;
|
1999-11-29 10:47:20 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-29 10:47:20 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::Repaint(PRBool aForce)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(mContentViewer));
|
|
|
|
NS_ENSURE_TRUE(docViewer, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIPresContext> context;
|
|
|
|
docViewer->GetPresContext(*getter_AddRefs(context));
|
|
|
|
NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
context->GetShell(getter_AddRefs(shell));
|
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
shell->GetViewManager(getter_AddRefs(viewManager));
|
|
|
|
NS_ENSURE_TRUE(viewManager, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// what about aForce ?
|
|
|
|
NS_ENSURE_SUCCESS(viewManager->UpdateAllViews(0), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetParentWidget(nsIWidget ** parentWidget)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(parentWidget);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*parentWidget = mParentWidget;
|
|
|
|
NS_IF_ADDREF(*parentWidget);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetParentWidget(nsIWidget * aParentWidget)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_STATE(!mContentViewer);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mParentWidget = aParentWidget;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetParentNativeWindow(nativeWindow * parentNativeWindow)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(parentNativeWindow);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mParentWidget)
|
|
|
|
*parentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET);
|
|
|
|
else
|
|
|
|
*parentNativeWindow = nsnull;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetParentNativeWindow(nativeWindow parentNativeWindow)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetVisibility(PRBool * aVisibility)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aVisibility);
|
|
|
|
if (!mContentViewer) {
|
|
|
|
*aVisibility = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// get the pres shell
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// get the view manager
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
NS_ENSURE_SUCCESS(presShell->GetViewManager(getter_AddRefs(vm)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE);
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// get the root view
|
|
|
|
nsIView *rootView = nsnull; // views are not ref counted
|
|
|
|
NS_ENSURE_SUCCESS(vm->GetRootView(rootView), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE);
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// convert the view's visibility attribute to a bool
|
|
|
|
nsViewVisibility vis;
|
2001-10-23 02:43:52 +04:00
|
|
|
NS_ENSURE_SUCCESS(rootView->GetVisibility(vis), NS_ERROR_FAILURE);
|
2001-04-27 17:38:15 +04:00
|
|
|
*aVisibility = nsViewVisibility_kHide == vis ? PR_FALSE : PR_TRUE;
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetVisibility(PRBool aVisibility)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
if (!mContentViewer)
|
|
|
|
return NS_OK;
|
|
|
|
if (aVisibility) {
|
|
|
|
NS_ENSURE_SUCCESS(EnsureContentViewer(), NS_ERROR_FAILURE);
|
|
|
|
mContentViewer->Show();
|
|
|
|
}
|
|
|
|
else if (mContentViewer)
|
|
|
|
mContentViewer->Hide();
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetMainWidget(nsIWidget ** aMainWidget)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// We don't create our own widget, so simply return the parent one.
|
|
|
|
return GetParentWidget(aMainWidget);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetFocus()
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-05-23 03:52:17 +04:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
2001-05-26 01:15:46 +04:00
|
|
|
printf("nsDocShell::SetFocus %p\n", (nsIDocShell*)this);
|
2001-05-23 03:52:17 +04:00
|
|
|
#endif
|
|
|
|
|
2001-05-26 01:15:46 +04:00
|
|
|
// Tell itself (and the DocShellFocusController) who has focus
|
|
|
|
// this way focus gets removed from the currently focused DocShell
|
|
|
|
|
2001-10-23 02:43:52 +04:00
|
|
|
SetHasFocus(PR_TRUE);
|
2001-04-18 10:18:10 +04:00
|
|
|
|
2001-05-26 01:15:46 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetTitle(PRUnichar ** aTitle)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aTitle);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
*aTitle = ToNewUnicode(mTitle);
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetTitle(const PRUnichar * aTitle)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// Store local title
|
|
|
|
mTitle = aTitle;
|
1999-12-21 03:11:33 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
GetSameTypeParent(getter_AddRefs(parent));
|
1999-12-21 03:11:33 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// When title is set on the top object it should then be passed to the
|
|
|
|
// tree owner.
|
|
|
|
if (!parent) {
|
|
|
|
nsCOMPtr<nsIBaseWindow>
|
|
|
|
treeOwnerAsWin(do_QueryInterface(mTreeOwner));
|
|
|
|
if (treeOwnerAsWin)
|
|
|
|
treeOwnerAsWin->SetTitle(aTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mGlobalHistory && mCurrentURI) {
|
|
|
|
nsXPIDLCString url;
|
|
|
|
mCurrentURI->GetSpec(getter_Copies(url));
|
|
|
|
nsCOMPtr<nsIBrowserHistory> browserHistory =
|
|
|
|
do_QueryInterface(mGlobalHistory);
|
2001-12-04 04:42:01 +03:00
|
|
|
if (browserHistory)
|
|
|
|
browserHistory->SetPageTitle(url, aTitle);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
1999-12-21 03:11:33 +03:00
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-10-01 23:47:50 +04:00
|
|
|
// Update SessionHistory with the document's title. If the
|
|
|
|
// page was loaded from history or the page bypassed history,
|
|
|
|
// there is no need to update the title. There is no need to
|
|
|
|
// go to mSessionHistory to update the title. Setting it in mOSHE
|
|
|
|
// would suffice.
|
|
|
|
if (mOSHE && (mLoadType != LOAD_BYPASS_HISTORY) && (mLoadType != LOAD_HISTORY)) {
|
|
|
|
mOSHE->SetTitle(mTitle.get());
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-05-11 02:45:24 +04:00
|
|
|
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIScrollable
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetCurScrollPos(PRInt32 scrollOrientation, PRInt32 * curPos)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(curPos);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (!scrollView) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nscoord x, y;
|
|
|
|
NS_ENSURE_SUCCESS(scrollView->GetScrollPosition(x, y), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
switch (scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
*curPos = x;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
case ScrollOrientation_Y:
|
|
|
|
*curPos = y;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetCurScrollPos(PRInt32 scrollOrientation, PRInt32 curPos)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (!scrollView) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 other;
|
|
|
|
PRInt32 x;
|
|
|
|
PRInt32 y;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
GetCurScrollPos(scrollOrientation, &other);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
switch (scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
x = curPos;
|
|
|
|
y = other;
|
|
|
|
break;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
case ScrollOrientation_Y:
|
|
|
|
x = other;
|
|
|
|
y = curPos;
|
|
|
|
break;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
x = 0;
|
|
|
|
y = 0; // fix compiler warning, not actually executed
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(scrollView->ScrollTo(x, y, NS_VMREFRESH_IMMEDIATE),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetCurScrollPosEx(PRInt32 curHorizontalPos, PRInt32 curVerticalPos)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (!scrollView) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(scrollView->ScrollTo(curHorizontalPos, curVerticalPos,
|
|
|
|
NS_VMREFRESH_IMMEDIATE),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX This is wrong
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetScrollRange(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 * minPos, PRInt32 * maxPos)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(minPos && maxPos);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (!scrollView) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 cx;
|
|
|
|
PRInt32 cy;
|
1999-12-07 01:32:32 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(scrollView->GetContainerSize(&cx, &cy), NS_ERROR_FAILURE);
|
|
|
|
*minPos = 0;
|
|
|
|
|
|
|
|
switch (scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
*maxPos = cx;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case ScrollOrientation_Y:
|
|
|
|
*maxPos = cy;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetScrollRange(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 minPos, PRInt32 maxPos)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
//XXX First Check
|
|
|
|
/*
|
|
|
|
Retrieves or Sets the valid ranges for the thumb. When maxPos is set to
|
|
|
|
something less than the current thumb position, curPos is set = to maxPos.
|
1999-12-07 01:32:32 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
@return NS_OK - Setting or Getting completed successfully.
|
|
|
|
NS_ERROR_INVALID_ARG - returned when curPos is not within the
|
|
|
|
minPos and maxPos.
|
|
|
|
*/
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetScrollRangeEx(PRInt32 minHorizontalPos,
|
|
|
|
PRInt32 maxHorizontalPos, PRInt32 minVerticalPos,
|
|
|
|
PRInt32 maxVerticalPos)
|
|
|
|
{
|
|
|
|
//XXX First Check
|
|
|
|
/*
|
|
|
|
Retrieves or Sets the valid ranges for the thumb. When maxPos is set to
|
|
|
|
something less than the current thumb position, curPos is set = to maxPos.
|
|
|
|
|
|
|
|
@return NS_OK - Setting or Getting completed successfully.
|
|
|
|
NS_ERROR_INVALID_ARG - returned when curPos is not within the
|
|
|
|
minPos and maxPos.
|
|
|
|
*/
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
// Get scroll setting for this document only
|
|
|
|
//
|
|
|
|
// One important client is nsCSSFrameConstructor::ConstructRootFrame()
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetCurrentScrollbarPreferences(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 * scrollbarPref)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(scrollbarPref);
|
|
|
|
switch (scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
*scrollbarPref = mCurrentScrollbarPref.x;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case ScrollOrientation_Y:
|
|
|
|
*scrollbarPref = mCurrentScrollbarPref.y;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-29 09:51:48 +03:00
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
// This returns setting for all documents in this webshell
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetDefaultScrollbarPreferences(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 * scrollbarPref)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(scrollbarPref);
|
|
|
|
switch (scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
*scrollbarPref = mDefaultScrollbarPref.x;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case ScrollOrientation_Y:
|
|
|
|
*scrollbarPref = mDefaultScrollbarPref.y;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
// Set scrolling preference for this document only.
|
|
|
|
//
|
|
|
|
// There are three possible values stored in the shell:
|
|
|
|
// 1) NS_STYLE_OVERFLOW_HIDDEN = no scrollbars
|
|
|
|
// 2) NS_STYLE_OVERFLOW_AUTO = scrollbars appear if needed
|
|
|
|
// 3) NS_STYLE_OVERFLOW_SCROLL = scrollbars always
|
|
|
|
//
|
|
|
|
// XXX Currently OVERFLOW_SCROLL isn't honored,
|
|
|
|
// as it is not implemented by Gfx scrollbars
|
|
|
|
// XXX setting has no effect after the root frame is created
|
|
|
|
// as it is not implemented by Gfx scrollbars
|
|
|
|
//
|
|
|
|
// One important client is HTMLContentSink::StartLayout()
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetCurrentScrollbarPreferences(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 scrollbarPref)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
switch (scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
mCurrentScrollbarPref.x = scrollbarPref;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
case ScrollOrientation_Y:
|
|
|
|
mCurrentScrollbarPref.y = scrollbarPref;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-29 09:51:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set scrolling preference for all documents in this shell
|
|
|
|
// One important client is nsHTMLFrameInnerFrame::CreateWebShell()
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetDefaultScrollbarPreferences(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 scrollbarPref)
|
2000-02-29 09:51:48 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
switch (scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
mDefaultScrollbarPref.x = scrollbarPref;
|
|
|
|
return NS_OK;
|
2000-02-29 09:51:48 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
case ScrollOrientation_Y:
|
|
|
|
mDefaultScrollbarPref.y = scrollbarPref;
|
|
|
|
return NS_OK;
|
2000-02-29 09:51:48 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-29 09:51:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset 'current' scrollbar settings to 'default'.
|
|
|
|
// This must be called before every document load or else
|
|
|
|
// frameset scrollbar settings (e.g. <IFRAME SCROLLING="no">
|
|
|
|
// will not be preserved.
|
|
|
|
//
|
|
|
|
// One important client is HTMLContentSink::StartLayout()
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::ResetScrollbarPreferences()
|
2000-02-29 09:51:48 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mCurrentScrollbarPref = mDefaultScrollbarPref;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetScrollbarVisibility(PRBool * verticalVisible,
|
|
|
|
PRBool * horizontalVisible)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (!scrollView) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRBool vertVisible;
|
|
|
|
PRBool horizVisible;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(scrollView->GetScrollbarVisibility(&vertVisible,
|
|
|
|
&horizVisible),
|
|
|
|
NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (verticalVisible)
|
|
|
|
*verticalVisible = vertVisible;
|
|
|
|
if (horizontalVisible)
|
|
|
|
*horizontalVisible = horizVisible;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsITextScroll
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::ScrollByLines(PRInt32 numLines)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (!scrollView) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(scrollView->ScrollByLines(0, numLines), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::ScrollByPages(PRInt32 numPages)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if (!scrollView) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(scrollView->ScrollByPages(numPages), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
1999-11-30 04:06:59 +03:00
|
|
|
//*****************************************************************************
|
1999-12-03 12:24:22 +03:00
|
|
|
// nsDocShell::nsIScriptGlobalObjectOwner
|
1999-11-30 04:06:59 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetScriptGlobalObject(nsIScriptGlobalObject ** aGlobal)
|
1999-11-30 04:06:59 +03:00
|
|
|
{
|
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 20:46:42 +04:00
|
|
|
if (mIsBeingDestroyed) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aGlobal);
|
|
|
|
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
|
1999-11-30 04:06:59 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aGlobal = mScriptGlobal;
|
|
|
|
NS_IF_ADDREF(*aGlobal);
|
|
|
|
return NS_OK;
|
1999-11-30 04:06:59 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::ReportScriptError(nsIScriptError * errorObject)
|
1999-11-30 04:06:59 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv;
|
2000-03-31 15:19:51 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (errorObject == nsnull)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-04-15 05:56:47 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Get the console service, where we're going to register the error.
|
|
|
|
nsCOMPtr<nsIConsoleService> consoleService
|
|
|
|
(do_GetService("@mozilla.org/consoleservice;1"));
|
2000-03-31 15:19:51 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (consoleService != nsnull) {
|
|
|
|
rv = consoleService->LogMessage(errorObject);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
1999-11-30 04:06:59 +03:00
|
|
|
}
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIRefreshURI
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::RefreshURI(nsIURI * aURI, PRInt32 aDelay, PRBool aRepeat,
|
|
|
|
PRBool aMetaRefresh)
|
2000-04-13 07:11:44 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
|
|
|
nsRefreshTimer *refreshTimer = new nsRefreshTimer();
|
|
|
|
NS_ENSURE_TRUE(refreshTimer, NS_ERROR_OUT_OF_MEMORY);
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsISupports> dataRef = refreshTimer; // Get the ref count to 1
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
refreshTimer->mDocShell = this;
|
|
|
|
refreshTimer->mURI = aURI;
|
|
|
|
refreshTimer->mDelay = aDelay;
|
|
|
|
refreshTimer->mRepeat = aRepeat;
|
|
|
|
refreshTimer->mMetaRefresh = aMetaRefresh;
|
|
|
|
|
|
|
|
if (!mRefreshURIList) {
|
|
|
|
NS_ENSURE_SUCCESS(NS_NewISupportsArray(getter_AddRefs(mRefreshURIList)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
NS_ENSURE_TRUE(timer, NS_ERROR_FAILURE);
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mRefreshURIList->AppendElement(timer); // owning timer ref
|
|
|
|
timer->Init(refreshTimer, aDelay);
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-04-13 07:11:44 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::CancelRefreshURITimers()
|
2000-04-13 07:11:44 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
if (!mRefreshURIList)
|
|
|
|
return NS_OK;
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRUint32 n;
|
|
|
|
mRefreshURIList->Count(&n);
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
while (n) {
|
|
|
|
nsCOMPtr<nsISupports> element;
|
|
|
|
mRefreshURIList->GetElementAt(0, getter_AddRefs(element));
|
|
|
|
nsCOMPtr<nsITimer> timer(do_QueryInterface(element));
|
2000-05-18 00:24:43 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mRefreshURIList->RemoveElementAt(0); // bye bye owning timer ref
|
2000-05-18 00:24:43 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (timer)
|
|
|
|
timer->Cancel();
|
|
|
|
n--;
|
|
|
|
}
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-04-13 07:11:44 +04:00
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIContentViewerContainer
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::Embed(nsIContentViewer * aContentViewer,
|
|
|
|
const char *aCommand, nsISupports * aExtraInfo)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// Save the LayoutHistoryState of the previous document, before
|
|
|
|
// setting up new document
|
|
|
|
PersistLayoutHistoryState();
|
2000-06-22 09:36:13 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv = SetupNewViewer(aContentViewer);
|
2000-06-22 09:36:13 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// XXX What if SetupNewViewer fails?
|
2001-07-03 04:00:12 +04:00
|
|
|
if (mLSHE)
|
|
|
|
mOSHE = mLSHE;
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
PRBool updateHistory = PR_TRUE;
|
2000-06-22 09:36:13 +04:00
|
|
|
|
|
|
|
// Determine if this type of load should update history
|
2001-04-27 17:38:15 +04:00
|
|
|
switch (mLoadType) {
|
2001-08-16 04:33:58 +04:00
|
|
|
case LOAD_RELOAD_CHARSET_CHANGE: //don't perserve history in charset reload
|
2000-09-20 16:23:53 +04:00
|
|
|
case LOAD_NORMAL_REPLACE:
|
|
|
|
case LOAD_RELOAD_BYPASS_CACHE:
|
|
|
|
case LOAD_RELOAD_BYPASS_PROXY:
|
|
|
|
case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
|
2000-06-22 09:36:13 +04:00
|
|
|
updateHistory = PR_FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-09-16 08:36:18 +04:00
|
|
|
|
2001-07-03 04:00:12 +04:00
|
|
|
if (mOSHE && updateHistory) {
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
2000-07-06 03:10:29 +04:00
|
|
|
|
2001-07-03 04:00:12 +04:00
|
|
|
rv = mOSHE->GetLayoutHistoryState(getter_AddRefs(layoutState));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (layoutState) {
|
2001-07-03 04:00:12 +04:00
|
|
|
// This is a SH load. That's why there is a LayoutHistoryState in mOSHE
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
rv = GetPresShell(getter_AddRefs(presShell));
|
|
|
|
if (NS_SUCCEEDED(rv) && presShell) {
|
|
|
|
rv = presShell->SetHistoryState(layoutState);
|
|
|
|
}
|
|
|
|
}
|
2000-06-22 09:36:13 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-06-20 11:59:45 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIWebProgressListener
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::OnProgressChange(nsIWebProgress * aProgress,
|
|
|
|
nsIRequest * aRequest,
|
|
|
|
PRInt32 aCurSelfProgress,
|
|
|
|
PRInt32 aMaxSelfProgress,
|
|
|
|
PRInt32 aCurTotalProgress,
|
|
|
|
PRInt32 aMaxTotalProgress)
|
2000-06-20 11:59:45 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-06-20 11:59:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest,
|
2000-06-20 11:59:45 +04:00
|
|
|
PRInt32 aStateFlags, nsresult aStatus)
|
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// Update the busy cursor
|
|
|
|
if ((~aStateFlags & (STATE_START | STATE_IS_NETWORK)) == 0) {
|
|
|
|
// Page has begun to load
|
|
|
|
mBusyFlags = BUSY_FLAGS_BUSY | BUSY_FLAGS_BEFORE_PAGE_LOAD;
|
|
|
|
nsCOMPtr<nsIWidget> mainWidget;
|
|
|
|
GetMainWidget(getter_AddRefs(mainWidget));
|
|
|
|
if (mainWidget) {
|
|
|
|
mainWidget->SetCursor(eCursor_spinning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((~aStateFlags & (STATE_TRANSFERRING | STATE_IS_DOCUMENT)) == 0) {
|
|
|
|
// Page is loading
|
|
|
|
mBusyFlags = BUSY_FLAGS_BUSY | BUSY_FLAGS_PAGE_LOADING;
|
|
|
|
}
|
|
|
|
else if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_NETWORK)) {
|
|
|
|
// Page has finished loading
|
|
|
|
mBusyFlags = BUSY_FLAGS_NONE;
|
|
|
|
nsCOMPtr<nsIWidget> mainWidget;
|
|
|
|
GetMainWidget(getter_AddRefs(mainWidget));
|
|
|
|
if (mainWidget) {
|
|
|
|
mainWidget->SetCursor(eCursor_standard);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((~aStateFlags & (STATE_IS_DOCUMENT | STATE_STOP)) == 0) {
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
|
|
|
|
|
|
|
// Is the document stop notification for this document?
|
|
|
|
if (aProgress == webProgress.get()) {
|
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
|
|
|
|
EndPageLoad(aProgress, channel, aStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((~aStateFlags & (STATE_IS_DOCUMENT | STATE_REDIRECTING)) == 0) {
|
|
|
|
// XXX Is it enough if I check just for the above 2 flags for redirection
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
|
|
|
|
|
|
|
// Is the document stop notification for this document?
|
|
|
|
if (aProgress == webProgress.get()) {
|
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
if (channel) {
|
|
|
|
// Get the uri from the channel
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
|
|
|
// Add the original url to global History so that
|
|
|
|
// visited url color changes happen.
|
|
|
|
if (uri) {
|
|
|
|
// Update Global history if necessary...
|
|
|
|
PRBool updateHistory = PR_FALSE;
|
|
|
|
ShouldAddToGlobalHistory(uri, &updateHistory);
|
|
|
|
if (updateHistory) {
|
|
|
|
AddToGlobalHistory(uri);
|
2001-11-19 23:22:14 +03:00
|
|
|
// this is a redirect, so hide the page from
|
|
|
|
// being enumerated in history
|
|
|
|
// this is temporary until bug 71482 is fixed
|
|
|
|
if (mGlobalHistory) {
|
|
|
|
nsCOMPtr<nsIBrowserHistory> browserHistory =
|
|
|
|
do_QueryInterface(mGlobalHistory);
|
|
|
|
if (browserHistory) {
|
|
|
|
nsXPIDLCString urlString;
|
|
|
|
if (NS_SUCCEEDED(uri->GetSpec(getter_Copies(urlString))))
|
|
|
|
browserHistory->HidePage(urlString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
} // uri
|
|
|
|
} // channel
|
|
|
|
} // aProgress
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-06-20 11:59:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::OnLocationChange(nsIWebProgress * aProgress,
|
|
|
|
nsIRequest * aRequest, nsIURI * aURI)
|
2000-06-20 11:59:45 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-06-20 11:59:45 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::OnStatusChange(nsIWebProgress * aWebProgress,
|
|
|
|
nsIRequest * aRequest,
|
|
|
|
nsresult aStatus, const PRUnichar * aMessage)
|
2000-07-25 09:45:56 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-09-15 02:56:56 +04:00
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::OnSecurityChange(nsIWebProgress * aWebProgress,
|
|
|
|
nsIRequest * aRequest, PRInt32 state)
|
2000-09-15 02:56:56 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult
|
|
|
|
nsDocShell::EndPageLoad(nsIWebProgress * aProgress,
|
|
|
|
nsIChannel * aChannel, nsresult aStatus)
|
|
|
|
{
|
2001-07-03 04:00:12 +04:00
|
|
|
if (mLSHE) {
|
|
|
|
mLSHE->SetLoadType(nsIDocShellLoadInfo::loadHistory);
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2001-07-03 04:00:12 +04:00
|
|
|
// Clear the mLSHE reference to indicate document loading is done one
|
2001-04-27 17:38:15 +04:00
|
|
|
// way or another.
|
2001-07-03 04:00:12 +04:00
|
|
|
mLSHE = nsnull;
|
2001-04-27 17:38:15 +04: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<nsIDocShell> kungFuDeathGrip(this);
|
|
|
|
//
|
|
|
|
// Notify the ContentViewer that the Document has finished loading...
|
|
|
|
//
|
|
|
|
// This will cause any OnLoad(...) handlers to fire, if it is a HTML
|
|
|
|
// document...
|
|
|
|
//
|
|
|
|
if (!mEODForCurrentDocument && mContentViewer) {
|
|
|
|
mContentViewer->LoadComplete(aStatus);
|
|
|
|
|
|
|
|
mEODForCurrentDocument = PR_TRUE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-12-21 02:18:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
2000-02-24 07:15:22 +03:00
|
|
|
// nsDocShell: Content Viewer Management
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::EnsureContentViewer()
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mContentViewer)
|
|
|
|
return NS_OK;
|
2001-11-16 05:15:31 +03:00
|
|
|
if (mIsBeingDestroyed)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return CreateAboutBlankContentViewer();
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::EnsureDeviceContext()
|
2000-03-08 06:58:33 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mDeviceContext)
|
|
|
|
return NS_OK;
|
2000-03-08 06:58:33 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mDeviceContext = do_CreateInstance(kDeviceContextCID);
|
|
|
|
NS_ENSURE_TRUE(mDeviceContext, NS_ERROR_FAILURE);
|
2000-03-08 06:58:33 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
GetMainWidget(getter_AddRefs(widget));
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
2000-03-08 06:58:33 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mDeviceContext->Init(widget->GetNativeData(NS_NATIVE_WIDGET));
|
|
|
|
float dev2twip;
|
|
|
|
mDeviceContext->GetDevUnitsToTwips(dev2twip);
|
|
|
|
mDeviceContext->SetDevUnitsToAppUnits(dev2twip);
|
|
|
|
float twip2dev;
|
|
|
|
mDeviceContext->GetTwipsToDevUnits(twip2dev);
|
|
|
|
mDeviceContext->SetAppUnitsToDevUnits(twip2dev);
|
|
|
|
mDeviceContext->SetGamma(1.0f);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-08 06:58:33 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::CreateAboutBlankContentViewer()
|
|
|
|
{
|
2001-11-06 04:24:39 +03:00
|
|
|
nsCOMPtr<nsIDocument> blankDoc;
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
2001-12-11 05:41:22 +03:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2001-11-06 04:24:39 +03:00
|
|
|
|
2001-12-11 05:41:22 +03:00
|
|
|
/* mCreatingDocument should never be true at this point. However, it's
|
|
|
|
a theoretical possibility. We want to know about it and make it stop,
|
|
|
|
and this sounds like a job for an assertion. */
|
|
|
|
NS_ASSERTION(!mCreatingDocument, "infinite(?) loop creating document averted");
|
|
|
|
if (mCreatingDocument)
|
2001-11-06 04:24:39 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-12-11 05:41:22 +03:00
|
|
|
mCreatingDocument = PR_TRUE;
|
2001-11-16 05:15:31 +03:00
|
|
|
|
2001-12-11 05:41:22 +03:00
|
|
|
// one helper factory, please
|
|
|
|
nsCOMPtr<nsIDocumentLoaderFactory> docFactory(do_CreateInstance(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=text/html"));
|
|
|
|
if (docFactory) {
|
2001-11-06 04:24:39 +03:00
|
|
|
|
2001-12-11 05:41:22 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(mLoadCookie));
|
2001-11-06 04:24:39 +03:00
|
|
|
|
2001-12-11 05:41:22 +03:00
|
|
|
// generate (about:blank) document to load
|
|
|
|
docFactory->CreateBlankDocument(loadGroup, getter_AddRefs(blankDoc));
|
|
|
|
if (blankDoc) {
|
|
|
|
|
|
|
|
// create a content viewer for us and the new document
|
|
|
|
docFactory->CreateInstanceForDocument(NS_ISUPPORTS_CAST(nsIDocShell *, this),
|
|
|
|
blankDoc, "view", getter_AddRefs(viewer));
|
|
|
|
|
|
|
|
// hook 'em up
|
|
|
|
if (viewer) {
|
|
|
|
viewer->SetContainer(NS_STATIC_CAST(nsIContentViewerContainer *,this));
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(blankDoc));
|
|
|
|
Embed(viewer, "", 0);
|
|
|
|
viewer->SetDOMDocument(domdoc);
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2001-11-06 04:24:39 +03:00
|
|
|
}
|
2001-12-11 05:41:22 +03:00
|
|
|
mCreatingDocument = PR_FALSE;
|
|
|
|
return rv;
|
2000-03-08 06:58:33 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::CreateContentViewer(const char *aContentType,
|
|
|
|
nsIRequest * request,
|
|
|
|
nsIStreamListener ** aContentHandler)
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// Can we check the content type of the current content viewer
|
|
|
|
// and reuse it without destroying it and re-creating it?
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(mLoadCookie));
|
|
|
|
NS_ENSURE_TRUE(loadGroup, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Instantiate the content viewer object
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
nsresult rv = NewContentViewerObj(aContentType, request, loadGroup,
|
|
|
|
aContentHandler, getter_AddRefs(viewer));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-07-18 00:17:38 +04:00
|
|
|
// Notify the current document that it is about to be unloaded!!
|
|
|
|
//
|
|
|
|
// It is important to fire the unload() notification *before* any state
|
|
|
|
// is changed within the DocShell - otherwise, javascript will get the
|
|
|
|
// wrong information :-(
|
|
|
|
//
|
|
|
|
(void) FireUnloadNotification();
|
|
|
|
|
|
|
|
// Set mFiredUnloadEvent = PR_FALSE so that the unload handler for the
|
|
|
|
// *new* document will fire.
|
|
|
|
mFiredUnloadEvent = PR_FALSE;
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// we've created a new document so go ahead and call OnLoadingSite
|
|
|
|
mURIResultedInDocument = PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> aOpenedChannel = do_QueryInterface(request);
|
|
|
|
|
|
|
|
OnLoadingSite(aOpenedChannel);
|
|
|
|
|
|
|
|
// let's try resetting the load group if we need to...
|
|
|
|
nsCOMPtr<nsILoadGroup> currentLoadGroup;
|
|
|
|
NS_ENSURE_SUCCESS(aOpenedChannel->
|
|
|
|
GetLoadGroup(getter_AddRefs(currentLoadGroup)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (currentLoadGroup.get() != loadGroup.get()) {
|
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
|
|
|
|
//Cancel any URIs that are currently loading...
|
|
|
|
/// XXX: Need to do this eventually Stop();
|
|
|
|
//
|
|
|
|
// Retarget the document to this loadgroup...
|
|
|
|
//
|
|
|
|
/* First attach the channel to the right loadgroup
|
|
|
|
* and then remove from the old loadgroup. This
|
|
|
|
* puts the notifications in the right order and
|
2001-07-03 04:00:12 +04:00
|
|
|
* we don't null-out mLSHE in OnStateChange() for
|
2001-04-27 17:38:15 +04:00
|
|
|
* all redirected urls
|
|
|
|
*/
|
|
|
|
aOpenedChannel->SetLoadGroup(loadGroup);
|
|
|
|
|
|
|
|
// Mark the channel as being a document URI...
|
|
|
|
aOpenedChannel->GetLoadFlags(&loadFlags);
|
|
|
|
loadFlags |= nsIChannel::LOAD_DOCUMENT_URI;
|
|
|
|
|
|
|
|
aOpenedChannel->SetLoadFlags(loadFlags);
|
|
|
|
|
|
|
|
loadGroup->AddRequest(request, nsnull);
|
|
|
|
if (currentLoadGroup)
|
|
|
|
currentLoadGroup->RemoveRequest(request, nsnull, NS_OK);
|
|
|
|
|
2001-05-30 02:10:50 +04:00
|
|
|
// Update the notification callbacks, so that progress and
|
|
|
|
// status information are sent to the right docshell...
|
|
|
|
aOpenedChannel->SetNotificationCallbacks(this);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(Embed(viewer, "", (nsISupports *) nsnull),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
2001-05-25 12:49:03 +04:00
|
|
|
mEODForCurrentDocument = PR_FALSE;
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocShell::NewContentViewerObj(const char *aContentType,
|
|
|
|
nsIRequest * request, nsILoadGroup * aLoadGroup,
|
|
|
|
nsIStreamListener ** aContentHandler,
|
|
|
|
nsIContentViewer ** aViewer)
|
|
|
|
{
|
|
|
|
//XXX This should probably be some category thing....
|
|
|
|
char id[256];
|
|
|
|
PR_snprintf(id, sizeof(id),
|
|
|
|
NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "%s;1?type=%s",
|
|
|
|
(const char *) "view", aContentType);
|
|
|
|
|
|
|
|
// Note that we're always passing in "view" for the component id above
|
|
|
|
// and to the docLoaderFactory->CreateInstance() at the end of this method.
|
|
|
|
// nsLayoutDLF makes the determination if it should be a "view-source"
|
|
|
|
|
|
|
|
// Create an instance of the document-loader-factory
|
|
|
|
nsCOMPtr<nsIDocumentLoaderFactory>
|
|
|
|
docLoaderFactory(do_CreateInstance(id));
|
|
|
|
if (!docLoaderFactory) {
|
|
|
|
// try again after loading plugins
|
|
|
|
nsresult err;
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIPluginHost> pluginHost =
|
|
|
|
do_GetService(kPluginManagerCID, &err);
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(err))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
pluginHost->LoadPlugins();
|
|
|
|
|
|
|
|
docLoaderFactory = do_CreateInstance(id);
|
|
|
|
|
|
|
|
if (!docLoaderFactory)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> aOpenedChannel = do_QueryInterface(request);
|
|
|
|
|
|
|
|
// Now create an instance of the content viewer
|
|
|
|
NS_ENSURE_SUCCESS(docLoaderFactory->CreateInstance("view",
|
|
|
|
aOpenedChannel,
|
|
|
|
aLoadGroup, aContentType,
|
|
|
|
NS_STATIC_CAST
|
|
|
|
(nsIContentViewerContainer
|
|
|
|
*, this), nsnull,
|
|
|
|
aContentHandler,
|
|
|
|
aViewer),
|
|
|
|
NS_ERROR_FAILURE);
|
2001-06-21 06:07:25 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
(*aViewer)->SetContainer(NS_STATIC_CAST(nsIContentViewerContainer *, this));
|
2001-06-21 06:07:25 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPluginViewer> pv(do_QueryInterface(*aViewer));
|
|
|
|
if (pv)
|
|
|
|
SetTitle(nsnull); // clear title bar for full-page plugin
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Copy content viewer state from previous or parent content viewer.
|
|
|
|
//
|
|
|
|
// The following logic is mirrored in nsHTMLDocument::StartDocumentLoad!
|
|
|
|
//
|
|
|
|
// Do NOT to maintain a reference to the old content viewer outside
|
|
|
|
// of this "copying" block, or it will not be destroyed until the end of
|
|
|
|
// this routine and all <SCRIPT>s and event handlers fail! (bug 20315)
|
|
|
|
//
|
|
|
|
// In this block of code, if we get an error result, we return it
|
|
|
|
// but if we get a null pointer, that's perfectly legal for parent
|
|
|
|
// and parentContentViewer.
|
|
|
|
//
|
|
|
|
|
|
|
|
PRInt32 x = 0;
|
|
|
|
PRInt32 y = 0;
|
|
|
|
PRInt32 cx = 0;
|
|
|
|
PRInt32 cy = 0;
|
1999-11-12 12:07:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// This will get the size from the current content viewer or from the
|
|
|
|
// Init settings
|
|
|
|
GetPositionAndSize(&x, &y, &cx, &cy);
|
1999-11-12 12:07:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
|
|
|
NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parentAsItem)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mContentViewer || parent) {
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> oldMUDV;
|
|
|
|
if (mContentViewer) {
|
|
|
|
// Get any interesting state from old content viewer
|
|
|
|
// XXX: it would be far better to just reuse the document viewer ,
|
|
|
|
// since we know we're just displaying the same document as before
|
|
|
|
oldMUDV = do_QueryInterface(mContentViewer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No old content viewer, so get state from parent's content viewer
|
|
|
|
nsCOMPtr<nsIContentViewer> parentContentViewer;
|
|
|
|
parent->GetContentViewer(getter_AddRefs(parentContentViewer));
|
|
|
|
oldMUDV = do_QueryInterface(parentContentViewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLString defaultCharset;
|
|
|
|
nsXPIDLString forceCharset;
|
|
|
|
nsXPIDLString hintCharset;
|
|
|
|
PRInt32 hintCharsetSource;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer>
|
|
|
|
newMUDV(do_QueryInterface(aNewViewer));
|
|
|
|
if (oldMUDV && newMUDV) {
|
|
|
|
NS_ENSURE_SUCCESS(oldMUDV->
|
|
|
|
GetDefaultCharacterSet(getter_Copies
|
|
|
|
(defaultCharset)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(oldMUDV->
|
|
|
|
GetForceCharacterSet(getter_Copies(forceCharset)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(oldMUDV->
|
|
|
|
GetHintCharacterSet(getter_Copies(hintCharset)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(oldMUDV->
|
|
|
|
GetHintCharacterSetSource(&hintCharsetSource),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// set the old state onto the new content viewer
|
|
|
|
NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet(defaultCharset),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet(forceCharset),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet(hintCharset),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(newMUDV->
|
|
|
|
SetHintCharacterSetSource(hintCharsetSource),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is necessary to obtain the focus controller to utilize its ability
|
|
|
|
// to suppress focus. This is necessary to fix Win32-only bugs related to
|
|
|
|
// a loss of focus when mContentViewer is set to null. The internal window
|
|
|
|
// is destroyed, and the OS focuses the parent window. This call ends up
|
|
|
|
// notifying the focus controller that the outer window should focus
|
|
|
|
// and this hoses us on any link traversal.
|
|
|
|
//
|
|
|
|
// Please do not touch any of the focus controller code here without
|
|
|
|
// testing bugs #28580 and 50509. These are immensely important bugs,
|
|
|
|
// so PLEASE take care not to regress them if you decide to alter this
|
|
|
|
// code later -- hyatt
|
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
|
|
|
if (mScriptGlobal) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(mScriptGlobal);
|
|
|
|
ourWindow->GetRootFocusController(getter_AddRefs(focusController));
|
|
|
|
if (focusController) {
|
|
|
|
// Suppress the command dispatcher.
|
|
|
|
focusController->SetSuppressFocus(PR_TRUE,
|
|
|
|
"Win32-Only Link Traversal Issue");
|
2001-05-30 03:26:50 +04:00
|
|
|
// Remove focus from the element that has it
|
2001-06-14 07:49:07 +04:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> focusedWindow;
|
|
|
|
focusController->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> ourFocusedWindow(do_QueryInterface(ourWindow));
|
2001-06-20 03:31:25 +04:00
|
|
|
|
|
|
|
// We want to null out the last focused element if the document containing
|
|
|
|
// it is going away. If the last focused element is in a descendent
|
|
|
|
// window of our domwindow, its document will be destroyed when we
|
|
|
|
// destroy our children. So, check for this case and null out the
|
|
|
|
// last focused element. See bug 70484.
|
|
|
|
|
|
|
|
PRBool isSubWindow = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIDOMWindow> curwin;
|
|
|
|
if (focusedWindow)
|
|
|
|
focusedWindow->GetParent(getter_AddRefs(curwin));
|
|
|
|
while (curwin) {
|
|
|
|
if (curwin == NS_STATIC_CAST(nsIDOMWindow*, ourFocusedWindow)) {
|
|
|
|
isSubWindow = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsIDOMWindow* temp;
|
|
|
|
curwin->GetParent(&temp);
|
|
|
|
if (curwin == temp) {
|
|
|
|
NS_RELEASE(temp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curwin = dont_AddRef(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ourFocusedWindow == focusedWindow || isSubWindow)
|
2001-06-14 07:49:07 +04:00
|
|
|
focusController->SetFocusedElement(nsnull);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
}
|
2000-09-08 12:04:53 +04:00
|
|
|
|
2001-04-24 05:01:16 +04:00
|
|
|
nscolor bgcolor = NS_RGBA(0, 0, 0, 0);
|
|
|
|
PRBool bgSet = PR_FALSE;
|
|
|
|
|
2001-04-27 15:17:30 +04:00
|
|
|
// Ensure that the content viewer is destroyed *after* the GC - bug 71515
|
|
|
|
nsCOMPtr<nsIContentViewer> kungfuDeathGrip = mContentViewer;
|
2001-04-24 05:01:16 +04:00
|
|
|
if (mContentViewer) {
|
2001-04-27 17:38:15 +04:00
|
|
|
// Stop any activity that may be happening in the old document before
|
|
|
|
// releasing it...
|
|
|
|
mContentViewer->Stop();
|
2001-05-25 19:00:51 +04:00
|
|
|
|
|
|
|
// Try to extract the default background color from the old
|
|
|
|
// view manager, so we can use it for the next document.
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docviewer =
|
|
|
|
do_QueryInterface(mContentViewer);
|
|
|
|
|
|
|
|
if (docviewer) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
docviewer->GetPresShell(*getter_AddRefs(shell));
|
|
|
|
|
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
|
|
|
|
if (vm) {
|
|
|
|
vm->GetDefaultBackgroundColor(&bgcolor);
|
|
|
|
// If the background color is not known, don't propagate it.
|
|
|
|
bgSet = NS_GET_A(bgcolor) != 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
mContentViewer->Close();
|
2001-05-02 02:54:11 +04:00
|
|
|
aNewViewer->SetPreviousViewer(mContentViewer);
|
2001-03-10 06:19:36 +03:00
|
|
|
mContentViewer = nsnull;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mContentViewer = aNewViewer;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
NS_ENSURE_SUCCESS(GetMainWidget(getter_AddRefs(widget)), NS_ERROR_FAILURE);
|
|
|
|
if (!widget) {
|
|
|
|
NS_ERROR("GetMainWidget coughed up a null widget");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect bounds(x, y, cx, cy);
|
|
|
|
NS_ENSURE_SUCCESS(EnsureDeviceContext(), NS_ERROR_FAILURE);
|
|
|
|
if (NS_FAILED(mContentViewer->Init(widget, mDeviceContext, bounds))) {
|
|
|
|
mContentViewer = nsnull;
|
|
|
|
NS_ERROR("ContentViewer Initialization failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-12-11 05:41:22 +03:00
|
|
|
// End copying block (Don't mess with the old content/document viewer
|
|
|
|
// beyond here!!)
|
|
|
|
|
|
|
|
// See the book I wrote above regarding why the focus controller is
|
|
|
|
// being used here. -- hyatt
|
|
|
|
|
|
|
|
/* Note it's important that focus suppression be turned off no earlier
|
|
|
|
because in cases where the docshell is lazily creating an about:blank
|
|
|
|
document, mContentViewer->Init finally puts a reference to that
|
|
|
|
document into the DOM window, which prevents an infinite recursion
|
|
|
|
attempting to lazily create the document as focus is unsuppressed
|
|
|
|
(bug 110856). */
|
|
|
|
if (focusController)
|
|
|
|
focusController->SetSuppressFocus(PR_FALSE,
|
|
|
|
"Win32-Only Link Traversal Issue");
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (bgSet) {
|
|
|
|
// Stuff the bgcolor from the last view manager into the new
|
|
|
|
// view manager. This improves page load continuity.
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docviewer =
|
|
|
|
do_QueryInterface(mContentViewer);
|
|
|
|
|
|
|
|
if (docviewer) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
docviewer->GetPresShell(*getter_AddRefs(shell));
|
|
|
|
|
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
|
|
|
|
if (vm) {
|
|
|
|
vm->SetDefaultBackgroundColor(bgcolor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-24 05:01:16 +04:00
|
|
|
|
2000-07-01 02:05:32 +04:00
|
|
|
// XXX: It looks like the LayoutState gets restored again in Embed()
|
|
|
|
// right after the call to SetupNewViewer(...)
|
2001-04-19 23:38:27 +04:00
|
|
|
|
2001-05-02 02:54:11 +04:00
|
|
|
// We don't show the mContentViewer yet, since we want to draw the old page
|
|
|
|
// until we have enough of the new page to show. Just return with the new
|
|
|
|
// viewer still set to hidden.
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Now that we have switched documents, forget all of our children
|
|
|
|
DestroyChildren();
|
2000-02-14 09:40:28 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2001-07-18 00:17:38 +04:00
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell: Site Loading
|
|
|
|
//*****************************************************************************
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
2001-05-14 06:16:27 +04:00
|
|
|
nsDocShell::InternalLoad(nsIURI * aURI,
|
|
|
|
nsIURI * aReferrer,
|
|
|
|
nsISupports * aOwner,
|
|
|
|
PRBool aInheritOwner,
|
|
|
|
const PRUnichar *aWindowTarget,
|
2001-04-27 17:38:15 +04:00
|
|
|
nsIInputStream * aPostData,
|
2001-05-14 06:16:27 +04:00
|
|
|
nsIInputStream * aHeadersData,
|
|
|
|
PRUint32 aLoadType,
|
2001-04-27 17:38:15 +04:00
|
|
|
nsISHEntry * aSHEntry)
|
|
|
|
{
|
2001-05-14 06:16:27 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2001-05-30 06:22:22 +04:00
|
|
|
nsCOMPtr<nsISupports> owner(aOwner);
|
|
|
|
//
|
2001-07-03 09:27:22 +04:00
|
|
|
// Get an owner from the current document if necessary
|
2001-05-30 06:22:22 +04:00
|
|
|
//
|
2001-07-03 09:27:22 +04:00
|
|
|
if (!owner && aInheritOwner)
|
|
|
|
GetCurrentDocumentOwner(getter_AddRefs(owner));
|
2001-05-30 06:22:22 +04:00
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
//
|
|
|
|
// Resolve the window target before going any further...
|
|
|
|
// If the load has been targeted to another DocShell, then transfer the
|
|
|
|
// load to it...
|
|
|
|
//
|
|
|
|
if (aWindowTarget && *aWindowTarget) {
|
|
|
|
PRBool bIsNewWindow;
|
|
|
|
nsCOMPtr<nsIDocShell> targetDocShell;
|
|
|
|
nsAutoString name(aWindowTarget);
|
|
|
|
|
|
|
|
//
|
|
|
|
// This is a hack for Shrimp :-(
|
|
|
|
//
|
|
|
|
// if the load cmd is a user click....and we are supposed to try using
|
|
|
|
// external default protocol handlers....then try to see if we have one for
|
|
|
|
// this protocol
|
|
|
|
//
|
|
|
|
// See bug #52182
|
|
|
|
//
|
|
|
|
if (mUseExternalProtocolHandler && aLoadType == LOAD_LINK) {
|
|
|
|
PRBool bIsJavascript = PR_FALSE;
|
|
|
|
|
|
|
|
aURI->SchemeIs("javascript", &bIsJavascript);
|
|
|
|
// don't do it for javascript urls!
|
|
|
|
if (!bIsJavascript &&
|
|
|
|
(name.EqualsIgnoreCase("_content") ||
|
|
|
|
name.EqualsIgnoreCase("_blank")))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtService;
|
|
|
|
nsXPIDLCString urlScheme;
|
|
|
|
|
|
|
|
extProtService = do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID);
|
|
|
|
if (extProtService) {
|
|
|
|
PRBool haveHandler = PR_FALSE;
|
|
|
|
aURI->GetScheme(getter_Copies(urlScheme));
|
|
|
|
|
|
|
|
extProtService->ExternalProtocolHandlerExists(urlScheme,
|
|
|
|
&haveHandler);
|
|
|
|
if (haveHandler)
|
|
|
|
return extProtService->LoadUrl(aURI);
|
|
|
|
}
|
2001-01-27 04:08:36 +03:00
|
|
|
}
|
2001-05-14 06:16:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This is a hack to prevent top-level windows from ever being
|
|
|
|
// created. It really doesn't belong here, but until there is a
|
|
|
|
// way for embeddors to get involved in window targeting, this is
|
|
|
|
// as good a place as any...
|
|
|
|
//
|
|
|
|
if (mDisallowPopupWindows) {
|
|
|
|
PRBool bIsChromeOrResource = PR_FALSE;
|
|
|
|
|
|
|
|
aURI->SchemeIs("chrome", &bIsChromeOrResource);
|
|
|
|
if (!bIsChromeOrResource) {
|
|
|
|
aURI->SchemeIs("resource", &bIsChromeOrResource);
|
|
|
|
}
|
|
|
|
if (!bIsChromeOrResource) {
|
|
|
|
if (name.EqualsIgnoreCase("_blank") ||
|
|
|
|
name.EqualsIgnoreCase("_new")) {
|
2001-12-16 14:58:03 +03:00
|
|
|
name.Assign(NS_LITERAL_STRING("_top"));
|
2001-05-14 06:16:27 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> targetTreeItem;
|
2001-06-30 15:02:25 +04:00
|
|
|
FindItemWithName(name.get(),
|
2001-05-14 06:16:27 +04:00
|
|
|
NS_STATIC_CAST(nsIInterfaceRequestor *, this),
|
|
|
|
getter_AddRefs(targetTreeItem));
|
|
|
|
if (targetTreeItem)
|
|
|
|
targetDocShell = do_QueryInterface(targetTreeItem);
|
|
|
|
else
|
2001-12-16 14:58:03 +03:00
|
|
|
name.Assign(NS_LITERAL_STRING("_top"));
|
2001-05-14 06:16:27 +04:00
|
|
|
}
|
2001-01-27 04:08:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
//
|
|
|
|
// Locate the target DocShell.
|
|
|
|
// This may involve creating a new toplevel window - if necessary.
|
|
|
|
//
|
|
|
|
if (!targetDocShell) {
|
2001-06-30 15:02:25 +04:00
|
|
|
rv = FindTarget(name.get(), &bIsNewWindow,
|
2001-05-14 06:16:27 +04:00
|
|
|
getter_AddRefs(targetDocShell));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(targetDocShell, "No Target docshell could be found!");
|
|
|
|
//
|
|
|
|
// Transfer the load to the target DocShell... Pass nsnull as the
|
|
|
|
// window target name from to prevent recursive retargeting!
|
|
|
|
//
|
|
|
|
if (targetDocShell) {
|
|
|
|
rv = targetDocShell->InternalLoad(aURI,
|
|
|
|
aReferrer,
|
2001-05-30 06:22:22 +04:00
|
|
|
owner,
|
2001-05-14 06:16:27 +04:00
|
|
|
aInheritOwner,
|
|
|
|
nsnull, // No window target
|
|
|
|
aPostData,
|
|
|
|
aHeadersData,
|
|
|
|
aLoadType,
|
|
|
|
aSHEntry);
|
2001-05-21 10:50:51 +04:00
|
|
|
if (rv == NS_ERROR_NO_CONTENT) {
|
|
|
|
if (bIsNewWindow) {
|
|
|
|
//
|
|
|
|
// At this point, a new window has been created, but the
|
|
|
|
// URI did not have any data associated with it...
|
|
|
|
//
|
|
|
|
// So, the best we can do, is to tear down the new window
|
|
|
|
// that was just created!
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem;
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
|
|
|
|
treeItem = do_QueryInterface(targetDocShell);
|
|
|
|
treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
if (treeOwner) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
|
|
|
|
|
|
|
treeOwnerAsWin = do_QueryInterface(treeOwner);
|
|
|
|
if (treeOwnerAsWin) {
|
|
|
|
treeOwnerAsWin->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// NS_ERROR_NO_CONTENT should not be returned to the
|
|
|
|
// caller... This is an internal error code indicating that
|
|
|
|
// the URI had no data associated with it - probably a
|
|
|
|
// helper-app style protocol (ie. mailto://)
|
|
|
|
//
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
else if (bIsNewWindow) {
|
|
|
|
// XXX: Once new windows are created hidden, the new
|
|
|
|
// window will need to be made visible... For now,
|
|
|
|
// do nothing.
|
|
|
|
}
|
2001-05-14 06:16:27 +04:00
|
|
|
}
|
2001-05-21 10:50:51 +04:00
|
|
|
return rv;
|
2001-05-14 06:16:27 +04:00
|
|
|
}
|
2001-05-21 10:50:51 +04:00
|
|
|
|
2001-08-21 04:50:26 +04:00
|
|
|
//
|
|
|
|
// Load is being targetted at this docshell so return an error if the
|
|
|
|
// docshell is in the process of being destroyed.
|
|
|
|
//
|
|
|
|
if (mIsBeingDestroyed) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-05-14 06:16:27 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mURIResultedInDocument = PR_FALSE; // reset the clock...
|
2001-10-20 01:28:57 +04:00
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
//
|
|
|
|
// First:
|
2000-06-06 02:13:52 +04:00
|
|
|
// Check to see if the new URI is an anchor in the existing document.
|
2001-05-14 06:16:27 +04:00
|
|
|
//
|
2001-04-27 17:38:15 +04:00
|
|
|
if ((aLoadType == LOAD_NORMAL ||
|
|
|
|
aLoadType == LOAD_NORMAL_REPLACE ||
|
|
|
|
aLoadType == LOAD_HISTORY ||
|
|
|
|
aLoadType == LOAD_LINK) && (aPostData == nsnull)) {
|
2000-06-06 02:13:52 +04:00
|
|
|
PRBool wasAnchor = PR_FALSE;
|
|
|
|
NS_ENSURE_SUCCESS(ScrollIfAnchor(aURI, &wasAnchor), NS_ERROR_FAILURE);
|
2001-04-27 17:38:15 +04:00
|
|
|
if (wasAnchor) {
|
2000-06-06 02:13:52 +04:00
|
|
|
mLoadType = aLoadType;
|
2000-09-02 02:34:19 +04:00
|
|
|
mURIResultedInDocument = PR_TRUE;
|
2001-10-20 01:28:57 +04:00
|
|
|
/* This is a anchor traversal with in the same page.
|
|
|
|
* call OnNewURI() so that, this traversal will be
|
|
|
|
* recorded in session and global history.
|
|
|
|
*/
|
2000-06-06 02:13:52 +04:00
|
|
|
OnNewURI(aURI, nsnull, mLoadType);
|
2001-10-20 01:28:57 +04:00
|
|
|
|
|
|
|
/* If this is a history load, OnNewURI() will not create
|
|
|
|
* a mLSHE. In that case, we want to assign mOSHE to aSHEntry
|
|
|
|
* passed by SH, otherwise, mLSHE created by OnNewURI() should
|
|
|
|
* be assigned to mOSHE.
|
|
|
|
*/
|
|
|
|
if (aSHEntry && !mLSHE)
|
|
|
|
mOSHE = aSHEntry;
|
|
|
|
else if (mLSHE)
|
2001-07-03 04:00:12 +04:00
|
|
|
mOSHE = mLSHE;
|
2001-05-04 01:15:31 +04:00
|
|
|
|
2001-07-03 04:00:12 +04:00
|
|
|
/* Clear out mLSHE so that further anchor visits get
|
2001-05-04 01:15:31 +04:00
|
|
|
* recorded in SH and SH won't misbehave.
|
2001-04-27 17:38:15 +04:00
|
|
|
*/
|
2001-07-03 04:00:12 +04:00
|
|
|
mLSHE = nsnull;
|
2001-04-27 17:38:15 +04:00
|
|
|
/* Set the title for the SH entry for this target url. so that
|
|
|
|
* SH menus in go/back/forward buttons won't be empty for this.
|
|
|
|
*/
|
|
|
|
if (mSessionHistory) {
|
|
|
|
PRInt32 index = -1;
|
|
|
|
mSessionHistory->GetIndex(&index);
|
|
|
|
nsCOMPtr<nsIHistoryEntry> hEntry;
|
|
|
|
mSessionHistory->GetEntryAtIndex(index, PR_FALSE,
|
|
|
|
getter_AddRefs(hEntry));
|
|
|
|
NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(hEntry));
|
|
|
|
if (shEntry)
|
2001-06-30 15:02:25 +04:00
|
|
|
shEntry->SetTitle(mTitle.get());
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
|
2000-06-06 02:13:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
2001-08-14 08:46:20 +04:00
|
|
|
//
|
|
|
|
// Stop any current network activity. Do not stop the content until
|
|
|
|
// data starts arriving from the new URI...
|
|
|
|
//
|
|
|
|
rv = Stop(nsIWebNavigation::STOP_NETWORK);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-08-17 03:49:50 +04:00
|
|
|
|
2000-09-10 10:00:46 +04:00
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
mLoadType = aLoadType;
|
2001-10-20 01:28:57 +04:00
|
|
|
// mLSHE should be assigned to aSHEntry, only after Stop() has
|
|
|
|
// been called.
|
|
|
|
mLSHE = aSHEntry;
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-10-27 06:52:39 +04:00
|
|
|
rv = DoURILoad(aURI, aReferrer, owner, aPostData, aHeadersData);
|
2001-05-14 06:16:27 +04:00
|
|
|
|
|
|
|
return rv;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::CreateFixupURI(const PRUnichar * aStringURI, nsIURI ** aURI)
|
2000-04-04 04:04:04 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
*aURI = nsnull;
|
|
|
|
nsAutoString uriString(aStringURI);
|
2001-11-20 00:48:31 +03:00
|
|
|
uriString.Trim(" "); // Cleanup the empty spaces that might be on each end.
|
2000-04-12 03:52:42 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Eliminate embedded newlines, which single-line text fields now allow:
|
|
|
|
uriString.StripChars("\r\n");
|
2000-08-29 02:15:03 +04:00
|
|
|
|
2001-11-18 10:45:14 +03:00
|
|
|
NS_ENSURE_TRUE(uriString.Length() > 0, NS_ERROR_FAILURE);
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Create the fixup object if necessary
|
|
|
|
if (!mURIFixup) {
|
|
|
|
mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID);
|
|
|
|
if (!mURIFixup) {
|
|
|
|
// No fixup service so try and create a URI and see what happens
|
|
|
|
return NS_NewURI(aURI, uriString, nsnull);
|
|
|
|
}
|
|
|
|
}
|
2000-04-12 03:52:42 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Call the fixup object
|
2001-11-07 01:55:30 +03:00
|
|
|
return mURIFixup->CreateFixupURI(aStringURI,
|
|
|
|
nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP, aURI);
|
2000-04-04 04:04:04 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetCurrentDocumentOwner(nsISupports ** aOwner)
|
2000-06-14 03:56:30 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
*aOwner = nsnull;
|
2000-08-10 00:08:54 +04:00
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
//-- Get the current document
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mContentViewer) {
|
|
|
|
nsCOMPtr<nsIDocumentViewer>
|
|
|
|
docViewer(do_QueryInterface(mContentViewer));
|
|
|
|
if (!docViewer)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-08-10 00:08:54 +04:00
|
|
|
rv = docViewer->GetDocument(*getter_AddRefs(document));
|
|
|
|
}
|
2001-05-30 06:22:22 +04:00
|
|
|
else //-- If there's no document loaded yet, look at the parent (frameset)
|
2000-08-10 00:08:54 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
rv = GetSameTypeParent(getter_AddRefs(parentItem));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (NS_FAILED(rv) || !parentItem)
|
|
|
|
return rv;
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal>
|
|
|
|
parentWindow(do_GetInterface(parentItem));
|
|
|
|
if (!parentWindow)
|
|
|
|
return NS_OK;
|
2000-08-10 00:08:54 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> parentDomDoc;
|
|
|
|
rv = parentWindow->GetDocument(getter_AddRefs(parentDomDoc));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (!parentDomDoc)
|
|
|
|
return NS_OK;
|
2000-08-10 00:08:54 +04:00
|
|
|
document = do_QueryInterface(parentDomDoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-- Get the document's principal
|
2000-06-14 03:56:30 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2000-08-10 00:08:54 +04:00
|
|
|
rv = document->GetPrincipal(getter_AddRefs(principal));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (NS_FAILED(rv) || !principal)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
rv = principal->QueryInterface(NS_GET_IID(nsISupports), (void **) aOwner);
|
2000-06-14 03:56:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
nsresult nsDocShell::DoURILoad(nsIURI * aURI,
|
|
|
|
nsIURI * aReferrerURI,
|
|
|
|
nsISupports * aOwner,
|
|
|
|
nsIInputStream * aPostData,
|
|
|
|
nsIInputStream * aHeadersData)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURILoader> uriLoader;
|
|
|
|
|
|
|
|
uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
// we need to get the load group from our load cookie so we can pass it into open uri...
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2001-05-14 06:16:27 +04:00
|
|
|
rv = uriLoader->GetLoadGroupForContext(NS_STATIC_CAST
|
|
|
|
(nsIDocShell *, this),
|
|
|
|
getter_AddRefs(loadGroup));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
// open a channel for the url
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
rv = NS_OpenURI(getter_AddRefs(channel),
|
|
|
|
aURI,
|
|
|
|
nsnull,
|
|
|
|
loadGroup,
|
|
|
|
NS_STATIC_CAST(nsIInterfaceRequestor *, this));
|
2001-05-18 01:38:27 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
channel->SetOriginalURI(aURI);
|
|
|
|
|
2001-05-12 01:05:08 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
2001-05-14 06:16:27 +04:00
|
|
|
//
|
|
|
|
// If this is a HTTP channel, then set up the HTTP specific information
|
2001-12-01 01:35:33 +03:00
|
|
|
// (ie. POST data, referrer, ...)
|
2001-05-14 06:16:27 +04:00
|
|
|
//
|
2001-04-27 17:38:15 +04:00
|
|
|
if (httpChannel) {
|
2001-11-02 01:21:31 +03:00
|
|
|
nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(httpChannel));
|
2001-04-27 17:38:15 +04:00
|
|
|
/* Get the cache Key from SH */
|
|
|
|
nsCOMPtr<nsISupports> cacheKey;
|
2001-07-03 04:00:12 +04:00
|
|
|
if (mLSHE) {
|
|
|
|
mLSHE->GetCacheKey(getter_AddRefs(cacheKey));
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2001-07-03 04:00:12 +04:00
|
|
|
else if (mOSHE) // for reload cases
|
|
|
|
mOSHE->GetCacheKey(getter_AddRefs(cacheKey));
|
2001-04-27 17:38:15 +04: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 (aPostData) {
|
|
|
|
// XXX it's a bit of a hack to rewind the postdata stream here but
|
|
|
|
// it has to be done in case the post data is being reused multiple
|
|
|
|
// times.
|
2001-11-14 09:45:27 +03:00
|
|
|
nsCOMPtr<nsISeekableStream>
|
|
|
|
postDataSeekable(do_QueryInterface(aPostData));
|
|
|
|
if (postDataSeekable) {
|
|
|
|
postDataSeekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
|
2001-09-05 07:52:26 +04:00
|
|
|
nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(httpChannel));
|
|
|
|
NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel");
|
|
|
|
|
|
|
|
// we really need to have a content type associated with this stream!!
|
|
|
|
uploadChannel->SetUploadStream(aPostData,nsnull, -1);
|
2001-04-27 17:38:15 +04:00
|
|
|
/* If there is a valid postdata *and* it is a History Load,
|
|
|
|
* set up the cache key on the channel, to retrieve the
|
2001-11-02 01:21:31 +03:00
|
|
|
* data *only* from the cache. If it is a normal reload, the
|
|
|
|
* cache is free to go to the server for updated postdata.
|
2001-04-27 17:38:15 +04:00
|
|
|
*/
|
2001-11-02 01:21:31 +03:00
|
|
|
if (cacheChannel && cacheKey) {
|
|
|
|
if (mLoadType == LOAD_HISTORY || mLoadType == LOAD_RELOAD_CHARSET_CHANGE)
|
|
|
|
cacheChannel->SetCacheKey(cacheKey, PR_TRUE);
|
|
|
|
else if (mLoadType == LOAD_RELOAD_NORMAL)
|
|
|
|
cacheChannel->SetCacheKey(cacheKey, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-14 02:20:33 +04:00
|
|
|
}
|
|
|
|
else {
|
2001-04-27 17:38:15 +04:00
|
|
|
/* If there is no postdata, set the cache key on the channel
|
|
|
|
* with the readFromCacheOnly set to false, so that cache will
|
|
|
|
* be free to get it from net if it is not found in cache.
|
|
|
|
* New cache may use it creatively on CGI pages with GET
|
|
|
|
* method and even on those that say "no-cache"
|
|
|
|
*/
|
2001-06-30 02:12:14 +04:00
|
|
|
if (mLoadType == LOAD_HISTORY || mLoadType == LOAD_RELOAD_NORMAL
|
|
|
|
|| mLoadType == LOAD_RELOAD_CHARSET_CHANGE) {
|
2001-04-27 17:38:15 +04:00
|
|
|
if (cacheChannel && cacheKey)
|
|
|
|
cacheChannel->SetCacheKey(cacheKey, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aHeadersData) {
|
|
|
|
rv = AddHeadersToChannel(aHeadersData, httpChannel);
|
2001-04-14 02:20:33 +04:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
// Set the referrer explicitly
|
|
|
|
if (aReferrerURI) // Referrer is currenly only set for link clicks here.
|
|
|
|
httpChannel->SetReferrer(aReferrerURI,
|
2001-05-12 01:05:08 +04:00
|
|
|
nsIHttpChannel::REFERRER_LINK_CLICK);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2001-05-14 06:16:27 +04:00
|
|
|
//
|
|
|
|
// Set the owner of the channel - only for javascript and data channels.
|
|
|
|
//
|
|
|
|
// XXX: Is seems wrong that the owner is ignored - even if one is
|
|
|
|
// supplied) unless the URI is javascript or data.
|
|
|
|
//
|
|
|
|
// (Currently chrome URIs set the owner when they are created!
|
|
|
|
// So setting a NULL owner would be bad!)
|
|
|
|
//
|
|
|
|
PRBool isJSOrData = PR_FALSE;
|
|
|
|
aURI->SchemeIs("javascript", &isJSOrData);
|
|
|
|
if (!isJSOrData) {
|
|
|
|
aURI->SchemeIs("data", &isJSOrData);
|
|
|
|
}
|
|
|
|
if (isJSOrData) {
|
|
|
|
channel->SetOwner(aOwner);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
|
2001-10-27 06:52:39 +04:00
|
|
|
rv = DoChannelLoad(channel, uriLoader);
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
return rv;
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD
|
|
|
|
AHTC_WriteFunc(nsIInputStream * in,
|
|
|
|
void *closure,
|
|
|
|
const char *fromRawSegment,
|
|
|
|
PRUint32 toOffset, PRUint32 count, PRUint32 * writeCount)
|
2000-09-05 23:03:56 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
if (nsnull == writeCount || nsnull == closure ||
|
2000-09-05 23:03:56 +04:00
|
|
|
nsnull == fromRawSegment || nsCRT::strlen(fromRawSegment) < 1) {
|
|
|
|
return NS_BASE_STREAM_CLOSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
*writeCount = 0;
|
2001-04-27 17:38:15 +04:00
|
|
|
char *headersBuf = *((char **) closure);
|
2000-09-05 23:03:56 +04:00
|
|
|
// pointer to where we should start copying bytes from rawSegment
|
|
|
|
char *pHeadersBuf = nsnull;
|
|
|
|
PRUint32 headersBufLen;
|
|
|
|
PRUint32 rawSegmentLen = nsCRT::strlen(fromRawSegment);
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2000-09-05 23:03:56 +04:00
|
|
|
// if the buffer has no data yet
|
|
|
|
if (!headersBuf) {
|
|
|
|
headersBufLen = rawSegmentLen;
|
|
|
|
pHeadersBuf = headersBuf = (char *) nsMemory::Alloc(headersBufLen + 1);
|
|
|
|
if (!headersBuf) {
|
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
}
|
|
|
|
nsCRT::memset(headersBuf, nsnull, headersBufLen + 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// data has been read, reallocate
|
|
|
|
// store a pointer to the old full buffer
|
|
|
|
pHeadersBuf = headersBuf;
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2000-09-05 23:03:56 +04:00
|
|
|
// create a new buffer
|
|
|
|
headersBufLen = nsCRT::strlen(headersBuf);
|
2001-04-27 17:38:15 +04:00
|
|
|
headersBuf =
|
|
|
|
(char *) nsMemory::Alloc(rawSegmentLen + headersBufLen + 1);
|
2000-09-05 23:03:56 +04:00
|
|
|
if (!headersBuf) {
|
|
|
|
headersBuf = pHeadersBuf;
|
|
|
|
pHeadersBuf = nsnull;
|
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
}
|
|
|
|
memset(headersBuf, nsnull, rawSegmentLen + headersBufLen + 1);
|
|
|
|
// copy the old buffer to the beginning of the new buffer
|
|
|
|
nsCRT::memcpy(headersBuf, pHeadersBuf, headersBufLen);
|
|
|
|
// free the old buffer
|
|
|
|
nsCRT::free(pHeadersBuf);
|
|
|
|
// make the buffer pointer point to the writeable part
|
|
|
|
// of the new buffer
|
|
|
|
pHeadersBuf = headersBuf + headersBufLen;
|
|
|
|
// increment the length of the buffer
|
|
|
|
headersBufLen += rawSegmentLen;
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-09-05 23:03:56 +04:00
|
|
|
|
|
|
|
// at this point, pHeadersBuf points to where we should copy bits
|
|
|
|
// from fromRawSegment.
|
|
|
|
nsCRT::memcpy(pHeadersBuf, fromRawSegment, rawSegmentLen);
|
|
|
|
// null termination
|
|
|
|
headersBuf[headersBufLen] = nsnull;
|
2001-04-27 17:38:15 +04:00
|
|
|
*((char **) closure) = headersBuf;
|
2000-09-05 23:03:56 +04:00
|
|
|
*writeCount = rawSegmentLen;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::AddHeadersToChannel(nsIInputStream * aHeadersData,
|
|
|
|
nsIChannel * aGenericChannel)
|
2000-09-05 23:03:56 +04:00
|
|
|
{
|
|
|
|
if (nsnull == aHeadersData || nsnull == aGenericChannel) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-05-12 01:05:08 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> aChannel = do_QueryInterface(aGenericChannel);
|
2000-09-05 23:03:56 +04:00
|
|
|
if (!aChannel) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// used during the manipulation of the InputStream
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
PRUint32 available = 0;
|
|
|
|
PRUint32 bytesRead;
|
|
|
|
char *headersBuf = nsnull;
|
|
|
|
|
|
|
|
// used during the manipulation of the String from the InputStream
|
|
|
|
nsCAutoString headersString;
|
|
|
|
nsCAutoString oneHeader;
|
|
|
|
nsCAutoString headerName;
|
|
|
|
nsCAutoString headerValue;
|
2001-03-10 06:19:36 +03:00
|
|
|
PRInt32 crlf = 0;
|
|
|
|
PRInt32 colon = 0;
|
2000-09-05 23:03:56 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Suck all the data out of the nsIInputStream into a char * buffer.
|
|
|
|
//
|
|
|
|
|
|
|
|
rv = aHeadersData->Available(&available);
|
|
|
|
if (NS_FAILED(rv) || available < 1) {
|
|
|
|
goto AHTC_CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
aHeadersData->ReadSegments(AHTC_WriteFunc, &headersBuf, available,
|
|
|
|
&bytesRead);
|
|
|
|
rv = aHeadersData->Available(&available);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto AHTC_CLEANUP;
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
} while (0 < available);
|
|
|
|
|
2000-09-05 23:03:56 +04:00
|
|
|
//
|
|
|
|
// Turn the char * buffer into an nsString.
|
|
|
|
//
|
|
|
|
headersString = (const char *) headersBuf;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Iterate over the nsString: for each "\r\n" delimeted chunk,
|
2001-05-12 01:05:08 +04:00
|
|
|
// add the value as a header to the nsIHttpChannel
|
2000-09-05 23:03:56 +04:00
|
|
|
//
|
|
|
|
|
2000-09-06 01:35:59 +04:00
|
|
|
while (PR_TRUE) {
|
2000-09-05 23:03:56 +04:00
|
|
|
crlf = headersString.Find("\r\n", PR_TRUE);
|
|
|
|
if (-1 == crlf) {
|
|
|
|
rv = NS_OK;
|
|
|
|
goto AHTC_CLEANUP;
|
|
|
|
}
|
|
|
|
headersString.Mid(oneHeader, 0, crlf);
|
|
|
|
headersString.Cut(0, crlf + 2);
|
|
|
|
oneHeader.StripWhitespace();
|
|
|
|
colon = oneHeader.Find(":");
|
|
|
|
if (-1 == colon) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto AHTC_CLEANUP;
|
|
|
|
}
|
|
|
|
oneHeader.Left(headerName, colon);
|
|
|
|
colon++;
|
|
|
|
oneHeader.Mid(headerValue, colon, oneHeader.Length() - colon);
|
|
|
|
|
|
|
|
//
|
|
|
|
// FINALLY: we can set the header!
|
|
|
|
//
|
|
|
|
|
2001-05-12 01:05:08 +04:00
|
|
|
rv = aChannel->SetRequestHeader(headerName.get(), headerValue.get());
|
2000-09-05 23:03:56 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto AHTC_CLEANUP;
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
AHTC_CLEANUP:
|
2000-09-05 23:03:56 +04:00
|
|
|
nsMemory::Free((void *) headersBuf);
|
|
|
|
headersBuf = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
nsresult nsDocShell::DoChannelLoad(nsIChannel * aChannel,
|
|
|
|
nsIURILoader * aURILoader)
|
2001-04-27 17:38:15 +04:00
|
|
|
{
|
2001-05-14 06:16:27 +04:00
|
|
|
nsresult rv;
|
2001-04-27 17:38:15 +04:00
|
|
|
// Mark the channel as being a document URI...
|
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
(void) aChannel->GetLoadFlags(&loadFlags);
|
|
|
|
loadFlags |= nsIChannel::LOAD_DOCUMENT_URI;
|
|
|
|
|
|
|
|
// Load attributes depend on load type...
|
|
|
|
switch (mLoadType) {
|
|
|
|
case LOAD_HISTORY:
|
2001-09-27 04:03:26 +04:00
|
|
|
loadFlags |= nsIRequest::VALIDATE_NEVER;
|
|
|
|
break;
|
|
|
|
|
2001-06-30 02:12:14 +04:00
|
|
|
case LOAD_RELOAD_CHARSET_CHANGE:
|
2001-04-27 17:38:15 +04:00
|
|
|
loadFlags |= nsIRequest::LOAD_FROM_CACHE;
|
|
|
|
break;
|
2001-06-30 02:12:14 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
case LOAD_RELOAD_NORMAL:
|
|
|
|
loadFlags |= nsIRequest::VALIDATE_ALWAYS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
|
|
|
|
case LOAD_REFRESH:
|
|
|
|
loadFlags |= nsIRequest::LOAD_BYPASS_CACHE;
|
|
|
|
break;
|
2001-09-27 04:03:26 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
case LOAD_NORMAL:
|
|
|
|
case LOAD_LINK:
|
|
|
|
// Set cache checking flags
|
|
|
|
if (mPrefs) {
|
|
|
|
PRInt32 prefSetting;
|
|
|
|
if (NS_SUCCEEDED
|
|
|
|
(mPrefs->
|
|
|
|
GetIntPref("browser.cache.check_doc_frequency",
|
|
|
|
&prefSetting))) {
|
|
|
|
switch (prefSetting) {
|
|
|
|
case 0:
|
|
|
|
loadFlags |= nsIRequest::VALIDATE_ONCE_PER_SESSION;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
loadFlags |= nsIRequest::VALIDATE_ALWAYS;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
loadFlags |= nsIRequest::VALIDATE_NEVER;
|
|
|
|
break;
|
2001-04-14 06:02:19 +04:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2000-07-01 03:39:30 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
(void) aChannel->SetLoadFlags(loadFlags);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
rv = aURILoader->OpenURI(aChannel,
|
2001-10-27 06:52:39 +04:00
|
|
|
(mLoadType == LOAD_LINK),
|
2001-05-14 06:16:27 +04:00
|
|
|
NS_STATIC_CAST(nsIDocShell *, this));
|
2001-06-06 04:10:09 +04:00
|
|
|
|
|
|
|
if (rv == NS_ERROR_PORT_ACCESS_NOT_ALLOWED) {
|
|
|
|
nsCOMPtr<nsIPrompt> prompter;
|
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
|
|
|
|
|
|
|
GetInterface(NS_GET_IID(nsIPrompt), getter_AddRefs(prompter));
|
|
|
|
if (!prompter) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundleService> sbs(do_GetService(NS_STRINGBUNDLE_CONTRACTID));
|
|
|
|
if (!sbs) return rv;
|
|
|
|
|
|
|
|
sbs->CreateBundle("chrome://necko/locale/necko.properties",
|
|
|
|
getter_AddRefs(stringBundle));
|
|
|
|
|
|
|
|
if (!stringBundle)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsXPIDLString messageStr;
|
|
|
|
stringBundle->GetStringFromName(NS_LITERAL_STRING("DeniedPortAccess").get(),
|
|
|
|
getter_Copies(messageStr));
|
|
|
|
|
|
|
|
prompter->Alert(nsnull, messageStr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
return rv;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::ScrollIfAnchor(nsIURI * aURI, PRBool * aWasAnchor)
|
2000-02-17 05:03:02 +03:00
|
|
|
{
|
2000-05-23 04:52:59 +04:00
|
|
|
NS_ASSERTION(aURI, "null uri arg");
|
2000-05-24 21:18:10 +04:00
|
|
|
NS_ASSERTION(aWasAnchor, "null anchor arg");
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (aURI == nsnull || aWasAnchor == nsnull) {
|
2000-05-23 04:52:59 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aWasAnchor = PR_FALSE;
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
if (!mCurrentURI) {
|
2000-05-23 04:52:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// NOTE: we assume URIs are absolute for comparison purposes
|
|
|
|
|
|
|
|
nsXPIDLCString currentSpec;
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(mCurrentURI->GetSpec(getter_Copies(currentSpec)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
nsXPIDLCString newSpec;
|
|
|
|
NS_ENSURE_SUCCESS(aURI->GetSpec(getter_Copies(newSpec)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Search for hash marks in the current URI and the new URI and
|
|
|
|
// take a copy of everything to the left of the hash for
|
|
|
|
// comparison.
|
|
|
|
|
|
|
|
const char kHash = '#';
|
|
|
|
|
|
|
|
// Split the new URI into a left and right part
|
2001-04-27 17:38:15 +04:00
|
|
|
nsAutoString sNew;
|
|
|
|
sNew.AssignWithConversion(newSpec);
|
2000-05-23 04:52:59 +04:00
|
|
|
nsAutoString sNewLeft;
|
|
|
|
nsAutoString sNewRef;
|
|
|
|
PRInt32 hashNew = sNew.FindChar(kHash);
|
2001-04-27 17:38:15 +04:00
|
|
|
if (hashNew == 0) {
|
|
|
|
return NS_OK; // Strange URI
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
else if (hashNew > 0) {
|
2000-05-23 04:52:59 +04:00
|
|
|
sNew.Left(sNewLeft, hashNew);
|
|
|
|
sNew.Right(sNewRef, sNew.Length() - hashNew - 1);
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
else {
|
2000-05-23 04:52:59 +04:00
|
|
|
sNewLeft = sNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split the current URI in a left and right part
|
2001-04-27 17:38:15 +04:00
|
|
|
nsAutoString sCurrent;
|
|
|
|
sCurrent.AssignWithConversion(currentSpec);
|
2000-05-23 04:52:59 +04:00
|
|
|
nsAutoString sCurrentLeft;
|
|
|
|
PRInt32 hashCurrent = sCurrent.FindChar(kHash);
|
2001-04-27 17:38:15 +04:00
|
|
|
if (hashCurrent == 0) {
|
|
|
|
return NS_OK; // Strange URI
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
else if (hashCurrent > 0) {
|
2000-05-23 04:52:59 +04:00
|
|
|
sCurrent.Left(sCurrentLeft, hashCurrent);
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
else {
|
2000-05-23 04:52:59 +04:00
|
|
|
sCurrentLeft = sCurrent;
|
|
|
|
}
|
|
|
|
|
2000-05-24 02:36:47 +04:00
|
|
|
// Exit when there are no anchors
|
2001-04-27 17:38:15 +04:00
|
|
|
if (hashNew <= 0 && hashCurrent <= 0) {
|
2000-05-24 02:36:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
// Compare the URIs.
|
|
|
|
//
|
2000-06-06 02:13:52 +04:00
|
|
|
// NOTE: this is a case sensitive comparison because some parts of the
|
|
|
|
// URI are case sensitive, and some are not. i.e. the domain name
|
|
|
|
// is case insensitive but the the paths are not.
|
|
|
|
//
|
|
|
|
// This means that comparing "http://www.ABC.com/" to "http://www.abc.com/"
|
|
|
|
// will fail this test.
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
if (sCurrentLeft.CompareWithConversion(sNewLeft, PR_FALSE, -1) != 0) {
|
|
|
|
return NS_OK; // URIs not the same
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Both the new and current URIs refer to the same page. We can now
|
|
|
|
// browse to the hash stored in the new URI.
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (!sNewRef.IsEmpty()) {
|
2000-05-23 04:52:59 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell = nsnull;
|
|
|
|
rv = GetPresShell(getter_AddRefs(shell));
|
2001-04-27 17:38:15 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
2000-05-24 21:18:10 +04:00
|
|
|
*aWasAnchor = PR_TRUE;
|
2000-08-18 11:31:40 +04:00
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
char *str = ToNewCString(sNewRef);
|
2000-08-18 11:31:40 +04:00
|
|
|
|
|
|
|
// nsUnescape modifies the string that is passed into it.
|
|
|
|
nsUnescape(str);
|
|
|
|
|
2000-11-15 03:17:41 +03:00
|
|
|
// We assume that the bytes are in UTF-8, as it says in the spec:
|
|
|
|
// http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1
|
|
|
|
nsAutoString savedNewRef(sNewRef);
|
|
|
|
sNewRef = NS_ConvertUTF8toUCS2(str);
|
2000-08-18 11:31:40 +04:00
|
|
|
|
|
|
|
nsMemory::Free(str);
|
|
|
|
|
2000-11-15 03:17:41 +03:00
|
|
|
// We try the UTF-8 string first, and then try the document's charset (see below).
|
2000-05-23 04:52:59 +04:00
|
|
|
rv = shell->GoToAnchor(sNewRef);
|
2000-11-15 03:17:41 +03:00
|
|
|
|
|
|
|
// Above will fail if the anchor name is not UTF-8.
|
|
|
|
// Need to convert from document charset to unicode.
|
2001-04-27 17:38:15 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Get a document charset
|
|
|
|
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIDocumentViewer>
|
|
|
|
docv(do_QueryInterface(mContentViewer));
|
|
|
|
NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
rv = docv->GetDocument(*getter_AddRefs(doc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
nsAutoString aCharset;
|
|
|
|
rv = doc->GetDocumentCharacterSet(aCharset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2001-09-29 12:28:41 +04:00
|
|
|
char *charsetStr = ToNewCString(aCharset);
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_TRUE(charsetStr, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// Use the saved string
|
2001-09-29 12:28:41 +04:00
|
|
|
char *uriStr = ToNewCString(savedNewRef);
|
2001-04-27 17:38:15 +04:00
|
|
|
if (!uriStr) {
|
|
|
|
nsMemory::Free(charsetStr);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITextToSubURI> textToSubURI =
|
|
|
|
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsMemory::Free(uriStr);
|
|
|
|
nsMemory::Free(charsetStr);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-11-15 03:17:41 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Unescape and convert to unicode
|
|
|
|
PRUnichar *uStr;
|
|
|
|
rv = textToSubURI->UnEscapeAndConvert(charsetStr, uriStr,
|
|
|
|
&uStr);
|
2000-11-15 03:17:41 +03:00
|
|
|
nsMemory::Free(uriStr);
|
|
|
|
nsMemory::Free(charsetStr);
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2000-11-15 03:17:41 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
sNewRef.Assign(uStr);
|
|
|
|
nsMemory::Free(uStr);
|
2000-11-15 03:17:41 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
rv = shell->GoToAnchor(sNewRef);
|
2000-11-15 03:17:41 +03:00
|
|
|
}
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
else {
|
2000-05-23 04:52:59 +04:00
|
|
|
// A bit of a hack - scroll to the top of the page.
|
2000-05-24 21:18:10 +04:00
|
|
|
SetCurScrollPosEx(0, 0);
|
2000-05-23 04:52:59 +04:00
|
|
|
*aWasAnchor = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
|
2000-06-22 09:36:13 +04:00
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel,
|
|
|
|
PRUint32 aLoadType)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2000-05-24 02:36:47 +04:00
|
|
|
NS_ASSERTION(aURI, "uri is null");
|
2000-03-30 06:24:17 +04:00
|
|
|
|
2000-05-24 02:36:47 +04:00
|
|
|
UpdateCurrentGlobalHistory();
|
|
|
|
PRBool updateHistory = PR_TRUE;
|
2000-12-18 23:02:26 +03:00
|
|
|
PRBool equalUri = PR_FALSE;
|
2001-09-08 02:06:08 +04:00
|
|
|
PRBool shAvailable = PR_TRUE;
|
2000-03-31 02:38:32 +04:00
|
|
|
|
2000-12-18 23:02:26 +03:00
|
|
|
// Get the post data from the channel
|
|
|
|
nsCOMPtr<nsIInputStream> inputStream;
|
|
|
|
if (aChannel) {
|
2001-05-12 01:05:08 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));
|
2001-11-28 02:14:15 +03:00
|
|
|
|
|
|
|
// Check if the HTTPChannel is hiding under a multiPartChannel
|
|
|
|
if (!httpChannel) {
|
|
|
|
GetHttpChannel(aChannel, getter_AddRefs(httpChannel));
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
if (httpChannel) {
|
2000-12-18 23:02:26 +03:00
|
|
|
httpChannel->GetUploadStream(getter_AddRefs(inputStream));
|
|
|
|
}
|
|
|
|
}
|
2001-07-13 08:53:58 +04:00
|
|
|
/* Create SH Entry (mLSHE) only if there is a SessionHistory object (mSessionHistory) in
|
|
|
|
* the current frame or in the root docshell
|
|
|
|
*/
|
2001-09-22 04:12:41 +04:00
|
|
|
nsCOMPtr<nsISHistory> rootSH=mSessionHistory;
|
2001-11-20 23:14:02 +03:00
|
|
|
if (!rootSH) {
|
|
|
|
// Get the handle to SH from the root docshell
|
|
|
|
nsresult rv = GetRootSessionHistory(getter_AddRefs(rootSH));
|
|
|
|
if (!rootSH)
|
|
|
|
shAvailable = PR_FALSE;
|
|
|
|
} // rootSH
|
2001-09-08 02:06:08 +04:00
|
|
|
|
2001-09-22 04:12:41 +04:00
|
|
|
|
2001-09-08 02:06:08 +04:00
|
|
|
// Determine if this type of load should update history.
|
2001-08-17 03:49:50 +04:00
|
|
|
if (aLoadType == LOAD_BYPASS_HISTORY ||
|
2001-08-24 01:56:38 +04:00
|
|
|
aLoadType & LOAD_CMD_HISTORY ||
|
|
|
|
aLoadType & LOAD_CMD_RELOAD)
|
2001-04-27 17:38:15 +04:00
|
|
|
updateHistory = PR_FALSE;
|
2001-09-08 02:06:08 +04:00
|
|
|
|
2001-08-24 01:56:38 +04:00
|
|
|
|
|
|
|
/* If the url to be loaded is the same as the one already there,
|
|
|
|
* and the original loadType is LOAD_NORMAL or LOAD_LINK,
|
|
|
|
* set loadType to LOAD_NORMAL_REPLACE so that AddToSessionHistory()
|
|
|
|
* won't mess with the current SHEntry and if this page has any frame
|
|
|
|
* children, it also will be handled properly. see bug 83684
|
|
|
|
*
|
|
|
|
* XXX Hopefully changing the loadType at this time will not hurt
|
|
|
|
* anywhere. The other way to take care of sequentially repeating
|
|
|
|
* frameset pages is to add new methods to nsIDocShellTreeItem.
|
|
|
|
* Hopefully I don't have to do that.
|
|
|
|
*/
|
2001-11-20 00:39:40 +03:00
|
|
|
if ((mLoadType == LOAD_NORMAL ||
|
|
|
|
mLoadType == LOAD_LINK ||
|
|
|
|
mLoadType == LOAD_REFRESH) &&
|
|
|
|
!inputStream &&
|
|
|
|
mCurrentURI &&
|
|
|
|
NS_SUCCEEDED(aURI->Equals(mCurrentURI, &equalUri)) &&
|
|
|
|
equalUri)
|
|
|
|
{
|
2001-08-24 01:56:38 +04:00
|
|
|
mLoadType = LOAD_NORMAL_REPLACE;
|
2001-11-20 00:39:40 +03:00
|
|
|
}
|
2001-08-24 01:56:38 +04:00
|
|
|
|
|
|
|
/* If the user pressed shift-reload, cache will create a new cache key
|
|
|
|
* for the page. Save the new cacheKey in Session History.
|
|
|
|
* see bug 90098
|
|
|
|
*/
|
|
|
|
if (aChannel && aLoadType == LOAD_RELOAD_BYPASS_CACHE ||
|
|
|
|
aLoadType == LOAD_RELOAD_BYPASS_PROXY ||
|
|
|
|
aLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(aChannel));
|
|
|
|
nsCOMPtr<nsISupports> cacheKey;
|
|
|
|
// Get the Cache Key and store it in SH.
|
|
|
|
if (cacheChannel)
|
|
|
|
cacheChannel->GetCacheKey(getter_AddRefs(cacheKey));
|
|
|
|
if (mLSHE)
|
|
|
|
mLSHE->SetCacheKey(cacheKey);
|
2000-09-20 16:23:53 +04:00
|
|
|
}
|
2000-06-24 03:54:30 +04:00
|
|
|
|
2001-09-22 04:12:41 +04:00
|
|
|
|
2001-07-13 08:53:58 +04:00
|
|
|
if (updateHistory && shAvailable) {
|
2001-09-22 04:12:41 +04:00
|
|
|
// Update session history if necessary...
|
2001-07-03 04:00:12 +04:00
|
|
|
if (!mLSHE && (mItemType == typeContent) && mURIResultedInDocument) {
|
2001-04-27 17:38:15 +04:00
|
|
|
/* This is a fresh page getting loaded for the first time
|
|
|
|
*.Create a Entry for it and add it to SH, if this is the
|
|
|
|
* rootDocShell
|
|
|
|
*/
|
2001-07-03 04:00:12 +04:00
|
|
|
(void) AddToSessionHistory(aURI, aChannel, getter_AddRefs(mLSHE));
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-06-22 09:36:13 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Update Global history if necessary...
|
|
|
|
updateHistory = PR_FALSE;
|
|
|
|
ShouldAddToGlobalHistory(aURI, &updateHistory);
|
|
|
|
if (updateHistory) {
|
|
|
|
AddToGlobalHistory(aURI);
|
|
|
|
}
|
2000-07-06 08:34:52 +04:00
|
|
|
}
|
2000-03-25 06:43:27 +03:00
|
|
|
|
2001-09-22 04:12:41 +04:00
|
|
|
// If this was a history load, update the index in
|
|
|
|
// SH.
|
|
|
|
if (rootSH && (mLoadType & LOAD_CMD_HISTORY)) {
|
|
|
|
nsCOMPtr<nsISHistoryInternal> shInternal(do_QueryInterface(rootSH));
|
|
|
|
if (shInternal)
|
|
|
|
shInternal->UpdateIndex();
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
SetCurrentURI(aURI);
|
|
|
|
// if there's a refresh header in the channel, this method
|
|
|
|
// will set it up for us.
|
|
|
|
SetupRefreshURI(aChannel);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-11-01 11:03:58 +03:00
|
|
|
}
|
|
|
|
|
2001-04-20 12:11:12 +04:00
|
|
|
nsresult
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::RefreshURIFromHeader(nsIURI * aBaseURI,
|
|
|
|
const nsAReadableString & aHeader)
|
|
|
|
{
|
|
|
|
// Refresh headers are parsed with the following format in mind
|
|
|
|
// <META HTTP-EQUIV=REFRESH CONTENT="5; URL=http://uri">
|
|
|
|
// By the time we are here, the following is true:
|
|
|
|
// header = "REFRESH"
|
|
|
|
// content = "5; URL=http://uri" // note the URL attribute is
|
|
|
|
// optional, if it is absent, the currently loaded url is used.
|
|
|
|
// Also note that the seconds and URL separator can be either
|
|
|
|
// a ';' or a ','. The ',' separator should be illegal but CNN
|
|
|
|
// is using it.
|
|
|
|
//
|
|
|
|
// We need to handle the following strings, where
|
|
|
|
// - X is a set of digits
|
|
|
|
// - URI is either a relative or absolute URI
|
|
|
|
//
|
|
|
|
// Note that URI should start with "url=" but we allow omission
|
|
|
|
//
|
|
|
|
// "" || ";" || ","
|
|
|
|
// empty string. use the currently loaded URI
|
|
|
|
// and refresh immediately.
|
|
|
|
// "X" || "X;" || "X,"
|
|
|
|
// Refresh the currently loaded URI in X seconds.
|
|
|
|
// "X; URI" || "X, URI"
|
|
|
|
// Refresh using URI as the destination in X seconds.
|
|
|
|
// "URI" || "; URI" || ", URI"
|
|
|
|
// Refresh immediately using URI as the destination.
|
|
|
|
//
|
|
|
|
// Currently, anything immediately following the URI, if
|
|
|
|
// seperated by any char in the set "'\"\t\r\n " will be
|
|
|
|
// ignored. So "10; url=go.html ; foo=bar" will work,
|
|
|
|
// and so will "10; url='go.html'; foo=bar". However,
|
|
|
|
// "10; url=go.html; foo=bar" will result in the uri
|
|
|
|
// "go.html;" since ';' and ',' are valid uri characters.
|
|
|
|
//
|
|
|
|
// Note that we need to remove any tokens wrapping the URI.
|
|
|
|
// These tokens currently include spaces, double and single
|
|
|
|
// quotes.
|
|
|
|
|
|
|
|
// when done, seconds is 0 or the given number of seconds
|
|
|
|
// uriAttrib is empty or the URI specified
|
|
|
|
nsAutoString uriAttrib;
|
|
|
|
PRInt32 seconds = 0;
|
|
|
|
|
|
|
|
nsReadingIterator < PRUnichar > iter, tokenStart, doneIterating;
|
|
|
|
|
|
|
|
aHeader.BeginReading(iter);
|
|
|
|
aHeader.EndReading(doneIterating);
|
|
|
|
|
|
|
|
// skip leading whitespace
|
|
|
|
while (iter != doneIterating && nsCRT::IsAsciiSpace(*iter))
|
2001-04-20 12:11:12 +04:00
|
|
|
++iter;
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
tokenStart = iter;
|
|
|
|
|
|
|
|
// skip leading + and -
|
|
|
|
if (iter != doneIterating && (*iter == '-' || *iter == '+'))
|
2001-04-20 12:11:12 +04:00
|
|
|
++iter;
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// parse number
|
|
|
|
while (iter != doneIterating && (*iter >= '0' && *iter <= '9')) {
|
|
|
|
seconds = seconds * 10 + (*iter - '0');
|
|
|
|
++iter;
|
2001-04-20 12:11:12 +04:00
|
|
|
}
|
2000-05-24 06:32:13 +04:00
|
|
|
|
2001-06-12 02:05:59 +04:00
|
|
|
if (iter != doneIterating) {
|
|
|
|
// if we started with a '-', number is negative
|
|
|
|
if (*tokenStart == '-')
|
|
|
|
seconds = -seconds;
|
|
|
|
|
|
|
|
// skip to next ';' or ','
|
|
|
|
while (iter != doneIterating && !(*iter == ';' || *iter == ','))
|
2001-04-27 17:38:15 +04:00
|
|
|
++iter;
|
|
|
|
|
2001-06-12 02:05:59 +04:00
|
|
|
// skip ';' or ','
|
|
|
|
if (iter != doneIterating && (*iter == ';' || *iter == ',')) {
|
|
|
|
++iter;
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
// skip whitespace
|
|
|
|
while (iter != doneIterating && nsCRT::IsAsciiSpace(*iter))
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
2000-05-24 06:32:13 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// possible start of URI
|
|
|
|
tokenStart = iter;
|
2001-04-20 12:11:12 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// skip "url = " to real start of URI
|
|
|
|
if (iter != doneIterating && (*iter == 'u' || *iter == 'U')) {
|
|
|
|
++iter;
|
|
|
|
if (iter != doneIterating && (*iter == 'r' || *iter == 'R')) {
|
2001-04-20 12:11:12 +04:00
|
|
|
++iter;
|
2001-04-27 17:38:15 +04:00
|
|
|
if (iter != doneIterating && (*iter == 'l' || *iter == 'L')) {
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
// skip whitespace
|
|
|
|
while (iter != doneIterating && nsCRT::IsAsciiSpace(*iter))
|
|
|
|
++iter;
|
2001-04-20 12:11:12 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (iter != doneIterating && *iter == '=') {
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
// skip whitespace
|
|
|
|
while (iter != doneIterating && nsCRT::IsAsciiSpace(*iter))
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
// found real start of URI
|
|
|
|
tokenStart = iter;
|
|
|
|
}
|
|
|
|
}
|
2000-05-24 06:32:13 +04:00
|
|
|
}
|
2001-04-20 12:11:12 +04:00
|
|
|
}
|
|
|
|
|
2001-06-12 02:05:59 +04:00
|
|
|
// skip a leading '"' or '\''
|
|
|
|
if (tokenStart != doneIterating && (*tokenStart == '"' || *tokenStart == '\''))
|
2001-04-27 17:38:15 +04:00
|
|
|
++tokenStart;
|
2001-04-20 12:11:12 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// set iter to start of URI
|
|
|
|
iter = tokenStart;
|
2001-04-20 12:11:12 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// tokenStart here points to the beginning of URI
|
2001-04-20 12:11:12 +04:00
|
|
|
|
2001-06-12 02:05:59 +04:00
|
|
|
// skip anything which isn't whitespace
|
|
|
|
while (iter != doneIterating && !nsCRT::IsAsciiSpace(*iter))
|
2001-04-27 17:38:15 +04:00
|
|
|
++iter;
|
2001-04-20 12:11:12 +04:00
|
|
|
|
2001-06-12 02:05:59 +04:00
|
|
|
// move iter one back if the last character is a '"' or '\''
|
|
|
|
if (iter != tokenStart) {
|
|
|
|
--iter;
|
|
|
|
if (!(*iter == '"' || *iter == '\''))
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// URI is whatever's contained from tokenStart to iter.
|
|
|
|
// note: if tokenStart == doneIterating, so is iter.
|
2000-05-24 06:32:13 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv = NS_OK;
|
2001-04-20 12:11:12 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (tokenStart == iter) {
|
|
|
|
uri = aBaseURI;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uriAttrib = Substring(tokenStart, iter);
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), uriAttrib, aBaseURI);
|
|
|
|
}
|
2001-04-20 12:11:12 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager>
|
|
|
|
securityManager(do_GetService
|
|
|
|
(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = securityManager->CheckLoadURI(aBaseURI, uri,
|
|
|
|
nsIScriptSecurityManager::
|
|
|
|
DISALLOW_FROM_MAIL);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// since we can't travel back in time yet, just pretend it was meant figuratively
|
|
|
|
if (seconds < 0)
|
|
|
|
seconds = 0;
|
|
|
|
|
|
|
|
rv = RefreshURI(uri, seconds * 1000, PR_FALSE, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
2001-04-20 12:11:12 +04:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
return rv;
|
2001-04-20 12:11:12 +04:00
|
|
|
}
|
2000-03-30 06:24:17 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::SetupRefreshURI(nsIChannel * aChannel)
|
2001-04-20 12:11:12 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult
|
|
|
|
rv;
|
2001-05-12 01:05:08 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel, &rv));
|
2001-04-20 12:11:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIURI> referrer;
|
|
|
|
rv = httpChannel->GetReferrer(getter_AddRefs(referrer));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetReferrerURI(referrer);
|
|
|
|
|
2001-05-12 01:05:08 +04:00
|
|
|
nsXPIDLCString refreshHeader;
|
|
|
|
rv = httpChannel->GetResponseHeader("refresh",
|
2001-04-27 17:38:15 +04:00
|
|
|
getter_Copies(refreshHeader));
|
|
|
|
|
|
|
|
if (refreshHeader)
|
|
|
|
rv = RefreshURIFromHeader(mCurrentURI,
|
|
|
|
NS_ConvertUTF8toUCS2(refreshHeader));
|
|
|
|
}
|
2001-04-20 12:11:12 +04:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
return rv;
|
2000-05-24 02:36:47 +04:00
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::OnLoadingSite(nsIChannel * aChannel)
|
2000-05-24 02:36:47 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2000-08-29 07:28:30 +04:00
|
|
|
// If this a redirect, use the final url (uri)
|
|
|
|
// else use the original url
|
|
|
|
//
|
|
|
|
// The better way would be to trust the OnRedirect() that necko gives us.
|
|
|
|
// But this notification happen after the necko notification and hence
|
|
|
|
// overrides it. Until OnRedirect() gets settles out, let us do this.
|
|
|
|
nsLoadFlags loadFlags = 0;
|
2001-04-10 10:01:08 +04:00
|
|
|
aChannel->GetLoadFlags(&loadFlags);
|
2001-04-14 06:02:19 +04:00
|
|
|
if (loadFlags & nsIChannel::LOAD_REPLACE)
|
2000-08-29 07:28:30 +04:00
|
|
|
aChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
else
|
|
|
|
aChannel->GetOriginalURI(getter_AddRefs(uri));
|
2000-05-24 02:36:47 +04:00
|
|
|
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
OnNewURI(uri, aChannel, mLoadType);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
void
|
|
|
|
nsDocShell::SetReferrerURI(nsIURI * aURI)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mReferrerURI = aURI; // This assigment addrefs
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell: Session History
|
|
|
|
//*****************************************************************************
|
2001-04-27 17:38:15 +04:00
|
|
|
PRBool
|
|
|
|
nsDocShell::ShouldAddToSessionHistory(nsIURI * aURI)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-01-31 04:33:03 +03:00
|
|
|
// I believe none of the about: urls should go in the history. But then
|
|
|
|
// that could just be me... If the intent is only deny about:blank then we
|
|
|
|
// should just do a spec compare, rather than two gets of the scheme and
|
|
|
|
// then the path. -Gagan
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsXPIDLCString buffer;
|
|
|
|
nsCAutoString schemeStr;
|
2000-04-17 06:17:42 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
rv = aURI->GetScheme(getter_Copies(buffer));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
2000-07-08 09:17:49 +04:00
|
|
|
|
|
|
|
schemeStr = buffer;
|
2001-04-27 17:38:15 +04:00
|
|
|
if (schemeStr.Equals("about")) {
|
|
|
|
rv = aURI->GetPath(getter_Copies(buffer));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
schemeStr = buffer;
|
|
|
|
if (schemeStr.Equals("blank")) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocShell::AddToSessionHistory(nsIURI * aURI,
|
|
|
|
nsIChannel * aChannel, nsISHEntry ** aNewEntry)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
|
|
|
PRBool shouldPersist;
|
|
|
|
|
|
|
|
shouldPersist = ShouldAddToSessionHistory(aURI);
|
|
|
|
|
2001-11-07 02:56:45 +03:00
|
|
|
// Get a handle to the root docshell
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
/*
|
|
|
|
* If this is a LOAD_NORMAL_REPLACE in a subframe, we use
|
|
|
|
* the existing SH entry in the page and replace the url and
|
|
|
|
* other vitalities.
|
|
|
|
*/
|
|
|
|
if (LOAD_NORMAL_REPLACE == mLoadType && (root.get() != NS_STATIC_CAST(nsIDocShellTreeItem *, this))) {
|
|
|
|
// This is a subframe
|
2001-07-03 04:00:12 +04:00
|
|
|
entry = mOSHE;
|
2001-11-07 02:56:45 +03:00
|
|
|
nsCOMPtr<nsISHContainer> shContainer(do_QueryInterface(entry));
|
|
|
|
if (shContainer) {
|
|
|
|
PRInt32 childCount = 0;
|
|
|
|
shContainer->GetChildCount(&childCount);
|
|
|
|
// Remove all children of this entry
|
|
|
|
for (PRInt32 i = childCount - 1; i >= 0; i--) {
|
|
|
|
nsCOMPtr<nsISHEntry> child;
|
|
|
|
shContainer->GetChildAt(i, getter_AddRefs(child));
|
|
|
|
shContainer->RemoveChild(child);
|
|
|
|
} // for
|
|
|
|
} // shContainer
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-03-25 06:43:27 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Create a new entry if necessary.
|
2000-07-08 09:17:49 +04:00
|
|
|
if (!entry) {
|
2001-04-27 17:38:15 +04:00
|
|
|
entry = do_CreateInstance(NS_SHENTRY_CONTRACTID);
|
|
|
|
|
|
|
|
if (!entry) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-04-14 02:20:33 +04:00
|
|
|
}
|
2000-03-29 14:29:58 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Get the post data & referrer
|
|
|
|
nsCOMPtr<nsIInputStream> inputStream;
|
|
|
|
nsCOMPtr<nsIURI> referrerURI;
|
|
|
|
nsCOMPtr<nsISupports> cacheKey;
|
2001-08-10 18:43:03 +04:00
|
|
|
nsCOMPtr<nsISupports> cacheToken;
|
2001-09-08 02:06:08 +04:00
|
|
|
PRPackedBool expired = PR_FALSE;
|
2001-10-11 22:50:05 +04:00
|
|
|
nsXPIDLCString val;
|
2001-04-27 17:38:15 +04:00
|
|
|
if (aChannel) {
|
|
|
|
nsCOMPtr<nsICachingChannel>
|
|
|
|
cacheChannel(do_QueryInterface(aChannel));
|
|
|
|
/* If there is a caching channel, get the Cache Key and store it
|
|
|
|
* in SH.
|
|
|
|
*/
|
|
|
|
if (cacheChannel) {
|
|
|
|
cacheChannel->GetCacheKey(getter_AddRefs(cacheKey));
|
2001-08-10 18:43:03 +04:00
|
|
|
cacheChannel->GetCacheToken(getter_AddRefs(cacheToken));
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2001-05-12 01:05:08 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));
|
2001-11-28 02:14:15 +03:00
|
|
|
|
|
|
|
// Check if the httpChannel is hiding under a multipartChannel
|
|
|
|
if (!httpChannel) {
|
|
|
|
GetHttpChannel(aChannel, getter_AddRefs(httpChannel));
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
if (httpChannel) {
|
|
|
|
httpChannel->GetUploadStream(getter_AddRefs(inputStream));
|
|
|
|
httpChannel->GetReferrer(getter_AddRefs(referrerURI));
|
2001-10-11 22:50:05 +04:00
|
|
|
httpChannel->GetResponseHeader("Cache-Control", getter_Copies(val));
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
2000-03-29 14:29:58 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
//Title is set in nsDocShell::SetTitle()
|
|
|
|
entry->Create(aURI, // uri
|
|
|
|
nsnull, // Title
|
|
|
|
nsnull, // DOMDocument
|
|
|
|
inputStream, // Post data stream
|
|
|
|
nsnull, // LayoutHistory state
|
|
|
|
cacheKey); // CacheKey
|
|
|
|
entry->SetReferrerURI(referrerURI);
|
2001-08-10 18:43:03 +04:00
|
|
|
/* If cache got a 'no-store', ask SH not to store
|
|
|
|
* HistoryLayoutState. By default, SH will set this
|
|
|
|
* flag to PR_TRUE and save HistoryLayoutState.
|
2001-10-11 22:50:05 +04:00
|
|
|
*/
|
2001-10-13 05:03:59 +04:00
|
|
|
if (val && (PL_strcasestr(val, "no-store") || PL_strcasestr(val, "no-cache"))) {
|
2001-09-22 04:12:41 +04:00
|
|
|
entry->SetSaveLayoutStateFlag(PR_FALSE);
|
2001-10-11 22:50:05 +04:00
|
|
|
}
|
|
|
|
if (cacheToken) {
|
2001-09-22 04:12:41 +04:00
|
|
|
// Check if the page has expired from cache
|
|
|
|
nsCOMPtr<nsICacheEntryDescriptor> cacheEntryDesc(do_QueryInterface(cacheToken));
|
|
|
|
if (cacheEntryDesc) {
|
|
|
|
PRUint32 expTime;
|
|
|
|
cacheEntryDesc->GetExpirationTime(&expTime);
|
|
|
|
PRUint32 now = PRTimeToSeconds(PR_Now());
|
|
|
|
if (expTime <= now)
|
|
|
|
expired = PR_TRUE;
|
2001-09-08 02:06:08 +04:00
|
|
|
|
2001-09-22 04:12:41 +04:00
|
|
|
}
|
2001-09-08 02:06:08 +04:00
|
|
|
}
|
|
|
|
if (expired == PR_TRUE)
|
2001-09-22 04:12:41 +04:00
|
|
|
entry->SetExpirationStatus(PR_TRUE);
|
2000-09-02 02:34:19 +04:00
|
|
|
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// If no Session History component is available in the parent DocShell
|
2001-09-08 02:06:08 +04:00
|
|
|
// hierarchy, then AddChildSHEntry(...) will fail and the new entry
|
2001-04-27 17:38:15 +04:00
|
|
|
// will be deleted when it loses scope...
|
|
|
|
//
|
|
|
|
if (mLoadType != LOAD_NORMAL_REPLACE) {
|
|
|
|
if (mSessionHistory) {
|
|
|
|
nsCOMPtr<nsISHistoryInternal>
|
|
|
|
shPrivate(do_QueryInterface(mSessionHistory));
|
|
|
|
NS_ENSURE_TRUE(shPrivate, NS_ERROR_FAILURE);
|
|
|
|
rv = shPrivate->AddEntry(entry, shouldPersist);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = AddChildSHEntry(nsnull, entry, mChildOffset);
|
2001-03-28 07:35:38 +04:00
|
|
|
}
|
2001-11-07 02:56:45 +03:00
|
|
|
else {
|
|
|
|
if (root.get() == NS_STATIC_CAST(nsIDocShellTreeItem *, this) && mSessionHistory) {
|
|
|
|
// It is a LOAD_NORMAL_REPLACE on the root docshell
|
|
|
|
PRInt32 index = 0;
|
|
|
|
nsCOMPtr<nsIHistoryEntry> hEntry;
|
|
|
|
mSessionHistory->GetIndex(&index);
|
|
|
|
nsCOMPtr<nsISHistoryInternal> shPrivate(do_QueryInterface(mSessionHistory));
|
|
|
|
// Replace the current entry with the new entry
|
|
|
|
if (shPrivate)
|
|
|
|
rv = shPrivate->ReplaceEntry(index, entry);
|
|
|
|
}
|
|
|
|
}
|
2000-03-29 14:29:58 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Return the new SH entry...
|
|
|
|
if (aNewEntry) {
|
|
|
|
*aNewEntry = nsnull;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aNewEntry = entry;
|
|
|
|
NS_ADDREF(*aNewEntry);
|
|
|
|
}
|
2000-07-08 09:17:49 +04:00
|
|
|
}
|
2000-05-23 04:52:59 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return rv;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2000-02-17 05:03:02 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-05-14 06:16:27 +04:00
|
|
|
nsresult rv;
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsCOMPtr<nsIInputStream> postData;
|
|
|
|
nsCOMPtr<nsIURI> referrerURI;
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIHistoryEntry> hEntry(do_QueryInterface(aEntry));
|
|
|
|
NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(hEntry->GetURI(getter_AddRefs(uri)), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(aEntry->GetReferrerURI(getter_AddRefs(referrerURI)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)),
|
|
|
|
NS_ERROR_FAILURE);
|
2001-05-06 22:43:07 +04:00
|
|
|
|
2001-05-04 01:15:31 +04:00
|
|
|
/* If there is a valid postdata *and* the user pressed
|
2001-09-26 23:33:14 +04:00
|
|
|
* reload or shift-reload, take user's permission before we
|
|
|
|
* repost the data to the server.
|
2001-05-04 01:15:31 +04:00
|
|
|
*/
|
2001-09-26 23:33:14 +04:00
|
|
|
if ((aLoadType & LOAD_CMD_RELOAD) && postData) {
|
2001-05-04 01:15:31 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPrompt> prompter;
|
|
|
|
PRBool repost;
|
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
|
|
|
GetPromptAndStringBundle(getter_AddRefs(prompter),
|
|
|
|
getter_AddRefs(stringBundle));
|
|
|
|
|
|
|
|
if (stringBundle && prompter) {
|
|
|
|
nsXPIDLString messageStr;
|
2001-11-14 04:33:42 +03:00
|
|
|
nsresult rv = stringBundle->GetStringFromName(NS_LITERAL_STRING("repostConfirm").get(),
|
2001-05-04 01:15:31 +04:00
|
|
|
getter_Copies(messageStr));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && messageStr) {
|
|
|
|
prompter->Confirm(nsnull, messageStr, &repost);
|
|
|
|
/* If the user pressed cancel in the dialog,
|
|
|
|
* return failure.
|
|
|
|
*/
|
|
|
|
if (!repost)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
rv = InternalLoad(uri,
|
|
|
|
referrerURI,
|
|
|
|
nsnull, // No owner
|
2001-07-03 09:27:22 +04:00
|
|
|
PR_FALSE, // Do not inherit owner from document (security-critical!)
|
2001-05-14 06:16:27 +04:00
|
|
|
nsnull, // No window target
|
|
|
|
postData, // Post data stream
|
|
|
|
nsnull, // No headers stream
|
|
|
|
aLoadType, // Load type
|
|
|
|
aEntry); // SHEntry
|
|
|
|
return rv;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2000-06-21 10:40:08 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::PersistLayoutHistoryState()
|
2000-06-21 10:40:08 +04:00
|
|
|
{
|
2001-08-10 18:43:03 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
|
2001-07-03 04:00:12 +04:00
|
|
|
if (mOSHE) {
|
2001-08-10 18:43:03 +04:00
|
|
|
PRBool saveHistoryState = PR_TRUE;
|
2001-09-22 04:12:41 +04:00
|
|
|
mOSHE->GetSaveLayoutStateFlag(&saveHistoryState);
|
2001-08-10 18:43:03 +04:00
|
|
|
// Don't capture historystate and save it in history
|
|
|
|
// if the page asked not to do so.
|
|
|
|
if (!saveHistoryState)
|
|
|
|
return NS_OK;
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
2000-06-21 10:40:08 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
rv = GetPresShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
|
|
|
rv = shell->CaptureHistoryState(getter_AddRefs(layoutState),
|
|
|
|
PR_TRUE);
|
|
|
|
if (NS_SUCCEEDED(rv) && layoutState) {
|
2001-07-03 04:00:12 +04:00
|
|
|
rv = mOSHE->SetLayoutHistoryState(layoutState);
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
}
|
2000-06-21 10:40:08 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
return rv;
|
2000-06-21 10:40:08 +04:00
|
|
|
}
|
|
|
|
|
2000-06-30 01:48:18 +04:00
|
|
|
NS_IMETHODIMP
|
2000-11-02 09:34:44 +03:00
|
|
|
nsDocShell::CloneAndReplace(nsISHEntry * src, PRUint32 aCloneID,
|
2001-04-27 17:38:15 +04:00
|
|
|
nsISHEntry * replaceEntry,
|
|
|
|
nsISHEntry ** resultEntry)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
NS_ENSURE_ARG_POINTER(resultEntry);
|
|
|
|
nsISHEntry *dest = (nsISHEntry *) nsnull;
|
|
|
|
PRUint32 srcID;
|
|
|
|
src->GetID(&srcID);
|
|
|
|
nsCOMPtr<nsIHistoryEntry> srcHE(do_QueryInterface(src));
|
|
|
|
|
|
|
|
if (!src || !replaceEntry || !srcHE)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (srcID == aCloneID) {
|
|
|
|
dest = replaceEntry;
|
|
|
|
dest->SetIsSubFrame(PR_TRUE);
|
|
|
|
*resultEntry = dest;
|
|
|
|
NS_IF_ADDREF(*resultEntry);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsCOMPtr<nsIInputStream> postdata;
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> LHS;
|
|
|
|
nsCOMPtr<nsIURI> referrerURI;
|
|
|
|
PRUnichar *title = nsnull;
|
|
|
|
nsCOMPtr<nsISHEntry> parent;
|
2001-09-22 04:12:41 +04:00
|
|
|
PRBool expirationStatus;
|
|
|
|
PRBool layoutStatus;
|
|
|
|
nsCOMPtr<nsISupports> cacheKey;
|
2001-04-27 17:38:15 +04:00
|
|
|
PRUint32 id;
|
|
|
|
result = nsComponentManager::CreateInstance(NS_SHENTRY_CONTRACTID, NULL,
|
|
|
|
NS_GET_IID(nsISHEntry),
|
|
|
|
(void **) &dest);
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(result))
|
2001-04-27 17:38:15 +04:00
|
|
|
return result;
|
|
|
|
|
|
|
|
srcHE->GetURI(getter_AddRefs(uri));
|
|
|
|
src->GetReferrerURI(getter_AddRefs(referrerURI));
|
|
|
|
src->GetPostData(getter_AddRefs(postdata));
|
|
|
|
srcHE->GetTitle(&title);
|
|
|
|
src->GetLayoutHistoryState(getter_AddRefs(LHS));
|
|
|
|
//XXX Is this correct? parent is a weak ref in nsISHEntry
|
|
|
|
src->GetParent(getter_AddRefs(parent));
|
|
|
|
src->GetID(&id);
|
2001-09-22 04:12:41 +04:00
|
|
|
src->GetExpirationStatus(&expirationStatus);
|
|
|
|
src->GetSaveLayoutStateFlag(&layoutStatus);
|
|
|
|
src->GetCacheKey(getter_AddRefs(cacheKey));
|
2001-04-27 17:38:15 +04:00
|
|
|
|
|
|
|
// XXX do we care much about valid values for these uri, title etc....
|
|
|
|
dest->SetURI(uri);
|
|
|
|
dest->SetReferrerURI(referrerURI);
|
|
|
|
dest->SetPostData(postdata);
|
|
|
|
dest->SetLayoutHistoryState(LHS);
|
|
|
|
dest->SetTitle(title);
|
|
|
|
dest->SetParent(parent);
|
|
|
|
dest->SetID(id);
|
|
|
|
dest->SetIsSubFrame(PR_TRUE);
|
2001-09-22 04:12:41 +04:00
|
|
|
dest->SetExpirationStatus(expirationStatus);
|
|
|
|
dest->SetSaveLayoutStateFlag(layoutStatus);
|
|
|
|
dest->SetCacheKey(cacheKey);
|
2001-04-27 17:38:15 +04:00
|
|
|
*resultEntry = dest;
|
|
|
|
|
|
|
|
PRInt32 childCount = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHContainer> srcContainer(do_QueryInterface(src));
|
|
|
|
if (!srcContainer)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsISHContainer> destContainer(do_QueryInterface(dest));
|
|
|
|
if (!destContainer)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
srcContainer->GetChildCount(&childCount);
|
|
|
|
for (PRInt32 i = 0; i < childCount; i++) {
|
|
|
|
nsCOMPtr<nsISHEntry> srcChild;
|
|
|
|
srcContainer->GetChildAt(i, getter_AddRefs(srcChild));
|
|
|
|
if (!srcChild)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsISHEntry> destChild;
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(result))
|
2001-04-27 17:38:15 +04:00
|
|
|
return result;
|
|
|
|
result =
|
|
|
|
CloneAndReplace(srcChild, aCloneID, replaceEntry,
|
|
|
|
getter_AddRefs(destChild));
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(result))
|
2001-04-27 17:38:15 +04:00
|
|
|
return result;
|
|
|
|
result = destContainer->AddChild(destChild, i);
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(result))
|
2001-04-27 17:38:15 +04:00
|
|
|
return result;
|
|
|
|
} // for
|
|
|
|
}
|
2001-03-28 07:35:38 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return result;
|
2000-06-30 01:48:18 +04:00
|
|
|
|
|
|
|
}
|
2000-06-21 10:40:08 +04:00
|
|
|
|
2001-11-28 02:14:15 +03:00
|
|
|
|
2001-11-20 23:14:02 +03:00
|
|
|
nsresult
|
|
|
|
nsDocShell::GetRootSessionHistory(nsISHistory ** aReturn)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
//Get the root docshell
|
|
|
|
rv = GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
// QI to nsIWebNavigation
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsWebnav(do_QueryInterface(root));
|
|
|
|
if (rootAsWebnav) {
|
|
|
|
// Get the handle to SH from the root docshell
|
|
|
|
rv = rootAsWebnav->GetSessionHistory(aReturn);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-11-28 02:14:15 +03:00
|
|
|
nsresult
|
|
|
|
nsDocShell::GetHttpChannel(nsIChannel * aChannel, nsIHttpChannel ** aReturn)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
if (!aChannel)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMultiPartChannel> multiPartChannel(do_QueryInterface(aChannel));
|
|
|
|
if (multiPartChannel) {
|
|
|
|
nsCOMPtr<nsIChannel> baseChannel;
|
|
|
|
multiPartChannel->GetBaseChannel(getter_AddRefs(baseChannel));
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(baseChannel));
|
|
|
|
*aReturn = httpChannel;
|
|
|
|
NS_IF_ADDREF(*aReturn);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell: Global History
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::ShouldAddToGlobalHistory(nsIURI * aURI, PRBool * aShouldAdd)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
*aShouldAdd = PR_FALSE;
|
|
|
|
if (!mGlobalHistory || !aURI || (typeContent != mItemType))
|
|
|
|
return NS_OK;
|
2001-01-31 04:33:03 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// The model is really if we don't know differently then add which basically
|
|
|
|
// means we are suppose to try all the things we know not to allow in and
|
|
|
|
// then if we don't bail go on and allow it in. But here lets compare
|
|
|
|
// against the most common case we know to allow in and go on and say yes
|
|
|
|
// to it.
|
|
|
|
PRBool isHTTP = PR_FALSE;
|
|
|
|
PRBool isHTTPS = PR_FALSE;
|
|
|
|
NS_ENSURE_SUCCESS(aURI->SchemeIs("http", &isHTTP), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(aURI->SchemeIs("https", &isHTTPS), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (isHTTP || isHTTPS) {
|
|
|
|
*aShouldAdd = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-01 08:18:04 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRBool isAbout = PR_FALSE;
|
|
|
|
PRBool isImap = PR_FALSE;
|
|
|
|
PRBool isNews = PR_FALSE;
|
|
|
|
PRBool isMailbox = PR_FALSE;
|
|
|
|
PRBool isViewSource = PR_FALSE;
|
2001-01-31 04:33:03 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(aURI->SchemeIs("about", &isAbout), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(aURI->SchemeIs("imap", &isImap), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(aURI->SchemeIs("news", &isNews), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(aURI->SchemeIs("mailbox", &isMailbox), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(aURI->SchemeIs("view-source", &isViewSource),
|
|
|
|
NS_ERROR_FAILURE);
|
2001-01-31 04:33:03 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (isAbout || isImap || isNews || isMailbox || isViewSource)
|
|
|
|
return NS_OK;
|
2000-04-17 09:54:09 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
*aShouldAdd = PR_TRUE;
|
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::AddToGlobalHistory(nsIURI * aURI)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_STATE(mGlobalHistory);
|
2000-04-16 12:39:15 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsXPIDLCString spec;
|
|
|
|
NS_ENSURE_SUCCESS(aURI->GetSpec(getter_Copies(spec)), NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(mGlobalHistory->AddPage(spec), NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::UpdateCurrentGlobalHistory()
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// XXX Add code here that needs to update the current history item
|
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell: Helper Routines
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult
|
|
|
|
nsDocShell::SetLoadCookie(nsISupports * aCookie)
|
2000-06-20 11:59:45 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
// Remove the DocShell as a listener of the old WebProgress...
|
|
|
|
if (mLoadCookie) {
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
2000-06-20 11:59:45 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (webProgress) {
|
|
|
|
webProgress->RemoveProgressListener(this);
|
|
|
|
}
|
2000-06-20 11:59:45 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mLoadCookie = aCookie;
|
2000-06-20 11:59:45 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
// Add the DocShell as a listener to the new WebProgress...
|
|
|
|
if (mLoadCookie) {
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
2000-06-20 11:59:45 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (webProgress) {
|
|
|
|
webProgress->AddProgressListener(this);
|
|
|
|
}
|
2000-06-20 11:59:45 +04:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-06-20 11:59:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult
|
|
|
|
nsDocShell::GetLoadCookie(nsISupports ** aResult)
|
2000-06-20 11:59:45 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
*aResult = mLoadCookie;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
2000-06-20 11:59:45 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-06-20 11:59:45 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 23:04:11 +04:00
|
|
|
NS_IMETHODIMP
|
2001-04-27 17:38:15 +04:00
|
|
|
nsDocShell::SetLoadType(PRUint32 aLoadType)
|
2000-09-02 02:34:19 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
mLoadType = aLoadType;
|
|
|
|
return NS_OK;
|
2000-09-02 02:34:19 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 23:04:11 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetLoadType(PRUint32 * aLoadType)
|
|
|
|
{
|
|
|
|
*aLoadType = mLoadType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-20 11:59:45 +04:00
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
#define DIALOG_STRING_URI "chrome://global/locale/appstrings.properties"
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetPromptAndStringBundle(nsIPrompt ** aPrompt,
|
|
|
|
nsIStringBundle ** aStringBundle)
|
2000-04-13 07:11:44 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(GetInterface(NS_GET_IID(nsIPrompt), (void **) aPrompt),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-04-22 03:32:11 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService>
|
|
|
|
stringBundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(stringBundleService, NS_ERROR_FAILURE);
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(stringBundleService->
|
2001-04-28 01:30:24 +04:00
|
|
|
CreateBundle(DIALOG_STRING_URI,
|
2001-05-03 14:09:59 +04:00
|
|
|
aStringBundle),
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ERROR_FAILURE);
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-04-13 07:11:44 +04:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetChildOffset(nsIDOMNode * aChild, nsIDOMNode * aParent,
|
|
|
|
PRInt32 * aOffset)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aChild || aParent);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIDOMNodeList> childNodes;
|
|
|
|
NS_ENSURE_SUCCESS(aParent->GetChildNodes(getter_AddRefs(childNodes)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(childNodes, NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRInt32 i = 0;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
for (; PR_TRUE; i++) {
|
|
|
|
nsCOMPtr<nsIDOMNode> childNode;
|
|
|
|
NS_ENSURE_SUCCESS(childNodes->Item(i, getter_AddRefs(childNode)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(childNode, NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (childNode.get() == aChild) {
|
|
|
|
*aOffset = i;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetRootScrollableView(nsIScrollableView ** aOutScrollView)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aOutScrollView);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(shell)), NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(viewManager)),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(viewManager->GetRootScrollableView(aOutScrollView),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (*aOutScrollView == nsnull) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::EnsureContentListener()
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mContentListener)
|
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mContentListener = new nsDSURIContentListener();
|
|
|
|
NS_ENSURE_TRUE(mContentListener, NS_ERROR_OUT_OF_MEMORY);
|
2001-04-17 03:05:08 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ADDREF(mContentListener);
|
2001-04-17 03:05:08 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
rv = mContentListener->Init();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mContentListener->DocShell(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::EnsureScriptEnvironment()
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mScriptContext)
|
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
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 20:46:42 +04:00
|
|
|
if (mIsBeingDestroyed) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMScriptObjectFactory> factory =
|
|
|
|
do_GetService(kDOMScriptObjectFactoryCID);
|
|
|
|
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
factory->NewScriptGlobalObject(getter_AddRefs(mScriptGlobal));
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_TRUE(mScriptGlobal, NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
mScriptGlobal->SetDocShell(NS_STATIC_CAST(nsIDocShell *, this));
|
|
|
|
mScriptGlobal->
|
|
|
|
SetGlobalObjectOwner(NS_STATIC_CAST
|
|
|
|
(nsIScriptGlobalObjectOwner *, this));
|
2000-02-24 07:15:22 +03:00
|
|
|
|
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 20:46:42 +04:00
|
|
|
factory->NewScriptContext(mScriptGlobal, getter_AddRefs(mScriptContext));
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_ENSURE_TRUE(mScriptContext, NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
2000-02-17 05:03:02 +03:00
|
|
|
|
2001-04-28 01:11:03 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::EnsureFind()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (!mFind)
|
|
|
|
{
|
|
|
|
mFind = do_CreateInstance("@mozilla.org/embedcomp/find;1", &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we promise that the nsIWebBrowserFind that we return has been set
|
|
|
|
// up to point to the focussed, or content window, so we have to
|
|
|
|
// set that up each time.
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> scriptGO;
|
|
|
|
rv = GetScriptGlobalObject(getter_AddRefs(scriptGO));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// default to our window
|
|
|
|
nsCOMPtr<nsIDOMWindow> rootWindow = do_QueryInterface(scriptGO);
|
|
|
|
nsCOMPtr<nsIDOMWindow> windowToSearch = rootWindow;
|
|
|
|
|
|
|
|
// if we can, search the focussed window
|
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(scriptGO);
|
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
|
|
|
if (ourWindow)
|
|
|
|
ourWindow->GetRootFocusController(getter_AddRefs(focusController));
|
|
|
|
if (focusController)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> focussedWindow;
|
|
|
|
focusController->GetFocusedWindow(getter_AddRefs(focussedWindow));
|
|
|
|
if (focussedWindow)
|
|
|
|
windowToSearch = focussedWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebBrowserFindInFrames> findInFrames = do_QueryInterface(mFind);
|
|
|
|
if (!findInFrames) return NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
rv = findInFrames->SetRootSearchFrame(rootWindow);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = findInFrames->SetCurrentSearchFrame(windowToSearch);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
PRBool
|
|
|
|
nsDocShell::IsFrame()
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mParent) {
|
|
|
|
PRInt32 parentType = ~mItemType; // Not us
|
|
|
|
mParent->GetItemType(&parentType);
|
|
|
|
if (parentType == mItemType) // This is a frame
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
return PR_FALSE;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2001-05-23 03:52:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetHasFocus(PRBool *aHasFocus)
|
|
|
|
{
|
|
|
|
*aHasFocus = mHasFocus;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetHasFocus(PRBool aHasFocus)
|
|
|
|
{
|
2001-10-23 02:43:52 +04:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
printf(">>>>>>>>>> nsDocShell::SetHasFocus: %p %s\n", this, aHasFocus?"Yes":"No");
|
|
|
|
#endif
|
2001-05-23 03:52:17 +04:00
|
|
|
|
|
|
|
mHasFocus = aHasFocus;
|
|
|
|
|
|
|
|
nsDocShellFocusController* dsfc = nsDocShellFocusController::GetInstance();
|
|
|
|
if (dsfc && aHasFocus) {
|
|
|
|
dsfc->Focus(this);
|
|
|
|
}
|
|
|
|
|
2001-10-23 02:43:52 +04:00
|
|
|
if (!aHasFocus) {
|
|
|
|
// We may be in a situation where the focus outline was shown
|
|
|
|
// on this document because the user tabbed into it, but the focus
|
|
|
|
// is now switching to another document via a click. In this case,
|
|
|
|
// we need to make sure the focus outline is removed from this document.
|
|
|
|
SetCanvasHasFocus(PR_FALSE);
|
|
|
|
}
|
2001-05-23 03:52:17 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
// Tells the HTMLFrame/CanvasFrame that is now has focus
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetCanvasHasFocus(PRBool aCanvasHasFocus)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
GetPresShell(getter_AddRefs(presShell));
|
|
|
|
if (!presShell) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
presShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (!doc) return NS_ERROR_FAILURE;
|
|
|
|
|
2001-06-20 07:27:48 +04:00
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
doc->GetRootContent(getter_AddRefs(rootContent));
|
2001-05-23 03:52:17 +04:00
|
|
|
if (!rootContent) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIFrame* frame;
|
|
|
|
presShell->GetPrimaryFrameFor(rootContent, &frame);
|
|
|
|
if (frame != nsnull) {
|
|
|
|
frame->GetParent(&frame);
|
|
|
|
if (frame != nsnull) {
|
|
|
|
nsICanvasFrame* canvasFrame;
|
|
|
|
if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsICanvasFrame), (void**)&canvasFrame))) {
|
|
|
|
canvasFrame->SetHasFocus(aCanvasHasFocus);
|
2001-10-23 02:43:52 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
nsIView* canvasView = nsnull;
|
|
|
|
frame->GetView(presContext, &canvasView);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
canvasView->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
viewManager->UpdateView(canvasView, NS_VMREFRESH_NO_SYNC);
|
|
|
|
|
2001-05-23 03:52:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetCanvasHasFocus(PRBool *aCanvasHasFocus)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-12-07 03:02:03 +03:00
|
|
|
/* boolean IsBeingDestroyed (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::IsBeingDestroyed(PRBool *aDoomed)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aDoomed);
|
|
|
|
*aDoomed = mIsBeingDestroyed;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsRefreshTimer: Object Management
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
nsRefreshTimer::nsRefreshTimer():mRepeat(PR_FALSE), mDelay(0),
|
|
|
|
mMetaRefresh(PR_FALSE)
|
2000-04-13 07:11:44 +04:00
|
|
|
{
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_INIT_REFCNT();
|
2000-04-13 07:11:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefreshTimer::~nsRefreshTimer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsRefreshTimer::nsISupports
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsRefreshTimer)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsRefreshTimer)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsRefreshTimer)
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITimerCallback)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
2000-04-13 07:11:44 +04:00
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
|
|
|
///*****************************************************************************
|
|
|
|
// nsRefreshTimer::nsITimerCallback
|
|
|
|
//*****************************************************************************
|
2001-04-27 17:38:15 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsRefreshTimer::Notify(nsITimer * aTimer)
|
2000-04-13 07:11:44 +04:00
|
|
|
{
|
2000-06-03 01:02:31 +04:00
|
|
|
NS_ASSERTION(mDocShell, "DocShell is somehow null");
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
if (mDocShell && aTimer) {
|
2001-05-19 01:43:29 +04:00
|
|
|
/* Check if Meta refresh/redirects are permitted. Some
|
|
|
|
* embedded applications may not want to do this.
|
|
|
|
*/
|
|
|
|
PRBool allowRedirects = PR_TRUE;
|
|
|
|
mDocShell->GetAllowMetaRedirects(&allowRedirects);
|
|
|
|
if (!allowRedirects)
|
|
|
|
return;
|
2001-04-27 17:38:15 +04:00
|
|
|
// Get the delay count
|
|
|
|
PRUint32 delay;
|
|
|
|
delay = aTimer->GetDelay();
|
|
|
|
// Get the current uri from the docshell.
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
|
|
|
nsCOMPtr<nsIURI> currURI;
|
|
|
|
if (webNav) {
|
|
|
|
webNav->GetCurrentURI(getter_AddRefs(currURI));
|
2001-03-24 04:23:42 +03:00
|
|
|
}
|
2001-04-27 17:38:15 +04:00
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
|
|
|
mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
/* Check if this META refresh causes a redirection
|
2001-05-19 01:43:29 +04:00
|
|
|
* to another site.
|
2001-03-24 04:23:42 +03:00
|
|
|
*/
|
2001-04-27 17:38:15 +04:00
|
|
|
PRBool equalUri = PR_FALSE;
|
|
|
|
nsresult rv = mURI->Equals(currURI, &equalUri);
|
|
|
|
if (NS_SUCCEEDED(rv) && (!equalUri) && mMetaRefresh) {
|
2001-05-19 01:43:29 +04:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
/* It is a META refresh based redirection. Now check if it happened within
|
|
|
|
* the threshold time we have in mind(15000 ms as defined by REFRESH_REDIRECT_TIMER).
|
|
|
|
* If so, pass a REPLACE flag to LoadURI().
|
|
|
|
*/
|
|
|
|
if (delay <= REFRESH_REDIRECT_TIMER) {
|
|
|
|
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadRefresh);
|
|
|
|
/*
|
|
|
|
* LoadURL(...) will cancel all refresh timers... This causes the Timer and
|
|
|
|
* its refreshData instance to be released...
|
|
|
|
*/
|
|
|
|
mDocShell->LoadURI(mURI, loadInfo,
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE);
|
|
|
|
return;
|
2001-03-24 04:23:42 +03:00
|
|
|
|
2001-04-27 17:38:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadRefresh);
|
|
|
|
mDocShell->LoadURI(mURI, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE);
|
2000-06-03 01:02:31 +04:00
|
|
|
}
|
2000-04-13 17:35:54 +04:00
|
|
|
}
|
2001-05-23 03:52:17 +04:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsDocShellFocusController: Object Management
|
|
|
|
//*****************************************************************************
|
|
|
|
void
|
|
|
|
nsDocShellFocusController::Focus(nsIDocShell* aDocShell)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
printf("****** nsDocShellFocusController Focus To: %p Blur To: %p\n", aDocShell, mFocusedDocShell);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aDocShell != mFocusedDocShell) {
|
|
|
|
if (mFocusedDocShell) {
|
|
|
|
mFocusedDocShell->SetHasFocus(PR_FALSE);
|
|
|
|
}
|
|
|
|
mFocusedDocShell = aDocShell;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
|
// This is need for when the document with focus goes away
|
|
|
|
void
|
|
|
|
nsDocShellFocusController::ClosingDown(nsIDocShell* aDocShell)
|
|
|
|
{
|
|
|
|
if (aDocShell == mFocusedDocShell) {
|
|
|
|
mFocusedDocShell = nsnull;
|
|
|
|
}
|
|
|
|
}
|