Fix bug #51130. Use common dialogs for nsIPrompt in the embedding widget. r=danm, sr=brendan
git-svn-id: svn://10.0.0.236/trunk@83381 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "nsIDocShell.h"
|
||||
|
||||
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
||||
static NS_DEFINE_CID(kCommonDialogsCID, NS_CommonDialog_CID);
|
||||
|
||||
// this is a define to make sure that we don't call certain function
|
||||
// before the object has been properly initialized
|
||||
@@ -93,6 +94,7 @@ NS_INTERFACE_MAP_BEGIN(GtkMozEmbedChrome)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIPrompt)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
// nsIGtkEmbed interface
|
||||
@@ -307,6 +309,44 @@ NS_IMETHODIMP GtkMozEmbedChrome::CloseStream (void)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::EnsureCommonDialogs(void)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (!mCommonDialogs)
|
||||
mCommonDialogs = do_GetService(kCommonDialogsCID, &rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::GetDOMWindowInternal (nsIDOMWindowInternal **aWindow)
|
||||
{
|
||||
|
||||
// get the browser as an item
|
||||
nsCOMPtr<nsIDocShellTreeItem> browserAsItem;
|
||||
browserAsItem = do_QueryInterface(mWebBrowser);
|
||||
NS_ENSURE_TRUE(browserAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
// get the owner for that item
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
browserAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
|
||||
|
||||
// get the primary content shell as an item
|
||||
nsCOMPtr<nsIDocShellTreeItem> contentItem;
|
||||
treeOwner->GetPrimaryContentShell(getter_AddRefs(contentItem));
|
||||
NS_ENSURE_TRUE(contentItem, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
domWindow = do_GetInterface(contentItem);
|
||||
NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
|
||||
|
||||
*aWindow = domWindow.get();
|
||||
NS_ADDREF(*aWindow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIInterfaceRequestor interface
|
||||
|
||||
NS_IMETHODIMP GtkMozEmbedChrome::GetInterface(const nsIID &aIID, void** aInstancePtr)
|
||||
@@ -867,3 +907,228 @@ GtkMozEmbedChrome::GetPersistence(PRBool* aPersistX, PRBool* aPersistY,
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// nsIPrompt
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::Alert(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->Alert(domWindow, dialogTitle, text);
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::AlertCheck(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text,
|
||||
const PRUnichar *checkMsg,
|
||||
PRBool *checkValue)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->AlertCheck(domWindow, dialogTitle, text, checkMsg, checkValue);
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::Confirm(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text, PRBool *_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->Confirm(domWindow, dialogTitle, text, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::ConfirmCheck(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text,
|
||||
const PRUnichar *checkMsg,
|
||||
PRBool *checkValue, PRBool *_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->ConfirmCheck(domWindow,
|
||||
dialogTitle,
|
||||
text,
|
||||
checkMsg,
|
||||
checkValue,
|
||||
_retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::Prompt(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text,
|
||||
const PRUnichar *passwordRealm,
|
||||
PRUint32 savePassword,
|
||||
const PRUnichar *defaultText,
|
||||
PRUnichar **result, PRBool *_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->Prompt(domWindow,
|
||||
dialogTitle,
|
||||
text,
|
||||
defaultText,
|
||||
result,
|
||||
_retval);
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::PromptUsernameAndPassword(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text,
|
||||
const PRUnichar *passwordRealm,
|
||||
PRUint32 savePassword,
|
||||
PRUnichar **user,
|
||||
PRUnichar **pwd,
|
||||
PRBool *_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->PromptUsernameAndPassword(domWindow, dialogTitle,
|
||||
text, user, pwd, _retval);
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::PromptPassword(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text,
|
||||
const PRUnichar *passwordRealm,
|
||||
PRUint32 savePassword, PRUnichar **pwd,
|
||||
PRBool *_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->PromptPassword(domWindow,
|
||||
dialogTitle,
|
||||
text,
|
||||
pwd, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::Select(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text, PRUint32 count,
|
||||
const PRUnichar **selectList,
|
||||
PRInt32 *outSelection, PRBool *_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->Select(domWindow, dialogTitle,
|
||||
text, count, selectList,
|
||||
outSelection, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkMozEmbedChrome::UniversalDialog(const PRUnichar *titleMessage,
|
||||
const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text,
|
||||
const PRUnichar *checkboxMsg,
|
||||
const PRUnichar *button0Text,
|
||||
const PRUnichar *button1Text,
|
||||
const PRUnichar *button2Text,
|
||||
const PRUnichar *button3Text,
|
||||
const PRUnichar *editfield1Msg,
|
||||
const PRUnichar *editfield2Msg,
|
||||
PRUnichar **editfield1Value,
|
||||
PRUnichar **editfield2Value,
|
||||
const PRUnichar *iconURL,
|
||||
PRBool *checkboxState,
|
||||
PRInt32 numberButtons,
|
||||
PRInt32 numberEditfields,
|
||||
PRInt32 editField1Password,
|
||||
PRInt32 *buttonPressed)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = EnsureCommonDialogs();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
rv = GetDOMWindowInternal(getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return mCommonDialogs->UniversalDialog(domWindow, titleMessage,
|
||||
dialogTitle, text,
|
||||
checkboxMsg, button0Text,
|
||||
button1Text,
|
||||
button2Text,
|
||||
button3Text,
|
||||
editfield1Msg,
|
||||
editfield2Msg,
|
||||
editfield1Value,
|
||||
editfield2Value,
|
||||
iconURL,
|
||||
checkboxState,
|
||||
numberButtons,
|
||||
numberEditfields,
|
||||
editField1Password,
|
||||
buttonPressed);
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIDocShellTreeOwner.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsICommonDialogs.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
|
||||
// utility classes
|
||||
#include "nsXPIDLString.h"
|
||||
@@ -54,7 +57,8 @@ class GtkMozEmbedChrome : public nsIGtkEmbed,
|
||||
public nsIBaseWindow,
|
||||
public nsIURIContentListener,
|
||||
public nsIDocShellTreeOwner,
|
||||
public nsIInterfaceRequestor
|
||||
public nsIInterfaceRequestor,
|
||||
public nsIPrompt
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -71,6 +75,8 @@ public:
|
||||
NS_IMETHOD OpenStream (const char *aBaseURI, const char *aContentType);
|
||||
NS_IMETHOD AppendToStream (const char *aData, gint32 aLen);
|
||||
NS_IMETHOD CloseStream (void);
|
||||
NS_IMETHOD EnsureCommonDialogs (void);
|
||||
NS_IMETHOD GetDOMWindowInternal (nsIDOMWindowInternal **aWindow);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
@@ -84,6 +90,8 @@ public:
|
||||
|
||||
NS_DECL_NSIBASEWINDOW
|
||||
|
||||
NS_DECL_NSIPROMPT
|
||||
|
||||
private:
|
||||
GtkWidget *mOwningGtkWidget;
|
||||
nsCOMPtr<nsIWebBrowser> mWebBrowser;
|
||||
@@ -104,6 +112,7 @@ private:
|
||||
PRBool mDoingStream;
|
||||
GtkEmbedListener *mChromeListener;
|
||||
nsIDocShellTreeItem *mContentShell;
|
||||
nsCOMPtr<nsICommonDialogs> mCommonDialogs;
|
||||
};
|
||||
|
||||
#endif /* __GtkMozEmbedChrome_h */
|
||||
|
||||
@@ -47,6 +47,8 @@
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsIAppShell.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsIXULWindow.h"
|
||||
|
||||
// freakin X headers
|
||||
#ifdef Success
|
||||
@@ -417,7 +419,7 @@ GtkMozEmbedPrivate::LoadChrome(void)
|
||||
NS_ASSERTION(cx == nsnull, "JSContextStack mismatch");
|
||||
|
||||
}
|
||||
|
||||
|
||||
// and spindown...
|
||||
subShell->Spindown();
|
||||
|
||||
@@ -740,7 +742,10 @@ static GdkWindow *offscreen_window = 0;
|
||||
|
||||
static char *component_path = 0;
|
||||
static gint num_widgets = 0;
|
||||
nsCOMPtr <nsIAppShell> gAppShell;
|
||||
nsCOMPtr <nsIAppShell> gAppShell;
|
||||
nsCOMPtr <nsIXULWindow> gHiddenWindow = 0;
|
||||
|
||||
|
||||
|
||||
/* class and instance initialization */
|
||||
|
||||
@@ -1551,6 +1556,15 @@ gtk_moz_embed_startup_xpcom(void)
|
||||
if (NS_FAILED(rv))
|
||||
return FALSE;
|
||||
|
||||
// Start up the appshell service. We need this for chrome windows.
|
||||
nsCOMPtr<nsIAppShellService> appShell(do_GetService(kAppShellServiceCID));
|
||||
appShell->Initialize(nsnull, nsnull);
|
||||
// create a hidden window so that the appshell service doesn't try
|
||||
// and Quit on us when a dialog goes away.
|
||||
appShell->CreateTopLevelWindow(nsnull, nsnull, PR_FALSE, PR_FALSE,
|
||||
0, 1, 1, getter_AddRefs(gHiddenWindow));
|
||||
|
||||
// spin up an appshell
|
||||
gAppShell = do_CreateInstance(kAppShellCID);
|
||||
NS_ENSURE_TRUE(gAppShell, NS_ERROR_FAILURE);
|
||||
|
||||
@@ -1565,8 +1579,14 @@ gtk_moz_embed_shutdown_xpcom(void)
|
||||
{
|
||||
if (gAppShell)
|
||||
{
|
||||
// Shutdown the appshell service after deleting the hidden window
|
||||
gHiddenWindow = 0;
|
||||
nsCOMPtr<nsIAppShellService> appShell(do_GetService(kAppShellServiceCID));
|
||||
appShell->Shutdown();
|
||||
appShell = 0;
|
||||
// spin down the appshell
|
||||
gAppShell->Spindown();
|
||||
gAppShell = nsnull;
|
||||
gAppShell = 0;
|
||||
// shut down XPCOM
|
||||
NS_TermEmbedding();
|
||||
}
|
||||
@@ -1618,6 +1638,27 @@ GtkMozEmbedListenerImpl::NewBrowser(PRUint32 chromeMask,
|
||||
nsIDocShellTreeItem **_retval)
|
||||
{
|
||||
GtkMozEmbed *newEmbed = NULL;
|
||||
// if it's a chrome window that's being requested, don't even bother
|
||||
// allowing the app to catch it.
|
||||
if (chromeMask & nsIWebBrowserChrome::CHROME_OPENAS_CHROME) {
|
||||
nsCOMPtr<nsIAppShellService> appShell(do_GetService(kAppShellServiceCID));
|
||||
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIXULWindow> newWindow;
|
||||
appShell->CreateTopLevelWindow(nsnull, nsnull, PR_FALSE, PR_FALSE,
|
||||
chromeMask, NS_SIZETOCONTENT, NS_SIZETOCONTENT,
|
||||
getter_AddRefs(newWindow));
|
||||
|
||||
NS_ENSURE_TRUE(newWindow, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(newWindow));
|
||||
if (browserChrome)
|
||||
browserChrome->SetChromeFlags(chromeMask);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
newWindow->GetDocShell(getter_AddRefs(docShell));
|
||||
CallQueryInterface(docShell, _retval);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
gtk_signal_emit(GTK_OBJECT(mEmbed), moz_embed_signals[NEW_WINDOW],
|
||||
&newEmbed, (guint)chromeMask);
|
||||
if (newEmbed) {
|
||||
|
||||
Reference in New Issue
Block a user