Updated control to implement an nsIPrompt service. b=75745, r=ccarlen@netscape.com, sr=blizzard@mozilla.org

This commit is contained in:
locka%iol.ie 2001-05-09 11:23:18 +00:00
parent c872c09c83
commit dd3c361895
6 changed files with 350 additions and 29 deletions

View File

@ -35,6 +35,7 @@
#include "MozillaBrowser.h"
#include "IEHtmlDocument.h"
#include "PropertyDlg.h"
#include "PromptService.h"
#include "nsCWebBrowser.h"
#include "nsIDiskDocument.h"
@ -55,6 +56,12 @@
static HANDLE s_hHackedNonReentrancy = NULL;
#endif
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);
// Macros to return errors from bad calls to the automation
// interfaces and sets a descriptive string on IErrorInfo so VB programmers
// have a clue why the call failed.
@ -95,6 +102,9 @@ GUID CGID_MSHTML_Moz =
/////////////////////////////////////////////////////////////////////////////
// CMozillaBrowser
nsVoidArray CMozillaBrowser::sBrowserList;
//
// Constructor
//
@ -895,6 +905,18 @@ 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;
@ -1022,6 +1044,9 @@ HRESULT CMozillaBrowser::CreateBrowser()
dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, mWebBrowserContainer))));
mWebBrowser->AddWebBrowserListener(listener, NS_GET_IID(nsIWebProgressListener));
// Append browser to browser list
sBrowserList.AppendElement(this);
mValidBrowserFlag = TRUE;
return S_OK;
@ -1032,7 +1057,10 @@ HRESULT CMozillaBrowser::DestroyBrowser()
{
// TODO unregister drop target
mValidBrowserFlag = FALSE;
mValidBrowserFlag = FALSE;
// Remove browser from browser list
sBrowserList.RemoveElement(this);
// Destroy the htmldoc
if (mIERootDocument != NULL)

View File

@ -58,6 +58,7 @@ extern GUID CGID_MSHTML_Moz;
typedef CComPtr<IUnknown> CComUnkPtr;
class CWebBrowserContainer;
class CPromptService;
/////////////////////////////////////////////////////////////////////////////
// CMozillaBrowser
@ -86,6 +87,8 @@ class ATL_NO_VTABLE CMozillaBrowser :
public IMozControlBridge
{
friend CWebBrowserContainer;
friend CPromptService;
public:
CMozillaBrowser();
virtual ~CMozillaBrowser();
@ -334,6 +337,9 @@ END_OLECOMMAND_TABLE()
// Protected members
protected:
// List of browsers
static nsVoidArray sBrowserList;
// Pointer to web shell manager
CWebBrowserContainer * mWebBrowserContainer;
// CComObject to IHTMLDocument implementer

View File

@ -142,6 +142,10 @@ SOURCE=.\nsSetupRegistry.cpp
# End Source File
# Begin Source File
SOURCE=.\PromptService.cpp
# End Source File
# Begin Source File
SOURCE=.\PropertyBag.cpp
# End Source File
# Begin Source File
@ -226,6 +230,10 @@ SOURCE=.\MozillaBrowser.h
# End Source File
# Begin Source File
SOURCE=.\PromptService.h
# End Source File
# Begin Source File
SOURCE=.\PropertyBag.h
# End Source File
# Begin Source File

View File

@ -0,0 +1,274 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "StdAfx.h"
#include "MozillaBrowser.h"
#include "PromptService.h"
#include "nsCOMPtr.h"
#include "nsIPromptService.h"
#include "nsIFactory.h"
#include "nsIDOMWindow.h"
//*****************************************************************************
// CPromptService
//*****************************************************************************
class CPromptService: public nsIPromptService
{
public:
CPromptService();
virtual ~CPromptService();
CMozillaBrowser *GetOwningBrowser(nsIDOMWindow *parent);
NS_DECL_ISUPPORTS
NS_DECL_NSIPROMPTSERVICE
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(CPromptService, nsIPromptService)
CPromptService::CPromptService()
{
NS_INIT_REFCNT();
}
CPromptService::~CPromptService()
{
}
CMozillaBrowser *CPromptService::GetOwningBrowser(nsIDOMWindow *parent)
{
if (parent == nsnull)
{
// return the first element from the list if there is one
if (CMozillaBrowser::sBrowserList.Count() > 0)
{
return (CMozillaBrowser *) CMozillaBrowser::sBrowserList[0];
}
return NULL;
}
// Search for the browser with a content window matching the one provided
PRInt32 i;
for (i = 0; i < CMozillaBrowser::sBrowserList.Count(); i++)
{
CMozillaBrowser *p = (CMozillaBrowser *) CMozillaBrowser::sBrowserList[i];
if (p->mWebBrowser)
{
nsCOMPtr<nsIDOMWindow> domWindow;
p->mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (domWindow.get() == parent)
{
return p;
}
}
}
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
// nsIPrompt
NS_IMETHODIMP CPromptService::Alert(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text)
{
CMozillaBrowser *pOwner = GetOwningBrowser(parent);
if (pOwner)
{
USES_CONVERSION;
pOwner->MessageBox(W2T(text), W2T(dialogTitle), MB_OK | MB_ICONEXCLAMATION);
}
return NS_OK;
}
NS_IMETHODIMP CPromptService::AlertCheck(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg, PRBool *checkValue)
{
CMozillaBrowser *pOwner = GetOwningBrowser(parent);
if (pOwner)
{
// TODO show dialog with check box
USES_CONVERSION;
pOwner->MessageBox(W2T(text), W2T(dialogTitle), MB_OK | MB_ICONEXCLAMATION);
}
return NS_OK;
}
NS_IMETHODIMP CPromptService::Confirm(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
CMozillaBrowser *pOwner = GetOwningBrowser(parent);
if (pOwner)
{
USES_CONVERSION;
int nAnswer = pOwner->MessageBox(W2T(text), W2T(dialogTitle),
MB_YESNO | MB_ICONQUESTION);
*_retval = (nAnswer == IDYES) ? PR_TRUE : PR_FALSE;
}
return NS_OK;
}
NS_IMETHODIMP CPromptService::ConfirmCheck(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg, PRBool *checkValue,
PRBool *_retval)
{
CMozillaBrowser *pOwner = GetOwningBrowser(parent);
if (pOwner)
{
// TODO show dialog with check box
USES_CONVERSION;
int nAnswer = pOwner->MessageBox(W2T(text), W2T(dialogTitle),
MB_YESNO | MB_ICONQUESTION);
*_retval = (nAnswer == IDYES) ? PR_TRUE : PR_FALSE;
}
return NS_OK;
}
NS_IMETHODIMP CPromptService::ConfirmEx(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg, PRBool *checkValue,
PRInt32 *buttonPressed)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CPromptService::Prompt(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text, PRUnichar **value,
const PRUnichar *checkMsg, PRBool *checkValue,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username, PRUnichar **password,
const PRUnichar *checkMsg, PRBool *checkValue,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CPromptService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg, PRBool *checkValue,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CPromptService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text, PRUint32 count,
const PRUnichar **selectList, PRInt32 *outSelection,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
// CPromptServiceFactory
//*****************************************************************************
class CPromptServiceFactory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
CPromptServiceFactory();
virtual ~CPromptServiceFactory();
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(CPromptServiceFactory, nsIFactory)
CPromptServiceFactory::CPromptServiceFactory()
{
NS_INIT_ISUPPORTS();
}
CPromptServiceFactory::~CPromptServiceFactory()
{
}
NS_IMETHODIMP CPromptServiceFactory::CreateInstance(nsISupports *aOuter, const nsIID & aIID, void **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = NULL;
CPromptService *inst = new CPromptService;
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = inst->QueryInterface(aIID, aResult);
if (rv != NS_OK) {
// We didn't get the right interface, so clean up
delete inst;
}
return rv;
}
NS_IMETHODIMP CPromptServiceFactory::LockFactory(PRBool lock)
{
return NS_OK;
}
//*****************************************************************************
nsresult NS_NewPromptServiceFactory(nsIFactory** aFactory)
{
NS_ENSURE_ARG_POINTER(aFactory);
*aFactory = nsnull;
CPromptServiceFactory *result = new CPromptServiceFactory;
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aFactory = result;
return NS_OK;
}

View File

@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __PromptService_h
#define __PromptService_h
#include "nsError.h"
class nsIFactory;
extern nsresult NS_NewPromptServiceFactory(nsIFactory** aFactory);
#endif

View File

@ -55,6 +55,7 @@ OBJS = \
.\$(OBJDIR)\IEHtmlDocument.obj \
.\$(OBJDIR)\DropTarget.obj \
.\$(OBJDIR)\PropertyDlg.obj \
.\$(OBJDIR)\PromptService.obj \
.\$(OBJDIR)\guids.obj \
$(NULL)
@ -106,31 +107,3 @@ $(DEFFILE) : mkctldef.bat
MozillaControl_i.c \
MozillaControl.h: MozillaControl.idl
midl /Oicf /h MozillaControl.h /iid MozillaControl_i.c MozillaControl.idl
PropertyDlg.cpp : StdAfx.h resource.h
ControlSite.cpp \
ControlSiteIPFrame.cpp \
PropertyBag.cpp : StdAfx.h PropertyBag.h ControlSite.h ControlSiteIPFrame.h
ItemContainer.cpp : StdAfx.h ItemContainer.h
MozillaControl.cpp \
StdAfx.cpp: StdAfx.h MozillaControl_i.c MozillaControl.h MozillaBrowser.h WebBrowserContainer.h
IEHtmlNode.cpp : StdAfx.h IEHtmlNode.h
IEHtmlElementCollection.cpp : StdAfx.h IEHtmlElementCollection.h
IEHtmlElement.cpp : StdAfx.h IEHtmlNode.h IEHtmlElement.h
IEHtmlDocument.cpp : StdAfx.h IEHtmlNode.h IEHtmlDocument.h
DropTarget.cpp: StdAfx.h DropTarget.h
MozillaControl.cpp \
MozillaBrowser.cpp \
WebBrowserContainer.cpp \
StdAfx.cpp: StdAfx.h MozillaControl.h MozillaBrowser.h WebBrowserContainer.h IOleCommandTargetImpl.h
guids.cpp: StdAfx.h guids.h