2001-03-28 22:09:03 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode:nil; c-basic-offset: 2 -*-
|
1999-11-02 22:36:43 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-11-02 22:36:43 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-11-02 22:36:43 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-11-02 22:36:43 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-11-02 22:36:43 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsURILoader.h"
|
1999-11-05 09:01:40 +03:00
|
|
|
#include "nsIURIContentListener.h"
|
1999-11-06 02:06:16 +03:00
|
|
|
#include "nsIContentHandler.h"
|
1999-11-05 09:01:40 +03:00
|
|
|
#include "nsILoadGroup.h"
|
2000-01-29 09:02:36 +03:00
|
|
|
#include "nsIDocumentLoader.h"
|
2000-04-03 06:26:05 +04:00
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
1999-11-05 09:01:40 +03:00
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStreamListener.h"
|
1999-11-30 00:00:52 +03:00
|
|
|
#include "nsIURI.h"
|
1999-11-05 09:01:40 +03:00
|
|
|
#include "nsIChannel.h"
|
1999-11-18 10:36:41 +03:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
1999-11-10 09:24:40 +03:00
|
|
|
#include "nsIProgressEventSink.h"
|
1999-11-30 00:00:52 +03:00
|
|
|
#include "nsIInputStream.h"
|
1999-11-18 04:02:31 +03:00
|
|
|
#include "nsIStreamConverterService.h"
|
2000-02-15 07:04:34 +03:00
|
|
|
#include "nsWeakReference.h"
|
2000-05-25 09:12:58 +04:00
|
|
|
#include "nsIHTTPChannel.h"
|
|
|
|
|
2000-02-15 07:04:34 +03:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIDocShellTreeOwner.h"
|
1999-11-05 09:01:40 +03:00
|
|
|
|
1999-11-02 22:36:43 +03:00
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2000-09-01 05:54:35 +04:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
2000-03-01 00:33:23 +03:00
|
|
|
#include "nsIUnkContentTypeHandler.h"
|
2000-04-21 09:18:15 +04:00
|
|
|
#include "nsDOMError.h"
|
2000-03-01 00:33:23 +03:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
#include "nsCExternalHandlerService.h" // contains contractids for the helper app service
|
2000-06-23 08:43:28 +04:00
|
|
|
|
2000-10-19 14:25:49 +04:00
|
|
|
// Following are for Bug 13871: Prevent frameset spoofing
|
|
|
|
#include "nsIPref.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsICodebasePrincipal.h"
|
2000-10-24 08:35:25 +04:00
|
|
|
#include "nsIHTMLDocument.h"
|
2000-10-19 14:25:49 +04:00
|
|
|
|
2001-02-05 13:50:33 +03:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
static NS_DEFINE_CID(kURILoaderCID, NS_URI_LOADER_CID);
|
1999-11-18 04:02:31 +03:00
|
|
|
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
1999-11-05 09:01:40 +03:00
|
|
|
|
2000-01-29 09:02:36 +03:00
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
/*
|
|
|
|
* The nsDocumentOpenInfo contains the state required when a single document
|
|
|
|
* is being opened in order to discover the content type... Each instance remains alive until its target URL has
|
|
|
|
* been loaded (or aborted).
|
|
|
|
*
|
|
|
|
*/
|
1999-11-16 00:35:40 +03:00
|
|
|
class nsDocumentOpenInfo : public nsIStreamListener
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDocumentOpenInfo();
|
|
|
|
|
2000-03-09 11:17:40 +03:00
|
|
|
nsresult Init(nsISupports * aRetargetedWindowContext,
|
|
|
|
nsISupports * aOriginalWindowContext);
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
nsresult Open(nsIChannel* channel,
|
1999-12-02 09:59:39 +03:00
|
|
|
nsURILoadCommand aCommand,
|
1999-11-05 09:01:40 +03:00
|
|
|
const char * aWindowTarget,
|
2000-01-29 09:02:36 +03:00
|
|
|
nsISupports * aWindowContext);
|
1999-11-05 09:01:40 +03:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
nsresult DispatchContent(nsIRequest *request, nsISupports * aCtxt);
|
|
|
|
nsresult RetargetOutput(nsIRequest *request, const char * aSrcContentType,
|
1999-11-18 04:02:31 +03:00
|
|
|
const char * aOutContentType, nsIStreamListener * aStreamListener);
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
// nsIRequestObserver methods:
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
1999-11-05 09:01:40 +03:00
|
|
|
|
2000-10-04 10:53:52 +04:00
|
|
|
// nsIStreamListener methods:
|
1999-11-16 00:35:40 +03:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsDocumentOpenInfo();
|
1999-12-28 12:20:05 +03:00
|
|
|
nsDocumentOpenInfo* Clone();
|
2000-06-17 01:21:04 +04:00
|
|
|
// ProcessCanceledCase will do a couple of things....(1) it checks to see if the channel was canceled,
|
|
|
|
// if it was, it will go out and release all of the document open info's local state for this load
|
|
|
|
// and it will return TRUE.
|
2001-02-21 23:38:08 +03:00
|
|
|
PRBool ProcessCanceledCase(nsIRequest *request);
|
1999-12-28 12:20:05 +03:00
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIURIContentListener> m_contentListener;
|
1999-11-16 00:35:40 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> m_targetStreamListener;
|
2000-03-09 11:17:40 +03:00
|
|
|
nsCOMPtr<nsISupports> m_originalContext;
|
1999-12-02 09:59:39 +03:00
|
|
|
nsURILoadCommand mCommand;
|
1999-11-05 09:01:40 +03:00
|
|
|
nsCString m_windowTarget;
|
2000-05-10 06:05:54 +04:00
|
|
|
PRBool mOnStopFired;
|
1999-11-05 09:01:40 +03:00
|
|
|
};
|
|
|
|
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsDocumentOpenInfo);
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsDocumentOpenInfo);
|
1999-11-30 00:00:52 +03:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDocumentOpenInfo)
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
1999-11-30 00:00:52 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
nsDocumentOpenInfo::nsDocumentOpenInfo()
|
2000-05-10 06:05:54 +04:00
|
|
|
: mOnStopFired (PR_FALSE)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDocumentOpenInfo::~nsDocumentOpenInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-03-09 11:17:40 +03:00
|
|
|
nsresult nsDocumentOpenInfo::Init(nsISupports * aCurrentWindowContext,
|
|
|
|
nsISupports * aOriginalWindowContext)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
1999-11-30 00:00:52 +03:00
|
|
|
// ask the window context if it has a uri content listener...
|
|
|
|
nsresult rv = NS_OK;
|
2000-03-09 11:17:40 +03:00
|
|
|
m_contentListener = do_GetInterface(aCurrentWindowContext, &rv);
|
|
|
|
m_originalContext = aOriginalWindowContext;
|
1999-11-30 00:00:52 +03:00
|
|
|
return rv;
|
1999-11-05 09:01:40 +03:00
|
|
|
}
|
|
|
|
|
1999-12-28 12:20:05 +03:00
|
|
|
nsDocumentOpenInfo* nsDocumentOpenInfo::Clone()
|
|
|
|
{
|
|
|
|
nsDocumentOpenInfo* newObject;
|
|
|
|
|
|
|
|
newObject = new nsDocumentOpenInfo();
|
|
|
|
if (newObject) {
|
|
|
|
newObject->m_contentListener = m_contentListener;
|
|
|
|
newObject->mCommand = mCommand;
|
|
|
|
newObject->m_windowTarget = m_windowTarget;
|
2000-06-23 08:43:28 +04:00
|
|
|
newObject->m_originalContext = m_originalContext;
|
1999-12-28 12:20:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return newObject;
|
|
|
|
}
|
|
|
|
|
2000-06-17 01:21:04 +04:00
|
|
|
// ProcessCanceledCase will do a couple of things....(1) it checks to see if the channel was canceled,
|
|
|
|
// if it was, it will go out and release all of the document open info's local state for this load
|
|
|
|
// and it will return TRUE.
|
2001-02-21 23:38:08 +03:00
|
|
|
PRBool nsDocumentOpenInfo::ProcessCanceledCase(nsIRequest *request)
|
2000-06-17 01:21:04 +04:00
|
|
|
{
|
|
|
|
PRBool canceled = PR_FALSE;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
if (request)
|
2000-06-17 01:21:04 +04:00
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
request->GetStatus(&rv);
|
2000-07-07 06:23:19 +04:00
|
|
|
|
|
|
|
// if we were aborted or if the js returned no result (i.e. we aren't replacing any window content)
|
|
|
|
if (rv == NS_BINDING_ABORTED || rv == NS_ERROR_DOM_RETVAL_UNDEFINED)
|
2000-06-17 01:21:04 +04:00
|
|
|
{
|
|
|
|
canceled = PR_TRUE;
|
|
|
|
// free any local state for this load since we are aborting it so we
|
|
|
|
// can break any cycles...
|
|
|
|
m_contentListener = nsnull;
|
|
|
|
m_targetStreamListener = nsnull;
|
|
|
|
m_originalContext = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return canceled;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
nsresult nsDocumentOpenInfo::Open(nsIChannel *aChannel,
|
1999-12-02 09:59:39 +03:00
|
|
|
nsURILoadCommand aCommand,
|
1999-11-05 09:01:40 +03:00
|
|
|
const char * aWindowTarget,
|
2000-01-29 09:02:36 +03:00
|
|
|
nsISupports * aWindowContext)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
|
|
|
// this method is not complete!!! Eventually, we should first go
|
|
|
|
// to the content listener and ask them for a protocol handler...
|
|
|
|
// if they don't give us one, we need to go to the registry and get
|
|
|
|
// the preferred protocol handler.
|
|
|
|
|
|
|
|
// But for now, I'm going to let necko do the work for us....
|
|
|
|
|
2000-01-17 22:55:27 +03:00
|
|
|
nsresult rv = NS_OK;
|
1999-11-05 09:01:40 +03:00
|
|
|
// store any local state
|
|
|
|
m_windowTarget = aWindowTarget;
|
1999-12-02 09:59:39 +03:00
|
|
|
mCommand = aCommand;
|
1999-11-05 09:01:40 +03:00
|
|
|
|
2000-04-03 06:26:05 +04:00
|
|
|
// now just open the channel!
|
2001-02-21 23:38:08 +03:00
|
|
|
if (aChannel){
|
|
|
|
rv = aChannel->AsyncOpen(this, nsnull);
|
|
|
|
}
|
|
|
|
|
2000-04-21 09:18:15 +04:00
|
|
|
if (rv == NS_ERROR_DOM_RETVAL_UNDEFINED) {
|
|
|
|
NS_WARNING("js returned no result -- not replacing window contents");
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
1999-11-05 09:01:40 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsDocumentOpenInfo::OnStartRequest(nsIRequest *request, nsISupports * aCtxt)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
2000-06-17 01:21:04 +04:00
|
|
|
nsresult rv = NS_OK;
|
2000-05-25 09:12:58 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Deal with "special" HTTP responses:
|
|
|
|
//
|
|
|
|
// - In the case of a 204 (No Content) response, do not try to find a
|
|
|
|
// content handler. Just return. This causes the request to be
|
|
|
|
// ignored.
|
|
|
|
//
|
2001-02-21 23:38:08 +03:00
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(request, &rv));
|
2000-05-25 09:12:58 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRUint32 responseCode = 0;
|
|
|
|
|
|
|
|
httpChannel->GetResponseStatus(&responseCode);
|
|
|
|
if (204 == responseCode) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
if (ProcessCanceledCase(request))
|
2000-06-17 01:21:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = DispatchContent(request, aCtxt);
|
1999-11-18 04:02:31 +03:00
|
|
|
if (m_targetStreamListener)
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = m_targetStreamListener->OnStartRequest(request, aCtxt);
|
1999-11-16 00:35:40 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsDocumentOpenInfo::OnDataAvailable(nsIRequest *request, nsISupports * aCtxt,
|
1999-11-16 00:35:40 +03:00
|
|
|
nsIInputStream * inStr, PRUint32 sourceOffset, PRUint32 count)
|
|
|
|
{
|
|
|
|
// if we have retarged to the end stream listener, then forward the call....
|
|
|
|
// otherwise, don't do anything
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2000-06-17 01:21:04 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
if (ProcessCanceledCase(request))
|
2000-06-17 01:21:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
1999-11-16 00:35:40 +03:00
|
|
|
if (m_targetStreamListener)
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = m_targetStreamListener->OnDataAvailable(request, aCtxt, inStr, sourceOffset, count);
|
1999-11-05 09:01:40 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsDocumentOpenInfo::OnStopRequest(nsIRequest *request, nsISupports *aCtxt,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult aStatus)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
2000-02-04 04:54:47 +03:00
|
|
|
nsresult rv = NS_OK;
|
2000-06-17 01:21:04 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
if (ProcessCanceledCase(request))
|
2000-06-17 01:21:04 +04:00
|
|
|
return NS_OK;
|
2000-05-10 06:05:54 +04:00
|
|
|
|
|
|
|
if (!mOnStopFired && m_targetStreamListener)
|
|
|
|
{
|
|
|
|
mOnStopFired = PR_TRUE;
|
2001-04-10 10:01:08 +04:00
|
|
|
m_targetStreamListener->OnStopRequest(request, aCtxt, aStatus);
|
2000-05-10 06:05:54 +04:00
|
|
|
}
|
1999-11-05 09:01:40 +03:00
|
|
|
|
1999-12-28 12:20:05 +03:00
|
|
|
m_targetStreamListener = 0;
|
|
|
|
|
2000-02-04 04:54:47 +03:00
|
|
|
return rv;
|
1999-11-05 09:01:40 +03:00
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * aCtxt)
|
1999-11-18 04:02:31 +03:00
|
|
|
{
|
2000-01-05 07:44:27 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsXPIDLCString contentType;
|
2000-04-19 00:41:38 +04:00
|
|
|
nsCOMPtr<nsISupports> originalWindowContext = m_originalContext; // local variable to keep track of this.
|
2000-06-23 08:43:28 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> contentStreamListener;
|
2001-02-21 23:38:08 +03:00
|
|
|
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
|
2001-04-10 10:01:08 +04:00
|
|
|
if (!aChannel) {
|
|
|
|
printf(">>> QI for channel from request failed!!\n");
|
2001-02-21 23:38:08 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
2000-01-05 07:44:27 +03:00
|
|
|
|
|
|
|
rv = aChannel->GetContentType(getter_Copies(contentType));
|
1999-11-18 04:02:31 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-01-05 07:44:27 +03:00
|
|
|
// go to the uri dispatcher and give them our stuff...
|
1999-11-18 04:02:31 +03:00
|
|
|
NS_WITH_SERVICE(nsIURILoader, pURILoader, kURILoaderCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2000-01-05 07:44:27 +03:00
|
|
|
nsCOMPtr<nsIURIContentListener> contentListener;
|
|
|
|
nsXPIDLCString desiredContentType;
|
|
|
|
|
|
|
|
//
|
|
|
|
// First step: See if any nsIURIContentListener prefers to handle this
|
|
|
|
// content type.
|
|
|
|
//
|
2000-01-18 01:21:25 +03:00
|
|
|
PRBool abortDispatch = PR_FALSE;
|
2000-01-05 07:44:27 +03:00
|
|
|
rv = pURILoader->DispatchContent(contentType, mCommand, m_windowTarget,
|
2001-02-21 23:38:08 +03:00
|
|
|
request, aCtxt,
|
1999-11-18 04:02:31 +03:00
|
|
|
m_contentListener,
|
2000-03-09 11:17:40 +03:00
|
|
|
m_originalContext,
|
2000-01-05 07:44:27 +03:00
|
|
|
getter_Copies(desiredContentType),
|
2000-01-18 01:21:25 +03:00
|
|
|
getter_AddRefs(contentListener),
|
2000-06-23 08:43:28 +04:00
|
|
|
&abortDispatch);
|
2000-01-18 01:21:25 +03:00
|
|
|
|
|
|
|
// if the uri loader says to abort the dispatch then someone
|
|
|
|
// else must have stepped in and taken over for us...so stop..
|
|
|
|
|
|
|
|
if (abortDispatch) return NS_OK;
|
2000-01-05 07:44:27 +03:00
|
|
|
//
|
|
|
|
// Second step: If no listener prefers this type, see if any stream
|
|
|
|
// decoders exist to transform this content type into
|
|
|
|
// some other.
|
|
|
|
//
|
2000-06-23 08:43:28 +04:00
|
|
|
if (!contentListener)
|
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = RetargetOutput(request, contentType, "*/*", nsnull);
|
2000-06-23 08:43:28 +04:00
|
|
|
if (m_targetStreamListener)
|
|
|
|
return NS_OK;
|
2000-01-05 07:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Step 3:
|
|
|
|
//
|
|
|
|
// BIG TIME HACK ALERT!!!!! WE NEED THIS HACK IN PLACE UNTIL OUR NEW UNKNOWN CONTENT
|
|
|
|
// HANDLER COMES ONLINE!!!
|
|
|
|
// Until that day, if we couldn't find a handler for the content type, then go back to the listener who
|
|
|
|
// originated the url request and force them to handle the content....this forces us through the old code
|
|
|
|
// path for unknown content types which brings up the file save as dialog...
|
|
|
|
if (!contentListener) {
|
|
|
|
contentListener = m_contentListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Good news! Some content listener can handle this content type.
|
|
|
|
//
|
|
|
|
if (contentListener)
|
1999-11-18 04:02:31 +03:00
|
|
|
{
|
2000-01-29 09:02:36 +03:00
|
|
|
PRBool bAbortProcess = PR_FALSE;
|
1999-11-18 04:02:31 +03:00
|
|
|
nsCAutoString contentTypeToUse;
|
2000-01-05 07:44:27 +03:00
|
|
|
if (desiredContentType)
|
2000-03-26 12:05:46 +04:00
|
|
|
contentTypeToUse.Assign(desiredContentType);
|
1999-11-18 04:02:31 +03:00
|
|
|
else
|
2000-03-26 12:05:46 +04:00
|
|
|
contentTypeToUse.Assign(contentType);
|
1999-11-18 04:02:31 +03:00
|
|
|
|
2000-01-29 09:02:36 +03:00
|
|
|
// We need to first figure out if we are retargeting the load to a content listener
|
|
|
|
// that is different from the one that originated the request....if so, set
|
|
|
|
// LOAD_RETARGETED_DOCUMENT_URI on the channel.
|
|
|
|
|
|
|
|
if (contentListener.get() != m_contentListener.get())
|
|
|
|
{
|
|
|
|
// we must be retargeting...so set an appropriate flag on the channel
|
2001-04-10 10:01:08 +04:00
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
aChannel->GetLoadFlags(&loadFlags);
|
2001-04-14 06:02:19 +04:00
|
|
|
loadFlags |= nsIChannel::LOAD_RETARGETED_DOCUMENT_URI;
|
2001-04-10 10:01:08 +04:00
|
|
|
aChannel->SetLoadFlags(loadFlags);
|
2000-01-29 09:02:36 +03:00
|
|
|
}
|
|
|
|
|
2000-01-05 07:44:27 +03:00
|
|
|
rv = contentListener->DoContent(contentTypeToUse, mCommand, m_windowTarget,
|
2001-02-21 23:38:08 +03:00
|
|
|
request, getter_AddRefs(contentStreamListener),
|
2000-01-05 07:44:27 +03:00
|
|
|
&bAbortProcess);
|
1999-11-18 04:02:31 +03:00
|
|
|
|
|
|
|
// the listener is doing all the work from here...we are done!!!
|
2000-01-05 07:44:27 +03:00
|
|
|
if (bAbortProcess) return rv;
|
1999-11-18 04:02:31 +03:00
|
|
|
|
2001-02-07 05:44:09 +03:00
|
|
|
// try to detect if there is a helper application we an use...
|
2000-10-04 10:53:52 +04:00
|
|
|
if (/* mCommand == nsIURILoader::viewUserClick && */ !contentStreamListener)
|
2000-06-23 08:43:28 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
PRBool abortProcess = PR_FALSE;
|
|
|
|
aChannel->GetURI(getter_AddRefs(uri));
|
2000-09-14 03:57:52 +04:00
|
|
|
nsCOMPtr<nsIExternalHelperAppService> helperAppService (do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID));
|
2000-06-28 01:43:17 +04:00
|
|
|
if (helperAppService)
|
|
|
|
{
|
|
|
|
rv = helperAppService->DoContent(contentType, uri, m_originalContext, &abortProcess, getter_AddRefs(contentStreamListener));
|
|
|
|
if (NS_SUCCEEDED(rv) && contentStreamListener)
|
2001-02-21 23:38:08 +03:00
|
|
|
return RetargetOutput(request, contentType, contentType, contentStreamListener);
|
2000-06-28 01:43:17 +04:00
|
|
|
}
|
|
|
|
rv = NS_ERROR_FAILURE; // this will cause us to bring up the unknown content handler dialog.
|
2000-06-23 08:43:28 +04:00
|
|
|
}
|
|
|
|
|
1999-11-18 04:02:31 +03:00
|
|
|
// okay, all registered listeners have had a chance to handle this content...
|
|
|
|
// did one of them give us a stream listener back? if so, let's start reading data
|
|
|
|
// into it...
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = RetargetOutput(request, contentType, desiredContentType, contentStreamListener);
|
2000-06-23 08:43:28 +04:00
|
|
|
m_originalContext = nsnull; // we don't need this anymore....
|
2000-01-05 07:44:27 +03:00
|
|
|
}
|
1999-11-18 04:02:31 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
nsresult nsDocumentOpenInfo::RetargetOutput(nsIRequest *request, const char * aSrcContentType, const char * aOutContentType,
|
1999-11-18 04:02:31 +03:00
|
|
|
nsIStreamListener * aStreamListener)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-06-23 08:43:28 +04:00
|
|
|
|
|
|
|
// catch the case when some joker server sends back a content type of "*/*"
|
|
|
|
// because we said we could handle "*/*" in our accept headers
|
|
|
|
if (aOutContentType && *aOutContentType && nsCRT::strcasecmp(aSrcContentType, aOutContentType) && nsCRT::strcmp(aSrcContentType, "*/*"))
|
1999-11-18 04:02:31 +03:00
|
|
|
{
|
2000-01-05 07:44:27 +03:00
|
|
|
NS_WITH_SERVICE(nsIStreamConverterService, StreamConvService, kStreamConverterServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-04-02 13:15:46 +04:00
|
|
|
nsAutoString from_w; from_w.AssignWithConversion (aSrcContentType);
|
|
|
|
nsAutoString to_w; to_w.AssignWithConversion (aOutContentType);
|
2000-06-23 08:43:28 +04:00
|
|
|
|
|
|
|
nsDocumentOpenInfo* nextLink;
|
|
|
|
|
|
|
|
// When applying stream decoders, it is necessary to "insert" an
|
|
|
|
// intermediate nsDocumentOpenInfo instance to handle the targeting of
|
|
|
|
// the "final" stream or streams.
|
|
|
|
//
|
|
|
|
// For certain content types (ie. multi-part/x-mixed-replace) the input
|
|
|
|
// stream is split up into multiple destination streams. This
|
|
|
|
// intermediate instance is used to target these "decoded" streams...
|
|
|
|
//
|
|
|
|
nextLink = Clone();
|
|
|
|
if (!nextLink) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(nextLink);
|
|
|
|
|
|
|
|
// Set up the final destination listener.
|
|
|
|
nextLink->m_targetStreamListener = nsnull;
|
1999-12-28 12:20:05 +03:00
|
|
|
|
1999-11-18 04:02:31 +03:00
|
|
|
// The following call binds this channelListener's mNextListener (typically
|
|
|
|
// the nsDocumentBindInfo) to the underlying stream converter, and returns
|
|
|
|
// the underlying stream converter which we then set to be this channelListener's
|
|
|
|
// mNextListener. This effectively nestles the stream converter down right
|
|
|
|
// in between the raw stream and the final listener.
|
2000-01-05 07:44:27 +03:00
|
|
|
rv = StreamConvService->AsyncConvertData(from_w.GetUnicode(),
|
|
|
|
to_w.GetUnicode(),
|
2000-06-23 08:43:28 +04:00
|
|
|
nextLink,
|
2001-02-21 23:38:08 +03:00
|
|
|
request,
|
2000-01-05 07:44:27 +03:00
|
|
|
getter_AddRefs(m_targetStreamListener));
|
2000-06-23 08:43:28 +04:00
|
|
|
NS_RELEASE(nextLink);
|
1999-11-18 04:02:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
m_targetStreamListener = aStreamListener; // no converter necessary so use a direct pipe
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-06 02:06:16 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation of nsURILoader
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-11-02 22:36:43 +03:00
|
|
|
nsURILoader::nsURILoader()
|
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
2001-03-28 22:09:03 +04:00
|
|
|
NS_NewISupportsArray(getter_AddRefs(m_listeners));
|
2000-10-19 14:25:49 +04:00
|
|
|
|
|
|
|
// Check pref to see if we should prevent frameset spoofing
|
|
|
|
mValidateOrigin = PR_TRUE; // secure by default, pref disables check
|
|
|
|
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
|
|
|
NS_ASSERTION(prefs,"nsURILoader: could not get prefs service!\n");
|
|
|
|
if (prefs)
|
|
|
|
prefs->GetBoolPref("browser.frame.validate_origin", &mValidateOrigin);
|
1999-11-02 22:36:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsURILoader::~nsURILoader()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-11-30 00:00:52 +03:00
|
|
|
NS_IMPL_ADDREF(nsURILoader);
|
|
|
|
NS_IMPL_RELEASE(nsURILoader);
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsURILoader)
|
1999-12-02 09:59:39 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURILoader)
|
1999-11-30 00:00:52 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIURILoader)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-11-02 22:36:43 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsURILoader::RegisterContentListener(nsIURIContentListener * aContentListener)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2001-03-28 22:09:03 +04:00
|
|
|
if (!m_listeners) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsWeakPtr weakListener = do_GetWeakReference(aContentListener);
|
|
|
|
NS_ASSERTION(weakListener, "your URIContentListener must support weak refs!\n");
|
|
|
|
|
|
|
|
if (weakListener)
|
|
|
|
m_listeners->AppendElement(weakListener);
|
1999-11-02 22:36:43 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsURILoader::UnRegisterContentListener(nsIURIContentListener * aContentListener)
|
|
|
|
{
|
2001-03-28 22:09:03 +04:00
|
|
|
if (!m_listeners) return NS_OK;
|
|
|
|
|
|
|
|
nsWeakPtr weakListener = do_GetWeakReference(aContentListener);
|
|
|
|
if (weakListener)
|
|
|
|
m_listeners->RemoveElement(weakListener);
|
|
|
|
|
1999-11-02 22:36:43 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsURILoader::OpenURI(nsIChannel *channel,
|
1999-12-02 09:59:39 +03:00
|
|
|
nsURILoadCommand aCommand,
|
1999-11-05 09:01:40 +03:00
|
|
|
const char * aWindowTarget,
|
2000-01-29 09:02:36 +03:00
|
|
|
nsISupports * aWindowContext)
|
1999-11-06 02:06:16 +03:00
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
return OpenURIVia(channel, aCommand, aWindowTarget, aWindowContext, 0 /* ip address */);
|
1999-11-06 02:06:16 +03:00
|
|
|
}
|
|
|
|
|
2000-10-19 14:25:49 +04:00
|
|
|
//
|
|
|
|
// Bug 13871: Prevent frameset spoofing
|
|
|
|
// Check if origin document uri is the equivalent to target's principal.
|
|
|
|
// This takes into account subdomain checking if document.domain is set for
|
|
|
|
// Nav 4.x compatability.
|
|
|
|
//
|
|
|
|
// The following was derived from nsCodeBasePrincipal::Equals but in addition
|
|
|
|
// to the host PL_strcmp, it accepts a subdomain (nsHTMLDocument::SetDomain)
|
|
|
|
// if the document.domain was set.
|
|
|
|
//
|
|
|
|
static
|
|
|
|
PRBool SameOrSubdomainOfTarget(nsIURI* aOriginURI, nsIURI* aTargetURI, PRBool aDocumentDomainSet)
|
|
|
|
{
|
|
|
|
nsXPIDLCString targetScheme;
|
|
|
|
nsresult rv = aTargetURI->GetScheme(getter_Copies(targetScheme));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetScheme, PR_TRUE);
|
|
|
|
|
|
|
|
nsXPIDLCString originScheme;
|
|
|
|
rv = aOriginURI->GetScheme(getter_Copies(originScheme));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originScheme, PR_TRUE);
|
|
|
|
|
|
|
|
if (PL_strcmp(targetScheme, originScheme))
|
|
|
|
return PR_FALSE; // Different schemes - check fails
|
|
|
|
|
|
|
|
if (! PL_strcmp(targetScheme, "file"))
|
|
|
|
return PR_TRUE; // All file: urls are considered to have the same origin.
|
|
|
|
|
|
|
|
if (! PL_strcmp(targetScheme, "imap") ||
|
|
|
|
! PL_strcmp(targetScheme, "mailbox") ||
|
|
|
|
! PL_strcmp(targetScheme, "news"))
|
|
|
|
{
|
|
|
|
|
|
|
|
// Each message is a distinct trust domain; use the whole spec for comparison
|
|
|
|
nsXPIDLCString targetSpec;
|
|
|
|
rv =aTargetURI->GetSpec(getter_Copies(targetSpec));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetSpec, PR_TRUE);
|
|
|
|
|
|
|
|
nsXPIDLCString originSpec;
|
|
|
|
rv = aOriginURI->GetSpec(getter_Copies(originSpec));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originSpec, PR_TRUE);
|
|
|
|
|
|
|
|
return (! PL_strcmp(targetSpec, originSpec)); // True if full spec is same, false otherwise
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare ports.
|
|
|
|
int targetPort, originPort;
|
|
|
|
rv = aTargetURI->GetPort(&targetPort);
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv), PR_TRUE);
|
|
|
|
|
|
|
|
rv = aOriginURI->GetPort(&originPort);
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv), PR_TRUE);
|
|
|
|
|
|
|
|
if (targetPort != originPort)
|
|
|
|
return PR_FALSE; // Different port - check fails
|
|
|
|
|
|
|
|
// Need to check the hosts
|
|
|
|
nsXPIDLCString targetHost;
|
|
|
|
rv = aTargetURI->GetHost(getter_Copies(targetHost));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetHost, PR_TRUE);
|
|
|
|
|
|
|
|
nsXPIDLCString originHost;
|
|
|
|
rv = aOriginURI->GetHost(getter_Copies(originHost));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originHost, PR_TRUE);
|
|
|
|
|
|
|
|
if (!PL_strcmp(targetHost, originHost))
|
|
|
|
return PR_TRUE; // Hosts are the same - check passed
|
|
|
|
|
|
|
|
// If document.domain was set, do the relaxed check
|
|
|
|
// Right align hostnames and compare - ensure preceeding char is . or /
|
|
|
|
if (aDocumentDomainSet)
|
|
|
|
{
|
|
|
|
int targetHostLen = PL_strlen(targetHost);
|
|
|
|
int originHostLen = PL_strlen(originHost);
|
|
|
|
int prefixChar = originHostLen-targetHostLen-1;
|
|
|
|
|
|
|
|
return ((originHostLen > targetHostLen) &&
|
|
|
|
(! PL_strcmp((originHost+prefixChar+1), targetHost)) &&
|
|
|
|
(originHost[prefixChar] == '.' || originHost[prefixChar] == '/'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE; // document.domain not set and hosts not same - check failed
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Bug 13871: Prevent frameset spoofing
|
|
|
|
//
|
|
|
|
// This routine answers: 'Is origin's document from same domain as target's document?'
|
|
|
|
// Be optimistic that domain is same - error cases all answer 'yes'.
|
|
|
|
//
|
|
|
|
// We have to compare the URI of the actual document loaded in the origin,
|
|
|
|
// ignoring any document.domain that was set, with the principal URI of the
|
|
|
|
// target (including any document.domain that was set). This puts control
|
|
|
|
// of loading in the hands of the target, which is more secure. (per Nav 4.x)
|
|
|
|
//
|
|
|
|
static
|
|
|
|
PRBool ValidateOrigin(nsIDocShellTreeItem* aOriginTreeItem, nsIDocShellTreeItem* aTargetTreeItem)
|
|
|
|
{
|
|
|
|
// Get origin document uri (ignoring document.domain)
|
|
|
|
nsCOMPtr<nsIWebNavigation> originWebNav(do_QueryInterface(aOriginTreeItem));
|
|
|
|
NS_ENSURE_TRUE(originWebNav, PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> originDocumentURI;
|
|
|
|
nsresult rv = originWebNav->GetCurrentURI(getter_AddRefs(originDocumentURI));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originDocumentURI, PR_TRUE);
|
|
|
|
|
|
|
|
// Get target principal uri (including document.domain)
|
|
|
|
nsCOMPtr<nsIDOMDocument> targetDOMDocument(do_GetInterface(aTargetTreeItem));
|
|
|
|
NS_ENSURE_TRUE(targetDOMDocument, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> targetDocument(do_QueryInterface(targetDOMDocument));
|
|
|
|
NS_ENSURE_TRUE(targetDocument, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> targetPrincipal;
|
|
|
|
rv = targetDocument->GetPrincipal(getter_AddRefs(targetPrincipal));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetPrincipal, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsICodebasePrincipal> targetCodebasePrincipal(do_QueryInterface(targetPrincipal));
|
|
|
|
NS_ENSURE_TRUE(targetCodebasePrincipal, PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> targetPrincipalURI;
|
|
|
|
rv = targetCodebasePrincipal->GetURI(getter_AddRefs(targetPrincipalURI));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetPrincipalURI, PR_TRUE);
|
|
|
|
|
2000-10-24 08:35:25 +04:00
|
|
|
// Find out if document.domain was set for HTML documents
|
|
|
|
PRBool documentDomainSet = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIHTMLDocument> targetHTMLDocument(do_QueryInterface(targetDocument));
|
2000-10-19 14:25:49 +04:00
|
|
|
|
2000-10-24 08:35:25 +04:00
|
|
|
// If we don't have an HTML document, fall through with documentDomainSet false
|
|
|
|
if (targetHTMLDocument) {
|
|
|
|
targetHTMLDocument->WasDomainSet(&documentDomainSet);
|
|
|
|
}
|
2000-10-19 14:25:49 +04:00
|
|
|
|
|
|
|
// Is origin same principal or a subdomain of target's document.domain
|
|
|
|
// Compare actual URI of origin document, not origin principal's URI. (Per Nav 4.x)
|
|
|
|
return SameOrSubdomainOfTarget(originDocumentURI, targetPrincipalURI, documentDomainSet);
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsURILoader::GetTarget(nsIChannel *channel, nsCString &aWindowTarget,
|
2000-02-15 07:04:34 +03:00
|
|
|
nsISupports * aWindowContext,
|
|
|
|
nsISupports ** aRetargetedWindowContext)
|
|
|
|
{
|
2000-04-02 13:15:46 +04:00
|
|
|
nsAutoString name; name.AssignWithConversion(aWindowTarget);
|
2000-02-15 07:04:34 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> windowCtxtAsTreeItem (do_GetInterface(aWindowContext));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem;
|
|
|
|
*aRetargetedWindowContext = nsnull;
|
|
|
|
|
2001-04-04 01:56:02 +04:00
|
|
|
PRBool mustMakeNewWindow = PR_FALSE;
|
|
|
|
|
2001-02-05 13:50:33 +03:00
|
|
|
if(!name.Length() || name.EqualsIgnoreCase("_self"))
|
|
|
|
{
|
|
|
|
*aRetargetedWindowContext = aWindowContext;
|
|
|
|
}
|
|
|
|
else if (name.EqualsIgnoreCase("_blank") || name.EqualsIgnoreCase("_new"))
|
2000-02-15 07:04:34 +03:00
|
|
|
{
|
2001-04-04 01:56:02 +04:00
|
|
|
mustMakeNewWindow = PR_TRUE;
|
2001-02-05 13:50:33 +03:00
|
|
|
aWindowTarget.Assign("");
|
2000-02-15 07:04:34 +03:00
|
|
|
}
|
|
|
|
else if(name.EqualsIgnoreCase("_parent"))
|
|
|
|
{
|
|
|
|
windowCtxtAsTreeItem->GetSameTypeParent(getter_AddRefs(treeItem));
|
|
|
|
if(!treeItem)
|
|
|
|
*aRetargetedWindowContext = aWindowContext;
|
|
|
|
}
|
|
|
|
else if(name.EqualsIgnoreCase("_top"))
|
|
|
|
{
|
|
|
|
windowCtxtAsTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(treeItem));
|
|
|
|
if(!treeItem)
|
|
|
|
*aRetargetedWindowContext = aWindowContext;
|
|
|
|
}
|
|
|
|
else if(name.EqualsIgnoreCase("_content"))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
windowCtxtAsTreeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
|
|
|
|
if (treeOwner)
|
|
|
|
treeOwner->FindItemWithName(name.GetUnicode(), nsnull, getter_AddRefs(treeItem));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_ERROR("Someone isn't setting up the tree owner. You might like to try that."
|
|
|
|
"Things will.....you know, work.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
windowCtxtAsTreeItem->FindItemWithName(name.GetUnicode(), nsnull, getter_AddRefs(treeItem));
|
2000-10-19 14:25:49 +04:00
|
|
|
|
2001-04-04 01:56:02 +04:00
|
|
|
// The named window cannot be found so it must be created to receive the
|
|
|
|
// channel data.
|
|
|
|
|
|
|
|
if (!treeItem) {
|
|
|
|
mustMakeNewWindow = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-10-19 14:25:49 +04:00
|
|
|
// Bug 13871: Prevent frameset spoofing
|
|
|
|
// See BugSplat 336170, 338737 and XP_FindNamedContextInList in the classic codebase
|
|
|
|
// Per Nav's behaviour:
|
|
|
|
// - pref controlled: "browser.frame.validate_origin" (mValidateOrigin)
|
|
|
|
// - allow load if host of target or target's parent is same as host of origin
|
|
|
|
// - allow load if target is a top level window
|
|
|
|
|
|
|
|
// Check to see if pref is true
|
|
|
|
if (mValidateOrigin && windowCtxtAsTreeItem && treeItem) {
|
|
|
|
|
|
|
|
// Is origin frame from the same domain as target frame?
|
|
|
|
if (! ValidateOrigin(windowCtxtAsTreeItem, treeItem)) {
|
|
|
|
|
|
|
|
// No. Is origin frame from the same domain as target's parent?
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> targetParentTreeItem;
|
|
|
|
nsresult rv = treeItem->GetSameTypeParent(getter_AddRefs(targetParentTreeItem));
|
|
|
|
if (NS_SUCCEEDED(rv) && targetParentTreeItem) {
|
|
|
|
if (! ValidateOrigin(windowCtxtAsTreeItem, targetParentTreeItem)) {
|
|
|
|
|
|
|
|
// Neither is from the origin domain, send load to a new window (_blank)
|
|
|
|
*aRetargetedWindowContext = aWindowContext;
|
|
|
|
aWindowTarget.Assign("_blank");
|
|
|
|
} // else (target's parent from origin domain) allow this load
|
|
|
|
} // else (no parent) allow this load since shell is a toplevel window
|
|
|
|
} // else (target from origin domain) allow this load
|
|
|
|
} // else (pref is false) allow this load
|
2000-02-15 07:04:34 +03:00
|
|
|
}
|
|
|
|
|
2001-04-04 01:56:02 +04:00
|
|
|
if (mustMakeNewWindow) {
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> parentWindow;
|
|
|
|
JSContext* jsContext = nsnull;
|
|
|
|
|
|
|
|
if (aWindowContext)
|
|
|
|
{
|
|
|
|
parentWindow = do_GetInterface(aWindowContext);
|
|
|
|
if (parentWindow)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
sgo = do_QueryInterface( parentWindow );
|
|
|
|
if (sgo)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext;
|
|
|
|
sgo->GetContext( getter_AddRefs( scriptContext ) );
|
|
|
|
if (scriptContext)
|
|
|
|
jsContext = (JSContext*)scriptContext->GetNativeContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!parentWindow || !jsContext)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new window (context) so that the uri loader has a proper
|
|
|
|
// target to push the content into.
|
|
|
|
|
|
|
|
void* mark;
|
|
|
|
jsval* argv;
|
|
|
|
|
|
|
|
nsAutoString uriValue; // Empty
|
|
|
|
argv = JS_PushArguments(jsContext, &mark, "Ws",
|
|
|
|
uriValue.GetUnicode(), aWindowTarget.get());
|
|
|
|
NS_ENSURE_TRUE(argv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> newWindow;
|
|
|
|
parentWindow->Open(jsContext, argv, 2, getter_AddRefs(newWindow));
|
|
|
|
JS_PopArguments(jsContext, mark);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(newWindow);
|
|
|
|
nsIDocShell *docShell = nsnull;
|
|
|
|
sgo->GetDocShell(&docShell);
|
|
|
|
|
|
|
|
*aRetargetedWindowContext = (nsISupports *) docShell;
|
|
|
|
}
|
|
|
|
|
2000-02-15 07:04:34 +03:00
|
|
|
nsCOMPtr<nsISupports> treeItemCtxt (do_QueryInterface(treeItem));
|
|
|
|
if (!*aRetargetedWindowContext)
|
2000-09-02 02:28:37 +04:00
|
|
|
{
|
2000-02-15 07:04:34 +03:00
|
|
|
*aRetargetedWindowContext = treeItemCtxt;
|
2000-09-02 02:28:37 +04:00
|
|
|
}
|
2000-02-15 07:04:34 +03:00
|
|
|
|
|
|
|
NS_IF_ADDREF(*aRetargetedWindowContext);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsURILoader::OpenURIVia(nsIChannel *channel,
|
1999-12-02 09:59:39 +03:00
|
|
|
nsURILoadCommand aCommand,
|
1999-11-10 09:24:40 +03:00
|
|
|
const char * aWindowTarget,
|
2000-03-09 11:17:40 +03:00
|
|
|
nsISupports * aOriginalWindowContext,
|
1999-11-18 23:47:57 +03:00
|
|
|
PRUint32 aLocalIP)
|
1999-11-02 22:36:43 +03:00
|
|
|
{
|
1999-11-05 09:01:40 +03:00
|
|
|
// we need to create a DocumentOpenInfo object which will go ahead and open the url
|
|
|
|
// and discover the content type....
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsDocumentOpenInfo* loader = nsnull;
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
if (!channel) return NS_ERROR_NULL_POINTER;
|
1999-11-05 09:01:40 +03:00
|
|
|
|
2000-03-24 03:23:40 +03:00
|
|
|
// Let the window context's uriListener know that the open is starting. This
|
|
|
|
// gives that window a chance to abort the load process.
|
|
|
|
nsCOMPtr<nsIURIContentListener> winContextListener(do_GetInterface(aOriginalWindowContext));
|
|
|
|
if(winContextListener)
|
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
// get channel from request
|
2000-03-24 03:23:40 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2001-02-21 23:38:08 +03:00
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
2000-03-24 03:23:40 +03:00
|
|
|
if(uri)
|
|
|
|
{
|
2000-03-30 07:21:26 +04:00
|
|
|
PRBool doAbort = PR_FALSE;
|
|
|
|
winContextListener->OnStartURIOpen(uri, aWindowTarget, &doAbort);
|
2000-03-24 03:23:40 +03:00
|
|
|
|
2000-03-30 07:21:26 +04:00
|
|
|
if(doAbort)
|
2000-03-24 03:23:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-19 14:25:49 +04:00
|
|
|
nsCAutoString windowTarget(aWindowTarget);
|
2000-02-15 07:04:34 +03:00
|
|
|
nsCOMPtr<nsISupports> retargetedWindowContext;
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_ENSURE_SUCCESS(GetTarget(channel, windowTarget, aOriginalWindowContext, getter_AddRefs(retargetedWindowContext)), NS_ERROR_FAILURE);
|
2000-02-15 07:04:34 +03:00
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
NS_NEWXPCOM(loader, nsDocumentOpenInfo);
|
|
|
|
if (!loader) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(loader);
|
2000-01-29 09:02:36 +03:00
|
|
|
|
2000-05-07 06:01:10 +04:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> loadCookie;
|
2000-02-15 07:04:34 +03:00
|
|
|
SetupLoadCookie(retargetedWindowContext, getter_AddRefs(loadCookie));
|
2000-01-29 09:02:36 +03:00
|
|
|
|
2000-03-09 11:17:40 +03:00
|
|
|
loader->Init(retargetedWindowContext, aOriginalWindowContext); // Extra Info
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
// now instruct the loader to go ahead and open the url
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = loader->Open(channel, aCommand, windowTarget, retargetedWindowContext);
|
1999-11-05 09:01:40 +03:00
|
|
|
NS_RELEASE(loader);
|
|
|
|
|
2000-04-21 09:18:15 +04:00
|
|
|
return rv;
|
1999-11-05 09:01:40 +03:00
|
|
|
}
|
|
|
|
|
2000-02-14 13:12:55 +03:00
|
|
|
NS_IMETHODIMP nsURILoader::Stop(nsISupports* aLoadCookie)
|
|
|
|
{
|
2000-05-07 06:01:10 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocumentLoader> docLoader;
|
2000-02-14 13:12:55 +03:00
|
|
|
|
2000-05-07 06:01:10 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aLoadCookie);
|
2000-02-14 13:12:55 +03:00
|
|
|
|
2000-05-07 06:01:10 +04:00
|
|
|
docLoader = do_GetInterface(aLoadCookie, &rv);
|
|
|
|
if (docLoader) {
|
|
|
|
rv = docLoader->Stop();
|
|
|
|
}
|
|
|
|
return rv;
|
2000-02-14 13:12:55 +03:00
|
|
|
}
|
|
|
|
|
2000-01-29 09:02:36 +03:00
|
|
|
NS_IMETHODIMP
|
2000-05-07 06:01:10 +04:00
|
|
|
nsURILoader::GetLoadGroupForContext(nsISupports * aWindowContext,
|
|
|
|
nsILoadGroup ** aLoadGroup)
|
2000-01-29 09:02:36 +03:00
|
|
|
{
|
2000-05-07 06:01:10 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> loadCookieForWindow;
|
|
|
|
|
|
|
|
// Initialize the [out] parameter...
|
|
|
|
*aLoadGroup= nsnull;
|
|
|
|
|
2000-01-29 09:02:36 +03:00
|
|
|
NS_ENSURE_ARG(aWindowContext);
|
2000-05-07 06:01:10 +04:00
|
|
|
|
|
|
|
rv = SetupLoadCookie(aWindowContext, getter_AddRefs(loadCookieForWindow));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-29 09:02:36 +03:00
|
|
|
|
2000-05-07 06:01:10 +04:00
|
|
|
rv = loadCookieForWindow->GetInterface(NS_GET_IID(nsILoadGroup),
|
|
|
|
(void **) aLoadGroup);
|
|
|
|
return rv;
|
2000-01-29 09:02:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-07 06:01:10 +04:00
|
|
|
nsURILoader::GetDocumentLoaderForContext(nsISupports * aWindowContext,
|
|
|
|
nsIDocumentLoader ** aDocLoader)
|
2000-01-29 09:02:36 +03:00
|
|
|
{
|
2000-05-07 06:01:10 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> loadCookieForWindow;
|
|
|
|
|
|
|
|
// Initialize the [out] parameter...
|
|
|
|
*aDocLoader = nsnull;
|
|
|
|
|
2000-01-29 09:02:36 +03:00
|
|
|
NS_ENSURE_ARG(aWindowContext);
|
2000-05-07 06:01:10 +04:00
|
|
|
|
|
|
|
rv = SetupLoadCookie(aWindowContext, getter_AddRefs(loadCookieForWindow));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-29 09:02:36 +03:00
|
|
|
|
2000-05-07 06:01:10 +04:00
|
|
|
rv = loadCookieForWindow->GetInterface(NS_GET_IID(nsIDocumentLoader),
|
|
|
|
(void **) aDocLoader);
|
|
|
|
return rv;
|
2000-01-29 09:02:36 +03:00
|
|
|
}
|
|
|
|
|
2000-05-07 06:01:10 +04:00
|
|
|
nsresult nsURILoader::SetupLoadCookie(nsISupports * aWindowContext,
|
|
|
|
nsIInterfaceRequestor ** aLoadCookie)
|
2000-01-29 09:02:36 +03:00
|
|
|
{
|
|
|
|
// first, see if we have already set a load cookie on the cnt listener..
|
|
|
|
// i.e. if this isn't the first time we've tried to run a url through this window
|
|
|
|
// context then we don't need to create another load cookie, we can reuse the first one.
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsISupports> loadCookie;
|
|
|
|
|
2000-05-07 06:01:10 +04:00
|
|
|
// Initialize the [out] parameter...
|
|
|
|
*aLoadCookie = nsnull;
|
|
|
|
|
2000-01-29 09:02:36 +03:00
|
|
|
nsCOMPtr<nsIURIContentListener> cntListener (do_GetInterface(aWindowContext));
|
2000-05-07 06:01:10 +04:00
|
|
|
if (cntListener) {
|
|
|
|
// Get the load cookie for the requested window context...
|
2000-01-29 09:02:36 +03:00
|
|
|
rv = cntListener->GetLoadCookie(getter_AddRefs(loadCookie));
|
2000-05-07 06:01:10 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// If we don't have a load cookie for this window context yet, then
|
|
|
|
// go create one! In order to create a load cookie, we need to get
|
|
|
|
// the parent's load cookie if there is one...
|
|
|
|
//
|
|
|
|
if (!loadCookie) {
|
2000-01-29 09:02:36 +03:00
|
|
|
nsCOMPtr<nsIURIContentListener> parentListener;
|
2000-05-07 06:01:10 +04:00
|
|
|
nsCOMPtr<nsIDocumentLoader> parentDocLoader;
|
|
|
|
nsCOMPtr<nsIDocumentLoader> newDocLoader;
|
|
|
|
|
|
|
|
// Try to get the parent's load cookie...
|
2000-01-29 09:02:36 +03:00
|
|
|
cntListener->GetParentContentListener(getter_AddRefs(parentListener));
|
2000-05-07 06:01:10 +04:00
|
|
|
if (parentListener) {
|
2000-01-29 09:02:36 +03:00
|
|
|
rv = parentListener->GetLoadCookie(getter_AddRefs(loadCookie));
|
2000-05-07 06:01:10 +04:00
|
|
|
|
|
|
|
// if we had a parent cookie use it to help with the creation process
|
|
|
|
if (loadCookie) {
|
|
|
|
parentDocLoader = do_GetInterface(loadCookie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If there is no parent DocLoader, then use the global DocLoader
|
|
|
|
// service as the parent...
|
|
|
|
if (!parentDocLoader) {
|
2000-09-14 03:57:52 +04:00
|
|
|
parentDocLoader = do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &rv);
|
2000-05-07 06:01:10 +04:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create a new document loader. The document loader represents
|
|
|
|
// the load cookie which the uriloader hands out...
|
|
|
|
//
|
|
|
|
rv = parentDocLoader->CreateDocumentLoader(getter_AddRefs(newDocLoader));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
newDocLoader->QueryInterface(NS_GET_IID(nsIInterfaceRequestor),
|
|
|
|
getter_AddRefs(loadCookie));
|
|
|
|
rv = cntListener->SetLoadCookie(loadCookie);
|
2000-01-29 09:02:36 +03:00
|
|
|
} // if we don't have a load cookie already
|
|
|
|
} // if we have a cntListener
|
|
|
|
|
2000-05-11 05:33:25 +04:00
|
|
|
// loadCookie may be null - for example, <a target="popupWin"> if popupWin is
|
|
|
|
// not a defined window. The following prevents a crash (Bug 32898)
|
|
|
|
if (loadCookie) {
|
|
|
|
rv = loadCookie->QueryInterface(NS_GET_IID(nsIInterfaceRequestor),
|
2000-05-07 06:01:10 +04:00
|
|
|
(void**)aLoadCookie);
|
2000-05-11 05:33:25 +04:00
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2000-01-29 09:02:36 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
1999-11-30 00:00:52 +03:00
|
|
|
|
2000-02-04 11:43:34 +03:00
|
|
|
PRBool nsURILoader::ShouldHandleContent(nsIURIContentListener * aCntListener,
|
|
|
|
const char * aContentType,
|
|
|
|
nsURILoadCommand aCommand,
|
|
|
|
const char * aWindowTarget,
|
|
|
|
char ** aContentTypeToUse)
|
|
|
|
{
|
|
|
|
PRBool foundContentHandler = PR_FALSE;
|
|
|
|
if (aCommand == nsIURILoader::viewUserClick)
|
|
|
|
aCntListener->IsPreferred(aContentType, aCommand, aWindowTarget,
|
|
|
|
aContentTypeToUse,
|
|
|
|
&foundContentHandler);
|
|
|
|
else
|
|
|
|
aCntListener->CanHandleContent(aContentType, aCommand, aWindowTarget,
|
|
|
|
aContentTypeToUse,
|
|
|
|
&foundContentHandler);
|
|
|
|
return foundContentHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsURILoader::DispatchContent(const char * aContentType,
|
|
|
|
nsURILoadCommand aCommand,
|
|
|
|
const char * aWindowTarget,
|
2001-02-21 23:38:08 +03:00
|
|
|
nsIRequest *request,
|
2000-02-04 11:43:34 +03:00
|
|
|
nsISupports * aCtxt,
|
|
|
|
nsIURIContentListener * aContentListener,
|
2000-03-09 11:17:40 +03:00
|
|
|
nsISupports * aSrcWindowContext,
|
2000-02-04 11:43:34 +03:00
|
|
|
char ** aContentTypeToUse,
|
|
|
|
nsIURIContentListener ** aContentListenerToUse,
|
|
|
|
PRBool * aAbortProcess)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
2000-02-04 11:43:34 +03:00
|
|
|
NS_ENSURE_ARG(aContentType);
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_ENSURE_ARG(request);
|
2000-02-04 11:43:34 +03:00
|
|
|
|
2001-03-28 22:09:03 +04:00
|
|
|
// okay, now we've discovered the content type. We need to do the
|
|
|
|
// following:
|
|
|
|
// (1) We always start with the original content listener (if any)
|
|
|
|
// that originated the request and then ask if it can handle the
|
|
|
|
// content.
|
|
|
|
// (2) if it can't, we'll move on to the registered content
|
|
|
|
// listeners and give them a crack at handling the content.
|
|
|
|
// (3) if we cannot find a registered content lister to handle the
|
|
|
|
// type, then we move on to phase II which is to try to find a
|
|
|
|
// content handler in the registry for the content type.
|
|
|
|
// hitting this phase usually means we'll be creating a new
|
|
|
|
// window or handing off to an external application.
|
2000-02-04 11:43:34 +03:00
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-11-06 02:06:16 +03:00
|
|
|
nsCOMPtr<nsIURIContentListener> listenerToUse = aContentListener;
|
2000-02-19 05:05:52 +03:00
|
|
|
PRBool skipRetargetingSearch = PR_FALSE;
|
2001-03-28 22:09:03 +04:00
|
|
|
// How do we determine whether we need to ask any registered content
|
|
|
|
// listeners if they want a crack at the content?
|
|
|
|
// (1) if the window target is blank or new, then we don't want to
|
|
|
|
// ask...
|
2000-02-19 05:05:52 +03:00
|
|
|
if (!nsCRT::strcasecmp(aWindowTarget, "_blank") || !nsCRT::strcasecmp(aWindowTarget, "_new"))
|
|
|
|
skipRetargetingSearch = PR_TRUE;
|
|
|
|
else
|
|
|
|
{
|
2001-03-28 22:09:03 +04:00
|
|
|
// (2) if the original content listener is NULL and we have a
|
|
|
|
// target name then we must not be a window open with that
|
|
|
|
// target name so skip the content listener search and skip to
|
|
|
|
// the part that brings up the new window.
|
2000-02-19 05:05:52 +03:00
|
|
|
if (aWindowTarget && *aWindowTarget && !aContentListener)
|
|
|
|
skipRetargetingSearch = PR_TRUE;
|
|
|
|
}
|
2000-02-04 11:43:34 +03:00
|
|
|
|
1999-11-06 02:06:16 +03:00
|
|
|
// find a content handler that can and will handle the content
|
2000-02-19 05:05:52 +03:00
|
|
|
if (!skipRetargetingSearch)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
2000-02-15 07:04:34 +03:00
|
|
|
PRBool foundContentHandler = PR_FALSE;
|
|
|
|
if (listenerToUse)
|
|
|
|
foundContentHandler = ShouldHandleContent(listenerToUse, aContentType,
|
|
|
|
aCommand, aWindowTarget, aContentTypeToUse);
|
|
|
|
|
|
|
|
|
2001-03-28 22:09:03 +04:00
|
|
|
// if it can't handle the content, scan through the list of
|
|
|
|
// registered listeners
|
|
|
|
if (!foundContentHandler)
|
2000-02-15 07:04:34 +03:00
|
|
|
{
|
|
|
|
PRInt32 i = 0;
|
|
|
|
// keep looping until we get a content listener back
|
2001-03-28 22:09:03 +04:00
|
|
|
PRUint32 count; m_listeners->Count(&count);
|
|
|
|
for(i = 0; i < PRInt32(count) && !foundContentHandler; i++)
|
2000-10-04 10:53:52 +04:00
|
|
|
{
|
|
|
|
//nsIURIContentListener's aren't refcounted.
|
2001-03-28 22:09:03 +04:00
|
|
|
nsWeakPtr weakListener;
|
|
|
|
m_listeners->QueryElementAt(i, NS_GET_IID(nsIWeakReference),
|
|
|
|
getter_AddRefs(weakListener));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURIContentListener> listener =
|
|
|
|
do_QueryReferent(weakListener);
|
2000-02-15 07:04:34 +03:00
|
|
|
if (listener)
|
|
|
|
{
|
|
|
|
foundContentHandler = ShouldHandleContent(listener, aContentType,
|
|
|
|
aCommand, aWindowTarget, aContentTypeToUse);
|
|
|
|
if (foundContentHandler)
|
|
|
|
listenerToUse = listener;
|
2001-03-28 22:09:03 +04:00
|
|
|
} else {
|
|
|
|
// remove from the listener list, and reset i
|
|
|
|
m_listeners->RemoveElementAt(i);
|
|
|
|
i--;
|
2000-02-15 07:04:34 +03:00
|
|
|
}
|
|
|
|
} // for loop
|
|
|
|
} // if we can't handle the content
|
|
|
|
|
|
|
|
|
|
|
|
if (foundContentHandler && listenerToUse)
|
|
|
|
{
|
|
|
|
*aContentListenerToUse = listenerToUse;
|
|
|
|
NS_IF_ADDREF(*aContentListenerToUse);
|
|
|
|
return rv;
|
|
|
|
}
|
1999-11-05 09:01:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// no registered content listeners to handle this type!!! so go to the register
|
|
|
|
// and get a registered nsIContentHandler for our content type. Hand it off
|
|
|
|
// to them...
|
1999-11-06 02:06:16 +03:00
|
|
|
// eventually we want to hit up the category manager so we can allow people to
|
|
|
|
// over ride the default content type handlers....for now...i'm skipping that part.
|
1999-11-05 09:01:40 +03:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
nsCAutoString handlerContractID (NS_CONTENT_HANDLER_CONTRACTID_PREFIX);
|
|
|
|
handlerContractID += aContentType;
|
1999-11-06 02:06:16 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContentHandler> aContentHandler;
|
2000-09-14 03:57:52 +04:00
|
|
|
rv = nsComponentManager::CreateInstance(handlerContractID, nsnull, NS_GET_IID(nsIContentHandler), getter_AddRefs(aContentHandler));
|
1999-11-06 02:06:16 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) // we did indeed have a content handler for this type!! yippee...
|
2000-01-18 01:21:25 +03:00
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = aContentHandler->HandleContent(aContentType, "view", aWindowTarget, aSrcWindowContext, request);
|
2000-02-04 11:43:34 +03:00
|
|
|
*aAbortProcess = PR_TRUE;
|
2000-01-18 01:21:25 +03:00
|
|
|
}
|
1999-12-02 09:59:39 +03:00
|
|
|
|
1999-11-06 02:06:16 +03:00
|
|
|
return rv;
|
1999-11-02 22:36:43 +03:00
|
|
|
}
|
|
|
|
|