summaryrefslogtreecommitdiff
blob: db2536bab3ac5c0fe467cde3a44c26c0940b589d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# Patch by Grant Gayed
# https://bugs.eclipse.org/bugs/show_bug.cgi?id=268651#c18
# https://bugs.eclipse.org/bugs/attachment.cgi?id=130751
Index: Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java,v
retrieving revision 1.105.2.3
diff -u -r1.105.2.3 Mozilla.java
--- src/org/eclipse/swt/browser/Mozilla.java	21 Aug 2008 16:02:30 -00001.105.2.3
+++ src/org/eclipse/swt/browser/Mozilla.java	2 Apr 2009 19:15:06 -0000
@@ -47,6 +47,7 @@
 	Shell tip = null;
 	Listener listener;
 	Vector unhookedDOMWindows = new Vector ();
+	byte[] htmlBytes;
 
 	static nsIAppShell AppShell;
 	static AppFileLocProvider LocationProvider;
@@ -1130,21 +1131,21 @@
 				 * Once the client does a proper navigate with either setUrl() or setText() then resume as
 				 * normal.  The Mozilla bug for this is https://bugzilla.mozilla.org/show_bug.cgi?id=415789.
 				 */
-				awaitingNavigate = true;
-				rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result);
-				if (rc != XPCOM.NS_OK) {
-					browser.dispose ();
-					error (rc);
-				}
-				if (result[0] == 0) {
-					browser.dispose ();
-					error (XPCOM.NS_ERROR_NO_INTERFACE);
-				}
-				nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
-			    char[] uri = new char[ABOUT_BLANK.length () + 1];
-			    ABOUT_BLANK.getChars (0, ABOUT_BLANK.length (), uri, 0);
-				rc = webNavigation.LoadURI (uri, nsIWebNavigation.LOAD_FLAGS_NONE, 0, 0, 0);
-				webNavigation.Release ();
+//				awaitingNavigate = true;
+//				rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result);
+//				if (rc != XPCOM.NS_OK) {
+//					browser.dispose ();
+//					error (rc);
+//				}
+//				if (result[0] == 0) {
+//					browser.dispose ();
+//					error (XPCOM.NS_ERROR_NO_INTERFACE);
+//				}
+//				nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
+//			    char[] uri = new char[ABOUT_BLANK.length () + 1];
+//			    ABOUT_BLANK.getChars (0, ABOUT_BLANK.length (), uri, 0);
+//				rc = webNavigation.LoadURI (uri, nsIWebNavigation.LOAD_FLAGS_NONE, 0, 0, 0);
+//				webNavigation.Release ();
 			}
 		}
 		result[0] = 0;
@@ -1223,6 +1224,7 @@
 }
 
 public boolean back () {
+	htmlBytes = null;
 	if (awaitingNavigate) return false;
 
 	long /*int*/[] result = new long /*int*/[1];
@@ -1425,6 +1427,7 @@
 }
 
 public boolean forward () {
+	htmlBytes = null;
 	if (awaitingNavigate) return false;
 
 	long /*int*/[] result = new long /*int*/[1];
@@ -1635,6 +1638,7 @@
 	webBrowser.Release ();
 	webBrowser = null;
 	webBrowserObject = null;
+	htmlBytes = null;
 
 	if (tip != null && !tip.isDisposed ()) tip.dispose ();
 	tip = null;
@@ -1696,6 +1700,7 @@
 }
 
 public void refresh () {
+	htmlBytes = null;
 	if (awaitingNavigate) return;
 
 	long /*int*/[] result = new long /*int*/[1];
@@ -1817,11 +1822,45 @@
 		} else {
 			result[0] = 0;
 			rc = interfaceRequestor.GetInterface (nsIDocShell.NS_IDOCSHELL_IID, result);
-			if (rc != XPCOM.NS_OK) error (rc);
-			if (result[0] == 0) error (XPCOM.NS_ERROR_NO_INTERFACE);
-			nsIDocShell docShell = new nsIDocShell (result[0]);
-			rc = docShell.LoadStream (inputStream.getAddress (), uri.getAddress (), aContentType,  aContentCharset, 0);
-			docShell.Release ();
+			if (rc == XPCOM.NS_OK) {
+				if (result[0] == 0) error (XPCOM.NS_ERROR_NO_INTERFACE);
+				nsIDocShell docShell = new nsIDocShell (result[0]);
+				rc = docShell.LoadStream (inputStream.getAddress (), uri.getAddress (), aContentType,  aContentCharset, 0);
+				docShell.Release ();
+			} else {
+				result[0] = 0;
+				rc = webBrowser.QueryInterface (nsIWebBrowserStream.NS_IWEBBROWSERSTREAM_IID, result);
+				if (rc == XPCOM.NS_OK) {
+					if (result[0] == 0) error (XPCOM.NS_ERROR_NO_INTERFACE);
+					/*
+					* Setting mozilla's content through nsIWebBrowserStream does not cause a page
+					* load to occur, so the events that usually accompany a page change are not
+					* fired.  To make this behave as expected, navigate to about:blank first and
+					* then set the html content once the page has loaded.
+					*/
+					new nsISupports (result[0]).Release ();
+					result[0] = 0;
+
+					/*
+					* If htmlBytes is not null then the about:blank page is already being loaded,
+					* so no Navigate is required.  Just set the html that is to be shown.
+					*/
+					boolean blankLoading = htmlBytes != null;
+					htmlBytes = data;
+					if (blankLoading) return true;
+
+					/* navigate to about:blank */
+					rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result);
+					if (rc != XPCOM.NS_OK) error (rc);
+					if (result[0] == 0) error (XPCOM.NS_ERROR_NO_INTERFACE);
+					nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
+					result[0] = 0;
+				    char[] uriChars = new char[ABOUT_BLANK.length () + 1];
+				    ABOUT_BLANK.getChars (0, ABOUT_BLANK.length (), uriChars, 0);
+					rc = webNavigation.LoadURI (uriChars, nsIWebNavigation.LOAD_FLAGS_NONE, 0, 0, 0);
+					webNavigation.Release ();
+				}
+			}
 		}
 	}
 	if (rc != XPCOM.NS_OK) error (rc);
