comparison dwt/browser/Mozilla.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents db5a898b2119
children 5583f8eeee6c
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2003, 2007 IBM Corporation and others. 2 * Copyright (c) 2003, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
27 import dwt.graphics.Rectangle; 27 import dwt.graphics.Rectangle;
28 import dwt.internal.C; 28 import dwt.internal.C;
29 import dwt.internal.Compatibility; 29 import dwt.internal.Compatibility;
30 import dwt.internal.LONG; 30 import dwt.internal.LONG;
31 import dwt.internal.Library; 31 import dwt.internal.Library;
32 import dwt.internal.mozilla.GREVersionRange;
33 import dwt.internal.mozilla.XPCOM; 32 import dwt.internal.mozilla.XPCOM;
34 import dwt.internal.mozilla.XPCOMInit;
35 import dwt.internal.mozilla.XPCOMObject; 33 import dwt.internal.mozilla.XPCOMObject;
36 import dwt.internal.mozilla.nsEmbedString; 34 import dwt.internal.mozilla.nsEmbedString;
37 import dwt.internal.mozilla.nsIAppShell; 35 import dwt.internal.mozilla.nsIAppShell;
38 import dwt.internal.mozilla.nsIBaseWindow; 36 import dwt.internal.mozilla.nsIBaseWindow;
39 import dwt.internal.mozilla.nsICategoryManager; 37 import dwt.internal.mozilla.nsICategoryManager;
81 import dwt.internal.mozilla.nsIWebNavigation; 79 import dwt.internal.mozilla.nsIWebNavigation;
82 import dwt.internal.mozilla.nsIWebNavigationInfo; 80 import dwt.internal.mozilla.nsIWebNavigationInfo;
83 import dwt.internal.mozilla.nsIWebProgress; 81 import dwt.internal.mozilla.nsIWebProgress;
84 import dwt.internal.mozilla.nsIWebProgressListener; 82 import dwt.internal.mozilla.nsIWebProgressListener;
85 import dwt.internal.mozilla.nsIWindowWatcher; 83 import dwt.internal.mozilla.nsIWindowWatcher;
84 import dwt.internal.mozilla.init.GREVersionRange;
85 import dwt.internal.mozilla.init.XPCOMInit;
86 import dwt.layout.FillLayout; 86 import dwt.layout.FillLayout;
87 import dwt.widgets.Composite; 87 import dwt.widgets.Composite;
88 import dwt.widgets.Display; 88 import dwt.widgets.Display;
89 import dwt.widgets.Event; 89 import dwt.widgets.Event;
90 import dwt.widgets.Label; 90 import dwt.widgets.Label;
221 }; 221 };
222 } 222 }
223 223
224 public void create (Composite parent, int style) { 224 public void create (Composite parent, int style) {
225 delegate = new MozillaDelegate (browser); 225 delegate = new MozillaDelegate (browser);
226 Display display = parent.getDisplay (); 226 final Display display = parent.getDisplay ();
227 227
228 int /*long*/[] result = new int /*long*/[1]; 228 int /*long*/[] result = new int /*long*/[1];
229 if (!Initialized) { 229 if (!Initialized) {
230 bool initLoaded = false; 230 bool initLoaded = false;
231 bool IsXULRunner = false; 231 bool IsXULRunner = false;
330 */ 330 */
331 if (IsXULRunner) { 331 if (IsXULRunner) {
332 byte[] path = MozillaDelegate.wcsToMbcs (null, mozillaPath, true); 332 byte[] path = MozillaDelegate.wcsToMbcs (null, mozillaPath, true);
333 rc = XPCOMInit.XPCOMGlueStartup (path); 333 rc = XPCOMInit.XPCOMGlueStartup (path);
334 if (rc !is XPCOM.NS_OK) { 334 if (rc !is XPCOM.NS_OK) {
335 IsXULRunner = false; /* failed */
336 mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf cast(SEPARATOR_OS)); 335 mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf cast(SEPARATOR_OS));
337 if (Device.DEBUG) System.out.println ("cannot use detected XULRunner: " + mozillaPath); //$NON-NLS-1$ 336 if (Device.DEBUG) System.out.println ("cannot use detected XULRunner: " + mozillaPath); //$NON-NLS-1$
338 } else { 337
338 /* attempt to XPCOMGlueStartup the GRE pointed at by MOZILLA_FIVE_HOME */
339 int /*long*/ ptr = C.getenv (MozillaDelegate.wcsToMbcs (null, XPCOM.MOZILLA_FIVE_HOME, true));
340 if (ptr is 0) {
341 IsXULRunner = false;
342 } else {
343 length = C.strlen (ptr);
344 byte[] buffer = new byte[length];
345 C.memmove (buffer, ptr, length);
346 mozillaPath = new String (MozillaDelegate.mbcsToWcs (null, buffer));
347 /*
348 * Attempting to XPCOMGlueStartup a mozilla-based GRE !is xulrunner can
349 * crash, so don't attempt unless the GRE appears to be xulrunner.
350 */
351 if (mozillaPath.indexOf("xulrunner") is -1) { //$NON-NLS-1$
352 IsXULRunner = false;
353 } else {
354 mozillaPath += SEPARATOR_OS + delegate.getLibraryName ();
355 path = MozillaDelegate.wcsToMbcs (null, mozillaPath, true);
356 rc = XPCOMInit.XPCOMGlueStartup (path);
357 if (rc !is XPCOM.NS_OK) {
358 IsXULRunner = false;
359 mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
360 if (Device.DEBUG) System.out.println ("failed to start as XULRunner: " + mozillaPath); //$NON-NLS-1$
361 }
362 }
363 }
364 }
365 if (IsXULRunner) {
339 XPCOMInitWasGlued = true; 366 XPCOMInitWasGlued = true;
340 } 367 }
341 } 368 }
342 } 369 }
343 C.free (greBuffer); 370 C.free (greBuffer);
938 browser.dispose (); 965 browser.dispose ();
939 error (rc); 966 error (rc);
940 } 967 }
941 factory.Release (); 968 factory.Release ();
942 969
943 HelperAppLauncherDialogFactory dialogFactory = new HelperAppLauncherDialogFactory ();
944 dialogFactory.AddRef ();
945 aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID, true);
946 aClassName = MozillaDelegate.wcsToMbcs (null, "Helper App Launcher Dialog", true); //$NON-NLS-1$
947 rc = componentRegistrar.RegisterFactory (XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CID, aClassName, aContractID, dialogFactory.getAddress ());
948 if (rc !is XPCOM.NS_OK) {
949 browser.dispose ();
950 error (rc);
951 }
952 dialogFactory.Release ();
953
954 /* 970 /*
955 * This Download factory will be used if the GRE version is < 1.8. 971 * This Download factory will be used if the GRE version is < 1.8.
956 * If the GRE version is 1.8.x then the Download factory that is registered later for 972 * If the GRE version is 1.8.x then the Download factory that is registered later for
957 * contract "Transfer" will be used. 973 * contract "Transfer" will be used.
958 * If the GRE version is >= 1.9 then no Download factory is registered because this 974 * If the GRE version is >= 1.9 then no Download factory is registered because this
1044 prefFile.Release (); 1060 prefFile.Release ();
1045 } 1061 }
1046 serviceManager.Release (); 1062 serviceManager.Release ();
1047 1063
1048 if (XPCOMWasGlued) { 1064 if (XPCOMWasGlued) {
1049 XPCOM.XPCOMGlueShutdown (); 1065 /*
1066 * XULRunner 1.9 can crash on Windows if XPCOMGlueShutdown is invoked here,
1067 * presumably because one or more of its unloaded symbols are referenced when
1068 * this callback returns. The workaround is to delay invoking XPCOMGlueShutdown
1069 * so that its symbols are still available once this callback returns.
1070 */
1071 display.asyncExec (new Runnable () {
1072 public void run () {
1073 XPCOM.XPCOMGlueShutdown ();
1074 }
1075 });
1050 XPCOMWasGlued = false; 1076 XPCOMWasGlued = false;
1051 } 1077 }
1052 if (XPCOMInitWasGlued) { 1078 if (XPCOMInitWasGlued) {
1053 XPCOMInit.XPCOMGlueShutdown (); 1079 XPCOMInit.XPCOMGlueShutdown ();
1054 XPCOMInitWasGlued = false; 1080 XPCOMInitWasGlued = false;
1131 } 1157 }
1132 baseWindow.Release (); 1158 baseWindow.Release ();
1133 1159
1134 if (!PerformedVersionCheck) { 1160 if (!PerformedVersionCheck) {
1135 PerformedVersionCheck = true; 1161 PerformedVersionCheck = true;
1162
1163 rc = componentManager.QueryInterface (nsIComponentRegistrar.NS_ICOMPONENTREGISTRAR_IID, result);
1164 if (rc !is XPCOM.NS_OK) {
1165 browser.dispose ();
1166 error (rc);
1167 }
1168 if (result[0] is 0) {
1169 browser.dispose ();
1170 error (XPCOM.NS_NOINTERFACE);
1171 }
1172 nsIComponentRegistrar componentRegistrar = new nsIComponentRegistrar (result[0]);
1173 result[0] = 0;
1174
1175 HelperAppLauncherDialogFactory dialogFactory = new HelperAppLauncherDialogFactory ();
1176 dialogFactory.AddRef ();
1177 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID, true);
1178 byte[] aClassName = MozillaDelegate.wcsToMbcs (null, "Helper App Launcher Dialog", true); //$NON-NLS-1$
1179 rc = componentRegistrar.RegisterFactory (XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CID, aClassName, aContractID, dialogFactory.getAddress ());
1180 if (rc !is XPCOM.NS_OK) {
1181 browser.dispose ();
1182 error (rc);
1183 }
1184 dialogFactory.Release ();
1136 1185
1137 /* 1186 /*
1138 * Check for the availability of the pre-1.8 implementation of nsIDocShell 1187 * Check for the availability of the pre-1.8 implementation of nsIDocShell
1139 * to determine if the GRE's version is < 1.8. 1188 * to determine if the GRE's version is < 1.8.
1140 */ 1189 */
1169 if (!IsPre_1_8) { 1218 if (!IsPre_1_8) {
1170 rc = interfaceRequestor.GetInterface (nsIDocShell_1_8.NS_IDOCSHELL_IID, result); 1219 rc = interfaceRequestor.GetInterface (nsIDocShell_1_8.NS_IDOCSHELL_IID, result);
1171 if (rc is XPCOM.NS_OK && result[0] !is 0) { /* 1.8 */ 1220 if (rc is XPCOM.NS_OK && result[0] !is 0) { /* 1.8 */
1172 new nsISupports (result[0]).Release (); 1221 new nsISupports (result[0]).Release ();
1173 result[0] = 0; 1222 result[0] = 0;
1174 rc = componentManager.QueryInterface (nsIComponentRegistrar.NS_ICOMPONENTREGISTRAR_IID, result); 1223
1175 if (rc !is XPCOM.NS_OK) {
1176 browser.dispose ();
1177 error (rc);
1178 }
1179 if (result[0] is 0) {
1180 browser.dispose ();
1181 error (XPCOM.NS_NOINTERFACE);
1182 }
1183
1184 nsIComponentRegistrar componentRegistrar = new nsIComponentRegistrar (result[0]);
1185 DownloadFactory_1_8 downloadFactory_1_8 = new DownloadFactory_1_8 (); 1224 DownloadFactory_1_8 downloadFactory_1_8 = new DownloadFactory_1_8 ();
1186 downloadFactory_1_8.AddRef (); 1225 downloadFactory_1_8.AddRef ();
1187 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_TRANSFER_CONTRACTID, true); 1226 aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_TRANSFER_CONTRACTID, true);
1188 byte[] aClassName = MozillaDelegate.wcsToMbcs (null, "Transfer", true); //$NON-NLS-1$ 1227 aClassName = MozillaDelegate.wcsToMbcs (null, "Transfer", true); //$NON-NLS-1$
1189 rc = componentRegistrar.RegisterFactory (XPCOM.NS_DOWNLOAD_CID, aClassName, aContractID, downloadFactory_1_8.getAddress ()); 1228 rc = componentRegistrar.RegisterFactory (XPCOM.NS_DOWNLOAD_CID, aClassName, aContractID, downloadFactory_1_8.getAddress ());
1190 if (rc !is XPCOM.NS_OK) { 1229 if (rc !is XPCOM.NS_OK) {
1191 browser.dispose (); 1230 browser.dispose ();
1192 error (rc); 1231 error (rc);
1193 } 1232 }
1194 downloadFactory_1_8.Release (); 1233 downloadFactory_1_8.Release ();
1195 componentRegistrar.Release ();
1196 } else { /* >= 1.9 */ 1234 } else { /* >= 1.9 */
1197 /* 1235 /*
1198 * Bug in XULRunner 1.9. Mozilla no longer clears its background before initial content has 1236 * Bug in XULRunner 1.9. Mozilla no longer clears its background before initial content has
1199 * been set. As a result embedders appear broken if they do not immediately navigate to a url. 1237 * been set. As a result embedders appear broken if they do not immediately navigate to a url.
1200 * The workaround for this is to navigate to about:blank immediately so that the background is 1238 * The workaround for this is to navigate to about:blank immediately so that the background is
1215 nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); 1253 nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
1216 char[] uri = new char[ABOUT_BLANK.length () + 1]; 1254 char[] uri = new char[ABOUT_BLANK.length () + 1];
1217 ABOUT_BLANK.getChars (0, ABOUT_BLANK.length (), uri, 0); 1255 ABOUT_BLANK.getChars (0, ABOUT_BLANK.length (), uri, 0);
1218 rc = webNavigation.LoadURI (uri, nsIWebNavigation.LOAD_FLAGS_NONE, 0, 0, 0); 1256 rc = webNavigation.LoadURI (uri, nsIWebNavigation.LOAD_FLAGS_NONE, 0, 0, 0);
1219 webNavigation.Release (); 1257 webNavigation.Release ();
1258
1259 dialogFactory.isPre_1_9 = false;
1220 } 1260 }
1221 } 1261 }
1222 result[0] = 0; 1262 result[0] = 0;
1223 interfaceRequestor.Release (); 1263 interfaceRequestor.Release ();
1264 componentRegistrar.Release ();
1224 } 1265 }
1225 componentManager.Release (); 1266 componentManager.Release ();
1226 1267
1227 rc = webBrowser.AddWebBrowserListener (weakReference.getAddress (), nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID); 1268 rc = webBrowser.AddWebBrowserListener (weakReference.getAddress (), nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID);
1228 if (rc !is XPCOM.NS_OK) { 1269 if (rc !is XPCOM.NS_OK) {
1494 1535
1495 static Browser findBrowser (int /*long*/ handle) { 1536 static Browser findBrowser (int /*long*/ handle) {
1496 return MozillaDelegate.findBrowser (handle); 1537 return MozillaDelegate.findBrowser (handle);
1497 } 1538 }
1498 1539
1540 static Browser findBrowser (nsIDOMWindow aDOMWindow) {
1541 int /*long*/[] result = new int /*long*/[1];
1542 int rc = XPCOM.NS_GetServiceManager (result);
1543 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
1544 if (result[0] is 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
1545
1546 nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
1547 result[0] = 0;
1548 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WINDOWWATCHER_CONTRACTID, true);
1549 rc = serviceManager.GetServiceByContractID (aContractID, nsIWindowWatcher.NS_IWINDOWWATCHER_IID, result);
1550 if (rc !is XPCOM.NS_OK) Mozilla.error(rc);
1551 if (result[0] is 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
1552 serviceManager.Release ();
1553
1554 nsIWindowWatcher windowWatcher = new nsIWindowWatcher (result[0]);
1555 result[0] = 0;
1556 /* the chrome will only be answered for the top-level nsIDOMWindow */
1557 rc = aDOMWindow.GetTop (result);
1558 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
1559 if (result[0] is 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
1560 int /*long*/ topDOMWindow = result[0];
1561 result[0] = 0;
1562 rc = windowWatcher.GetChromeForWindow (topDOMWindow, result);
1563 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
1564 if (result[0] is 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
1565 new nsISupports (topDOMWindow).Release ();
1566 windowWatcher.Release ();
1567
1568 nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome (result[0]);
1569 result[0] = 0;
1570 rc = webBrowserChrome.QueryInterface (nsIEmbeddingSiteWindow.NS_IEMBEDDINGSITEWINDOW_IID, result);
1571 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
1572 if (result[0] is 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
1573 webBrowserChrome.Release ();
1574
1575 nsIEmbeddingSiteWindow embeddingSiteWindow = new nsIEmbeddingSiteWindow (result[0]);
1576 result[0] = 0;
1577 rc = embeddingSiteWindow.GetSiteWindow (result);
1578 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
1579 if (result[0] is 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
1580 embeddingSiteWindow.Release ();
1581
1582 return findBrowser (result[0]);
1583 }
1584
1499 public bool forward () { 1585 public bool forward () {
1500 if (awaitingNavigate) return false; 1586 if (awaitingNavigate) return false;
1501 1587
1502 int /*long*/[] result = new int /*long*/[1]; 1588 int /*long*/[] result = new int /*long*/[1];
1503 int rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result); 1589 int rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result);
1507 nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); 1593 nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
1508 rc = webNavigation.GoForward (); 1594 rc = webNavigation.GoForward ();
1509 webNavigation.Release (); 1595 webNavigation.Release ();
1510 1596
1511 return rc is XPCOM.NS_OK; 1597 return rc is XPCOM.NS_OK;
1598 }
1599
1600 public String getBrowserType () {
1601 return "mozilla"; //$NON-NLS-1$
1512 } 1602 }
1513 1603
1514 public String getText () { 1604 public String getText () {
1515 if (awaitingNavigate) return ""; //$NON-NLS-1$ 1605 if (awaitingNavigate) return ""; //$NON-NLS-1$
1516 1606
2443 return XPCOM.NS_OK; 2533 return XPCOM.NS_OK;
2444 } 2534 }
2445 2535
2446 int SetWebBrowser (int /*long*/ aWebBrowser) { 2536 int SetWebBrowser (int /*long*/ aWebBrowser) {
2447 if (webBrowser !is null) webBrowser.Release (); 2537 if (webBrowser !is null) webBrowser.Release ();
2448 webBrowser = aWebBrowser !is 0 ? new nsIWebBrowser (aWebBrowser) : null; 2538 webBrowser = aWebBrowser !is 0 ? new nsIWebBrowser (aWebBrowser) : null;
2449 return XPCOM.NS_OK; 2539 return XPCOM.NS_OK;
2450 } 2540 }
2451 2541
2452 int GetChromeFlags (int /*long*/ aChromeFlags) { 2542 int GetChromeFlags (int /*long*/ aChromeFlags) {
2453 int[] ret = new int[1]; 2543 int[] ret = new int[1];
2801 result[0] = 0; 2891 result[0] = 0;
2802 2892
2803 /* First try to use the nsIWebNavigationInfo if it's available (>= mozilla 1.8) */ 2893 /* First try to use the nsIWebNavigationInfo if it's available (>= mozilla 1.8) */
2804 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WEBNAVIGATIONINFO_CONTRACTID, true); 2894 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WEBNAVIGATIONINFO_CONTRACTID, true);
2805 rc = serviceManager.GetServiceByContractID (aContractID, nsIWebNavigationInfo.NS_IWEBNAVIGATIONINFO_IID, result); 2895 rc = serviceManager.GetServiceByContractID (aContractID, nsIWebNavigationInfo.NS_IWEBNAVIGATIONINFO_IID, result);
2806 if (rc is 0) { 2896 if (rc is XPCOM.NS_OK) {
2807 byte[] bytes = MozillaDelegate.wcsToMbcs (null, contentType, true); 2897 byte[] bytes = MozillaDelegate.wcsToMbcs (null, contentType, true);
2808 int /*long*/ typePtr = XPCOM.nsEmbedCString_new (bytes, bytes.length); 2898 int /*long*/ typePtr = XPCOM.nsEmbedCString_new (bytes, bytes.length);
2809 nsIWebNavigationInfo info = new nsIWebNavigationInfo (result[0]); 2899 nsIWebNavigationInfo info = new nsIWebNavigationInfo (result[0]);
2810 result[0] = 0; 2900 result[0] = 0;
2811 int[] isSupportedResult = new int[1]; /* PRUint32 */ 2901 int[] isSupportedResult = new int[1]; /* PRUint32 */