XULRUNNER
XULRUNNER Download
http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/latest/
http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/
XULRunner runtime vs. sdk
How to install XULRunner for Eclipse
Edit your app's Run Configuration->Arguments->VM Arguments, add following argument. -Dorg.eclipse.swt.browser.XULRunnerPath=C:\xulrunner
http://www.kodewerx.org/wiki/A_Brief_Introduction_To_XULRunner:_Part_2
Download the latest stable version from Mozilla: http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ (Note: Go into the most recent sub-directory and then the "runtimes" sub-directory. You don't need the SDK.)
XULRunner内核版本
SWT Browser(xulrunner v24)在使用SWT.MOZILLA时的浏览器属性信息如下:
js: alert(navigator.userAgent.toLowerCase()); ==> mozilla/5.0 (windows nt 6.3; wow64; rv:24.0) gecko/ /24.0
Chrome 49: mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, like gecko) chrome/49.0.2623.110 safari/537.36
IE 11: mozilla/5.0 (windows nt 6.3; wow64; trident/7.0; .net4.0e; .net4.0c; tablet pc 2.0; .net clr 3.5.30729; .net clr 2.0.50727; .net clr 3.0.30729; infopath.3; rv:11.0) like gecko
Firefox 45: mozilla/5.0 (windows nt 6.3; wow64; rv:45.0) gecko/20100101 firefox/45.0
XULRunner 24: mozilla/5.0 (windows nt 6.3; wow64; rv:24.0) gecko/ /24.0
Gecko
Gecko是由Mozilla基金会开发的布局引擎的名字。它原本叫作NGLayout。Gecko的作用是读取诸如HTML、CSS、XUL和JavaScript等的网页内容,并呈现到用户屏幕或打印出来。Gecko已经被许多应用程序所使用,包括若干浏览器,例如Firefox、Mozilla Suite、Camino等。
Trouble Shooting
如果没有设置xulrunner路径或注册(xulrunner2.0之前),则报错如下:
Exception in thread "main" org.eclipse.swt.SWTError: No more handles [Could not detect registered XULRunner to use]
at org.eclipse.swt.SWT.error(SWT.java:4109)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:633)
at org.eclipse.swt.browser.Browser.(Browser.java:119)
at com.cci.ddt.composite.LoginComposite.login(LoginComposite.java:280)
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "C:\\Program Files (x86)\\xulrunner");
eclipse.ini设置在程序中无法使用,该参数显示为null
-Dorg.eclipse.swt.browser.XULRunnerPath=C:/Resource_SD/XULRUNNER/xulrunner-36.0.1.en-US.win32/xulrunner
static void printJavaVmArgs(){
System.out.println("************************************Begin");
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List arguments = runtimeMxBean.getInputArguments();
for(int i=0;i
System.out.println(arguments.get(i));
}
System.out.println(System.getProperty("org.eclipse.swt.browser.XULRunnerPath"));
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "C:/Resource_SD/XULRUNNER/xulrunner-36.0.1.en-US.win32/xulrunner");
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "C:/sd/eclipse-jee-luna-SR1-win32/eclipse/workspace/DDTClientSWT/xulrunner");
System.out.println(System.getProperty("org.eclipse.swt.browser.XULRunnerPath"));
System.out.println("************************************End");
}
通过System.setProperty设置之后报错如下:
Exception in thread "main" org.eclipse.swt.SWTError: XPCOM error -2147467259
at org.eclipse.swt.browser.Mozilla.error(Mozilla.java:2347)
at org.eclipse.swt.browser.Mozilla.initXULRunner(Mozilla.java:2310)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:622)
at org.eclipse.swt.browser.Browser.(Browser.java:119)
at com.cci.ddt.composite.LoginComposite.login(LoginComposite.java:280)
...
JavaXPCOM
Note: JavaXPCOM was included in XULRunner up through version 1.9.2. It has been removed in XULRunner 2, and is not actively maintained. C:\sd\tools\Eclipse\MyEclipse 6.5\myeclipse\eclipse\plugins\org.mozilla.xpcom_1.8.1.3-20070320\MozillaInterfaces.jar 695 KB (712,495 字节)
Q: What do I need to run the SWT Browser inside Eclipse on Linux?
A: The browser versions that are supported by each Eclipse release are listed below.
Note that Mozilla/XULRunner versions that are not final releases (eg.- betas, alphas, nightlies) are not supported, even if their version technically satisfies a listed version range.
Also note that the Mozilla/XULRunner must be compiled for the same architecture as the SWT jar that is being used.
Eclipse 3.0.x: Mozilla 1.4 GTK2 - 1.6 GTK2.
Eclipse 3.1.x: Mozilla 1.4 GTK2 - 1.7.8 GTK2.
Eclipse 3.2.x: Mozilla 1.4 GTK2 - 1.7.x GTK2.
Eclipse 3.3.x: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x.
Eclipse 3.4.x: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.0.x.
Eclipse 3.5.0 and 3.5.1: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.1.x.
Eclipse 3.5.2: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.x and 3.6.x (but not 2.x).
Eclipse 3.6.x: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.x and 3.6.x (but not 2.x), WebKitGTK+ 1.2.x (see How do I use the WebKit renderer on Linux-GTK?)
Eclipse 3.7.x: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.x and 3.6.x (but not 2.x), WebKitGTK+ 1.2.x and newer
Eclipse 3.8.x: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.x, 3.6.x and 10.x (but not 2.x nor 4.x - 9.x), WebKitGTK+ 1.2.x and newer
Eclipse 4.2: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.x, 3.6.x and 10.x (but not 2.x nor 4.x - 9.x), WebKitGTK+ 1.2.x - 1.8.x
Eclipse 4.2.2 and newer: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.x, 3.6.x and 10.x (but not 2.x nor 4.x - 9.x), WebKitGTK+ 1.2.x and newer
Eclipse 4.4 and newer: Mozilla 1.4 GTK2 - 1.7.x GTK2, XULRunner 1.8.x - 1.9.x, 3.6.x, 10.x and 24.x (but not 2.x nor other unlisted versions), WebKitGTK+ 1.2.x and newer (Eclipse 4.4 and newer uses GTK 3 by default and XULRunner cannot be used in this case as it is not ported to GTK 3 yet)
Also note that a Firefox release whose contained Gecko version correlates with the Mozilla versions above can also be used with Eclipse 3.1 and newer (Linux only), provided that it has been compiled with linkable Gecko libraries. It is important to note that Firefox downloads from mozilla.org do not satisfy this criteria, but Firefox installations that are included in major Linux distributions often do in the absence of a XULRunner installation. Attempting to use a Firefox install without linkable Gecko libraries will throw an error with message "No more handles [NS_InitEmbedding...error -2147221164]".
JavaXPCOM Errors
XULRunner path: C:/sd/eclipse-jee-luna-SR1-win32/eclipse/workspace/DDTClientSWT/xulrunner\xpcom.dll
>>>This failed with the following error:
org.eclipse.swt.SWTError: XPCOM error -2142109695
at org.eclipse.swt.browser.Mozilla.error(Mozilla.java:2347)
at org.eclipse.swt.browser.Mozilla.initXPCOM(Mozilla.java:1718)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:650)
at org.eclipse.swt.browser.Browser.(Browser.java:119)
at com.cci.ddt.windows.Start.displayMozillarVersion(Start.java:100)
at com.cci.ddt.windows.Start.main(Start.java:48)
XULRunner path: C:/Resource_SD/XULRUNNER/xulrunner-36.0.1.en-US.win32/xulrunner\xpcom.dll
>>>This failed with the following error:
org.eclipse.swt.SWTError: XPCOM error -2147467259
at org.eclipse.swt.browser.Mozilla.error(Mozilla.java:2347)
at org.eclipse.swt.browser.Mozilla.initXULRunner(Mozilla.java:2310)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:622)
at org.eclipse.swt.browser.Browser.(Browser.java:119)
at com.cci.ddt.windows.Start.displayMozillarVersion(Start.java:100)
at com.cci.ddt.windows.Start.main(Start.java:48)
>>>Snippet creating SWT.MOZILLA-style Browser
XULRunner path: C:\Resource_SD\XULRUNNER\xulrunner-13.0.en-US.win32\xulrunner\xpcom.dll
>>>This failed with the following error:
org.eclipse.swt.SWTError: XPCOM error -2147467261
at org.eclipse.swt.browser.Mozilla.error(Mozilla.java:2347)
at org.eclipse.swt.browser.Mozilla.initXPCOM(Mozilla.java:1748)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:650)
at org.eclipse.swt.browser.Browser.(Browser.java:119)
at com.cci.ddt.windows.Start.displayMozillarVersion(Start.java:101)
at com.cci.ddt.windows.Start.main(Start.java:48)
SWTError (XPCOM error -2147467259) https://bugs.eclipse.org/bugs/show_bug.cgi?id=174395
Profile Manager
https://developer.mozilla.org/zh-CN/docs/Profile_Manager Finding your profile without opening Firefox C:\Users\Mark\AppData\Local\Mozilla\Firefox\Profiles
https://developer.mozilla.org/en-US/docs/How_to_enable_locale_switching_in_a_XULRunner_application /* Don't inherit OS locale */ pref("intl.locale.matchOS", "false"); user_pref("intl.locale.matchOS", true); user_pref("intl.locale.matchOS", false); /* Choose own fallback locale; later it can be overridden by the user */ pref("general.useragent.locale", "en-GB");
Moazilla.java http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/bundles/org.eclipse.swt/Eclipse%20SWT%20Mozilla/common/org/eclipse/swt/browser/Mozilla.java
Could not initialize the application's security component. The most likely cause is problms with files in your application's profile directory.
https://developer.mozilla.org/en-US/docs/Make_your_xulrunner_app_match_the_system_locale
https://adblockplus.org/blog/xulrunner-in-large-projects-part-4-localization-pitfalls some strings are not localized, e.g. labels of default alert dialog buttons, the entire add-on manager or error console UI, some error messages. Yes, these strings are not part of your application, they are part of XULRunner. The good news: XULRunner locales are all there, you can get them. http://hg.mozilla.org/l10n-central/
user_pref("general.useragent.locale" "zh-CN");
user_pref("intl.locale.matchOS", "false");
http://labs.abeautifulsite.net/archived/jquery-alerts/demo/
http://www.ibm.com/developerworks/cn/opensource/os-cn-freemarker/ 基于 SWT Browser 与 Freemarker 的 Java 桌面开发
What information is stored in my profile? https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data?redirectlocale=en-US&redirectslug=Profiles#w_finding-your-profile-without-opening-firefox
SWT Browser Setup: about:config
print.print_footerleft=&PT
print.print_footerright=&D
print.print_headercenter=""
print.print_headerleft=&T
print.print_headright=&U
Profile的位置
Also the SWT browser should have a profile named "eclipse" by default (it seems it's located at C:\Documents and Settings\\Application Data\Mozilla\eclipse\, see mozilla support for more info about profiles.
winxp: C:\Documents and Settings\\Application Data\Mozilla\eclipse\ win7/8: C:\Users\\AppData\Roaming\Mozilla\eclipse\prefs.js
Flexible Mozilla profile support https://bugs.eclipse.org/bugs/show_bug.cgi?id=178918
指定profile
http://www.eclipse.org/swt/faq.php#specifyprofile
Q: Can I specify which Mozilla profile gets used?
A: (@since 4.4) A profile can be specified for use by all Mozilla-based Browser instances by setting Java property org.eclipse.swt.browser.MOZ_PROFILE_PATH to the path of the profile before the first instance of a Mozilla-based Browser is created. The best opportunity for a user to set this property is by launching their application with a -D VM switch (eg.- add to the end of the eclipse.ini file: -Dorg.eclipse.swt.browser.MOZ_PROFILE_PATH=...).
SWT Browser
SWT Javadoc
https://www.eclipse.org/swt/javadoc.php
Package org.eclipse.swt.browser
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fbrowser%2Fpackage-summary.html
eclipse.org关于SWT Browser的FAQ
http://www.eclipse.org/swt/faq.php#whatisbrowser
Q: Which platforms support the SWT Browser, and which native renderers do they use?
A: The SWT Browser is currently available on the platforms listed below. By default, Browser instances created with style SWT.NONE use the following native renderers:
Windows 2000 and newer (Internet Explorer 5.5 and newer) Mac OS X 10.5 and newer (WebKit) Linux GTK (details) Solaris-x86 and Solaris 10 SPARC (details) Browsers should typically be created with style SWT.NONE as this will attempt to use a native renderer that should not require additional software installation. However for clients with specific native browser requirements, the type of native renderer to use can be specified on a per-instance basis, see How do I explicity use WebKit as the Browser's underlying renderer? and How do I explicitly use Mozilla as the Browser's underlying renderer?.
Also note that as of Eclipse/SWT 3.7 it is possible to override the default native renderer that is used for SWT.NONE-style Browsers, see How do I specify the default type of native renderer that is used by the Browser?.
Q: Can I specify which XULRunner installation gets used?
A: Typically a Mozilla-based Browser uses XULRunner's lookup mechanism to find a registered XULRunner at runtime, in which case a XULRunner location does not need to be specified. However if you wish to override this mechanism you can set the value of java system property org.eclipse.swt.browser.XULRunnerPath to the full path of a specific XULRunner to use. This property must be set before the first Browser instance is created.
The best opportunity for a user to set this property is by launching their application with a -D VM switch (eg.- add to the end of the eclipse.ini file: -Dorg.eclipse.swt.browser.XULRunnerPath=...).
SWT Browser的一些实现
打开新窗口
This html opens external windows either via JavaScript window.open or alinks with a target="_new" attribute.
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet270.java
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
/*
* Browser snippet: bring up a browser with pop-up window support
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*
* @since 3.1
*/
import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class Snippet270 {
static final int BROWSER_STYLE = SWT.NONE;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Main Window");
shell.setLayout(new FillLayout());
final Browser browser;
try {
browser = new Browser(shell, BROWSER_STYLE);
} catch (SWTError e) {
System.out.println("Could not instantiate Browser: " + e.getMessage());
display.dispose();
return;
}
initialize(display, browser);
shell.open();
browser.setUrl("http://www.eclipse.org");
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
/* register WindowEvent listeners */
static void initialize(final Display display, Browser browser) {
browser.addOpenWindowListener(event -> {
if (!event.required) return;/* only do it if necessary */
Shell shell = new Shell(display);
shell.setText("New Window");
shell.setLayout(new FillLayout());
Browser browser1 = new Browser(shell, BROWSER_STYLE);
initialize(display, browser1);
event.browser = browser1;
});
browser.addVisibilityWindowListener(new VisibilityWindowListener() {
@Override
public void hide(WindowEvent event) {
Browser browser = (Browser)event.widget;
Shell shell = browser.getShell();
shell.setVisible(false);
}
@Override
public void show(WindowEvent event) {
Browser browser = (Browser)event.widget;
final Shell shell = browser.getShell();
if (event.location != null) shell.setLocation(event.location);
if (event.size != null) {
Point size = event.size;
shell.setSize(shell.computeSize(size.x, size.y));
}
shell.open();
}
});
browser.addCloseWindowListener(event -> {
Browser browser1 = (Browser)event.widget;
Shell shell = browser1.getShell();
shell.close();
});
}
}
Class WindowEvent
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fbrowser%2FWindowEvent.html
AWindowEventis sent by aBrowserwhen a new window needs to be created or when an existing window needs to be closed. This notification occurs when a javascript command such aswindow.openorwindow.closegets executed by aBrowser.
The following notifications are emitted when the user selects a hyperlink that targets a new window or as the result of a javascript that executes window.open.
Main Browser
User selects a link that opens in a new window or javascript requests a new window
OpenWindowListener.open() notified
Application creates a new Shell and a second Browser inside that Shell
Application registers WindowListener's on that second Browser, such as VisibilityWindowListener
Application returns the second Browser as the host for the new window content
Second Browser
VisibilityWindowListener.show() notified
Application sets navigation tool bar, status bar, menu bar and Shell size
Application makes the Shell hosting the second Browser visible
User now sees the new window
Trouble Shooting
关于Unresponsive Script Warning的处理
http://kb.mozillazine.org/Unresponsive_Script_Warning
https://support.mozilla.org/en-US/kb/warning-unresponsive-script
/**
* Warning Unresponsive script - What it means and how to fix it
* https://support.mozilla.org/en-US/kb/warning-unresponsive-script
*/
else if (data != null && data.contains("dom.max_script_run_time")) {//
data = data.substring(0, data.lastIndexOf(",") + 1) + "60);";
}else if (data != null && data.contains("dom.max_chrome_script_run_time")) {//
data = data.substring(0, data.lastIndexOf(",") + 1) + "60);";
}
关于打开PDF文件的设置
指定浏览器打开PDF文件的工具
If you want the browser to open PDF files in a separate Acrobat window, configure the browser to use Acrobat or Adobe Reader as a helper application.
Then, when you select a PDF file in Internet Explorer, the browser will open the PDF file in an Acrobat window instead of the browser window.
To configure the browser to use Acrobat or Adobe Reader to open PDF files:
Quit Internet Explorer.
Start Acrobat or Adobe Reader.
Choose "Edit" > "Preferences."
Select Internet in the list on the left.
Deselect "Display PDF" in Browser, and click "OK."
Restart Internet Explorer.
Note: The next time you select a link to a PDF file, the browser may prompt you to open or save the file.
If you choose to open the file, the browser opens the file in the helper application that you specified.
If you choose to save the file, the browser downloads the file to the hard disk.
How to disable the built-in PDF viewer and use another viewer
https://support.mozilla.org/en-US/kb/disable-built-pdf-viewer-and-use-another-viewer
user_pref("pref.downloads.disable_button.edit_actions", false);
Acrobat Reader FAQ
http://plugindoc.mozdev.org/faqs/acroread.html#install-linux
about:config
about:plugins
ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/24.0/win32/zh-CN/Firefox%20Setup%2024.0.exe
SWT Mozilla 在访问https网页后弹出invalid certificate提示:
1. certificate name is invalid or does not match site name. Certificate issued to: "localhost". (CN=192.168.1.155)
2. Certificate is not currently valid. Valid date range: "2015-06-04 08:46:38 - 2015-09-02 08:46:38". ( -validity 3650)
3. Certificate is not from a trusted certifying authority. Certificate issuer: "localhost". (cert_override.txt)
https://192.168.1.155:8443/ddt
让客户端信任服务器证书 cert_override.txt
使用firefox访问服务https://192.168.1.155:8443添加例外
拷贝C:\Users\Mark\AppData\Roaming\Mozilla\Firefox\Profiles\ba07kksh.default\cert_override.txt的内容到C:\Users\Mark\mozilla_config/cert_override.txt
如下:(U后的内容可以不要,U后必须保留一个空格)
112.74.247.82:8443 OID.2.16.840.1.101.3.4.2.1 50:C8:75:77:C6:FE:D8:5A:12:10:77:8B:ED:18:5A:79:8F:1F:05:98:F7:11:7B:40:25:C8:18:EC:B2:20:AF:86 U
弱临时 Diffie-Hellman 密钥
Chrome:服务器的瞬时 Diffie-Hellman 公共密钥过弱 ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY
Firefox:连接 ddt2.soudang.com:8443 时发生错误。 在服务器密钥交换握手信息中 SSL 收到了一个弱临时 Diffie-Hellman 密钥。 (错误码: ssl_error_weak_server_ephemeral_dh_key)
IE:提示证书出错但是可以打开页面
about:config 里,把下面两个值从true改成false
security.ssl3.dhe_rsa_aes_128_sha=false
security.ssl3.dhe_rsa_aes_256_sha=false
关于安全警告的处理 | Disable security warning
常用的关于security的profile设置参数
http://kb.mozillazine.org/About:config_entries#Security
关于mixed content warning
Security Warning
Although this page is encrypted, the information you have entered is to be sent over an unencrypted connection and could easily be read by a third party.
Are you sure you want to continue sending this information?
Firefox对mixed-conten的解释
https://support.mozilla.org/en-US/kb/mixed-content-blocking-firefox
if the HTTPS page you visit includes HTTP content, the HTTP portion can be read or modified by attackers, even though the main page is served over HTTPS. When an HTTPS page has HTTP content, we call that content “mixed”.
如何应对mixed-content-blocking
security.mixed_content.block_active_content;false
security.mixed_content.block_display_content;false
user_pref("security.warn_viewing_mixed", false);
user_pref("security.warn_viewing_mixed.show_once", false);
设置了这么多也没用:
user_pref("security.ui.enable", false);
user_pref("security.warn_entering_secure", false);
user_pref("security.warn_entering_secure.show_once", false);
user_pref("security.warn_entering_weak", false);
user_pref("security.warn_entering_weak.show_once", false);
user_pref("security.warn_leaving_secure", false);
user_pref("security.warn_leaving_secure.show_once", false);
user_pref("security.warn_submit_insecure", false);
user_pref("security.warn_submit_insecure.show_once", false);
user_pref("security.insecure_field_warning.contextual.enabled", false);
user_pref("security.insecure_password.ui.enabled", false);
user_pref("security.warn_viewing_mixed", false);
user_pref("security.warn_viewing_mixed.show_once", false);