implement ShowAsModal and remove nsIPrompt implementation; requirements for fielding default nsIPrompts. bug 75745 r=blizzard,hyatt

This commit is contained in:
danm%netscape.com 2001-04-21 02:45:37 +00:00
parent d592be4318
commit 727db81742
5 changed files with 135 additions and 196 deletions

View File

@ -19,9 +19,6 @@
* Contributor(s):
*/
// XXX Windows.h should not be needed. This file is meant to be platform neutral
#include <windows.h> // for cheesy nsIPrompt implementation
// Mozilla Includes
#include "nsIGenericFactory.h"
#include "nsString.h"
@ -118,7 +115,6 @@ NS_INTERFACE_MAP_BEGIN(WebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsISHistoryListener)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIPrompt)
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener)
NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
NS_INTERFACE_MAP_END
@ -193,8 +189,10 @@ NS_IMETHODIMP WebBrowserChrome::CreateBrowserWindow(PRUint32 aChromeFlags,
nsresult rv;
nsIWebBrowserChrome *parent = aChromeFlags & nsIWebBrowserChrome::CHROME_DEPENDENT ? this : 0;
nsIWebBrowserChrome *newChrome = nsnull;
rv = ::CreateBrowserWindow(nsIWebBrowserChrome::CHROME_ALL, nsnull, &newChrome);
rv = AppCallbacks::CreateBrowserWindow(aChromeFlags, parent, &newChrome);
if (NS_SUCCEEDED(rv))
{
newChrome->GetWebBrowser(_retval);
@ -219,7 +217,16 @@ NS_IMETHODIMP WebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
NS_IMETHODIMP WebBrowserChrome::ShowAsModal(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mDependentParent)
AppCallbacks::EnableChromeWindow(mDependentParent, PR_FALSE);
mContinueModalLoop = PR_TRUE;
AppCallbacks::RunEventLoop(mContinueModalLoop);
if (mDependentParent)
AppCallbacks::EnableChromeWindow(mDependentParent, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::IsWindowModal(PRBool *_retval)
@ -230,7 +237,8 @@ NS_IMETHODIMP WebBrowserChrome::IsWindowModal(PRBool *_retval)
NS_IMETHODIMP WebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
{
return NS_ERROR_NOT_IMPLEMENTED;
mContinueModalLoop = PR_FALSE;
return NS_OK;
}
//*****************************************************************************
@ -529,91 +537,3 @@ NS_IMETHODIMP WebBrowserChrome::OnHideTooltip()
WebBrowserChromeUI::HideTooltip(this);
return NS_OK;
}
//*****************************************************************************
// WebBrowserChrome::nsIPrompt
//*****************************************************************************
/* Simple, cheesy, partial implementation of nsIPrompt.
A real app would want better. */
NS_IMETHODIMP WebBrowserChrome::Alert(const PRUnichar* dialogTitle, const PRUnichar *text)
{
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
// XXX platform specific user-interface code should happen in WebBrowserChromeUI
::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_OK | MB_ICONEXCLAMATION);
nsMemory::Free(ctitle);
nsMemory::Free(ctext);
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::AlertCheck(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue)
{
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
// XXX platform specific user-interface code should happen in WebBrowserChromeUI
::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_OK | MB_ICONEXCLAMATION);
*checkValue = PR_FALSE; // yeah, well, it's not a real implementation
delete ctitle;
delete ctext;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::Confirm(const PRUnichar* dialogTitle, const PRUnichar *text, PRBool *_retval)
{
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
// XXX platform specific user-interface code should happen in WebBrowserChromeUI
int answer = ::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_YESNO | MB_ICONQUESTION);
delete ctitle;
delete ctext;
*_retval = answer == IDYES ? PR_TRUE : PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::ConfirmCheck(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
{
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
// XXX platform specific user-interface code should happen in WebBrowserChromeUI
int answer = ::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_YESNO | MB_ICONQUESTION);
delete ctitle;
delete ctext;
*_retval = answer == IDYES ? PR_TRUE : PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::ConfirmEx(const PRUnichar *dialogTitle, const PRUnichar *text, PRUint32 button0And1Flags, const PRUnichar *button2Title, const PRUnichar *checkMsg, PRBool *checkValue, PRInt32 *buttonPressed)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **answer, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::PromptUsernameAndPassword(const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **username, PRUnichar **password, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **password, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::Select(const PRUnichar *inDialogTitle, const PRUnichar *inMsg, PRUint32 inCount, const PRUnichar **inList, PRInt32 *outSelection, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -35,7 +35,6 @@
#include "nsIWebNavigation.h"
#include "nsIWebProgressListener.h"
#include "nsIInterfaceRequestor.h"
#include "nsIPrompt.h"
#include "nsIWebBrowser.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
@ -62,7 +61,6 @@ public:
class WebBrowserChrome : public nsIWebBrowserChrome,
public nsIWebProgressListener,
public nsIEmbeddingSiteWindow,
public nsIPrompt,
public nsIInterfaceRequestor,
public nsISHistoryListener,
public nsIObserver,
@ -79,7 +77,6 @@ public:
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSIPROMPT
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSISHISTORYLISTENER
NS_DECL_NSIOBSERVER
@ -88,15 +85,19 @@ public:
nsresult CreateBrowser(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY,
nsIWebBrowser **aBrowser);
void SetParent(nsIWebBrowserChrome *aParent)
{ mDependentParent = aParent; }
protected:
nsresult SendHistoryStatusMessage(nsIURI * aURI, char * operation, PRInt32 info1=0, PRUint32 info2=0);
nativeWindow mNativeWindow;
PRUint32 mChromeFlags;
PRBool mContinueModalLoop;
nsCOMPtr<nsIWebBrowser> mWebBrowser;
nsCOMPtr<nsIWebBrowserChrome> mTopWindow;
nsCOMPtr<nsIWebBrowserChrome> mDependentParent; // opener (for dependent windows only)
};
#endif /* __WebBrowserChrome__ */

View File

@ -41,6 +41,6 @@ WindowCreator::CreateChromeWindow(nsIWebBrowserChrome *parent,
nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
::CreateBrowserWindow(PRInt32(chromeFlags), parent, _retval);
AppCallbacks::CreateBrowserWindow(PRInt32(chromeFlags), parent, _retval);
return *_retval ? NS_OK : NS_ERROR_FAILURE;
}

View File

@ -149,10 +149,10 @@ int main(int argc, char *argv[])
}
// Now register an observer to watch for profile changes
nsresult rv;
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
ProfileChangeObserver *observer = new ProfileChangeObserver;
observer->AddRef();
nsCOMPtr<nsIObserverService> observerService(do_GetService(NS_OBSERVERSERVICE_CONTRACTID));
ProfileChangeObserver *observer = new ProfileChangeObserver;
observer->AddRef();
observerService->AddObserver(NS_STATIC_CAST(nsIObserver *, observer), NS_LITERAL_STRING("profile-approve-change").get());
observerService->AddObserver(NS_STATIC_CAST(nsIObserver *, observer), NS_LITERAL_STRING("profile-change-teardown").get());
observerService->AddObserver(NS_STATIC_CAST(nsIObserver *, observer), NS_LITERAL_STRING("profile-after-change").get());
@ -165,43 +165,16 @@ int main(int argc, char *argv[])
// Main message loop.
// NOTE: We use a fake event and a timeout in order to process idle stuff for
// Mozilla every 1/10th of a second.
MSG msg;
HANDLE hFakeEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
while (1)
{
// Process pending messages
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!::GetMessage(&msg, NULL, 0, 0))
{
// WM_QUIT
goto end_msg_loop;
}
PRBool runCondition = PR_TRUE;
WPARAM rv;
rv = AppCallbacks::RunEventLoop(runCondition);
PRBool wasHandled = PR_FALSE;
NS_HandleEmbeddingEvent(msg, wasHandled);
if (wasHandled)
{
continue;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Do idle stuff
NS_DoIdleEmbeddingStuff();
MsgWaitForMultipleObjects(1, &hFakeEvent, FALSE, 100, QS_ALLEVENTS);
}
CloseHandle(hFakeEvent);
end_msg_loop:
observer->Release();
observer->Release();
// Close down Embedding APIs
NS_TermEmbedding();
return msg.wParam;
return rv;
}
//-----------------------------------------------------------------------------
@ -307,7 +280,8 @@ nsresult OpenWebPage(const char *url)
// destruction (via Win32UI::Destroy)
nsIWebBrowserChrome *chrome = nsnull;
rv = CreateBrowserWindow(nsIWebBrowserChrome::CHROME_ALL, nsnull, &chrome);
rv = AppCallbacks::CreateBrowserWindow(nsIWebBrowserChrome::CHROME_ALL,
nsnull, &chrome);
if (NS_SUCCEEDED(rv))
{
// Start loading a page
@ -321,36 +295,6 @@ nsresult OpenWebPage(const char *url)
return rv;
}
nsresult CreateBrowserWindow(PRUint32 aChromeFlags, nsIWebBrowserChrome *aParent, nsIWebBrowserChrome **aNewWindow)
{
WebBrowserChrome * chrome = new WebBrowserChrome();
if (!chrome)
{
return NS_ERROR_FAILURE;
}
CallQueryInterface(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome), aNewWindow);
chrome->SetChromeFlags(aChromeFlags);
// Insert the browser
nsCOMPtr<nsIWebBrowser> newBrowser;
chrome->CreateBrowser(-1, -1, -1, -1, getter_AddRefs(newBrowser));
if (!newBrowser)
return NS_ERROR_FAILURE;
// Place it where we want it.
ResizeEmbedding(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome));
// Subscribe new window to profile changes so it can kill itself when one happens
nsresult rv;
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
observerService->AddObserver(NS_STATIC_CAST(nsIObserver *, chrome), NS_LITERAL_STRING("profile-change-teardown").get());
return NS_OK;
}
//
// FUNCTION: GetBrowserFromChrome()
//
@ -1058,7 +1002,8 @@ nativeWindow WebBrowserChromeUI::CreateNativeWindow(nsIWebBrowserChrome* chrome)
if (chromeFlags & nsIWebBrowserChrome::CHROME_MENUBAR) {
HMENU hmenuDlg = LoadMenu(ghInstanceResources, MAKEINTRESOURCE(IDC_WINEMBED));
SetMenu(hwndDialog, hmenuDlg);
}
} else
SetMenu(hwndDialog, 0);
// Add some interesting URLs to the address drop down
HWND hwndAddress = GetDlgItem(hwndDialog, IDC_ADDRESS);
@ -1087,37 +1032,32 @@ nativeWindow WebBrowserChromeUI::CreateNativeWindow(nsIWebBrowserChrome* chrome)
//
void WebBrowserChromeUI::Destroy(nsIWebBrowserChrome* chrome)
{
nsCOMPtr<nsIWebBrowser> webBrowser;
nsCOMPtr<nsIWebNavigation> webNavigation;
nsCOMPtr<nsIWebBrowser> webBrowser;
nsCOMPtr<nsIWebNavigation> webNavigation;
chrome->GetWebBrowser(getter_AddRefs(webBrowser));
webNavigation = do_QueryInterface(webBrowser);
chrome->GetWebBrowser(getter_AddRefs(webBrowser));
webNavigation = do_QueryInterface(webBrowser);
if (webNavigation)
webNavigation->Stop();
if (webNavigation)
{
webNavigation->Stop();
}
chrome->ExitModalEventLoop(NS_OK);
HWND hwndDlg = GetBrowserDlgFromChrome(chrome);
if (hwndDlg == NULL)
{
return;
}
HWND hwndDlg = GetBrowserDlgFromChrome(chrome);
if (hwndDlg == NULL)
return;
// Explicitly destroy the embedded browser and then the chrome
// Explicitly destroy the embedded browser and then the chrome
// First the browser
nsCOMPtr<nsIWebBrowser> browser = nsnull;
chrome->GetWebBrowser(getter_AddRefs(browser));
nsCOMPtr<nsIBaseWindow> browserAsWin = do_QueryInterface(browser);
if (browserAsWin)
{
browserAsWin->Destroy();
}
// First the browser
nsCOMPtr<nsIWebBrowser> browser = nsnull;
chrome->GetWebBrowser(getter_AddRefs(browser));
nsCOMPtr<nsIBaseWindow> browserAsWin = do_QueryInterface(browser);
if (browserAsWin)
browserAsWin->Destroy();
// Now the chrome
chrome->SetWebBrowser(nsnull);
NS_RELEASE(chrome);
// Now the chrome
chrome->SetWebBrowser(nsnull);
NS_RELEASE(chrome);
}
@ -1286,3 +1226,76 @@ void WebBrowserChromeUI::GetResourceStringById(PRInt32 aID, char ** aReturn)
return;
}
//-----------------------------------------------------------------------------
// AppCallbacks
//-----------------------------------------------------------------------------
nsresult AppCallbacks::CreateBrowserWindow(PRUint32 aChromeFlags,
nsIWebBrowserChrome *aParent,
nsIWebBrowserChrome **aNewWindow)
{
WebBrowserChrome * chrome = new WebBrowserChrome();
if (!chrome)
return NS_ERROR_FAILURE;
CallQueryInterface(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome), aNewWindow);
chrome->SetChromeFlags(aChromeFlags);
chrome->SetParent(aParent);
// Insert the browser
nsCOMPtr<nsIWebBrowser> newBrowser;
chrome->CreateBrowser(-1, -1, -1, -1, getter_AddRefs(newBrowser));
if (!newBrowser)
return NS_ERROR_FAILURE;
// Place it where we want it.
ResizeEmbedding(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome));
// Subscribe new window to profile changes so it can kill itself when one happens
nsCOMPtr<nsIObserverService> observerService(do_GetService(NS_OBSERVERSERVICE_CONTRACTID));
if (observerService)
observerService->AddObserver(NS_STATIC_CAST(nsIObserver *, chrome),
NS_LITERAL_STRING("profile-change-teardown").get());
return NS_OK;
}
void AppCallbacks::EnableChromeWindow(nsIWebBrowserChrome *aWindow,
PRBool aEnabled)
{
HWND hwnd = GetBrowserDlgFromChrome(aWindow);
::EnableWindow(hwnd, aEnabled ? TRUE : FALSE);
}
PRUint32 AppCallbacks::RunEventLoop(PRBool &aRunCondition)
{
MSG msg;
HANDLE hFakeEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
while (aRunCondition ) {
// Process pending messages
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!::GetMessage(&msg, NULL, 0, 0)) {
// WM_QUIT
aRunCondition = PR_FALSE;
break;
}
PRBool wasHandled = PR_FALSE;
::NS_HandleEmbeddingEvent(msg, wasHandled);
if (wasHandled)
continue;
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
// Do idle stuff
::NS_DoIdleEmbeddingStuff();
::MsgWaitForMultipleObjects(1, &hFakeEvent, FALSE, 100, QS_ALLEVENTS);
}
::CloseHandle(hFakeEvent);
return msg.wParam;
}

View File

@ -24,7 +24,12 @@
class nsIWebBrowserChrome;
// a little ooky, but new windows gotta come from somewhere
nsresult CreateBrowserWindow(PRUint32 aChromeFlags, nsIWebBrowserChrome *aParent,
nsIWebBrowserChrome **aNewWindow);
namespace AppCallbacks {
nsresult CreateBrowserWindow(PRUint32 aChromeFlags,
nsIWebBrowserChrome *aParent,
nsIWebBrowserChrome **aNewWindow);
void EnableChromeWindow(nsIWebBrowserChrome *aWindow, PRBool aEnabled);
PRUint32 RunEventLoop(PRBool &aRunCondition);
}