25
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2003, 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * John Reimer <terminal.node@gmail.com>
|
|
12 *******************************************************************************/
|
|
13 module org.eclipse.swt.browser.Mozilla;
|
|
14
|
|
15 import java.lang.all;
|
|
16
|
48
|
17
|
|
18 version(Tango){
|
25
|
19 import tango.text.locale.Core;
|
|
20 import tango.io.Console;
|
|
21 import tango.sys.Environment;
|
|
22 import tango.stdc.string;
|
48
|
23 } else { // Phobos
|
|
24 }
|
25
|
25
|
|
26 import org.eclipse.swt.internal.c.gtk;
|
|
27
|
|
28 import org.eclipse.swt.SWT;
|
|
29 import org.eclipse.swt.SWTError;
|
|
30 import org.eclipse.swt.graphics.Device;
|
|
31 import org.eclipse.swt.graphics.Point;
|
|
32 import org.eclipse.swt.graphics.Rectangle;
|
|
33
|
|
34 import org.eclipse.swt.browser.Browser;
|
|
35 import org.eclipse.swt.browser.WebBrowser;
|
|
36 import org.eclipse.swt.browser.MozillaDelegate;
|
|
37 import org.eclipse.swt.browser.AppFileLocProvider;
|
|
38 import org.eclipse.swt.browser.WindowCreator2;
|
|
39 import org.eclipse.swt.browser.PromptService2Factory;
|
|
40 import org.eclipse.swt.browser.HelperAppLauncherDialogFactory;
|
|
41 import org.eclipse.swt.browser.DownloadFactory;
|
|
42 import org.eclipse.swt.browser.DownloadFactory_1_8;
|
|
43 import org.eclipse.swt.browser.FilePickerFactory;
|
|
44 import org.eclipse.swt.browser.FilePickerFactory_1_8;
|
|
45 import org.eclipse.swt.browser.InputStream;
|
|
46 import org.eclipse.swt.browser.StatusTextEvent;
|
|
47 import org.eclipse.swt.browser.ProgressEvent;
|
|
48 import org.eclipse.swt.browser.LocationEvent;
|
|
49 import org.eclipse.swt.browser.WindowEvent;
|
|
50 import org.eclipse.swt.browser.TitleEvent;
|
|
51
|
|
52 import org.eclipse.swt.internal.Compatibility;
|
|
53 import org.eclipse.swt.internal.LONG;
|
|
54 import org.eclipse.swt.internal.Library;
|
|
55
|
|
56 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM;
|
|
57 import XPCOMInit = org.eclipse.swt.internal.mozilla.XPCOMInit;
|
|
58
|
|
59 import org.eclipse.swt.internal.mozilla.Common;
|
|
60 import org.eclipse.swt.internal.mozilla.nsEmbedString;
|
|
61 import org.eclipse.swt.internal.mozilla.nsIAppShell;
|
|
62 import org.eclipse.swt.internal.mozilla.nsIBaseWindow;
|
|
63 import org.eclipse.swt.internal.mozilla.nsICategoryManager;
|
|
64 import org.eclipse.swt.internal.mozilla.nsIComponentManager;
|
|
65 import org.eclipse.swt.internal.mozilla.nsIComponentRegistrar;
|
|
66 import org.eclipse.swt.internal.mozilla.nsIContextMenuListener;
|
|
67 import org.eclipse.swt.internal.mozilla.nsICookie;
|
|
68 import org.eclipse.swt.internal.mozilla.nsICookieManager;
|
|
69 import org.eclipse.swt.internal.mozilla.nsID;
|
|
70 import org.eclipse.swt.internal.mozilla.nsIDOMNode;
|
|
71 import org.eclipse.swt.internal.mozilla.nsIDOMEvent;
|
|
72 import org.eclipse.swt.internal.mozilla.nsIDOMEventListener;
|
|
73 import org.eclipse.swt.internal.mozilla.nsIDOMEventTarget;
|
|
74 import org.eclipse.swt.internal.mozilla.nsIDOMKeyEvent;
|
|
75 import org.eclipse.swt.internal.mozilla.nsIDOMMouseEvent;
|
|
76 import org.eclipse.swt.internal.mozilla.nsIDOMSerializer;
|
|
77 import org.eclipse.swt.internal.mozilla.nsIDOMSerializer_1_7;
|
|
78 import org.eclipse.swt.internal.mozilla.nsIDOMWindow;
|
|
79 import org.eclipse.swt.internal.mozilla.nsIDOMWindowCollection;
|
|
80 import org.eclipse.swt.internal.mozilla.nsIDOMDocument;
|
|
81 import org.eclipse.swt.internal.mozilla.nsIDirectoryService;
|
|
82 import org.eclipse.swt.internal.mozilla.nsIDocShell;
|
|
83 import org.eclipse.swt.internal.mozilla.nsIEmbeddingSiteWindow;
|
|
84 import org.eclipse.swt.internal.mozilla.nsIFile;
|
|
85 import org.eclipse.swt.internal.mozilla.nsIFactory;
|
|
86 import org.eclipse.swt.internal.mozilla.nsIIOService;
|
|
87 import org.eclipse.swt.internal.mozilla.nsIInterfaceRequestor;
|
|
88 import org.eclipse.swt.internal.mozilla.nsIJSContextStack;
|
|
89 import org.eclipse.swt.internal.mozilla.nsILocalFile;
|
|
90 import org.eclipse.swt.internal.mozilla.nsIObserverService;
|
|
91 import org.eclipse.swt.internal.mozilla.nsIPrefBranch;
|
|
92 import org.eclipse.swt.internal.mozilla.nsIPrefLocalizedString;
|
|
93 import org.eclipse.swt.internal.mozilla.nsIPrefService;
|
|
94 import org.eclipse.swt.internal.mozilla.nsIProperties;
|
|
95 import org.eclipse.swt.internal.mozilla.nsIRequest;
|
|
96 import org.eclipse.swt.internal.mozilla.nsIServiceManager;
|
|
97 import org.eclipse.swt.internal.mozilla.nsISimpleEnumerator;
|
|
98 import org.eclipse.swt.internal.mozilla.nsIStreamListener;
|
|
99 import org.eclipse.swt.internal.mozilla.nsISupports;
|
|
100 import org.eclipse.swt.internal.mozilla.nsITooltipListener;
|
|
101 import org.eclipse.swt.internal.mozilla.nsIURI;
|
|
102 import org.eclipse.swt.internal.mozilla.nsIURIContentListener;
|
|
103 import org.eclipse.swt.internal.mozilla.nsIWeakReference;
|
|
104 import org.eclipse.swt.internal.mozilla.nsIWebBrowser;
|
|
105 import org.eclipse.swt.internal.mozilla.nsIWebBrowserChrome;
|
|
106 import org.eclipse.swt.internal.mozilla.nsIWebBrowserChromeFocus;
|
|
107 import org.eclipse.swt.internal.mozilla.nsIWebBrowserFocus;
|
|
108 import org.eclipse.swt.internal.mozilla.nsIWebNavigation;
|
|
109 import org.eclipse.swt.internal.mozilla.nsIWebNavigationInfo;
|
|
110 import org.eclipse.swt.internal.mozilla.nsIWebProgress;
|
|
111 import org.eclipse.swt.internal.mozilla.nsIWebProgressListener;
|
|
112 import org.eclipse.swt.internal.mozilla.nsIWindowWatcher;
|
|
113 import org.eclipse.swt.internal.mozilla.nsIWindowCreator;
|
|
114 import org.eclipse.swt.internal.mozilla.nsStringAPI;
|
|
115
|
|
116 import org.eclipse.swt.layout.FillLayout;
|
|
117 import org.eclipse.swt.widgets.Composite;
|
|
118 import org.eclipse.swt.widgets.Display;
|
|
119 import org.eclipse.swt.widgets.Event;
|
|
120 import org.eclipse.swt.widgets.Label;
|
|
121 import org.eclipse.swt.widgets.Listener;
|
|
122 import org.eclipse.swt.widgets.Menu;
|
|
123 import org.eclipse.swt.widgets.Shell;
|
|
124 import org.eclipse.swt.widgets.Control;
|
|
125
|
|
126 class Mozilla : WebBrowser,
|
|
127 nsIWeakReference,
|
|
128 nsIWebProgressListener,
|
|
129 nsIWebBrowserChrome,
|
|
130 nsIWebBrowserChromeFocus,
|
|
131 nsIEmbeddingSiteWindow,
|
|
132 nsIInterfaceRequestor,
|
|
133 nsISupportsWeakReference,
|
|
134 nsIContextMenuListener,
|
|
135 nsIURIContentListener,
|
|
136 nsITooltipListener,
|
|
137 nsIDOMEventListener {
|
|
138
|
|
139 GtkWidget* embedHandle;
|
|
140 nsIWebBrowser webBrowser;
|
|
141 Object webBrowserObject;
|
|
142 MozillaDelegate mozDelegate;
|
|
143
|
|
144 int chromeFlags = nsIWebBrowserChrome.CHROME_DEFAULT;
|
|
145 int refCount, lastKeyCode, lastCharCode;
|
|
146 nsIRequest request;
|
|
147 Point location, size;
|
|
148 bool visible, isChild, ignoreDispose, awaitingNavigate;
|
|
149 Shell tip = null;
|
|
150 Listener listener;
|
|
151 nsIDOMWindow[] unhookedDOMWindows;
|
|
152
|
|
153 static nsIAppShell AppShell;
|
|
154 static AppFileLocProvider LocationProvider;
|
|
155 static WindowCreator2 WindowCreator;
|
|
156 static int BrowserCount;
|
|
157 static bool Initialized, IsPre_1_8, PerformedVersionCheck, XPCOMWasGlued, XPCOMInitWasGlued;
|
|
158
|
|
159 /* XULRunner detect constants */
|
|
160 static const String GRERANGE_LOWER = "1.8.1.2"; //$NON-NLS-1$
|
|
161 static const String GRERANGE_LOWER_FALLBACK = "1.8"; //$NON-NLS-1$
|
|
162 static const bool LowerRangeInclusive = true;
|
|
163 static const String GRERANGE_UPPER = "1.9.*"; //$NON-NLS-1$
|
|
164 static const bool UpperRangeInclusive = true;
|
|
165
|
|
166 static const int MAX_PORT = 65535;
|
|
167 static String SEPARATOR_OS(){
|
|
168 return System.getProperty ("file.separator"); //$NON-NLS-1$
|
|
169 }
|
|
170 static const String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$
|
|
171 static const String DISPOSE_LISTENER_HOOKED = "org.eclipse.swt.browser.Mozilla.disposeListenerHooked"; //$NON-NLS-1$
|
|
172 static const String PREFIX_JAVASCRIPT = "javascript:"; //$NON-NLS-1$
|
|
173 static const String PREFERENCE_CHARSET = "intl.charset.default"; //$NON-NLS-1$
|
|
174 static const String PREFERENCE_DISABLEOPENDURINGLOAD = "dom.disable_open_during_load"; //$NON-NLS-1$
|
|
175 static const String PREFERENCE_DISABLEWINDOWSTATUSCHANGE = "dom.disable_window_status_change"; //$NON-NLS-1$
|
|
176 static const String PREFERENCE_LANGUAGES = "intl.accept_languages"; //$NON-NLS-1$
|
|
177 static const String PREFERENCE_PROXYHOST_FTP = "network.proxy.ftp"; //$NON-NLS-1$
|
|
178 static const String PREFERENCE_PROXYPORT_FTP = "network.proxy.ftp_port"; //$NON-NLS-1$
|
|
179 static const String PREFERENCE_PROXYHOST_HTTP = "network.proxy.http"; //$NON-NLS-1$
|
|
180 static const String PREFERENCE_PROXYPORT_HTTP = "network.proxy.http_port"; //$NON-NLS-1$
|
|
181 static const String PREFERENCE_PROXYHOST_SSL = "network.proxy.ssl"; //$NON-NLS-1$
|
|
182 static const String PREFERENCE_PROXYPORT_SSL = "network.proxy.ssl_port"; //$NON-NLS-1$
|
|
183 static const String PREFERENCE_PROXYTYPE = "network.proxy.type"; //$NON-NLS-1$
|
|
184 static const String PROFILE_AFTER_CHANGE = "profile-after-change"; //$NON-NLS-1$
|
|
185 static const String PROFILE_BEFORE_CHANGE = "profile-before-change"; //$NON-NLS-1$
|
|
186 static String PROFILE_DIR; //= SEPARATOR_OS ~ "eclipse" ~ SEPARATOR_OS; //$NON-NLS-1$
|
|
187 static const String PROFILE_DO_CHANGE = "profile-do-change"; //$NON-NLS-1$
|
|
188 static const String PROPERTY_PROXYPORT = "network.proxy_port"; //$NON-NLS-1$
|
|
189 static const String PROPERTY_PROXYHOST = "network.proxy_host"; //$NON-NLS-1$
|
|
190 static const String SEPARATOR_LOCALE = "-"; //$NON-NLS-1$
|
|
191 static const String SHUTDOWN_PERSIST = "shutdown-persist"; //$NON-NLS-1$
|
|
192 static const String STARTUP = "startup"; //$NON-NLS-1$
|
|
193 static const String TOKENIZER_LOCALE = ","; //$NON-NLS-1$
|
|
194 static const String URI_FROMMEMORY = "file:///"; //$NON-NLS-1$
|
|
195 static const String XULRUNNER_PATH = "org.eclipse.swt.browser.XULRunnerPath"; //$NON-NLS-1$
|
|
196
|
|
197 // TEMPORARY CODE
|
|
198 static const String GRE_INITIALIZED = "org.eclipse.swt.browser.XULRunnerInitialized"; //$NON-NLS-1$
|
|
199
|
|
200 this () {
|
|
201 PROFILE_DIR = SEPARATOR_OS ~ "eclipse" ~ SEPARATOR_OS;
|
|
202 MozillaClearSessions = new class() Runnable {
|
|
203 public void run () {
|
|
204 if (!Initialized) return;
|
|
205 nsIServiceManager serviceManager;
|
|
206 int rc = XPCOM.NS_GetServiceManager (&serviceManager);
|
|
207 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
208 if (serviceManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
209
|
|
210 nsICookieManager manager;
|
|
211 rc = serviceManager.GetServiceByContractID (XPCOM.NS_COOKIEMANAGER_CONTRACTID.ptr, &nsICookieManager.IID, cast(void**)&manager);
|
|
212 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
213 if (manager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
214 serviceManager.Release ();
|
|
215
|
|
216 nsISimpleEnumerator enumerator;
|
|
217 rc = manager.GetEnumerator (&enumerator);
|
|
218 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
219 manager.Release ();
|
|
220
|
|
221 PRBool moreElements;
|
|
222 rc = enumerator.HasMoreElements (&moreElements);
|
|
223 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
224 while (moreElements !is 0) {
|
|
225 nsICookie cookie;
|
|
226 rc = enumerator.GetNext (cast(nsISupports*)&cookie);
|
|
227 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
228 PRUint64 expires;
|
|
229 rc = cookie.GetExpires (&expires);
|
|
230 if (expires is 0) {
|
|
231 /* indicates a session cookie */
|
|
232 scope auto domain = new nsEmbedCString;
|
|
233 scope auto name = new nsEmbedCString;
|
|
234 scope auto path = new nsEmbedCString;
|
|
235 cookie.GetHost (cast(nsACString*)domain);
|
|
236 cookie.GetName (cast(nsACString*)name);
|
|
237 cookie.GetPath (cast(nsACString*)path);
|
|
238 rc = manager.Remove (cast(nsACString*)domain, cast(nsACString*)name, cast(nsACString*)path, 0);
|
|
239 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
240 }
|
|
241 cookie.Release ();
|
|
242 rc = enumerator.HasMoreElements (&moreElements);
|
|
243 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
244 }
|
|
245 enumerator.Release ();
|
|
246 }
|
|
247 };
|
|
248 }
|
|
249
|
|
250 extern(D)
|
|
251 public void create (Composite parent, int style) {
|
|
252 mozDelegate = new MozillaDelegate (super.browser);
|
|
253 Display display = parent.getDisplay ();
|
|
254
|
|
255 if (!Initialized) {
|
|
256 bool initLoaded = false;
|
|
257 bool IsXULRunner = false;
|
|
258
|
|
259 String greInitialized = System.getProperty (GRE_INITIALIZED);
|
|
260 if ("true" == greInitialized) { //$NON-NLS-1$
|
|
261 /*
|
|
262 * Another browser has already initialized xulrunner in this process,
|
|
263 * so just bind to it instead of trying to initialize a new one.
|
|
264 */
|
|
265 Initialized = true;
|
|
266 }
|
|
267 String mozillaPath = System.getProperty (XULRUNNER_PATH);
|
|
268 if (mozillaPath is null) {
|
|
269 // we don't need to load an initial library in D, so set to "true"
|
|
270 initLoaded = true;
|
|
271 } else {
|
|
272 mozillaPath ~= SEPARATOR_OS ~ mozDelegate.getLibraryName ();
|
|
273 IsXULRunner = true;
|
|
274 }
|
|
275
|
|
276 if (initLoaded) {
|
|
277 /* attempt to discover a XULRunner to use as the GRE */
|
|
278 XPCOMInit.GREVersionRange range;
|
|
279
|
|
280 range.lower = GRERANGE_LOWER.ptr;
|
|
281 range.lowerInclusive = LowerRangeInclusive;
|
|
282
|
|
283 range.upper = GRERANGE_UPPER.ptr;
|
|
284 range.upperInclusive = UpperRangeInclusive;
|
|
285
|
|
286 char[] greBuffer = new char[XPCOMInit.PATH_MAX];
|
|
287
|
|
288 int rc = XPCOMInit.GRE_GetGREPathWithProperties (&range, 1, null, 0, greBuffer.ptr, greBuffer.length);
|
|
289
|
|
290 /*
|
|
291 * A XULRunner was not found that supports wrapping of XPCOM handles as JavaXPCOM objects.
|
|
292 * Drop the lower version bound and try to detect an earlier XULRunner installation.
|
|
293 */
|
|
294
|
|
295 if (rc !is XPCOM.NS_OK) {
|
|
296 range.lower = GRERANGE_LOWER_FALLBACK.ptr;
|
|
297 rc = XPCOMInit.GRE_GetGREPathWithProperties (&range, 1, null, 0, greBuffer.ptr, greBuffer.length);
|
|
298 }
|
|
299
|
|
300 if (rc is XPCOM.NS_OK) {
|
|
301 /* indicates that a XULRunner was found */
|
|
302 mozillaPath = greBuffer;
|
|
303 IsXULRunner = mozillaPath.length > 0;
|
|
304
|
|
305 /*
|
|
306 * Test whether the detected XULRunner can be used as the GRE before loading swt's
|
|
307 * XULRunner library. If it cannot be used then fall back to attempting to use
|
|
308 * the GRE pointed to by MOZILLA_FIVE_HOME.
|
|
309 *
|
|
310 * One case where this will fail is attempting to use a 64-bit xulrunner while swt
|
|
311 * is running in 32-bit mode, or vice versa.
|
|
312 */
|
|
313
|
|
314 if (IsXULRunner) {
|
|
315 rc = XPCOMInit.XPCOMGlueStartup (mozillaPath.ptr);
|
|
316 if (rc !is XPCOM.NS_OK) {
|
|
317 mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
|
|
318 if (Device.DEBUG) Cerr ("cannot use detected XULRunner: ") (mozillaPath).newline; //$NON-NLS-1$
|
|
319
|
|
320 /* attempt to XPCOMGlueStartup the GRE pointed at by MOZILLA_FIVE_HOME */
|
|
321 auto ptr = Environment.get(XPCOM.MOZILLA_FIVE_HOME);
|
|
322
|
|
323 if (ptr is null) {
|
|
324 IsXULRunner = false;
|
|
325 } else {
|
|
326 mozillaPath = ptr;
|
|
327 /*
|
|
328 * Attempting to XPCOMGlueStartup a mozilla-based GRE !is xulrunner can
|
|
329 * crash, so don't attempt unless the GRE appears to be xulrunner.
|
|
330 */
|
|
331 if (mozillaPath.indexOf("xulrunner") is -1) { //$NON-NLS-1$
|
|
332 IsXULRunner = false;
|
|
333
|
|
334 } else {
|
|
335 mozillaPath ~= SEPARATOR_OS ~ mozDelegate.getLibraryName ();
|
|
336 rc = XPCOMInit.XPCOMGlueStartup (toStringz(mozillaPath));
|
|
337 if (rc !is XPCOM.NS_OK) {
|
|
338 IsXULRunner = false;
|
|
339 mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
|
|
340 if (Device.DEBUG) Cerr ("failed to start as XULRunner: " )(mozillaPath).newline; //$NON-NLS-1$
|
|
341 }
|
|
342 }
|
|
343 }
|
|
344 }
|
|
345 if (IsXULRunner) {
|
|
346 XPCOMInitWasGlued = true;
|
|
347 }
|
|
348 }
|
|
349 }
|
|
350 }
|
|
351
|
|
352 if (IsXULRunner) {
|
|
353 if (Device.DEBUG) Cerr ("XULRunner path: ") (mozillaPath).newline; //$NON-NLS-1$
|
|
354
|
|
355 XPCOMWasGlued = true;
|
|
356
|
|
357 /*
|
|
358 * Remove the trailing xpcom lib name from mozillaPath because the
|
|
359 * Mozilla.initialize and NS_InitXPCOM2 invocations require a directory name only.
|
|
360 */
|
|
361 mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
|
|
362 } else {
|
|
363 if ((style & SWT.MOZILLA) !is 0) {
|
|
364 browser.dispose ();
|
|
365 String errorString = (mozillaPath !is null && mozillaPath.length > 0) ?
|
|
366 " [Failed to use detected XULRunner: " ~ mozillaPath ~ "]" :
|
|
367 " [Could not detect registered XULRunner to use]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
368 SWT.error (SWT.ERROR_NO_HANDLES, null, errorString);
|
|
369 }
|
|
370
|
|
371 /* attempt to use the GRE pointed at by MOZILLA_FIVE_HOME */
|
|
372 auto mozFiveHome = Environment.get(XPCOM.MOZILLA_FIVE_HOME);
|
|
373 if (mozFiveHome !is null) {
|
|
374 mozillaPath = mozFiveHome;
|
|
375 } else {
|
|
376 browser.dispose ();
|
|
377 SWT.error (SWT.ERROR_NO_HANDLES, null, " [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]"); //$NON-NLS-1$
|
|
378 }
|
|
379 if (Device.DEBUG) Cerr ("Mozilla path: ") (mozillaPath).newline; //$NON-NLS-1$
|
|
380
|
|
381 /*
|
|
382 * Note. Embedding a Mozilla GTK1.2 causes a crash. The workaround
|
|
383 * is to check the version of GTK used by Mozilla by looking for
|
|
384 * the libwidget_gtk.so library used by Mozilla GTK1.2. Mozilla GTK2
|
|
385 * uses the libwidget_gtk2.so library.
|
|
386 */
|
|
387 if (Compatibility.fileExists (mozillaPath, "components/libwidget_gtk.so")) { //$NON-NLS-1$
|
|
388 browser.dispose ();
|
|
389 SWT.error (SWT.ERROR_NO_HANDLES, null, " [Mozilla GTK2 required (GTK1.2 detected)]"); //$NON-NLS-1$
|
|
390 }
|
|
391 }
|
|
392
|
|
393 if (!Initialized) {
|
|
394 nsILocalFile localFile;
|
|
395 scope auto pathString = new nsEmbedString (mozillaPath.toWCharArray());
|
|
396 nsresult rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile);
|
|
397 if (rc !is XPCOM.NS_OK) {
|
|
398 browser.dispose ();
|
|
399 error (rc, __FILE__, __LINE__);
|
|
400 }
|
|
401 if (localFile is null) {
|
|
402 browser.dispose ();
|
|
403 error (XPCOM.NS_ERROR_NULL_POINTER);
|
|
404 }
|
|
405
|
|
406 LocationProvider = new AppFileLocProvider (mozillaPath);
|
|
407 LocationProvider.AddRef ();
|
|
408
|
|
409 nsIDirectoryServiceProvider directoryServiceProvider;
|
|
410 rc = LocationProvider.QueryInterface( &nsIDirectoryServiceProvider.IID, cast(void**)&directoryServiceProvider);
|
|
411 if (rc !is XPCOM.NS_OK) {
|
|
412 browser.dispose();
|
|
413 error(rc);
|
|
414 }
|
|
415 rc = XPCOM.NS_InitXPCOM2 (null, cast(nsIFile)localFile, directoryServiceProvider);
|
|
416 localFile.Release ();
|
|
417 LocationProvider.Release();
|
|
418 if (rc !is XPCOM.NS_OK) {
|
|
419 browser.dispose ();
|
|
420 SWT.error (SWT.ERROR_NO_HANDLES, null, Format(" [MOZILLA_FIVE_HOME may not point at an embeddable GRE] [NS_InitEmbedding {0} error {1} ] ", mozillaPath, rc ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
421 }
|
|
422 System.setProperty (GRE_INITIALIZED, "true"); //$NON-NLS-1$
|
|
423 if (IsXULRunner) {
|
|
424 System.setProperty (XULRUNNER_PATH, mozillaPath);
|
|
425 }
|
|
426 }
|
|
427
|
|
428 nsIComponentManager componentManager;
|
|
429 int rc = XPCOM.NS_GetComponentManager (&componentManager);
|
|
430 if (rc !is XPCOM.NS_OK) {
|
|
431 browser.dispose ();
|
|
432 error (rc, __FILE__, __LINE__);
|
|
433 }
|
|
434 if (componentManager is null) {
|
|
435 browser.dispose ();
|
|
436 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
437 }
|
|
438
|
|
439 if (mozDelegate.needsSpinup ()) {
|
|
440 /* nsIAppShell is discontinued as of xulrunner 1.9, so do not fail if it is not found */
|
|
441 rc = componentManager.CreateInstance (&XPCOM.NS_APPSHELL_CID, null, &nsIAppShell.IID, cast(void**)&AppShell);
|
|
442 if (rc !is XPCOM.NS_ERROR_NO_INTERFACE) {
|
|
443 if (rc !is XPCOM.NS_OK) {
|
|
444 browser.dispose ();
|
|
445 error (rc, __FILE__, __LINE__);
|
|
446 }
|
|
447 if (AppShell is null) {
|
|
448 browser.dispose ();
|
|
449 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
450 }
|
|
451
|
|
452 rc = AppShell.Create (null, null);
|
|
453 if (rc !is XPCOM.NS_OK) {
|
|
454 browser.dispose ();
|
|
455 error (rc, __FILE__, __LINE__);
|
|
456 }
|
|
457 rc = AppShell.Spinup ();
|
|
458 if (rc !is XPCOM.NS_OK) {
|
|
459 browser.dispose ();
|
|
460 error (rc, __FILE__, __LINE__);
|
|
461 }
|
|
462 }
|
|
463 }
|
|
464
|
|
465 WindowCreator = new WindowCreator2;
|
|
466 WindowCreator.AddRef ();
|
|
467
|
|
468 nsIServiceManager serviceManager;
|
|
469 rc = XPCOM.NS_GetServiceManager (&serviceManager);
|
|
470 if (rc !is XPCOM.NS_OK) {
|
|
471 browser.dispose ();
|
|
472 error (rc, __FILE__, __LINE__);
|
|
473 }
|
|
474 if (serviceManager is null) {
|
|
475 browser.dispose ();
|
|
476 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
477 }
|
|
478
|
|
479 nsIWindowWatcher windowWatcher;
|
|
480 rc = serviceManager.GetServiceByContractID (XPCOM.NS_WINDOWWATCHER_CONTRACTID.ptr, &nsIWindowWatcher.IID, cast(void**)&windowWatcher);
|
|
481 if (rc !is XPCOM.NS_OK) {
|
|
482 browser.dispose ();
|
|
483 error (rc, __FILE__, __LINE__);
|
|
484 }
|
|
485 if (windowWatcher is null) {
|
|
486 browser.dispose ();
|
|
487 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
488 }
|
|
489
|
|
490 rc = windowWatcher.SetWindowCreator (cast(nsIWindowCreator)WindowCreator);
|
|
491 if (rc !is XPCOM.NS_OK) {
|
|
492 browser.dispose ();
|
|
493 error (rc, __FILE__, __LINE__);
|
|
494 }
|
|
495 windowWatcher.Release ();
|
|
496
|
|
497 if (LocationProvider !is null) {
|
|
498 nsIDirectoryService directoryService;
|
|
499 rc = serviceManager.GetServiceByContractID (XPCOM.NS_DIRECTORYSERVICE_CONTRACTID.ptr, &nsIDirectoryService.IID, cast(void**)&directoryService);
|
|
500 if (rc !is XPCOM.NS_OK) {
|
|
501 browser.dispose ();
|
|
502 error (rc, __FILE__, __LINE__);
|
|
503 }
|
|
504 if (directoryService is null) {
|
|
505 browser.dispose ();
|
|
506 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
507 }
|
|
508
|
|
509 nsIProperties properties;
|
|
510 rc = directoryService.QueryInterface (&nsIProperties.IID, cast(void**)&properties);
|
|
511 if (rc !is XPCOM.NS_OK) {
|
|
512 browser.dispose ();
|
|
513 error (rc, __FILE__, __LINE__);
|
|
514 }
|
|
515 if (properties is null) {
|
|
516 browser.dispose ();
|
|
517 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
518 }
|
|
519 directoryService.Release ();
|
|
520
|
|
521 nsIFile profileDir;
|
|
522 rc = properties.Get (XPCOM.NS_APP_APPLICATION_REGISTRY_DIR.ptr, &nsIFile.IID, cast(void**)&profileDir);
|
|
523 if (rc !is XPCOM.NS_OK) {
|
|
524 browser.dispose ();
|
|
525 error (rc, __FILE__, __LINE__);
|
|
526 }
|
|
527 if (profileDir is null) {
|
|
528 browser.dispose ();
|
|
529 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
530 }
|
|
531 properties.Release ();
|
|
532
|
|
533 scope auto path = new nsEmbedCString;
|
|
534 rc = profileDir.GetNativePath (cast(nsACString*)path);
|
|
535 if (rc !is XPCOM.NS_OK) {
|
|
536 browser.dispose ();
|
|
537 error (rc, __FILE__, __LINE__);
|
|
538 }
|
|
539
|
|
540 String profilePath = path.toString() ~ PROFILE_DIR;
|
|
541 LocationProvider.setProfilePath (profilePath);
|
|
542 LocationProvider.isXULRunner = IsXULRunner;
|
|
543
|
|
544 profileDir.Release ();
|
|
545
|
|
546 /* notify observers of a new profile directory being used */
|
|
547 nsIObserverService observerService;
|
|
548 rc = serviceManager.GetServiceByContractID (XPCOM.NS_OBSERVER_CONTRACTID.ptr, &nsIObserverService.IID, cast(void**)&observerService);
|
|
549 if (rc !is XPCOM.NS_OK) {
|
|
550 browser.dispose ();
|
|
551 error (rc, __FILE__, __LINE__);
|
|
552 }
|
|
553 if (observerService is null) {
|
|
554 browser.dispose ();
|
|
555 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
556 }
|
|
557
|
|
558 wchar* chars = STARTUP.toWCharArray().toString16z();
|
|
559 rc = observerService.NotifyObservers (null, PROFILE_DO_CHANGE.ptr, chars);
|
|
560 if (rc !is XPCOM.NS_OK) {
|
|
561 browser.dispose ();
|
|
562 error (rc, __FILE__, __LINE__);
|
|
563 }
|
|
564
|
|
565 rc = observerService.NotifyObservers (null, PROFILE_AFTER_CHANGE.ptr, chars);
|
|
566 if (rc !is XPCOM.NS_OK) {
|
|
567 browser.dispose ();
|
|
568 error (rc, __FILE__, __LINE__);
|
|
569 }
|
|
570 observerService.Release ();
|
|
571 }
|
|
572
|
|
573 /*
|
|
574 * As a result of using a common profile the user cannot change their locale
|
|
575 * and charset. The fix for this is to set mozilla's locale and charset
|
|
576 * preference values according to the user's current locale and charset.
|
|
577 */
|
|
578
|
|
579 nsIPrefService prefService;
|
|
580 rc = serviceManager.GetServiceByContractID (XPCOM.NS_PREFSERVICE_CONTRACTID.ptr, &nsIPrefService.IID, cast(void**)&prefService);
|
|
581 serviceManager.Release ();
|
|
582 if (rc !is XPCOM.NS_OK) {
|
|
583 browser.dispose ();
|
|
584 error (rc, __FILE__, __LINE__);
|
|
585 }
|
|
586 if (serviceManager is null) {
|
|
587 browser.dispose ();
|
|
588 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
589 }
|
|
590
|
|
591 char[1] buffer = new char[1];
|
|
592 nsIPrefBranch prefBranch;
|
|
593 rc = prefService.GetBranch (buffer.ptr, &prefBranch); /* empty buffer denotes root preference level */
|
|
594 prefService.Release ();
|
|
595 if (rc !is XPCOM.NS_OK) {
|
|
596 browser.dispose ();
|
|
597 error (rc, __FILE__, __LINE__);
|
|
598 }
|
|
599 if (prefBranch is null) {
|
|
600 browser.dispose ();
|
|
601 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
602 }
|
|
603
|
|
604 /* get Mozilla's current locale preference value */
|
|
605 String prefLocales = null;
|
|
606 nsIPrefLocalizedString localizedString = null;
|
|
607 //buffer = MozillaDelegate.wcsToMbcs (null, PREFERENCE_LANGUAGES, true);
|
|
608 rc = prefBranch.GetComplexValue (PREFERENCE_LANGUAGES.ptr, &nsIPrefLocalizedString.IID, cast(void**)&localizedString);
|
|
609 /*
|
|
610 * Feature of Debian. For some reason attempting to query for the current locale
|
|
611 * preference fails on Debian. The workaround for this is to assume a value of
|
|
612 * "en-us,en" since this is typically the default value when mozilla is used without
|
|
613 * a profile.
|
|
614 */
|
|
615 if (rc !is XPCOM.NS_OK) {
|
|
616 prefLocales = "en-us,en" ~ TOKENIZER_LOCALE; //$NON-NLS-1$
|
|
617 } else {
|
|
618 if (localizedString is null) {
|
|
619 browser.dispose ();
|
|
620 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
621 }
|
|
622 PRUnichar* tmpChars;
|
|
623 rc = localizedString.ToString (&tmpChars);
|
|
624 if (rc !is XPCOM.NS_OK) {
|
|
625 browser.dispose ();
|
|
626 error (rc, __FILE__, __LINE__);
|
|
627 }
|
|
628 if (tmpChars is null) {
|
|
629 browser.dispose ();
|
|
630 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
631 }
|
|
632 int span = XPCOM.strlen_PRUnichar (tmpChars);
|
|
633 prefLocales = Utf.toString(tmpChars[0 .. span]) ~ TOKENIZER_LOCALE;
|
|
634 }
|
|
635
|
|
636 /*
|
|
637 * construct the new locale preference value by prepending the
|
|
638 * user's current locale and language to the original value
|
|
639 */
|
|
640
|
|
641 String language = Culture.current.twoLetterLanguageName ();
|
|
642 String country = Region.current.twoLetterRegionName ();
|
|
643 String stringBuffer = language.dup;
|
|
644
|
|
645 stringBuffer ~= SEPARATOR_LOCALE;
|
|
646 stringBuffer ~= country.toLowerCase ();
|
|
647 stringBuffer ~= TOKENIZER_LOCALE;
|
|
648 stringBuffer ~= language;
|
|
649 stringBuffer ~= TOKENIZER_LOCALE;
|
|
650 String newLocales = stringBuffer.dup;
|
|
651
|
|
652 int start, end = -1;
|
|
653 do {
|
|
654 start = end + 1;
|
|
655 end = prefLocales.indexOf (TOKENIZER_LOCALE, start);
|
|
656 String token;
|
|
657 if (end is -1) {
|
|
658 token = prefLocales.substring (start);
|
|
659 } else {
|
|
660 token = prefLocales.substring (start, end);
|
|
661 }
|
|
662 if (token.length () > 0) {
|
|
663 token = (token ~ TOKENIZER_LOCALE).trim ();
|
|
664 /* ensure that duplicate locale values are not added */
|
|
665 if (newLocales.indexOf (token) is -1) {
|
|
666 stringBuffer ~= token;
|
|
667 }
|
|
668 }
|
|
669 } while (end !is -1);
|
|
670 newLocales[] = stringBuffer[];
|
|
671 if (!newLocales.equals (prefLocales)) {
|
|
672 /* write the new locale value */
|
|
673 newLocales = newLocales.substring (0, newLocales.length () - TOKENIZER_LOCALE.length ()); /* remove trailing tokenizer */
|
|
674 if (localizedString is null) {
|
|
675 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID.ptr, null, &nsIPrefLocalizedString.IID, cast(void**)&localizedString);
|
|
676 if (rc !is XPCOM.NS_OK) {
|
|
677 browser.dispose ();
|
|
678 error (rc, __FILE__, __LINE__);
|
|
679 }
|
|
680 if (localizedString is null) {
|
|
681 browser.dispose ();
|
|
682 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
683 }
|
|
684 }
|
|
685 localizedString.SetDataWithLength (newLocales.length, newLocales.toWCharArray().toString16z());
|
|
686 rc = prefBranch.SetComplexValue (PREFERENCE_LANGUAGES.ptr, &nsIPrefLocalizedString.IID, cast(nsISupports)localizedString);
|
|
687 }
|
|
688 if (localizedString !is null) {
|
|
689 localizedString.Release ();
|
|
690 localizedString = null;
|
|
691 }
|
|
692
|
|
693 /* get Mozilla's current charset preference value */
|
|
694 String prefCharset = null;
|
|
695 rc = prefBranch.GetComplexValue (PREFERENCE_CHARSET.ptr, &nsIPrefLocalizedString.IID, cast(void**)&localizedString);
|
|
696 /*
|
|
697 * Feature of Debian. For some reason attempting to query for the current charset
|
|
698 * preference fails on Debian. The workaround for this is to assume a value of
|
|
699 * "ISO-8859-1" since this is typically the default value when mozilla is used
|
|
700 * without a profile.
|
|
701 */
|
|
702 if (rc !is XPCOM.NS_OK) {
|
|
703 prefCharset = "ISO-8859-1"; //$NON_NLS-1$
|
|
704 } else {
|
|
705 if (localizedString is null) {
|
|
706 browser.dispose ();
|
|
707 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
708 }
|
|
709 PRUnichar* tmpChar;
|
|
710 rc = localizedString.ToString (&tmpChar);
|
|
711 if (rc !is XPCOM.NS_OK) {
|
|
712 browser.dispose ();
|
|
713 error (rc, __FILE__, __LINE__);
|
|
714 }
|
|
715 if (tmpChar is null) {
|
|
716 browser.dispose ();
|
|
717 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
718 }
|
|
719 int span = XPCOM.strlen_PRUnichar (tmpChar);
|
|
720 prefCharset = Utf.toString(tmpChar[0 .. span]);
|
|
721 }
|
|
722
|
|
723 String newCharset = System.getProperty ("file.encoding"); // $NON-NLS-1$
|
|
724 if (!newCharset.equals (prefCharset)) {
|
|
725 /* write the new charset value */
|
|
726 if (localizedString is null) {
|
|
727 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID.ptr, null, &nsIPrefLocalizedString.IID, cast(void**)&localizedString);
|
|
728 if (rc !is XPCOM.NS_OK) {
|
|
729 browser.dispose ();
|
|
730 error (rc, __FILE__, __LINE__);
|
|
731 }
|
|
732 if (localizedString is null) {
|
|
733 browser.dispose ();
|
|
734 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
735 }
|
|
736 }
|
|
737 localizedString.SetDataWithLength (newCharset.length, newCharset.toWCharArray().toString16z());
|
|
738 rc = prefBranch.SetComplexValue (PREFERENCE_CHARSET.ptr, &nsIPrefLocalizedString.IID, cast(nsISupports)localizedString);
|
|
739 }
|
|
740 if (localizedString !is null) localizedString.Release ();
|
|
741
|
|
742 /*
|
|
743 * Check for proxy values set as documented java properties and update mozilla's
|
|
744 * preferences with these values if needed.
|
|
745 */
|
|
746
|
|
747 // NOTE: in org.eclipse.swt, these properties don't exist so both keys will return null
|
|
748 // (which appears to be ok in this situaion)
|
|
749 String proxyHost = System.getProperty (PROPERTY_PROXYHOST);
|
|
750 String proxyPortString = System.getProperty (PROPERTY_PROXYPORT);
|
|
751
|
|
752 int port = -1;
|
|
753 if (proxyPortString !is null) {
|
|
754 try {
|
|
755 int value = Integer.valueOf (proxyPortString).intValue ();
|
|
756 if (0 <= value && value <= MAX_PORT) port = value;
|
|
757 } catch (NumberFormatException e) {
|
|
758 /* do nothing, java property has non-integer value */
|
|
759 }
|
|
760 }
|
|
761
|
|
762 if (proxyHost !is null) {
|
|
763 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_PREFLOCALIZEDSTRING_CONTRACTID.ptr, null, &nsIPrefLocalizedString.IID, cast(void**)&localizedString);
|
|
764 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
765 if (localizedString is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
766
|
|
767 rc = localizedString.SetDataWithLength (proxyHost.length, proxyHost.toWCharArray().toString16z());
|
|
768 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
769 rc = prefBranch.SetComplexValue (PREFERENCE_PROXYHOST_FTP.ptr, &nsIPrefLocalizedString.IID, cast(nsISupports)localizedString);
|
|
770 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
771 rc = prefBranch.SetComplexValue (PREFERENCE_PROXYHOST_HTTP.ptr, &nsIPrefLocalizedString.IID, cast(nsISupports)localizedString);
|
|
772 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
773 rc = prefBranch.SetComplexValue (PREFERENCE_PROXYHOST_SSL.ptr, &nsIPrefLocalizedString.IID, cast(nsISupports)localizedString);
|
|
774 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
775 localizedString.Release ();
|
|
776 }
|
|
777
|
|
778 if (port !is -1) {
|
|
779 rc = prefBranch.SetIntPref (PREFERENCE_PROXYPORT_FTP.ptr, port);
|
|
780 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
781 rc = prefBranch.SetIntPref (PREFERENCE_PROXYPORT_HTTP.ptr, port);
|
|
782 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
783 rc = prefBranch.SetIntPref (PREFERENCE_PROXYPORT_SSL.ptr, port);
|
|
784 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
785 }
|
|
786
|
|
787 if (proxyHost !is null || port !is -1) {
|
|
788 rc = prefBranch.SetIntPref (PREFERENCE_PROXYTYPE.ptr, 1);
|
|
789 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
790 }
|
|
791
|
|
792 /*
|
|
793 * Ensure that windows that are shown during page loads are not blocked. Firefox may
|
|
794 * try to block these by default since such windows are often unwelcome, but this
|
|
795 * assumption should not be made in the Browser's context. Since the Browser client
|
|
796 * is responsible for creating the new Browser and Shell in an OpenWindowListener,
|
|
797 * they should decide whether the new window is unwelcome or not and act accordingly.
|
|
798 */
|
|
799 rc = prefBranch.SetBoolPref (PREFERENCE_DISABLEOPENDURINGLOAD.ptr, 0);
|
|
800 if (rc !is XPCOM.NS_OK) {
|
|
801 browser.dispose ();
|
|
802 error (rc, __FILE__, __LINE__);
|
|
803 }
|
|
804
|
|
805 /* Ensure that the status text can be set through means like javascript */
|
|
806 rc = prefBranch.SetBoolPref (PREFERENCE_DISABLEWINDOWSTATUSCHANGE.ptr, 0);
|
|
807 if (rc !is XPCOM.NS_OK) {
|
|
808 browser.dispose ();
|
|
809 error (rc, __FILE__, __LINE__);
|
|
810 }
|
|
811
|
|
812 prefBranch.Release ();
|
|
813
|
|
814 PromptService2Factory factory = new PromptService2Factory ();
|
|
815 factory.AddRef ();
|
|
816
|
|
817 nsIComponentRegistrar componentRegistrar;
|
|
818 rc = componentManager.QueryInterface (&nsIComponentRegistrar.IID, cast(void**)&componentRegistrar);
|
|
819 if (rc !is XPCOM.NS_OK) {
|
|
820 browser.dispose ();
|
|
821 error (rc, __FILE__, __LINE__);
|
|
822 }
|
|
823 if (componentRegistrar is null) {
|
|
824 browser.dispose ();
|
|
825 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
826 }
|
|
827
|
|
828 String aClassName = "Prompt Service";
|
|
829
|
|
830 rc = componentRegistrar.RegisterFactory (&XPCOM.NS_PROMPTSERVICE_CID, aClassName.ptr, XPCOM.NS_PROMPTSERVICE_CONTRACTID.ptr, cast(nsIFactory)factory);
|
|
831
|
|
832 if (rc !is XPCOM.NS_OK) {
|
|
833 browser.dispose ();
|
|
834 error (rc, __FILE__, __LINE__);
|
|
835 }
|
|
836 factory.Release ();
|
|
837
|
|
838 /*
|
|
839 * This Download factory will be used if the GRE version is < 1.8.
|
|
840 * If the GRE version is 1.8.x then the Download factory that is registered later for
|
|
841 * contract "Transfer" will be used.
|
|
842 * If the GRE version is >= 1.9 then no Download factory is registered because this
|
|
843 * functionality is provided by the GRE.
|
|
844 */
|
|
845 DownloadFactory downloadFactory = new DownloadFactory ();
|
|
846 downloadFactory.AddRef ();
|
|
847 aClassName = "Download";
|
|
848 rc = componentRegistrar.RegisterFactory (&XPCOM.NS_DOWNLOAD_CID, aClassName.ptr, XPCOM.NS_DOWNLOAD_CONTRACTID.ptr, cast(nsIFactory)downloadFactory);
|
|
849 if (rc !is XPCOM.NS_OK) {
|
|
850 browser.dispose ();
|
|
851 error (rc, __FILE__, __LINE__);
|
|
852 }
|
|
853 downloadFactory.Release ();
|
|
854
|
|
855 FilePickerFactory pickerFactory = IsXULRunner ? new FilePickerFactory_1_8 () : new FilePickerFactory ();
|
|
856 pickerFactory.AddRef ();
|
|
857 aClassName = "FilePicker";
|
|
858 rc = componentRegistrar.RegisterFactory (&XPCOM.NS_FILEPICKER_CID, aClassName.ptr, XPCOM.NS_FILEPICKER_CONTRACTID.ptr, cast(nsIFactory)pickerFactory);
|
|
859 if (rc !is XPCOM.NS_OK) {
|
|
860 browser.dispose ();
|
|
861 error (rc, __FILE__, __LINE__);
|
|
862 }
|
|
863 pickerFactory.Release ();
|
|
864
|
|
865 componentRegistrar.Release ();
|
|
866 componentManager.Release ();
|
|
867
|
|
868 Initialized = true;
|
|
869 }
|
|
870
|
|
871 if (display.getData (DISPOSE_LISTENER_HOOKED) is null) {
|
|
872 display.setData (DISPOSE_LISTENER_HOOKED, stringcast(DISPOSE_LISTENER_HOOKED));
|
|
873 display.addListener (SWT.Dispose, dgListener( &handleDisposeEvent, display ) );
|
|
874 }
|
|
875
|
|
876 BrowserCount++;
|
|
877 nsIComponentManager componentManager;
|
|
878 int rc = XPCOM.NS_GetComponentManager (&componentManager);
|
|
879 if (rc !is XPCOM.NS_OK) {
|
|
880 browser.dispose ();
|
|
881 error (rc, __FILE__, __LINE__);
|
|
882 }
|
|
883 if (componentManager is null) {
|
|
884 browser.dispose ();
|
|
885 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
886 }
|
|
887
|
|
888 nsID NS_IWEBBROWSER_CID = { 0xF1EAC761, 0x87E9, 0x11d3, [0xAF, 0x80, 0x00, 0xA0, 0x24, 0xFF, 0xC0, 0x8C] }; //$NON-NLS-1$
|
|
889 rc = componentManager.CreateInstance (&NS_IWEBBROWSER_CID, null, &nsIWebBrowser.IID, cast(void**)&webBrowser);
|
|
890 if (rc !is XPCOM.NS_OK) {
|
|
891 browser.dispose ();
|
|
892 error (rc, __FILE__, __LINE__);
|
|
893 }
|
|
894 if (webBrowser is null) {
|
|
895 browser.dispose ();
|
|
896 error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
897 }
|
|
898
|
|
899 this.AddRef ();
|
|
900
|
|
901 rc = webBrowser.SetContainerWindow ( cast(nsIWebBrowserChrome)this );
|
|
902 if (rc !is XPCOM.NS_OK) {
|
|
903 browser.dispose ();
|
|
904 error (rc, __FILE__, __LINE__);
|
|
905 }
|
|
906
|
|
907 nsIBaseWindow baseWindow;
|
|
908 rc = webBrowser.QueryInterface (&nsIBaseWindow.IID, cast(void**)&baseWindow);
|
|
909 if (rc !is XPCOM.NS_OK) {
|
|
910 browser.dispose ();
|
|
911 error (rc, __FILE__, __LINE__);
|
|
912 }
|
|
913 if (baseWindow is null) {
|
|
914 browser.dispose ();
|
|
915 error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
916 }
|
|
917
|
|
918 Rectangle rect = browser.getClientArea ();
|
|
919 if (rect.isEmpty ()) {
|
|
920 rect.width = 1;
|
|
921 rect.height = 1;
|
|
922 }
|
|
923
|
|
924 embedHandle = mozDelegate.getHandle ();
|
|
925
|
|
926 rc = baseWindow.InitWindow (cast(void*)embedHandle, null, 0, 0, rect.width, rect.height);
|
|
927 if (rc !is XPCOM.NS_OK) {
|
|
928 browser.dispose ();
|
|
929 error (XPCOM.NS_ERROR_FAILURE);
|
|
930 }
|
|
931 rc = baseWindow.Create ();
|
|
932 if (rc !is XPCOM.NS_OK) {
|
|
933 browser.dispose ();
|
|
934 error (XPCOM.NS_ERROR_FAILURE);
|
|
935 }
|
|
936 rc = baseWindow.SetVisibility (1);
|
|
937 if (rc !is XPCOM.NS_OK) {
|
|
938 browser.dispose ();
|
|
939 error (XPCOM.NS_ERROR_FAILURE);
|
|
940 }
|
|
941 baseWindow.Release ();
|
|
942
|
|
943 if (!PerformedVersionCheck) {
|
|
944 PerformedVersionCheck = true;
|
|
945
|
|
946 nsIComponentRegistrar componentRegistrar;
|
|
947 rc = componentManager.QueryInterface (&nsIComponentRegistrar.IID, cast(void**)&componentRegistrar);
|
|
948 if (rc !is XPCOM.NS_OK) {
|
|
949 browser.dispose ();
|
|
950 error (rc, __FILE__,__LINE__);
|
|
951 }
|
|
952 if (componentRegistrar is null) {
|
|
953 browser.dispose ();
|
|
954 error (XPCOM.NS_NOINTERFACE,__FILE__,__LINE__);
|
|
955 }
|
|
956
|
|
957 HelperAppLauncherDialogFactory dialogFactory = new HelperAppLauncherDialogFactory ();
|
|
958 dialogFactory.AddRef ();
|
|
959 String aClassName = "Helper App Launcher Dialog"; //$NON-NLS-1$
|
|
960 rc = componentRegistrar.RegisterFactory (&XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CID, aClassName.ptr, XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID.ptr, cast(nsIFactory)dialogFactory);
|
|
961 if (rc !is XPCOM.NS_OK) {
|
|
962 browser.dispose ();
|
|
963 error (rc,__FILE__,__LINE__);
|
|
964 }
|
|
965 dialogFactory.Release ();
|
|
966
|
|
967 /*
|
|
968 * Check for the availability of the pre-1.8 implementation of nsIDocShell
|
|
969 * to determine if the GRE's version is < 1.8.
|
|
970 */
|
|
971 nsIInterfaceRequestor interfaceRequestor;
|
|
972 rc = webBrowser.QueryInterface (&nsIInterfaceRequestor.IID, cast(void**)&interfaceRequestor);
|
|
973 if (rc !is XPCOM.NS_OK) {
|
|
974 browser.dispose ();
|
|
975 error (XPCOM.NS_ERROR_FAILURE);
|
|
976 }
|
|
977 if (interfaceRequestor is null) {
|
|
978 browser.dispose ();
|
|
979 error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
980 }
|
|
981
|
|
982 nsIDocShell docShell;
|
|
983 rc = interfaceRequestor.GetInterface (&nsIDocShell.IID, cast(void**)&docShell);
|
|
984 if (rc is XPCOM.NS_OK && docShell !is null) {
|
|
985 IsPre_1_8 = true;
|
|
986 docShell.Release ();
|
|
987 }
|
|
988
|
|
989 /*
|
|
990 * A Download factory for contract "Transfer" must be registered iff the GRE's version is 1.8.x.
|
|
991 * Check for the availability of the 1.8 implementation of nsIDocShell to determine if the
|
|
992 * GRE's version is 1.8.x.
|
|
993 * If the GRE version is < 1.8 then the previously-registered Download factory for contract
|
|
994 * "Download" will be used.
|
|
995 * If the GRE version is >= 1.9 then no Download factory is registered because this
|
|
996 * functionality is provided by the GRE.
|
|
997 */
|
|
998 if (!IsPre_1_8) {
|
|
999 nsIDocShell_1_8 docShell_1_8;
|
|
1000 rc = interfaceRequestor.GetInterface (&nsIDocShell_1_8.IID, cast(void**)&docShell_1_8);
|
|
1001 if (rc is XPCOM.NS_OK && docShell_1_8 !is null) { /* 1.8 */
|
|
1002 docShell_1_8.Release ();
|
|
1003
|
|
1004 DownloadFactory_1_8 downloadFactory_1_8 = new DownloadFactory_1_8 ();
|
|
1005 downloadFactory_1_8.AddRef ();
|
|
1006
|
|
1007 aClassName = "Transfer"; //$NON-NLS-1$
|
|
1008 rc = componentRegistrar.RegisterFactory (&XPCOM.NS_DOWNLOAD_CID, aClassName.ptr, XPCOM.NS_TRANSFER_CONTRACTID.ptr, cast(nsIFactory)downloadFactory_1_8);
|
|
1009 if (rc !is XPCOM.NS_OK) {
|
|
1010 browser.dispose ();
|
|
1011 error (rc, __FILE__, __LINE__);
|
|
1012 }
|
|
1013 downloadFactory_1_8.Release ();
|
|
1014 } else { /* >= 1.9 */
|
|
1015 /*
|
|
1016 * Bug in XULRunner 1.9. Mozilla no longer clears its background before initial content has
|
|
1017 * been set. As a result embedders appear broken if they do not immediately navigate to a url.
|
|
1018 * The workaround for this is to navigate to about:blank immediately so that the background is
|
|
1019 * cleared, but do not fire any corresponding events or allow Browser API calls to reveal this.
|
|
1020 * Once the client does a proper navigate with either setUrl() or setText() then resume as
|
|
1021 * normal. The Mozilla bug for this is https://bugzilla.mozilla.org/show_bug.cgi?id=415789.
|
|
1022 */
|
|
1023 awaitingNavigate = true;
|
|
1024 nsIWebNavigation webNavigation;
|
|
1025 rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1026 if (rc !is XPCOM.NS_OK) {
|
|
1027 browser.dispose ();
|
|
1028 error (rc, __FILE__, __LINE__);
|
|
1029 }
|
|
1030 if (webNavigation is null) {
|
|
1031 browser.dispose ();
|
|
1032 error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1033 }
|
|
1034 rc = webNavigation.LoadURI (ABOUT_BLANK.toWCharArray().toString16z(), nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
|
|
1035 webNavigation.Release ();
|
|
1036 dialogFactory.isPre_1_9 = false;
|
|
1037 }
|
|
1038 }
|
|
1039 interfaceRequestor.Release ();
|
|
1040 componentRegistrar.Release ();
|
|
1041 }
|
|
1042 componentManager.Release ();
|
|
1043
|
|
1044 rc = webBrowser.AddWebBrowserListener (cast(nsIWeakReference)this, &nsIWebProgressListener.IID);
|
|
1045 if (rc !is XPCOM.NS_OK) {
|
|
1046 browser.dispose ();
|
|
1047 error (rc, __FILE__, __LINE__);
|
|
1048 }
|
|
1049
|
|
1050 // TODO: Find appropriate place to "Release" uriContentListener -JJR
|
|
1051 nsIURIContentListener uriContentListener;
|
|
1052 this.QueryInterface(&nsIURIContentListener.IID, cast(void**)&uriContentListener);
|
|
1053 if (rc !is XPCOM.NS_OK) {
|
|
1054 browser.dispose();
|
|
1055 error(rc);
|
|
1056 }
|
|
1057 if (uriContentListener is null) {
|
|
1058 browser.dispose();
|
|
1059 error(XPCOM.NS_ERROR_NO_INTERFACE);
|
|
1060 }
|
|
1061
|
|
1062 rc = webBrowser.SetParentURIContentListener (uriContentListener);
|
|
1063 if (rc !is XPCOM.NS_OK) {
|
|
1064 browser.dispose ();
|
|
1065 error (rc, __FILE__, __LINE__);
|
|
1066 }
|
|
1067
|
|
1068 mozDelegate.init ();
|
|
1069
|
|
1070 int[] folderEvents = [
|
|
1071 SWT.Dispose,
|
|
1072 SWT.Resize,
|
|
1073 SWT.FocusIn,
|
|
1074 SWT.Activate,
|
|
1075 SWT.Deactivate,
|
|
1076 SWT.Show,
|
|
1077 SWT.KeyDown // needed to make browser traversable
|
|
1078 ];
|
|
1079
|
|
1080 for (int i = 0; i < folderEvents.length; i++) {
|
|
1081 browser.addListener (folderEvents[i], dgListener( &handleFolderEvent ));
|
|
1082 }
|
|
1083 }
|
|
1084
|
|
1085 /*******************************************************************************
|
|
1086
|
|
1087 Event Handlers for the Mozilla Class:
|
|
1088
|
|
1089 These represent replacements for SWT's anonymous classes as used within
|
|
1090 the Mozilla class. Since D 1.0x anonymous classes do not work equivalently
|
|
1091 to Java's, we replace the anonymous classes with D delegates and templates
|
|
1092 (ie dgListener which wrap the delegate in a class). This circumvents some
|
|
1093 nasty, evasive bugs.
|
|
1094
|
|
1095 extern(D) becomes a necessary override on these methods because this class
|
|
1096 implements a XPCOM/COM interface resulting in all class methods defaulting
|
|
1097 to extern(System). -JJR
|
|
1098
|
|
1099 ******************************************************************************/
|
|
1100
|
|
1101 extern(D)
|
|
1102 private void handleDisposeEvent (Event event, Display display) {
|
|
1103 if (BrowserCount > 0) return; /* another display is still active */
|
|
1104
|
|
1105 nsIServiceManager serviceManager;
|
|
1106
|
|
1107 int rc = XPCOM.NS_GetServiceManager (&serviceManager);
|
|
1108 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1109 if (serviceManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1110
|
|
1111 nsIObserverService observerService;
|
|
1112 rc = serviceManager.GetServiceByContractID (XPCOM.NS_OBSERVER_CONTRACTID.ptr, &nsIObserverService.IID, cast(void**)&observerService);
|
|
1113 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1114 if (observerService is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1115
|
|
1116 rc = observerService.NotifyObservers (null, PROFILE_BEFORE_CHANGE.ptr, SHUTDOWN_PERSIST.toWCharArray().toString16z());
|
|
1117 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1118 observerService.Release ();
|
|
1119
|
|
1120 if (LocationProvider !is null) {
|
|
1121 String prefsLocation = LocationProvider.profilePath ~ AppFileLocProvider.PREFERENCES_FILE;
|
|
1122 scope auto pathString = new nsEmbedString (prefsLocation.toWCharArray());
|
|
1123 nsILocalFile localFile;
|
|
1124 rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile);
|
|
1125 if (rc !is XPCOM.NS_OK) Mozilla.error (rc, __FILE__, __LINE__);
|
|
1126 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
|
|
1127
|
|
1128 nsIFile prefFile;
|
|
1129 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&prefFile);
|
|
1130 if (rc !is XPCOM.NS_OK) Mozilla.error (rc, __FILE__, __LINE__);
|
|
1131 if (prefFile is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1132 localFile.Release ();
|
|
1133
|
|
1134 nsIPrefService prefService;
|
|
1135 rc = serviceManager.GetServiceByContractID (XPCOM.NS_PREFSERVICE_CONTRACTID.ptr, &nsIPrefService.IID, cast(void**)&prefService);
|
|
1136 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1137 if (prefService is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1138
|
|
1139 rc = prefService.SavePrefFile(prefFile);
|
|
1140 prefService.Release ();
|
|
1141 prefFile.Release ();
|
|
1142 }
|
|
1143 serviceManager.Release ();
|
|
1144
|
|
1145 if (XPCOMWasGlued) {
|
|
1146 /*
|
|
1147 * XULRunner 1.9 can crash on Windows if XPCOMGlueShutdown is invoked here,
|
|
1148 * presumably because one or more of its unloaded symbols are referenced when
|
|
1149 * this callback returns. The workaround is to delay invoking XPCOMGlueShutdown
|
|
1150 * so that its symbols are still available once this callback returns.
|
|
1151 */
|
|
1152 display.asyncExec (new class() Runnable {
|
|
1153 public void run () {
|
|
1154 XPCOMInit.XPCOMGlueShutdown ();
|
|
1155 }
|
|
1156 });
|
|
1157 XPCOMWasGlued = XPCOMInitWasGlued = false;
|
|
1158 }
|
|
1159
|
|
1160 Initialized = false;
|
|
1161 }
|
|
1162
|
|
1163
|
|
1164 extern(D)
|
|
1165 private void handleFolderEvent (Event event) {
|
|
1166 Control control = cast(Control)browser;
|
|
1167 switch (event.type) {
|
|
1168 case SWT.Dispose: {
|
|
1169 /* make this handler run after other dispose listeners */
|
|
1170 if (ignoreDispose) {
|
|
1171 ignoreDispose = false;
|
|
1172 break;
|
|
1173 }
|
|
1174 ignoreDispose = true;
|
|
1175 browser.notifyListeners (event.type, event);
|
|
1176 event.type = SWT.NONE;
|
|
1177 onDispose (event.display);
|
|
1178 break;
|
|
1179 }
|
|
1180 case SWT.Resize: onResize (); break;
|
|
1181 case SWT.FocusIn: Activate (); break;
|
|
1182 case SWT.Activate: Activate (); break;
|
|
1183 case SWT.Deactivate: {
|
|
1184 Display display = event.display;
|
|
1185 if (control is display.getFocusControl ()) Deactivate ();
|
|
1186 break;
|
|
1187 }
|
|
1188 case SWT.Show: {
|
|
1189 /*
|
|
1190 * Feature in GTK Mozilla. Mozilla does not show up when
|
|
1191 * its container (a GTK fixed handle) is made visible
|
|
1192 * after having been hidden. The workaround is to reset
|
|
1193 * its size after the container has been made visible.
|
|
1194 */
|
|
1195 Display display = event.display;
|
|
1196 display.asyncExec(new class () Runnable {
|
|
1197 public void run() {
|
|
1198 if (browser.isDisposed ()) return;
|
|
1199 onResize ();
|
|
1200 }
|
|
1201 });
|
|
1202 break;
|
|
1203 }
|
|
1204 default: break;
|
|
1205 }
|
|
1206 }
|
|
1207
|
|
1208 /*******************************************************************************
|
|
1209
|
|
1210 *******************************************************************************/
|
|
1211
|
|
1212 extern(D)
|
|
1213 public bool back () {
|
|
1214 if (awaitingNavigate) return false;
|
|
1215
|
|
1216 //int /*long*/[] result = new int /*long*/[1];
|
|
1217 nsIWebNavigation webNavigation;
|
|
1218 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1219 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1220 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1221
|
|
1222 //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
|
|
1223 rc = webNavigation.GoBack ();
|
|
1224 webNavigation.Release ();
|
|
1225 return rc is XPCOM.NS_OK;
|
|
1226 }
|
|
1227
|
|
1228 extern(D)
|
|
1229 public bool execute (String script) {
|
|
1230 if (awaitingNavigate) return false;
|
|
1231
|
|
1232 String url = PREFIX_JAVASCRIPT ~ script ~ ";void(0);"; //$NON-NLS-1$
|
|
1233 //int /*long*/[] result = new int /*long*/[1];
|
|
1234 nsIWebNavigation webNavigation;
|
|
1235 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1236 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1237 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1238
|
|
1239 //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
|
|
1240 //char[] arg = url.toCharArray ();
|
|
1241 //char[] c = new char[arg.length+1];
|
|
1242 //System.arraycopy (arg, 0, c, 0, arg.length);
|
|
1243 rc = webNavigation.LoadURI (url.toWCharArray().toString16z(), nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
|
|
1244 webNavigation.Release ();
|
|
1245 return rc is XPCOM.NS_OK;
|
|
1246 }
|
|
1247
|
|
1248 extern(D)
|
|
1249 static Browser findBrowser (void* handle) {
|
|
1250 return MozillaDelegate.findBrowser (cast(GtkWidget*)handle);
|
|
1251 }
|
|
1252
|
|
1253 extern(D)
|
|
1254 public bool forward () {
|
|
1255 if (awaitingNavigate) return false;
|
|
1256
|
|
1257 //int /*long*/[] result = new int /*long*/[1];
|
|
1258 nsIWebNavigation webNavigation;
|
|
1259 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1260 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1261 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1262
|
|
1263 //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
|
|
1264 rc = webNavigation.GoForward ();
|
|
1265 webNavigation.Release ();
|
|
1266
|
|
1267 return rc is XPCOM.NS_OK;
|
|
1268 }
|
|
1269
|
|
1270 extern(D)
|
|
1271 public String getText () {
|
|
1272 if (awaitingNavigate) return ""; //$NON-NLS-1$
|
|
1273
|
|
1274 //int /*long*/[] result = new int /*long*/[1];
|
|
1275 nsIDOMWindow window;
|
|
1276 int rc = webBrowser.GetContentDOMWindow (&window);
|
|
1277 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1278 if (window is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1279
|
|
1280 //nsIDOMWindow window = new nsIDOMWindow (result[0]);
|
|
1281 //result[0] = 0;
|
|
1282 nsIDOMDocument document;
|
|
1283 rc = window.GetDocument (&document);
|
|
1284 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1285 if (document is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1286 window.Release ();
|
|
1287
|
|
1288 //int /*long*/ document = result[0];
|
|
1289 //result[0] = 0;
|
|
1290 nsIComponentManager componentManager;
|
|
1291 rc = XPCOM.NS_GetComponentManager (&componentManager);
|
|
1292 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1293 if (componentManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1294
|
|
1295 //nsIComponentManager componentManager = new nsIComponentManager (result[0]);
|
|
1296 //result[0] = 0;
|
|
1297 //byte[] contractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_DOMSERIALIZER_CONTRACTID, true);
|
|
1298 String chars = null;
|
|
1299 nsIDOMSerializer_1_7 serializer_1_7;
|
|
1300 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_DOMSERIALIZER_CONTRACTID.ptr, null, &nsIDOMSerializer_1_7.IID, cast(void**)&serializer_1_7);
|
|
1301 if (rc is XPCOM.NS_OK) { /* mozilla >= 1.7 */
|
|
1302 if (serializer_1_7 is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1303
|
|
1304 //nsIDOMSerializer_1_7 serializer = new nsIDOMSerializer_1_7 (result[0]);
|
|
1305 //result[0] = 0;
|
|
1306 scope auto string = new nsEmbedString;
|
|
1307 rc = serializer_1_7.SerializeToString (cast(nsIDOMNode)document, cast(nsAString*) string);
|
|
1308 serializer_1_7.Release ();
|
|
1309
|
|
1310 //int length = XPCOM.nsEmbedString_Length (string);
|
|
1311 //int /*long*/ buffer = XPCOM.nsEmbedString_get (string);
|
|
1312 //chars = new char[length];
|
|
1313 //XPCOM.memmove (chars, buffer, length * 2);
|
|
1314 //XPCOM.nsEmbedString_delete (string);
|
|
1315 chars = string.toString();
|
|
1316 } else { /* mozilla < 1.7 */
|
|
1317 nsIDOMSerializer serializer;
|
|
1318 rc = componentManager.CreateInstanceByContractID (XPCOM.NS_DOMSERIALIZER_CONTRACTID.ptr, null, &nsIDOMSerializer.IID, cast(void**)&serializer);
|
|
1319 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1320 if (serializer is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1321 // TODO: Lookup SerializeToString contract. Find out if the string must provide it's own memory to the method. -JJR
|
|
1322 PRUnichar* string;
|
|
1323 //nsIDOMSerializer serializer = new nsIDOMSerializer (result[0]);
|
|
1324 //result[0] = 0;
|
|
1325 rc = serializer.SerializeToString (cast(nsIDOMNode)document, &string );
|
|
1326 serializer.Release ();
|
|
1327
|
|
1328 //int length = XPCOM.strlen_PRUnichar (string);
|
|
1329 //chars = new char[length];
|
|
1330 //XPCOM.memmove (chars, result[0], length * 2);
|
|
1331 chars = Utf.toString(fromString16z(string));
|
|
1332 }
|
|
1333
|
|
1334 componentManager.Release ();
|
|
1335 document.Release ();
|
|
1336 return chars.dup;
|
|
1337 }
|
|
1338
|
|
1339 extern(D)
|
|
1340 public String getUrl () {
|
|
1341 if (awaitingNavigate) return ""; //$NON-NLS-1$
|
|
1342
|
|
1343 //int /*long*/[] result = new int /*long*/[1];
|
|
1344 nsIWebNavigation webNavigation;
|
|
1345 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1346 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1347 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1348
|
|
1349 //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
|
|
1350 nsIURI aCurrentURI;
|
|
1351 rc = webNavigation.GetCurrentURI (&aCurrentURI);
|
|
1352 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1353 webNavigation.Release ();
|
|
1354
|
|
1355 String location = null;
|
|
1356 if (aCurrentURI !is null) {
|
|
1357 //nsIURI uri = new nsIURI (aCurrentURI[0]);
|
|
1358 scope auto aSpec = new nsEmbedCString;
|
|
1359 rc = aCurrentURI.GetSpec (cast(nsACString*)aSpec);
|
|
1360 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1361 //int length = XPCOM.nsEmbedCString_Length (aSpec);
|
|
1362 //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
|
|
1363 location = aSpec.toString;
|
|
1364 //XPCOM.memmove (dest, buffer, length);
|
|
1365 //XPCOM.nsEmbedCString_delete (aSpec);
|
|
1366 aCurrentURI.Release ();
|
|
1367 }
|
|
1368 if (location is null) return ""; //$NON-NLS-1$
|
|
1369
|
|
1370 /*
|
|
1371 * If the URI indicates that the page is being rendered from memory
|
|
1372 * (via setText()) then set it to about:blank to be consistent with IE.
|
|
1373 */
|
|
1374 if (location.equals (URI_FROMMEMORY)) location = ABOUT_BLANK;
|
|
1375 return location;
|
|
1376 }
|
|
1377
|
|
1378 extern(D)
|
|
1379 public Object getWebBrowser () {
|
|
1380 if ((browser.getStyle () & SWT.MOZILLA) is 0) return null;
|
|
1381 if (webBrowserObject !is null) return webBrowserObject;
|
|
1382 implMissing(__FILE__,__LINE__);
|
|
1383 /+
|
|
1384 try {
|
|
1385 // TODO: this references the JavaXPCOM browser... not sure what needs to be done here,
|
|
1386 // but I don't think this method is necessary.
|
|
1387 Class clazz = Class.forName ("org.mozilla.xpcom.Mozilla"); //$NON-NLS-1$
|
|
1388 Method method = clazz.getMethod ("getInstance", new Class[0]); //$NON-NLS-1$
|
|
1389 Object mozilla = method.invoke (null, new Object[0]);
|
|
1390 method = clazz.getMethod ("wrapXPCOMObject", new Class[] {Long.TYPE, String.class}); //$NON-NLS-1$
|
|
1391 webBrowserObject = webBrowser.getAddress ()), nsIWebBrowser.NS_IWEBBROWSER_IID_STR});
|
|
1392 /*
|
|
1393 * The following AddRef() is needed to offset the automatic Release() that
|
|
1394 * will be performed by JavaXPCOM when webBrowserObject is finalized.
|
|
1395 */
|
|
1396 webBrowser.AddRef ();
|
|
1397 return webBrowserObject;
|
|
1398 } catch (ClassNotFoundException e) {
|
|
1399 } catch (NoSuchMethodException e) {
|
|
1400 } catch (IllegalArgumentException e) {
|
|
1401 } catch (IllegalAccessException e) {
|
|
1402 } catch (InvocationTargetException e) {
|
|
1403 }
|
|
1404 +/
|
|
1405 return null;
|
|
1406 }
|
|
1407
|
|
1408 extern(D)
|
|
1409 public bool isBackEnabled () {
|
|
1410 if (awaitingNavigate) return false;
|
|
1411
|
|
1412 //int /*long*/[] result = new int /*long*/[1];
|
|
1413 nsIWebNavigation webNavigation;
|
|
1414 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1415 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1416 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1417
|
|
1418 //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
|
|
1419 PRBool aCanGoBack; /* PRBool */
|
|
1420 rc = webNavigation.GetCanGoBack (&aCanGoBack);
|
|
1421 webNavigation.Release ();
|
|
1422 return aCanGoBack !is 0;
|
|
1423 }
|
|
1424
|
|
1425 extern(D)
|
|
1426 public bool isForwardEnabled () {
|
|
1427 if (awaitingNavigate) return false;
|
|
1428
|
|
1429 //int /*long*/[] result = new int /*long*/[1];
|
|
1430 nsIWebNavigation webNavigation;
|
|
1431 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1432 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1433 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1434
|
|
1435 //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
|
|
1436 PRBool aCanGoForward; /* PRBool */
|
|
1437 rc = webNavigation.GetCanGoForward (&aCanGoForward);
|
|
1438 webNavigation.Release ();
|
|
1439 return aCanGoForward !is 0;
|
|
1440 }
|
|
1441
|
|
1442 extern(D)
|
|
1443 static void error (int code ) {
|
|
1444 error ( code, "NOT GIVEN", 0 );
|
|
1445 }
|
|
1446
|
|
1447 extern(D)
|
|
1448 static String error (int code, char[] file, int line) {
|
|
1449 getDwtLogger().info( __FILE__, __LINE__, "File: {} Line: {}", file, line);
|
|
1450 throw new SWTError ("XPCOM error " ~ Integer.toString(code)); //$NON-NLS-1$
|
|
1451 }
|
|
1452
|
|
1453 extern(D)
|
|
1454 void onDispose (Display display) {
|
|
1455 int rc = webBrowser.RemoveWebBrowserListener (cast(nsIWeakReference)this, &nsIWebProgressListener.IID);
|
|
1456 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1457
|
|
1458 rc = webBrowser.SetParentURIContentListener (null);
|
|
1459 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1460
|
|
1461 unhookDOMListeners ();
|
|
1462 if (listener !is null) {
|
|
1463 int[] folderEvents = [
|
|
1464 SWT.Dispose,
|
|
1465 SWT.Resize,
|
|
1466 SWT.FocusIn,
|
|
1467 SWT.Activate,
|
|
1468 SWT.Deactivate,
|
|
1469 SWT.Show,
|
|
1470 SWT.KeyDown,
|
|
1471 ];
|
|
1472 for (int i = 0; i < folderEvents.length; i++) {
|
|
1473 browser.removeListener (folderEvents[i], listener);
|
|
1474 }
|
|
1475 listener = null;
|
|
1476 }
|
|
1477
|
|
1478 //int /*long*/[] result = new int /*long*/[1];
|
|
1479 nsIBaseWindow baseWindow;
|
|
1480 rc = webBrowser.QueryInterface (&nsIBaseWindow.IID, cast(void**)&baseWindow);
|
|
1481 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1482 if (baseWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1483
|
|
1484 //nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]);
|
|
1485 rc = baseWindow.Destroy ();
|
|
1486 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1487 baseWindow.Release ();
|
|
1488
|
|
1489 Release ();
|
|
1490 webBrowser.Release ();
|
|
1491 webBrowser = null;
|
|
1492 webBrowserObject = null;
|
|
1493
|
|
1494 if (tip !is null && !tip.isDisposed ()) tip.dispose ();
|
|
1495 tip = null;
|
|
1496 location = size = null;
|
|
1497
|
|
1498 //Enumeration elements = unhookedDOMWindows.elements ();
|
|
1499 foreach (win ; unhookedDOMWindows) {
|
|
1500 //LONG ptrObject = (LONG)elements.nextElement ();
|
|
1501 win.Release ();
|
|
1502 }
|
|
1503 unhookedDOMWindows = null;
|
|
1504
|
|
1505 mozDelegate.onDispose (embedHandle);
|
|
1506 mozDelegate = null;
|
|
1507
|
|
1508 embedHandle = null;
|
|
1509 BrowserCount--;
|
|
1510 }
|
|
1511
|
|
1512 extern(D)
|
|
1513 void Activate () {
|
|
1514 //int /*long*/[] result = new int /*long*/[1];
|
|
1515 nsIWebBrowserFocus webBrowserFocus;
|
|
1516 int rc = webBrowser.QueryInterface (&nsIWebBrowserFocus.IID, cast(void**)&webBrowserFocus);
|
|
1517 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1518 if (webBrowserFocus is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1519
|
|
1520 //nsIWebBrowserFocus webBrowserFocus = new nsIWebBrowserFocus (result[0]);
|
|
1521 rc = webBrowserFocus.Activate ();
|
|
1522 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1523 webBrowserFocus.Release ();
|
|
1524 }
|
|
1525
|
|
1526 extern(D)
|
|
1527 void Deactivate () {
|
|
1528 //int /*long*/[] result = new int /*long*/[1];
|
|
1529 nsIWebBrowserFocus webBrowserFocus;
|
|
1530 int rc = webBrowser.QueryInterface (&nsIWebBrowserFocus.IID, cast(void**)&webBrowserFocus);
|
|
1531 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1532 if (webBrowserFocus is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1533
|
|
1534 //nsIWebBrowserFocus webBrowserFocus = new nsIWebBrowserFocus (result[0]);
|
|
1535 rc = webBrowserFocus.Deactivate ();
|
|
1536 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1537 webBrowserFocus.Release ();
|
|
1538 }
|
|
1539
|
|
1540 extern(D)
|
|
1541 void onResize () {
|
|
1542 Rectangle rect = browser.getClientArea ();
|
|
1543 int width = Math.max (1, rect.width);
|
|
1544 int height = Math.max (1, rect.height);
|
|
1545
|
|
1546 //int /*long*/[] result = new int /*long*/[1];
|
|
1547 nsIBaseWindow baseWindow;
|
|
1548 int rc = webBrowser.QueryInterface (&nsIBaseWindow.IID, cast(void**)&baseWindow);
|
|
1549 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1550 if (baseWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1551
|
|
1552 mozDelegate.setSize (embedHandle, width, height);
|
|
1553 //nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]);
|
|
1554 rc = baseWindow.SetPositionAndSize (0, 0, width, height, 1);
|
|
1555 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1556 baseWindow.Release ();
|
|
1557 }
|
|
1558
|
|
1559 extern(D)
|
|
1560 public void refresh () {
|
|
1561 if (awaitingNavigate) return;
|
|
1562
|
|
1563 //int /*long*/[] result = new int /*long*/[1];
|
|
1564 nsIWebNavigation webNavigation;
|
|
1565 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1566 if (rc !is XPCOM.NS_OK) error(rc);
|
|
1567 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1568
|
|
1569 //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
|
|
1570 rc = webNavigation.Reload (nsIWebNavigation.LOAD_FLAGS_NONE);
|
|
1571 webNavigation.Release ();
|
|
1572 if (rc is XPCOM.NS_OK) return;
|
|
1573 /*
|
|
1574 * Feature in Mozilla. Reload returns an error code NS_ERROR_INVALID_POINTER
|
|
1575 * when it is called immediately after a request to load a new document using
|
|
1576 * LoadURI. The workaround is to ignore this error code.
|
|
1577 *
|
|
1578 * Feature in Mozilla. Attempting to reload a file that no longer exists
|
|
1579 * returns an error code of NS_ERROR_FILE_NOT_FOUND. This is equivalent to
|
|
1580 * attempting to load a non-existent local url, which is not a Browser error,
|
|
1581 * so this error code should be ignored.
|
|
1582 */
|
|
1583 if (rc !is XPCOM.NS_ERROR_INVALID_POINTER && rc !is XPCOM.NS_ERROR_FILE_NOT_FOUND) error (rc, __FILE__, __LINE__);
|
|
1584 }
|
|
1585
|
|
1586 extern(D)
|
|
1587 public bool setText (String html) {
|
|
1588 /*
|
|
1589 * Feature in Mozilla. The focus memory of Mozilla must be
|
|
1590 * properly managed through the nsIWebBrowserFocus interface.
|
|
1591 * In particular, nsIWebBrowserFocus.deactivate must be called
|
|
1592 * when the focus moves from the browser (or one of its children
|
|
1593 * managed by Mozilla to another widget. We currently do not
|
|
1594 * get notified when a widget takes focus away from the Browser.
|
|
1595 * As a result, deactivate is not properly called. This causes
|
|
1596 * Mozilla to retake focus the next time a document is loaded.
|
|
1597 * This breaks the case where the HTML loaded in the Browser
|
|
1598 * varies while the user enters characters in a text widget. The text
|
|
1599 * widget loses focus every time new content is loaded.
|
|
1600 * The current workaround is to call deactivate everytime if
|
|
1601 * the browser currently does not have focus. A better workaround
|
|
1602 * would be to have a way to call deactivate when the Browser
|
|
1603 * or one of its children loses focus.
|
|
1604 */
|
|
1605 if (browser !is browser.getDisplay().getFocusControl ()) {
|
|
1606 Deactivate ();
|
|
1607 }
|
|
1608 /* convert the String containing HTML to an array of bytes with UTF-8 data */
|
|
1609 /+
|
|
1610 byte[] data = null;
|
|
1611 try {
|
|
1612 data = html.getBytes ("UTF-8"); //$NON-NLS-1$
|
|
1613 } catch (UnsupportedEncodingException e) {
|
|
1614 return false;
|
|
1615 }
|
|
1616 +/
|
|
1617 awaitingNavigate = false;
|
|
1618
|
|
1619 //byte[] contentTypeBuffer = MozillaDelegate.wcsToMbcs (null, "text/html", true); // $NON-NLS-1$
|
|
1620 scope auto aContentType = new nsEmbedCString ("text/html");
|
|
1621 //byte[] contentCharsetBuffer = MozillaDelegate.wcsToMbcs (null, "UTF-8", true); //$NON-NLS-1$
|
|
1622 scope auto aContentCharset = new nsEmbedCString ("UTF-8");
|
|
1623
|
|
1624 //int /*long*/[] result = new int /*long*/[1];
|
|
1625 nsIServiceManager serviceManager;
|
|
1626 int rc = XPCOM.NS_GetServiceManager (&serviceManager);
|
|
1627 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1628 if (serviceManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1629
|
|
1630 //nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
|
|
1631 //result[0] = 0;
|
|
1632 nsIIOService ioService;
|
|
1633 rc = serviceManager.GetService (&XPCOM.NS_IOSERVICE_CID, &nsIIOService.IID, cast(void**)&ioService);
|
|
1634 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1635 if (ioService is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1636 serviceManager.Release ();
|
|
1637
|
|
1638 //nsIIOService ioService = new nsIIOService (result[0]);
|
|
1639 //result[0] = 0;
|
|
1640 /*
|
|
1641 * Note. Mozilla ignores LINK tags used to load CSS stylesheets
|
|
1642 * when the URI protocol for the nsInputStreamChannel
|
|
1643 * is about:blank. The fix is to specify the file protocol.
|
|
1644 */
|
|
1645 //byte[] aString = MozillaDelegate.wcsToMbcs (null, URI_FROMMEMORY, false);
|
|
1646 scope auto aSpec = new nsEmbedCString(URI_FROMMEMORY);
|
|
1647 nsIURI uri;
|
|
1648 rc = ioService.NewURI (cast(nsACString*)aSpec, null, null, &uri);
|
|
1649 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1650 if (uri is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
1651 //XPCOM.nsEmbedCString_delete (aSpec);
|
|
1652 ioService.Release ();
|
|
1653
|
|
1654 //nsIURI uri = new nsIURI (result[0]);
|
|
1655 //result[0] = 0;
|
|
1656 nsIInterfaceRequestor interfaceRequestor;
|
|
1657 rc = webBrowser.QueryInterface (&nsIInterfaceRequestor.IID, cast(void**)&interfaceRequestor);
|
|
1658 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1659 if (interfaceRequestor is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1660 //nsIInterfaceRequestor interfaceRequestor = new nsIInterfaceRequestor (result[0]);
|
|
1661 //result[0] = 0;
|
|
1662
|
|
1663 /*
|
|
1664 * Feature in Mozilla. LoadStream invokes the nsIInputStream argument
|
|
1665 * through a different thread. The callback mechanism must attach
|
|
1666 * a non java thread to the JVM otherwise the nsIInputStream Read and
|
|
1667 * Close methods never get called.
|
|
1668 */
|
|
1669
|
|
1670 // Using fully qualified name for disambiguation with java.io.InputStream -JJR
|
|
1671 auto inputStream = new org.eclipse.swt.browser.InputStream.InputStream (cast(byte[])html);
|
|
1672 inputStream.AddRef ();
|
|
1673
|
|
1674 nsIDocShell_1_9 docShell_1_9;
|
|
1675 rc = interfaceRequestor.GetInterface (&nsIDocShell_1_9.IID, cast(void**)&docShell_1_9);
|
|
1676 if (rc is XPCOM.NS_OK) {
|
|
1677 if (docShell_1_9 is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1678 //nsIDocShell_1_9 docShell = new nsIDocShell_1_9 (result[0]);
|
|
1679 rc = docShell_1_9.LoadStream (inputStream, uri, cast(nsACString*)aContentType, cast(nsACString*)aContentCharset, null);
|
|
1680 docShell_1_9.Release ();
|
|
1681 } else {
|
|
1682 //result[0] = 0;
|
|
1683 nsIDocShell_1_8 docShell_1_8;
|
|
1684 rc = interfaceRequestor.GetInterface (&nsIDocShell_1_8.IID, cast(void**)&docShell_1_8);
|
|
1685 if (rc is XPCOM.NS_OK) {
|
|
1686 if (docShell_1_8 is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1687 //nsIDocShell_1_8 docShell = new nsIDocShell_1_8 (result[0]);
|
|
1688 rc = docShell_1_8.LoadStream (inputStream, uri, cast(nsACString*)aContentType, cast(nsACString*)aContentCharset, null);
|
|
1689 docShell_1_8.Release ();
|
|
1690 } else {
|
|
1691 //result[0] = 0;
|
|
1692 nsIDocShell docShell;
|
|
1693 rc = interfaceRequestor.GetInterface (&nsIDocShell.IID, cast(void**)&docShell);
|
|
1694 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1695 if (docShell is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1696 //nsIDocShell docShell = new nsIDocShell (result[0]);
|
|
1697 rc = docShell.LoadStream (inputStream, uri, cast(nsACString*) aContentType, cast(nsACString*)aContentCharset, null);
|
|
1698 docShell.Release ();
|
|
1699 }
|
|
1700 }
|
|
1701 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1702 //result[0] = 0;
|
|
1703
|
|
1704 inputStream.Release ();
|
|
1705 interfaceRequestor.Release ();
|
|
1706 uri.Release ();
|
|
1707 //XPCOM.nsEmbedCString_delete (aContentCharset);
|
|
1708 //XPCOM.nsEmbedCString_delete (aContentType);
|
|
1709 return true;
|
|
1710 }
|
|
1711
|
|
1712 extern(D)
|
|
1713 public bool setUrl (String url) {
|
|
1714 awaitingNavigate = false;
|
|
1715
|
|
1716 nsIWebNavigation webNavigation;
|
|
1717 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1718 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1719 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1720
|
|
1721 rc = webNavigation.LoadURI (url.toWCharArray().toString16z(), nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
|
|
1722 webNavigation.Release ();
|
|
1723 return rc is XPCOM.NS_OK;
|
|
1724 }
|
|
1725
|
|
1726 extern(D)
|
|
1727 public void stop () {
|
|
1728 if (awaitingNavigate) return;
|
|
1729
|
|
1730 nsIWebNavigation webNavigation;
|
|
1731 //int /*long*/[] result = new int /*long*/[1];
|
|
1732 int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation);
|
|
1733 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1734 if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1735
|
|
1736 //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]);
|
|
1737 rc = webNavigation.Stop (nsIWebNavigation.STOP_ALL);
|
|
1738 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1739 webNavigation.Release ();
|
|
1740 }
|
|
1741
|
|
1742 extern(D)
|
|
1743 void hookDOMListeners (nsIDOMEventTarget target, bool isTop) {
|
|
1744 scope auto string = new nsEmbedString (XPCOM.DOMEVENT_FOCUS.toWCharArray());
|
|
1745 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1746 //string.dispose ();
|
|
1747 string = new nsEmbedString (XPCOM.DOMEVENT_UNLOAD.toWCharArray());
|
|
1748 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1749 //string.dispose ();
|
|
1750 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEDOWN.toWCharArray());
|
|
1751 target.AddEventListener (cast(nsAString*)string,cast(nsIDOMEventListener)this, 0);
|
|
1752 //string.dispose ();
|
|
1753 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEUP.toWCharArray());
|
|
1754 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1755 //string.dispose ();
|
|
1756 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEMOVE.toWCharArray());
|
|
1757 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1758 //string.dispose ();
|
|
1759 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEWHEEL.toWCharArray());
|
|
1760 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1761 //string.dispose ();
|
|
1762 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEDRAG.toWCharArray());
|
|
1763 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1764 //string.dispose ();
|
|
1765
|
|
1766 /*
|
|
1767 * Only hook mouseover and mouseout if the target is a top-level frame, so that mouse moves
|
|
1768 * between frames will not generate events.
|
|
1769 */
|
|
1770 if (isTop && mozDelegate.hookEnterExit ()) {
|
|
1771 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEOVER.toWCharArray());
|
|
1772 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1773 //string.dispose ();
|
|
1774 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEOUT.toWCharArray());
|
|
1775 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1776 //string.dispose ();
|
|
1777 }
|
|
1778
|
|
1779 string = new nsEmbedString (XPCOM.DOMEVENT_KEYDOWN.toWCharArray());
|
|
1780 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1781 //string.dispose ();
|
|
1782 string = new nsEmbedString (XPCOM.DOMEVENT_KEYPRESS.toWCharArray());
|
|
1783 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1784 //string.dispose ();
|
|
1785 string = new nsEmbedString (XPCOM.DOMEVENT_KEYUP.toWCharArray());
|
|
1786 target.AddEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1787 //string.dispose ();
|
|
1788 }
|
|
1789
|
|
1790 extern(D)
|
|
1791 void unhookDOMListeners () {
|
|
1792 //int /*long*/[] result = new int /*long*/[1];
|
|
1793 nsIDOMWindow window;
|
|
1794 int rc = webBrowser.GetContentDOMWindow (&window);
|
|
1795 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1796 if (window is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1797
|
|
1798 //nsIDOMWindow window = new nsIDOMWindow (result[0]);
|
|
1799 //result[0] = 0;
|
|
1800 nsIDOMEventTarget target;
|
|
1801 rc = window.QueryInterface (&nsIDOMEventTarget.IID, cast(void**)&target);
|
|
1802 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1803 if (target is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1804
|
|
1805 //nsIDOMEventTarget target = new nsIDOMEventTarget (result[0]);
|
|
1806 //result[0] = 0;
|
|
1807 unhookDOMListeners (target);
|
|
1808 target.Release ();
|
|
1809
|
|
1810 /* Listeners must be unhooked in pages contained in frames */
|
|
1811 nsIDOMWindowCollection frames;
|
|
1812 rc = window.GetFrames (&frames);
|
|
1813 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1814 if (frames is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1815 //nsIDOMWindowCollection frames = new nsIDOMWindowCollection (result[0]);
|
|
1816 //result[0] = 0;
|
|
1817 PRUint32 count;
|
|
1818 rc = frames.GetLength (&count); /* PRUint32 */
|
|
1819 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1820 //int count = frameCount[0];
|
|
1821
|
|
1822 if (count > 0) {
|
|
1823 nsIDOMWindow frame;
|
|
1824 for (int i = 0; i < count; i++) {
|
|
1825 rc = frames.Item (i, &frame);
|
|
1826 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1827 if (frame is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1828
|
|
1829 //nsIDOMWindow frame = new nsIDOMWindow (result[0]);
|
|
1830 //result[0] = 0;
|
|
1831 rc = frame.QueryInterface (&nsIDOMEventTarget.IID, cast(void**)&target);
|
|
1832 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1833 if (target is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1834
|
|
1835 //target = new nsIDOMEventTarget (result[0]);
|
|
1836 //result[0] = 0;
|
|
1837 unhookDOMListeners (target);
|
|
1838 target.Release ();
|
|
1839 frame.Release ();
|
|
1840 }
|
|
1841 }
|
|
1842 frames.Release ();
|
|
1843 window.Release ();
|
|
1844 }
|
|
1845
|
|
1846 extern(D)
|
|
1847 void unhookDOMListeners (nsIDOMEventTarget target) {
|
|
1848 scope auto string = new nsEmbedString (XPCOM.DOMEVENT_FOCUS.toWCharArray());
|
|
1849 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1850 //string.dispose ();
|
|
1851 string = new nsEmbedString (XPCOM.DOMEVENT_UNLOAD.toWCharArray());
|
|
1852 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1853 //string.dispose ();
|
|
1854 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEDOWN.toWCharArray());
|
|
1855 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1856 //string.dispose ();
|
|
1857 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEUP.toWCharArray());
|
|
1858 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1859 //string.dispose ();
|
|
1860 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEMOVE.toWCharArray());
|
|
1861 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1862 //string.dispose ();
|
|
1863 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEWHEEL.toWCharArray());
|
|
1864 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1865 //string.dispose ();
|
|
1866 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEDRAG.toWCharArray());
|
|
1867 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1868 //string.dispose ();
|
|
1869 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEOVER.toWCharArray());
|
|
1870 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1871 //string.dispose ();
|
|
1872 string = new nsEmbedString (XPCOM.DOMEVENT_MOUSEOUT.toWCharArray());
|
|
1873 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1874 //string.dispose ();
|
|
1875 string = new nsEmbedString (XPCOM.DOMEVENT_KEYDOWN.toWCharArray());
|
|
1876 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1877 //string.dispose ();
|
|
1878 string = new nsEmbedString (XPCOM.DOMEVENT_KEYPRESS.toWCharArray());
|
|
1879 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1880 //string.dispose ();
|
|
1881 string = new nsEmbedString (XPCOM.DOMEVENT_KEYUP.toWCharArray());
|
|
1882 target.RemoveEventListener (cast(nsAString*)string, cast(nsIDOMEventListener)this, 0);
|
|
1883 //string.dispose ();
|
|
1884 }
|
|
1885
|
|
1886 /* nsISupports */
|
|
1887
|
|
1888 extern(System)
|
|
1889 nsresult QueryInterface (nsID* riid, void** ppvObject) {
|
|
1890 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
|
|
1891
|
|
1892 if (*riid == nsISupports.IID) {
|
|
1893 *ppvObject = cast(void*)cast(nsISupports)this;
|
|
1894 AddRef ();
|
|
1895 return XPCOM.NS_OK;
|
|
1896 }
|
|
1897 if (*riid == nsIWeakReference.IID) {
|
|
1898 *ppvObject = cast(void*)cast(nsIWeakReference)this;
|
|
1899 AddRef ();
|
|
1900 return XPCOM.NS_OK;
|
|
1901 }
|
|
1902 if (*riid == nsIWebProgressListener.IID) {
|
|
1903 *ppvObject = cast(void*)cast(nsIWebProgressListener)this;
|
|
1904 AddRef ();
|
|
1905 return XPCOM.NS_OK;
|
|
1906 }
|
|
1907 if (*riid == nsIWebBrowserChrome.IID) {
|
|
1908 *ppvObject = cast(void*)cast(nsIWebBrowserChrome)this;
|
|
1909 AddRef ();
|
|
1910 return XPCOM.NS_OK;
|
|
1911 }
|
|
1912 if (*riid == nsIWebBrowserChromeFocus.IID) {
|
|
1913 *ppvObject = cast(void*)cast(nsIWebBrowserChromeFocus)this;
|
|
1914 AddRef ();
|
|
1915 return XPCOM.NS_OK;
|
|
1916 }
|
|
1917 if (*riid == nsIEmbeddingSiteWindow.IID) {
|
|
1918 *ppvObject = cast(void*)cast(nsIEmbeddingSiteWindow)this;
|
|
1919 AddRef ();
|
|
1920 return XPCOM.NS_OK;
|
|
1921 }
|
|
1922 if (*riid == nsIInterfaceRequestor.IID) {
|
|
1923 *ppvObject = cast(void*)cast(nsIInterfaceRequestor)this;
|
|
1924 AddRef ();
|
|
1925 return XPCOM.NS_OK;
|
|
1926 }
|
|
1927 if (*riid == nsISupportsWeakReference.IID) {
|
|
1928 *ppvObject = cast(void*)cast(nsISupportsWeakReference)this;
|
|
1929 AddRef ();
|
|
1930 return XPCOM.NS_OK;
|
|
1931 }
|
|
1932 if (*riid == nsIContextMenuListener.IID) {
|
|
1933 *ppvObject = cast(void*)cast(nsIContextMenuListener)this;
|
|
1934 AddRef ();
|
|
1935 return XPCOM.NS_OK;
|
|
1936 }
|
|
1937 if (*riid == nsIURIContentListener.IID) {
|
|
1938 *ppvObject = cast(void*)cast(nsIURIContentListener)this;
|
|
1939 AddRef ();
|
|
1940 return XPCOM.NS_OK;
|
|
1941 }
|
|
1942 if (*riid == nsITooltipListener.IID) {
|
|
1943 *ppvObject = cast(void*)cast(nsITooltipListener)this;
|
|
1944 AddRef ();
|
|
1945 return XPCOM.NS_OK;
|
|
1946 }
|
|
1947 *ppvObject = null;
|
|
1948 return XPCOM.NS_ERROR_NO_INTERFACE;
|
|
1949 }
|
|
1950
|
|
1951 extern(System)
|
|
1952 nsrefcnt AddRef () {
|
|
1953 refCount++;
|
|
1954 return refCount;
|
|
1955 }
|
|
1956
|
|
1957 extern(System)
|
|
1958 nsrefcnt Release () {
|
|
1959 refCount--;
|
|
1960 if (refCount is 0) return 0;
|
|
1961 return refCount;
|
|
1962 }
|
|
1963
|
|
1964 /* nsIWeakReference */
|
|
1965
|
|
1966 extern(System)
|
|
1967 nsresult QueryReferent (nsID* riid, void** ppvObject) {
|
|
1968 return QueryInterface (riid, ppvObject);
|
|
1969 }
|
|
1970
|
|
1971 /* nsIInterfaceRequestor */
|
|
1972
|
|
1973 extern(System)
|
|
1974 nsresult GetInterface ( nsID* riid, void** ppvObject) {
|
|
1975 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
|
|
1976 //nsID guid = new nsID ();
|
|
1977 //XPCOM.memmove (guid, riid, nsID.sizeof);
|
|
1978 if (*riid == nsIDOMWindow.IID) {
|
|
1979 nsIDOMWindow aContentDOMWindow;
|
|
1980 //int /*long*/[] aContentDOMWindow = new int /*long*/[1];
|
|
1981 int rc = webBrowser.GetContentDOMWindow (&aContentDOMWindow);
|
|
1982 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
1983 if (aContentDOMWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
1984 *ppvObject = cast(void*)aContentDOMWindow;
|
|
1985 //XPCOM.memmove (ppvObject, aContentDOMWindow, C.PTR_SIZEOF);
|
|
1986 return rc;
|
|
1987 }
|
|
1988 return QueryInterface (riid, ppvObject);
|
|
1989 }
|
|
1990
|
|
1991 extern(System)
|
|
1992 nsresult GetWeakReference (nsIWeakReference* ppvObject) {
|
|
1993 *ppvObject = cast(nsIWeakReference)this;
|
|
1994 //XPCOM.memmove (ppvObject, new int /*long*/[] {weakReference.getAddress ()}, C.PTR_SIZEOF);
|
|
1995 AddRef ();
|
|
1996 return XPCOM.NS_OK;
|
|
1997 }
|
|
1998
|
|
1999 /* nsIWebProgressListener */
|
|
2000
|
|
2001 extern(System)
|
|
2002 nsresult OnStateChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUint32 aStateFlags, nsresult aStatus) {
|
|
2003 if ((aStateFlags & nsIWebProgressListener.STATE_IS_DOCUMENT) is 0) return XPCOM.NS_OK;
|
|
2004 if ((aStateFlags & nsIWebProgressListener.STATE_START) !is 0) {
|
|
2005 if (request is null) request = aRequest;
|
|
2006
|
|
2007 if (!awaitingNavigate) {
|
|
2008 /*
|
|
2009 * Add the page's nsIDOMWindow to the collection of windows that will
|
|
2010 * have DOM listeners added to them later on in the page loading
|
|
2011 * process. These listeners cannot be added yet because the
|
|
2012 * nsIDOMWindow is not ready to take them at this stage.
|
|
2013 */
|
|
2014 //int /*long*/[] result = new int /*long*/[1];
|
|
2015 nsIDOMWindow window;
|
|
2016 //nsIWebProgress progress = new nsIWebProgress (aWebProgress);
|
|
2017 int rc = aWebProgress.GetDOMWindow (&window);
|
|
2018 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2019 if (window is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2020 unhookedDOMWindows ~= window;
|
|
2021 }
|
|
2022 } else if ((aStateFlags & nsIWebProgressListener.STATE_REDIRECTING) !is 0) {
|
|
2023 if (request is aRequest) request = null;
|
|
2024 } else if ((aStateFlags & nsIWebProgressListener.STATE_STOP) !is 0) {
|
|
2025 /*
|
|
2026 * If this page's nsIDOMWindow handle is still in unhookedDOMWindows then
|
|
2027 * add its DOM listeners now. It's possible for this to happen since
|
|
2028 * there is no guarantee that a STATE_TRANSFERRING state change will be
|
|
2029 * received for every window in a page, which is when these listeners
|
|
2030 * are typically added.
|
|
2031 */
|
|
2032 //int /*long*/[] result = new int /*long*/[1];
|
|
2033 //nsIWebProgress progress = new nsIWebProgress (aWebProgress);
|
|
2034 nsIDOMWindow domWindow;
|
|
2035 int rc = aWebProgress.GetDOMWindow (&domWindow);
|
|
2036 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2037 if (domWindow is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2038 //nsIDOMWindow domWindow = new nsIDOMWindow (result[0]);
|
|
2039
|
|
2040 //LONG ptrObject = new LONG (result[0]);
|
|
2041 //result[0] = 0;
|
|
2042 int index = unhookedDOMWindows.arrayIndexOf (domWindow);
|
|
2043 if (index !is -1) {
|
|
2044 nsIDOMWindow contentWindow;
|
|
2045 rc = webBrowser.GetContentDOMWindow (&contentWindow);
|
|
2046 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2047 if (contentWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
2048 bool isTop = contentWindow is domWindow;
|
|
2049 contentWindow.Release ();
|
|
2050 //result[0] = 0;
|
|
2051 nsIDOMEventTarget target;
|
|
2052 rc = domWindow.QueryInterface (&nsIDOMEventTarget.IID, cast(void**)&target);
|
|
2053 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2054 if (target is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
2055
|
|
2056 //nsIDOMEventTarget target = new nsIDOMEventTarget (result[0]);
|
|
2057 //result[0] = 0;
|
|
2058 hookDOMListeners (target, isTop);
|
|
2059 target.Release ();
|
|
2060
|
|
2061 /*
|
|
2062 * Remove and unreference the nsIDOMWindow from the collection of windows
|
|
2063 * that are waiting to have DOM listeners hooked on them.
|
|
2064 */
|
|
2065 unhookedDOMWindows = unhookedDOMWindows.arrayIndexRemove (index);
|
|
2066 domWindow.Release ();
|
|
2067 }
|
|
2068 domWindow.Release ();
|
|
2069
|
|
2070 /*
|
|
2071 * Feature in Mozilla. When a request is redirected (STATE_REDIRECTING),
|
|
2072 * it never reaches the state STATE_STOP and it is replaced with a new request.
|
|
2073 * The new request is received when it is in the state STATE_STOP.
|
|
2074 * To handle this case, the variable request is set to 0 when the corresponding
|
|
2075 * request is redirected. The following request received with the state STATE_STOP
|
|
2076 * - the new request resulting from the redirection - is used to send
|
|
2077 * the ProgressListener.completed event.
|
|
2078 */
|
|
2079 if (request is aRequest || request is null) {
|
|
2080 request = null;
|
|
2081 if (!awaitingNavigate) {
|
|
2082 StatusTextEvent event = new StatusTextEvent (browser);
|
|
2083 event.display = browser.getDisplay ();
|
|
2084 event.widget = browser;
|
|
2085 event.text = ""; //$NON-NLS-1$
|
|
2086 for (int i = 0; i < statusTextListeners.length; i++) {
|
|
2087 statusTextListeners[i].changed (event);
|
|
2088 }
|
|
2089 ProgressEvent event2 = new ProgressEvent (browser);
|
|
2090 event2.display = browser.getDisplay ();
|
|
2091 event2.widget = browser;
|
|
2092 for (int i = 0; i < progressListeners.length; i++) {
|
|
2093 progressListeners[i].completed (event2);
|
|
2094 }
|
|
2095 }
|
|
2096 }
|
|
2097 } else if ((aStateFlags & nsIWebProgressListener.STATE_TRANSFERRING) !is 0) {
|
|
2098 /*
|
|
2099 * Hook DOM listeners to the page's nsIDOMWindow here because this is
|
|
2100 * the earliest opportunity to do so.
|
|
2101 */
|
|
2102 //int /*long*/[] result = new int /*long*/[1];
|
|
2103 // nsIWebProgress progress = new nsIWebProgress (aWebProgress);
|
|
2104 nsIDOMWindow domWindow;
|
|
2105 int rc = aWebProgress.GetDOMWindow (&domWindow);
|
|
2106 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2107 if (domWindow is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2108 //nsIDOMWindow domWindow = new nsIDOMWindow (result[0]);
|
|
2109
|
|
2110 //LONG ptrObject = new LONG (result[0]);
|
|
2111 //result[0] = 0;
|
|
2112 int index = unhookedDOMWindows.arrayIndexOf ( domWindow);
|
|
2113 if (index !is -1) {
|
|
2114 nsIDOMWindow contentWindow;
|
|
2115 rc = webBrowser.GetContentDOMWindow (&contentWindow);
|
|
2116 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2117 if (contentWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
2118 bool isTop = contentWindow is domWindow;
|
|
2119 contentWindow.Release ();
|
|
2120 //result[0] = 0;
|
|
2121 nsIDOMEventTarget target;
|
|
2122 rc = domWindow.QueryInterface (&nsIDOMEventTarget.IID, cast(void**)&target);
|
|
2123 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2124 if (target is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
2125
|
|
2126 //nsIDOMEventTarget target = new nsIDOMEventTarget (result[0]);
|
|
2127 //result[0] = 0;
|
|
2128 hookDOMListeners (target, isTop);
|
|
2129 target.Release ();
|
|
2130
|
|
2131 /*
|
|
2132 * Remove and unreference the nsIDOMWindow from the collection of windows
|
|
2133 * that are waiting to have DOM listeners hooked on them.
|
|
2134 */
|
|
2135 unhookedDOMWindows = unhookedDOMWindows.arrayIndexRemove(index);
|
|
2136 domWindow.Release ();
|
|
2137 }
|
|
2138 domWindow.Release ();
|
|
2139 }
|
|
2140 return XPCOM.NS_OK;
|
|
2141 }
|
|
2142
|
|
2143 extern(System)
|
|
2144 nsresult OnProgressChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) {
|
|
2145 if (awaitingNavigate || super.progressListeners.length is 0) return XPCOM.NS_OK;
|
|
2146 ProgressEvent event = new ProgressEvent (browser);
|
|
2147 event.display = browser.getDisplay ();
|
|
2148 event.widget = browser;
|
|
2149 event.current = aCurTotalProgress;
|
|
2150 event.total = aMaxTotalProgress;
|
|
2151 for (int i = 0; i < super.progressListeners.length; i++) {
|
|
2152 super.progressListeners[i].changed (event);
|
|
2153 }
|
|
2154 return XPCOM.NS_OK;
|
|
2155 }
|
|
2156
|
|
2157 extern(System)
|
|
2158 nsresult OnLocationChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsIURI aLocation) {
|
|
2159 /*
|
|
2160 * Feature in Mozilla. When a page is loaded via setText before a previous
|
|
2161 * setText page load has completed, the expected OnStateChange STATE_STOP for the
|
|
2162 * original setText never arrives because it gets replaced by the OnStateChange
|
|
2163 * STATE_STOP for the new request. This results in the request field never being
|
|
2164 * cleared because the original request's OnStateChange STATE_STOP is still expected
|
|
2165 * (but never arrives). To handle this case, the request field is updated to the new
|
|
2166 * overriding request since its OnStateChange STATE_STOP will be received next.
|
|
2167 */
|
|
2168 if (request !is null && request !is aRequest) request = aRequest;
|
|
2169
|
|
2170 if (awaitingNavigate || locationListeners.length is 0) return XPCOM.NS_OK;
|
|
2171
|
|
2172 //nsIWebProgress webProgress = new nsIWebProgress (aWebProgress);
|
|
2173
|
|
2174 nsIDOMWindow domWindow;
|
|
2175 //int /*long*/[] aDOMWindow = new int /*long*/[1];
|
|
2176 int rc = aWebProgress.GetDOMWindow (&domWindow);
|
|
2177 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2178 if (domWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
2179
|
|
2180 //nsIDOMWindow domWindow = new nsIDOMWindow (aDOMWindow[0]);
|
|
2181 //int /*long*/[] aTop = new int /*long*/[1];
|
|
2182 nsIDOMWindow topWindow;
|
|
2183 rc = domWindow.GetTop (&topWindow);
|
|
2184 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2185 if (topWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
2186 domWindow.Release ();
|
|
2187
|
|
2188 //nsIDOMWindow topWindow = new nsIDOMWindow (aTop[0]);
|
|
2189 topWindow.Release ();
|
|
2190
|
|
2191 //nsIURI location = new nsIURI (aLocation);
|
|
2192 scope auto aSpec = new nsEmbedCString;
|
|
2193 aLocation.GetSpec (cast(nsACString*)aSpec);
|
|
2194 //int length = XPCOM.nsEmbedCString_Length (aSpec);
|
|
2195 //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
|
|
2196 //byte[] dest = new byte[length];
|
|
2197 //XPCOM.memmove (dest, buffer, length);
|
|
2198 //XPCOM.nsEmbedCString_delete (aSpec);
|
|
2199 String url = aSpec.toString;
|
|
2200
|
|
2201 /*
|
|
2202 * As of Mozilla 1.8, the first time that a page is displayed, regardless of
|
|
2203 * whether it's via Browser.setURL() or Browser.setText(), the GRE navigates
|
|
2204 * to about:blank and fires the corresponding navigation events. Do not send
|
|
2205 * this event on to the user since it is not expected.
|
|
2206 */
|
|
2207 if (!IsPre_1_8 && aRequest is null && url.startsWith (ABOUT_BLANK)) return XPCOM.NS_OK;
|
|
2208
|
|
2209 LocationEvent event = new LocationEvent (browser);
|
|
2210 event.display = browser.getDisplay ();
|
|
2211 event.widget = browser;
|
|
2212 event.location = url;
|
|
2213 /*
|
|
2214 * If the URI indicates that the page is being rendered from memory
|
|
2215 * (via setText()) then set it to about:blank to be consistent with IE.
|
|
2216 */
|
|
2217 if (event.location.equals (URI_FROMMEMORY)) event.location = ABOUT_BLANK;
|
|
2218 event.top = topWindow is domWindow;
|
|
2219 for (int i = 0; i < locationListeners.length; i++) {
|
|
2220 locationListeners[i].changed (event);
|
|
2221 }
|
|
2222 return XPCOM.NS_OK;
|
|
2223 }
|
|
2224
|
|
2225 extern(System)
|
|
2226 nsresult OnStatusChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsresult aStatus, PRUnichar* aMessage) {
|
|
2227 if (awaitingNavigate || statusTextListeners.length is 0) return XPCOM.NS_OK;
|
|
2228 StatusTextEvent event = new StatusTextEvent (browser);
|
|
2229 event.display = browser.getDisplay ();
|
|
2230 event.widget = browser;
|
|
2231 //int length = XPCOM.strlen_PRUnichar (aMessage);
|
|
2232 //char[] dest = new char[length];
|
|
2233 //XPCOM.memmove (dest, aMessage, length * 2);
|
|
2234 event.text = Utf.toString(fromString16z(aMessage));
|
|
2235 for (int i = 0; i < statusTextListeners.length; i++) {
|
|
2236 statusTextListeners[i].changed (event);
|
|
2237 }
|
|
2238 return XPCOM.NS_OK;
|
|
2239 }
|
|
2240
|
|
2241 extern(System)
|
|
2242 nsresult OnSecurityChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUint32 state) {
|
|
2243 return XPCOM.NS_OK;
|
|
2244 }
|
|
2245
|
|
2246 /* nsIWebBrowserChrome */
|
|
2247
|
|
2248 extern(System)
|
|
2249 nsresult SetStatus (PRUint32 statusType, PRUnichar* status) {
|
|
2250 if (awaitingNavigate || statusTextListeners.length is 0) return XPCOM.NS_OK;
|
|
2251 StatusTextEvent event = new StatusTextEvent (browser);
|
|
2252 event.display = browser.getDisplay ();
|
|
2253 event.widget = browser;
|
|
2254 //int length = XPCOM.strlen_PRUnichar (status);
|
|
2255 //char[] dest = new char[length];
|
|
2256 //XPCOM.memmove (dest, status, length * 2);
|
|
2257 //String string = new String (dest);
|
|
2258 event.text = Utf.toString(fromString16z(status));
|
|
2259 for (int i = 0; i < statusTextListeners.length; i++) {
|
|
2260 statusTextListeners[i].changed (event);
|
|
2261 }
|
|
2262 return XPCOM.NS_OK;
|
|
2263 }
|
|
2264
|
|
2265 extern(System)
|
|
2266 nsresult GetWebBrowser (nsIWebBrowser* aWebBrowser) {
|
|
2267 //int /*long*/[] ret = new int /*long*/[1];
|
|
2268 if (webBrowser !is null) {
|
|
2269 webBrowser.AddRef ();
|
|
2270 *aWebBrowser = webBrowser;
|
|
2271 }
|
|
2272 //XPCOM.memmove (aWebBrowser, ret, C.PTR_SIZEOF);
|
|
2273 return XPCOM.NS_OK;
|
|
2274 }
|
|
2275
|
|
2276 extern(System)
|
|
2277 nsresult SetWebBrowser (nsIWebBrowser aWebBrowser) {
|
|
2278 if (webBrowser !is null) webBrowser.Release ();
|
|
2279 webBrowser = aWebBrowser !is null ? cast(nsIWebBrowser)cast(void*)aWebBrowser : null;
|
|
2280 return XPCOM.NS_OK;
|
|
2281 }
|
|
2282
|
|
2283 extern(System)
|
|
2284 nsresult GetChromeFlags (PRUint32* aChromeFlags) {
|
|
2285 //int[] ret = new int[1];
|
|
2286 *aChromeFlags = chromeFlags;
|
|
2287 //XPCOM.memmove (aChromeFlags, ret, 4); /* PRUint32 */
|
|
2288 return XPCOM.NS_OK;
|
|
2289 }
|
|
2290
|
|
2291 extern(System)
|
|
2292 nsresult SetChromeFlags (PRUint32 aChromeFlags) {
|
|
2293 chromeFlags = aChromeFlags;
|
|
2294 return XPCOM.NS_OK;
|
|
2295 }
|
|
2296
|
|
2297 extern(System)
|
|
2298 nsresult DestroyBrowserWindow () {
|
|
2299 WindowEvent newEvent = new WindowEvent (browser);
|
|
2300 newEvent.display = browser.getDisplay ();
|
|
2301 newEvent.widget = browser;
|
|
2302 for (int i = 0; i < closeWindowListeners.length; i++) {
|
|
2303 closeWindowListeners[i].close (newEvent);
|
|
2304 }
|
|
2305 /*
|
|
2306 * Note on Mozilla. The DestroyBrowserWindow notification cannot be cancelled.
|
|
2307 * The browser widget cannot be used after this notification has been received.
|
|
2308 * The application is advised to close the window hosting the browser widget.
|
|
2309 * The browser widget must be disposed in all cases.
|
|
2310 */
|
|
2311 browser.dispose ();
|
|
2312 return XPCOM.NS_OK;
|
|
2313 }
|
|
2314
|
|
2315 extern(System)
|
|
2316 nsresult SizeBrowserTo (PRInt32 aCX, PRInt32 aCY) {
|
|
2317 size = new Point (aCX, aCY);
|
|
2318 bool isChrome = (chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) !is 0;
|
|
2319 if (isChrome) {
|
|
2320 Shell shell = browser.getShell ();
|
|
2321 shell.setSize (shell.computeSize (size.x, size.y));
|
|
2322 }
|
|
2323 return XPCOM.NS_OK;
|
|
2324 }
|
|
2325
|
|
2326 extern(System)
|
|
2327 nsresult ShowAsModal () {
|
|
2328 //int /*long*/[] result = new int /*long*/[1];
|
|
2329 nsIServiceManager serviceManager;
|
|
2330 int rc = XPCOM.NS_GetServiceManager (&serviceManager);
|
|
2331 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2332 if (serviceManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2333
|
|
2334 //nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
|
|
2335 //result[0] = 0;
|
|
2336 //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_CONTEXTSTACK_CONTRACTID, true);
|
|
2337 nsIJSContextStack stack;
|
|
2338 rc = serviceManager.GetServiceByContractID (XPCOM.NS_CONTEXTSTACK_CONTRACTID.ptr, &nsIJSContextStack.IID, cast(void**)&stack);
|
|
2339 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2340 if (stack is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2341 serviceManager.Release ();
|
|
2342
|
|
2343 //nsIJSContextStack stack = new nsIJSContextStack (result[0]);
|
|
2344 //result[0] = 0;
|
|
2345 rc = stack.Push (null);
|
|
2346 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2347
|
|
2348 Shell shell = browser.getShell ();
|
|
2349 Display display = browser.getDisplay ();
|
|
2350 while (!shell.isDisposed ()) {
|
|
2351 if (!display.readAndDispatch ()) display.sleep ();
|
|
2352 }
|
|
2353 JSContext* result;
|
|
2354 rc = stack.Pop (&result);
|
|
2355 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2356 stack.Release ();
|
|
2357 return XPCOM.NS_OK;
|
|
2358 }
|
|
2359
|
|
2360 extern(System)
|
|
2361 nsresult IsWindowModal (PRBool* retval) {
|
|
2362 *retval = (chromeFlags & nsIWebBrowserChrome.CHROME_MODAL) !is 0 ? 1 : 0;
|
|
2363 //XPCOM.memmove (retval, new int[] {result}, 4); /* PRBool */
|
|
2364 return XPCOM.NS_OK;
|
|
2365 }
|
|
2366
|
|
2367 extern(System)
|
|
2368 nsresult ExitModalEventLoop (nsresult aStatus) {
|
|
2369 return XPCOM.NS_OK;
|
|
2370 }
|
|
2371
|
|
2372 /* nsIEmbeddingSiteWindow */
|
|
2373
|
|
2374 extern(System)
|
|
2375 nsresult SetDimensions (PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy) {
|
|
2376 if ((flags & nsIEmbeddingSiteWindow.DIM_FLAGS_POSITION) !is 0) {
|
|
2377 location = new Point (x, y);
|
|
2378 browser.getShell ().setLocation (x, y);
|
|
2379 }
|
|
2380 if ((flags & nsIEmbeddingSiteWindow.DIM_FLAGS_SIZE_INNER) !is 0) {
|
|
2381 browser.setSize (cx, cy);
|
|
2382 }
|
|
2383 if ((flags & nsIEmbeddingSiteWindow.DIM_FLAGS_SIZE_OUTER) !is 0) {
|
|
2384 browser.getShell ().setSize (cx, cy);
|
|
2385 }
|
|
2386 return XPCOM.NS_OK;
|
|
2387 }
|
|
2388
|
|
2389 extern(System)
|
|
2390 nsresult GetDimensions (PRUint32 flags, PRInt32* x, PRInt32* y, PRInt32* cx, PRInt32* cy) {
|
|
2391 if ((flags & nsIEmbeddingSiteWindow.DIM_FLAGS_POSITION) !is 0) {
|
|
2392 Point location = browser.getShell ().getLocation ();
|
|
2393 if (x !is null) *x = location.x; /* PRInt32 */
|
|
2394 if (y !is null) *y = location.y; /* PRInt32 */
|
|
2395 }
|
|
2396 if ((flags & nsIEmbeddingSiteWindow.DIM_FLAGS_SIZE_INNER) !is 0) {
|
|
2397 Point size = browser.getSize ();
|
|
2398 if (cx !is null) *cx = size.x; /* PRInt32 */
|
|
2399 if (cy !is null) *cy = size.y; /* PRInt32 */
|
|
2400 }
|
|
2401 if ((flags & nsIEmbeddingSiteWindow.DIM_FLAGS_SIZE_OUTER) !is 0) {
|
|
2402 Point size = browser.getShell().getSize ();
|
|
2403 if (cx !is null) *cx = size.x; /* PRInt32 */
|
|
2404 if (cy !is null) *cy = size.y; /* PRInt32 */
|
|
2405 }
|
|
2406 return XPCOM.NS_OK;
|
|
2407 }
|
|
2408
|
|
2409 extern(System)
|
|
2410 nsresult SetFocus () {
|
|
2411 //int /*long*/[] result = new int /*long*/[1];
|
|
2412 nsIBaseWindow baseWindow;
|
|
2413 int rc = webBrowser.QueryInterface (&nsIBaseWindow.IID, cast(void**)&baseWindow);
|
|
2414 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2415 if (baseWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
|
|
2416
|
|
2417 //nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]);
|
|
2418 rc = baseWindow.SetFocus ();
|
|
2419 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2420 baseWindow.Release ();
|
|
2421
|
|
2422 /*
|
|
2423 * Note. Mozilla notifies here that one of the children took
|
|
2424 * focus. This could or should be used to fire an SWT.FOCUS_IN
|
|
2425 * event on Browser focus listeners.
|
|
2426 */
|
|
2427 return XPCOM.NS_OK;
|
|
2428 }
|
|
2429
|
|
2430 extern(System)
|
|
2431 nsresult GetVisibility (PRBool* aVisibility) {
|
|
2432 bool visible = browser.isVisible () && !browser.getShell ().getMinimized ();
|
|
2433 *aVisibility = visible ? 1 : 0;
|
|
2434 //XPCOM.memmove (aVisibility, new int[] {visible ? 1 : 0}, 4); /* PRBool */
|
|
2435 return XPCOM.NS_OK;
|
|
2436 }
|
|
2437
|
|
2438 extern(System)
|
|
2439 nsresult SetVisibility (PRBool aVisibility) {
|
|
2440 if (isChild) {
|
|
2441 WindowEvent event = new WindowEvent (browser);
|
|
2442 event.display = browser.getDisplay ();
|
|
2443 event.widget = browser;
|
|
2444 if (aVisibility !is 0) {
|
|
2445 /*
|
|
2446 * Bug in Mozilla. When the JavaScript window.open is executed, Mozilla
|
|
2447 * fires multiple SetVisibility 1 notifications. The workaround is
|
|
2448 * to ignore subsequent notifications.
|
|
2449 */
|
|
2450 if (!visible) {
|
|
2451 visible = true;
|
|
2452 event.location = location;
|
|
2453 event.size = size;
|
|
2454 event.addressBar = (chromeFlags & nsIWebBrowserChrome.CHROME_LOCATIONBAR) !is 0;
|
|
2455 event.menuBar = (chromeFlags & nsIWebBrowserChrome.CHROME_MENUBAR) !is 0;
|
|
2456 event.statusBar = (chromeFlags & nsIWebBrowserChrome.CHROME_STATUSBAR) !is 0;
|
|
2457 event.toolBar = (chromeFlags & nsIWebBrowserChrome.CHROME_TOOLBAR) !is 0;
|
|
2458 for (int i = 0; i < visibilityWindowListeners.length; i++) {
|
|
2459 visibilityWindowListeners[i].show (event);
|
|
2460 }
|
|
2461 location = null;
|
|
2462 size = null;
|
|
2463 }
|
|
2464 } else {
|
|
2465 visible = false;
|
|
2466 for (int i = 0; i < visibilityWindowListeners.length; i++) {
|
|
2467 visibilityWindowListeners[i].hide (event);
|
|
2468 }
|
|
2469 }
|
|
2470 } else {
|
|
2471 visible = aVisibility !is 0;
|
|
2472 }
|
|
2473 return XPCOM.NS_OK;
|
|
2474 }
|
|
2475
|
|
2476 extern(System)
|
|
2477 nsresult GetTitle (PRUnichar** aTitle) {
|
|
2478 return XPCOM.NS_OK;
|
|
2479 }
|
|
2480
|
|
2481 extern(System)
|
|
2482 nsresult SetTitle (PRUnichar* aTitle) {
|
|
2483 if (awaitingNavigate || titleListeners.length is 0) return XPCOM.NS_OK;
|
|
2484 TitleEvent event = new TitleEvent (browser);
|
|
2485 event.display = browser.getDisplay ();
|
|
2486 event.widget = browser;
|
|
2487 /*
|
|
2488 * To be consistent with other platforms the title event should
|
|
2489 * contain the page's url if the page does not contain a <title>
|
|
2490 * tag.
|
|
2491 */
|
|
2492 int length = XPCOM.strlen_PRUnichar (aTitle);
|
|
2493 if (length > 0) {
|
|
2494 //char[] dest = new char[length];
|
|
2495 //XPCOM.memmove (dest, aTitle, length * 2);
|
|
2496 event.title = Utf.toString(fromString16z(aTitle));
|
|
2497 } else {
|
|
2498 event.title = getUrl ();
|
|
2499 }
|
|
2500 for (int i = 0; i < titleListeners.length; i++) {
|
|
2501 titleListeners[i].changed (event);
|
|
2502 }
|
|
2503 return XPCOM.NS_OK;
|
|
2504 }
|
|
2505
|
|
2506 extern(System)
|
|
2507 nsresult GetSiteWindow (void** aSiteWindow) {
|
|
2508 /*
|
|
2509 * Note. The handle is expected to be an HWND on Windows and
|
|
2510 * a GtkWidget* on GTK. This callback is invoked on Windows
|
|
2511 * when the javascript window.print is invoked and the print
|
|
2512 * dialog comes up. If no handle is returned, the print dialog
|
|
2513 * does not come up on this platform.
|
|
2514 */
|
|
2515 *aSiteWindow = cast(void*) embedHandle;
|
|
2516 return XPCOM.NS_OK;
|
|
2517 }
|
|
2518
|
|
2519 /* nsIWebBrowserChromeFocus */
|
|
2520
|
|
2521 extern(System)
|
|
2522 nsresult FocusNextElement () {
|
|
2523 /*
|
|
2524 * Bug in Mozilla embedding API. Mozilla takes back the focus after sending
|
|
2525 * this event. This prevents tabbing out of Mozilla. This behaviour can be reproduced
|
|
2526 * with the Mozilla application TestGtkEmbed. The workaround is to
|
|
2527 * send the traversal notification after this callback returns.
|
|
2528 */
|
|
2529 browser.getDisplay ().asyncExec (new class() Runnable {
|
|
2530 public void run () {
|
|
2531 if (browser.isDisposed ()) return;
|
|
2532 browser.traverse (SWT.TRAVERSE_TAB_NEXT);
|
|
2533 }
|
|
2534 });
|
|
2535 return XPCOM.NS_OK;
|
|
2536 }
|
|
2537
|
|
2538 extern(System)
|
|
2539 nsresult FocusPrevElement () {
|
|
2540 /*
|
|
2541 * Bug in Mozilla embedding API. Mozilla takes back the focus after sending
|
|
2542 * this event. This prevents tabbing out of Mozilla. This behaviour can be reproduced
|
|
2543 * with the Mozilla application TestGtkEmbed. The workaround is to
|
|
2544 * send the traversal notification after this callback returns.
|
|
2545 */
|
|
2546 browser.getDisplay ().asyncExec (new class() Runnable {
|
|
2547 public void run () {
|
|
2548 if (browser.isDisposed ()) return;
|
|
2549 browser.traverse (SWT.TRAVERSE_TAB_PREVIOUS);
|
|
2550 }
|
|
2551 });
|
|
2552 return XPCOM.NS_OK;
|
|
2553 }
|
|
2554
|
|
2555 /* nsIContextMenuListener */
|
|
2556
|
|
2557 extern(System)
|
|
2558 nsresult OnShowContextMenu (PRUint32 aContextFlags, nsIDOMEvent aEvent, nsIDOMNode aNode) {
|
|
2559 if (awaitingNavigate) return XPCOM.NS_OK;
|
|
2560
|
|
2561 //nsIDOMEvent domEvent = new nsIDOMEvent (aEvent);
|
|
2562 //int /*long*/[] result = new int /*long*/[1];
|
|
2563 nsIDOMMouseEvent domMouseEvent;
|
|
2564 int rc = aEvent.QueryInterface (&nsIDOMMouseEvent.IID, cast(void**)&domMouseEvent);
|
|
2565 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2566 if (domMouseEvent is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2567
|
|
2568 //nsIDOMMouseEvent domMouseEvent = new nsIDOMMouseEvent (result[0]);
|
|
2569 PRInt32 aScreenX, aScreenY;
|
|
2570 rc = domMouseEvent.GetScreenX (&aScreenX);
|
|
2571 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2572 rc = domMouseEvent.GetScreenY (&aScreenY);
|
|
2573 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2574 domMouseEvent.Release ();
|
|
2575
|
|
2576 auto event = new Event;
|
|
2577 event.x = aScreenX;
|
|
2578 event.y = aScreenY;
|
|
2579 browser.notifyListeners (SWT.MenuDetect, event);
|
|
2580 if (!event.doit) return XPCOM.NS_OK;
|
|
2581 Menu menu = browser.getMenu ();
|
|
2582 if (menu !is null && !menu.isDisposed ()) {
|
|
2583 if (aScreenX !is event.x || aScreenY !is event.y) {
|
|
2584 menu.setLocation (event.x, event.y);
|
|
2585 }
|
|
2586 menu.setVisible (true);
|
|
2587 }
|
|
2588 return XPCOM.NS_OK;
|
|
2589 }
|
|
2590
|
|
2591 /* nsIURIContentListener */
|
|
2592
|
|
2593 extern(System)
|
|
2594 nsresult OnStartURIOpen (nsIURI aURI, PRBool* retval) {
|
|
2595 if (awaitingNavigate || locationListeners.length is 0) {
|
|
2596 *retval = 0;
|
|
2597 //XPCOM.memmove (retval, new int[] {0}, 4); /* PRBool */
|
|
2598 return XPCOM.NS_OK;
|
|
2599 }
|
|
2600 //nsIURI location = new nsIURI (aURI);
|
|
2601 scope auto aSpec = new nsEmbedCString;
|
|
2602 aURI.GetSpec (cast(nsACString*)aSpec);
|
|
2603 //int length = XPCOM.nsEmbedCString_Length (aSpec);
|
|
2604 //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
|
|
2605 //buffer = XPCOM.nsEmbedCString_get (aSpec);
|
|
2606 //byte[] dest = new byte[length];
|
|
2607 //XPCOM.memmove (dest, buffer, length);
|
|
2608 //XPCOM.nsEmbedCString_delete (aSpec);
|
|
2609 String value = aSpec.toString;
|
|
2610 bool doit = true;
|
|
2611 if (request is null) {
|
|
2612 /*
|
|
2613 * listeners should not be notified of internal transitions like "javascipt:..."
|
|
2614 * because this is an implementation side-effect, not a true navigate
|
|
2615 */
|
|
2616 if (!value.startsWith (PREFIX_JAVASCRIPT)) {
|
|
2617 LocationEvent event = new LocationEvent (browser);
|
|
2618 event.display = browser.getDisplay();
|
|
2619 event.widget = browser;
|
|
2620 event.location = value;
|
|
2621 /*
|
|
2622 * If the URI indicates that the page is being rendered from memory
|
|
2623 * (via setText()) then set it to about:blank to be consistent with IE.
|
|
2624 */
|
|
2625 if (event.location.equals (URI_FROMMEMORY)) event.location = ABOUT_BLANK;
|
|
2626 event.doit = doit;
|
|
2627 for (int i = 0; i < locationListeners.length; i++) {
|
|
2628 locationListeners[i].changing (event);
|
|
2629 }
|
|
2630 doit = event.doit && !browser.isDisposed();
|
|
2631 }
|
|
2632 }
|
|
2633 *retval = doit ? 0 : 1;
|
|
2634 //XPCOM.memmove (retval, new int[] {doit ? 0 : 1}, 4); /* PRBool */
|
|
2635 return XPCOM.NS_OK;
|
|
2636 }
|
|
2637
|
|
2638 extern(System)
|
|
2639 nsresult DoContent (char* aContentType, PRBool aIsContentPreferred, nsIRequest aRequest, nsIStreamListener* aContentHandler, PRBool* retval) {
|
|
2640 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
|
|
2641 }
|
|
2642
|
|
2643 extern(System)
|
|
2644 nsresult IsPreferred (char* aContentType, char** aDesiredContentType, PRBool* retval) {
|
|
2645 bool preferred = false;
|
|
2646 auto size = strlen (aContentType);
|
|
2647 if (size > 0) {
|
|
2648 //byte[] typeBytes = new byte[size + 1];
|
|
2649 //XPCOM.memmove (typeBytes, aContentType, size);
|
|
2650 String contentType = fromStringz(aContentType);
|
|
2651
|
|
2652 /* do not attempt to handle known problematic content types */
|
|
2653 if (!contentType.equals (XPCOM.CONTENT_MAYBETEXT) && !contentType.equals (XPCOM.CONTENT_MULTIPART)) {
|
|
2654 /* determine whether browser can handle the content type */
|
|
2655 // int /*long*/[] result = new int /*long*/[1];
|
|
2656 nsIServiceManager serviceManager;
|
|
2657 int rc = XPCOM.NS_GetServiceManager (&serviceManager);
|
|
2658 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2659 if (serviceManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2660 //nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
|
|
2661 //result[0] = 0;
|
|
2662
|
|
2663 /* First try to use the nsIWebNavigationInfo if it's available (>= mozilla 1.8) */
|
|
2664 //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WEBNAVIGATIONINFO_CONTRACTID, true);
|
|
2665 nsIWebNavigationInfo info;
|
|
2666 rc = serviceManager.GetServiceByContractID (XPCOM.NS_WEBNAVIGATIONINFO_CONTRACTID.ptr, &nsIWebNavigationInfo.IID, cast(void**)&info);
|
|
2667 if (rc is XPCOM.NS_OK) {
|
|
2668 //byte[] bytes = MozillaDelegate.wcsToMbcs (null, contentType, true);
|
|
2669 scope auto typePtr = new nsEmbedCString(contentType);
|
|
2670 //nsIWebNavigationInfo info = new nsIWebNavigationInfo (result[0]);
|
|
2671 //result[0] = 0;
|
|
2672 PRUint32 isSupportedResult; /* PRUint32 */
|
|
2673 rc = info.IsTypeSupported (cast(nsACString*)typePtr, null, &isSupportedResult);
|
|
2674 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2675 info.Release ();
|
|
2676 //XPCOM.nsEmbedCString_delete (typePtr);
|
|
2677 preferred = isSupportedResult !is 0;
|
|
2678 } else {
|
|
2679 /* nsIWebNavigationInfo is not available, so do the type lookup */
|
|
2680 //result[0] = 0;
|
|
2681 nsICategoryManager categoryManager;
|
|
2682 rc = serviceManager.GetService (&XPCOM.NS_CATEGORYMANAGER_CID, &nsICategoryManager.IID, cast(void**)&categoryManager);
|
|
2683 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2684 if (categoryManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2685
|
|
2686 //nsICategoryManager categoryManager = new nsICategoryManager (result[0]);
|
|
2687 //result[0] = 0;
|
|
2688 char* categoryBytes = "Gecko-Content-Viewers"; //$NON-NLS-1$
|
|
2689 char* result;
|
|
2690 rc = categoryManager.GetCategoryEntry (categoryBytes, aContentType, &result);
|
|
2691 categoryManager.Release ();
|
|
2692 /* if no viewer for the content type is registered then rc is XPCOM.NS_ERROR_NOT_AVAILABLE */
|
|
2693 preferred = rc is XPCOM.NS_OK;
|
|
2694 }
|
|
2695 serviceManager.Release ();
|
|
2696 }
|
|
2697 }
|
|
2698
|
|
2699 *retval = preferred ? 1 : 0; /* PRBool */
|
|
2700 if (preferred) {
|
|
2701 *aDesiredContentType = null;
|
|
2702 }
|
|
2703 return XPCOM.NS_OK;
|
|
2704 }
|
|
2705
|
|
2706 extern(System)
|
|
2707 nsresult CanHandleContent (char* aContentType, PRBool aIsContentPreferred, char** aDesiredContentType, PRBool* retval) {
|
|
2708 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
|
|
2709 }
|
|
2710
|
|
2711 extern(System)
|
|
2712 nsresult GetLoadCookie (nsISupports* aLoadCookie) {
|
|
2713 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
|
|
2714 }
|
|
2715
|
|
2716 extern(System)
|
|
2717 nsresult SetLoadCookie (nsISupports aLoadCookie) {
|
|
2718 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
|
|
2719 }
|
|
2720
|
|
2721 extern(System)
|
|
2722 nsresult GetParentContentListener (nsIURIContentListener* aParentContentListener) {
|
|
2723 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
|
|
2724 }
|
|
2725
|
|
2726 extern(System)
|
|
2727 nsresult SetParentContentListener (nsIURIContentListener aParentContentListener) {
|
|
2728 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
|
|
2729 }
|
|
2730
|
|
2731 /* nsITooltipListener */
|
|
2732
|
|
2733 extern(System)
|
|
2734 nsresult OnShowTooltip (PRInt32 aXCoords, PRInt32 aYCoords, PRUnichar* aTipText) {
|
|
2735 if (awaitingNavigate) return XPCOM.NS_OK;
|
|
2736
|
|
2737 //int length = XPCOM.strlen_PRUnichar (aTipText);
|
|
2738 //char[] dest = new char[length];
|
|
2739 //XPCOM.memmove (dest, aTipText, length * 2);
|
|
2740 String text = Utf.toString(fromString16z(aTipText));
|
|
2741 if (tip !is null && !tip.isDisposed ()) tip.dispose ();
|
|
2742 Display display = browser.getDisplay ();
|
|
2743 Shell parent = browser.getShell ();
|
|
2744 tip = new Shell (parent, SWT.ON_TOP);
|
|
2745 tip.setLayout (new FillLayout());
|
|
2746 Label label = new Label (tip, SWT.CENTER);
|
|
2747 label.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));
|
|
2748 label.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
|
|
2749 label.setText (text);
|
|
2750 /*
|
|
2751 * Bug in Mozilla embedded API. Tooltip coordinates are wrong for
|
|
2752 * elements inside an inline frame (IFrame tag). The workaround is
|
|
2753 * to position the tooltip based on the mouse cursor location.
|
|
2754 */
|
|
2755 Point point = display.getCursorLocation ();
|
|
2756 /* Assuming cursor is 21x21 because this is the size of
|
|
2757 * the arrow cursor on Windows
|
|
2758 */
|
|
2759 point.y += 21;
|
|
2760 tip.setLocation (point);
|
|
2761 tip.pack ();
|
|
2762 tip.setVisible (true);
|
|
2763 return XPCOM.NS_OK;
|
|
2764 }
|
|
2765
|
|
2766 extern(System)
|
|
2767 nsresult OnHideTooltip () {
|
|
2768 if (tip !is null && !tip.isDisposed ()) tip.dispose ();
|
|
2769 tip = null;
|
|
2770 return XPCOM.NS_OK;
|
|
2771 }
|
|
2772
|
|
2773 /* nsIDOMEventListener */
|
|
2774
|
|
2775 extern(System)
|
|
2776 nsresult HandleEvent (nsIDOMEvent event) {
|
|
2777 //nsIDOMEvent domEvent = new nsIDOMEvent (event);
|
|
2778
|
|
2779 scope auto type = new nsEmbedString;
|
|
2780 int rc = event.GetType (cast(nsAString*)type);
|
|
2781 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2782 //int length = XPCOM.nsEmbedString_Length (type);
|
|
2783 //int /*long*/ buffer = XPCOM.nsEmbedString_get (type);
|
|
2784 //char[] chars = new char[length];
|
|
2785 //XPCOM.memmove (chars, buffer, length * 2);
|
|
2786 String typeString = type.toString;
|
|
2787 //XPCOM.nsEmbedString_delete (type);
|
|
2788
|
|
2789 if (XPCOM.DOMEVENT_UNLOAD.equals (typeString)) {
|
|
2790 //int /*long*/[] result = new int /*long*/[1];
|
|
2791 nsIDOMEventTarget target;
|
|
2792 rc = event.GetCurrentTarget (&target);
|
|
2793 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2794 if (target is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2795
|
|
2796 //nsIDOMEventTarget target = new nsIDOMEventTarget (result[0]);
|
|
2797 unhookDOMListeners (target);
|
|
2798 target.Release ();
|
|
2799 return XPCOM.NS_OK;
|
|
2800 }
|
|
2801
|
|
2802 if (XPCOM.DOMEVENT_FOCUS.equals (typeString)) {
|
|
2803 mozDelegate.handleFocus ();
|
|
2804 return XPCOM.NS_OK;
|
|
2805 }
|
|
2806
|
|
2807 if (XPCOM.DOMEVENT_KEYDOWN.equals (typeString)) {
|
|
2808 //int /*long*/[] result = new int /*long*/[1];
|
|
2809 nsIDOMKeyEvent domKeyEvent;
|
|
2810 rc = event.QueryInterface (&nsIDOMKeyEvent.IID, cast(void**)&domKeyEvent);
|
|
2811 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2812 if (domKeyEvent is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2813 //nsIDOMKeyEvent domKeyEvent = new nsIDOMKeyEvent (result[0]);
|
|
2814 //result[0] = 0;
|
|
2815
|
|
2816 PRUint32 aKeyCode; /* PRUint32 */
|
|
2817 rc = domKeyEvent.GetKeyCode (&aKeyCode);
|
|
2818 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2819 int keyCode = super.translateKey (aKeyCode);
|
|
2820
|
|
2821 /*
|
|
2822 * if keyCode is lastKeyCode then either a repeating key like Shift
|
|
2823 * is being held or a key for which key events are not sent has been
|
|
2824 * pressed. In both of these cases a KeyDown should not be sent.
|
|
2825 */
|
|
2826 if (keyCode !is lastKeyCode) {
|
|
2827 lastKeyCode = keyCode;
|
|
2828 switch (keyCode) {
|
|
2829 case SWT.SHIFT:
|
|
2830 case SWT.CONTROL:
|
|
2831 case SWT.ALT:
|
|
2832 case SWT.CAPS_LOCK:
|
|
2833 case SWT.NUM_LOCK:
|
|
2834 case SWT.SCROLL_LOCK:
|
|
2835 case SWT.COMMAND: {
|
|
2836 /* keypress events will not be received for these keys, so send KeyDowns for them now */
|
|
2837 PRBool aAltKey, aCtrlKey, aShiftKey, aMetaKey; /* PRBool */
|
|
2838 rc = domKeyEvent.GetAltKey (&aAltKey);
|
|
2839 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2840 rc = domKeyEvent.GetCtrlKey (&aCtrlKey);
|
|
2841 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2842 rc = domKeyEvent.GetShiftKey (&aShiftKey);
|
|
2843 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2844 rc = domKeyEvent.GetMetaKey (&aMetaKey);
|
|
2845 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2846
|
|
2847 Event keyEvent = new Event ();
|
|
2848 keyEvent.widget = browser;
|
|
2849 keyEvent.type = SWT.KeyDown;
|
|
2850 keyEvent.keyCode = keyCode;
|
|
2851 keyEvent.stateMask = (aAltKey !is 0 ? SWT.ALT : 0) | (aCtrlKey !is 0 ? SWT.CTRL : 0) | (aShiftKey !is 0 ? SWT.SHIFT : 0) | (aMetaKey !is 0 ? SWT.COMMAND : 0);
|
|
2852 keyEvent.stateMask &= ~keyCode; /* remove current keydown if it's a state key */
|
|
2853 browser.notifyListeners (keyEvent.type, keyEvent);
|
|
2854 if (!keyEvent.doit) {
|
|
2855 event.PreventDefault ();
|
|
2856 }
|
|
2857 break;
|
|
2858 }
|
|
2859 default: {
|
|
2860 /*
|
|
2861 * If the keydown has Meta (but not Meta+Ctrl) as a modifier then send a KeyDown event for it here
|
|
2862 * because a corresponding keypress event will not be received for it from the DOM. If the keydown
|
|
2863 * does not have Meta as a modifier, or has Meta+Ctrl as a modifier, then then do nothing here
|
|
2864 * because its KeyDown event will be sent from the keypress listener.
|
|
2865 */
|
|
2866 PRBool aMetaKey; /* PRBool */
|
|
2867 rc = domKeyEvent.GetMetaKey (&aMetaKey);
|
|
2868 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2869 if (aMetaKey !is 0) {
|
|
2870 PRBool aCtrlKey; /* PRBool */
|
|
2871 rc = domKeyEvent.GetCtrlKey (&aCtrlKey);
|
|
2872 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2873 if (aCtrlKey is 0) {
|
|
2874 PRBool aAltKey, aShiftKey; /* PRBool */
|
|
2875 rc = domKeyEvent.GetAltKey (&aAltKey);
|
|
2876 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2877 rc = domKeyEvent.GetShiftKey (&aShiftKey);
|
|
2878 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2879
|
|
2880 Event keyEvent = new Event ();
|
|
2881 keyEvent.widget = browser;
|
|
2882 keyEvent.type = SWT.KeyDown;
|
|
2883 keyEvent.keyCode = lastKeyCode;
|
|
2884 keyEvent.stateMask = (aAltKey !is 0 ? SWT.ALT : 0) | (aCtrlKey !is 0? SWT.CTRL : 0) | (aShiftKey !is 0? SWT.SHIFT : 0) | (aMetaKey !is 0? SWT.COMMAND : 0);
|
|
2885 browser.notifyListeners (keyEvent.type, keyEvent);
|
|
2886 if (!keyEvent.doit) {
|
|
2887 event.PreventDefault ();
|
|
2888 }
|
|
2889 }
|
|
2890 }
|
|
2891 }
|
|
2892 }
|
|
2893 }
|
|
2894
|
|
2895 domKeyEvent.Release ();
|
|
2896 return XPCOM.NS_OK;
|
|
2897 }
|
|
2898
|
|
2899 if (XPCOM.DOMEVENT_KEYPRESS.equals (typeString)) {
|
|
2900 /*
|
|
2901 * if keydown could not determine a keycode for this key then it's a
|
|
2902 * key for which key events are not sent (eg.- the Windows key)
|
|
2903 */
|
|
2904 if (lastKeyCode is 0) return XPCOM.NS_OK;
|
|
2905
|
|
2906 /*
|
|
2907 * On linux only, unexpected keypress events are received for some
|
|
2908 * modifier keys. The workaround is to ignore these events since
|
|
2909 * KeyDown events are sent for these keys in the keydown listener.
|
|
2910 */
|
|
2911 switch (lastKeyCode) {
|
|
2912 case SWT.CAPS_LOCK:
|
|
2913 case SWT.NUM_LOCK:
|
|
2914 case SWT.SCROLL_LOCK: return XPCOM.NS_OK;
|
|
2915 default: break;
|
|
2916 }
|
|
2917
|
|
2918 //int /*long*/[] result = new int /*long*/[1];
|
|
2919 nsIDOMKeyEvent domKeyEvent;
|
|
2920 rc = event.QueryInterface (&nsIDOMKeyEvent.IID, cast(void**)&domKeyEvent);
|
|
2921 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2922 if (domKeyEvent is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2923 //nsIDOMKeyEvent domKeyEvent = new nsIDOMKeyEvent (result[0]);
|
|
2924 //result[0] = 0;
|
|
2925
|
|
2926 PRBool aAltKey, aCtrlKey, aShiftKey, aMetaKey; /* PRBool */
|
|
2927 rc = domKeyEvent.GetAltKey (&aAltKey);
|
|
2928 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2929 rc = domKeyEvent.GetCtrlKey (&aCtrlKey);
|
|
2930 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2931 rc = domKeyEvent.GetShiftKey (&aShiftKey);
|
|
2932 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2933 rc = domKeyEvent.GetMetaKey (&aMetaKey);
|
|
2934 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2935 domKeyEvent.Release ();
|
|
2936
|
|
2937 PRUint32 aCharCode; /* PRUint32 */
|
|
2938 rc = domKeyEvent.GetCharCode (&aCharCode);
|
|
2939 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2940 lastCharCode = aCharCode;
|
|
2941 if (lastCharCode is 0) {
|
|
2942 switch (lastKeyCode) {
|
|
2943 case SWT.TAB: lastCharCode = SWT.TAB; break;
|
|
2944 case SWT.CR: lastCharCode = SWT.CR; break;
|
|
2945 case SWT.BS: lastCharCode = SWT.BS; break;
|
|
2946 case SWT.ESC: lastCharCode = SWT.ESC; break;
|
|
2947 case SWT.DEL: lastCharCode = SWT.DEL; break;
|
|
2948 default: break;
|
|
2949 }
|
|
2950 }
|
|
2951 if (aCtrlKey !is 0 && (0 <= lastCharCode && lastCharCode <= 0x7F)) {
|
|
2952 if ('a' <= lastCharCode && lastCharCode <= 'z') lastCharCode -= 'a' - 'A';
|
|
2953 if (64 <= lastCharCode && lastCharCode <= 95) lastCharCode -= 64;
|
|
2954 }
|
|
2955
|
|
2956 Event keyEvent = new Event ();
|
|
2957 keyEvent.widget = browser;
|
|
2958 keyEvent.type = SWT.KeyDown;
|
|
2959 keyEvent.keyCode = lastKeyCode;
|
|
2960 keyEvent.character = cast(wchar)lastCharCode;
|
|
2961 keyEvent.stateMask = (aAltKey !is 0 ? SWT.ALT : 0) | (aCtrlKey !is 0 ? SWT.CTRL : 0) | (aShiftKey !is 0 ? SWT.SHIFT : 0) | (aMetaKey !is 0 ? SWT.COMMAND : 0);
|
|
2962 browser.notifyListeners (keyEvent.type, keyEvent);
|
|
2963 if (!keyEvent.doit) {
|
|
2964 event.PreventDefault ();
|
|
2965 }
|
|
2966 return XPCOM.NS_OK;
|
|
2967 }
|
|
2968
|
|
2969 if (XPCOM.DOMEVENT_KEYUP.equals (typeString)) {
|
|
2970 //int /*long*/[] result = new int /*long*/[1];
|
|
2971 nsIDOMKeyEvent domKeyEvent;
|
|
2972 rc = event.QueryInterface (&nsIDOMKeyEvent.IID, cast(void**)&domKeyEvent);
|
|
2973 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2974 if (domKeyEvent is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
2975 //nsIDOMKeyEvent domKeyEvent = new nsIDOMKeyEvent (result[0]);
|
|
2976 //result[0] = 0;
|
|
2977
|
|
2978 PRUint32 aKeyCode; /* PRUint32 */
|
|
2979 rc = domKeyEvent.GetKeyCode (&aKeyCode);
|
|
2980 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2981 int keyCode = super.translateKey (aKeyCode);
|
|
2982 if (keyCode is 0) {
|
|
2983 /* indicates a key for which key events are not sent */
|
|
2984 domKeyEvent.Release ();
|
|
2985 return XPCOM.NS_OK;
|
|
2986 }
|
|
2987 if (keyCode !is lastKeyCode) {
|
|
2988 /* keyup does not correspond to the last keydown */
|
|
2989 lastKeyCode = keyCode;
|
|
2990 lastCharCode = 0;
|
|
2991 }
|
|
2992
|
|
2993 PRBool aAltKey, aCtrlKey, aShiftKey, aMetaKey; /* PRBool */
|
|
2994 rc = domKeyEvent.GetAltKey (&aAltKey);
|
|
2995 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2996 rc = domKeyEvent.GetCtrlKey (&aCtrlKey);
|
|
2997 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
2998 rc = domKeyEvent.GetShiftKey (&aShiftKey);
|
|
2999 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3000 rc = domKeyEvent.GetMetaKey (&aMetaKey);
|
|
3001 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3002 domKeyEvent.Release ();
|
|
3003
|
|
3004 Event keyEvent = new Event ();
|
|
3005 keyEvent.widget = browser;
|
|
3006 keyEvent.type = SWT.KeyUp;
|
|
3007 keyEvent.keyCode = lastKeyCode;
|
|
3008 keyEvent.character = cast(wchar)lastCharCode;
|
|
3009 keyEvent.stateMask = (aAltKey !is 0 ? SWT.ALT : 0) | (aCtrlKey !is 0 ? SWT.CTRL : 0) | (aShiftKey !is 0 ? SWT.SHIFT : 0) | (aMetaKey !is 0 ? SWT.COMMAND : 0);
|
|
3010 switch (lastKeyCode) {
|
|
3011 case SWT.SHIFT:
|
|
3012 case SWT.CONTROL:
|
|
3013 case SWT.ALT:
|
|
3014 case SWT.COMMAND: {
|
|
3015 keyEvent.stateMask |= lastKeyCode;
|
|
3016 }
|
|
3017 default: break;
|
|
3018 }
|
|
3019 browser.notifyListeners (keyEvent.type, keyEvent);
|
|
3020 if (!keyEvent.doit) {
|
|
3021 event.PreventDefault ();
|
|
3022 }
|
|
3023 lastKeyCode = lastCharCode = 0;
|
|
3024 return XPCOM.NS_OK;
|
|
3025 }
|
|
3026
|
|
3027 /* mouse event */
|
|
3028
|
|
3029 //int /*long*/[] result = new int /*long*/[1];
|
|
3030 nsIDOMMouseEvent domMouseEvent;
|
|
3031 rc = event.QueryInterface (&nsIDOMMouseEvent.IID, cast(void**)&domMouseEvent);
|
|
3032 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3033 if (domMouseEvent is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
|
|
3034 //nsIDOMMouseEvent domMouseEvent = new nsIDOMMouseEvent (result[0]);
|
|
3035 //result[0] = 0;
|
|
3036
|
|
3037 /*
|
|
3038 * MouseOver and MouseOut events are fired any time the mouse enters or exits
|
|
3039 * any element within the Browser. To ensure that SWT events are only
|
|
3040 * fired for mouse movements into or out of the Browser, do not fire an
|
|
3041 * event if the element being exited (on MouseOver) or entered (on MouseExit)
|
|
3042 * is within the Browser.
|
|
3043 */
|
|
3044 if (XPCOM.DOMEVENT_MOUSEOVER.equals (typeString) || XPCOM.DOMEVENT_MOUSEOUT.equals (typeString)) {
|
|
3045 nsIDOMEventTarget eventTarget;
|
|
3046 rc = domMouseEvent.GetRelatedTarget (&eventTarget);
|
|
3047 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3048 if (eventTarget !is null) {
|
|
3049 domMouseEvent.Release ();
|
|
3050 return XPCOM.NS_OK;
|
|
3051 }
|
|
3052 }
|
|
3053
|
|
3054 PRInt32 aClientX, aClientY, aDetail; /* PRInt32 */
|
|
3055 rc = domMouseEvent.GetClientX (&aClientX);
|
|
3056 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3057 rc = domMouseEvent.GetClientY (&aClientY);
|
|
3058 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3059 rc = domMouseEvent.GetDetail (&aDetail);
|
|
3060 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3061 PRUint16 aButton; /* PRUint16 */
|
|
3062 rc = domMouseEvent.GetButton (&aButton);
|
|
3063 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3064 PRBool aAltKey, aCtrlKey, aShiftKey, aMetaKey; /* PRBool */
|
|
3065 rc = domMouseEvent.GetAltKey (&aAltKey);
|
|
3066 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3067 rc = domMouseEvent.GetCtrlKey (&aCtrlKey);
|
|
3068 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3069 rc = domMouseEvent.GetShiftKey (&aShiftKey);
|
|
3070 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3071 rc = domMouseEvent.GetMetaKey (&aMetaKey);
|
|
3072 if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
|
|
3073 domMouseEvent.Release ();
|
|
3074
|
|
3075 Event mouseEvent = new Event ();
|
|
3076 mouseEvent.widget = browser;
|
|
3077 mouseEvent.x = aClientX; mouseEvent.y = aClientY;
|
|
3078 mouseEvent.stateMask = (aAltKey !is 0 ? SWT.ALT : 0) | (aCtrlKey !is 0 ? SWT.CTRL : 0) | (aShiftKey !is 0 ? SWT.SHIFT : 0) | (aMetaKey !is 0 ? SWT.COMMAND : 0);
|
|
3079
|
|
3080 if (XPCOM.DOMEVENT_MOUSEDOWN.equals (typeString)) {
|
|
3081 mozDelegate.handleMouseDown ();
|
|
3082 mouseEvent.type = SWT.MouseDown;
|
|
3083 mouseEvent.button = aButton + 1;
|
|
3084 mouseEvent.count = aDetail;
|
|
3085 } else if (XPCOM.DOMEVENT_MOUSEUP.equals (typeString)) {
|
|
3086 /*
|
|
3087 * Bug on OSX. For some reason multiple mouseup events come from the DOM
|
|
3088 * when button 3 is released on OSX. The first of these events has a count
|
|
3089 * detail and the others do not. The workaround is to not fire received
|
|
3090 * button 3 mouseup events that do not have a count since mouse events
|
|
3091 * without a click count are not valid.
|
|
3092 */
|
|
3093 int button = aButton + 1;
|
|
3094 int count = aDetail;
|
|
3095 if (count is 0 && button is 3) return XPCOM.NS_OK;
|
|
3096 mouseEvent.type = SWT.MouseUp;
|
|
3097 mouseEvent.button = button;
|
|
3098 mouseEvent.count = count;
|
|
3099 } else if (XPCOM.DOMEVENT_MOUSEMOVE.equals (typeString)) {
|
|
3100 mouseEvent.type = SWT.MouseMove;
|
|
3101 } else if (XPCOM.DOMEVENT_MOUSEWHEEL.equals (typeString)) {
|
|
3102 mouseEvent.type = SWT.MouseWheel;
|
|
3103 mouseEvent.count = -aDetail;
|
|
3104 } else if (XPCOM.DOMEVENT_MOUSEOVER.equals (typeString)) {
|
|
3105 mouseEvent.type = SWT.MouseEnter;
|
|
3106 } else if (XPCOM.DOMEVENT_MOUSEOUT.equals (typeString)) {
|
|
3107 mouseEvent.type = SWT.MouseExit;
|
|
3108 } else if (XPCOM.DOMEVENT_MOUSEDRAG.equals (typeString)) {
|
|
3109 mouseEvent.type = SWT.DragDetect;
|
|
3110 mouseEvent.button = aButton + 1;
|
|
3111 switch (mouseEvent.button) {
|
|
3112 case 1: mouseEvent.stateMask |= SWT.BUTTON1; break;
|
|
3113 case 2: mouseEvent.stateMask |= SWT.BUTTON2; break;
|
|
3114 case 3: mouseEvent.stateMask |= SWT.BUTTON3; break;
|
|
3115 case 4: mouseEvent.stateMask |= SWT.BUTTON4; break;
|
|
3116 case 5: mouseEvent.stateMask |= SWT.BUTTON5; break;
|
|
3117 default: break;
|
|
3118 }
|
|
3119 }
|
|
3120
|
|
3121 browser.notifyListeners (mouseEvent.type, mouseEvent);
|
|
3122 if (aDetail is 2 && XPCOM.DOMEVENT_MOUSEDOWN.equals (typeString)) {
|
|
3123 mouseEvent = new Event ();
|
|
3124 mouseEvent.widget = browser;
|
|
3125 mouseEvent.x = aClientX; mouseEvent.y = aClientY;
|
|
3126 mouseEvent.stateMask = (aAltKey !is 0 ? SWT.ALT : 0) | (aCtrlKey !is 0 ? SWT.CTRL : 0) | (aShiftKey !is 0 ? SWT.SHIFT : 0) | (aMetaKey !is 0 ? SWT.COMMAND : 0);
|
|
3127 mouseEvent.type = SWT.MouseDoubleClick;
|
|
3128 mouseEvent.button = aButton + 1;
|
|
3129 mouseEvent.count = aDetail;
|
|
3130 browser.notifyListeners (mouseEvent.type, mouseEvent);
|
|
3131 }
|
|
3132 return XPCOM.NS_OK;
|
|
3133 }
|
|
3134 }
|