2001-04-13 17:05:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1999-11-06 07:51:05 +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>
|
|
|
|
*/
|
|
|
|
|
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"
|
2001-04-17 03:05:08 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2001-11-27 04:22:34 +03:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
1999-11-06 07:51:05 +03:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsDSURIContentListener: Object Management
|
|
|
|
//*****************************************************************************
|
|
|
|
|
1999-12-21 03:09:48 +03:00
|
|
|
nsDSURIContentListener::nsDSURIContentListener() : mDocShell(nsnull),
|
2001-04-13 17:05:16 +04:00
|
|
|
mParentContentListener(nsnull)
|
1999-11-06 07:51:05 +03:00
|
|
|
{
|
2001-04-13 17:05:16 +04:00
|
|
|
NS_INIT_REFCNT();
|
1999-11-06 07:51:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDSURIContentListener::~nsDSURIContentListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-04-17 03:05:08 +04:00
|
|
|
nsresult
|
|
|
|
nsDSURIContentListener::Init()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
mCatMgr = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
2001-12-03 15:42:49 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-04-17 03:05:08 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-06 07:51:05 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// 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)
|
2001-04-13 17:05:16 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIContentListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
|
2000-01-14 11:16:50 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
1999-11-06 07:51:05 +03:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsDSURIContentListener::nsIURIContentListener
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::OnStartURIOpen(nsIURI* aURI, PRBool* aAbortOpen)
|
2000-03-24 03:26:51 +03:00
|
|
|
{
|
2001-04-13 17:05:16 +04:00
|
|
|
if(mParentContentListener)
|
2001-05-14 06:16:27 +04:00
|
|
|
return mParentContentListener->OnStartURIOpen(aURI, aAbortOpen);
|
2000-03-24 03:26:51 +03:00
|
|
|
|
2001-04-13 17:05:16 +04:00
|
|
|
return NS_OK;
|
2000-03-24 03:26:51 +03:00
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::DoContent(const char* aContentType,
|
2001-10-27 06:52:39 +04:00
|
|
|
PRBool aIsContentPreferred,
|
2001-05-14 06:16:27 +04:00
|
|
|
nsIRequest* request,
|
|
|
|
nsIStreamListener** aContentHandler,
|
|
|
|
PRBool* aAbortProcess)
|
1999-11-06 07:51:05 +03:00
|
|
|
{
|
2001-05-14 06:16:27 +04:00
|
|
|
nsresult rv;
|
2001-04-13 17:05:16 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aContentHandler);
|
2001-04-14 02:26:28 +04:00
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
2001-04-13 17:05:16 +04:00
|
|
|
if(aAbortProcess)
|
|
|
|
*aAbortProcess = PR_FALSE;
|
2000-02-17 04:58:34 +03:00
|
|
|
|
2001-04-13 17:05:16 +04:00
|
|
|
// determine if the channel has just been retargeted to us...
|
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
nsCOMPtr<nsIChannel> aOpenedChannel = do_QueryInterface(request);
|
2000-02-17 04:58:34 +03:00
|
|
|
|
2001-04-14 02:26:28 +04:00
|
|
|
if (aOpenedChannel)
|
|
|
|
aOpenedChannel->GetLoadFlags(&loadFlags);
|
2000-10-12 03:17:02 +04:00
|
|
|
|
2001-04-14 06:02:19 +04:00
|
|
|
if(loadFlags & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI)
|
2001-04-13 17:05:16 +04:00
|
|
|
{
|
2001-08-14 08:46:20 +04:00
|
|
|
// XXX: Why does this not stop the content too?
|
|
|
|
mDocShell->Stop(nsIWebNavigation::STOP_NETWORK);
|
2001-10-29 09:03:27 +03:00
|
|
|
|
|
|
|
mDocShell->SetLoadType(aIsContentPreferred ? LOAD_LINK : LOAD_NORMAL);
|
2001-04-13 17:05:16 +04:00
|
|
|
}
|
2000-02-17 04:58:34 +03:00
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
rv = mDocShell->CreateContentViewer(aContentType, request, aContentHandler);
|
2001-08-24 22:45:11 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// it's okay if we don't know how to handle the content
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-06 07:51:05 +03:00
|
|
|
|
2001-11-27 04:22:34 +03:00
|
|
|
if (loadFlags & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI) {
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_GetInterface(NS_STATIC_CAST(nsIDocShell*, mDocShell));
|
2001-12-03 15:42:49 +03:00
|
|
|
NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
|
2001-11-27 04:22:34 +03:00
|
|
|
domWindow->Focus();
|
|
|
|
}
|
2001-04-13 17:05:16 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-06 07:51:05 +03:00
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::IsPreferred(const char* aContentType,
|
|
|
|
char ** aDesiredContentType,
|
|
|
|
PRBool* aCanHandle)
|
1999-11-06 07:51:05 +03:00
|
|
|
{
|
2001-04-13 17:05:16 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aCanHandle);
|
|
|
|
NS_ENSURE_ARG_POINTER(aDesiredContentType);
|
|
|
|
|
|
|
|
// 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...
|
|
|
|
|
2001-10-27 06:52:39 +04:00
|
|
|
if(mParentContentListener) {
|
2001-05-14 06:16:27 +04:00
|
|
|
return mParentContentListener->IsPreferred(aContentType,
|
|
|
|
aDesiredContentType,
|
|
|
|
aCanHandle);
|
2001-04-13 17:05:16 +04:00
|
|
|
}
|
2001-10-27 06:52:39 +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,
|
|
|
|
PR_TRUE,
|
|
|
|
aDesiredContentType,
|
|
|
|
aCanHandle);
|
1999-11-06 07:51:05 +03:00
|
|
|
}
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::CanHandleContent(const char* aContentType,
|
2001-10-27 06:52:39 +04:00
|
|
|
PRBool aIsContentPreferred,
|
2001-05-14 06:16:27 +04:00
|
|
|
char ** aDesiredContentType,
|
|
|
|
PRBool* aCanHandleContent)
|
2000-02-04 11:45:34 +03:00
|
|
|
{
|
2001-05-14 06:16:27 +04:00
|
|
|
nsresult rv;
|
2001-04-13 17:05:16 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aCanHandleContent);
|
|
|
|
NS_ENSURE_ARG_POINTER(aDesiredContentType);
|
|
|
|
|
2001-05-14 06:16:27 +04:00
|
|
|
*aCanHandleContent = PR_FALSE;
|
|
|
|
|
2001-12-03 15:42:49 +03:00
|
|
|
if (aContentType && mCatMgr)
|
2001-04-13 17:05:16 +04:00
|
|
|
{
|
2001-04-17 03:05:08 +04:00
|
|
|
nsXPIDLCString value;
|
2001-05-14 06:16:27 +04:00
|
|
|
rv = mCatMgr->GetCategoryEntry("Gecko-Content-Viewers",
|
|
|
|
aContentType,
|
2001-04-17 03:05:08 +04:00
|
|
|
getter_Copies(value));
|
2001-05-18 01:33:16 +04:00
|
|
|
|
|
|
|
// If the category manager can't find what we're looking for
|
2001-12-24 02:23:41 +03:00
|
|
|
// it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate
|
2001-05-18 01:33:16 +04:00
|
|
|
// that to the caller since it's really not a failure
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE)
|
|
|
|
return rv;
|
2001-04-17 03:05:08 +04:00
|
|
|
|
|
|
|
if (value && *value)
|
2001-04-17 00:17:36 +04:00
|
|
|
*aCanHandleContent = PR_TRUE;
|
2001-04-13 17:05:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-04 11:45:34 +03:00
|
|
|
}
|
|
|
|
|
2000-05-06 10:05:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::GetLoadCookie(nsISupports ** aLoadCookie)
|
2000-03-11 03:49:47 +03:00
|
|
|
{
|
2001-04-13 17:05:16 +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
|
|
|
{
|
2001-04-13 17:05:16 +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
|
|
|
{
|
2001-04-13 17:05:16 +04:00
|
|
|
*aParentListener = mParentContentListener;
|
|
|
|
NS_IF_ADDREF(*aParentListener);
|
|
|
|
return NS_OK;
|
2000-01-29 09:10:54 +03:00
|
|
|
}
|
|
|
|
|
2000-05-06 10:05:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDSURIContentListener::SetParentContentListener(nsIURIContentListener*
|
|
|
|
aParentListener)
|
2000-01-29 09:10:54 +03:00
|
|
|
{
|
2001-04-13 17:05:16 +04:00
|
|
|
// Weak Reference, don't addref
|
|
|
|
mParentContentListener = aParentListener;
|
|
|
|
return NS_OK;
|
2000-01-29 09:10:54 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2001-04-13 17:05:16 +04: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
|
|
|
{
|
2001-04-13 17:05:16 +04:00
|
|
|
return mDocShell;
|
2000-03-25 10:58:28 +03:00
|
|
|
}
|