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