Bug 467203 - Download progress window not shown with XULRunner 31 The
download doesn't start automatically with XULR 31 browser and the
progress window doesn't show up. The workaround is to open the download
progress window, so that user can start the download.

Change-Id: I375726944c5482506d8189a4955fdcbbe1ea0f09
Change-Id: Change-Id: Ibfd81d646bfd6fdd35c5572a300cae24ce353795
Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialogFactory.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialogFactory.java
index 01887f8..5bc5616 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialogFactory.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialogFactory.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2013 IBM Corporation and others.
+ * Copyright (c) 2003, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,7 +10,7 @@
  *******************************************************************************/
 package org.eclipse.swt.browser;
 
-import org.eclipse.swt.internal.C;
+import org.eclipse.swt.internal.*;
 import org.eclipse.swt.internal.mozilla.*;
 
 class HelperAppLauncherDialogFactory {
@@ -18,8 +18,8 @@
 	XPCOMObject factory;
 	int refCount = 0;
 
-HelperAppLauncherDialogFactory () {
-	createCOMInterfaces ();
+HelperAppLauncherDialogFactory (final Mozilla webBrowser) {
+	createCOMInterfaces (webBrowser);
 }
 
 int AddRef () {
@@ -27,7 +27,7 @@
 	return refCount;
 }
 
-void createCOMInterfaces () {
+void createCOMInterfaces (final Mozilla webBrowser) {
 	/* Create each of the interfaces that this object implements */
 	supports = new XPCOMObject (new int[] {2, 0, 0}) {
 		@Override
@@ -46,7 +46,7 @@
 		@Override
 		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
 		@Override
-		public long /*int*/ method3 (long /*int*/[] args) {return CreateInstance (args[0], args[1], args[2]);}
+		public long /*int*/ method3 (long /*int*/[] args) {return CreateInstance (args[0], args[1], args[2], webBrowser);}
 		@Override
 		public long /*int*/ method4 (long /*int*/[] args) {return LockFactory ((int)/*64*/args[0]);}
 	};
@@ -95,17 +95,17 @@
 	
 /* nsIFactory */
 
-int CreateInstance (long /*int*/ aOuter, long /*int*/ iid, long /*int*/ result) {
+int CreateInstance (long /*int*/ aOuter, long /*int*/ iid, long /*int*/ result, final Mozilla webBrowser) {
 	if (!MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR1_9)) {
 		HelperAppLauncherDialog helperAppLauncherDialog = new HelperAppLauncherDialog ();
 		helperAppLauncherDialog.AddRef ();
 		XPCOM.memmove (result, new long /*int*/[] {helperAppLauncherDialog.getAddress ()}, C.PTR_SIZEOF);
 	} else if (!MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR10)){
-		HelperAppLauncherDialog_1_9 helperAppLauncherDialog = new HelperAppLauncherDialog_1_9 ();
+		HelperAppLauncherDialog_1_9 helperAppLauncherDialog = new HelperAppLauncherDialog_1_9 (webBrowser);
 		helperAppLauncherDialog.AddRef ();
 		XPCOM.memmove (result, new long /*int*/[] {helperAppLauncherDialog.getAddress ()}, C.PTR_SIZEOF);
 	} else {
-		HelperAppLauncherDialog_10 helperAppLauncherDialog = new HelperAppLauncherDialog_10 ();
+		HelperAppLauncherDialog_10 helperAppLauncherDialog = new HelperAppLauncherDialog_10 (webBrowser);
 		helperAppLauncherDialog.AddRef ();
 		XPCOM.memmove (result, new long /*int*/[] {helperAppLauncherDialog.getAddress ()}, C.PTR_SIZEOF);
 	}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialog_10.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialog_10.java
index 1e1b963..0976e59 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialog_10.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialog_10.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 IBM Corporation and others.
+ * Copyright (c) 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -26,8 +26,9 @@
 	XPCOMObject helperAppLauncherDialog;
 	int refCount = 0;
 
-HelperAppLauncherDialog_10 () {
-	createCOMInterfaces ();
+HelperAppLauncherDialog_10 (final Mozilla webBrowser) {
+	super (webBrowser);
+	createCOMInterfaces (webBrowser);
 }
 
 /* nsIHelperAppLauncherDialog */
@@ -39,7 +40,7 @@
 }
 
 @Override
-int PromptForSaveToFile (long /*int*/ aLauncher, long /*int*/ aWindowContext, long /*int*/ aDefaultFileName, long /*int*/ aSuggestedFileExtension, int aForcePrompt, long /*int*/ _retval) {
+int PromptForSaveToFile (long /*int*/ aLauncher, long /*int*/ aWindowContext, long /*int*/ aDefaultFileName, long /*int*/ aSuggestedFileExtension, int aForcePrompt, long /*int*/ _retval, final Mozilla webBrowser) {
 	int length = XPCOM.strlen_PRUnichar (aDefaultFileName);
 	char[] dest = new char[length];
 	XPCOM.memmove (dest, aDefaultFileName, length * 2);
@@ -68,8 +69,12 @@
 	path.dispose ();
 	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
 	if (result[0] == 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
+	/* 
+	 * In XULRunner 31, download doesn't start automatically and progress window doesn't open. 
+	 * We open it the download progress window, so that user can start the download, bug 467203.
+	 */	
 	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR31, true)) {
-		Mozilla.shouldOpenDownloadProgressWindow = true;
+		webBrowser.openDownloadProgressWindow = true;
 	}
 	XPCOM.memmove (_retval, result, C.PTR_SIZEOF);	
 	return XPCOM.NS_OK;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialog_1_9.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialog_1_9.java
index 36c01f5..49d1190 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialog_1_9.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/HelperAppLauncherDialog_1_9.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2013 IBM Corporation and others.
+ * Copyright (c) 2003, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -11,7 +11,7 @@
 package org.eclipse.swt.browser;
 
 import org.eclipse.swt.*;
-import org.eclipse.swt.internal.C;
+import org.eclipse.swt.internal.*;
 import org.eclipse.swt.internal.mozilla.*;
 import org.eclipse.swt.widgets.*;
 
@@ -26,8 +26,8 @@
 	XPCOMObject helperAppLauncherDialog;
 	int refCount = 0;
 
-HelperAppLauncherDialog_1_9 () {
-	createCOMInterfaces ();
+HelperAppLauncherDialog_1_9 (final Mozilla webBrowser) {
+	createCOMInterfaces (webBrowser);
 }
 
 int AddRef () {
@@ -35,7 +35,7 @@
 	return refCount;
 }
 
-void createCOMInterfaces () {
+void createCOMInterfaces (final Mozilla webBrowser) {
 	/* Create each of the interfaces that this object implements */
 	supports = new XPCOMObject (new int[] {2, 0, 0}) {
 		@Override
@@ -56,7 +56,7 @@
 		@Override
 		public long /*int*/ method3 (long /*int*/[] args) {return Show (args[0], args[1], (int)/*64*/args[2]);}
 		@Override
-		public long /*int*/ method4 (long /*int*/[] args) {return PromptForSaveToFile (args[0], args[1], args[2], args[3], (int)/*64*/args[4], args[5]);}
+		public long /*int*/ method4 (long /*int*/[] args) {return PromptForSaveToFile (args[0], args[1], args[2], args[3], (int)/*64*/args[4], args[5], webBrowser);}
 	};		
 }
 
@@ -115,7 +115,7 @@
 	return helperAppLauncher.SaveToDisk (0, 0);
 }
 
-int PromptForSaveToFile (long /*int*/ aLauncher, long /*int*/ aWindowContext, long /*int*/ aDefaultFileName, long /*int*/ aSuggestedFileExtension, int aForcePrompt, long /*int*/ _retval) {
+int PromptForSaveToFile (long /*int*/ aLauncher, long /*int*/ aWindowContext, long /*int*/ aDefaultFileName, long /*int*/ aSuggestedFileExtension, int aForcePrompt, long /*int*/ _retval, final Mozilla webBrowser) {
 	int length = XPCOM.strlen_PRUnichar (aDefaultFileName);
 	char[] dest = new char[length];
 	XPCOM.memmove (dest, aDefaultFileName, length * 2);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
index d7cc81c..8070087 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
@@ -54,7 +54,7 @@
 	long /*int*/ request, badCertRequest;
 	Point location, size;
 	boolean visible, isActive, isChild, ignoreDispose, isRetrievingBadCert, isViewingErrorPage, ignoreAllMessages, untrustedText;
-	boolean updateLastNavigateUrl;
+	boolean updateLastNavigateUrl, openDownloadProgressWindow;
 	Shell tip = null;
 	Listener listener;
 	Vector<LONG> unhookedDOMWindows = new Vector<LONG> ();
@@ -69,7 +69,6 @@
 	static Listener DisplayListener;
 	static boolean Initialized, IsXULRunner, PerformedVersionCheck, XPCOMWasGlued, XPCOMInitWasGlued;
 	static boolean IsGettingSiteWindow;
-	static boolean shouldOpenDownloadProgressWindow = false;
 	static String MozillaPath;
 	static String oldProxyHostFTP, oldProxyHostHTTP, oldProxyHostSSL;
 	static int oldProxyPortFTP = -1, oldProxyPortHTTP = -1, oldProxyPortSSL = -1, oldProxyType = -1;
@@ -898,7 +897,7 @@
 		componentRegistrar.Release ();
 		
 		if (!factoriesRegistered) {
-			HelperAppLauncherDialogFactory dialogFactory = new HelperAppLauncherDialogFactory ();
+			HelperAppLauncherDialogFactory dialogFactory = new HelperAppLauncherDialogFactory (this);
 			dialogFactory.AddRef ();
 			byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID, true);
 			byte[] aClassName = MozillaDelegate.wcsToMbcs (null, "swtHelperAppLauncherDialog", true); //$NON-NLS-1$
@@ -2879,7 +2878,7 @@
 }
 
 void initWindowCreator (nsIServiceManager serviceManager) {
-	WindowCreator = new WindowCreator2 ();
+	WindowCreator = new WindowCreator2 (this);
 	WindowCreator.AddRef ();
 	
 	long /*int*/[] result = new long /*int*/[1];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/WindowCreator2.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/WindowCreator2.java
index 375c2ee..a76f920 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/WindowCreator2.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/WindowCreator2.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2013 IBM Corporation and others.
+ * Copyright (c) 2003, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -23,8 +23,8 @@
 	XPCOMObject windowCreator2;
 	int refCount = 0;
 
-WindowCreator2 () {
-	createCOMInterfaces ();
+WindowCreator2 (final Mozilla webBrowser) {
+	createCOMInterfaces (webBrowser);
 }
 
 int AddRef () {
@@ -32,7 +32,7 @@
 	return refCount;
 }
 
-void createCOMInterfaces () {
+void createCOMInterfaces (final Mozilla webBrowser) {
 	/* Create each of the interfaces that this object implements */
 	supports = new XPCOMObject (new int[] {2, 0, 0}) {
 		@Override
@@ -51,7 +51,7 @@
 		@Override
 		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
 		@Override
-		public long /*int*/ method3 (long /*int*/[] args) {return CreateChromeWindow (args[0], (int)/*64*/args[1], args[2]);}
+		public long /*int*/ method3 (long /*int*/[] args) {return CreateChromeWindow (args[0], (int)/*64*/args[1], args[2], webBrowser);}
 	};
 
 	windowCreator2 = new XPCOMObject (new int[] {2, 0, 0, 3, 6}) {
@@ -62,9 +62,9 @@
 		@Override
 		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
 		@Override
-		public long /*int*/ method3 (long /*int*/[] args) {return CreateChromeWindow (args[0], (int)/*64*/args[1], args[2]);}
+		public long /*int*/ method3 (long /*int*/[] args) {return CreateChromeWindow (args[0], (int)/*64*/args[1], args[2], webBrowser);}
 		@Override
-		public long /*int*/ method4 (long /*int*/[] args) {return CreateChromeWindow2 (args[0], (int)/*64*/args[1], (int)/*64*/args[2], args[3], args[4], args[5]);}
+		public long /*int*/ method4 (long /*int*/[] args) {return CreateChromeWindow2 (args[0], (int)/*64*/args[1], (int)/*64*/args[2], args[3], args[4], args[5], webBrowser);}
 	};
 }
 
@@ -121,13 +121,13 @@
 	
 /* nsIWindowCreator */
 
-int CreateChromeWindow (long /*int*/ parent, int chromeFlags, long /*int*/ _retval) {
-	return CreateChromeWindow2 (parent, chromeFlags, 0, 0, 0, _retval);
+int CreateChromeWindow (long /*int*/ parent, int chromeFlags, long /*int*/ _retval, final Mozilla webBrowser) {
+	return CreateChromeWindow2 (parent, chromeFlags, 0, 0, 0, _retval, webBrowser);
 }
 
 /* nsIWindowCreator2 */
 
-int CreateChromeWindow2 (long /*int*/ parent, int chromeFlags, int contextFlags, long /*int*/ uri, long /*int*/ cancel, long /*int*/ _retval) {
+int CreateChromeWindow2 (long /*int*/ parent, int chromeFlags, int contextFlags, long /*int*/ uri, long /*int*/ cancel, long /*int*/ _retval, final Mozilla webBrowser) {
 	if (parent == 0 && (chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) == 0) {
 		return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 	}
@@ -139,14 +139,14 @@
 		if (rc != XPCOM.NS_OK) Mozilla.error (rc);
 		if (aWebBrowser[0] == 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
 
-		nsIWebBrowser webBrowser = new nsIWebBrowser (aWebBrowser[0]);
+		nsIWebBrowser nsiwebBrowser = new nsIWebBrowser (aWebBrowser[0]);
 		long /*int*/[] result = new long /*int*/[1];
-		rc = webBrowser.QueryInterface (IIDStore.GetIID (nsIBaseWindow.class), result);
+		rc = nsiwebBrowser.QueryInterface (IIDStore.GetIID (nsIBaseWindow.class), result);
 		if (rc != XPCOM.NS_OK) {
 			SWT.error (rc);
 		}
 		if (result[0] == 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
-		webBrowser.Release ();
+		nsiwebBrowser.Release ();
 
 		nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]);
 		result[0] = 0;
@@ -177,13 +177,12 @@
 			new Shell (src.getShell(), style);
 		shell.setLayout (new FillLayout ());
 		browser = new Browser (shell, src == null ? SWT.MOZILLA : src.getStyle () & SWT.MOZILLA);
-		if (Mozilla.shouldOpenDownloadProgressWindow) {
+		if (webBrowser.openDownloadProgressWindow) {
 			/* 
 			 * In XULRunner 31, download doesn't start automatically and progress window doesn't open. 
-			 * We open it the download progress window, so that user can start the download.
+			 * We open it the download progress window, so that user can start the download, bug 467203.
 			 */
-			
-			Mozilla.shouldOpenDownloadProgressWindow = false;
+			webBrowser.openDownloadProgressWindow = false;
 			shell.open();
 		}
 		browser.addVisibilityWindowListener (new VisibilityWindowListener () {