From c0e8b19693a09635ee2e2549501800c6e492284d Mon Sep 17 00:00:00 2001 From: Lakshmi Shanmugam Date: Mon, 27 Feb 2012 16:06:53 +0530 Subject: changed the fix for Bug 372134-Prompter.getBrowser() not working. Also fixes 372143. --- .../org/eclipse/swt/browser/PromptAuth2.java | 35 ++++--------------- .../org/eclipse/swt/browser/PromptFactory.java | 4 ++- .../common/org/eclipse/swt/browser/Prompter.java | 40 ++++++---------------- .../swt/internal/mozilla/nsIPromptFactory.java | 4 +-- 4 files changed, 22 insertions(+), 61 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptAuth2.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptAuth2.java index 4ab9d4daf3..69813f2261 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptAuth2.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptAuth2.java @@ -19,6 +19,7 @@ class PromptAuth2 { XPCOMObject supports; XPCOMObject promptAuth; int refCount = 0; + int /*long*/ parent; PromptAuth2 () { createCOMInterfaces (); @@ -87,36 +88,14 @@ int Release () { return refCount; } -Browser getBrowser() { - int /*long*/[] result = new int /*long*/[1]; - int rc = XPCOM.NS_GetServiceManager (result); - if (rc != XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE); - - nsIServiceManager serviceManager = new nsIServiceManager (result[0]); - result[0] = 0; - byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_FOCUSMANAGER_CONTRACTID, true); - rc = serviceManager.GetServiceByContractID (aContractID, !Mozilla.IsPre_4 ? nsIFocusManager.NS_IFOCUSMANAGER_10_IID : nsIFocusManager.NS_IFOCUSMANAGER_IID, result); - serviceManager.Release (); - - if (rc == XPCOM.NS_OK && result[0] != 0) { - nsIFocusManager focusManager = new nsIFocusManager (result[0]); - result[0] = 0; - rc = focusManager.GetActiveWindow (result); - focusManager.Release (); - if (rc == XPCOM.NS_OK && result[0] != 0) { - nsIDOMWindow domWindow = new nsIDOMWindow (result[0]); - result[0] = 0; - rc = domWindow.GetTop(result); - domWindow.Release(); - if (rc == XPCOM.NS_OK && result[0] != 0) { - return Mozilla.getBrowser(result[0]); - } - } - } - return null; +Browser getBrowser () { + if (parent == 0) return null; + return Mozilla.getBrowser (parent); } +void setParent(int /*long*/ aParent) { + parent = aParent; +} int PromptAuth(int /*long*/ aChannel, int level, int /*long*/ authInfo, int /*long*/ _retval) { nsIAuthInformation auth = new nsIAuthInformation (authInfo); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptFactory.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptFactory.java index ea4339d408..f2b4c70d8b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptFactory.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptFactory.java @@ -86,13 +86,14 @@ int Release () { /* nsIPromptFactory */ -int GetPrompt (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { +int GetPrompt (int /*long*/ aParent, int /*long*/ iid, int /*long*/ result) { nsID guid = new nsID (); XPCOM.memmove (guid, iid, nsID.sizeof); if (guid.Equals (nsIPrompt.NS_IPROMPT_IID)) { Prompter prompter = new Prompter (); prompter.AddRef (); + prompter.setParent (aParent); XPCOM.memmove (result, new int /*long*/[] {prompter.getAddress ()}, C.PTR_SIZEOF); AddRef (); return XPCOM.NS_OK; @@ -100,6 +101,7 @@ int GetPrompt (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { if (guid.Equals (nsIAuthPrompt2.NS_IAUTHPROMPT2_IID)) { PromptAuth2 promptAuth = new PromptAuth2(); promptAuth.AddRef (); + promptAuth.setParent (aParent); XPCOM.memmove (result, new int /*long*/[] {promptAuth.getAddress ()}, C.PTR_SIZEOF); AddRef (); return XPCOM.NS_OK; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Prompter.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Prompter.java index 173f55fdbd..1541d1fdc1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Prompter.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Prompter.java @@ -19,6 +19,7 @@ class Prompter { XPCOMObject supports; XPCOMObject prompt; int refCount = 0; + int /*long*/ parent; Prompter () { createCOMInterfaces (); @@ -93,6 +94,11 @@ int Release () { return refCount; } +Browser getBrowser () { + if (parent == 0) return null; + return Mozilla.getBrowser (parent); +} + String getLabel (int buttonFlag, int index, int /*long*/ buttonTitle) { String label = null; int flag = (buttonFlag & (0xff * index)) / index; @@ -112,6 +118,10 @@ String getLabel (int buttonFlag, int index, int /*long*/ buttonTitle) { return label; } +void setParent(int /*long*/ aParent) { + parent = aParent; +} + /* nsIPrompt */ int Alert (int /*long*/ aDialogTitle, int /*long*/ aText) { @@ -144,36 +154,6 @@ int Alert (int /*long*/ aDialogTitle, int /*long*/ aText) { return XPCOM.NS_OK; } -Browser getBrowser() { - int /*long*/[] result = new int /*long*/[1]; - int rc = XPCOM.NS_GetServiceManager (result); - if (rc != XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE); - - nsIServiceManager serviceManager = new nsIServiceManager (result[0]); - result[0] = 0; - byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_FOCUSMANAGER_CONTRACTID, true); - rc = serviceManager.GetServiceByContractID (aContractID, !Mozilla.IsPre_4 ? nsIFocusManager.NS_IFOCUSMANAGER_10_IID : nsIFocusManager.NS_IFOCUSMANAGER_IID, result); - serviceManager.Release (); - - if (rc == XPCOM.NS_OK && result[0] != 0) { - nsIFocusManager focusManager = new nsIFocusManager (result[0]); - result[0] = 0; - rc = focusManager.GetActiveWindow (result); - focusManager.Release (); - if (rc == XPCOM.NS_OK && result[0] != 0) { - nsIDOMWindow domWindow = new nsIDOMWindow (result[0]); - result[0] = 0; - rc = domWindow.GetTop(result); - domWindow.Release(); - if (rc == XPCOM.NS_OK && result[0] != 0) { - return Mozilla.getBrowser(result[0]); - } - } - } - return null; -} - int AlertCheck (int /*long*/ aDialogTitle, int /*long*/ aText, int /*long*/ aCheckMsg, int /*long*/ aCheckState) { Browser browser = getBrowser (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIPromptFactory.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIPromptFactory.java index fada150e7c..6f692c923a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIPromptFactory.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIPromptFactory.java @@ -41,7 +41,7 @@ public class nsIPromptFactory extends nsISupports { super(address); } - public int Alert(char[] aDialogTitle, char[] aText) { - return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 1, getAddress(), aDialogTitle, aText); + public int getPrompt(int /*long*/ aParent, nsID iid, int /*long*/[] result) { + return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 1, getAddress(), aParent, iid, result); } } -- cgit v1.2.3