Removed nsIDocShellTreeOwner impl in control's chrome object because it was causing clicked links to open in new window. Cleaned up web browser creation and initialisation. b=82116 r=ccarlen@netscape.com sr=blizzard@mozilla.org

This commit is contained in:
locka%iol.ie 2001-05-22 21:31:01 +00:00
Родитель 55869b3c62
Коммит 971dce35c2
3 изменённых файлов: 82 добавлений и 145 удалений

Просмотреть файл

@ -844,8 +844,19 @@ BOOL CMozillaBrowser::IsValid()
// Initialises the web shell engine
HRESULT CMozillaBrowser::Initialize()
{
// Extract the bin directory path from the control's filename
#ifdef HACK_NON_REENTRANCY
// Attempt to open a named event for this process. If it's not there we
// know this is the first time the control has run in this process, so create
// the named event and do the initialisation. Otherwise do nothing.
TCHAR szHackEvent[255];
_stprintf(szHackEvent, _T("MozCtlEvent%d"), (int) GetCurrentProcessId());
s_hHackedNonReentrancy = OpenEvent(EVENT_ALL_ACCESS, FALSE, szHackEvent);
if (s_hHackedNonReentrancy == NULL)
{
s_hHackedNonReentrancy = CreateEvent(NULL, FALSE, FALSE, szHackEvent);
#endif
// Extract the bin directory path from the control's filename
TCHAR szMozCtlPath[MAX_PATH];
memset(szMozCtlPath, 0, sizeof(szMozCtlPath));
GetModuleFileName(_Module.m_hInst, szMozCtlPath, sizeof(szMozCtlPath) / sizeof(szMozCtlPath[0]));
@ -859,35 +870,25 @@ HRESULT CMozillaBrowser::Initialize()
_tsplitpath(szMozCtlPath, szTmpDrive, szTmpDir, szTmpFname, szTmpExt);
memset(szBinDirPath, 0, sizeof(szBinDirPath));
_tmakepath(szBinDirPath, szTmpDrive, szTmpDir, NULL, NULL);
#ifdef HACK_NON_REENTRANCY
// Attempt to open a named event for this process. If it's not there we
// know this is the first time the control has run in this process, so create
// the named event and do the initialisation. Otherwise do nothing.
TCHAR szHackEvent[255];
_stprintf(szHackEvent, _T("MozCtlEvent%d"), (int) GetCurrentProcessId());
s_hHackedNonReentrancy = OpenEvent(EVENT_ALL_ACCESS, FALSE, szHackEvent);
if (s_hHackedNonReentrancy == NULL)
if (_tcslen(szBinDirPath) == 0)
{
s_hHackedNonReentrancy = CreateEvent(NULL, FALSE, FALSE, szHackEvent);
#endif
// Create an object to represent the path
if (_tcslen(szBinDirPath) > 0)
{
nsCOMPtr<nsILocalFile> binDir;
USES_CONVERSION;
NS_NewLocalFile(T2A(szBinDirPath), TRUE, getter_AddRefs(binDir));
nsresult res = NS_InitEmbedding(binDir, nsnull);
}
else
{
NS_InitEmbedding(nsnull, nsnull);
return E_FAIL;
}
nsresult rv;
// Create a directory file loc object
nsCOMPtr<nsIDirectoryServiceProvider> provider; // nsnull for the moment
// TODO put alternative directory service provider here at some point
// Create an object to represent the path
nsCOMPtr<nsILocalFile> binDir;
USES_CONVERSION;
NS_NewLocalFile(T2A(szBinDirPath), TRUE, getter_AddRefs(binDir));
rv = NS_InitEmbedding(binDir, provider);
// Load preferences service
nsresult rv = nsServiceManager::GetService(kPrefCID,
rv = nsServiceManager::GetService(kPrefCID,
NS_GET_IID(nsIPref),
(nsISupports **)&mPrefs);
if (NS_FAILED(rv))
@ -946,7 +947,6 @@ HRESULT CMozillaBrowser::Initialize()
return S_OK;
}
// Terminates the web shell engine
HRESULT CMozillaBrowser::Terminate()
{
@ -999,7 +999,6 @@ HRESULT CMozillaBrowser::CreateBrowser()
return rv;
}
// Configure what the web browser can and cannot do
nsCOMPtr<nsIWebBrowserSetup> webBrowserAsSetup(do_QueryInterface(mWebBrowser));
// webBrowserAsSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS, aAllowPlugins);
@ -1021,29 +1020,18 @@ HRESULT CMozillaBrowser::CreateBrowser()
}
mWebBrowserContainer->AddRef();
// Set up the web shell
mWebBrowser->SetParentURIContentListener(mWebBrowserContainer);
// XXX delete when tree owner is not necessary (to receive context menu events)
nsCOMPtr<nsIDocShellTreeItem> browserAsItem = do_QueryInterface(mWebBrowser);
browserAsItem->SetTreeOwner(NS_STATIC_CAST(nsIDocShellTreeOwner *, mWebBrowserContainer));
// XXX delete when docshell becomes inaccessible
nsCOMPtr<nsIDocShell> rootDocShell = do_GetInterface(mWebBrowser);
if (rootDocShell == nsnull)
{
NG_ASSERT(0);
NG_TRACE_ALWAYS(_T("Could not get root docshell object rv=%08x\n"), (int) rv);
SetStartupErrorMessage(IDS_CANNOTCREATEPREFS);
return rv;
}
mWebBrowserAsWin->SetVisibility(PR_TRUE);
// Set up the browser with its chrome
mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, mWebBrowserContainer));
mWebBrowser->SetParentURIContentListener(mWebBrowserContainer);
// Subscribe for progress notifications
nsCOMPtr<nsIWeakReference> listener(
dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, mWebBrowserContainer))));
mWebBrowser->AddWebBrowserListener(listener, NS_GET_IID(nsIWebProgressListener));
// Visible
mWebBrowserAsWin->SetVisibility(PR_TRUE);
// Append browser to browser list
sBrowserList.AppendElement(this);

