1999-10-30 01:46:18 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
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-10-30 01:46:18 +04: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-10-30 01:46:18 +04: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-10-30 01:46:18 +04: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-10-30 01:46:18 +04:00
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#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"
|
1999-11-30 00:03:41 +03:00
|
|
|
#include "nsIHTTPChannel.h"
|
1999-11-30 00:00:52 +03:00
|
|
|
#include "nsHTTPEnums.h"
|
1999-11-05 09:01:40 +03:00
|
|
|
|
1999-10-30 01:46:18 +04:00
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* 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();
|
|
|
|
|
1999-11-30 00:00:52 +03:00
|
|
|
nsresult Init(nsISupports * aWindowContext);
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsresult Open(nsIURI *aURL,
|
|
|
|
const char * aWindowTarget,
|
1999-11-30 00:00:52 +03:00
|
|
|
nsISupports * aWindowContext,
|
1999-11-10 09:24:40 +03:00
|
|
|
nsIURI * aReferringURI,
|
1999-11-30 00:00:52 +03:00
|
|
|
nsIInputStream * aInputStream,
|
1999-11-10 09:24:40 +03:00
|
|
|
nsISupports * aOpenContext,
|
|
|
|
nsISupports ** aCurrentOpenContext);
|
1999-11-05 09:01:40 +03:00
|
|
|
|
1999-11-18 04:02:31 +03:00
|
|
|
nsresult DispatchContent(nsIChannel * aChannel, nsISupports * aCtxt);
|
|
|
|
nsresult RetargetOutput(nsIChannel * aChannel, const char * aSrcContentType,
|
|
|
|
const char * aOutContentType, nsIStreamListener * aStreamListener);
|
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
// nsIStreamObserver methods:
|
|
|
|
NS_DECL_NSISTREAMOBSERVER
|
|
|
|
|
1999-11-16 00:35:40 +03:00
|
|
|
// nsIStreamListener methods:
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsDocumentOpenInfo();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIURIContentListener> m_contentListener;
|
1999-11-16 00:35:40 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> m_targetStreamListener;
|
1999-11-05 09:01:40 +03:00
|
|
|
nsCString m_windowTarget;
|
|
|
|
};
|
|
|
|
|
1999-11-30 00:00:52 +03:00
|
|
|
NS_IMPL_ADDREF(nsDocumentOpenInfo);
|
|
|
|
NS_IMPL_RELEASE(nsDocumentOpenInfo);
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDocumentOpenInfo)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
nsDocumentOpenInfo::nsDocumentOpenInfo()
|
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDocumentOpenInfo::~nsDocumentOpenInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-11-30 00:00:52 +03:00
|
|
|
nsresult nsDocumentOpenInfo::Init(nsISupports * aWindowContext)
|
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;
|
|
|
|
m_contentListener = do_GetInterface(aWindowContext, &rv);
|
|
|
|
return rv;
|
1999-11-05 09:01:40 +03:00
|
|
|
}
|
|
|
|
|
1999-11-10 09:24:40 +03:00
|
|
|
nsresult nsDocumentOpenInfo::Open(nsIURI *aURI,
|
1999-11-05 09:01:40 +03:00
|
|
|
const char * aWindowTarget,
|
1999-11-30 00:00:52 +03:00
|
|
|
nsISupports * aWindowContext,
|
1999-11-10 09:24:40 +03:00
|
|
|
nsIURI * aReferringURI,
|
1999-11-30 00:00:52 +03:00
|
|
|
nsIInputStream * aPostData,
|
1999-11-10 09:24:40 +03:00
|
|
|
nsISupports * aOpenContext,
|
|
|
|
nsISupports ** aCurrentOpenContext)
|
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....
|
|
|
|
|
|
|
|
// store any local state
|
|
|
|
m_windowTarget = aWindowTarget;
|
|
|
|
|
1999-11-30 00:00:52 +03:00
|
|
|
// get the requestor for the window context...
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> requestor = do_QueryInterface(aWindowContext);
|
|
|
|
|
|
|
|
|
1999-11-10 09:24:40 +03:00
|
|
|
// and get the load group out of the open context
|
|
|
|
nsCOMPtr<nsILoadGroup> aLoadGroup = do_QueryInterface(aOpenContext);
|
|
|
|
if (!aLoadGroup)
|
|
|
|
{
|
|
|
|
// i haven't implemented this yet...it's going to be hard
|
|
|
|
// because it requires a persistant stream observer (the uri loader maybe???)
|
|
|
|
// that we don't have in this architecture in order to create a new load group
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCurrentOpenContext)
|
|
|
|
aLoadGroup->QueryInterface(NS_GET_IID(nsISupports), (void **) aCurrentOpenContext);
|
|
|
|
|
|
|
|
// now we have all we need, so go get the necko channel service so we can
|
|
|
|
// open the url.
|
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
NS_WITH_SERVICE(nsIIOService, pNetService, kIOServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
1999-11-19 06:04:25 +03:00
|
|
|
nsCOMPtr<nsIChannel> aChannel;
|
1999-11-30 00:00:52 +03:00
|
|
|
rv = pNetService->NewChannelFromURI("", aURI, aLoadGroup, requestor,
|
1999-11-19 06:04:25 +03:00
|
|
|
nsIChannel::LOAD_NORMAL, aReferringURI, getter_AddRefs(aChannel));
|
1999-11-05 09:01:40 +03:00
|
|
|
if (NS_FAILED(rv)) return rv; // uhoh we were unable to get a channel to handle the url!!!
|
1999-11-30 00:00:52 +03:00
|
|
|
// figure out if we need to set the post data stream on the channel...right now,
|
|
|
|
// this is only done for http channels.....
|
|
|
|
|
|
|
|
if (aPostData || aReferringURI)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(aChannel));
|
|
|
|
if (httpChannel)
|
|
|
|
{
|
|
|
|
if (aPostData)
|
|
|
|
{
|
|
|
|
httpChannel->SetRequestMethod(HM_POST);
|
|
|
|
httpChannel->SetPostDataStream(aPostData);
|
|
|
|
}
|
|
|
|
if (aReferringURI)
|
|
|
|
{
|
|
|
|
// Referer - misspelled, but per the HTTP spec
|
|
|
|
nsCOMPtr<nsIAtom> key = NS_NewAtom("referer");
|
|
|
|
nsXPIDLCString aSpec;
|
|
|
|
aReferringURI->GetSpec(getter_Copies(aSpec));
|
|
|
|
httpChannel->SetRequestHeader(key, aSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if post data || a refferring uri
|
1999-11-19 06:04:25 +03:00
|
|
|
rv = aChannel->AsyncRead(0, -1, nsnull, this);
|
1999-11-05 09:01:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocumentOpenInfo::OnStartRequest(nsIChannel * aChannel, nsISupports * aCtxt)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-11-18 04:02:31 +03:00
|
|
|
rv = DispatchContent(aChannel, aCtxt);
|
|
|
|
if (m_targetStreamListener)
|
|
|
|
m_targetStreamListener->OnStartRequest(aChannel, aCtxt);
|
1999-11-16 00:35:40 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocumentOpenInfo::OnDataAvailable(nsIChannel * aChannel, nsISupports * aCtxt,
|
|
|
|
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;
|
|
|
|
if (m_targetStreamListener)
|
|
|
|
rv = m_targetStreamListener->OnDataAvailable(aChannel, aCtxt, inStr, sourceOffset, count);
|
1999-11-05 09:01:40 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocumentOpenInfo::OnStopRequest(nsIChannel * aChannel, nsISupports *aCtxt,
|
|
|
|
nsresult aStatus, const PRUnichar * errorMsg)
|
|
|
|
{
|
1999-11-16 00:35:40 +03:00
|
|
|
if (m_targetStreamListener)
|
|
|
|
m_targetStreamListener->OnStopRequest(aChannel, aCtxt, aStatus, errorMsg);
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 04:02:31 +03:00
|
|
|
nsresult nsDocumentOpenInfo::DispatchContent(nsIChannel * aChannel, nsISupports * aCtxt)
|
|
|
|
{
|
|
|
|
nsXPIDLCString aContentType;
|
|
|
|
nsresult rv = aChannel->GetContentType(getter_Copies(aContentType));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// go to the uri dispatcher and give them our stuff...
|
|
|
|
NS_WITH_SERVICE(nsIURILoader, pURILoader, kURILoaderCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURIContentListener> aContentListener;
|
|
|
|
nsXPIDLCString aDesiredContentType;
|
|
|
|
rv = pURILoader->DispatchContent(aContentType, "view", m_windowTarget,
|
|
|
|
aChannel, aCtxt,
|
|
|
|
m_contentListener,
|
|
|
|
getter_Copies(aDesiredContentType),
|
|
|
|
getter_AddRefs(aContentListener));
|
|
|
|
if (NS_SUCCEEDED(rv) && aContentListener)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStreamListener> aContentStreamListener;
|
|
|
|
PRBool aAbortProcess = PR_FALSE;
|
|
|
|
nsCAutoString contentTypeToUse;
|
|
|
|
if (aDesiredContentType)
|
|
|
|
contentTypeToUse = aDesiredContentType;
|
|
|
|
else
|
|
|
|
contentTypeToUse = aContentType;
|
|
|
|
|
|
|
|
rv = aContentListener->DoContent(contentTypeToUse, "view", m_windowTarget,
|
|
|
|
aChannel, getter_AddRefs(aContentStreamListener),
|
|
|
|
&aAbortProcess);
|
|
|
|
|
|
|
|
// the listener is doing all the work from here...we are done!!!
|
|
|
|
if (aAbortProcess) return rv;
|
|
|
|
|
|
|
|
// 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...
|
|
|
|
rv = RetargetOutput(aChannel, aContentType, aDesiredContentType, aContentStreamListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDocumentOpenInfo::RetargetOutput(nsIChannel * aChannel, const char * aSrcContentType, const char * aOutContentType,
|
|
|
|
nsIStreamListener * aStreamListener)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// do we need to invoke the stream converter service?
|
|
|
|
if (aOutContentType && *aOutContentType && nsCRT::strcasecmp(aSrcContentType, aOutContentType))
|
|
|
|
{
|
|
|
|
NS_WITH_SERVICE(nsIStreamConverterService, StreamConvService, kStreamConverterServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsAutoString aUnicSrc (aSrcContentType);
|
|
|
|
nsAutoString aUniTo (aOutContentType);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
rv = StreamConvService->AsyncConvertData(aUnicSrc.GetUnicode(), aUniTo.GetUnicode(), aStreamListener, aChannel,
|
|
|
|
getter_AddRefs(m_targetStreamListener));
|
|
|
|
}
|
|
|
|
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()
|
1999-10-30 01:46:18 +04:00
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
m_listeners = new nsVoidArray();
|
|
|
|
}
|
|
|
|
|
1999-11-02 22:36:43 +03:00
|
|
|
nsURILoader::~nsURILoader()
|
1999-10-30 01:46:18 +04:00
|
|
|
{
|
|
|
|
if (m_listeners)
|
|
|
|
delete m_listeners;
|
|
|
|
}
|
|
|
|
|
1999-11-30 00:00:52 +03:00
|
|
|
NS_IMPL_ADDREF(nsURILoader);
|
|
|
|
NS_IMPL_RELEASE(nsURILoader);
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsURILoader)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIURILoader)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIURILoaderWithPostData)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-10-30 01:46:18 +04:00
|
|
|
|
1999-11-02 22:36:43 +03:00
|
|
|
NS_IMETHODIMP nsURILoader::RegisterContentListener(nsIURIContentListener * aContentListener)
|
1999-10-30 01:46:18 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (m_listeners)
|
|
|
|
m_listeners->AppendElement(aContentListener);
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-02 22:36:43 +03:00
|
|
|
NS_IMETHODIMP nsURILoader::UnRegisterContentListener(nsIURIContentListener * aContentListener)
|
1999-10-30 01:46:18 +04:00
|
|
|
{
|
|
|
|
if (m_listeners)
|
|
|
|
m_listeners->RemoveElement(aContentListener);
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
NS_IMETHODIMP nsURILoader::OpenURI(nsIURI *aURI,
|
|
|
|
const char * aWindowTarget,
|
1999-11-30 00:00:52 +03:00
|
|
|
nsISupports * aWindowContext,
|
1999-11-10 09:24:40 +03:00
|
|
|
nsIURI *aReferringURI,
|
|
|
|
nsISupports *aOpenContext,
|
|
|
|
nsISupports **aCurrentOpenContext)
|
1999-11-06 02:06:16 +03:00
|
|
|
{
|
1999-11-30 00:00:52 +03:00
|
|
|
return OpenURIVia(aURI, aWindowTarget, aWindowContext, aReferringURI, aOpenContext,
|
|
|
|
aCurrentOpenContext, 0 /* ip address */);
|
1999-11-06 02:06:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsURILoader::OpenURIVia(nsIURI *aURI,
|
1999-11-10 09:24:40 +03:00
|
|
|
const char * aWindowTarget,
|
1999-11-30 00:00:52 +03:00
|
|
|
nsISupports * aWindowContext,
|
1999-11-10 09:24:40 +03:00
|
|
|
nsIURI *aReferringURI,
|
|
|
|
nsISupports *aOpenContext,
|
|
|
|
nsISupports **aCurrentOpenContext,
|
1999-11-18 23:47:57 +03:00
|
|
|
PRUint32 aLocalIP)
|
1999-11-30 00:00:52 +03:00
|
|
|
{
|
|
|
|
// forward our call
|
|
|
|
return OpenURIWithPostDataVia(aURI, aWindowTarget, aWindowContext, aReferringURI, nsnull /* post stream */,
|
|
|
|
aOpenContext,aCurrentOpenContext, aLocalIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsURILoader::OpenURIWithPostData(nsIURI *aURI,
|
|
|
|
const char *aWindowTarget,
|
|
|
|
nsISupports * aWindowContext,
|
|
|
|
nsIURI *aReferringURI,
|
|
|
|
nsIInputStream *aPostDataStream,
|
|
|
|
nsISupports *aOpenContext,
|
|
|
|
nsISupports **aCurrentOpenContext)
|
|
|
|
{
|
|
|
|
return OpenURIWithPostDataVia(aURI, aWindowTarget, aWindowContext, aReferringURI,
|
|
|
|
aPostDataStream, aOpenContext, aCurrentOpenContext, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsURILoader::OpenURIWithPostDataVia(nsIURI *aURI,
|
|
|
|
const char *aWindowTarget,
|
|
|
|
nsISupports * aWindowContext,
|
|
|
|
nsIURI *aReferringURI,
|
|
|
|
nsIInputStream *aPostDataStream,
|
|
|
|
nsISupports *aOpenContext,
|
|
|
|
nsISupports **aCurrentOpenContext,
|
|
|
|
PRUint32 adapterBinding)
|
1999-10-30 01:46:18 +04: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;
|
|
|
|
|
|
|
|
if (!aURI) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
NS_NEWXPCOM(loader, nsDocumentOpenInfo);
|
|
|
|
if (!loader) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(loader);
|
1999-11-30 00:00:52 +03:00
|
|
|
loader->Init(aWindowContext); // Extra Info
|
1999-11-05 09:01:40 +03:00
|
|
|
|
|
|
|
// now instruct the loader to go ahead and open the url
|
1999-11-30 00:00:52 +03:00
|
|
|
rv = loader->Open(aURI, aWindowTarget, aWindowContext,
|
|
|
|
aReferringURI, aPostDataStream, aOpenContext, aCurrentOpenContext);
|
1999-11-05 09:01:40 +03:00
|
|
|
NS_RELEASE(loader);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-30 00:00:52 +03:00
|
|
|
|
1999-11-05 09:01:40 +03:00
|
|
|
nsresult nsURILoader::DispatchContent(const char * aContentType,
|
1999-11-10 09:24:40 +03:00
|
|
|
const char * aCommand,
|
1999-11-05 09:01:40 +03:00
|
|
|
const char * aWindowTarget,
|
|
|
|
nsIChannel * aChannel,
|
|
|
|
nsISupports * aCtxt,
|
1999-11-16 00:35:40 +03:00
|
|
|
nsIURIContentListener * aContentListener,
|
1999-11-18 04:02:31 +03:00
|
|
|
char ** aContentTypeToUse,
|
|
|
|
nsIURIContentListener ** aContentListenerToUse)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
|
|
|
// okay, now we've discovered the content type. We need to do the following:
|
|
|
|
// (1) Give our uri content listener first crack at handling this content type.
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-11-06 02:06:16 +03:00
|
|
|
nsCOMPtr<nsIURIContentListener> listenerToUse = aContentListener;
|
|
|
|
// find a content handler that can and will handle the content
|
|
|
|
PRBool canHandleContent = PR_FALSE;
|
|
|
|
if (listenerToUse)
|
1999-11-18 04:02:31 +03:00
|
|
|
listenerToUse->CanHandleContent(aContentType, aCommand, aWindowTarget,
|
|
|
|
aContentTypeToUse,
|
|
|
|
&canHandleContent);
|
1999-11-06 02:06:16 +03:00
|
|
|
if (!canHandleContent) // if it can't handle the content, scan through the list of registered listeners
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
1999-11-06 02:06:16 +03:00
|
|
|
PRInt32 i = 0;
|
|
|
|
// keep looping until we are told to abort or we get a content listener back
|
|
|
|
for(i = 0; i < m_listeners->Count() && !canHandleContent; i++)
|
|
|
|
{
|
|
|
|
//nsIURIContentListener's aren't refcounted.
|
|
|
|
nsIURIContentListener * listener =(nsIURIContentListener*)m_listeners->ElementAt(i);
|
|
|
|
if (listener)
|
|
|
|
{
|
1999-11-18 04:02:31 +03:00
|
|
|
rv = listener->CanHandleContent(aContentType, aCommand, aWindowTarget,
|
|
|
|
aContentTypeToUse,
|
|
|
|
&canHandleContent);
|
1999-11-06 02:06:16 +03:00
|
|
|
if (canHandleContent)
|
|
|
|
listenerToUse = listener;
|
|
|
|
}
|
|
|
|
} // for loop
|
|
|
|
} // if we can't handle the content
|
|
|
|
|
|
|
|
|
|
|
|
if (canHandleContent && listenerToUse)
|
1999-11-05 09:01:40 +03:00
|
|
|
{
|
1999-11-18 04:02:31 +03:00
|
|
|
*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
|
|
|
|
1999-11-06 02:06:16 +03:00
|
|
|
nsCAutoString handlerProgID (NS_CONTENT_HANDLER_PROGID_PREFIX);
|
|
|
|
handlerProgID += aContentType;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentHandler> aContentHandler;
|
|
|
|
rv = nsComponentManager::CreateInstance(handlerProgID, nsnull, NS_GET_IID(nsIContentHandler), getter_AddRefs(aContentHandler));
|
|
|
|
if (NS_SUCCEEDED(rv)) // we did indeed have a content handler for this type!! yippee...
|
|
|
|
rv = aContentHandler->HandleContent(aContentType, aCommand, aWindowTarget, aChannel);
|
|
|
|
return rv;
|
1999-10-30 01:46:18 +04:00
|
|
|
}
|
|
|
|
|