Implement nsIWindowCreator service for ActiveX control. r=danm@netscape.com sr=rpotts@netscape.com

git-svn-id: svn://10.0.0.236/trunk@109012 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
locka%iol.ie 2001-11-27 20:13:43 +00:00
parent 5c84a7ab0a
commit 3b1d6316a3
7 changed files with 207 additions and 15 deletions

View File

@ -21,8 +21,6 @@
*
* Contributor(s):
* Adam Lock <adamlock@netscape.com>
* Pierre Phaneuf <pp@ludusdesign.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -50,6 +48,7 @@
#include "IEHtmlDocument.h"
#include "PropertyDlg.h"
#include "PromptService.h"
#include "WindowCreator.h"
#include "nsCWebBrowser.h"
#include "nsILocalFile.h"
@ -62,6 +61,7 @@
#include "nsIWebBrowserPrint.h"
#include "nsIWidget.h"
#include "nsIWebBrowserFocus.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindowInternal.h"
#include "nsIDOMHTMLAnchorElement.h"
@ -997,18 +997,6 @@ HRESULT CMozillaBrowser::Initialize()
return E_FAIL;
}
// Register our own native prompting service for message boxes, login
// prompts etc.
nsCOMPtr<nsIFactory> promptFactory;
rv = NS_NewPromptServiceFactory(getter_AddRefs(promptFactory));
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::RegisterFactory(kPromptServiceCID,
"Prompt Service",
"@mozilla.org/embedcomp/prompt-service;1",
promptFactory,
PR_TRUE); // replace existing
// Make a new default profile
nsAutoString newProfileName; newProfileName.AssignWithConversion("MozillaControl");
PRBool profileExists = PR_FALSE;
@ -1031,6 +1019,33 @@ HRESULT CMozillaBrowser::Initialize()
return E_FAIL;
}
// Stuff in here only needs to be done once
static BOOL bRegisterComponents = FALSE;
if (!bRegisterComponents)
{
// Register our own native prompting service for message boxes, login
// prompts etc.
nsCOMPtr<nsIFactory> promptFactory;
rv = NS_NewPromptServiceFactory(getter_AddRefs(promptFactory));
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::RegisterFactory(kPromptServiceCID,
"Prompt Service",
"@mozilla.org/embedcomp/prompt-service;1",
promptFactory,
PR_TRUE); // replace existing
// create our local object
CWindowCreator *creator = new CWindowCreator();
nsCOMPtr<nsIWindowCreator> windowCreator;
windowCreator = NS_STATIC_CAST(nsIWindowCreator *, creator);
// Attach it via the watcher service
nsCOMPtr<nsIWindowWatcher> watcher =
do_GetService("@mozilla.org/embedcomp/window-watcher;1");
if (watcher)
watcher->SetWindowCreator(windowCreator);
}
#ifdef HACK_NON_REENTRANCY
}
#endif

View File

@ -158,8 +158,16 @@ SOURCE=.\StdAfx.cpp
# End Source File
# Begin Source File
SOURCE=.\TextProviderService.cpp
# End Source File
# Begin Source File
SOURCE=.\WebBrowserContainer.cpp
# End Source File
# Begin Source File
SOURCE=.\WindowCreator.cpp
# End Source File
# End Group
# Begin Group "Header Files"
@ -254,8 +262,16 @@ SOURCE=.\StdAfx.h
# End Source File
# Begin Source File
SOURCE=.\TextProviderService.h
# End Source File
# Begin Source File
SOURCE=.\WebBrowserContainer.h
# End Source File
# Begin Source File
SOURCE=.\WindowCreator.h
# End Source File
# End Group
# Begin Group "Resource Files"

View File

@ -167,6 +167,7 @@ typedef long int32;
#include "IEHtmlDocument.h"
#include "CPMozillaControl.h"
#include "MozillaBrowser.h"
#include "WindowCreator.h"
#include "WebBrowserContainer.h"
#include "DropTarget.h"
#include "guids.h"

View File

@ -47,7 +47,6 @@
#include "nsIWebBrowserChromeFocus.h"
#include "nsWeakReference.h"
// This is the class that handles the XPCOM side of things, callback
// interfaces into the web shell and so forth.
@ -67,6 +66,7 @@ public:
CWebBrowserContainer(CMozillaBrowser *pOwner);
friend CMozillaBrowser;
friend CWindowCreator;
protected:
virtual ~CWebBrowserContainer();

View File

@ -0,0 +1,101 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Adam Lock <adamlock@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "stdafx.h"
#include "WindowCreator.h"
NS_IMPL_ISUPPORTS1(CWindowCreator, nsIWindowCreator)
CWindowCreator::CWindowCreator(void)
{
NS_INIT_REFCNT();
}
CWindowCreator::~CWindowCreator()
{
}
NS_IMETHODIMP
CWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent, PRUint32 aChromeFlags, nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
// NOTE:
//
// The nsIWindowCreator::CreateChromeWindow is REQUIRED to handle a nsnull
// parent window but this implementation must have one in order to fire
// events to the ActiveX container. Therefore we treat a nsnull aParent
// as an error and return.
if (aParent == nsnull)
{
return NS_ERROR_FAILURE;
}
CWebBrowserContainer *pContainer = NS_STATIC_CAST(CWebBrowserContainer *, aParent);
CComQIPtr<IDispatch> dispNew;
VARIANT_BOOL bCancel = VARIANT_FALSE;
// Test if the event sink can give us a new window to navigate into
if (pContainer->m_pEvents2)
{
pContainer->m_pEvents2->Fire_NewWindow2(&dispNew, &bCancel);
if ((bCancel == VARIANT_FALSE) && dispNew)
{
CComQIPtr<IMozControlBridge> cpBridge = dispNew;
if (cpBridge)
{
nsIWebBrowser *browser = nsnull;
cpBridge->GetWebBrowser((void **) &browser);
if (browser)
{
nsresult rv = browser->GetContainerWindow(_retval);
NS_RELEASE(browser);
return rv;
}
}
}
}
return NS_ERROR_FAILURE;
}

View File

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Adam Lock <adamlock@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef WINDOWCREATOR_H
#define WINDOWCREATOR_H
#include "nsIWindowCreator.h"
#include "nsIWebBrowserChrome.h"
class CWindowCreator : public nsIWindowCreator
{
public:
CWindowCreator();
protected:
virtual ~CWindowCreator();
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
};
#endif

View File

@ -81,6 +81,7 @@ OBJS = \
.\$(OBJDIR)\DropTarget.obj \
.\$(OBJDIR)\PropertyDlg.obj \
.\$(OBJDIR)\PromptService.obj \
.\$(OBJDIR)\WindowCreator.obj \
.\$(OBJDIR)\guids.obj \
$(NULL)