@@ -1836,6 +1875,7 @@
 }
 
 public boolean setUrl (String url) {
+	htmlBytes = null;
 	awaitingNavigate = false;
 
 	long /*int*/[] result = new long /*int*/[1];
@@ -1852,6 +1892,7 @@
 }
 
 public void stop () {
+	htmlBytes = null;
 	if (awaitingNavigate) return;
 
 	long /*int*/[] result = new long /*int*/[1];
@@ -2174,6 +2215,108 @@
 			unhookedDOMWindows.remove (ptrObject);
 			new nsISupports (ptrObject.value).Release ();
 		}
+
+		/*
+		* If htmlBytes is not null then there is html from a previous setText() call
+		* waiting to be set into the about:blank page once it has completed loading. 
+		*/
+		if (htmlBytes != null) {
+			nsIRequest req = new nsIRequest (aRequest);
+			long /*int*/ name = XPCOM.nsEmbedCString_new ();
+			rc = req.GetName (name);
+			if (rc != XPCOM.NS_OK) error (rc);
+			int length = XPCOM.nsEmbedCString_Length (name);
+			long /*int*/ buffer = XPCOM.nsEmbedCString_get (name);
+			byte[] dest = new byte[length];
+			XPCOM.memmove (dest, buffer, length);
+			String url = new String (dest);
+			XPCOM.nsEmbedCString_delete (name);
+
+			if (url.startsWith (ABOUT_BLANK)) {
+				/*
+				 * Setting mozilla's content with nsIWebBrowserStream invalidates the 
+				 * DOM listeners that were hooked on it (about:blank), so remove them and
+				 * add new ones after the content has been set.
+				 */
+				unhookDOMListeners ();
+
+				rc = XPCOM.NS_GetServiceManager (result);
+				if (rc != XPCOM.NS_OK) error (rc);
+				if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+				nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
+				result[0] = 0;
+				rc = serviceManager.GetService (XPCOM.NS_IOSERVICE_CID, nsIIOService.NS_IIOSERVICE_IID, result);
+				if (rc != XPCOM.NS_OK) error (rc);
+				if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+				serviceManager.Release ();
+
+				nsIIOService ioService = new nsIIOService (result[0]);
+				result[0] = 0;
+				/*
+				* Note.  Mozilla ignores LINK tags used to load CSS stylesheets
+				* when the URI protocol for the nsInputStreamChannel
+				* is about:blank.  The fix is to specify the file protocol.
+				*/
+				byte[] aString = MozillaDelegate.wcsToMbcs (null, URI_FROMMEMORY, false);
+				long /*int*/ aSpec = XPCOM.nsEmbedCString_new (aString, aString.length);
+				rc = ioService.NewURI (aSpec, null, 0, result);
+				if (rc != XPCOM.NS_OK) error (rc);
+				if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+				XPCOM.nsEmbedCString_delete (aSpec);
+				ioService.Release ();
+
+				nsIURI uri = new nsIURI (result[0]);
+				result[0] = 0;
+
+				rc = webBrowser.QueryInterface (nsIWebBrowserStream.NS_IWEBBROWSERSTREAM_IID, result);
+				if (rc != XPCOM.NS_OK) error (rc);
+				if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+				nsIWebBrowserStream stream = new nsIWebBrowserStream (result[0]);
+				result[0] = 0;
+
+				byte[] contentTypeBuffer = MozillaDelegate.wcsToMbcs (null, "text/html", true); // $NON-NLS-1$
+				long /*int*/ aContentType = XPCOM.nsEmbedCString_new (contentTypeBuffer, contentTypeBuffer.length);
+
+				rc = stream.OpenStream (uri.getAddress (), aContentType);
+				if (rc != XPCOM.NS_OK) error (rc);
+				long /*int*/ ptr = C.malloc (htmlBytes.length);
+				XPCOM.memmove (ptr, htmlBytes, htmlBytes.length);
+				int pageSize = 8192;
+				int pageCount = htmlBytes.length / pageSize + 1;
+				long /*int*/ current = ptr;
+				for (int i = 0; i < pageCount; i++) {
+					length = i == pageCount - 1 ? htmlBytes.length % pageSize : pageSize;
+					if (length > 0) {
+						rc = stream.AppendToStream (current, length);
+						if (rc != XPCOM.NS_OK) error (rc);
+					}
+					current += pageSize;
+				}
+				rc = stream.CloseStream ();
+				if (rc != XPCOM.NS_OK) error (rc);
+				C.free (ptr);
+				XPCOM.nsEmbedCString_delete (aContentType);
+				stream.Release ();
+				uri.Release ();
+				htmlBytes = null;
+
+				rc = webBrowser.GetContentDOMWindow (result);
+				if (rc != XPCOM.NS_OK) error (rc);
+				if (result[0] == 0) error (XPCOM.NS_ERROR_NO_INTERFACE);
+				boolean isTop = result[0] == domWindow.getAddress ();
+				new nsISupports (result[0]).Release ();
+				result[0] = 0;
+				rc = domWindow.QueryInterface (nsIDOMEventTarget.NS_IDOMEVENTTARGET_IID, result);
+				if (rc != XPCOM.NS_OK) error (rc);
+				if (result[0] == 0) error (XPCOM.NS_ERROR_NO_INTERFACE);
+				nsIDOMEventTarget target = new nsIDOMEventTarget (result[0]);
+				result[0] = 0;
+				hookDOMListeners (target, isTop);
+				target.Release ();
+			}
+		}
 		domWindow.Release ();
 
 		/*
Index: Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIWebBrowserStream.java
===================================================================
RCS file: Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIWebBrowserStream.java
diff -N Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIWebBrowserStream.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/swt/internal/mozilla/nsIWebBrowserStream.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,55 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code, released March 31, 1998.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by Netscape are Copyright (C) 1998-1999
+ * Netscape Communications Corporation.  All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * IBM
+ * -  Binding to permit interfacing between Mozilla and SWT
+ * -  Copyright (C) 2003, 2009 IBM Corp.  All Rights Reserved.
+ *
+ * ***** END LICENSE BLOCK ***** */
+package org.eclipse.swt.internal.mozilla;
+
+public class nsIWebBrowserStream extends nsISupports {
+
+	static final int LAST_METHOD_ID = nsISupports.LAST_METHOD_ID + 3;
+
+	public static final String NS_IWEBBROWSERSTREAM_IID_STR =
+		"86d02f0e-219b-4cfc-9c88-bd98d2cce0b8";
+
+	public static final nsID NS_IWEBBROWSERSTREAM_IID =
+		new nsID(NS_IWEBBROWSERSTREAM_IID_STR);
+
+	public nsIWebBrowserStream(long /*int*/ address) {
+		super(address);
+	}
+
+	public int OpenStream(long /*int*/ aBaseURI, long /*int*/ aContentType) {
+		return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 1, getAddress(), aBaseURI, aContentType);
+	}
+
+	public int AppendToStream(long /*int*/ aData, int aLen) {
+		return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 2, getAddress(), aData, aLen);
+	}
+
+	public int CloseStream() {
+		return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 3, getAddress());
+	}
+}