Просмотреть файл

@ -30,6 +30,8 @@
#include "WebBrowserContainer.h"
#include "nsICategoryManager.h"
CWebBrowserContainer::CWebBrowserContainer(CMozillaBrowser *pOwner)
{
NS_INIT_REFCNT();
@ -56,7 +58,6 @@ NS_INTERFACE_MAP_BEGIN(CWebBrowserContainer)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner)
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
@ -367,7 +368,7 @@ NS_IMETHODIMP CWebBrowserContainer::OnStartURIOpen(nsIURI *pURI, PRBool *aAbortO
m_pEvents1->Fire_DownloadComplete();
m_pEvents2->Fire_DownloadComplete();
return NS_ERROR_NOT_IMPLEMENTED;
return NS_OK;
}
/* void getProtocolHandler (in nsIURI aURI, out nsIProtocolHandler aProtocolHandler); */
@ -387,14 +388,34 @@ NS_IMETHODIMP CWebBrowserContainer::DoContent(const char *aContentType, nsURILoa
/* boolean isPreferred (in string aContentType, in nsURILoadCommand aCommand, out string aDesiredContentType); */
NS_IMETHODIMP CWebBrowserContainer::IsPreferred(const char *aContentType, nsURILoadCommand aCommand, char **aDesiredContentType, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
return CanHandleContent(aContentType, aCommand, aDesiredContentType, _retval);
}
/* boolean canHandleContent (in string aContentType, in nsURILoadCommand aCommand, out string aDesiredContentType); */
NS_IMETHODIMP CWebBrowserContainer::CanHandleContent(const char *aContentType, nsURILoadCommand aCommand, char **aDesiredContentType, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (aContentType)
{
nsCOMPtr<nsICategoryManager> catMgr;
nsresult rv;
catMgr = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
nsXPIDLCString value;
rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers",
aContentType,
getter_Copies(value));
// If the category manager can't find what we're looking for
// it returns NS_ERROR_NOT_AVAILABLE, we don't wanto propagate
// that to the caller since it's really not a failure
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE)
return rv;
if (value && *value)
*_retval = PR_TRUE;
}
return NS_OK;
}
@ -424,100 +445,6 @@ NS_IMETHODIMP CWebBrowserContainer::SetParentContentListener(nsIURIContentListen
}
///////////////////////////////////////////////////////////////////////////////
// nsIDocShellTreeOwner
NS_IMETHODIMP
CWebBrowserContainer::FindItemWithName(const PRUnichar* aName,
nsIDocShellTreeItem* aRequestor, nsIDocShellTreeItem** aFoundItem)
{
return NS_ERROR_FAILURE;
/*
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(m_pOwner->mWebBrowser));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
return docShellAsItem->FindItemWithName(aName, NS_STATIC_CAST(nsIWebBrowserChrome*, this), aFoundItem);
*/
}
static nsIDocShellTreeItem* contentShell = nsnull;
NS_IMETHODIMP
CWebBrowserContainer::ContentShellAdded(nsIDocShellTreeItem* aContentShell,
PRBool aPrimary, const PRUnichar* aID)
{
if (aPrimary)
contentShell = aContentShell;
return NS_OK;
}
NS_IMETHODIMP
CWebBrowserContainer::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
{
// NS_ERROR("Haven't Implemented this yet");
NS_IF_ADDREF(contentShell);
*aShell = contentShell;
return NS_OK;
}
NS_IMETHODIMP
CWebBrowserContainer::SizeShellTo(nsIDocShellTreeItem* aShell,
PRInt32 aCX, PRInt32 aCY)
{
// Ignore request to be resized
return NS_OK;
}
NS_IMETHODIMP CWebBrowserContainer::GetNewWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem)
{
IDispatch *pDispNew = NULL;
VARIANT_BOOL bCancel = VARIANT_FALSE;
*aDocShellTreeItem = nsnull;
// Test if the event sink can give us a new window to navigate into
m_pEvents2->Fire_NewWindow2(&pDispNew, &bCancel);
if ((bCancel == VARIANT_FALSE) && pDispNew)
{
CComQIPtr<IMozControlBridge, &IID_IMozControlBridge> cpBridge = pDispNew;
if (cpBridge)
{
nsIWebBrowser *browser = nsnull;
cpBridge->GetWebBrowser((void **) &browser);
if (browser)
{
nsCOMPtr<nsIDocShell> docshell = do_GetInterface(browser);
docshell->QueryInterface(NS_GET_IID(nsIDocShellTreeItem), (void **) aDocShellTreeItem);
NS_RELEASE(browser);
}
}
pDispNew->Release();
}
return (*aDocShellTreeItem) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
CWebBrowserContainer::SetPersistence(PRBool aPersistPosition,
PRBool aPersistSize,
PRBool aPersistSizeMode)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CWebBrowserContainer::GetPersistence(PRBool* aPersistPosition,
PRBool* aPersistSize,
PRBool* aPersistSizeMode)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
///////////////////////////////////////////////////////////////////////////////
// nsIEmbeddingSiteWindow
@ -622,6 +549,30 @@ CWebBrowserContainer::SetChromeFlags(PRUint32 aChromeFlags)
NS_IMETHODIMP
CWebBrowserContainer::CreateBrowserWindow(PRUint32 chromeFlags, PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, nsIWebBrowser **_retval)
{
IDispatch *pDispNew = NULL;
VARIANT_BOOL bCancel = VARIANT_FALSE;
*_retval = nsnull;
// Test if the event sink can give us a new window to navigate into
m_pEvents2->Fire_NewWindow2(&pDispNew, &bCancel);
if ((bCancel == VARIANT_FALSE) && pDispNew)
{
CComQIPtr<IMozControlBridge, &IID_IMozControlBridge> cpBridge = pDispNew;
if (cpBridge)
{
nsIWebBrowser *browser = nsnull;
cpBridge->GetWebBrowser((void **) &browser);
if (browser)
{
*_retval = browser;
return NS_OK;
}
}
pDispNew->Release();
}
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -40,7 +40,6 @@ class CWebBrowserContainer :
public nsIWebProgressListener,
public nsIRequestObserver,
public nsIURIContentListener,
public nsIDocShellTreeOwner,
public nsIInterfaceRequestor,
public nsIContextMenuListener,
public nsICommandHandler,
@ -67,7 +66,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIDOCSHELLTREEOWNER
NS_DECL_NSIURICONTENTLISTENER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSIINTERFACEREQUESTOR