NOT PART OF BUILD (Photon port only)

- added new prompt service
- new history resource.
This commit is contained in:
dinglis%qnx.com 2001-08-24 13:51:21 +00:00
Родитель ccb8817a18
Коммит afd9368f28
9 изменённых файлов: 551 добавлений и 220 удалений

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

@ -33,6 +33,7 @@ CPPSRCS = \
PhMozEmbedStream.cpp \
PtMozilla.cpp \
WebBrowserContainer.cpp \
PromptService.cpp \
nsUnknownContentTypeHandler.cpp
SHARED_LIBRARY_LIBS= \

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

@ -0,0 +1,331 @@
/* -*- 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) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* PromptService is intended to override the default Mozilla PromptService,
giving nsIPrompt implementations of our own design, rather than using
Mozilla's. Do this by building this into a component and registering the
factory with the same CID/ContractID as Mozilla's (see MfcEmbed.cpp).
*/
#include "PromptService.h"
#include "nsCOMPtr.h"
#include "nsMemory.h"
#include "nsString.h"
#include "nsIDOMWindow.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIFactory.h"
#include "nsIPromptService.h"
#include "nsIServiceManager.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWindowWatcher.h"
#include "PtMozilla.h"
//*****************************************************************************
// CPromptService
//*****************************************************************************
class CPromptService: public nsIPromptService {
public:
CPromptService();
virtual ~CPromptService();
NS_DECL_ISUPPORTS
NS_DECL_NSIPROMPTSERVICE
private:
nsCOMPtr<nsIWindowWatcher> mWWatch;
CWebBrowserContainer *GetWebBrowser(nsIDOMWindow *aWindow);
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(CPromptService, nsIPromptService)
CPromptService::CPromptService() :
mWWatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")) {
NS_INIT_REFCNT();
}
CPromptService::~CPromptService() {
}
CWebBrowserContainer *CPromptService::GetWebBrowser(nsIDOMWindow *aWindow)
{
nsCOMPtr<nsIWebBrowserChrome> chrome;
CWebBrowserContainer *val = 0;
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!wwatch) return nsnull;
if( wwatch ) {
nsCOMPtr<nsIDOMWindow> fosterParent;
if (!aWindow) { // it will be a dependent window. try to find a foster parent.
wwatch->GetActiveWindow(getter_AddRefs(fosterParent));
aWindow = fosterParent;
}
nsresult rv = wwatch->GetChromeForWindow(aWindow, getter_AddRefs(chrome));
}
if (chrome) {
nsCOMPtr<nsIEmbeddingSiteWindow> site(do_QueryInterface(chrome));
if (site) {
site->GetSiteWindow(reinterpret_cast<void **>(&val));
}
}
return val;
}
NS_IMETHODIMP CPromptService::Alert(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsString mTitle(dialogTitle);
nsString mText(text);
CWebBrowserContainer *w = GetWebBrowser( parent );
w->InvokeDialogCallback(Pt_MOZ_DIALOG_ALERT, mTitle.ToNewCString(), mText.ToNewCString(), nsnull, nsnull);
return NS_OK;
}
NS_IMETHODIMP CPromptService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkboxMsg,
PRBool *checkValue)
{
nsString mTitle(dialogTitle);
nsString mText(text);
nsString mMsg(checkboxMsg);
int ret;
CWebBrowserContainer *w = GetWebBrowser( parent );
w->InvokeDialogCallback(Pt_MOZ_DIALOG_ALERT, mTitle.ToNewCString(), mText.ToNewCString(), \
mMsg.ToNewCString(), &ret);
*checkValue = ret;
return NS_OK;
}
NS_IMETHODIMP CPromptService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsString mTitle(dialogTitle);
nsString mText(text);
CWebBrowserContainer *w = GetWebBrowser( parent );
if (w->InvokeDialogCallback(Pt_MOZ_DIALOG_CONFIRM, mTitle.ToNewCString(), mText.ToNewCString(), nsnull, nsnull) == Pt_CONTINUE)
*_retval = PR_TRUE;
else
*_retval = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP CPromptService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkboxMsg,
PRBool *checkValue,
PRBool *_retval)
{
// TODO implement proper confirmation checkbox dialog
return Confirm(parent, dialogTitle, text, _retval);
}
NS_IMETHODIMP CPromptService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkboxMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsString mTitle(dialogTitle);
nsString mText(text);
nsString mMsg(checkboxMsg);
int ret;
CWebBrowserContainer *w = GetWebBrowser( parent );
if (w->InvokeDialogCallback(Pt_MOZ_DIALOG_CONFIRM, mTitle.ToNewCString(), mText.ToNewCString(), \
mMsg.ToNewCString(), &ret) == Pt_CONTINUE)
*_retval = PR_TRUE;
else
*_retval = PR_FALSE;
*checkValue = ret;
return NS_OK;
}
NS_IMETHODIMP CPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkboxMsg,
PRBool *checkValue,
PRBool *_retval)
{
CWebBrowserContainer *w = GetWebBrowser( parent );
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) w->m_pOwner;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaAuthenticateCb_t auth;
nsString mTitle(dialogTitle);
nsString mRealm(checkboxMsg);
/* ATENTIE */ printf( "CWebBrowserContainer::PromptUsernameAndPassword\n" );
if (!moz->auth_cb)
return NS_OK;
cb = moz->auth_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_AUTHENTICATE;
cbinfo.cbdata = &auth;
memset(&auth, 0, sizeof(PtMozillaAuthenticateCb_t));
auth.title = mTitle.ToNewCString();
auth.realm = mRealm.ToNewCString();
if (PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo) == Pt_CONTINUE)
{
nsCString mUser(auth.user);
nsCString mPass(auth.pass);
*username = mUser.ToNewUnicode();
*password = mPass.ToNewUnicode();
*_retval = PR_TRUE;
}
else
*_retval = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP CPromptService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkboxMsg,
PRBool *checkValue,
PRBool *_retval)
{
/* ATENTIE */ printf( "CWebBrowserContainer::PromptPassword\n" );
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;
}
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;
}
//*****************************************************************************
// 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;
}
//*****************************************************************************
void InitPromptService( ) {
}
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;
}

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

@ -0,0 +1,36 @@
/* -*- 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) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __PromptService_h
#define __PromptService_h
#include "nsError.h"
class nsIFactory;
extern "C" NS_EXPORT nsresult NS_NewPromptServiceFactory(nsIFactory** aFactory);
#define kPromptServiceFactoryFuncName "NS_NewPromptServiceFactory"
extern "C" NS_EXPORT void InitPromptService( );
#define kPromptServiceInitFuncName "InitPromptService"
#endif

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

@ -55,6 +55,7 @@
#include "nsNetUtil.h"
#include "nsMPFileLocProvider.h"
#include "nsIFocusController.h"
#include "PromptService.h"
#include "nsIViewManager.h"
@ -76,7 +77,6 @@
#define NS_TO_PH_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#define PH_TO_NS_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#define NS_EXTERN_IID(_name) \
extern const nsIID _name;
@ -84,7 +84,6 @@
NS_EXTERN_IID(kHTMLEditorCID);
NS_EXTERN_IID(kCookieServiceCID);
NS_EXTERN_IID(kWindowCID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
@ -92,6 +91,10 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);
static void mozilla_set_pref( PtWidget_t *widget, char *option, char *value );
static void mozilla_get_pref( PtWidget_t *widget, char *option, char *value );
@ -114,9 +117,19 @@ static void MozCreateWindow(PtMozillaWidget_t *moz)
exit(-1);
}
//moz->MyBrowser->WebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this));
//nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(moz->MyBrowser->WebBrowser);
//dsti->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
// Create the container object
moz->MyBrowser->WebBrowserContainer = new CWebBrowserContainer((PtWidget_t *)moz);
if (moz->MyBrowser->WebBrowserContainer == NULL) {
printf("Could not create webbrowsercontainer\n");
exit(-1);
}
moz->MyBrowser->WebBrowserContainer->AddRef();
moz->MyBrowser->WebBrowser->SetContainerWindow( NS_STATIC_CAST( nsIWebBrowserChrome*, moz->MyBrowser->WebBrowserContainer ) );
//nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(moz->MyBrowser->WebBrowser);
//dsti->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
// Create the webbrowser window
moz->MyBrowser->WebBrowserAsWin = do_QueryInterface(moz->MyBrowser->WebBrowser);
@ -128,29 +141,21 @@ static void MozCreateWindow(PtMozillaWidget_t *moz)
// webBrowserAsSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS, aAllowPlugins);
// webBrowserAsSetup->SetProperty(nsIWebBrowserSetup::SETUP_CONTAINS_CHROME, PR_TRUE);
// Create the container object
moz->MyBrowser->WebBrowserContainer = new CWebBrowserContainer((PtWidget_t *)moz);
if (moz->MyBrowser->WebBrowserContainer == NULL)
{
printf("Could not create webbrowsercontainer\n");
exit(-1);
}
moz->MyBrowser->WebBrowserContainer->AddRef();
// Set up the web shell
moz->MyBrowser->WebBrowser->SetParentURIContentListener(moz->MyBrowser->WebBrowserContainer);
// XXX delete when tree owner is not necessary (to receive context menu events)
nsCOMPtr<nsIDocShellTreeItem> browserAsItem = do_QueryInterface(moz->MyBrowser->WebBrowser);
browserAsItem->SetTreeOwner(NS_STATIC_CAST(nsIDocShellTreeOwner *, moz->MyBrowser->WebBrowserContainer));
// Set up the web shell
// ATENTIE moz->MyBrowser->WebBrowser->SetParentURIContentListener( (nsIURIContentListener*) moz );
// XXX delete when tree owner is not necessary (to receive context menu events)
nsCOMPtr<nsIDocShellTreeItem> browserAsItem = do_QueryInterface(moz->MyBrowser->WebBrowser);
browserAsItem->SetTreeOwner(NS_STATIC_CAST(nsIDocShellTreeOwner *, moz->MyBrowser->WebBrowserContainer));
// XXX delete when docshell becomes inaccessible
moz->MyBrowser->rootDocShell = do_GetInterface(moz->MyBrowser->WebBrowser);
if (moz->MyBrowser->rootDocShell == nsnull)
{
printf("Could not get root docshell object\n");
exit(-1);
}
if (moz->MyBrowser->rootDocShell == nsnull) {
printf("Could not get root docshell object\n");
exit(-1);
}
nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports **)&(moz->MyBrowser->mPrefs));
@ -523,18 +528,18 @@ static void mozilla_modify( PtWidget_t *widget, PtArg_t const *argt ) {
nsCOMPtr<nsIDOMWindow> window;
moz->MyBrowser->WebBrowser->GetContentDOMWindow(getter_AddRefs(window));
nsCOMPtr<nsIWebBrowserPrint> print( do_GetInterface( moz->MyBrowser->WebBrowser ) );
WWWRequest *pPageInfo = ( WWWRequest * ) argt->value;
PpPrintContext_t *pc = moz_construct_print_context( pPageInfo );
nsresult rv;
nsCOMPtr<nsIPrintOptions> printService =
do_GetService(kPrintOptionsCID, &rv);
nsCOMPtr<nsIPrintOptions> printService =
do_GetService(kPrintOptionsCID, &rv);
printService->SetEndPageRange( (PRInt32) pc ); /* use SetEndPageRange/GetEndPageRange to convey the print context */
print->Print( window, printService, moz->MyBrowser->WebBrowserContainer );
}
break;
}
break;
case Pt_ARG_MOZ_OPTION:
mozilla_set_pref( widget, (char*)argt->len, (char*)argt->value );
@ -741,6 +746,34 @@ static int mozilla_get_info(PtWidget_t *widget, PtArg_t *argt)
strcpy( (char*)argt->value, s );
}
break;
case Pt_ARG_MOZ_GET_HISTORY: {
WWWRequest *req = ( WWWRequest * ) argt->len;
PtWebClientHistoryData_t *HistoryReplyBuf = (PtWebClientHistoryData_t *) argt->value;
int i, j;
PRInt32 total;
moz->MyBrowser->mSessionHistory->GetCount( &total );
for( i=total-2, j=0; i>=0 && j<req->History.num; i--, j++) {
nsIHistoryEntry *entry;
moz->MyBrowser->mSessionHistory->GetEntryAtIndex( i, PR_FALSE, &entry );
PRUnichar *title;
nsIURI *url;
entry->GetTitle( &title );
entry->GetURI( &url );
nsString stitle( title );
strncpy( HistoryReplyBuf[j].title, stitle.ToNewCString(), 127 );
HistoryReplyBuf[j].title[127] = '\0';
char *urlspec;
url->GetSpec( &urlspec );
strcpy( HistoryReplyBuf[j].url, urlspec );
}
}
break;
}
return (Pt_CONTINUE);
@ -1180,6 +1213,7 @@ PtWidgetClass_t *PtCreateMozillaClass( void )
{ Pt_ARG_MOZ_COMMAND, mozilla_modify, Pt_QUERY_PREVENT },
{ Pt_ARG_MOZ_OPTION, mozilla_modify, mozilla_get_info },
{ Pt_ARG_MOZ_GET_CONTEXT, NULL, mozilla_get_info },
{ Pt_ARG_MOZ_GET_HISTORY, NULL, mozilla_get_info },
{ Pt_ARG_MOZ_ENCODING, mozilla_modify, mozilla_get_info },
{ Pt_ARG_MOZ_WEB_DATA_URL, mozilla_modify, Pt_QUERY_PREVENT },
{ Pt_ARG_MOZ_WEB_DATA, mozilla_modify, Pt_QUERY_PREVENT },
@ -1256,5 +1290,15 @@ PtWidgetClass_t *PtCreateMozillaClass( void )
InitProfiles( getenv( "HOME" ), ".mozilla" );
Init_nsUnknownContentTypeHandler_Factory( );
nsCOMPtr<nsIFactory> promptFactory;
NS_NewPromptServiceFactory(getter_AddRefs(promptFactory));
nsComponentManager::RegisterFactory(kPromptServiceCID,
"Prompt Service",
"@mozilla.org/embedcomp/prompt-service;1",
promptFactory,
PR_TRUE); // replace existing
InitializeWindowCreator( );
return (PtMozilla->wclass);
}

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

@ -35,6 +35,7 @@
#include "nsIStreamListener.h"
#include "nsIExternalHelperAppService.h"
#include "nsISHistory.h"
#include "nsIHistoryEntry.h"
/*
* PtMozilla public
@ -57,6 +58,7 @@ extern PtWidgetClassRef_t *PtMozilla;
#define Pt_ARG_MOZ_GET_CONTEXT Pt_RESOURCE( 104, 10 )
#define Pt_ARG_MOZ_UNKNOWN_RESP Pt_RESOURCE( 104, 11 )
#define Pt_ARG_MOZ_DOWNLOAD Pt_RESOURCE( 104, 12 )
#define Pt_ARG_MOZ_GET_HISTORY Pt_RESOURCE( 104, 13 )
#define Pt_CB_MOZ_PROGRESS Pt_RESOURCE( 104, 20 )
#define Pt_CB_MOZ_START Pt_RESOURCE( 104, 21 )

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

@ -31,6 +31,8 @@
#include "nsIDOMHTMLHtmlElement.h"
#include "nsIDOMElement.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIWindowCreator.h"
#include "nsIWindowWatcher.h"
CWebBrowserContainer::CWebBrowserContainer(PtWidget_t *pOwner)
{
@ -114,7 +116,6 @@ NS_INTERFACE_MAP_BEGIN(CWebBrowserContainer)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_ENTRY(nsIPrompt)
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener)
NS_INTERFACE_MAP_ENTRY(nsICommandHandler)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
@ -126,13 +127,6 @@ NS_INTERFACE_MAP_END
NS_IMETHODIMP CWebBrowserContainer::GetInterface(const nsIID & uuid, void * *result)
{
const nsIID &iid = NS_GET_IID(nsIPrompt);
if (memcmp(&uuid, &iid, sizeof(nsIID)) == 0)
{
*result = (nsIPrompt *) this;
AddRef();
return NS_OK;
}
return QueryInterface(uuid, result);
}
@ -199,165 +193,6 @@ NS_IMETHODIMP CWebBrowserContainer::OnShowContextMenu(PRUint32 aContextFlags, ns
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsIPrompt
/* void alert (in wstring text); */
NS_IMETHODIMP CWebBrowserContainer::Alert(const PRUnichar* dialogTitle, const PRUnichar *text)
{
nsString mTitle(dialogTitle);
nsString mText(text);
InvokeDialogCallback(Pt_MOZ_DIALOG_ALERT, mTitle.ToNewCString(), mText.ToNewCString(), nsnull, nsnull);
return NS_OK;
}
/* boolean confirmCheck (in wstring text, in wstring checkMsg, out boolean checkValue); */
NS_IMETHODIMP CWebBrowserContainer::AlertCheck(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue)
{
nsString mTitle(dialogTitle);
nsString mText(text);
nsString mMsg(checkMsg);
int ret;
InvokeDialogCallback(Pt_MOZ_DIALOG_ALERT, mTitle.ToNewCString(), mText.ToNewCString(), \
mMsg.ToNewCString(), &ret);
*checkValue = ret;
return NS_OK;
}
/* boolean confirm (in wstring text); */
NS_IMETHODIMP CWebBrowserContainer::Confirm(const PRUnichar* dialogTitle, const PRUnichar *text, PRBool *_retval)
{
nsString mTitle(dialogTitle);
nsString mText(text);
if (InvokeDialogCallback(Pt_MOZ_DIALOG_CONFIRM, mTitle.ToNewCString(), mText.ToNewCString(), nsnull, nsnull) == Pt_CONTINUE)
*_retval = PR_TRUE;
else
*_retval = PR_FALSE;
return NS_OK;
}
/* boolean confirmCheck (in wstring text, in wstring checkMsg, out boolean checkValue); */
NS_IMETHODIMP CWebBrowserContainer::ConfirmCheck(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
{
nsString mTitle(dialogTitle);
nsString mText(text);
nsString mMsg(checkMsg);
int ret;
if (InvokeDialogCallback(Pt_MOZ_DIALOG_CONFIRM, mTitle.ToNewCString(), mText.ToNewCString(), \
mMsg.ToNewCString(), &ret) == Pt_CONTINUE)
*_retval = PR_TRUE;
else
*_retval = PR_FALSE;
*checkValue = ret;
return NS_OK;
}
NS_IMETHODIMP CWebBrowserContainer::ConfirmEx(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 CWebBrowserContainer::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **value, const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval )
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) m_pOwner;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaPromptCb_t pr;
nsString mTitle(dialogTitle);
nsString mText(text);
nsString mDflt(checkMsg);
if (!moz->prompt_cb)
return NS_OK;
cb = moz->prompt_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_PROMPT;
cbinfo.cbdata = &pr;
memset(&pr, 0, sizeof(PtMozillaPromptCb_t));
pr.title = mTitle.ToNewCString();
pr.text = mText.ToNewCString();
pr.dflt_resp = mDflt.ToNewCString();
if (PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo) == Pt_END)
*_retval = PR_FALSE;
else
{
nsCString mResp(pr.response);
*value = mResp.ToNewUnicode();
*_retval = PR_TRUE;
}
return NS_OK;
}
/* boolean promptUsernameAndPassword (in wstring text, out wstring user, out wstring pwd); */
NS_IMETHODIMP CWebBrowserContainer::PromptUsernameAndPassword(
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) m_pOwner;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaAuthenticateCb_t auth;
nsString mTitle(dialogTitle);
nsString mRealm(checkMsg);
if (!moz->auth_cb)
return NS_OK;
cb = moz->auth_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_AUTHENTICATE;
cbinfo.cbdata = &auth;
memset(&auth, 0, sizeof(PtMozillaAuthenticateCb_t));
auth.title = mTitle.ToNewCString();
auth.realm = mRealm.ToNewCString();
if (PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo) == Pt_CONTINUE)
{
nsCString mUser(auth.user);
nsCString mPass(auth.pass);
*username = mUser.ToNewUnicode();
*password = mPass.ToNewUnicode();
*_retval = PR_TRUE;
}
else
*_retval = PR_FALSE;
return NS_OK;
}
/* boolean promptPassword (in wstring text, in wstring title, out wstring pwd); */
NS_IMETHODIMP CWebBrowserContainer::PromptPassword(
const PRUnichar *dialogTitle, const PRUnichar *text,
PRUnichar **password, const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* boolean select (in wstring inDialogTitle, in wstring inMsg, in PRUint32 inCount, [array, size_is (inCount)] in wstring inList, out long outSelection); */
NS_IMETHODIMP CWebBrowserContainer::Select(const PRUnichar *inDialogTitle, const PRUnichar *inMsg, PRUint32 inCount, const PRUnichar **inList, PRInt32 *outSelection, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
///////////////////////////////////////////////////////////////////////////////
// nsIWebProgressListener
@ -1018,7 +853,9 @@ NS_IMETHODIMP CWebBrowserContainer::SetTitle(const PRUnichar * aTitle) {
/* [noscript] readonly attribute voidPtr siteWindow; */
NS_IMETHODIMP CWebBrowserContainer::GetSiteWindow(void * *aSiteWindow)
{
return NS_ERROR_NOT_IMPLEMENTED;
*aSiteWindow = this;
return NS_OK;
}
NS_IMETHODIMP
@ -1266,3 +1103,59 @@ NS_IMETHODIMP CWebBrowserContainer::FocusNextElement() {
NS_IMETHODIMP CWebBrowserContainer::FocusPrevElement() {
return NS_ERROR_NOT_IMPLEMENTED;
}
// ---------------------------------------------------------------------------
// Window Creator
// ---------------------------------------------------------------------------
class CWindowCreator : public nsIWindowCreator
{
public:
CWindowCreator();
virtual ~CWindowCreator();
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
};
NS_IMPL_ISUPPORTS1(CWindowCreator, nsIWindowCreator);
CWindowCreator::CWindowCreator()
{
NS_INIT_ISUPPORTS();
}
CWindowCreator::~CWindowCreator()
{
}
NS_IMETHODIMP CWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
PRUint32 aChromeFlags,
nsIWebBrowserChrome **_retval)
{
return NS_OK;
}
/*
InitializeWindowCreator creates and hands off an object with a callback
to a window creation function. This will be used by Gecko C++ code
(never JS) to create new windows when no previous window is handy
to begin with. This is done in a few exceptional cases, like PSM code.
Failure to set this callback will only disable the ability to create
new windows under these circumstances.
*/
nsresult InitializeWindowCreator()
{
// Create a CWindowCreator and give it to the WindowWatcher service
// The WindowWatcher service will own it so we don't keep a ref.
CWindowCreator *windowCreator = new CWindowCreator;
if (!windowCreator) return NS_ERROR_FAILURE;
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!wwatch) return NS_ERROR_FAILURE;
return wwatch->SetWindowCreator(windowCreator);
}

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

@ -59,7 +59,6 @@ class CWebBrowserContainer :
public nsIURIContentListener,
public nsIDocShellTreeOwner,
public nsIInterfaceRequestor,
public nsIPrompt,
public nsIContextMenuListener,
public nsICommandHandler,
public nsIPrintListener,
@ -104,9 +103,6 @@ public:
NS_DECL_NSICOMMANDHANDLER
NS_DECL_NSIPRINTLISTENER
// "Services" accessed through nsIInterfaceRequestor
NS_DECL_NSIPROMPT
private:
nsCOMPtr<nsIInputStream> mStream;
nsCOMPtr<nsIStreamListener> mStreamListener;
@ -115,4 +111,6 @@ private:
PRBool mDoingStream;
};
nsresult InitializeWindowCreator();
#endif

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

@ -45,7 +45,7 @@ nsUnknownContentTypeHandler::~nsUnknownContentTypeHandler( ) { }
NS_IMETHODIMP nsUnknownContentTypeHandler::ShowProgressDialog(nsIHelperAppLauncher *aLauncher, nsISupports *aContext ) {
nsresult rv = NS_OK;
printf("ShowProgressDialog!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* ATENTIE */ printf("ShowProgressDialog!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* we need a dummy listener because the nsExternalAppHandler class verifies that a progress window has been displayed */
nsCOMPtr<nsIWebProgressListener> dummy = new nsWebProgressListener;
@ -56,20 +56,16 @@ NS_IMETHODIMP nsUnknownContentTypeHandler::ShowProgressDialog(nsIHelperAppLaunch
NS_IMETHODIMP nsUnknownContentTypeHandler::Show( nsIHelperAppLauncher *aLauncher, nsISupports *aContext ) {
nsresult rv = NS_OK;
printf("Show!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* ATENTIE */ printf("Show!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* try to get the PtMozillawidget_t* pointer form the aContext - use the fact the the WebBrowserContainer is
registering itself as nsIDocumentLoaderObserver ( SetDocLoaderObserver ) */
/* aContext is a nsDocShell* */
nsCOMPtr<nsIDocShell> docShell( do_GetInterface( aContext ) );
nsIURIContentListener *dl;
rv = docShell->GetParentURIContentListener( &dl );
CWebBrowserContainer *webc = NS_STATIC_CAST( CWebBrowserContainer*, dl );
printf("webc=%p\n", webc );
PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) webc->m_pOwner;
nsCOMPtr<nsIDOMWindow> domw( do_GetInterface( aContext ) );
nsIDOMWindow *parent;
domw->GetParent( &parent );
CWebBrowserContainer *w = GetWebBrowser( parent );
PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) w->m_pOwner;
/* go ahead and start the downloading process */
nsCOMPtr<nsIWebProgressListener> listener = NS_STATIC_CAST(nsIWebProgressListener*, moz->MyBrowser->WebBrowserContainer );
@ -110,16 +106,43 @@ printf("webc=%p\n", webc );
/* only Show() method is used - remove this code */
NS_IMETHODIMP nsUnknownContentTypeHandler::PromptForSaveToFile( nsISupports * aWindowContext, const PRUnichar * aDefaultFile, const PRUnichar * aSuggestedFileExtension, nsILocalFile ** aNewFile ) {
printf("PromptForSaveToFile!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* ATENTIE */ printf("PromptForSaveToFile!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
return NS_OK;
}
CWebBrowserContainer *nsUnknownContentTypeHandler::GetWebBrowser(nsIDOMWindow *aWindow)
{
nsCOMPtr<nsIWebBrowserChrome> chrome;
CWebBrowserContainer *val = 0;
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!wwatch) return nsnull;
if( wwatch ) {
nsCOMPtr<nsIDOMWindow> fosterParent;
if (!aWindow) { // it will be a dependent window. try to find a foster parent.
wwatch->GetActiveWindow(getter_AddRefs(fosterParent));
aWindow = fosterParent;
}
wwatch->GetChromeForWindow(aWindow, getter_AddRefs(chrome));
}
if (chrome) {
nsCOMPtr<nsIEmbeddingSiteWindow> site(do_QueryInterface(chrome));
if (site) {
site->GetSiteWindow(reinterpret_cast<void **>(&val));
}
}
return val;
}
//###########################################################################
NS_IMPL_ISUPPORTS2(nsWebProgressListener, nsIWebProgressListener, nsISupportsWeakReference);
nsWebProgressListener::nsWebProgressListener() {
printf("11111111111111\n");
NS_INIT_ISUPPORTS();
}
@ -130,25 +153,21 @@ nsWebProgressListener::~nsWebProgressListener() { }
/* void onProgressChange (in nsIWebProgress aProgress, in nsIRequest aRequest, in long curSelfProgress, in long maxSelfProgress, in long curTotalProgress, in long maxTotalProgress); */
NS_IMETHODIMP nsWebProgressListener::OnProgressChange(nsIWebProgress *aProgress, nsIRequest *aRequest, PRInt32 curSelfProgress, PRInt32 maxSelfProgress, PRInt32 curTotalProgress, PRInt32 maxTotalProgress) {
printf("OnProgressChange curSelfProgress=%d maxSelfProgress=%d curTotalProgress=%d maxTotalProgress=%d\n",
/* ATENTIE */ printf("OnProgressChange curSelfProgress=%d maxSelfProgress=%d curTotalProgress=%d maxTotalProgress=%d\n",
curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress );
return NS_OK;
}
NS_IMETHODIMP nsWebProgressListener::OnStateChange(nsIWebProgress* aWebProgress, nsIRequest *aRequest, PRInt32 progressStateFlags, nsresult aStatus) {
printf("222\n");
return NS_OK;
}
NS_IMETHODIMP nsWebProgressListener::OnLocationChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsIURI *location) {
printf("333\n");
return NS_OK;
}
NS_IMETHODIMP nsWebProgressListener::OnStatusChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsresult aStatus, const PRUnichar* aMessage) {
printf("OnStatusChange aStatus=%d\n", aStatus );
return NS_OK;
}
NS_IMETHODIMP nsWebProgressListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state) {
printf("555\n");
return NS_OK;
}
@ -177,7 +196,7 @@ NS_IMPL_RELEASE( className );
/* QueryInterface implementation for this class. */
NS_IMETHODIMP className::QueryInterface( REFNSIID anIID, void **anInstancePtr ) {
nsresult rv = NS_OK;
printf("QueryInterface!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* ATENTIE */ printf("QueryInterface!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* Check for place to return result. */
if( !anInstancePtr ) rv = NS_ERROR_NULL_POINTER;

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

@ -7,6 +7,8 @@
#include "nsIWebProgressListener.h"
#include "nsIWebBrowserPersist.h"
#include "nsWeakReference.h"
#include "nsIWindowWatcher.h"
#include "WebBrowserContainer.h"
static NS_DEFINE_CID( kCID, NS_IHELPERAPPLAUNCHERDIALOG_IID );
@ -19,6 +21,8 @@ public:
nsUnknownContentTypeHandler();
virtual ~nsUnknownContentTypeHandler();
// This class implements the nsISupports interface functions.
NS_DECL_ISUPPORTS
@ -27,6 +31,9 @@ public:
// This class implements the nsIHelperAppLauncherDialog interface functions.
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
private:
CWebBrowserContainer* GetWebBrowser(nsIDOMWindow *aWindow);
}; // nsUnknownContentTypeHandler