зеркало из https://github.com/mozilla/pjs.git
Implemented the nsWBURIContentListener class and hooked it up to the build. It now sets itself as the parentURIListener for the internal docShell. Doing this makes the webBrowser control now the preferred handler for most webBrowser type loads. This fixes the problem where people who were embedding with this would always get a new window. Added a method to nsIWebBrowser to allow setting a parent URI Listener. Split the destruction of the webBrowser object into an InternalDestroy method. This fixes the odd construct where the destructor was calling Destroy and then having to clean up the Init structure that the Destroy method created.
This commit is contained in:
Родитель
ffe651e6f2
Коммит
84a6a00947
|
@ -36,6 +36,7 @@ XPIDLSRCS = \
|
|||
|
||||
CPPSRCS = \
|
||||
nsDocShellTreeOwner.cpp \
|
||||
nsWBURIContentListener.cpp \
|
||||
nsWebBrowser.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ LIBRARY_NAME=nsWebBrowser_s
|
|||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsDocShellTreeOwner.obj \
|
||||
.\$(OBJDIR)\nsWBURIContentListener.obj \
|
||||
.\$(OBJDIR)\nsWebBrowser.obj \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
interface nsIDocShell;
|
||||
interface nsIInterfaceRequestor;
|
||||
interface nsIWebBrowserChrome;
|
||||
interface nsIURIContentListener;
|
||||
|
||||
/**
|
||||
* The nsIWebBrowser
|
||||
|
@ -76,6 +77,13 @@ interface nsIWebBrowser : nsISupports
|
|||
*/
|
||||
attribute nsIWebBrowserChrome topLevelWindow;
|
||||
|
||||
/*
|
||||
URI content listener parent. This is not refcounted and is assumed to be
|
||||
nulled out by the parent when the parent is going away.
|
||||
*/
|
||||
attribute nsIURIContentListener parentURIContentListener;
|
||||
|
||||
|
||||
/*
|
||||
The root docShell of the browserWindow.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,197 @@
|
|||
/* -*- 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>
|
||||
*/
|
||||
|
||||
// Local Includes
|
||||
#include "nsWebBrowser.h"
|
||||
#include "nsWBURIContentListener.h"
|
||||
|
||||
// Interfaces Needed
|
||||
#include "nsIChannel.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//*** nsWBURIContentListener: Object Management
|
||||
//*****************************************************************************
|
||||
|
||||
nsWBURIContentListener::nsWBURIContentListener() : mWebBrowser(nsnull),
|
||||
mParentContentListener(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsWBURIContentListener::~nsWBURIContentListener()
|
||||
{
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsWBURIContentListener::nsISupports
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMPL_ADDREF(nsWBURIContentListener)
|
||||
NS_IMPL_RELEASE(nsWBURIContentListener)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsWBURIContentListener)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIContentListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
//*****************************************************************************
|
||||
// nsWBURIContentListener::nsIURIContentListener
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::OnStartURIOpen(nsIURI* aURI,
|
||||
const char* aWindowTarget, PRBool* aAbortOpen)
|
||||
{
|
||||
if(mParentContentListener)
|
||||
return mParentContentListener->OnStartURIOpen(aURI, aWindowTarget,
|
||||
aAbortOpen);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::DoContent(const char* aContentType,
|
||||
nsURILoadCommand aCommand, const char* aWindowTarget,
|
||||
nsIChannel* aOpenedChannel, nsIStreamListener** aContentHandler,
|
||||
PRBool* aAbortProcess)
|
||||
{
|
||||
NS_ERROR("Hmmmm, why is this getting called?");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::IsPreferred(const char* aContentType,
|
||||
nsURILoadCommand aCommand, const char* aWindowTarget, char ** aDesiredContentType,
|
||||
PRBool* aCanHandle)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCanHandle);
|
||||
NS_ENSURE_ARG_POINTER(aDesiredContentType);
|
||||
|
||||
if(mParentContentListener)
|
||||
return mParentContentListener->IsPreferred(aContentType, aCommand,
|
||||
aWindowTarget, aDesiredContentType, aCanHandle);
|
||||
else
|
||||
{
|
||||
*aCanHandle = PR_FALSE;
|
||||
// the webbrowser object is the primary content handler for the following types:
|
||||
// If we are asked to handle any of these types, we will always say Yes!
|
||||
// regardlesss of the uri load command.
|
||||
// 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
|
||||
|
||||
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
|
||||
|| nsCRT::strcasecmp(aContentType, "image/tiff") == 0
|
||||
|| nsCRT::strcasecmp(aContentType, "application/http-index-format") == 0)
|
||||
*aCanHandle = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::CanHandleContent(const char* aContentType,
|
||||
nsURILoadCommand aCommand, const char* aWindowTarget, char ** aDesiredContentType,
|
||||
PRBool* aCanHandleContent)
|
||||
{
|
||||
NS_ERROR("Hmmmm, why is this getting called?");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::GetLoadCookie(nsISupports ** aLoadCookie)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aLoadCookie);
|
||||
*aLoadCookie = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::SetLoadCookie(nsISupports * aLoadCookie)
|
||||
{
|
||||
NS_ERROR("Hmmmm, why is this getting called?");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::GetParentContentListener(nsIURIContentListener**
|
||||
aParentListener)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParentListener);
|
||||
|
||||
*aParentListener = mParentContentListener;
|
||||
NS_IF_ADDREF(*aParentListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWBURIContentListener::SetParentContentListener(nsIURIContentListener*
|
||||
aParentListener)
|
||||
{
|
||||
// Weak Reference, don't addref
|
||||
mParentContentListener = aParentListener;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsWBURIContentListener: Helpers
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
// nsWBURIContentListener: Accessors
|
||||
//*****************************************************************************
|
||||
|
||||
void nsWBURIContentListener::WebBrowser(nsWebBrowser* aWebBrowser)
|
||||
{
|
||||
mWebBrowser = aWebBrowser;
|
||||
}
|
||||
|
||||
nsWebBrowser* nsWBURIContentListener::WebBrowser()
|
||||
{
|
||||
return mWebBrowser;
|
||||
}
|
|
@ -44,8 +44,9 @@ static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
|
|||
//*** nsWebBrowser: Object Management
|
||||
//*****************************************************************************
|
||||
|
||||
nsWebBrowser::nsWebBrowser() : mDocShellTreeOwner(nsnull), mInitInfo(nsnull),
|
||||
mParentNativeWindow(nsnull), mParentWidget(nsnull), mParent(nsnull)
|
||||
nsWebBrowser::nsWebBrowser() : mDocShellTreeOwner(nsnull),
|
||||
mContentListener(nsnull), mInitInfo(nsnull), mParentNativeWindow(nsnull),
|
||||
mParentWidget(nsnull), mParent(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mInitInfo = new nsWebBrowserInitInfo();
|
||||
|
@ -53,17 +54,30 @@ nsWebBrowser::nsWebBrowser() : mDocShellTreeOwner(nsnull), mInitInfo(nsnull),
|
|||
|
||||
nsWebBrowser::~nsWebBrowser()
|
||||
{
|
||||
Destroy();
|
||||
InternalDestroy();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::InternalDestroy()
|
||||
{
|
||||
SetDocShell(nsnull);
|
||||
|
||||
if(mDocShellTreeOwner)
|
||||
{
|
||||
delete mDocShellTreeOwner;
|
||||
mDocShellTreeOwner = nsnull;
|
||||
mDocShellTreeOwner->WebBrowser(nsnull);
|
||||
NS_RELEASE(mDocShellTreeOwner);
|
||||
}
|
||||
if(mContentListener)
|
||||
{
|
||||
mContentListener->WebBrowser(nsnull);
|
||||
NS_RELEASE(mContentListener);
|
||||
}
|
||||
if(mInitInfo)
|
||||
{
|
||||
delete mInitInfo;
|
||||
mInitInfo = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
|
@ -149,6 +163,23 @@ NS_IMETHODIMP nsWebBrowser::SetTopLevelWindow(nsIWebBrowserChrome* aTopWindow)
|
|||
return mDocShellTreeOwner->SetWebBrowserChrome(aTopWindow);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::GetParentURIContentListener(nsIURIContentListener**
|
||||
aParentContentListener)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParentContentListener);
|
||||
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
||||
|
||||
return mContentListener->GetParentContentListener(aParentContentListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::SetParentURIContentListener(nsIURIContentListener*
|
||||
aParentContentListener)
|
||||
{
|
||||
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
||||
|
||||
return mContentListener->SetParentContentListener(aParentContentListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::GetDocShell(nsIDocShell** aDocShell)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDocShell);
|
||||
|
@ -483,6 +514,7 @@ NS_IMETHODIMP nsWebBrowser::Create()
|
|||
NS_ENSURE_STATE(!mDocShell && (mParentNativeWindow || mParentWidget));
|
||||
|
||||
NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIWidget> docShellParentWidget(mParentWidget);
|
||||
if(!mParentWidget) // We need to create a widget
|
||||
|
@ -524,6 +556,7 @@ NS_IMETHODIMP nsWebBrowser::Create()
|
|||
mDocShellAsItem->SetName(mInitInfo->name.GetUnicode());
|
||||
mDocShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent);
|
||||
mDocShellAsItem->SetTreeOwner(mDocShellTreeOwner);
|
||||
mDocShell->SetParentURIContentListener(mContentListener);
|
||||
|
||||
if(!mInitInfo->sessionHistory)
|
||||
mInitInfo->sessionHistory = do_CreateInstance(NS_SHISTORY_PROGID);
|
||||
|
@ -540,7 +573,7 @@ NS_IMETHODIMP nsWebBrowser::Create()
|
|||
|
||||
NS_IMETHODIMP nsWebBrowser::Destroy()
|
||||
{
|
||||
SetDocShell(nsnull);
|
||||
InternalDestroy();
|
||||
|
||||
if(!mInitInfo)
|
||||
mInitInfo = new nsWebBrowserInitInfo();
|
||||
|
@ -980,3 +1013,17 @@ NS_IMETHODIMP nsWebBrowser::EnsureDocShellTreeOwner()
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::EnsureContentListener()
|
||||
{
|
||||
if(mContentListener)
|
||||
return NS_OK;
|
||||
|
||||
mContentListener = new nsWBURIContentListener();
|
||||
NS_ENSURE_TRUE(mContentListener, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(mContentListener);
|
||||
mContentListener->WebBrowser(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
// Local Includes
|
||||
#include "nsDocShellTreeOwner.h"
|
||||
#include "nsWBURIContentListener.h"
|
||||
|
||||
// Core Includes
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -68,6 +69,7 @@ class nsWebBrowser : public nsIWebBrowser,
|
|||
public nsIInterfaceRequestor
|
||||
{
|
||||
friend class nsDocShellTreeOwner;
|
||||
friend class nsWBURIContentListener;
|
||||
public:
|
||||
nsWebBrowser();
|
||||
|
||||
|
@ -84,12 +86,15 @@ public:
|
|||
|
||||
protected:
|
||||
virtual ~nsWebBrowser();
|
||||
NS_IMETHOD InternalDestroy();
|
||||
|
||||
NS_IMETHOD SetDocShell(nsIDocShell* aDocShell);
|
||||
NS_IMETHOD EnsureDocShellTreeOwner();
|
||||
NS_IMETHOD EnsureContentListener();
|
||||
|
||||
protected:
|
||||
nsDocShellTreeOwner* mDocShellTreeOwner;
|
||||
nsWBURIContentListener* mContentListener;
|
||||
nsCOMPtr<nsISupportsArray> mListenerList;
|
||||
nsCOMPtr<nsIDocShell> mDocShell;
|
||||
nsCOMPtr<nsIInterfaceRequestor> mDocShellAsReq;
|
||||
|
|
Загрузка…
Ссылка в новой задаче