diff options
author | Grant Gayed <grant_gayed@ca.ibm.com> | 2012-04-09 14:53:37 -0400 |
---|---|---|
committer | Grant Gayed <grant_gayed@ca.ibm.com> | 2012-04-09 14:53:37 -0400 |
commit | 8710f852db4fc9958b4bb54e4ade6b0911b03418 (patch) | |
tree | 6b097bc8652044f7199754f3db344bfb704b6caf | |
parent | 31cb89b02b5dd4f6edf6e9fd65ce9f2e59fabcb6 (diff) | |
download | eclipse.platform.swt-8710f852db4fc9958b4bb54e4ade6b0911b03418.tar.gz eclipse.platform.swt-8710f852db4fc9958b4bb54e4ade6b0911b03418.tar.xz eclipse.platform.swt-8710f852db4fc9958b4bb54e4ade6b0911b03418.zip |
Bug 372654 - XULRunner 10 crash when JS window.print() invoked
6 files changed, 73 insertions, 10 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java index 88c2d85c48..486dbdc803 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java @@ -257,6 +257,10 @@ int getHandle () { return embedHandle; } +int /*long*/ getSiteWindow () { + return embedHandle; +} + void handleFocus () { if (hasFocus) return; hasFocus = true; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java index 7801df8112..e0044d63a8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java @@ -142,6 +142,10 @@ int /*long*/ getHandle () { return browser.view.id; } +int /*long*/ getSiteWindow () { + return browser.view.id; +} + void handleFocus () { if (hasFocus) return; hasFocus = true; 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 99488e790e..eff03b2ebc 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 @@ -63,6 +63,7 @@ class Mozilla extends WebBrowser { static Hashtable AllFunctions = new Hashtable (); static Listener DisplayListener; static boolean Initialized, IsPre_1_8, IsPre_1_9, IsPre_4, IsXULRunner, PerformedVersionCheck, XPCOMWasGlued, XPCOMInitWasGlued; + static boolean IsGettingSiteWindow; static String MozillaPath; static String oldProxyHostFTP, oldProxyHostHTTP, oldProxyHostSSL; static int oldProxyPortFTP = -1, oldProxyPortHTTP = -1, oldProxyPortSSL = -1, oldProxyType = -1; @@ -1464,7 +1465,9 @@ static Browser getBrowser (int /*long*/ aDOMWindow) { nsIEmbeddingSiteWindow embeddingSiteWindow = new nsIEmbeddingSiteWindow (result[0]); result[0] = 0; + IsGettingSiteWindow = true; rc = embeddingSiteWindow.GetSiteWindow (result); + IsGettingSiteWindow = false; if (rc != XPCOM.NS_OK) Mozilla.error (rc); if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE); embeddingSiteWindow.Release (); @@ -4221,15 +4224,16 @@ int SetTitle (int /*long*/ aTitle) { int GetSiteWindow (int /*long*/ aSiteWindow) { /* - * Note. The handle is expected to be an HWND on Windows and - * a GtkWidget* on GTK. This callback is invoked on Windows - * when the javascript window.print is invoked and the print - * dialog comes up. If no handle is returned, the print dialog - * does not come up on this platform. + * This is expected to be an HWND on Windows, a GtkWidget* on GTK, and + * a WindowPtr on OS X. This callback is invoked on Windows when the + * print dialog is to be shown. If no handle is returned then no print + * dialog is shown with XULRunner versions < 4. */ - XPCOM.memmove (aSiteWindow, new int /*long*/[] {embedHandle}, C.PTR_SIZEOF); + + int /*long*/ siteWindow = delegate.getSiteWindow (); + XPCOM.memmove (aSiteWindow, new int /*long*/[] {siteWindow}, C.PTR_SIZEOF); return XPCOM.NS_OK; -} +} /* nsIWebBrowserChromeFocus */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java index afe1f0fd5a..956f0fcd35 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java @@ -183,6 +183,10 @@ int /*long*/ getHandle () { return embedHandle; } +int /*long*/ getSiteWindow () { + return embedHandle; +} + int /*long*/ gtk_event (int /*long*/ handle, int /*long*/ gdkEvent, int /*long*/ pointer) { GdkEvent event = new GdkEvent (); OS.memmove (event, gdkEvent, GdkEvent.sizeof); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java index ebd5eb8f92..057c38fbd3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java @@ -20,6 +20,7 @@ class MozillaDelegate { Browser browser; Listener listener; boolean hasFocus; + int embedHandle; static boolean GtkLoaded, IsLinux; static { @@ -146,9 +147,13 @@ int getHandle() { }); } browser.getShell ().setFocus (); - int result = GTK.gtk_plug_new (browser.embeddedHandle); - GTK.gtk_widget_show (result); - return result; + embedHandle = GTK.gtk_plug_new (browser.embeddedHandle); + GTK.gtk_widget_show (embedHandle); + return embedHandle; +} + +int /*long*/ getSiteWindow () { + return embedHandle; } void handleFocus () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java index 3d2ef95ce1..a26f9e1ef3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.swt.browser; +import java.util.*; + import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.internal.Callback; @@ -19,6 +21,7 @@ import org.eclipse.swt.widgets.*; class MozillaDelegate { Browser browser; + Vector childWindows = new Vector (9); static int /*long*/ MozillaProc; static Callback SubclassProc; @@ -131,6 +134,33 @@ int /*long*/ getHandle () { return browser.handle; } +int /*long*/ getSiteWindow () { + /* + * As of XULRunner 4, XULRunner's printing facilities on Windows destroy + * the HWND that is returned from here once the print dialog is dismissed + * (originating bug: https://bugzilla.mozilla.org/show_bug.cgi?id=588735 ). + * For this scenario it is now expected that the handle that is returned + * here is a child of the browser handle, not the browser handle itself. + * + * The other scenario that requests this handle is the Mozilla.getBrowser() + * implementation. This method's GetSiteWindow() invocation is surrounded + * by boolean flags to help differentiate it from the printing scenario, + * since Mozilla.getBrowser() does not destroy the handle it receives back. + * + * All children that are created here are stored and then destroyed once + * the current page is left. This is guard code that should only be needed + * if Mozilla.getSiteWindow() is ever invoked by a path other than one of + * the two described above. + */ + if (Mozilla.IsPre_4 || Mozilla.IsGettingSiteWindow) { + return getHandle (); + } + + Composite child = new Composite (browser, SWT.NONE); + childWindows.addElement (child); + return child.handle; +} + void handleFocus () { } @@ -176,11 +206,23 @@ void init () { } } }); + + /* children created in getSiteHandle() should be destroyed whenever a page is left */ + browser.addLocationListener (new LocationAdapter () { + public void changing (LocationEvent event) { + Enumeration enumeration = childWindows.elements (); + while (enumeration.hasMoreElements ()) { + ((Composite)enumeration.nextElement ()).dispose (); + } + childWindows.clear (); + } + }); } } void onDispose (int /*long*/ embedHandle) { removeWindowSubclass (); + childWindows = null; browser = null; } |