1999-11-06 07:51:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
*/
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
#include "nsDocShell.h"
|
1999-11-06 07:51:05 +03:00
|
|
|
#include "nsDSURIContentListener.h"
|
2000-01-29 09:10:54 +03:00
|
|
|
#include "nsIChannel.h"
|
1999-11-06 07:51:05 +03:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsDSURIContentListener: Object Management
|
|
|
|
//*****************************************************************************
|
|
|
|
|
1999-12-21 03:09:48 +03:00
|
|
|
nsDSURIContentListener::nsDSURIContentListener() : mDocShell(nsnull),
|
|
|
|
mParentContentListener(nsnull)
|
1999-11-06 07:51:05 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDSURIContentListener::~nsDSURIContentListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDSURIContentListener::nsISupports
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2000-04-16 17:00:52 +04:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsDSURIContentListener)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsDSURIContentListener)
|
2000-01-14 11:16:50 +03:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDSURIContentListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIContentListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-11-06 07:51:05 +03:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDSURIContentListener::nsIURIContentListener
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2000-03-24 03:26:51 +03:00
|
|
|
NS_IMETHODIMP nsDSURIContentListener::OnStartURIOpen(nsIURI* aURI,
|
|
|
|
const char* aWindowTarget, PRBool* aAbortOpen)
|
|
|
|
{
|
|
|
|
if(mParentContentListener)
|
|
|
|
return mParentContentListener->OnStartURIOpen(aURI, aWindowTarget,
|
|
|
|
aAbortOpen);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-06 07:51:05 +03:00
|
|
|
NS_IMETHODIMP nsDSURIContentListener::GetProtocolHandler(nsIURI* aURI,
|
|
|
|
nsIProtocolHandler** aProtocolHandler)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aProtocolHandler);
|
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
|
|
|
if(mParentContentListener)
|
|
|
|
return mParentContentListener->GetProtocolHandler(aURI, aProtocolHandler);
|
|
|
|
else
|
|
|
|
*aProtocolHandler = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-01 01:32:24 +03:00
|
|
|
NS_IMETHODIMP nsDSURIContentListener::DoContent(const char* aContentType,
|
|
|
|
nsURILoadCommand aCommand, const char* aWindowTarget,
|
2001-02-10 03:16:26 +03:00
|
|
|
nsIRequest* request, nsIStreamListener** aContentHandler,
|
2000-03-01 01:32:24 +03:00
|
|
|
PRBool* aAbortProcess)
|
1999-11-06 07:51:05 +03:00
|
|
|
{
|
2000-02-17 04:58:34 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aContentHandler);
|
|
|
|
if(aAbortProcess)
|
|
|
|
*aAbortProcess = PR_FALSE;
|
|
|
|
|
|
|
|
// determine if the channel has just been retargeted to us...
|
|
|
|
nsLoadFlags loadAttribs = 0;
|
2001-02-10 03:16:26 +03:00
|
|
|
nsCOMPtr<nsIChannel> aOpenedChannel = do_QueryInterface(request);
|
|
|
|
|
2000-02-17 04:58:34 +03:00
|
|
|
aOpenedChannel->GetLoadAttributes(&loadAttribs);
|
|
|
|
|
2000-10-12 03:17:02 +04:00
|
|
|
PRUint32 loadType = mDocShell->ConvertDocShellLoadInfoToLoadType((nsDocShellInfoLoadType) aCommand);
|
|
|
|
mDocShell->SetLoadType(loadType);
|
|
|
|
|
2000-02-17 04:58:34 +03:00
|
|
|
if(loadAttribs & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI)
|
2000-09-02 02:35:05 +04:00
|
|
|
{
|
2000-06-19 09:54:37 +04:00
|
|
|
mDocShell->StopLoad();
|
2000-09-02 02:35:05 +04:00
|
|
|
}
|
2000-02-17 04:58:34 +03:00
|
|
|
|
2000-06-22 10:55:10 +04:00
|
|
|
nsresult rv = mDocShell->CreateContentViewer(aContentType,
|
2001-02-10 03:16:26 +03:00
|
|
|
request, aContentHandler);
|
2000-09-02 02:35:05 +04:00
|
|
|
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; // it's okay if we don't know how to handle the content
|
2000-02-17 04:58:34 +03:00
|
|
|
|
|
|
|
if(loadAttribs & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI)
|
|
|
|
mDocShell->SetFocus();
|
1999-11-06 07:51:05 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-04 11:45:34 +03:00
|
|
|
NS_IMETHODIMP nsDSURIContentListener::IsPreferred(const char* aContentType,
|
1999-12-02 10:01:11 +03:00
|
|
|
nsURILoadCommand aCommand, const char* aWindowTarget, char ** aDesiredContentType, PRBool* aCanHandle)
|
1999-11-06 07:51:05 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCanHandle);
|
1999-11-18 04:09:56 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aDesiredContentType);
|
|
|
|
|
2000-02-04 11:45:34 +03:00
|
|
|
// the docshell has no idea if it is the preferred content provider or not.
|
|
|
|
// It needs to ask it's parent if it is the preferred content handler or not...
|
|
|
|
|
|
|
|
if(mParentContentListener)
|
|
|
|
return mParentContentListener->IsPreferred(aContentType, aCommand,
|
|
|
|
aWindowTarget, aDesiredContentType, aCanHandle);
|
|
|
|
else
|
2000-08-26 06:52:09 +04:00
|
|
|
{
|
|
|
|
// we used to return false here if we didn't have a parent properly registered at the top of
|
|
|
|
// the docshell hierarchy to dictate what content types this docshell should be a preferred handler for.
|
|
|
|
// But this really makes it hard for developers using iframe or browser tags because then they need to
|
|
|
|
// make sure they implement nsIURIContentListener otherwise all link clicks would get sent to another window
|
|
|
|
// because we said we weren't the preferred handler type. I'm going to change the default now...if we can handle the
|
|
|
|
// content, and someone didn't EXPLICITLY set a nsIURIContentListener at the top of our docshell chain, then we'll
|
|
|
|
// now always attempt to process the content ourselves...
|
|
|
|
return CanHandleContent(aContentType, aCommand, aWindowTarget, aDesiredContentType, aCanHandle);
|
|
|
|
}
|
1999-11-06 07:51:05 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-04 11:45:34 +03:00
|
|
|
NS_IMETHODIMP nsDSURIContentListener::CanHandleContent(const char* aContentType,
|
|
|
|
nsURILoadCommand aCommand, const char* aWindowTarget, char ** aDesiredContentType, PRBool* aCanHandleContent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCanHandleContent);
|
|
|
|
NS_ENSURE_ARG_POINTER(aDesiredContentType);
|
|
|
|
|
|
|
|
// this implementation should be the same for all webshell's so no need to pass it up the chain...
|
|
|
|
// although I suspect if aWindowTarget has a value, we will need to pass it up the chain in order to find
|
|
|
|
// the desired window target.
|
|
|
|
|
|
|
|
// a webshell can handle the following types. Eventually I think we want to get this information
|
|
|
|
// from the registry and in addition, we want to
|
|
|
|
// incoming Type Preferred type
|
|
|
|
// text/html
|
|
|
|
// text/xul
|
|
|
|
// text/rdf
|
|
|
|
// text/xml
|
|
|
|
// text/css
|
|
|
|
// image/gif
|
|
|
|
// image/jpeg
|
|
|
|
// image/png
|
|
|
|
// image/tiff
|
|
|
|
// application/http-index-format
|
|
|
|
// message/rfc822 text/xul
|
|
|
|
|
|
|
|
if (aContentType)
|
|
|
|
{
|
|
|
|
// (1) list all content types we want to be the primary handler for....
|
|
|
|
// and suggest a desired content type if appropriate...
|
|
|
|
if (nsCRT::strcasecmp(aContentType, "text/html") == 0
|
|
|
|
|| nsCRT::strcasecmp(aContentType, "text/xul") == 0
|
|
|
|
|| nsCRT::strcasecmp(aContentType, "text/rdf") == 0
|
|
|
|
|| nsCRT::strcasecmp(aContentType, "text/xml") == 0
|
|
|
|
|| nsCRT::strcasecmp(aContentType, "text/css") == 0
|
|
|
|
|| nsCRT::strcasecmp(aContentType, "image/gif") == 0
|
|
|
|
|| nsCRT::strcasecmp(aContentType, "image/jpeg") == 0
|
|
|
|
|| nsCRT::strcasecmp(aContentType, "image/png") == 0
|
2000-07-11 09:09:42 +04:00
|
|
|
|| nsCRT::strcasecmp(aContentType, "text/plain") == 0
|
2000-02-04 11:45:34 +03:00
|
|
|
|| nsCRT::strcasecmp(aContentType, "image/tiff") == 0
|
|
|
|
|| nsCRT::strcasecmp(aContentType, "application/http-index-format") == 0)
|
|
|
|
*aCanHandleContent = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*aCanHandleContent = PR_FALSE;
|
|
|
|
|
|
|
|
// we may need to ask the plugin manager for this webshell if it can handle the content type too...
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-06 10:05:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::GetLoadCookie(nsISupports ** aLoadCookie)
|
2000-03-11 03:49:47 +03:00
|
|
|
{
|
2000-06-20 12:01:19 +04:00
|
|
|
return mDocShell->GetLoadCookie(aLoadCookie);
|
2000-03-11 03:49:47 +03:00
|
|
|
}
|
|
|
|
|
2000-05-06 10:05:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::SetLoadCookie(nsISupports * aLoadCookie)
|
2000-03-11 03:49:47 +03:00
|
|
|
{
|
2000-06-20 12:01:19 +04:00
|
|
|
return mDocShell->SetLoadCookie(aLoadCookie);
|
2000-03-11 03:49:47 +03:00
|
|
|
}
|
|
|
|
|
2000-05-06 10:05:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::GetParentContentListener(nsIURIContentListener**
|
|
|
|
aParentListener)
|
2000-01-29 09:10:54 +03:00
|
|
|
{
|
|
|
|
*aParentListener = mParentContentListener;
|
|
|
|
NS_IF_ADDREF(*aParentListener);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-06 10:05:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::SetParentContentListener(nsIURIContentListener*
|
|
|
|
aParentListener)
|
2000-01-29 09:10:54 +03:00
|
|
|
{
|
|
|
|
// Weak Reference, don't addref
|
|
|
|
mParentContentListener = aParentListener;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-06 07:51:05 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsDSURIContentListener: Helpers
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDSURIContentListener: Accessors
|
|
|
|
//*****************************************************************************
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
void nsDSURIContentListener::DocShell(nsDocShell* aDocShell)
|
1999-11-06 07:51:05 +03:00
|
|
|
{
|
1999-11-12 10:28:25 +03:00
|
|
|
mDocShell = aDocShell;
|
1999-11-06 07:51:05 +03:00
|
|
|
}
|
|
|
|
|
1999-11-12 10:28:25 +03:00
|
|
|
nsDocShell* nsDSURIContentListener::DocShell()
|
1999-11-06 07:51:05 +03:00
|
|
|
{
|
|
|
|
return mDocShell;
|
2000-03-25 10:58:28 +03:00
|
|
|
}
|