2000-05-23 04:52:59 +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>
|
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"
|
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"
|
1999-12-21 03:11:33 +03:00
|
|
|
#include "nsIChromeEventHandler.h"
|
2000-01-23 09:00:11 +03:00
|
|
|
#include "nsIDOMWindow.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"
|
2000-05-19 01:52:23 +04:00
|
|
|
#include "nsTextFormatter.h"
|
2000-08-25 05:46:00 +04:00
|
|
|
#include "nsIHTTPEventSink.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-04-12 03:52:42 +04:00
|
|
|
// Helper Classes
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsHTTPEnums.h"
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
// Interfaces Needed
|
2000-04-12 03:52:42 +04:00
|
|
|
#include "nsICharsetConverterManager.h"
|
2000-03-30 06:24:17 +04:00
|
|
|
#include "nsIHTTPChannel.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 "nsILocaleService.h"
|
2000-04-12 03:52:42 +04:00
|
|
|
#include "nsIPlatformCharset.h"
|
2000-04-13 07:11:44 +04:00
|
|
|
#include "nsITimer.h"
|
2000-05-23 04:52:59 +04:00
|
|
|
#include "nsIFileStream.h"
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2000-06-14 03:56:30 +04:00
|
|
|
#include "nsIPrincipal.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-03-08 06:58:33 +03:00
|
|
|
static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
|
2000-04-13 06:54:38 +04:00
|
|
|
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
|
|
|
|
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
2000-07-01 03:39:30 +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);
|
2000-03-08 06:58:33 +03:00
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsDocShell: Object Management
|
|
|
|
//*****************************************************************************
|
|
|
|
|
1999-11-19 10:35:27 +03:00
|
|
|
nsDocShell::nsDocShell() :
|
|
|
|
mContentListener(nsnull),
|
1999-12-28 22:41:57 +03:00
|
|
|
mInitInfo(nsnull),
|
1999-11-19 10:35:27 +03:00
|
|
|
mMarginWidth(0),
|
1999-12-12 13:15:26 +03:00
|
|
|
mMarginHeight(0),
|
1999-12-28 22:41:57 +03:00
|
|
|
mItemType(typeContent),
|
2000-03-11 03:53:48 +03:00
|
|
|
mCurrentScrollbarPref(-1,-1),
|
|
|
|
mDefaultScrollbarPref(-1,-1),
|
2000-02-24 07:15:22 +03:00
|
|
|
mInitialPageLoad(PR_TRUE),
|
2000-03-11 03:53:48 +03:00
|
|
|
mAllowPlugins(PR_TRUE),
|
2000-03-14 07:36:55 +03:00
|
|
|
mViewMode(viewNormal),
|
2000-08-25 22:39:46 +04:00
|
|
|
mLastViewMode(viewNormal),
|
|
|
|
mRestoreViewMode(PR_FALSE),
|
2000-03-11 03:53:48 +03:00
|
|
|
mEODForCurrentDocument (PR_FALSE),
|
2000-06-23 08:44:36 +04:00
|
|
|
mUseExternalProtocolHandler (PR_FALSE),
|
1999-12-12 13:15:26 +03:00
|
|
|
mParent(nsnull),
|
1999-12-21 03:11:33 +03:00
|
|
|
mTreeOwner(nsnull),
|
2000-03-11 03:53:48 +03:00
|
|
|
mChromeEventHandler(nsnull)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-12-07 01:32:32 +03:00
|
|
|
NS_INIT_REFCNT();
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDocShell::~nsDocShell()
|
|
|
|
{
|
2000-02-14 09:40:28 +03:00
|
|
|
Destroy();
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::DestroyChildren()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
nsCOMPtr<nsIBaseWindow> shellWin(do_QueryInterface(shell));
|
|
|
|
if(shellWin)
|
|
|
|
shellWin->Destroy();
|
|
|
|
}
|
|
|
|
mChildren.Clear();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShell)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShell)
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem)
|
1999-12-03 12:24:22 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode)
|
2000-07-06 03:10:29 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocShellHistory)
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebNavigation)
|
1999-11-23 13:15:10 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollable)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITextScroll)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
1999-12-03 12:24:22 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
|
2000-04-13 07:11:44 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRefreshURI)
|
2000-06-20 11:59:45 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
|
2000-05-28 13:25:55 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-06-22 09:36:13 +04:00
|
|
|
|
2000-02-08 16:40:10 +03:00
|
|
|
///*****************************************************************************
|
|
|
|
// nsDocShell::nsIInterfaceRequestor
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& aIID, void** aSink)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aSink);
|
|
|
|
|
|
|
|
if(aIID.Equals(NS_GET_IID(nsIURIContentListener)) &&
|
|
|
|
NS_SUCCEEDED(EnsureContentListener()))
|
2000-08-25 22:39:46 +04:00
|
|
|
{
|
|
|
|
*aSink = mContentListener;
|
|
|
|
}
|
2000-02-08 16:40:10 +03:00
|
|
|
else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)) &&
|
|
|
|
NS_SUCCEEDED(EnsureScriptEnvironment()))
|
2000-08-25 22:39:46 +04:00
|
|
|
{
|
2000-02-08 16:40:10 +03:00
|
|
|
*aSink = mScriptGlobal;
|
2000-08-25 22:39:46 +04:00
|
|
|
}
|
2000-02-08 16:40:10 +03:00
|
|
|
else if(aIID.Equals(NS_GET_IID(nsIDOMWindow)) &&
|
|
|
|
NS_SUCCEEDED(EnsureScriptEnvironment()))
|
2000-08-25 22:39:46 +04:00
|
|
|
{
|
2000-02-08 16:40:10 +03:00
|
|
|
NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindow),
|
|
|
|
aSink), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
2000-08-25 22:39:46 +04:00
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIDOMDocument)) &&
|
|
|
|
NS_SUCCEEDED(EnsureContentViewer()))
|
|
|
|
{
|
|
|
|
mContentViewer->GetDOMDocument((nsIDOMDocument**) aSink);
|
|
|
|
}
|
2000-03-08 03:38:58 +03:00
|
|
|
else if(aIID.Equals(NS_GET_IID(nsIPrompt)))
|
2000-08-25 22:39:46 +04:00
|
|
|
{
|
2000-03-08 03:38:58 +03:00
|
|
|
nsCOMPtr<nsIPrompt> prompter(do_GetInterface(mTreeOwner));
|
|
|
|
if (prompter)
|
|
|
|
{
|
|
|
|
*aSink = prompter;
|
|
|
|
NS_ADDREF((nsISupports*)*aSink);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
2000-08-25 05:46:00 +04:00
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIProgressEventSink)) || aIID.Equals(NS_GET_IID(nsIHTTPEventSink)) ||
|
2000-06-19 09:54:37 +04:00
|
|
|
aIID.Equals(NS_GET_IID(nsIWebProgress)))
|
2000-04-23 03:18:18 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURILoader> uriLoader(do_GetService(NS_URI_LOADER_PROGID));
|
|
|
|
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);
|
2000-06-19 09:54:37 +04:00
|
|
|
if (docLoader) {
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(docLoader));
|
|
|
|
return requestor->GetInterface(aIID, aSink);
|
|
|
|
}
|
2000-04-23 03:18:18 +04:00
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-02-08 16:40:10 +03:00
|
|
|
else
|
2000-08-25 22:39:46 +04:00
|
|
|
{
|
2000-02-08 16:40:10 +03:00
|
|
|
return QueryInterface(aIID, aSink);
|
2000-08-25 22:39:46 +04:00
|
|
|
}
|
2000-02-08 16:40:10 +03:00
|
|
|
|
|
|
|
NS_IF_ADDREF(((nsISupports*)*aSink));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIDocShell
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-07-08 09:17:49 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> referrer;
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
2000-08-31 09:53:32 +04:00
|
|
|
PRBool inheritOwner = PR_FALSE;
|
2000-07-08 09:17:49 +04:00
|
|
|
nsCOMPtr<nsISHEntry> shEntry;
|
|
|
|
nsDocShellInfoLoadType loadType = nsIDocShellLoadInfo::loadNormal;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
|
|
|
// Extract the info from the DocShellLoadInfo struct...
|
|
|
|
if(aLoadInfo) {
|
|
|
|
aLoadInfo->GetReferrer(getter_AddRefs(referrer));
|
|
|
|
aLoadInfo->GetLoadType(&loadType);
|
|
|
|
aLoadInfo->GetOwner(getter_AddRefs(owner));
|
2000-08-31 09:53:32 +04:00
|
|
|
aLoadInfo->GetInheritOwner(&inheritOwner);
|
2000-07-08 09:17:49 +04:00
|
|
|
aLoadInfo->GetSHEntry(getter_AddRefs(shEntry));
|
|
|
|
}
|
2000-06-22 11:22:23 +04:00
|
|
|
|
2000-08-03 01:49:26 +04:00
|
|
|
if (!shEntry && loadType != nsIDocShellLoadInfo::loadNormalReplace) {
|
2000-07-08 09:17:49 +04:00
|
|
|
/* Check if we are in the middle of loading a subframe whose parent
|
|
|
|
* was originally loaded thro' Session History. ie., you were in a frameset
|
|
|
|
* page, went somewhere else and clicked 'back'. The loading of the root page
|
|
|
|
* is done and we are currently loading one of its children or sub-children.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
|
|
|
GetSameTypeParent(getter_AddRefs(parentAsItem));
|
|
|
|
|
|
|
|
// Try to get your SHEntry from your parent
|
|
|
|
if (parentAsItem) {
|
|
|
|
nsCOMPtr<nsIDocShellHistory> parent(do_QueryInterface(parentAsItem));
|
|
|
|
|
|
|
|
// XXX: Should we care if this QI fails?
|
|
|
|
if (parent) {
|
|
|
|
parent->GetChildSHEntry(mChildOffset, getter_AddRefs(shEntry));
|
|
|
|
if (shEntry) {
|
|
|
|
loadType = nsIDocShellLoadInfo::loadHistory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-01 02:05:32 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
if (shEntry) {
|
|
|
|
rv = LoadHistoryEntry(shEntry, loadType);
|
|
|
|
} else {
|
2000-08-31 09:53:32 +04:00
|
|
|
rv = InternalLoad(aURI, referrer, owner, inheritOwner, nsnull, nsnull, loadType, nsnull);
|
2000-07-08 09:17:49 +04:00
|
|
|
}
|
2000-06-22 11:22:23 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
return rv;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
2000-01-17 22:56:31 +03:00
|
|
|
|
2000-07-01 03:39:30 +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;
|
|
|
|
rv = uri->SetSpec("stream");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDocShellInfoLoadType loadType = nsIDocShellLoadInfo::loadNormal;
|
|
|
|
|
|
|
|
if(aLoadInfo)
|
|
|
|
(void)aLoadInfo->GetLoadType(&loadType);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(StopLoad(), NS_ERROR_FAILURE);
|
|
|
|
// Cancel any timers that were set for this loader.
|
|
|
|
(void)CancelRefreshURITimers();
|
|
|
|
|
|
|
|
mLoadType = loadType;
|
|
|
|
|
|
|
|
// build up a channel for this stream.
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
NS_ENSURE_SUCCESS(NS_NewInputStreamChannel(getter_AddRefs(channel), aURI, aStream,
|
|
|
|
aContentType, aContentLen), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURILoader> uriLoader(do_GetService(NS_URI_LOADER_PROGID));
|
|
|
|
NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(DoChannelLoad(channel, nsIURILoader::viewNormal, nsnull, uriLoader), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-30 16:52:02 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::CreateLoadInfo(nsIDocShellLoadInfo** aLoadInfo)
|
|
|
|
{
|
|
|
|
nsDocShellLoadInfo* loadInfo = new nsDocShellLoadInfo();
|
|
|
|
NS_ENSURE_TRUE(loadInfo, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> localRef(loadInfo);
|
|
|
|
|
|
|
|
*aLoadInfo = localRef;
|
|
|
|
NS_ADDREF(*aLoadInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::StopLoad()
|
|
|
|
{
|
2000-07-22 03:44:38 +04:00
|
|
|
// Cancel any timers that were set for this loader.
|
|
|
|
CancelRefreshURITimers();
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
if(mLoadCookie)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURILoader> uriLoader = do_GetService(NS_URI_LOADER_PROGID);
|
|
|
|
if(uriLoader)
|
|
|
|
uriLoader->Stop(mLoadCookie);
|
|
|
|
}
|
2000-01-17 22:56:31 +03:00
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
PRInt32 n;
|
|
|
|
PRInt32 count = mChildren.Count();
|
|
|
|
for(n = 0; n < count; n++)
|
|
|
|
{
|
|
|
|
nsIDocShellTreeItem* shellItem = (nsIDocShellTreeItem*)mChildren.ElementAt(n);
|
|
|
|
nsCOMPtr<nsIDocShell> shell(do_QueryInterface(shellItem));
|
|
|
|
if(shell)
|
|
|
|
shell->StopLoad();
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetDocLoaderObserver(nsIDocumentLoaderObserver * *aDocLoaderObserver)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDocLoaderObserver);
|
|
|
|
|
|
|
|
*aDocLoaderObserver = mDocLoaderObserver;
|
|
|
|
NS_IF_ADDREF(*aDocLoaderObserver);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::SetDocLoaderObserver(nsIDocumentLoaderObserver * aDocLoaderObserver)
|
|
|
|
{
|
|
|
|
// it's legal for aDocLoaderObserver to be null.
|
|
|
|
mDocLoaderObserver = aDocLoaderObserver;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetPresContext(nsIPresContext** aPresContext)
|
|
|
|
{
|
2000-07-06 03:10:29 +04:00
|
|
|
nsresult rv = NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
|
|
|
*aPresContext = nsnull;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
if (mContentViewer) {
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
if (docv) {
|
|
|
|
rv = docv->GetPresContext(*aPresContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fail silently, if no PresContext is available...
|
|
|
|
return rv;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
1999-11-29 21:41:59 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetPresShell(nsIPresShell** aPresShell)
|
|
|
|
{
|
2000-07-06 03:10:29 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresShell);
|
|
|
|
*aPresShell = nsnull;
|
1999-11-29 21:41:59 +03:00
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
(void) GetPresContext(getter_AddRefs(presContext));
|
1999-11-29 21:41:59 +03:00
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
if(presContext) {
|
|
|
|
rv = presContext->GetShell(aPresShell);
|
|
|
|
}
|
1999-11-29 21:41:59 +03:00
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
return rv;
|
1999-11-29 21:41:59 +03:00
|
|
|
}
|
|
|
|
|
1999-11-16 01:54:47 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetContentViewer(nsIContentViewer** aContentViewer)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aContentViewer);
|
|
|
|
|
|
|
|
*aContentViewer = mContentViewer;
|
|
|
|
NS_IF_ADDREF(*aContentViewer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-18 05:23:31 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::SetChromeEventHandler(nsIChromeEventHandler* aChromeEventHandler)
|
|
|
|
{
|
1999-12-21 03:11:33 +03:00
|
|
|
// Weak reference. Don't addref.
|
|
|
|
mChromeEventHandler = aChromeEventHandler;
|
1999-12-18 05:23:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetChromeEventHandler(nsIChromeEventHandler** aChromeEventHandler)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChromeEventHandler);
|
|
|
|
|
1999-12-21 03:11:33 +03:00
|
|
|
*aChromeEventHandler = mChromeEventHandler;
|
|
|
|
NS_IF_ADDREF(*aChromeEventHandler);
|
1999-12-18 05:23:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetParentURIContentListener(nsIURIContentListener**
|
|
|
|
aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
|
2000-01-29 09:10:54 +03:00
|
|
|
return mContentListener->GetParentContentListener(aParent);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetParentURIContentListener(nsIURIContentListener*
|
|
|
|
aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
|
|
|
|
2000-01-29 09:10:54 +03:00
|
|
|
return mContentListener->SetParentContentListener(aParent);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-04-12 04:07:04 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::GetDocumentCharsetInfo(nsIDocumentCharsetInfo**
|
|
|
|
aDocumentCharsetInfo)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDocumentCharsetInfo);
|
|
|
|
|
2000-08-05 04:07:03 +04:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2000-04-12 04:07:04 +04:00
|
|
|
*aDocumentCharsetInfo = mDocumentCharsetInfo;
|
|
|
|
NS_IF_ADDREF(*aDocumentCharsetInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetDocumentCharsetInfo(nsIDocumentCharsetInfo*
|
|
|
|
aDocumentCharsetInfo)
|
|
|
|
{
|
|
|
|
mDocumentCharsetInfo = aDocumentCharsetInfo;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetAllowPlugins(PRBool* aAllowPlugins)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAllowPlugins);
|
|
|
|
|
|
|
|
*aAllowPlugins = mAllowPlugins;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetAllowPlugins(PRBool aAllowPlugins)
|
|
|
|
{
|
|
|
|
mAllowPlugins = aAllowPlugins;
|
|
|
|
//XXX should enable or disable a plugin host
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-14 07:36:55 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetViewMode(PRInt32* aViewMode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aViewMode);
|
|
|
|
|
|
|
|
*aViewMode = mViewMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetViewMode(PRInt32 aViewMode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG((viewNormal == aViewMode) || (viewSource == aViewMode));
|
|
|
|
|
2000-03-14 09:30:30 +03:00
|
|
|
PRBool reload = PR_FALSE;
|
|
|
|
|
|
|
|
if((mViewMode != aViewMode) && mCurrentURI)
|
|
|
|
reload = PR_TRUE;
|
|
|
|
|
|
|
|
mViewMode = aViewMode;
|
|
|
|
|
|
|
|
if(reload)
|
2000-06-30 01:48:18 +04:00
|
|
|
Reload(nsIDocShellLoadInfo::loadReloadNormal);
|
2000-03-14 07:36:55 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetZoom(float* zoom)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(zoom);
|
2000-03-08 06:58:33 +03:00
|
|
|
NS_ENSURE_SUCCESS(EnsureDeviceContext(), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-08 06:58:33 +03:00
|
|
|
NS_ENSURE_SUCCESS(mDeviceContext->GetZoom(*zoom), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetZoom(float zoom)
|
|
|
|
{
|
2000-03-08 06:58:33 +03:00
|
|
|
NS_ENSURE_SUCCESS(EnsureDeviceContext(), NS_ERROR_FAILURE);
|
|
|
|
mDeviceContext->SetZoom(zoom);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-08 06:58:33 +03: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);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-08 06:58:33 +03: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);
|
|
|
|
|
|
|
|
// get the root scrollable view
|
|
|
|
nsIScrollableView* scrollableView = nsnull;
|
|
|
|
vm->GetRootScrollableView(&scrollableView);
|
|
|
|
if(scrollableView)
|
|
|
|
scrollableView->ComputeScrollOffsets();
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-08 06:58:33 +03:00
|
|
|
// 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
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetMarginWidth(PRInt32* aWidth)
|
1999-11-19 10:35:27 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
|
|
|
|
|
|
|
*aWidth = mMarginWidth;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::SetMarginWidth(PRInt32 aWidth)
|
1999-11-19 10:35:27 +03:00
|
|
|
{
|
|
|
|
mMarginWidth = aWidth;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetMarginHeight(PRInt32* aHeight)
|
1999-11-19 10:35:27 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
|
|
|
|
|
|
|
*aHeight = mMarginHeight;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::SetMarginHeight(PRInt32 aHeight)
|
1999-11-19 10:35:27 +03:00
|
|
|
{
|
|
|
|
mMarginHeight = aHeight;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIDocShellTreeItem
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetName(PRUnichar** aName)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aName);
|
1999-12-03 14:22:54 +03:00
|
|
|
*aName = mName.ToNewUnicode();
|
1999-12-03 13:29:08 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetName(const PRUnichar* aName)
|
|
|
|
{
|
1999-12-03 14:22:54 +03:00
|
|
|
mName = aName; // this does a copy of aName
|
|
|
|
return NS_OK;
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
1999-12-08 07:57:23 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetItemType(PRInt32* aItemType)
|
1999-12-03 13:29:08 +03:00
|
|
|
{
|
1999-12-08 07:57:23 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aItemType);
|
1999-12-03 13:29:08 +03:00
|
|
|
|
1999-12-08 07:57:23 +03:00
|
|
|
*aItemType = mItemType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetItemType(PRInt32 aItemType)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG((aItemType == typeChrome) || (typeContent == aItemType));
|
2000-02-11 04:09:12 +03:00
|
|
|
NS_ENSURE_STATE(!mParent);
|
|
|
|
|
1999-12-08 07:57:23 +03:00
|
|
|
mItemType = aItemType;
|
2000-02-11 04:09:12 +03:00
|
|
|
|
1999-12-08 07:57:23 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetParent(nsIDocShellTreeItem** aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
|
|
|
*aParent = mParent;
|
|
|
|
NS_IF_ADDREF(*aParent);
|
1999-12-03 13:29:08 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetParent(nsIDocShellTreeItem* aParent)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
|
|
nsCOMPtr<nsIURIContentListener> parentURIListener(do_GetInterface(aParent));
|
|
|
|
if(parentURIListener)
|
|
|
|
SetParentURIContentListener(parentURIListener);
|
|
|
|
return NS_OK;
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
1999-12-08 07:57:23 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetSameTypeParent(nsIDocShellTreeItem** aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
*aParent = nsnull;
|
|
|
|
|
|
|
|
if(!mParent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRInt32 parentType;
|
|
|
|
NS_ENSURE_SUCCESS(mParent->GetItemType(&parentType), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if(parentType == mItemType)
|
|
|
|
{
|
|
|
|
*aParent = mParent;
|
|
|
|
NS_ADDREF(*aParent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetRootTreeItem(nsIDocShellTreeItem** aRootTreeItem)
|
|
|
|
{
|
1999-12-08 07:57:23 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aRootTreeItem);
|
|
|
|
*aRootTreeItem = NS_STATIC_CAST(nsIDocShellTreeItem*, this);
|
1999-12-03 13:29:08 +03:00
|
|
|
|
1999-12-08 07:57:23 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
NS_ENSURE_SUCCESS(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE);
|
|
|
|
while(parent)
|
|
|
|
{
|
|
|
|
*aRootTreeItem = parent;
|
1999-12-18 05:23:31 +03:00
|
|
|
NS_ENSURE_SUCCESS((*aRootTreeItem)->GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE);
|
1999-12-08 07:57:23 +03:00
|
|
|
}
|
1999-12-18 05:23:31 +03:00
|
|
|
NS_ADDREF(*aRootTreeItem);
|
1999-12-08 07:57:23 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
1999-12-18 05:23:31 +03:00
|
|
|
NS_ENSURE_SUCCESS((*aRootTreeItem)->GetSameTypeParent(getter_AddRefs(parent)),
|
1999-12-08 07:57:23 +03:00
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
1999-12-18 05:23:31 +03:00
|
|
|
NS_ADDREF(*aRootTreeItem);
|
1999-12-08 07:57:23 +03:00
|
|
|
return NS_OK;
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
1999-12-12 13:15:26 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::FindItemWithName(const PRUnichar *aName,
|
1999-12-18 05:23:31 +03:00
|
|
|
nsISupports* aRequestor, nsIDocShellTreeItem **_retval)
|
1999-12-12 13:15:26 +03:00
|
|
|
{
|
|
|
|
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
|
1999-12-18 05:23:31 +03: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-12-12 13:15:26 +03:00
|
|
|
|
1999-12-18 05:23:31 +03:00
|
|
|
// First we check our name.
|
2000-04-28 00:59:12 +04:00
|
|
|
if(mName.EqualsWithConversion(aName))
|
1999-12-18 05:23:31 +03:00
|
|
|
{
|
|
|
|
*_retval = NS_STATIC_CAST(nsIDocShellTreeItem*, this);
|
|
|
|
NS_ADDREF(*_retval);
|
2000-02-17 05:03:02 +03:00
|
|
|
return NS_OK;
|
1999-12-18 05:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Second we check our children making sure not to ask a child if it
|
1999-12-12 13:15:26 +03:00
|
|
|
// is the aRequestor.
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_ENSURE_SUCCESS(FindChildWithName(aName, PR_TRUE, PR_TRUE, reqAsTreeItem,
|
|
|
|
_retval),
|
1999-12-12 13:15:26 +03:00
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if(*_retval)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-12-18 05:23:31 +03:00
|
|
|
// Third if we have a parent and it isn't the requestor then we should ask
|
1999-12-12 13:15:26 +03:00
|
|
|
// 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)
|
|
|
|
{
|
1999-12-18 05:23:31 +03:00
|
|
|
if(mParent == reqAsTreeItem.get())
|
1999-12-12 13:15:26 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
1999-12-18 05:23:31 +03:00
|
|
|
// This QI may fail, but comparing against null serves the same purpose
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> reqAsTreeOwner(do_QueryInterface(aRequestor));
|
|
|
|
|
|
|
|
if(mTreeOwner && (mTreeOwner != reqAsTreeOwner.get()))
|
1999-12-12 13:15:26 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mTreeOwner->FindItemWithName(aName,
|
|
|
|
NS_STATIC_CAST(nsIDocShellTreeItem*, this), _retval),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-03 13:35:43 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTreeOwner);
|
|
|
|
|
1999-12-12 13:15:26 +03:00
|
|
|
*aTreeOwner = mTreeOwner;
|
|
|
|
NS_IF_ADDREF(*aTreeOwner);
|
1999-12-03 13:35:43 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner)
|
|
|
|
{
|
2000-03-30 06:24:17 +04:00
|
|
|
// Don't automatically set the progress based on the tree owner for frames
|
2000-06-19 09:54:37 +04:00
|
|
|
if (!IsFrame()) {
|
2000-06-20 11:59:45 +04:00
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
if (webProgress) {
|
|
|
|
nsCOMPtr<nsIWebProgressListener> oldListener(do_QueryInterface(mTreeOwner));
|
|
|
|
nsCOMPtr<nsIWebProgressListener> newListener(do_QueryInterface(aTreeOwner));
|
|
|
|
|
|
|
|
if (oldListener) {
|
|
|
|
webProgress->RemoveProgressListener(oldListener);
|
2000-03-30 06:24:17 +04:00
|
|
|
}
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
if (newListener) {
|
|
|
|
webProgress->AddProgressListener(newListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mTreeOwner = aTreeOwner; // Weak reference per API
|
1999-12-12 13:15:26 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
1999-12-03 13:35:43 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-24 03:54:30 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::SetChildOffset(PRInt32 aChildOffset)
|
|
|
|
{
|
|
|
|
mChildOffset = aChildOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetChildOffset(PRInt32 *aChildOffset)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChildOffset);
|
|
|
|
*aChildOffset = mChildOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
1999-12-03 12:24:22 +03:00
|
|
|
// nsDocShell::nsIDocShellTreeNode
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetChildCount(PRInt32 *aChildCount)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChildCount);
|
|
|
|
*aChildCount = mChildren.Count();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-24 03:54:30 +04:00
|
|
|
|
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::AddChild(nsIDocShellTreeItem *aChild)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aChild);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE);
|
|
|
|
mChildren.AppendElement(aChild);
|
|
|
|
NS_ADDREF(aChild);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-06-24 03:54:30 +04:00
|
|
|
// 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.
|
2000-06-30 01:48:18 +04:00
|
|
|
PRInt32 childCount = mChildren.Count();
|
|
|
|
aChild->SetChildOffset(childCount-1);
|
2000-06-24 03:54:30 +04:00
|
|
|
|
2000-07-19 01:55:37 +04:00
|
|
|
/* Set the child's global history if the parent has one */
|
|
|
|
if (mGlobalHistory) {
|
|
|
|
nsCOMPtr<nsIDocShellHistory> dsHistoryChild(do_QueryInterface(aChild));
|
|
|
|
if (dsHistoryChild)
|
|
|
|
dsHistoryChild->SetGlobalHistory(mGlobalHistory);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-14 11:19:19 +03:00
|
|
|
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.
|
|
|
|
|
2000-06-24 03:54:30 +04:00
|
|
|
|
2000-01-14 11:19:19 +03:00
|
|
|
aChild->SetTreeOwner(mTreeOwner);
|
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
nsCOMPtr<nsIDocShell> childAsDocShell(do_QueryInterface(aChild));
|
|
|
|
if(!childAsDocShell)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Do some docShell Specific stuff.
|
1999-12-08 08:01:06 +03:00
|
|
|
nsXPIDLString defaultCharset;
|
|
|
|
nsXPIDLString forceCharset;
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(mContentViewer);
|
|
|
|
if(muDV)
|
|
|
|
{
|
1999-12-08 08:01:06 +03:00
|
|
|
NS_ENSURE_SUCCESS(muDV->GetDefaultCharacterSet(getter_Copies(defaultCharset)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(muDV->GetForceCharacterSet(getter_Copies(forceCharset)),
|
|
|
|
NS_ERROR_FAILURE);
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContentViewer> childCV;
|
|
|
|
NS_ENSURE_SUCCESS(childAsDocShell->GetContentViewer(getter_AddRefs(childCV)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
if(childCV)
|
1999-11-13 11:09:16 +03:00
|
|
|
{
|
1999-12-03 13:29:08 +03:00
|
|
|
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);
|
|
|
|
}
|
1999-11-13 11:09:16 +03:00
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-08-05 04:07:03 +04:00
|
|
|
// 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
|
|
|
|
res = dcInfo->SetParentCharset(&parentCS);
|
|
|
|
if (NS_FAILED(res)) return NS_OK;
|
|
|
|
|
|
|
|
// printf("### 1 >>> Adding child. Parent CS = %s. ItemType = %d.\n", parentCS.ToNewCString(), mItemType);
|
|
|
|
|
1999-11-19 10:35:27 +03:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::RemoveChild(nsIDocShellTreeItem *aChild)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-12-01 06:37:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aChild);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
1999-12-01 06:37:21 +03:00
|
|
|
if(mChildren.RemoveElement(aChild))
|
|
|
|
{
|
2000-01-14 11:19:19 +03:00
|
|
|
aChild->SetParent(nsnull);
|
|
|
|
aChild->SetTreeOwner(nsnull);
|
1999-12-01 06:37:21 +03:00
|
|
|
NS_RELEASE(aChild);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShellTreeItem** aChild)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aChild);
|
1999-12-01 06:08:58 +03:00
|
|
|
NS_ENSURE_ARG_RANGE(aIndex, 0, mChildren.Count() - 1);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
*aChild = (nsIDocShellTreeItem*) mChildren.ElementAt(aIndex);
|
|
|
|
NS_IF_ADDREF(*aChild);
|
1999-12-01 06:08:58 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
1999-12-12 13:15:26 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::FindChildWithName(const PRUnichar *aName,
|
2000-03-11 03:53:48 +03:00
|
|
|
PRBool aRecurse, PRBool aSameType, nsIDocShellTreeItem* aRequestor,
|
1999-12-12 13:15:26 +03:00
|
|
|
nsIDocShellTreeItem **_retval)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-12-03 13:29:08 +03:00
|
|
|
NS_ENSURE_ARG(aName);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
*_retval = nsnull; // if we don't find one, we return NS_OK and a null result
|
1999-12-12 13:15:26 +03:00
|
|
|
|
1999-12-03 13:29:08 +03:00
|
|
|
nsAutoString name(aName);
|
1999-12-03 14:22:54 +03:00
|
|
|
nsXPIDLString childName;
|
1999-12-03 13:29:08 +03:00
|
|
|
PRInt32 i, n = mChildren.Count();
|
1999-12-12 13:15:26 +03:00
|
|
|
for(i = 0; i < n; i++)
|
1999-12-03 13:29:08 +03:00
|
|
|
{
|
|
|
|
nsIDocShellTreeItem* child = (nsIDocShellTreeItem*) mChildren.ElementAt(i); // doesn't addref the result
|
|
|
|
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
|
2000-03-11 03:53:48 +03:00
|
|
|
PRInt32 childType;
|
|
|
|
child->GetItemType(&childType);
|
|
|
|
|
|
|
|
if(aSameType && (childType != mItemType))
|
|
|
|
continue;
|
|
|
|
|
1999-12-03 14:22:54 +03:00
|
|
|
child->GetName(getter_Copies(childName));
|
2000-04-28 00:59:12 +04:00
|
|
|
if(name.EqualsWithConversion(childName))
|
1999-12-03 13:29:08 +03:00
|
|
|
{
|
|
|
|
*_retval = child;
|
1999-12-18 05:23:31 +03:00
|
|
|
NS_ADDREF(*_retval);
|
1999-12-03 13:29:08 +03:00
|
|
|
break;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
if(childType != mItemType) //Only ask it to check children if it is same type
|
|
|
|
continue;
|
|
|
|
|
1999-12-12 13:15:26 +03:00
|
|
|
if(aRecurse && (aRequestor != child)) // Only ask the child if it isn't the requestor
|
1999-12-03 13:29:08 +03:00
|
|
|
{
|
2000-03-11 03:53:48 +03:00
|
|
|
// See if child contains the shell with the given name
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> childAsNode(do_QueryInterface(child));
|
|
|
|
if(child)
|
1999-12-08 07:57:23 +03:00
|
|
|
{
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_ENSURE_SUCCESS(childAsNode->FindChildWithName(aName, PR_TRUE,
|
|
|
|
aSameType, NS_STATIC_CAST(nsIDocShellTreeItem*, this), _retval),
|
|
|
|
NS_ERROR_FAILURE);
|
1999-12-08 07:57:23 +03:00
|
|
|
}
|
1999-12-03 13:29:08 +03:00
|
|
|
}
|
1999-12-12 13:15:26 +03:00
|
|
|
if(*_retval) // found it
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
1999-12-12 13:15:26 +03:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-07-06 03:10:29 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIDocShellHistory
|
|
|
|
//*****************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetChildSHEntry(PRInt32 aChildOffset, nsISHEntry ** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
//
|
|
|
|
// A nsISHEntry for a child is *only* available when the parent is in
|
|
|
|
// the progress of loading a document too...
|
|
|
|
//
|
|
|
|
if (LSHE) {
|
|
|
|
nsCOMPtr<nsISHContainer> container(do_QueryInterface(LSHE));
|
|
|
|
if (container) {
|
|
|
|
rv = container->GetChildAt(aChildOffset, aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry,
|
|
|
|
PRInt32 aChildOffset)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (LSHE) {
|
|
|
|
/* You get here if you are currently building a
|
|
|
|
* hierarchy ie.,you just visited a frameset page
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsISHContainer> container(do_QueryInterface(LSHE, &rv));
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
PRInt32 index=-1;
|
|
|
|
nsCOMPtr<nsISHEntry> currentEntry;
|
|
|
|
mSessionHistory->GetIndex(&index);
|
|
|
|
if (index < 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = mSessionHistory->GetEntryAtIndex(index, PR_FALSE,
|
|
|
|
getter_AddRefs(currentEntry));
|
|
|
|
if (currentEntry) {
|
|
|
|
nsCOMPtr<nsISHEntry> nextEntry; //(do_CreateInstance(NS_SHENTRY_PROGID));
|
|
|
|
// NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
|
|
|
|
rv = CloneAndReplace(currentEntry, aCloneRef, aNewEntry,
|
|
|
|
getter_AddRefs(nextEntry));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = mSessionHistory->AddEntry(nextEntry, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* You will get here when you are in a subframe and
|
|
|
|
* a new url has been loaded on you.
|
|
|
|
* The OSHE in this subframe will be the previous url's
|
|
|
|
* OSHE. This OSHE will be used as the identification
|
|
|
|
* for this subframe in the CloneAndReplace function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellHistory> parent(do_QueryInterface(mParent, &rv));
|
|
|
|
if (parent) {
|
|
|
|
if (!aCloneRef) {
|
|
|
|
aCloneRef = OSHE;
|
|
|
|
}
|
|
|
|
rv = parent->AddChildSHEntry(aCloneRef, aNewEntry, aChildOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-07-19 01:55:37 +04:00
|
|
|
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;
|
|
|
|
}
|
2000-07-06 03:10:29 +04:00
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIWebNavigation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetCanGoBack(PRBool* aCanGoBack)
|
|
|
|
{
|
2000-06-24 03:54:30 +04:00
|
|
|
#ifndef SH_IN_FRAMES
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aCanGoBack);
|
|
|
|
*aCanGoBack = PR_FALSE;
|
2000-05-23 04:52:59 +04:00
|
|
|
if (mSessionHistory == nsnull) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(mSessionHistory);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
|
|
|
PRInt32 index = -1;
|
|
|
|
NS_ENSURE_SUCCESS(mSessionHistory->GetIndex(&index), NS_ERROR_FAILURE);
|
|
|
|
if(index > 0)
|
|
|
|
*aCanGoBack = PR_TRUE;
|
2000-07-01 02:05:32 +04:00
|
|
|
#else
|
|
|
|
if (mSessionHistory) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mSessionHistory));
|
|
|
|
|
|
|
|
if (webNav) {
|
|
|
|
return webNav->GetCanGoBack(aCanGoBack);
|
|
|
|
}
|
|
|
|
}
|
2000-08-03 01:49:26 +04:00
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsWebnav(do_QueryInterface(root));
|
|
|
|
if (rootAsWebnav) {
|
|
|
|
rootAsWebnav->GetCanGoBack(aCanGoBack);
|
|
|
|
}
|
|
|
|
}
|
2000-06-24 03:54:30 +04:00
|
|
|
#endif
|
2000-02-24 07:15:22 +03:00
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetCanGoForward(PRBool* aCanGoForward)
|
|
|
|
{
|
2000-06-24 03:54:30 +04:00
|
|
|
#ifndef SH_IN_FRAMES
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aCanGoForward);
|
|
|
|
*aCanGoForward = PR_FALSE;
|
2000-05-23 04:52:59 +04:00
|
|
|
if (mSessionHistory == nsnull) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(mSessionHistory);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
|
|
|
PRInt32 index = -1;
|
|
|
|
PRInt32 count = -1;
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(mSessionHistory->GetIndex(&index), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(mSessionHistory->GetCount(&count), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if((index >= 0) && (index < (count - 1)))
|
|
|
|
*aCanGoForward = PR_TRUE;
|
2000-07-01 02:05:32 +04:00
|
|
|
#else
|
|
|
|
if (mSessionHistory) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mSessionHistory));
|
|
|
|
|
|
|
|
if (webNav) {
|
|
|
|
return webNav->GetCanGoForward(aCanGoForward);
|
|
|
|
}
|
|
|
|
}
|
2000-08-03 01:49:26 +04:00
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsWebnav(do_QueryInterface(root));
|
|
|
|
if (rootAsWebnav) {
|
|
|
|
rootAsWebnav->GetCanGoForward(aCanGoForward);
|
|
|
|
}
|
|
|
|
}
|
2000-06-24 03:54:30 +04:00
|
|
|
#endif
|
2000-02-24 07:15:22 +03:00
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GoBack()
|
|
|
|
{
|
2000-06-24 03:54:30 +04:00
|
|
|
#ifndef SH_IN_FRAMES
|
2000-05-23 04:52:59 +04:00
|
|
|
if (mSessionHistory == nsnull) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
if(root.get() != NS_STATIC_CAST(nsIDocShellTreeItem*, this))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsNav(do_QueryInterface(root));
|
|
|
|
return rootAsNav->GoBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(mSessionHistory);
|
|
|
|
|
2000-05-27 01:03:34 +04:00
|
|
|
|
|
|
|
UpdateCurrentSessionHistory();
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
nsCOMPtr<nsISHEntry> previousEntry;
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(mSessionHistory->GetPreviousEntry(PR_TRUE,
|
|
|
|
getter_AddRefs(previousEntry)), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(previousEntry, NS_ERROR_FAILURE);
|
|
|
|
|
2000-05-27 01:03:34 +04:00
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_ENSURE_SUCCESS(LoadHistoryEntry(previousEntry), NS_ERROR_FAILURE);
|
2000-07-01 02:05:32 +04:00
|
|
|
#else
|
|
|
|
if (mSessionHistory) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mSessionHistory));
|
|
|
|
|
|
|
|
if (webNav) {
|
|
|
|
return webNav->GoBack();
|
|
|
|
}
|
|
|
|
}
|
2000-08-03 01:49:26 +04:00
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsWebnav(do_QueryInterface(root));
|
|
|
|
if (rootAsWebnav) {
|
|
|
|
rootAsWebnav->GoBack();
|
|
|
|
}
|
|
|
|
}
|
2000-06-24 03:54:30 +04:00
|
|
|
#endif
|
2000-02-24 07:15:22 +03:00
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GoForward()
|
|
|
|
{
|
2000-06-24 03:54:30 +04:00
|
|
|
#ifndef SH_IN_FRAMES
|
2000-05-23 04:52:59 +04:00
|
|
|
if (mSessionHistory == nsnull) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
if(root.get() != NS_STATIC_CAST(nsIDocShellTreeItem*, this))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsNav(do_QueryInterface(root));
|
|
|
|
return rootAsNav->GoForward();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(mSessionHistory);
|
|
|
|
|
2000-05-27 01:03:34 +04:00
|
|
|
UpdateCurrentSessionHistory();
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
nsCOMPtr<nsISHEntry> nextEntry;
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(mSessionHistory->GetNextEntry(PR_TRUE,
|
|
|
|
getter_AddRefs(nextEntry)), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(nextEntry, NS_ERROR_FAILURE);
|
2000-05-27 01:03:34 +04:00
|
|
|
|
2000-04-16 09:16:16 +04:00
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_ENSURE_SUCCESS(LoadHistoryEntry(nextEntry), NS_ERROR_FAILURE);
|
2000-07-01 02:05:32 +04:00
|
|
|
#else
|
|
|
|
if (mSessionHistory) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mSessionHistory));
|
|
|
|
|
|
|
|
if (webNav) {
|
|
|
|
return webNav->GoForward();
|
|
|
|
}
|
|
|
|
}
|
2000-08-03 01:49:26 +04:00
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsWebnav(do_QueryInterface(root));
|
|
|
|
if (rootAsWebnav) {
|
|
|
|
rootAsWebnav->GoForward();
|
|
|
|
}
|
|
|
|
}
|
2000-06-24 03:54:30 +04:00
|
|
|
#endif
|
2000-02-24 07:15:22 +03:00
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2000-06-24 03:54:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GotoIndex(PRInt32 aIndex)
|
|
|
|
{
|
2000-08-03 01:49:26 +04:00
|
|
|
if (mSessionHistory) {
|
|
|
|
nsCOMPtr<nsIWebNavigation>webNav(do_QueryInterface(mSessionHistory));
|
|
|
|
if (webNav) {
|
|
|
|
return webNav->GotoIndex(aIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsWebnav(do_QueryInterface(root));
|
|
|
|
if (rootAsWebnav) {
|
|
|
|
rootAsWebnav->GotoIndex(aIndex);
|
|
|
|
}
|
|
|
|
}
|
2000-06-24 03:54:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-07-13 03:31:31 +04:00
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::LoadURI(const PRUnichar* aURI)
|
|
|
|
{
|
2000-02-24 07:15:22 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
nsresult rv = CreateFixupURI(aURI, getter_AddRefs(uri));
|
2000-04-12 03:52:42 +04:00
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
if(NS_ERROR_UNKNOWN_PROTOCOL == rv)
|
|
|
|
{
|
|
|
|
// we weren't able to find a protocol handler
|
|
|
|
nsCOMPtr<nsIPrompt> prompter;
|
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
2000-04-22 03:32:11 +04:00
|
|
|
GetPromptAndStringBundle(getter_AddRefs(prompter),
|
|
|
|
getter_AddRefs(stringBundle));
|
2000-04-13 07:11:44 +04:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(stringBundle, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsXPIDLString messageStr;
|
2000-04-17 15:24:01 +04:00
|
|
|
NS_ENSURE_SUCCESS(stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("protocolNotFound").GetUnicode(),
|
2000-04-13 07:11:44 +04:00
|
|
|
getter_Copies(messageStr)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsAutoString uriString(aURI);
|
|
|
|
PRInt32 colon = uriString.FindChar(':');
|
|
|
|
// extract the scheme
|
|
|
|
nsAutoString scheme;
|
|
|
|
uriString.Left(scheme, colon);
|
2000-05-19 01:52:23 +04:00
|
|
|
nsCAutoString cScheme;
|
|
|
|
cScheme.AssignWithConversion(scheme);
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2000-05-19 01:52:23 +04:00
|
|
|
PRUnichar *msg = nsTextFormatter::smprintf(messageStr, cScheme.GetBuffer());
|
|
|
|
if (!msg) return NS_ERROR_OUT_OF_MEMORY;
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2000-05-19 01:52:23 +04:00
|
|
|
prompter->Alert(nsnull, msg);
|
|
|
|
nsTextFormatter::smprintf_free(msg);
|
2000-04-13 07:11:44 +04:00
|
|
|
} // end unknown protocol
|
|
|
|
|
|
|
|
if(!uri)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(LoadURI(uri, nsnull), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::Reload(PRInt32 aReloadType)
|
|
|
|
{
|
2000-06-22 09:36:13 +04:00
|
|
|
#ifdef SH_IN_FRAMES
|
|
|
|
// XXX Honor the reload type
|
2000-07-15 02:42:33 +04:00
|
|
|
//NS_ENSURE_STATE(mCurrentURI);
|
2000-06-22 09:36:13 +04:00
|
|
|
|
|
|
|
// XXXTAB Convert reload type to our type
|
2000-06-22 11:22:23 +04:00
|
|
|
nsDocShellInfoLoadType type = nsIDocShellLoadInfo::loadReloadNormal;
|
2000-06-30 01:48:18 +04:00
|
|
|
if ( aReloadType == nsIWebNavigation::loadReloadBypassProxyAndCache )
|
2000-06-22 11:22:23 +04:00
|
|
|
type = nsIDocShellLoadInfo::loadReloadBypassProxyAndCache;
|
2000-07-19 02:24:27 +04:00
|
|
|
#if 0
|
2000-06-22 09:36:13 +04:00
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
2000-07-15 02:42:33 +04:00
|
|
|
if (OSHE) {
|
|
|
|
/* We should fall here in most cases including subframes & refreshes */
|
|
|
|
entry = OSHE;
|
|
|
|
} else if (mSessionHistory) {
|
|
|
|
/* In case we fail above, as a last ditch effort, we
|
|
|
|
* reload the whole page.
|
|
|
|
*/
|
|
|
|
PRInt32 index = -1;
|
|
|
|
NS_ENSURE_SUCCESS(mSessionHistory->GetIndex(&index), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(mSessionHistory->GetEntryAtIndex(index, PR_FALSE,
|
|
|
|
getter_AddRefs(entry)), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE);
|
|
|
|
}
|
2000-07-18 00:12:27 +04:00
|
|
|
else {
|
|
|
|
//May be one of those <META> charset reloads in a composer or Messenger
|
2000-08-31 09:53:32 +04:00
|
|
|
return InternalLoad(mCurrentURI, mReferrerURI, nsnull, PR_TRUE, nsnull,
|
2000-07-18 00:12:27 +04:00
|
|
|
nsnull, type);
|
|
|
|
|
|
|
|
}
|
2000-07-19 02:24:27 +04:00
|
|
|
#else
|
|
|
|
// OK. Atleast for the heck of it, pollmann says that he doesn't crash
|
|
|
|
// in bug 45297 if he just did the following, instead of the one in #if 0.
|
|
|
|
// If this really keeps the crash from re-occuring, may be this can stay. However
|
|
|
|
// there is no major difference between this one and the one inside #if 0
|
|
|
|
|
2000-08-31 09:53:32 +04:00
|
|
|
return InternalLoad(mCurrentURI, mReferrerURI, nsnull, PR_TRUE, nsnull,
|
2000-07-19 02:24:27 +04:00
|
|
|
nsnull, type);
|
|
|
|
#endif /* 0 */
|
2000-07-18 00:12:27 +04:00
|
|
|
|
2000-07-15 02:42:33 +04:00
|
|
|
|
2000-07-19 02:24:27 +04:00
|
|
|
// return LoadHistoryEntry(entry, type);
|
2000-06-22 09:36:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
// XXX Honor the reload type
|
|
|
|
NS_ENSURE_STATE(mCurrentURI);
|
|
|
|
|
2000-03-25 06:43:27 +03:00
|
|
|
// XXXTAB Convert reload type to our type
|
2000-06-22 11:22:23 +04:00
|
|
|
nsDocShellInfoLoadType type = nsIDocShellLoadInfo::loadReloadNormal;
|
2000-06-30 01:48:18 +04:00
|
|
|
if ( aReloadType == nsIWebNavigation::loadReloadBypassProxyAndCache )
|
2000-06-22 11:22:23 +04:00
|
|
|
type = nsIDocShellLoadInfo::loadReloadBypassProxyAndCache;
|
|
|
|
|
2000-06-22 01:33:17 +04:00
|
|
|
UpdateCurrentSessionHistory();
|
|
|
|
|
2000-08-31 09:53:32 +04:00
|
|
|
NS_ENSURE_SUCCESS(InternalLoad(mCurrentURI, mReferrerURI, nsnull, PR_TRUE, nsnull,
|
2000-06-14 03:56:30 +04:00
|
|
|
nsnull, type), NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
return NS_OK;
|
2000-07-15 02:42:33 +04:00
|
|
|
#endif /* SH_IN_FRAMES */
|
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::Stop()
|
|
|
|
{
|
2000-04-13 07:11:44 +04:00
|
|
|
// Cancel any timers that were set for this loader.
|
|
|
|
CancelRefreshURITimers();
|
|
|
|
|
2000-02-14 13:27:32 +03:00
|
|
|
if(mContentViewer)
|
|
|
|
mContentViewer->Stop();
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
if(mLoadCookie)
|
2000-02-14 13:27:32 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURILoader> uriLoader = do_GetService(NS_URI_LOADER_PROGID);
|
|
|
|
if(uriLoader)
|
2000-02-24 07:15:22 +03:00
|
|
|
uriLoader->Stop(mLoadCookie);
|
2000-02-14 13:27:32 +03: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)
|
|
|
|
shellAsNav->Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetDocument(nsIDOMDocument** aDocument)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDocument);
|
|
|
|
NS_ENSURE_STATE(mContentViewer);
|
|
|
|
|
2000-06-22 09:38:07 +04:00
|
|
|
return mContentViewer->GetDOMDocument(aDocument);
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
2000-08-30 15:32:30 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetCurrentURI(nsIURI** aURI)
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
2000-08-30 15:32:30 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2000-02-17 05:03:02 +03:00
|
|
|
|
2000-08-30 15:32:30 +04:00
|
|
|
*aURI = mCurrentURI;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
2000-02-17 05:03:02 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetSessionHistory(nsISHistory* aSessionHistory)
|
|
|
|
{
|
2000-02-17 05:03:02 +03:00
|
|
|
mSessionHistory = aSessionHistory;
|
2000-07-01 02:05:32 +04:00
|
|
|
|
|
|
|
#if defined(SH_IN_FRAMES)
|
|
|
|
if (mSessionHistory) {
|
|
|
|
mSessionHistory->SetRootDocShell(this);
|
|
|
|
}
|
|
|
|
#endif /* SH_IN_FRAMES */
|
|
|
|
|
2000-02-17 05:03:02 +03:00
|
|
|
return NS_OK;
|
2000-02-14 09:40:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetSessionHistory(nsISHistory** aSessionHistory)
|
|
|
|
{
|
2000-02-17 05:03:02 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aSessionHistory);
|
|
|
|
|
2000-08-03 01:49:26 +04:00
|
|
|
if (mSessionHistory) {
|
|
|
|
*aSessionHistory = mSessionHistory;
|
|
|
|
NS_IF_ADDREF(*aSessionHistory);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIWebNavigation> rootAsWebnav(do_QueryInterface(root));
|
|
|
|
if (rootAsWebnav) {
|
|
|
|
rootAsWebnav->GetSessionHistory(aSessionHistory);
|
|
|
|
}
|
|
|
|
}
|
2000-02-17 05:03:02 +03:00
|
|
|
return NS_OK;
|
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
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::InitWindow(nativeWindow parentNativeWindow,
|
|
|
|
nsIWidget* parentWidget, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(parentWidget); // DocShells must get a widget for a parent
|
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
SetParentWidget(parentWidget);
|
|
|
|
SetPositionAndSize(x, y, cx, cy, PR_FALSE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::Create()
|
|
|
|
{
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_ENSURE_STATE(!mContentViewer);
|
2000-03-02 10:13:02 +03:00
|
|
|
mPrefs = do_GetService(NS_PREF_PROGID);
|
2000-07-19 01:55:37 +04:00
|
|
|
//GlobalHistory is now set in SetGlobalHistory
|
|
|
|
// mGlobalHistory = do_GetService(NS_GLOBALHISTORY_PROGID);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-06-23 08:44:36 +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);
|
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::Destroy()
|
|
|
|
{
|
2000-03-31 04:15:17 +04:00
|
|
|
// Stop any URLs that are currently being loaded...
|
|
|
|
Stop();
|
|
|
|
if(mDocLoader)
|
|
|
|
{
|
|
|
|
mDocLoader->Destroy();
|
|
|
|
mDocLoader->SetContainer(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDocLoaderObserver(nsnull);
|
|
|
|
|
2000-07-06 03:10:29 +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();
|
|
|
|
|
2000-03-31 04:15:17 +04:00
|
|
|
// Remove this docshell from its parent's child list
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellParentAsNode(do_QueryInterface(mParent));
|
|
|
|
if(docShellParentAsNode)
|
|
|
|
docShellParentAsNode->RemoveChild(this);
|
|
|
|
|
2000-03-31 05:19:28 +04:00
|
|
|
mContentViewer = nsnull;
|
|
|
|
|
2000-03-31 04:15:17 +04:00
|
|
|
DestroyChildren();
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
mDocLoader = nsnull;
|
|
|
|
mDocLoaderObserver = nsnull;
|
|
|
|
mParentWidget = nsnull;
|
|
|
|
mPrefs = nsnull;
|
|
|
|
mCurrentURI = nsnull;
|
2000-03-25 06:43:27 +03:00
|
|
|
|
|
|
|
if(mScriptGlobal)
|
|
|
|
{
|
|
|
|
mScriptGlobal->SetDocShell(nsnull);
|
|
|
|
mScriptGlobal = nsnull;
|
|
|
|
}
|
|
|
|
if(mScriptContext)
|
|
|
|
{
|
|
|
|
mScriptContext->SetOwner(nsnull);
|
|
|
|
mScriptContext = nsnull;
|
|
|
|
}
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
mScriptGlobal = nsnull;
|
|
|
|
mScriptContext = nsnull;
|
|
|
|
mSessionHistory = nsnull;
|
2000-03-31 04:15:17 +04:00
|
|
|
SetTreeOwner(nsnull);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2000-06-20 11:59:45 +04:00
|
|
|
SetLoadCookie(nsnull);
|
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
if(mInitInfo)
|
|
|
|
{
|
|
|
|
delete mInitInfo;
|
|
|
|
mInitInfo = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mContentListener)
|
|
|
|
{
|
|
|
|
mContentListener->DocShell(nsnull);
|
|
|
|
NS_RELEASE(mContentListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetPosition(PRInt32 x, PRInt32 y)
|
|
|
|
{
|
1999-11-13 11:09:16 +03:00
|
|
|
if(mContentViewer)
|
|
|
|
NS_ENSURE_SUCCESS(mContentViewer->Move(x, y), NS_ERROR_FAILURE);
|
|
|
|
else if(InitInfo())
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-11-13 11:09:16 +03:00
|
|
|
mInitInfo->x = x;
|
|
|
|
mInitInfo->y = y;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
else
|
1999-11-13 11:09:16 +03:00
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-14 11:19:19 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetPosition(PRInt32* aX, PRInt32* aY)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-01-14 11:19:19 +03:00
|
|
|
PRInt32 dummyHolder;
|
|
|
|
return GetPositionAndSize(aX, aY, &dummyHolder, &dummyHolder);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::SetSize(PRInt32 aCX, PRInt32 aCY, PRBool aRepaint)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-03-11 03:53:48 +03:00
|
|
|
PRInt32 x = 0, y = 0;
|
|
|
|
GetPosition(&x, &y);
|
|
|
|
return SetPositionAndSize(x, y, aCX, aCY, aRepaint);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-01-14 11:19:19 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetSize(PRInt32* aCX, PRInt32* aCY)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-01-14 11:19:19 +03:00
|
|
|
PRInt32 dummyHolder;
|
|
|
|
return GetPositionAndSize(&dummyHolder, &dummyHolder, aCX, aCY);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx,
|
|
|
|
PRInt32 cy, PRBool fRepaint)
|
|
|
|
{
|
1999-11-13 11:09:16 +03:00
|
|
|
if(mContentViewer)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-11-13 11:09:16 +03:00
|
|
|
//XXX Border figured in here or is that handled elsewhere?
|
|
|
|
nsRect bounds(x, y, cx, cy);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(mContentViewer->SetBounds(bounds), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
1999-11-13 11:09:16 +03:00
|
|
|
else if(InitInfo())
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-11-13 11:09:16 +03:00
|
|
|
mInitInfo->x = x;
|
|
|
|
mInitInfo->y = y;
|
|
|
|
mInitInfo->cx = cx;
|
|
|
|
mInitInfo->cy = cy;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
1999-11-13 11:09:16 +03:00
|
|
|
else
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-29 10:47:20 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx,
|
|
|
|
PRInt32* cy)
|
|
|
|
{
|
|
|
|
if(mContentViewer)
|
|
|
|
{
|
|
|
|
nsRect bounds;
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(mContentViewer->GetBounds(bounds), NS_ERROR_FAILURE);
|
|
|
|
|
2000-02-08 16:40:10 +03:00
|
|
|
if(x)
|
|
|
|
*x = bounds.x;
|
|
|
|
if(y)
|
|
|
|
*y = bounds.y;
|
|
|
|
if(cx)
|
|
|
|
*cx = bounds.width;
|
|
|
|
if(cy)
|
|
|
|
*cy = bounds.height;
|
1999-11-29 10:47:20 +03:00
|
|
|
}
|
|
|
|
else if(InitInfo())
|
|
|
|
{
|
2000-02-08 16:40:10 +03:00
|
|
|
if(x)
|
|
|
|
*x = mInitInfo->x;
|
|
|
|
if(y)
|
|
|
|
*y = mInitInfo->y;
|
|
|
|
if(cx)
|
|
|
|
*cx = mInitInfo->cx;
|
|
|
|
if(cy)
|
|
|
|
*cy = mInitInfo->cy;
|
1999-11-29 10:47:20 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::Repaint(PRBool aForce)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-03-11 03:53:48 +03:00
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(mContentViewer));
|
|
|
|
NS_ENSURE_TRUE(docViewer, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
nsCOMPtr<nsIPresContext> context;
|
|
|
|
docViewer->GetPresContext(*getter_AddRefs(context));
|
|
|
|
NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
context->GetShell(getter_AddRefs(shell));
|
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
shell->GetViewManager(getter_AddRefs(viewManager));
|
|
|
|
NS_ENSURE_TRUE(viewManager, NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
// what about aForce ?
|
|
|
|
NS_ENSURE_SUCCESS(viewManager->UpdateAllViews(0), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetParentWidget(nsIWidget** parentWidget)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(parentWidget);
|
|
|
|
|
|
|
|
*parentWidget = mParentWidget;
|
1999-12-12 13:15:26 +03:00
|
|
|
NS_IF_ADDREF(*parentWidget);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::SetParentWidget(nsIWidget* aParentWidget)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_ENSURE_STATE(!mContentViewer);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
mParentWidget = aParentWidget;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetParentNativeWindow(nativeWindow* parentNativeWindow)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(parentNativeWindow);
|
|
|
|
|
|
|
|
if(mParentWidget)
|
|
|
|
*parentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET);
|
|
|
|
else
|
|
|
|
*parentNativeWindow = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetParentNativeWindow(nativeWindow parentNativeWindow)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetVisibility(PRBool* aVisibility)
|
|
|
|
{
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aVisibility);
|
|
|
|
if(!mContentViewer)
|
|
|
|
{
|
1999-11-12 10:28:25 +03:00
|
|
|
*aVisibility = PR_FALSE;
|
2000-02-14 09:40:28 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-14 09:40:28 +03: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);
|
|
|
|
|
|
|
|
// 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 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);
|
|
|
|
|
|
|
|
// convert the view's visibility attribute to a bool
|
|
|
|
nsViewVisibility vis;
|
|
|
|
NS_ENSURE_TRUE(rootView->GetVisibility(vis), NS_ERROR_FAILURE);
|
|
|
|
*aVisibility = nsViewVisibility_kHide==vis ? PR_FALSE : PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::SetVisibility(PRBool aVisibility)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-02-14 09:40:28 +03:00
|
|
|
if(!mContentViewer)
|
|
|
|
return NS_OK;
|
|
|
|
if(aVisibility)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_ENSURE_SUCCESS(EnsureContentViewer(), NS_ERROR_FAILURE);
|
|
|
|
mContentViewer->Show();
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
2000-02-14 09:40:28 +03:00
|
|
|
else if(mContentViewer)
|
|
|
|
mContentViewer->Hide();
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-11 03:53:48 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetMainWidget(nsIWidget** aMainWidget)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-03-11 03:53:48 +03: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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetFocus()
|
|
|
|
{
|
2000-04-13 06:54:38 +04:00
|
|
|
nsCOMPtr<nsIWidget> mainWidget;
|
|
|
|
GetMainWidget(getter_AddRefs(mainWidget));
|
|
|
|
if(mainWidget)
|
|
|
|
mainWidget->SetFocus();
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
1999-12-02 12:42:11 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::FocusAvailable(nsIBaseWindow* aCurrentFocus,
|
|
|
|
PRBool* aTookFocus)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTookFocus);
|
|
|
|
|
|
|
|
// Next person we should call is first the parent otherwise the
|
|
|
|
// docshell tree owner.
|
|
|
|
nsCOMPtr<nsIBaseWindow> nextCallWin(do_QueryInterface(mParent));
|
|
|
|
if(!nextCallWin)
|
2000-02-11 04:09:12 +03:00
|
|
|
{
|
|
|
|
nextCallWin = do_QueryInterface(mTreeOwner);
|
1999-12-02 12:42:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//If the current focus is us, offer it to the next owner.
|
|
|
|
if(aCurrentFocus == NS_STATIC_CAST(nsIBaseWindow*, this))
|
|
|
|
{
|
|
|
|
if(nextCallWin)
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
{
|
|
|
|
nsresult ret = nextCallWin->FocusAvailable(aCurrentFocus, aTookFocus);
|
|
|
|
if (NS_SUCCEEDED(ret) && *aTookFocus)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mChildren.Count())
|
|
|
|
{
|
|
|
|
//If we don't have children and our parent didn't want
|
|
|
|
//the focus then we should just stop now.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-12-02 12:42:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//Otherwise, check the chilren and offer it to the next sibling.
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 n = mChildren.Count();
|
|
|
|
for(i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIBaseWindow>
|
|
|
|
child(do_QueryInterface((nsISupports*)mChildren.ElementAt(i)));
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
//If we have focus we offer it to our first child.
|
|
|
|
if(aCurrentFocus == NS_STATIC_CAST(nsIBaseWindow*, this))
|
|
|
|
{
|
|
|
|
if(NS_SUCCEEDED(child->SetFocus()))
|
|
|
|
{
|
|
|
|
*aTookFocus = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//If we don't have focus, find the child that does then
|
|
|
|
//offer focus to the next one.
|
|
|
|
if (child.get() == aCurrentFocus)
|
1999-12-02 12:42:11 +03:00
|
|
|
{
|
|
|
|
while(++i < n)
|
|
|
|
{
|
1999-12-02 13:05:17 +03:00
|
|
|
child = do_QueryInterface((nsISupports*)mChildren.ElementAt(i));
|
1999-12-02 12:42:11 +03:00
|
|
|
if(NS_SUCCEEDED(child->SetFocus()))
|
|
|
|
{
|
|
|
|
*aTookFocus = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-12-02 12:42:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
|
|
|
//Reached the end of our child list. Call again to offer focus
|
|
|
|
//upwards and to start at the beginning of our child list if
|
|
|
|
//no one above us wants focus.
|
|
|
|
return FocusAvailable(this, aTookFocus);
|
1999-12-02 12:42:11 +03:00
|
|
|
}
|
|
|
|
|
1999-12-21 03:11:33 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetTitle(PRUnichar** aTitle)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-12-21 03:11:33 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aTitle);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
1999-12-21 03:11:33 +03:00
|
|
|
*aTitle = mTitle.ToNewUnicode();
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
1999-12-21 03:11:33 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::SetTitle(const PRUnichar* aTitle)
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
1999-12-21 03:11:33 +03:00
|
|
|
// Store local title
|
|
|
|
mTitle = aTitle;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
GetSameTypeParent(getter_AddRefs(parent));
|
|
|
|
|
|
|
|
// 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));
|
2000-07-05 01:49:27 +04:00
|
|
|
if (treeOwnerAsWin)
|
2000-07-05 02:08:41 +04:00
|
|
|
treeOwnerAsWin->SetTitle(aTitle);
|
1999-12-21 03:11:33 +03:00
|
|
|
}
|
|
|
|
|
2000-04-16 12:39:15 +04:00
|
|
|
if(mGlobalHistory && mCurrentURI)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
|
|
|
nsXPIDLCString url;
|
|
|
|
mCurrentURI->GetSpec(getter_Copies(url));
|
2000-04-16 12:39:15 +04:00
|
|
|
mGlobalHistory->SetPageTitle(url, aTitle);
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2000-05-11 02:45:24 +04:00
|
|
|
|
2000-04-21 03:14:53 +04:00
|
|
|
// Update SessionHistory too with Title. Otherwise entry for current page
|
|
|
|
// has previous page's title.
|
2000-04-22 03:32:11 +04:00
|
|
|
if(mSessionHistory)
|
|
|
|
{
|
|
|
|
PRInt32 index = -1;
|
|
|
|
mSessionHistory->GetIndex(&index);
|
|
|
|
nsCOMPtr<nsISHEntry> shEntry;
|
|
|
|
mSessionHistory->GetEntryAtIndex(index, PR_FALSE, getter_AddRefs(shEntry));
|
|
|
|
if(shEntry)
|
|
|
|
shEntry->SetTitle(mTitle.GetUnicode());
|
|
|
|
}
|
2000-04-21 03:14:53 +04:00
|
|
|
|
2000-05-11 02:45:24 +04:00
|
|
|
|
1999-12-21 03:11:33 +03:00
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIScrollable
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetCurScrollPos(PRInt32 scrollOrientation,
|
|
|
|
PRInt32* curPos)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(curPos);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-05-24 02:36:47 +04:00
|
|
|
if (!scrollView)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
nscoord x, y;
|
|
|
|
NS_ENSURE_SUCCESS(scrollView->GetScrollPosition(x, y), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
switch(scrollOrientation)
|
|
|
|
{
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
*curPos = x;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case ScrollOrientation_Y:
|
|
|
|
*curPos = y;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetCurScrollPos(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 curPos)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-05-24 02:36:47 +04:00
|
|
|
if (!scrollView)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
PRInt32 other;
|
|
|
|
PRInt32 x;
|
|
|
|
PRInt32 y;
|
|
|
|
|
|
|
|
GetCurScrollPos(scrollOrientation, &other);
|
|
|
|
|
|
|
|
switch(scrollOrientation)
|
|
|
|
{
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
x = curPos;
|
|
|
|
y = other;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ScrollOrientation_Y:
|
|
|
|
x = other;
|
|
|
|
y = curPos;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(scrollView->ScrollTo(x, y, NS_VMREFRESH_IMMEDIATE),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetCurScrollPosEx(PRInt32 curHorizontalPos,
|
|
|
|
PRInt32 curVerticalPos)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-05-24 02:36:47 +04:00
|
|
|
if (!scrollView)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(scrollView->ScrollTo(curHorizontalPos, curVerticalPos,
|
|
|
|
NS_VMREFRESH_IMMEDIATE), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX This is wrong
|
|
|
|
NS_IMETHODIMP nsDocShell::GetScrollRange(PRInt32 scrollOrientation,
|
|
|
|
PRInt32* minPos, PRInt32* maxPos)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(minPos && maxPos);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-05-24 02:36:47 +04:00
|
|
|
if (!scrollView)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
PRInt32 cx;
|
|
|
|
PRInt32 cy;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetScrollRange(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 minPos, PRInt32 maxPos)
|
|
|
|
{
|
|
|
|
//XXX First Check
|
1999-12-07 01:32:32 +03:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
1999-11-12 10:28:25 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::SetScrollRangeEx(PRInt32 minHorizontalPos,
|
|
|
|
PRInt32 maxHorizontalPos, PRInt32 minVerticalPos, PRInt32 maxVerticalPos)
|
|
|
|
{
|
|
|
|
//XXX First Check
|
1999-12-07 01:32:32 +03:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
1999-11-12 10:28:25 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
// Get scroll setting for this document only
|
|
|
|
//
|
|
|
|
// One important client is nsCSSFrameConstructor::ConstructRootFrame()
|
|
|
|
NS_IMETHODIMP nsDocShell::GetCurrentScrollbarPreferences(PRInt32 scrollOrientation,
|
1999-11-12 10:28:25 +03:00
|
|
|
PRInt32* scrollbarPref)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(scrollbarPref);
|
2000-02-29 09:51:48 +03:00
|
|
|
switch(scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
*scrollbarPref = mCurrentScrollbarPref.x;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
case ScrollOrientation_Y:
|
|
|
|
*scrollbarPref = mCurrentScrollbarPref.y;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
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
|
|
|
// This returns setting for all documents in this webshell
|
|
|
|
NS_IMETHODIMP nsDocShell::GetDefaultScrollbarPreferences(PRInt32 scrollOrientation,
|
|
|
|
PRInt32* scrollbarPref)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(scrollbarPref);
|
|
|
|
switch(scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
*scrollbarPref = mDefaultScrollbarPref.x;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
case ScrollOrientation_Y:
|
|
|
|
*scrollbarPref = mDefaultScrollbarPref.y;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
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()
|
|
|
|
NS_IMETHODIMP nsDocShell::SetCurrentScrollbarPreferences(PRInt32 scrollOrientation,
|
1999-11-12 10:28:25 +03:00
|
|
|
PRInt32 scrollbarPref)
|
|
|
|
{
|
2000-02-29 09:51:48 +03:00
|
|
|
switch(scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
mCurrentScrollbarPref.x = scrollbarPref;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
case ScrollOrientation_Y:
|
|
|
|
mCurrentScrollbarPref.y = scrollbarPref;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-02-29 09:51:48 +03:00
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set scrolling preference for all documents in this shell
|
|
|
|
// One important client is nsHTMLFrameInnerFrame::CreateWebShell()
|
|
|
|
NS_IMETHODIMP nsDocShell::SetDefaultScrollbarPreferences(PRInt32 scrollOrientation,
|
|
|
|
PRInt32 scrollbarPref)
|
|
|
|
{
|
|
|
|
switch(scrollOrientation) {
|
|
|
|
case ScrollOrientation_X:
|
|
|
|
mDefaultScrollbarPref.x = scrollbarPref;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case ScrollOrientation_Y:
|
|
|
|
mDefaultScrollbarPref.y = scrollbarPref;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
NS_IMETHODIMP nsDocShell::ResetScrollbarPreferences()
|
|
|
|
{
|
|
|
|
mCurrentScrollbarPref = mDefaultScrollbarPref;
|
|
|
|
return NS_OK;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetScrollbarVisibility(PRBool* verticalVisible,
|
|
|
|
PRBool* horizontalVisible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-05-24 02:36:47 +04:00
|
|
|
if (!scrollView)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
PRBool vertVisible;
|
|
|
|
PRBool horizVisible;
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(scrollView->GetScrollbarVisibility(&vertVisible,
|
|
|
|
&horizVisible), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if(verticalVisible)
|
|
|
|
*verticalVisible = vertVisible;
|
|
|
|
if(horizontalVisible)
|
|
|
|
*horizontalVisible = horizVisible;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsITextScroll
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::ScrollByLines(PRInt32 numLines)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-05-24 02:36:47 +04:00
|
|
|
if (!scrollView)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
2000-05-16 15:35:12 +04:00
|
|
|
NS_ENSURE_SUCCESS(scrollView->ScrollByLines(0, numLines), NS_ERROR_FAILURE);
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::ScrollByPages(PRInt32 numPages)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScrollableView> scrollView;
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-05-24 02:36:47 +04:00
|
|
|
if (!scrollView)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-12 10:28:25 +03:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(scrollView->ScrollByPages(numPages), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetScriptGlobalObject(nsIScriptGlobalObject** aGlobal)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aGlobal);
|
|
|
|
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
|
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
*aGlobal = mScriptGlobal;
|
|
|
|
NS_IF_ADDREF(*aGlobal);
|
1999-11-30 04:06:59 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-15 05:56:47 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::ReportScriptError(nsIScriptError *errorObject)
|
1999-11-30 04:06:59 +03:00
|
|
|
{
|
2000-03-31 15:19:51 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2000-04-15 05:56:47 +04:00
|
|
|
if (errorObject == nsnull)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-03-31 15:19:51 +04:00
|
|
|
// Get the console service, where we're going to register the error.
|
|
|
|
nsCOMPtr<nsIConsoleService> consoleService
|
|
|
|
(do_GetService("mozilla.consoleservice.1"));
|
|
|
|
|
2000-04-15 05:56:47 +04:00
|
|
|
if (consoleService != nsnull)
|
2000-03-31 15:19:51 +04:00
|
|
|
{
|
2000-04-15 05:56:47 +04:00
|
|
|
rv = consoleService->LogMessage(errorObject);
|
2000-03-31 15:19:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2000-04-15 05:56:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return rv;
|
2000-03-31 15:19:51 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-15 05:56:47 +04:00
|
|
|
else
|
1999-11-30 04:06:59 +03:00
|
|
|
{
|
2000-04-15 05:56:47 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
1999-11-30 04:06:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIRefreshURI
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::RefreshURI(nsIURI *aURI, PRInt32 aDelay, PRBool aRepeat)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
|
|
|
nsRefreshTimer* refreshTimer = new nsRefreshTimer();
|
|
|
|
NS_ENSURE_TRUE(refreshTimer, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> dataRef = refreshTimer; // Get the ref count to 1
|
|
|
|
|
|
|
|
refreshTimer->mDocShell = this;
|
|
|
|
refreshTimer->mURI = aURI;
|
|
|
|
refreshTimer->mDelay = aDelay;
|
|
|
|
refreshTimer->mRepeat = aRepeat;
|
|
|
|
|
2000-05-18 00:24:43 +04:00
|
|
|
if (!mRefreshURIList)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(NS_NewISupportsArray(getter_AddRefs(mRefreshURIList)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
2000-05-17 06:49:35 +04:00
|
|
|
nsCOMPtr<nsITimer> timer = do_CreateInstance("component://netscape/timer");
|
2000-04-13 07:11:44 +04:00
|
|
|
NS_ENSURE_TRUE(timer, NS_ERROR_FAILURE);
|
2000-05-18 00:24:43 +04:00
|
|
|
|
|
|
|
mRefreshURIList->AppendElement(timer); // owning timer ref
|
2000-04-13 07:11:44 +04:00
|
|
|
timer->Init(refreshTimer, aDelay);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::CancelRefreshURITimers()
|
|
|
|
{
|
2000-05-18 00:24:43 +04:00
|
|
|
if (!mRefreshURIList) return NS_OK;
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2000-05-18 00:24:43 +04:00
|
|
|
PRUint32 n;
|
|
|
|
mRefreshURIList->Count(&n);
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2000-05-18 00:24:43 +04:00
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> element;
|
|
|
|
mRefreshURIList->GetElementAt(0, getter_AddRefs(element));
|
|
|
|
nsCOMPtr<nsITimer> timer(do_QueryInterface(element));
|
|
|
|
|
|
|
|
mRefreshURIList->RemoveElementAt(0); // bye bye owning timer ref
|
|
|
|
|
|
|
|
if (timer)
|
2000-04-13 07:11:44 +04:00
|
|
|
timer->Cancel();
|
|
|
|
n--;
|
2000-05-18 00:24:43 +04:00
|
|
|
}
|
2000-04-13 07:11:44 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIContentViewerContainer
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::Embed(nsIContentViewer* aContentViewer,
|
|
|
|
const char * aCommand,
|
|
|
|
nsISupports * aExtraInfo)
|
|
|
|
{
|
2000-06-22 09:36:13 +04:00
|
|
|
#ifdef SH_IN_FRAMES
|
|
|
|
// Save the LayoutHistoryState of the previous document, before
|
|
|
|
// setting up new document
|
|
|
|
PersistLayoutHistoryState();
|
|
|
|
|
|
|
|
nsresult rv = SetupNewViewer(aContentViewer);
|
|
|
|
|
|
|
|
// XXX What if SetupNewViewer fails?
|
|
|
|
|
|
|
|
OSHE = LSHE;
|
2000-07-06 03:10:29 +04:00
|
|
|
/*
|
2000-06-22 09:36:13 +04:00
|
|
|
PRBool updateHistory = PR_TRUE;
|
|
|
|
|
|
|
|
// Determine if this type of load should update history
|
|
|
|
switch(mLoadType)
|
|
|
|
{
|
2000-06-24 03:54:30 +04:00
|
|
|
case nsIDocShellLoadInfo::loadHistory:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadNormal:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassCache:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxy:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxyAndCache:
|
2000-06-22 09:36:13 +04:00
|
|
|
updateHistory = PR_FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-07-06 03:10:29 +04:00
|
|
|
*/
|
|
|
|
if (OSHE) {
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
|
|
|
|
2000-06-22 09:36:13 +04:00
|
|
|
rv = OSHE->GetLayoutHistoryState(getter_AddRefs(layoutState));
|
2000-07-15 01:06:20 +04:00
|
|
|
if (layoutState && (mLoadType != nsIDocShellLoadInfo::loadNormalReplace)) {
|
2000-06-22 09:36:13 +04:00
|
|
|
// This is a SH load. That's why there is a LayoutHistoryState in OSHE
|
2000-07-06 03:10:29 +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
|
|
|
}
|
2000-07-06 03:10:29 +04:00
|
|
|
}
|
2000-06-22 09:36:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
#else
|
2000-02-14 09:40:28 +03:00
|
|
|
return SetupNewViewer(aContentViewer);
|
2000-06-22 09:36:13 +04:00
|
|
|
#endif /* SH_IN_FRAMES */
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-06-20 11:59:45 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell::nsIWebProgressListener
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::OnProgressChange(nsIWebProgress *aProgress, nsIRequest *aRequest,
|
|
|
|
PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress,
|
|
|
|
PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::OnStateChange(nsIWebProgress *aProgress, nsIRequest *aRequest,
|
|
|
|
PRInt32 aStateFlags, nsresult aStatus)
|
|
|
|
{
|
2000-07-01 02:05:32 +04:00
|
|
|
// Clear the LSHE reference to indicate document loading has finished
|
|
|
|
// one way or another.
|
2000-08-25 22:39:46 +04:00
|
|
|
if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_NETWORK)) {
|
2000-07-01 02:05:32 +04:00
|
|
|
LSHE = nsnull;
|
|
|
|
}
|
2000-06-20 11:59:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-07-25 09:45:56 +04:00
|
|
|
nsDocShell::OnLocationChange(nsIWebProgress *aProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
nsIURI *aURI)
|
2000-06-20 11:59:45 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-07-25 09:45:56 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* aMessage)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
//*****************************************************************************
|
|
|
|
|
2000-02-14 09:40:28 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::EnsureContentViewer()
|
|
|
|
{
|
|
|
|
if(mContentViewer)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return CreateAboutBlankContentViewer();
|
|
|
|
}
|
|
|
|
|
2000-03-08 06:58:33 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::EnsureDeviceContext()
|
|
|
|
{
|
|
|
|
if(mDeviceContext)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mDeviceContext = do_CreateInstance(kDeviceContextCID);
|
|
|
|
NS_ENSURE_TRUE(mDeviceContext, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
GetMainWidget(getter_AddRefs(widget));
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
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-02-14 09:40:28 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::CreateAboutBlankContentViewer()
|
|
|
|
{
|
|
|
|
// XXX
|
|
|
|
NS_ERROR("Not Implemented yet");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::CreateContentViewer(const char* aContentType,
|
2000-04-04 04:04:04 +04:00
|
|
|
nsIChannel* aOpenedChannel, nsIStreamListener** aContentHandler)
|
1999-11-12 12:07:28 +03:00
|
|
|
{
|
2000-03-01 01:32:24 +03:00
|
|
|
// Can we check the content type of the current content viewer
|
1999-11-12 12:07:28 +03:00
|
|
|
// and reuse it without destroying it and re-creating it?
|
|
|
|
|
2000-03-01 01:32:24 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(mLoadCookie));
|
|
|
|
NS_ENSURE_TRUE(loadGroup, NS_ERROR_FAILURE);
|
1999-11-12 12:07:28 +03:00
|
|
|
|
|
|
|
// Instantiate the content viewer object
|
2000-03-01 01:32:24 +03:00
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
2000-04-04 04:04:04 +04:00
|
|
|
if(NS_FAILED(NewContentViewerObj(aContentType, aOpenedChannel, loadGroup,
|
|
|
|
aContentHandler, getter_AddRefs(viewer))))
|
2000-03-01 01:32:24 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-11-12 12:07:28 +03:00
|
|
|
|
2000-03-01 01:32:24 +03:00
|
|
|
// 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);
|
1999-11-12 12:07:28 +03:00
|
|
|
|
2000-03-01 01:32:24 +03:00
|
|
|
if(currentLoadGroup.get() != loadGroup.get())
|
|
|
|
{
|
|
|
|
nsLoadFlags loadAttribs = 0;
|
|
|
|
|
|
|
|
//Cancel any URIs that are currently loading...
|
|
|
|
/// XXX: Need to do this eventually Stop();
|
|
|
|
//
|
|
|
|
// Retarget the document to this loadgroup...
|
|
|
|
//
|
|
|
|
if(currentLoadGroup)
|
|
|
|
currentLoadGroup->RemoveChannel(aOpenedChannel, nsnull, nsnull, nsnull);
|
|
|
|
|
|
|
|
aOpenedChannel->SetLoadGroup(loadGroup);
|
|
|
|
|
|
|
|
// Mark the channel as being a document URI...
|
|
|
|
aOpenedChannel->GetLoadAttributes(&loadAttribs);
|
|
|
|
loadAttribs |= nsIChannel::LOAD_DOCUMENT_URI;
|
|
|
|
|
|
|
|
aOpenedChannel->SetLoadAttributes(loadAttribs);
|
|
|
|
|
|
|
|
loadGroup->AddChannel(aOpenedChannel, nsnull);
|
|
|
|
}
|
2000-06-30 01:48:18 +04:00
|
|
|
#ifdef SH_IN_FRAMES
|
|
|
|
NS_ENSURE_SUCCESS(Embed(viewer, "", (nsISupports *) nsnull), NS_ERROR_FAILURE);
|
|
|
|
#else
|
2000-03-01 01:32:24 +03:00
|
|
|
NS_ENSURE_SUCCESS(SetupNewViewer(viewer), NS_ERROR_FAILURE);
|
2000-06-30 01:48:18 +04:00
|
|
|
#endif /* SH_IN_FRAMES */
|
|
|
|
|
2000-03-07 09:02:04 +03:00
|
|
|
mEODForCurrentDocument = PR_FALSE; // clear the current flag
|
2000-03-01 01:32:24 +03:00
|
|
|
return NS_OK;
|
1999-11-12 12:07:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDocShell::NewContentViewerObj(const char* aContentType,
|
2000-04-04 04:04:04 +04:00
|
|
|
nsIChannel* aOpenedChannel, nsILoadGroup* aLoadGroup,
|
|
|
|
nsIStreamListener** aContentHandler, nsIContentViewer** aViewer)
|
1999-11-12 12:07:28 +03:00
|
|
|
{
|
2000-08-17 23:16:39 +04:00
|
|
|
//XXX This should probably be some category thing....
|
|
|
|
char id[256];
|
|
|
|
PR_snprintf(id, sizeof(id), NS_DOCUMENT_LOADER_FACTORY_PROGID_PREFIX "%s/%s",
|
|
|
|
(const char*)((viewSource == mViewMode) ? "view-source" : "view"),
|
|
|
|
aContentType);
|
|
|
|
|
|
|
|
// Create an instance of the document-loader-factory
|
|
|
|
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory(do_CreateInstance(id));
|
|
|
|
if(!docLoaderFactory)
|
|
|
|
{
|
|
|
|
// try again after loading plugins
|
|
|
|
nsresult err;
|
|
|
|
NS_WITH_SERVICE(nsIPluginHost, pluginHost, kPluginManagerCID, &err);
|
|
|
|
|
|
|
|
if(NS_FAILED(err))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
pluginHost->LoadPlugins();
|
|
|
|
|
|
|
|
docLoaderFactory = do_CreateInstance(id);
|
1999-11-12 12:07:28 +03:00
|
|
|
|
2000-08-17 23:16:39 +04:00
|
|
|
if(!docLoaderFactory)
|
2000-03-01 01:32:24 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-08-17 23:16:39 +04:00
|
|
|
}
|
1999-11-12 12:07:28 +03:00
|
|
|
|
2000-08-17 23:16:39 +04:00
|
|
|
// Now create an instance of the content viewer
|
|
|
|
NS_ENSURE_SUCCESS(docLoaderFactory->CreateInstance(
|
|
|
|
(viewSource == mViewMode) ? "view-source" : "view",
|
|
|
|
aOpenedChannel, aLoadGroup, aContentType,
|
|
|
|
NS_STATIC_CAST(nsIContentViewerContainer*, this), nsnull,
|
|
|
|
aContentHandler, aViewer), NS_ERROR_FAILURE);
|
1999-11-12 12:07:28 +03:00
|
|
|
|
2000-08-17 23:16:39 +04:00
|
|
|
(*aViewer)->SetContainer(NS_STATIC_CAST(nsIContentViewerContainer*, this));
|
2000-03-01 01:32:24 +03:00
|
|
|
|
2000-08-17 23:16:39 +04:00
|
|
|
return NS_OK;
|
1999-11-12 12:07:28 +03:00
|
|
|
}
|
|
|
|
|
2000-02-14 09:40:28 +03: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;
|
|
|
|
|
|
|
|
// This will get the size from the current content viewer or from the
|
|
|
|
// Init settings
|
|
|
|
GetPositionAndSize(&x, &y, &cx, &cy);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
|
|
|
NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parentAsItem)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mContentViewer = nsnull;
|
|
|
|
// End copying block (Don't hold content/document viewer ref beyond here!!)
|
|
|
|
|
|
|
|
if(mScriptContext)
|
|
|
|
mScriptContext->GC();
|
|
|
|
|
|
|
|
mContentViewer = aNewViewer;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
NS_ENSURE_SUCCESS(GetMainWidget(getter_AddRefs(widget)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsRect bounds(x, y, cx, cy);
|
2000-03-08 06:58:33 +03:00
|
|
|
NS_ENSURE_SUCCESS(EnsureDeviceContext(), NS_ERROR_FAILURE);
|
2000-03-11 03:53:48 +03:00
|
|
|
if(NS_FAILED(mContentViewer->Init(widget,
|
|
|
|
mDeviceContext, bounds)))
|
2000-02-14 09:40:28 +03:00
|
|
|
{
|
|
|
|
mContentViewer = nsnull;
|
|
|
|
NS_ERROR("ContentViewer Initialization failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-30 01:48:18 +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(...)
|
2000-06-30 01:48:18 +04:00
|
|
|
#ifndef SH_IN_FRAMES
|
2000-05-27 01:03:34 +04:00
|
|
|
// Restore up any HistoryLayoutState this page might have.
|
|
|
|
nsresult rv = NS_OK;
|
2000-06-16 02:08:25 +04:00
|
|
|
PRBool updateHistory = PR_TRUE;
|
|
|
|
|
|
|
|
// Determine if this type of load should update history
|
|
|
|
switch(mLoadType)
|
|
|
|
{
|
2000-06-22 11:22:23 +04:00
|
|
|
case nsIDocShellLoadInfo::loadHistory:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadNormal:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassCache:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxy:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxyAndCache:
|
2000-06-16 02:08:25 +04:00
|
|
|
updateHistory = PR_FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mSessionHistory && !updateHistory) {
|
2000-05-27 01:03:34 +04:00
|
|
|
PRInt32 index = 0;
|
|
|
|
mSessionHistory->GetIndex(&index);
|
|
|
|
if (-1 < index) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
|
|
|
rv = mSessionHistory->GetEntryAtIndex(index, PR_FALSE, getter_AddRefs(entry));
|
|
|
|
if (NS_SUCCEEDED(rv) && entry) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
|
|
|
rv = entry->GetLayoutHistoryState(getter_AddRefs(layoutState));
|
|
|
|
if (NS_SUCCEEDED(rv) && layoutState) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
rv = GetPresShell(getter_AddRefs(presShell));
|
|
|
|
if (NS_SUCCEEDED(rv) && presShell) {
|
|
|
|
|
|
|
|
rv = presShell->SetHistoryState(layoutState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-06-30 01:48:18 +04:00
|
|
|
#endif /* SH_IN_FRAMES */
|
2000-02-14 09:40:28 +03:00
|
|
|
|
|
|
|
mContentViewer->Show();
|
|
|
|
|
|
|
|
// Now that we have switched documents, forget all of our children
|
|
|
|
DestroyChildren();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell: Site Loading
|
|
|
|
//*****************************************************************************
|
2000-06-22 09:36:13 +04:00
|
|
|
#ifdef SH_IN_FRAMES
|
|
|
|
NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer,
|
2000-08-31 09:53:32 +04:00
|
|
|
nsISupports* aOwner, PRBool aInheritOwner,
|
|
|
|
const char* aWindowTarget, nsIInputStream* aPostData,
|
2000-06-22 11:22:23 +04:00
|
|
|
nsDocShellInfoLoadType aLoadType, nsISHEntry * aSHEntry)
|
2000-06-22 09:36:13 +04:00
|
|
|
#else
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer,
|
2000-08-31 09:53:32 +04:00
|
|
|
nsISupports* aOwner, PRBool aInheritOwner,
|
|
|
|
const char* aWindowTarget, nsIInputStream* aPostData,
|
2000-06-22 11:22:23 +04:00
|
|
|
nsDocShellInfoLoadType aLoadType)
|
2000-06-22 09:36:13 +04:00
|
|
|
#endif
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2000-06-06 02:13:52 +04:00
|
|
|
// Check to see if the new URI is an anchor in the existing document.
|
2000-06-22 11:22:23 +04:00
|
|
|
if (aLoadType == nsIDocShellLoadInfo::loadNormal ||
|
|
|
|
aLoadType == nsIDocShellLoadInfo::loadNormalReplace ||
|
|
|
|
aLoadType == nsIDocShellLoadInfo::loadHistory ||
|
|
|
|
aLoadType == nsIDocShellLoadInfo::loadLink)
|
2000-05-23 04:52:59 +04:00
|
|
|
{
|
2000-06-06 02:13:52 +04:00
|
|
|
PRBool wasAnchor = PR_FALSE;
|
|
|
|
NS_ENSURE_SUCCESS(ScrollIfAnchor(aURI, &wasAnchor), NS_ERROR_FAILURE);
|
|
|
|
if(wasAnchor)
|
|
|
|
{
|
|
|
|
mLoadType = aLoadType;
|
|
|
|
OnNewURI(aURI, nsnull, mLoadType);
|
2000-08-18 22:33:12 +04:00
|
|
|
/* Clear out LSHE so that further anchor visits get
|
|
|
|
* recorded in SH and SH won't misbehave. i think this is
|
|
|
|
* sufficient for now to take care of any Sh mis-behaviors.
|
|
|
|
* Other option is to call OnEndDocumentLoad() with a dummy channel
|
|
|
|
* and uriloader and letting everybody know that we are done
|
|
|
|
* with this target load. I don't think that is necessay
|
|
|
|
* considering that nsIDocLoaderObserver is on its way out.
|
|
|
|
* Hopefully the following is sufficient.
|
|
|
|
*/
|
|
|
|
LSHE = nsnull;
|
|
|
|
/* 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<nsISHEntry> shEntry;
|
|
|
|
mSessionHistory->GetEntryAtIndex(index, PR_FALSE, getter_AddRefs(shEntry));
|
|
|
|
if(shEntry)
|
|
|
|
shEntry->SetTitle(mTitle.GetUnicode());
|
|
|
|
}
|
|
|
|
|
2000-06-06 02:13:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
2000-05-24 06:32:13 +04:00
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
NS_ENSURE_SUCCESS(StopLoad(), NS_ERROR_FAILURE);
|
2000-05-23 04:52:59 +04:00
|
|
|
// Cancel any timers that were set for this loader.
|
|
|
|
CancelRefreshURITimers();
|
2000-04-04 04:04:04 +04:00
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
mLoadType = aLoadType;
|
2000-06-22 09:36:13 +04:00
|
|
|
#ifdef SH_IN_FRAMES
|
2000-07-01 02:05:32 +04:00
|
|
|
// XXX: I think that LSHE should *always* be set to the new Entry.
|
|
|
|
// Even if it is null...
|
|
|
|
// if (aSHEntry)
|
2000-06-22 09:36:13 +04:00
|
|
|
LSHE = aSHEntry;
|
|
|
|
#endif
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
nsURILoadCommand loadCmd = nsIURILoader::viewNormal;
|
2000-06-22 11:22:23 +04:00
|
|
|
if(nsIDocShellLoadInfo::loadLink == aLoadType)
|
2000-05-23 04:52:59 +04:00
|
|
|
loadCmd = nsIURILoader::viewUserClick;
|
2000-08-31 09:53:32 +04:00
|
|
|
NS_ENSURE_SUCCESS(DoURILoad(aURI, aReferrer, aOwner, aInheritOwner,
|
|
|
|
loadCmd, aWindowTarget, aPostData), NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
return NS_OK;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2000-04-04 04:04:04 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::CreateFixupURI(const PRUnichar* aStringURI,
|
|
|
|
nsIURI** aURI)
|
|
|
|
{
|
2000-04-12 03:52:42 +04:00
|
|
|
*aURI = nsnull;
|
|
|
|
nsAutoString uriString(aStringURI);
|
|
|
|
uriString.Trim(" "); // Cleanup the empty spaces that might be on each end.
|
|
|
|
|
2000-08-29 02:15:03 +04:00
|
|
|
// Eliminate embedded newlines, which single-line text fields now allow:
|
|
|
|
uriString.StripChars("\r\n");
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
// XXX nasty hack to check for the view-source: prefix
|
|
|
|
//
|
|
|
|
// The long term way and probably CORRECT way to do this is to write a
|
|
|
|
// protocol handler for the view-source: schema and have that feed back a
|
|
|
|
// content type that the docshell recognizes to mean to use viewSource mode.
|
|
|
|
//
|
|
|
|
const char cViewSource[] = "view-source:";
|
|
|
|
if (uriString.EqualsWithConversion(cViewSource, PR_TRUE, sizeof(cViewSource) - 1))
|
|
|
|
{
|
|
|
|
// Strip the view-source: prefix and set the docshell's view mode
|
|
|
|
nsAutoString newUri;
|
|
|
|
uriString.Mid(newUri, sizeof(cViewSource) - 1, -1);
|
|
|
|
uriString = newUri;
|
|
|
|
mLastViewMode = mViewMode;
|
|
|
|
mViewMode = viewSource;
|
|
|
|
mRestoreViewMode = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (mRestoreViewMode)
|
|
|
|
{
|
|
|
|
mRestoreViewMode = PR_FALSE;
|
|
|
|
mViewMode = mLastViewMode;
|
|
|
|
}
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
// Just try to create an URL out of it
|
2000-08-20 02:35:49 +04:00
|
|
|
NS_NewURI(aURI, uriString, nsnull);
|
2000-04-12 03:52:42 +04:00
|
|
|
if(*aURI)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
// Check for if it is a file URL
|
|
|
|
FileURIFixup(uriString.GetUnicode(), aURI);
|
2000-04-12 03:52:42 +04:00
|
|
|
if(*aURI)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// See if it is a keyword
|
|
|
|
KeywordURIFixup(uriString.GetUnicode(), aURI);
|
|
|
|
if(*aURI)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// See if a protocol needs to be added
|
2000-07-15 02:21:52 +04:00
|
|
|
PRInt32 checkprotocol = uriString.Find("://",0);
|
|
|
|
// if no scheme (protocol) is found, assume http or ftp.
|
|
|
|
if (checkprotocol == -1) {
|
|
|
|
// find host name
|
|
|
|
PRInt32 hostPos = uriString.FindCharInSet("./:");
|
|
|
|
if (hostPos == -1)
|
|
|
|
hostPos = uriString.Length();
|
|
|
|
|
|
|
|
// extract host name
|
|
|
|
nsAutoString hostSpec;
|
|
|
|
uriString.Left(hostSpec, hostPos);
|
|
|
|
|
|
|
|
// insert url spec corresponding to host name
|
|
|
|
if (hostSpec.EqualsIgnoreCase("ftp"))
|
|
|
|
uriString.InsertWithConversion("ftp://", 0, 6);
|
|
|
|
else
|
|
|
|
uriString.InsertWithConversion("http://", 0, 7);
|
|
|
|
} // end if checkprotocol
|
2000-08-20 02:35:49 +04:00
|
|
|
return NS_NewURI(aURI, uriString, nsnull);
|
2000-04-12 03:52:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::FileURIFixup(const PRUnichar* aStringURI,
|
|
|
|
nsIURI** aURI)
|
|
|
|
{
|
2000-06-22 02:36:50 +04:00
|
|
|
nsAutoString uriSpecIn(aStringURI);
|
|
|
|
nsAutoString uriSpecOut(aStringURI);
|
2000-04-12 03:52:42 +04:00
|
|
|
|
2000-06-22 02:36:50 +04:00
|
|
|
ConvertFileToStringURI(uriSpecIn, uriSpecOut);
|
2000-04-12 14:06:58 +04:00
|
|
|
|
2000-06-22 02:36:50 +04:00
|
|
|
if(0 == uriSpecOut.Find("file:", 0))
|
2000-04-12 14:06:58 +04:00
|
|
|
{
|
|
|
|
// if this is file url, we need to convert the URI
|
|
|
|
// from Unicode to the FS charset
|
|
|
|
nsCAutoString inFSCharset;
|
2000-06-22 02:36:50 +04:00
|
|
|
NS_ENSURE_SUCCESS(ConvertStringURIToFileCharset(uriSpecOut, inFSCharset),
|
2000-04-12 14:06:58 +04:00
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if(NS_SUCCEEDED(NS_NewURI(aURI, inFSCharset.GetBuffer(), nsnull)))
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-04-12 03:52:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FILE_PROTOCOL "file://"
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::ConvertFileToStringURI(nsString& aIn, nsString& aOut)
|
|
|
|
{
|
|
|
|
#ifdef XP_PC
|
2000-04-16 11:11:43 +04:00
|
|
|
// Check for \ in the url-string or just a drive (PC)
|
|
|
|
if(kNotFound != aIn.FindChar(PRUnichar('\\')) || ((aIn.Length() == 2 ) && (aIn.Last() == PRUnichar(':') || aIn.Last() == PRUnichar('|'))))
|
2000-04-12 03:52:42 +04:00
|
|
|
{
|
|
|
|
#elif XP_UNIX
|
|
|
|
// Check if it starts with / or \ (UNIX)
|
|
|
|
const PRUnichar * up = aIn.GetUnicode();
|
|
|
|
if((PRUnichar('/') == *up) || (PRUnichar('\\') == *up))
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
// Do nothing (All others for now)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_PC
|
|
|
|
// Translate '\' to '/'
|
|
|
|
aOut.ReplaceChar(PRUnichar('\\'), PRUnichar('/'));
|
|
|
|
aOut.ReplaceChar(PRUnichar(':'), PRUnichar('|'));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Build the file URL
|
2000-04-17 15:24:01 +04:00
|
|
|
aOut.InsertWithConversion(FILE_PROTOCOL,0);
|
2000-04-12 03:52:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::ConvertStringURIToFileCharset(nsString& aIn,
|
|
|
|
nsCString& aOut)
|
|
|
|
{
|
|
|
|
aOut = "";
|
|
|
|
// for file url, we need to convert the nsString to the file system
|
|
|
|
// charset before we pass to NS_NewURI
|
2000-04-17 15:24:01 +04:00
|
|
|
static nsAutoString fsCharset;
|
2000-04-12 03:52:42 +04:00
|
|
|
// find out the file system charset first
|
|
|
|
if(0 == fsCharset.Length())
|
|
|
|
{
|
2000-04-17 15:24:01 +04:00
|
|
|
fsCharset.AssignWithConversion("ISO-8859-1"); // set the fallback first.
|
2000-04-12 03:52:42 +04:00
|
|
|
nsCOMPtr<nsIPlatformCharset> plat(do_GetService(kPlatformCharsetCID));
|
|
|
|
NS_ENSURE_TRUE(plat, NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(plat->GetCharset(kPlatformCharsetSel_FileName, fsCharset),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
// We probably should cache ccm here.
|
|
|
|
// get a charset converter from the manager
|
|
|
|
nsCOMPtr<nsICharsetConverterManager> ccm(do_GetService(kCharsetConverterManagerCID));
|
|
|
|
NS_ENSURE_TRUE(ccm, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUnicodeEncoder> fsEncoder;
|
|
|
|
NS_ENSURE_SUCCESS(ccm->GetUnicodeEncoder(&fsCharset,
|
|
|
|
getter_AddRefs(fsEncoder)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRInt32 bufLen = 0;
|
|
|
|
NS_ENSURE_SUCCESS(fsEncoder->GetMaxLength(aIn.GetUnicode(), aIn.Length(),
|
|
|
|
&bufLen), NS_ERROR_FAILURE);
|
|
|
|
aOut.SetCapacity(bufLen+1);
|
|
|
|
PRInt32 srclen = aIn.Length();
|
|
|
|
NS_ENSURE_SUCCESS(fsEncoder->Convert(aIn.GetUnicode(), &srclen,
|
|
|
|
(char*)aOut.GetBuffer(), &bufLen), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
((char*)aOut.GetBuffer())[bufLen]='\0';
|
|
|
|
aOut.SetLength(bufLen);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::KeywordURIFixup(const PRUnichar* aStringURI,
|
|
|
|
nsIURI** aURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(mPrefs);
|
|
|
|
|
|
|
|
PRBool keywordsEnabled = PR_FALSE;
|
|
|
|
NS_ENSURE_SUCCESS(mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if(!keywordsEnabled)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// These are keyword formatted strings
|
|
|
|
// "what is mozilla"
|
|
|
|
// "what is mozilla?"
|
|
|
|
// "?mozilla"
|
|
|
|
// "?What is mozilla"
|
|
|
|
|
|
|
|
// These are not keyword formatted strings
|
|
|
|
// "www.blah.com" - anything with a dot in it
|
|
|
|
// "nonQualifiedHost:80" - anything with a colon in it
|
|
|
|
// "nonQualifiedHost?"
|
|
|
|
// "nonQualifiedHost?args"
|
|
|
|
// "nonQualifiedHost?some args"
|
|
|
|
|
|
|
|
nsAutoString uriString(aStringURI);
|
|
|
|
if(uriString.FindChar('.') == -1 && uriString.FindChar(':') == -1)
|
|
|
|
{
|
|
|
|
PRInt32 qMarkLoc = uriString.FindChar('?');
|
|
|
|
PRInt32 spaceLoc = uriString.FindChar(' ');
|
|
|
|
|
|
|
|
PRBool keyword = PR_FALSE;
|
|
|
|
if(qMarkLoc == 0)
|
|
|
|
keyword = PR_TRUE;
|
|
|
|
else if((spaceLoc > 0) && ((qMarkLoc == -1) || (spaceLoc < qMarkLoc)))
|
|
|
|
keyword = PR_TRUE;
|
|
|
|
|
|
|
|
if(keyword)
|
|
|
|
{
|
|
|
|
nsCAutoString keywordSpec("keyword:");
|
|
|
|
char *utf8Spec = uriString.ToNewUTF8String();
|
|
|
|
if(utf8Spec)
|
|
|
|
{
|
|
|
|
char* escapedUTF8Spec = nsEscape(utf8Spec, url_Path);
|
|
|
|
if(escapedUTF8Spec)
|
|
|
|
{
|
|
|
|
keywordSpec.Append(escapedUTF8Spec);
|
|
|
|
NS_NewURI(aURI, keywordSpec.GetBuffer(), nsnull);
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(escapedUTF8Spec);
|
2000-04-12 03:52:42 +04:00
|
|
|
} // escapedUTF8Spec
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(utf8Spec);
|
2000-04-12 03:52:42 +04:00
|
|
|
} // utf8Spec
|
|
|
|
} // keyword
|
|
|
|
} // FindChar
|
|
|
|
|
|
|
|
if(*aURI)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-04-04 04:04:04 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-06-14 03:56:30 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::GetCurrentDocumentOwner(nsISupports** aOwner)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
*aOwner = nsnull;
|
2000-08-10 00:08:54 +04:00
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
//-- Get the current document
|
|
|
|
if (mContentViewer)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(mContentViewer));
|
|
|
|
if (!docViewer) return NS_ERROR_FAILURE;
|
|
|
|
rv = docViewer->GetDocument(*getter_AddRefs(document));
|
|
|
|
}
|
|
|
|
else //-- If there's no document loaded yet, look at the parent (frameset)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
rv = GetSameTypeParent(getter_AddRefs(parentItem));
|
|
|
|
if (NS_FAILED(rv) || !parentItem) return rv;
|
|
|
|
nsCOMPtr<nsIDOMWindow> parentWindow(do_GetInterface(parentItem));
|
|
|
|
if (!parentWindow) return NS_OK;
|
|
|
|
nsCOMPtr<nsIDOMDocument> parentDomDoc;
|
|
|
|
rv = parentWindow->GetDocument(getter_AddRefs(parentDomDoc));
|
|
|
|
if (!parentDomDoc) return NS_OK;
|
|
|
|
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));
|
2000-06-14 03:56:30 +04:00
|
|
|
if (NS_FAILED(rv) || !principal) return NS_ERROR_FAILURE;
|
|
|
|
rv = principal->QueryInterface(NS_GET_IID(nsISupports),(void**)aOwner);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI,
|
2000-08-31 09:53:32 +04:00
|
|
|
nsISupports* aOwner, PRBool aInheritOwner, nsURILoadCommand aLoadCmd,
|
|
|
|
const char* aWindowTarget, nsIInputStream* aPostData)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2000-08-31 09:53:32 +04:00
|
|
|
static const char jsSchemeName[] = "javascript";
|
2000-06-23 08:44:36 +04:00
|
|
|
// 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
|
|
|
|
if (mUseExternalProtocolHandler && aLoadCmd == nsIURILoader::viewUserClick)
|
|
|
|
{
|
|
|
|
nsXPIDLCString urlScheme;
|
|
|
|
aURI->GetScheme(getter_Copies(urlScheme));
|
2000-08-09 06:30:58 +04:00
|
|
|
// don't do it for javascript urls!
|
2000-08-31 09:53:32 +04:00
|
|
|
if (urlScheme && nsCRT::strcasecmp(jsSchemeName, urlScheme))
|
2000-08-09 06:30:58 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtService (do_GetService(NS_EXTERNALPROTOCOLSERVICE_PROGID));
|
|
|
|
PRBool haveHandler = PR_FALSE;
|
|
|
|
extProtService->ExternalProtocolHandlerExists(urlScheme, &haveHandler);
|
|
|
|
if (haveHandler)
|
|
|
|
return extProtService->LoadUrl(aURI);
|
|
|
|
}
|
2000-06-23 08:44:36 +04:00
|
|
|
}
|
2000-04-12 03:52:42 +04:00
|
|
|
nsCOMPtr<nsIURILoader> uriLoader(do_GetService(NS_URI_LOADER_PROGID));
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// we need to get the load group from our load cookie so we can pass it into open uri...
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
NS_ENSURE_SUCCESS(
|
|
|
|
uriLoader->GetLoadGroupForContext(NS_STATIC_CAST(nsIDocShell*, this),
|
|
|
|
getter_AddRefs(loadGroup)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// open a channel for the url
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2000-04-12 03:52:42 +04:00
|
|
|
nsresult rv;
|
|
|
|
rv = NS_OpenURI(getter_AddRefs(channel), aURI, nsnull, loadGroup,
|
|
|
|
NS_STATIC_CAST(nsIInterfaceRequestor*, this));
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
if(NS_ERROR_DOM_RETVAL_UNDEFINED == rv) // if causing the channel changed the
|
|
|
|
return NS_OK; // dom and there is nothing else to do
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-06-14 03:56:30 +04:00
|
|
|
channel->SetOriginalURI(aURI);
|
2000-04-12 03:52:42 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if(httpChannel)
|
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
{
|
2000-05-23 04:52:59 +04:00
|
|
|
// 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.
|
|
|
|
nsCOMPtr<nsIRandomAccessStore> postDataRandomAccess(do_QueryInterface(aPostData));
|
|
|
|
if (postDataRandomAccess)
|
|
|
|
{
|
|
|
|
postDataRandomAccess->Seek(PR_SEEK_SET, 0);
|
|
|
|
}
|
|
|
|
|
2000-05-03 04:21:51 +04:00
|
|
|
nsCOMPtr<nsIAtom> method = NS_NewAtom ("POST");
|
|
|
|
httpChannel->SetRequestMethod(method);
|
2000-04-22 04:40:21 +04:00
|
|
|
httpChannel->SetUploadStream(aPostData);
|
2000-04-12 03:52:42 +04:00
|
|
|
}
|
|
|
|
// Set the referrer explicitly
|
|
|
|
if(aReferrerURI) // Referrer is currenly only set for link clicks here.
|
|
|
|
httpChannel->SetReferrer(aReferrerURI,
|
|
|
|
nsIHTTPChannel::REFERRER_LINK_CLICK);
|
|
|
|
}
|
2000-06-14 03:56:30 +04:00
|
|
|
else
|
|
|
|
{
|
2000-08-31 09:53:32 +04:00
|
|
|
// iff we are dealing with a JS or a data url, we may need an inherited owner.
|
|
|
|
// This is either aOwner or, if aInheritOwner is true, the owner of the
|
|
|
|
// current document.
|
|
|
|
nsCOMPtr<nsISupports> owner = aOwner;
|
|
|
|
PRBool isJSOrData = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIStreamIOChannel> ioChannel(do_QueryInterface(channel));
|
|
|
|
if(ioChannel) // Might be a javascript: URL load, need to set owner
|
|
|
|
{
|
|
|
|
nsXPIDLCString scheme;
|
|
|
|
aURI->GetScheme(getter_Copies(scheme));
|
|
|
|
isJSOrData = (PL_strcasecmp(scheme, jsSchemeName) == 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Also set owner for data: URLs
|
|
|
|
nsCOMPtr<nsIDataChannel> dataChannel(do_QueryInterface(channel));
|
|
|
|
isJSOrData = (dataChannel != nsnull);
|
|
|
|
}
|
|
|
|
if (isJSOrData)
|
|
|
|
{
|
|
|
|
if (aInheritOwner && !owner)
|
|
|
|
GetCurrentDocumentOwner(getter_AddRefs(owner));
|
2000-07-12 09:06:28 +04:00
|
|
|
channel->SetOwner(owner);
|
2000-08-31 09:53:32 +04:00
|
|
|
}
|
2000-06-14 03:56:30 +04:00
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2000-07-01 03:39:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(DoChannelLoad(channel, aLoadCmd, aWindowTarget, uriLoader), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::DoChannelLoad(nsIChannel *aChannel, nsURILoadCommand aLoadCmd,
|
|
|
|
const char* aWindowTarget, nsIURILoader *aURILoader)
|
|
|
|
{
|
|
|
|
// Mark the channel as being a document URI...
|
|
|
|
nsLoadFlags loadAttribs = 0;
|
|
|
|
(void)aChannel->GetLoadAttributes(&loadAttribs);
|
|
|
|
loadAttribs |= nsIChannel::LOAD_DOCUMENT_URI;
|
|
|
|
|
|
|
|
switch ( mLoadType )
|
|
|
|
{
|
|
|
|
case nsIDocShellLoadInfo::loadHistory:
|
|
|
|
loadAttribs |= nsIChannel::VALIDATE_NEVER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDocShellLoadInfo::loadReloadNormal:
|
|
|
|
loadAttribs |= nsIChannel::FORCE_VALIDATION;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxyAndCache:
|
|
|
|
loadAttribs |= nsIChannel::FORCE_RELOAD;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadRefresh:
|
|
|
|
loadAttribs |= nsIChannel::FORCE_RELOAD;
|
|
|
|
break;
|
|
|
|
case nsIDocShellLoadInfo::loadNormal:
|
2000-07-11 19:00:59 +04:00
|
|
|
case nsIDocShellLoadInfo::loadLink:
|
2000-07-01 03:39:30 +04:00
|
|
|
// Set cache checking flags
|
|
|
|
if ( mPrefs )
|
|
|
|
{
|
|
|
|
PRInt32 prefSetting;
|
|
|
|
if ( NS_SUCCEEDED( mPrefs->GetIntPref( "browser.cache.check_doc_frequency" , &prefSetting) ) )
|
|
|
|
{
|
|
|
|
switch ( prefSetting )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
loadAttribs |= nsIChannel::VALIDATE_ONCE_PER_SESSION;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
loadAttribs |= nsIChannel::VALIDATE_ALWAYS;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
loadAttribs |= nsIChannel::VALIDATE_NEVER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-07-08 01:43:16 +04:00
|
|
|
(void) aChannel->SetLoadAttributes(loadAttribs);
|
2000-07-01 03:39:30 +04:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(aURILoader->OpenURI(aChannel, aLoadCmd,
|
2000-04-04 04:04:04 +04:00
|
|
|
aWindowTarget, NS_STATIC_CAST(nsIDocShell*, this)), NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
if (aURI == nsnull || aWasAnchor == nsnull)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aWasAnchor = PR_FALSE;
|
|
|
|
|
|
|
|
if (!mCurrentURI)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// NOTE: we assume URIs are absolute for comparison purposes
|
|
|
|
|
|
|
|
nsXPIDLCString currentSpec;
|
|
|
|
NS_ENSURE_SUCCESS(mCurrentURI->GetSpec(getter_Copies(currentSpec)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
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
|
|
|
|
nsAutoString sNew; sNew.AssignWithConversion(newSpec);
|
|
|
|
nsAutoString sNewLeft;
|
|
|
|
nsAutoString sNewRef;
|
|
|
|
PRInt32 hashNew = sNew.FindChar(kHash);
|
|
|
|
if (hashNew == 0)
|
|
|
|
{
|
|
|
|
return NS_OK; // Strange URI
|
|
|
|
}
|
|
|
|
else if (hashNew > 0)
|
|
|
|
{
|
|
|
|
sNew.Left(sNewLeft, hashNew);
|
|
|
|
sNew.Right(sNewRef, sNew.Length() - hashNew - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sNewLeft = sNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split the current URI in a left and right part
|
|
|
|
nsAutoString sCurrent; sCurrent.AssignWithConversion(currentSpec);
|
|
|
|
nsAutoString sCurrentLeft;
|
|
|
|
PRInt32 hashCurrent = sCurrent.FindChar(kHash);
|
|
|
|
if (hashCurrent == 0)
|
|
|
|
{
|
|
|
|
return NS_OK; // Strange URI
|
|
|
|
}
|
|
|
|
else if (hashCurrent > 0)
|
|
|
|
{
|
|
|
|
sCurrent.Left(sCurrentLeft, hashCurrent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sCurrentLeft = sCurrent;
|
|
|
|
}
|
|
|
|
|
2000-05-24 02:36:47 +04:00
|
|
|
// Exit when there are no anchors
|
|
|
|
if (hashNew <= 0 && hashCurrent <= 0)
|
|
|
|
{
|
|
|
|
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.
|
2000-05-23 04:52:59 +04:00
|
|
|
|
|
|
|
if (sCurrentLeft.CompareWithConversion(sNewLeft, PR_FALSE, -1) != 0)
|
|
|
|
{
|
|
|
|
return NS_OK; // URIs not the same
|
|
|
|
}
|
|
|
|
|
|
|
|
// Both the new and current URIs refer to the same page. We can now
|
|
|
|
// browse to the hash stored in the new URI.
|
|
|
|
|
|
|
|
if (!sNewRef.IsEmpty())
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> shell = nsnull;
|
|
|
|
rv = GetPresShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell)
|
|
|
|
{
|
2000-05-24 21:18:10 +04:00
|
|
|
*aWasAnchor = PR_TRUE;
|
2000-08-18 11:31:40 +04:00
|
|
|
|
|
|
|
char *str = sNewRef.ToNewCString();
|
|
|
|
|
|
|
|
// nsUnescape modifies the string that is passed into it.
|
|
|
|
nsUnescape(str);
|
|
|
|
|
|
|
|
sNewRef.AssignWithConversion(str);
|
|
|
|
|
|
|
|
nsMemory::Free(str);
|
|
|
|
|
2000-05-23 04:52:59 +04:00
|
|
|
rv = shell->GoToAnchor(sNewRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 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
|
2000-06-22 11:22:23 +04:00
|
|
|
nsDocShell::OnNewURI(nsIURI *aURI, nsIChannel *aChannel, nsDocShellInfoLoadType 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-03-31 02:38:32 +04:00
|
|
|
|
2000-05-24 02:36:47 +04:00
|
|
|
// Determine if this type of load should update history
|
|
|
|
switch(aLoadType)
|
|
|
|
{
|
2000-06-22 11:22:23 +04:00
|
|
|
case nsIDocShellLoadInfo::loadHistory:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadNormal:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassCache:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxy:
|
|
|
|
case nsIDocShellLoadInfo::loadReloadBypassProxyAndCache:
|
2000-05-24 02:36:47 +04:00
|
|
|
updateHistory = PR_FALSE;
|
|
|
|
break;
|
|
|
|
|
2000-06-22 11:22:23 +04:00
|
|
|
case nsIDocShellLoadInfo::loadNormal:
|
|
|
|
case nsIDocShellLoadInfo::loadRefresh:
|
|
|
|
case nsIDocShellLoadInfo::loadNormalReplace:
|
|
|
|
case nsIDocShellLoadInfo::loadLink:
|
2000-05-24 02:36:47 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ERROR("Need to update case");
|
|
|
|
break;
|
|
|
|
}
|
2000-06-24 03:54:30 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
if (updateHistory) { // Page load not from SH
|
|
|
|
// Update session history if necessary...
|
|
|
|
if (!LSHE && (mItemType == typeContent)) {
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
(void) AddToSessionHistory(aURI, aChannel, getter_AddRefs(LSHE));
|
2000-05-24 02:36:47 +04:00
|
|
|
}
|
2000-06-22 09:36:13 +04:00
|
|
|
|
2000-07-08 09:17:49 +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-07-08 09:17:49 +04:00
|
|
|
}
|
2000-03-25 06:43:27 +03:00
|
|
|
|
2000-05-24 06:32:13 +04:00
|
|
|
SetCurrentURI(aURI);
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(aChannel));
|
|
|
|
if(httpChannel)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> referrer;
|
|
|
|
httpChannel->GetReferrer(getter_AddRefs(referrer));
|
|
|
|
SetReferrerURI(referrer);
|
2000-03-25 06:43:27 +03:00
|
|
|
|
2000-05-24 06:32:13 +04:00
|
|
|
nsXPIDLCString refreshHeader;
|
2000-06-23 02:49:44 +04:00
|
|
|
nsCOMPtr<nsIAtom> refreshAtom ( dont_AddRef( NS_NewAtom("refresh") ) );
|
2000-05-24 06:32:13 +04:00
|
|
|
|
|
|
|
httpChannel -> GetResponseHeader (refreshAtom, getter_Copies (refreshHeader));
|
|
|
|
|
|
|
|
if (refreshHeader)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> baseURI = mCurrentURI;
|
|
|
|
|
|
|
|
PRInt32 millis = -1;
|
2000-08-23 21:27:06 +04:00
|
|
|
nsAutoString uriAttrib;
|
2000-05-24 06:32:13 +04:00
|
|
|
nsString result; result.AssignWithConversion (refreshHeader);
|
|
|
|
|
|
|
|
PRInt32 semiColon = result.FindCharInSet(";,");
|
|
|
|
nsAutoString token;
|
|
|
|
if (semiColon > -1)
|
|
|
|
result.Left(token, semiColon);
|
|
|
|
else
|
|
|
|
token = result;
|
|
|
|
|
|
|
|
PRBool done = PR_FALSE;
|
|
|
|
while (!done && !token.IsEmpty()) {
|
|
|
|
token.CompressWhitespace();
|
|
|
|
if (millis == -1 && nsCRT::IsAsciiDigit(token.First())) {
|
|
|
|
PRInt32 i = 0;
|
|
|
|
PRUnichar value = nsnull;
|
2000-08-25 02:15:32 +04:00
|
|
|
for ( ; i < (PRInt32) token.Length (); i++)
|
|
|
|
{
|
|
|
|
value = token[i];
|
2000-05-24 06:32:13 +04:00
|
|
|
if (!nsCRT::IsAsciiDigit(value)) {
|
|
|
|
i = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > -1) {
|
|
|
|
PRInt32 err;
|
|
|
|
millis = token.ToInteger(&err) * 1000;
|
|
|
|
} else {
|
|
|
|
done = PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
done = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
PRInt32 loc = token.FindChar('=');
|
|
|
|
if (loc > -1)
|
|
|
|
token.Cut(0, loc+1);
|
|
|
|
token.Trim(" \"'");
|
2000-08-23 21:27:06 +04:00
|
|
|
uriAttrib = token;
|
2000-05-24 06:32:13 +04:00
|
|
|
} else {
|
|
|
|
// Increment to the next token.
|
|
|
|
if (semiColon > -1) {
|
|
|
|
semiColon++;
|
|
|
|
PRInt32 semiColon2 = result.FindCharInSet(";,", semiColon);
|
|
|
|
if (semiColon2 == -1) semiColon2 = result.Length();
|
|
|
|
result.Mid(token, semiColon, semiColon2 - semiColon);
|
|
|
|
semiColon = semiColon2;
|
|
|
|
} else {
|
|
|
|
done = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end while
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2000-08-23 21:27:06 +04:00
|
|
|
if (!uriAttrib.Length()) {
|
2000-05-24 06:32:13 +04:00
|
|
|
uri = baseURI;
|
|
|
|
} else {
|
2000-08-23 21:27:06 +04:00
|
|
|
NS_NewURI(getter_AddRefs(uri), uriAttrib, baseURI);
|
2000-05-24 06:32:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshURI (uri, millis, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2000-03-30 06:24:17 +04:00
|
|
|
|
2000-05-24 06:32:13 +04:00
|
|
|
mInitialPageLoad = PR_FALSE;
|
2000-06-22 09:36:13 +04:00
|
|
|
return NS_OK;
|
2000-05-24 02:36:47 +04:00
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2000-05-24 02:36:47 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::OnLoadingSite(nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
aChannel->GetLoadAttributes(&loadFlags);
|
|
|
|
if (loadFlags & nsIChannel::LOAD_REPLACE)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocShell::SetCurrentURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
mCurrentURI = aURI; //This assignment addrefs
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentLoader> loader(do_GetInterface(mLoadCookie));
|
|
|
|
|
|
|
|
NS_ASSERTION(loader, "No document loader");
|
|
|
|
if (loader) {
|
2000-07-25 09:45:56 +04:00
|
|
|
loader->FireOnLocationChange(nsnull, nsnull, aURI);
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocShell::SetReferrerURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
mReferrerURI = aURI; // This assigment addrefs
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell: Session History
|
|
|
|
//*****************************************************************************
|
2000-07-08 09:17:49 +04:00
|
|
|
PRBool nsDocShell::ShouldAddToSessionHistory(nsIURI* aURI)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2000-07-08 09:17:49 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsXPIDLCString buffer;
|
|
|
|
nsCAutoString schemeStr;
|
2000-04-17 06:17:42 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
rv = aURI->GetScheme(getter_Copies(buffer));
|
|
|
|
if (NS_FAILED(rv)) return PR_FALSE;
|
2000-04-17 06:17:42 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
schemeStr = buffer;
|
|
|
|
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;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
nsresult nsDocShell::AddToSessionHistory(nsIURI *aURI,
|
|
|
|
nsIChannel *aChannel,
|
|
|
|
nsISHEntry **aNewEntry)
|
2000-03-25 06:43:27 +03:00
|
|
|
{
|
2000-08-18 11:31:40 +04:00
|
|
|
nsresult rv = NS_OK;
|
2000-07-08 09:17:49 +04:00
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
|
|
|
PRBool shouldPersist;
|
2000-04-19 03:30:02 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
shouldPersist = ShouldAddToSessionHistory(aURI);
|
2000-03-29 14:29:58 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
//
|
|
|
|
// If the entry is being replaced in SH, then just use the
|
|
|
|
// current entry...
|
|
|
|
//
|
|
|
|
if(mSessionHistory && nsIDocShellLoadInfo::loadNormalReplace == mLoadType) {
|
|
|
|
PRInt32 index = 0;
|
|
|
|
mSessionHistory->GetIndex(&index);
|
|
|
|
mSessionHistory->GetEntryAtIndex(index, PR_FALSE, getter_AddRefs(entry));
|
|
|
|
}
|
2000-03-25 06:43:27 +03:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
// Create a new entry if necessary.
|
|
|
|
if(!entry) {
|
|
|
|
entry = do_CreateInstance(NS_SHENTRY_PROGID);
|
2000-03-25 06:43:27 +03:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
if (!entry) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
2000-07-08 09:17:49 +04:00
|
|
|
}
|
2000-03-31 02:38:32 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
// Get the post data
|
|
|
|
nsCOMPtr<nsIInputStream> inputStream;
|
|
|
|
if (aChannel) {
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(aChannel));
|
2000-03-29 14:29:58 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
if(httpChannel) {
|
|
|
|
httpChannel->GetUploadStream(getter_AddRefs(inputStream));
|
2000-05-23 04:52:59 +04:00
|
|
|
}
|
2000-07-08 09:17:49 +04:00
|
|
|
}
|
2000-03-29 14:29:58 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
//Title is set in nsDocShell::SetTitle()
|
|
|
|
entry->Create(aURI, // uri
|
|
|
|
nsnull, // Title
|
|
|
|
nsnull, // DOMDocument
|
|
|
|
inputStream, // Post data stream
|
|
|
|
nsnull); // LayoutHistory state
|
|
|
|
//
|
|
|
|
// Add the new entry to session history.
|
|
|
|
//
|
|
|
|
// If no Session History component is available in the parent DocShell
|
|
|
|
// heirarchy, then AddChildSHEntry(...) will fail and the new entry
|
|
|
|
// will be deleted when it loses scope...
|
|
|
|
//
|
2000-08-03 01:49:26 +04:00
|
|
|
if (mLoadType != nsIDocShellLoadInfo::loadNormalReplace) {
|
|
|
|
if (mSessionHistory)
|
2000-07-15 01:06:20 +04:00
|
|
|
rv = mSessionHistory->AddEntry(entry, shouldPersist);
|
2000-08-03 01:49:26 +04:00
|
|
|
else
|
|
|
|
rv = AddChildSHEntry(nsnull, entry, mChildOffset);
|
2000-07-08 09:17:49 +04:00
|
|
|
}
|
2000-03-29 14:29:58 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
// Return the new SH entry...
|
|
|
|
if (aNewEntry) {
|
|
|
|
*aNewEntry = nsnull;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aNewEntry = entry;
|
|
|
|
NS_ADDREF(*aNewEntry);
|
|
|
|
}
|
|
|
|
}
|
2000-05-23 04:52:59 +04:00
|
|
|
|
2000-07-08 09:17:49 +04:00
|
|
|
return rv;
|
2000-02-24 07:15:22 +03:00
|
|
|
}
|
|
|
|
|
2000-05-27 01:03:34 +04:00
|
|
|
/*
|
|
|
|
* Save the HistoryLayoutState for this page before we leave it.
|
|
|
|
*/
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::UpdateCurrentSessionHistory()
|
|
|
|
{
|
2000-05-27 01:03:34 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if(!mInitialPageLoad && mSessionHistory) {
|
|
|
|
|
|
|
|
PRInt32 index = 0;
|
|
|
|
mSessionHistory->GetIndex(&index);
|
|
|
|
if (-1 < index) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
|
|
|
rv = mSessionHistory->GetEntryAtIndex(index, PR_FALSE, getter_AddRefs(entry));
|
|
|
|
if (NS_SUCCEEDED(rv) && entry) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = GetPresShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
2000-06-15 04:35:46 +04:00
|
|
|
rv = shell->CaptureHistoryState(getter_AddRefs(layoutState), PR_TRUE);
|
2000-05-27 01:03:34 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && layoutState) {
|
|
|
|
|
|
|
|
rv = entry->SetLayoutHistoryState(layoutState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
|
2000-02-17 05:03:02 +03:00
|
|
|
}
|
|
|
|
|
2000-06-24 03:54:30 +04:00
|
|
|
#ifdef SH_IN_FRAMES
|
2000-07-06 03:10:29 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, nsDocShellInfoLoadType aLoadType)
|
2000-06-24 03:54:30 +04:00
|
|
|
#else
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry)
|
2000-06-24 03:54:30 +04:00
|
|
|
#endif
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsCOMPtr<nsIInputStream> postData;
|
2000-05-27 01:03:34 +04:00
|
|
|
PRBool repost = PR_TRUE;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
2000-07-18 00:12:27 +04:00
|
|
|
NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE);
|
|
|
|
|
2000-03-28 05:38:40 +04:00
|
|
|
NS_ENSURE_SUCCESS(aEntry->GetURI(getter_AddRefs(uri)), NS_ERROR_FAILURE);
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
2000-05-27 01:03:34 +04:00
|
|
|
/* Ask whether to repost form post data */
|
|
|
|
if (postData) {
|
|
|
|
nsCOMPtr<nsIPrompt> prompter;
|
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
|
|
|
GetPromptAndStringBundle(getter_AddRefs(prompter),
|
|
|
|
getter_AddRefs(stringBundle));
|
|
|
|
|
|
|
|
if (stringBundle && prompter) {
|
|
|
|
nsXPIDLString messageStr;
|
|
|
|
nsresult rv = stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("repost").GetUnicode(),
|
|
|
|
getter_Copies(messageStr));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && messageStr) {
|
|
|
|
prompter->Confirm(nsnull, messageStr, &repost);
|
|
|
|
if (!repost)
|
|
|
|
postData = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-22 11:22:23 +04:00
|
|
|
|
2000-06-22 09:36:13 +04:00
|
|
|
#ifdef SH_IN_FRAMES
|
2000-08-31 09:53:32 +04:00
|
|
|
NS_ENSURE_SUCCESS(InternalLoad(uri, nsnull, nsnull, PR_TRUE, nsnull, postData, aLoadType, aEntry),
|
2000-06-22 09:36:13 +04:00
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
#else
|
2000-08-31 09:53:32 +04:00
|
|
|
NS_ENSURE_SUCCESS(InternalLoad(uri, nsnull, nsnull, PR_TRUE, nsnull, postData, nsIDocShellLoadInfo::loadHistory),
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_ERROR_FAILURE);
|
2000-06-22 09:36:13 +04:00
|
|
|
#endif
|
2000-02-24 07:15:22 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-22 09:36:13 +04:00
|
|
|
/*
|
2000-06-21 10:40:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::GetSHEForChild(PRInt32 aChildOffset, nsISHEntry ** aResult)
|
|
|
|
{
|
|
|
|
if (OSHE) {
|
|
|
|
nsCOMPtr<nsISHContainer> container(do_QueryInterface(OSHE));
|
|
|
|
if (container)
|
|
|
|
return container->GetChildAt(aChildOffset, aResult);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
}
|
2000-06-22 09:36:13 +04:00
|
|
|
*/
|
2000-06-21 10:40:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::PersistLayoutHistoryState()
|
|
|
|
{
|
2000-08-18 11:31:40 +04:00
|
|
|
nsresult rv = NS_OK;
|
2000-06-21 10:40:08 +04:00
|
|
|
if (OSHE) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
rv = OSHE->SetLayoutHistoryState(layoutState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-06-30 01:48:18 +04:00
|
|
|
#if 0
|
2000-06-21 10:40:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::CloneAndReplace(nsISHEntry * src, nsISHEntry * cloneRef,
|
|
|
|
nsISHEntry * replaceEntry, nsISHEntry * dest)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
if (!src || !replaceEntry || !cloneRef || !dest)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
// NS_ENSURE_ARG_POINTER(dest, NS_ERROR_FAILURE);
|
|
|
|
// static PRBool firstTime = PR_TRUE;
|
|
|
|
// static nsISHEntry * rootSHEntry = nsnull;
|
|
|
|
|
|
|
|
if (src == cloneRef) {
|
|
|
|
// release the original object before assigning a new one.
|
|
|
|
NS_RELEASE(dest);
|
|
|
|
dest = replaceEntry;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsCOMPtr<nsIInputStream> postdata;
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> LHS;
|
|
|
|
PRUnichar * title=nsnull;
|
|
|
|
nsCOMPtr<nsISHEntry> parent;
|
|
|
|
|
|
|
|
src->GetURI(getter_AddRefs(uri));
|
|
|
|
src->GetPostData(getter_AddRefs(postdata));
|
|
|
|
src->GetTitle(&title);
|
|
|
|
src->GetLayoutHistoryState(getter_AddRefs(LHS));
|
|
|
|
//XXX Is this correct? parent is a weak ref in nsISHEntry
|
|
|
|
src->GetParent(getter_AddRefs(parent));
|
|
|
|
|
|
|
|
// XXX do we care much about valid values for these uri, title etc....
|
|
|
|
dest->SetURI(uri);
|
|
|
|
dest->SetPostData(postdata);
|
|
|
|
dest->SetLayoutHistoryState(LHS);
|
|
|
|
dest->SetTitle(title);
|
|
|
|
dest->SetParent(parent);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if (firstTime) {
|
|
|
|
// Save the root of the hierarchy in the result parameter
|
|
|
|
rootSHEntry = dest;
|
|
|
|
firstTime = PR_FALSE;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
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(do_CreateInstance(NS_SHENTRY_PROGID));
|
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
|
|
|
result = CloneAndReplace(srcChild, cloneRef, replaceEntry, destChild);
|
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
2000-06-30 01:48:18 +04:00
|
|
|
result = destContainer->AddChild(destChild, i);
|
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
2000-06-21 10:40:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
2000-06-30 01:48:18 +04:00
|
|
|
#else
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocShell::CloneAndReplace(nsISHEntry * src, nsISHEntry * cloneRef,
|
|
|
|
nsISHEntry * replaceEntry, nsISHEntry ** resultEntry)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
NS_ENSURE_ARG_POINTER(resultEntry);
|
|
|
|
if (!src || !replaceEntry || !cloneRef)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
// NS_ENSURE_ARG_POINTER(dest, NS_ERROR_FAILURE);
|
|
|
|
// static PRBool firstTime = PR_TRUE;
|
|
|
|
// static nsISHEntry * rootSHEntry = nsnull;
|
|
|
|
nsISHEntry * dest = *resultEntry;
|
|
|
|
dest = (nsISHEntry *) nsnull;
|
2000-06-21 10:40:08 +04:00
|
|
|
|
2000-06-30 01:48:18 +04:00
|
|
|
if (src == cloneRef) {
|
|
|
|
// release the original object before assigning a new one.
|
|
|
|
//NS_RELEASE(dest);
|
|
|
|
|
|
|
|
dest = replaceEntry;
|
|
|
|
*resultEntry = dest;
|
|
|
|
NS_IF_ADDREF(*resultEntry);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsCOMPtr<nsIInputStream> postdata;
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> LHS;
|
|
|
|
PRUnichar * title=nsnull;
|
|
|
|
nsCOMPtr<nsISHEntry> parent;
|
|
|
|
result = nsComponentManager::CreateInstance(NS_SHENTRY_PROGID, NULL,
|
|
|
|
NS_GET_IID(nsISHEntry), (void **) &dest);
|
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
src->GetURI(getter_AddRefs(uri));
|
|
|
|
src->GetPostData(getter_AddRefs(postdata));
|
|
|
|
src->GetTitle(&title);
|
|
|
|
src->GetLayoutHistoryState(getter_AddRefs(LHS));
|
|
|
|
//XXX Is this correct? parent is a weak ref in nsISHEntry
|
|
|
|
src->GetParent(getter_AddRefs(parent));
|
|
|
|
|
|
|
|
// XXX do we care much about valid values for these uri, title etc....
|
|
|
|
dest->SetURI(uri);
|
|
|
|
dest->SetPostData(postdata);
|
|
|
|
dest->SetLayoutHistoryState(LHS);
|
|
|
|
dest->SetTitle(title);
|
|
|
|
dest->SetParent(parent);
|
|
|
|
*resultEntry = dest;
|
|
|
|
|
|
|
|
}
|
|
|
|
*resultEntry = dest;
|
|
|
|
/*
|
|
|
|
if (firstTime) {
|
|
|
|
// Save the root of the hierarchy in the result parameter
|
|
|
|
rootSHEntry = dest;
|
|
|
|
firstTime = PR_FALSE;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
|
|
|
result = CloneAndReplace(srcChild, cloneRef, replaceEntry, getter_AddRefs(destChild));
|
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
|
|
|
result = destContainer->AddChild(destChild, i);
|
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* 0 */
|
2000-06-21 10:40:08 +04:00
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell: Global History
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2000-05-27 01:03:34 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::ShouldAddToGlobalHistory(nsIURI* aURI, PRBool* aShouldAdd)
|
2000-02-24 07:15:22 +03:00
|
|
|
{
|
2000-04-17 09:54:09 +04:00
|
|
|
*aShouldAdd = PR_FALSE;
|
2000-04-22 03:32:11 +04:00
|
|
|
if(!mGlobalHistory || !aURI || (typeContent != mItemType))
|
2000-04-17 09:54:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsXPIDLCString scheme;
|
|
|
|
NS_ENSURE_SUCCESS(aURI->GetScheme(getter_Copies(scheme)), NS_ERROR_FAILURE);
|
|
|
|
|
2000-04-17 15:24:01 +04:00
|
|
|
nsAutoString schemeStr; schemeStr.AssignWithConversion(scheme);
|
2000-04-17 09:54:09 +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.
|
2000-04-17 15:24:01 +04:00
|
|
|
if(schemeStr.EqualsWithConversion("http") || schemeStr.EqualsWithConversion("https"))
|
2000-03-01 08:18:04 +03:00
|
|
|
{
|
|
|
|
*aShouldAdd = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-17 15:24:01 +04:00
|
|
|
if(schemeStr.EqualsWithConversion("about") || schemeStr.EqualsWithConversion("imap") ||
|
|
|
|
schemeStr.EqualsWithConversion("news") || schemeStr.EqualsWithConversion("mailbox"))
|
2000-04-17 09:54:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
*aShouldAdd = PR_TRUE;
|
2000-02-24 07:15:22 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::AddToGlobalHistory(nsIURI* aURI)
|
|
|
|
{
|
2000-04-22 03:32:11 +04:00
|
|
|
NS_ENSURE_STATE(mGlobalHistory);
|
2000-04-16 12:39:15 +04:00
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
nsXPIDLCString spec;
|
|
|
|
NS_ENSURE_SUCCESS(aURI->GetSpec(getter_Copies(spec)), NS_ERROR_FAILURE);
|
|
|
|
|
2000-04-16 12:39:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(mGlobalHistory->AddPage(spec, nsnull, PR_Now()),
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::UpdateCurrentGlobalHistory()
|
|
|
|
{
|
|
|
|
// XXX Add code here that needs to update the current history item
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDocShell: Helper Routines
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2000-06-20 11:59:45 +04:00
|
|
|
nsresult nsDocShell::SetLoadCookie(nsISupports *aCookie)
|
|
|
|
{
|
|
|
|
// Remove the DocShell as a listener of the old WebProgress...
|
|
|
|
if (mLoadCookie) {
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
|
|
|
|
|
|
|
if (webProgress) {
|
|
|
|
webProgress->RemoveProgressListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mLoadCookie = aCookie;
|
|
|
|
|
|
|
|
// Add the DocShell as a listener to the new WebProgress...
|
|
|
|
if (mLoadCookie) {
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
|
|
|
|
|
|
|
|
if (webProgress) {
|
|
|
|
webProgress->AddProgressListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult nsDocShell::GetLoadCookie(nsISupports **aResult)
|
|
|
|
{
|
|
|
|
*aResult = mLoadCookie;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
nsDocShellInitInfo* nsDocShell::InitInfo()
|
|
|
|
{
|
|
|
|
if(mInitInfo)
|
|
|
|
return mInitInfo;
|
|
|
|
return mInitInfo = new nsDocShellInitInfo();
|
|
|
|
}
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
#define DIALOG_STRING_URI "chrome://global/locale/appstrings.properties"
|
|
|
|
|
2000-04-22 03:32:11 +04:00
|
|
|
NS_IMETHODIMP nsDocShell::GetPromptAndStringBundle(nsIPrompt** aPrompt,
|
|
|
|
nsIStringBundle** aStringBundle)
|
2000-04-13 07:11:44 +04:00
|
|
|
{
|
2000-04-22 03:32:11 +04:00
|
|
|
NS_ENSURE_SUCCESS(GetInterface(NS_GET_IID(nsIPrompt), (void**)aPrompt), NS_ERROR_FAILURE);
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
nsCOMPtr<nsILocaleService> localeService(do_GetService(NS_LOCALESERVICE_PROGID));
|
|
|
|
NS_ENSURE_TRUE(localeService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocale> locale;
|
|
|
|
localeService->GetSystemLocale(getter_AddRefs(locale));
|
|
|
|
NS_ENSURE_TRUE(locale, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundleService> stringBundleService(do_GetService(NS_STRINGBUNDLE_PROGID));
|
|
|
|
NS_ENSURE_TRUE(stringBundleService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(stringBundleService->CreateBundle(DIALOG_STRING_URI, locale,
|
|
|
|
getter_AddRefs(aStringBundle)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
NS_IMETHODIMP nsDocShell::GetChildOffset(nsIDOMNode *aChild, nsIDOMNode* aParent,
|
|
|
|
PRInt32* aOffset)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChild || aParent);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> childNodes;
|
|
|
|
NS_ENSURE_SUCCESS(aParent->GetChildNodes(getter_AddRefs(childNodes)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(childNodes, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRInt32 i=0;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if(childNode.get() == aChild)
|
|
|
|
{
|
|
|
|
*aOffset = i;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::GetRootScrollableView(nsIScrollableView** aOutScrollView)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOutScrollView);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(shell)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(viewManager)),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(viewManager->GetRootScrollableView(aOutScrollView),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
2000-05-24 02:36:47 +04:00
|
|
|
if (*aOutScrollView == nsnull)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::EnsureContentListener()
|
|
|
|
{
|
|
|
|
if(mContentListener)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mContentListener = new nsDSURIContentListener();
|
|
|
|
NS_ENSURE_TRUE(mContentListener, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
NS_ADDREF(mContentListener);
|
|
|
|
mContentListener->DocShell(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocShell::EnsureScriptEnvironment()
|
|
|
|
{
|
|
|
|
if(mScriptContext)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_NewScriptGlobalObject(getter_AddRefs(mScriptGlobal));
|
|
|
|
NS_ENSURE_TRUE(mScriptGlobal, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
mScriptGlobal->SetDocShell(NS_STATIC_CAST(nsIDocShell*, this));
|
|
|
|
mScriptGlobal->SetGlobalObjectOwner(
|
|
|
|
NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this));
|
|
|
|
|
|
|
|
NS_CreateScriptContext(mScriptGlobal, getter_AddRefs(mScriptContext));
|
|
|
|
NS_ENSURE_TRUE(mScriptContext, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-17 05:03:02 +03:00
|
|
|
|
2000-02-24 07:15:22 +03:00
|
|
|
PRBool nsDocShell::IsFrame()
|
1999-11-12 10:28:25 +03:00
|
|
|
{
|
2000-02-24 07:15:22 +03:00
|
|
|
if(mParent)
|
1999-11-13 11:09:16 +03:00
|
|
|
{
|
2000-02-24 07:15:22 +03:00
|
|
|
PRInt32 parentType = ~mItemType; // Not us
|
|
|
|
mParent->GetItemType(&parentType);
|
|
|
|
if(parentType == mItemType) // This is a frame
|
|
|
|
return PR_TRUE;
|
1999-11-13 11:09:16 +03:00
|
|
|
}
|
2000-02-24 07:15:22 +03:00
|
|
|
|
|
|
|
return PR_FALSE;
|
1999-11-12 10:28:25 +03:00
|
|
|
}
|
|
|
|
|
2000-04-13 07:11:44 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsRefreshTimer: Object Management
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
nsRefreshTimer::nsRefreshTimer() : mRepeat(PR_FALSE), mDelay(0)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefreshTimer::~nsRefreshTimer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsRefreshTimer::nsISupports
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsRefreshTimer)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsRefreshTimer)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsRefreshTimer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITimerCallback)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
|
|
|
///*****************************************************************************
|
|
|
|
// nsRefreshTimer::nsITimerCallback
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void) nsRefreshTimer::Notify(nsITimer *aTimer)
|
|
|
|
{
|
2000-06-03 01:02:31 +04:00
|
|
|
NS_ASSERTION(mDocShell, "DocShell is somehow null");
|
2000-04-13 07:11:44 +04:00
|
|
|
|
2000-06-03 01:02:31 +04:00
|
|
|
if(mDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
|
|
|
mDocShell -> CreateLoadInfo (getter_AddRefs (loadInfo));
|
|
|
|
|
2000-06-22 11:22:23 +04:00
|
|
|
loadInfo -> SetLoadType(nsIDocShellLoadInfo::loadRefresh);
|
2000-06-03 01:02:31 +04:00
|
|
|
mDocShell -> LoadURI(mURI, loadInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LoadURL(...) will cancel all refresh timers... This causes the Timer and
|
|
|
|
* its refreshData instance to be released...
|
|
|
|
*/
|
2000-04-13 17:35:54 +04:00
|
|
|
}
|
|
|
|
|