comparison dwt/browser/Mozilla.d @ 340:3f4a5c7d138f

Fixes
author John Reimer <terminal.node@gmail.com>
date Sun, 26 Oct 2008 08:09:00 -0700
parents c317081df76f
children 942da4b6558a
comparison
equal deleted inserted replaced
339:c317081df76f 340:3f4a5c7d138f
21 //import java.util.Enumeration; 21 //import java.util.Enumeration;
22 //import java.util.Locale; 22 //import java.util.Locale;
23 //import java.util.Vector; 23 //import java.util.Vector;
24 24
25 import tango.text.locale.Core; // Necessary for Region/Culture/Locale code 25 import tango.text.locale.Core; // Necessary for Region/Culture/Locale code
26 import dwt.internal.c.gtk;
26 27
27 import dwt.DWT; 28 import dwt.DWT;
28 import dwt.DWTError; 29 import dwt.DWTError;
29 import dwt.graphics.Device; 30 import dwt.graphics.Device;
30 import dwt.graphics.Point; 31 import dwt.graphics.Point;
31 import dwt.graphics.Rectangle; 32 import dwt.graphics.Rectangle;
32 33
34 import dwt.browser.MozillaDelegate;
35 import dwt.browser.AppFileLocProvider;
36 import dwt.browser.WindowCreator2;
37
33 import dwt.internal.Compatibility; 38 import dwt.internal.Compatibility;
34 import dwt.internal.LONG; 39 import dwt.internal.LONG;
35 import dwt.internal.Library; 40 import dwt.internal.Library;
36 41
37 import dwt.internal.mozilla.XPCOM; 42 import dwt.internal.mozilla.XPCOM;
38 import dwt.internal.mozilla.XPCOMInit; 43 import dwt.internal.mozilla.XPCOMInit;
44 import dwt.internal.mozilla.Common;
39 45
40 import dwt.internal.mozilla.nsEmbedString; 46 import dwt.internal.mozilla.nsEmbedString;
41 import dwt.internal.mozilla.nsIAppShell; 47 import dwt.internal.mozilla.nsIAppShell;
42 import dwt.internal.mozilla.nsIBaseWindow; 48 import dwt.internal.mozilla.nsIBaseWindow;
43 import dwt.internal.mozilla.nsICategoryManager; 49 import dwt.internal.mozilla.nsICategoryManager;
46 import dwt.internal.mozilla.nsIContextMenuListener; 52 import dwt.internal.mozilla.nsIContextMenuListener;
47 import dwt.internal.mozilla.nsICookie; 53 import dwt.internal.mozilla.nsICookie;
48 import dwt.internal.mozilla.nsICookieManager; 54 import dwt.internal.mozilla.nsICookieManager;
49 import dwt.internal.mozilla.nsID; 55 import dwt.internal.mozilla.nsID;
50 import dwt.internal.mozilla.nsIDOMEvent; 56 import dwt.internal.mozilla.nsIDOMEvent;
57 import dwt.internal.mozilla.nsIDOMEventListener;
51 import dwt.internal.mozilla.nsIDOMEventTarget; 58 import dwt.internal.mozilla.nsIDOMEventTarget;
52 import dwt.internal.mozilla.nsIDOMKeyEvent; 59 import dwt.internal.mozilla.nsIDOMKeyEvent;
53 import dwt.internal.mozilla.nsIDOMMouseEvent; 60 import dwt.internal.mozilla.nsIDOMMouseEvent;
54 import dwt.internal.mozilla.nsIDOMSerializer; 61 import dwt.internal.mozilla.nsIDOMSerializer;
55 import dwt.internal.mozilla.nsIDOMSerializer_1_7; 62 import dwt.internal.mozilla.nsIDOMSerializer_1_7;
56 import dwt.internal.mozilla.nsIDOMWindow; 63 import dwt.internal.mozilla.nsIDOMWindow;
57 import dwt.internal.mozilla.nsIDOMWindowCollection; 64 import dwt.internal.mozilla.nsIDOMWindowCollection;
58 import dwt.internal.mozilla.nsIDirectoryService; 65 import dwt.internal.mozilla.nsIDirectoryService;
59 import dwt.internal.mozilla.nsIDocShell; 66 import dwt.internal.mozilla.nsIDocShell;
60 import dwt.internal.mozilla.nsIDocShell_1_8; 67 //import dwt.internal.mozilla.nsIDocShell_1_8;
61 import dwt.internal.mozilla.nsIDocShell_1_9; 68 //import dwt.internal.mozilla.nsIDocShell_1_9;
62 import dwt.internal.mozilla.nsIEmbeddingSiteWindow; 69 import dwt.internal.mozilla.nsIEmbeddingSiteWindow;
63 import dwt.internal.mozilla.nsIFile; 70 import dwt.internal.mozilla.nsIFile;
64 import dwt.internal.mozilla.nsIIOService; 71 import dwt.internal.mozilla.nsIIOService;
65 import dwt.internal.mozilla.nsIInterfaceRequestor; 72 import dwt.internal.mozilla.nsIInterfaceRequestor;
66 import dwt.internal.mozilla.nsIJSContextStack; 73 import dwt.internal.mozilla.nsIJSContextStack;
72 import dwt.internal.mozilla.nsIProperties; 79 import dwt.internal.mozilla.nsIProperties;
73 import dwt.internal.mozilla.nsIRequest; 80 import dwt.internal.mozilla.nsIRequest;
74 import dwt.internal.mozilla.nsIServiceManager; 81 import dwt.internal.mozilla.nsIServiceManager;
75 import dwt.internal.mozilla.nsISimpleEnumerator; 82 import dwt.internal.mozilla.nsISimpleEnumerator;
76 import dwt.internal.mozilla.nsISupports; 83 import dwt.internal.mozilla.nsISupports;
77 import dwt.internal.mozilla.nsISupportsWeakReference; 84 //import dwt.internal.mozilla.nsISupportsWeakReference;
78 import dwt.internal.mozilla.nsITooltipListener; 85 import dwt.internal.mozilla.nsITooltipListener;
79 import dwt.internal.mozilla.nsIURI; 86 import dwt.internal.mozilla.nsIURI;
80 import dwt.internal.mozilla.nsIURIContentListener; 87 import dwt.internal.mozilla.nsIURIContentListener;
81 import dwt.internal.mozilla.nsIWeakReference; 88 import dwt.internal.mozilla.nsIWeakReference;
82 import dwt.internal.mozilla.nsIWebBrowser; 89 import dwt.internal.mozilla.nsIWebBrowser;
94 import dwt.widgets.Event; 101 import dwt.widgets.Event;
95 import dwt.widgets.Label; 102 import dwt.widgets.Label;
96 import dwt.widgets.Listener; 103 import dwt.widgets.Listener;
97 import dwt.widgets.Menu; 104 import dwt.widgets.Menu;
98 import dwt.widgets.Shell; 105 import dwt.widgets.Shell;
106 import dwt.browser.WebBrowser;
99 107
100 class Mozilla : WebBrowser, 108 class Mozilla : WebBrowser,
101 nsIWeakReference, 109 nsIWeakReference,
102 nsIWebProgressListener, 110 nsIWebProgressListener,
103 nsIWebBrowserChrome, 111 nsIWebBrowserChrome,
104 nsIWebBrowserFocus, 112 nsIWebBrowserFocus,
105 nsIEmbeddingSiteWindow, 113 nsIEmbeddingSiteWindow,
106 nsIInterfaceRequestor, 114 nsIInterfaceRequestor,
107 nsISupportsWeakReference, 115 nsISupportsWeakReference,
108 nsIContextMenuListener, 116 nsIContextMenuListener,
109 nsIUriContextListener, 117 nsIURIContentListener,
110 nsITooltipListener, 118 nsITooltipListener,
111 nsIDomEventListener { 119 nsIDOMEventListener {
112 120
113 GtkWidget* embedHandle; 121 GtkWidget* embedHandle;
114 nsIWebBrowser webBrowser; 122 nsIWebBrowser webBrowser;
115 Object webBrowserObject; 123 Object webBrowserObject;
116 MozillaDelegate mozDelegate; 124 MozillaDelegate mozDelegate;
181 189
182 // TEMPORARY CODE 190 // TEMPORARY CODE
183 static final String GRE_INITIALIZED = "dwt.browser.XULRunnerInitialized"; //$NON-NLS-1$ 191 static final String GRE_INITIALIZED = "dwt.browser.XULRunnerInitialized"; //$NON-NLS-1$
184 192
185 static this () { 193 static this () {
186 MozillaClearSessions = new Runnable () { 194 MozillaClearSessions = new class() Runnable {
187 public void run () { 195 public void run () {
188 if (!Initialized) return; 196 if (!Initialized) return;
189 nsIServiceManager serviceManager; 197 nsIServiceManager serviceManager;
190 int rc = XPCOM.NS_GetServiceManager (&serviceManager); 198 int rc = XPCOM.NS_GetServiceManager (&serviceManager);
191 if (rc !is XPCOM.NS_OK) error (rc); 199 if (rc !is XPCOM.NS_OK) error (rc);
249 if (!Initialized) { 257 if (!Initialized) {
250 bool initLoaded = false; 258 bool initLoaded = false;
251 bool IsXULRunner = false; 259 bool IsXULRunner = false;
252 260
253 String greInitialized = System.getProperty (GRE_INITIALIZED); 261 String greInitialized = System.getProperty (GRE_INITIALIZED);
254 if ("true" == greInitialized)) { //$NON-NLS-1$ 262 if ("true" == greInitialized) { //$NON-NLS-1$
255 /* 263 /*
256 * Another browser has already initialized xulrunner in this process, 264 * Another browser has already initialized xulrunner in this process,
257 * so just bind to it instead of trying to initialize a new one. 265 * so just bind to it instead of trying to initialize a new one.
258 */ 266 */
259 Initialized = true; 267 Initialized = true;
886 894
887 if (proxyHost !is null) { 895 if (proxyHost !is null) {
888 //byte[] contractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID, true); 896 //byte[] contractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID, true);
889 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID, null, &nsIPrefLocalizedString.IID, cast(void**)&localizedString); 897 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID, null, &nsIPrefLocalizedString.IID, cast(void**)&localizedString);
890 if (rc !is XPCOM.NS_OK) error (rc); 898 if (rc !is XPCOM.NS_OK) error (rc);
891 if (localizedString] is null) error (XPCOM.NS_NOINTERFACE); 899 if (localizedString is null) error (XPCOM.NS_NOINTERFACE);
892 900
893 //localizedString = new nsIPrefLocalizedString (result[0]); 901 //localizedString = new nsIPrefLocalizedString (result[0]);
894 //result[0] = 0; 902 //result[0] = 0;
895 //int length = proxyHost.length (); 903 //int length = proxyHost.length ();
896 //char[] charBuffer = new char[length + 1]; 904 //char[] charBuffer = new char[length + 1];
1028 Initialized = true; 1036 Initialized = true;
1029 } 1037 }
1030 1038
1031 if (display.getData (DISPOSE_LISTENER_HOOKED) is null) { 1039 if (display.getData (DISPOSE_LISTENER_HOOKED) is null) {
1032 display.setData (DISPOSE_LISTENER_HOOKED, DISPOSE_LISTENER_HOOKED); 1040 display.setData (DISPOSE_LISTENER_HOOKED, DISPOSE_LISTENER_HOOKED);
1033 display.addListener (DWT.Dispose, new Listener () { 1041 display.addListener (DWT.Dispose, new class() Listener {
1034 public void handleEvent (Event event) { 1042 public void handleEvent (Event event) {
1035 if (BrowserCount > 0) return; /* another display is still active */ 1043 if (BrowserCount > 0) return; /* another display is still active */
1036 1044
1037 nsIServiceManager serviceManager; 1045 nsIServiceManager serviceManager;
1038 //int /*long*/[] result = new int /*long*/[1]; 1046 //int /*long*/[] result = new int /*long*/[1];
1157 rc = webBrowser.QueryInterface (nsIBaseWindow.IID, cast(void**)&baseWindow); 1165 rc = webBrowser.QueryInterface (nsIBaseWindow.IID, cast(void**)&baseWindow);
1158 if (rc !is XPCOM.NS_OK) { 1166 if (rc !is XPCOM.NS_OK) {
1159 browser.dispose (); 1167 browser.dispose ();
1160 error (rc); 1168 error (rc);
1161 } 1169 }
1162 if (baseWindow] is null) { 1170 if (baseWindow is null) {
1163 browser.dispose (); 1171 browser.dispose ();
1164 error (XPCOM.NS_ERROR_NO_INTERFACE); 1172 error (XPCOM.NS_ERROR_NO_INTERFACE);
1165 } 1173 }
1166 1174
1167 //nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); 1175 //nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]);
1311 // TODO: Find appropriate place to "Release" uriContentListener -JJR 1319 // TODO: Find appropriate place to "Release" uriContentListener -JJR
1312 nsIUriContentListener uriContentListener; 1320 nsIUriContentListener uriContentListener;
1313 this.QueryInterface(&nsIUriContentListener.IID, cast(void**)&uriContentListener); 1321 this.QueryInterface(&nsIUriContentListener.IID, cast(void**)&uriContentListener);
1314 if (rc !is XPCOM.NS_OK) { 1322 if (rc !is XPCOM.NS_OK) {
1315 browser.dispose(); 1323 browser.dispose();
1316 error(rc) 1324 error(rc);
1317 } 1325 }
1318 if (uriContentListener is null) 1326 if (uriContentListener is null) {
1319 browser.dispose(); 1327 browser.dispose();
1320 error(XPCOM.NS_ERROR_NO_INTERFACE); 1328 error(XPCOM.NS_ERROR_NO_INTERFACE);
1321 } 1329 }
1322 1330
1323 rc = webBrowser.SetParentURIContentListener (uriContentListener); 1331 rc = webBrowser.SetParentURIContentListener (uriContentListener);
1326 error (rc); 1334 error (rc);
1327 } 1335 }
1328 1336
1329 mozDelegate.init (); 1337 mozDelegate.init ();
1330 1338
1331 listener = new Listener () { 1339 listener = new class () Listener {
1332 public void handleEvent (Event event) { 1340 public void handleEvent (Event event) {
1333 switch (event.type) { 1341 switch (event.type) {
1334 case DWT.Dispose: { 1342 case DWT.Dispose: {
1335 /* make this handler run after other dispose listeners */ 1343 /* make this handler run after other dispose listeners */
1336 if (ignoreDispose) { 1344 if (ignoreDispose) {
1346 case DWT.Resize: onResize (); break; 1354 case DWT.Resize: onResize (); break;
1347 case DWT.FocusIn: Activate (); break; 1355 case DWT.FocusIn: Activate (); break;
1348 case DWT.Activate: Activate (); break; 1356 case DWT.Activate: Activate (); break;
1349 case DWT.Deactivate: { 1357 case DWT.Deactivate: {
1350 Display display = event.display; 1358 Display display = event.display;
1351 if (Mozilla.this.browser is display.getFocusControl ()) Deactivate (); 1359 if (this.browser is display.getFocusControl ()) Deactivate ();
1352 break; 1360 break;
1353 } 1361 }
1354 case DWT.Show: { 1362 case DWT.Show: {
1355 /* 1363 /*
1356 * Feature in GTK Mozilla. Mozilla does not show up when 1364 * Feature in GTK Mozilla. Mozilla does not show up when
1357 * its container (a GTK fixed handle) is made visible 1365 * its container (a GTK fixed handle) is made visible
1358 * after having been hidden. The workaround is to reset 1366 * after having been hidden. The workaround is to reset
1359 * its size after the container has been made visible. 1367 * its size after the container has been made visible.
1360 */ 1368 */
1361 Display display = event.display; 1369 Display display = event.display;
1362 display.asyncExec(new Runnable () { 1370 display.asyncExec(new class () Runnable {
1363 public void run() { 1371 public void run() {
1364 if (browser.isDisposed ()) return; 1372 if (browser.isDisposed ()) return;
1365 onResize (); 1373 onResize ();
1366 } 1374 }
1367 }); 1375 });
1368 break; 1376 break;
1369 } 1377 }
1370 } 1378 }
1371 } 1379 }
1372 }; 1380 };
1373 int[] folderEvents = new int[] { 1381 int[] folderEvents = [
1374 DWT.Dispose, 1382 DWT.Dispose,
1375 DWT.Resize, 1383 DWT.Resize,
1376 DWT.FocusIn, 1384 DWT.FocusIn,
1377 DWT.Activate, 1385 DWT.Activate,
1378 DWT.Deactivate, 1386 DWT.Deactivate,
1379 DWT.Show, 1387 DWT.Show,
1380 DWT.KeyDown // needed to make browser traversable 1388 DWT.KeyDown // needed to make browser traversable
1381 }; 1389 ];
1382 for (int i = 0; i < folderEvents.length; i++) { 1390 for (int i = 0; i < folderEvents.length; i++) {
1383 browser.addListener (folderEvents[i], listener); 1391 browser.addListener (folderEvents[i], listener);
1384 } 1392 }
1385 } 1393 }
1386 1394
2026 //string.dispose (); 2034 //string.dispose ();
2027 string = new nsEmbedString (XPCOM.DOMEVENT_KEYPRESS); 2035 string = new nsEmbedString (XPCOM.DOMEVENT_KEYPRESS);
2028 target.RemoveEventListener (cast(nsAString*)string, domEventListener, 0); 2036 target.RemoveEventListener (cast(nsAString*)string, domEventListener, 0);
2029 //string.dispose (); 2037 //string.dispose ();
2030 string = new nsEmbedString (XPCOM.DOMEVENT_KEYUP); 2038 string = new nsEmbedString (XPCOM.DOMEVENT_KEYUP);
2031 target.RemoveEventListener (cast(nsAString*)string, domEventListener., 0); 2039 target.RemoveEventListener (cast(nsAString*)string, domEventListener, 0);
2032 //string.dispose (); 2040 //string.dispose ();
2033 } 2041 }
2034 2042
2035 /* nsISupports */ 2043 /* nsISupports */
2036 2044
2085 if (*riid == nsIURIContentListener.IID) { 2093 if (*riid == nsIURIContentListener.IID) {
2086 *ppvObject = cast(void*)cast(nsIUriContentListener)this; 2094 *ppvObject = cast(void*)cast(nsIUriContentListener)this;
2087 AddRef (); 2095 AddRef ();
2088 return XPCOM.NS_OK; 2096 return XPCOM.NS_OK;
2089 } 2097 }
2090 if (*riid == nsITooltipListener.IID)) { 2098 if (*riid == nsITooltipListener.IID) {
2091 *ppvObject = cast(void*)cast(nsITooltipListener)this; 2099 *ppvObject = cast(void*)cast(nsITooltipListener)this;
2092 AddRef (); 2100 AddRef ();
2093 return XPCOM.NS_OK; 2101 return XPCOM.NS_OK;
2094 } 2102 }
2095 *ppvObject = null; 2103 *ppvObject = null;
2249 if (domWindow is null) error (XPCOM.NS_NOINTERFACE); 2257 if (domWindow is null) error (XPCOM.NS_NOINTERFACE);
2250 //nsIDOMWindow domWindow = new nsIDOMWindow (result[0]); 2258 //nsIDOMWindow domWindow = new nsIDOMWindow (result[0]);
2251 2259
2252 //LONG ptrObject = new LONG (result[0]); 2260 //LONG ptrObject = new LONG (result[0]);
2253 //result[0] = 0; 2261 //result[0] = 0;
2254 int index = unhookedDOMWindows.arrayIndexOf (domWindow); 2262 int index = unhookedDOMWindows.arrayIndexOf ( domWindow);
2255 if (index !is -1) { 2263 if (index !is -1) {
2256 nsIDOMWindow contentWindow 2264 nsIDOMWindow contentWindow;
2257 rc = webBrowser.GetContentDOMWindow (&contentWindow); 2265 rc = webBrowser.GetContentDOMWindow (&contentWindow);
2258 if (rc !is XPCOM.NS_OK) error (rc); 2266 if (rc !is XPCOM.NS_OK) error (rc);
2259 if (contentWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE); 2267 if (contentWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE);
2260 bool isTop = contentWindow is domWindow; 2268 bool isTop = contentWindow is domWindow;
2261 contentWindow.Release (); 2269 contentWindow.Release ();
2272 2280
2273 /* 2281 /*
2274 * Remove and unreference the nsIDOMWindow from the collection of windows 2282 * Remove and unreference the nsIDOMWindow from the collection of windows
2275 * that are waiting to have DOM listeners hooked on them. 2283 * that are waiting to have DOM listeners hooked on them.
2276 */ 2284 */
2277 unhookedDOMWindows = unhookedDOMWindows.arrayIndexRemove (domWindow); 2285 unhookedDOMWindows = unhookedDOMWindows.arrayIndexRemove( domWindow);
2278 domWIndow.Release (); 2286 domWIndow.Release ();
2279 } 2287 }
2280 domWindow.Release (); 2288 domWindow.Release ();
2281 } 2289 }
2282 return XPCOM.NS_OK; 2290 return XPCOM.NS_OK;
2643 * Bug in Mozilla embedding API. Mozilla takes back the focus after sending 2651 * Bug in Mozilla embedding API. Mozilla takes back the focus after sending
2644 * this event. This prevents tabbing out of Mozilla. This behaviour can be reproduced 2652 * this event. This prevents tabbing out of Mozilla. This behaviour can be reproduced
2645 * with the Mozilla application TestGtkEmbed. The workaround is to 2653 * with the Mozilla application TestGtkEmbed. The workaround is to
2646 * send the traversal notification after this callback returns. 2654 * send the traversal notification after this callback returns.
2647 */ 2655 */
2648 browser.getDisplay ().asyncExec (new Runnable () { 2656 browser.getDisplay ().asyncExec (new class() Runnable {
2649 public void run () { 2657 public void run () {
2650 if (browser.isDisposed ()) return; 2658 if (browser.isDisposed ()) return;
2651 browser.traverse (DWT.TRAVERSE_TAB_NEXT); 2659 browser.traverse (DWT.TRAVERSE_TAB_NEXT);
2652 } 2660 }
2653 }); 2661 });
2659 * Bug in Mozilla embedding API. Mozilla takes back the focus after sending 2667 * Bug in Mozilla embedding API. Mozilla takes back the focus after sending
2660 * this event. This prevents tabbing out of Mozilla. This behaviour can be reproduced 2668 * this event. This prevents tabbing out of Mozilla. This behaviour can be reproduced
2661 * with the Mozilla application TestGtkEmbed. The workaround is to 2669 * with the Mozilla application TestGtkEmbed. The workaround is to
2662 * send the traversal notification after this callback returns. 2670 * send the traversal notification after this callback returns.
2663 */ 2671 */
2664 browser.getDisplay ().asyncExec (new Runnable () { 2672 browser.getDisplay ().asyncExec (new class() Runnable {
2665 public void run () { 2673 public void run () {
2666 if (browser.isDisposed ()) return; 2674 if (browser.isDisposed ()) return;
2667 browser.traverse (DWT.TRAVERSE_TAB_PREVIOUS); 2675 browser.traverse (DWT.TRAVERSE_TAB_PREVIOUS);
2668 } 2676 }
2669 }); 2677 });