Skip to content

Commit

Permalink
Merge pull request #21 from sciamano/master
Browse files Browse the repository at this point in the history
do not force xulrunner on linux
  • Loading branch information
Xyrio authored Apr 8, 2018
2 parents 3a5bf2c + a4beba1 commit ca5362d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 93 deletions.
18 changes: 15 additions & 3 deletions org.rssowl.ui/src/org/rssowl/ui/internal/ApplicationServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ public class ApplicationServer {

/* Used after all HTTP-Headers */
private static final String CRLF = "\r\n"; //$NON-NLS-1$

/* HTTP status codes */
private static final String HTTP_CODE_200 = "HTTP/1.1 200 OK"; //$NON-NLS-1$

/* HTTP content types */
private static final String HTTP_CONTENT_TYPE_TEXT = "Content-Type: text/html; charset=UTF-8"; //$NON-NLS-1$
private static final String HTTP_CONTENT_TYPE_GIF = "Content-Type: image/gif"; //$NON-NLS-1$

/* Registry of known Viewer */
private static Map<String, ContentViewer> fRegistry = new ConcurrentHashMap<String, ContentViewer>();
Expand Down Expand Up @@ -526,6 +533,11 @@ private void processResourceOperation(Socket socket, String message) {
BufferedOutputStream outS = null;
try {
outS = new BufferedOutputStream(socket.getOutputStream());
outS.write(HTTP_CODE_200.getBytes());
outS.write(CRLF.getBytes());
outS.write(HTTP_CONTENT_TYPE_GIF.getBytes());
outS.write(CRLF.getBytes());
outS.write(CRLF.getBytes());
CoreUtils.copy(OwlUI.class.getResourceAsStream(parameter), outS);
} catch (IOException e) {
/* Ignore */
Expand Down Expand Up @@ -680,14 +692,14 @@ private void reply(Socket socket, String viewerId, Object[] elements) {
if (Application.IS_WINDOWS && portable)
writer.append("HTTP/1.1 205 OK").append(CRLF); //$NON-NLS-1$
else
writer.append("HTTP/1.1 200 OK").append(CRLF); //$NON-NLS-1$
writer.append(HTTP_CODE_200).append(CRLF);

synchronized (RFC_1123_DATE) {
writer.append("Date: ").append(RFC_1123_DATE.format(new Date())).append(CRLF); //$NON-NLS-1$
}

writer.append("Server: " + Owl.APPLICATION_NAME + " Local Server").append(CRLF); //$NON-NLS-1$ //$NON-NLS-2$
writer.append("Content-Type: text/html; charset=UTF-8").append(CRLF); //$NON-NLS-1$
writer.append(HTTP_CONTENT_TYPE_TEXT).append(CRLF);
writer.append("Connection: close").append(CRLF); //$NON-NLS-1$
writer.append("Expires: 0").append(CRLF); //$NON-NLS-1$
writer.write(CRLF);
Expand Down Expand Up @@ -802,4 +814,4 @@ public int getPort() {
public String getHost() {
return LOCALHOST;
}
}
}
93 changes: 3 additions & 90 deletions org.rssowl.ui/src/org/rssowl/ui/internal/util/CBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@

package org.rssowl.ui.internal.util;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
Expand Down Expand Up @@ -60,11 +58,9 @@
import org.rssowl.ui.internal.editors.browser.WebBrowserContext;
import org.rssowl.ui.internal.editors.browser.WebBrowserView;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -96,11 +92,6 @@ public class CBrowser {
/* System Property to force disable XULRunner even if registered */
private static final String DISABLE_XULRUNNER = "noXulrunner"; //$NON-NLS-1$

/* Local XULRunner Runtime Constants */
private static final String XULRUNNER_PATH_PROPERTY = "org.eclipse.swt.browser.XULRunnerPath"; //$NON-NLS-1$
private static final String XULRUNNER_DIR = "xulrunner"; //$NON-NLS-1$
private static boolean fgXulrunnerRuntimeTested = false;

/* Delay in millies after a refresh until to allow ext. navigation again (see Bug 1429) */
private static final long REFRESH_NAVIGATION_DELAY = 3000;

Expand Down Expand Up @@ -224,51 +215,9 @@ private Browser createBrowser(Composite parent, int style) {
}
}

/* Linux: Multiple approaches to get XULRunner right */
if (Application.IS_LINUX && !fgXulrunnerRuntimeTested) {
boolean xulrunnerPathSpecified = (System.getProperty(XULRUNNER_PATH_PROPERTY) != null);

/* 1.) User has XULRunner path explicitly set, try it first */
if (xulrunnerPathSpecified) {
try {
browser = new Browser(parent, styleForLinux(style));
} catch (SWTError e) {
Activator.safeLogInfo(NLS.bind("Error loading XULRunner from system property (''{0}'')", System.getProperty(XULRUNNER_PATH_PROPERTY))); //Ignored (we continue trying) //$NON-NLS-1$
}
}

/* 2.) Fallback to default OS XULRunner runtime */
if (browser == null) {
if (xulrunnerPathSpecified)
System.clearProperty(XULRUNNER_PATH_PROPERTY);

try {
browser = new Browser(parent, styleForLinux(style));
} catch (SWTError e) {
Activator.safeLogInfo("Error loading system default XULRunner"); //Ignored (we continue trying) //$NON-NLS-1$
}
}

/* 3.) Try with deployed XULRunner runtime */
if (browser == null) {
File xulRunnerRuntimeDir = getXULRunnerRuntimeDir();
if (xulRunnerRuntimeDir != null) {
System.setProperty(XULRUNNER_PATH_PROPERTY, xulRunnerRuntimeDir.toString());

try {
browser = new Browser(parent, styleForLinux(style));
} catch (SWTError e) {
Activator.safeLogInfo("Error loading XULRunner from bundled version"); //Ignored (we continue trying) //$NON-NLS-1$
}
}
}

fgXulrunnerRuntimeTested = true; //Avoid redundant lookup if XULRunner runtime found
}

/* Any other OS, or Mozilla unavailable, use default */
if (browser == null)
browser = new Browser(parent, styleForLinux(style));
browser = new Browser(parent, style);

/* Add Focusless Scroll Hook on Windows */
if (Application.IS_WINDOWS)
Expand Down Expand Up @@ -302,42 +251,6 @@ public void widgetDisposed(DisposeEvent e) {
return browser;
}

private File getXULRunnerRuntimeDir() {

/* Retrieve Install Location */
Location installLocation = Platform.getInstallLocation();
if (installLocation == null || installLocation.getURL() == null)
return null;

/* Retrieve Program Dir as File Object */
File programDir = toFile(installLocation.getURL());
if (programDir == null || !programDir.isDirectory() || !programDir.exists())
return null;

/* Retrieve the XULRunner Directory */
File xulrunnerDir = new File(programDir, XULRUNNER_DIR);
if (!xulrunnerDir.exists() || !xulrunnerDir.isDirectory())
return null;

return xulrunnerDir;
}

private File toFile(URL url) {
try {
return new File(url.toURI());
} catch (URISyntaxException e) {
return new File(url.getPath());
}
}

/* If RSSOwl runs with SWT 3.7, force use of Mozilla over WebKit */
private int styleForLinux(int style) {
if (Application.IS_LINUX && SWT.getVersion() >= 3700)
return style | SWT.MOZILLA;

return style;
}

private Method callCoInternetSetFeatureEnabled(Method method, int feature, int scope, boolean enable) {
if (!fgCoInternetSetFeatureError && Application.IS_WINDOWS && !useMozillaOnWindows()) {
try {
Expand Down Expand Up @@ -621,7 +534,7 @@ public void open(WindowEvent event) {
if (OwlUI.useExternalBrowser()) {

/* Avoid IE being loaded from SWT on Windows */
final Browser tempBrowser = new Browser(fBrowser.getShell(), useMozilla ? SWT.MOZILLA : styleForLinux(SWT.NONE));
final Browser tempBrowser = new Browser(fBrowser.getShell(), useMozilla ? SWT.MOZILLA : SWT.NONE);
tempBrowser.setVisible(false);
event.browser = tempBrowser;
tempBrowser.getDisplay().timerExec(useMozilla ? MOZILLA_BROWSER_URL_DELAY : IE_BROWSER_URL_DELAY, new Runnable() {
Expand All @@ -648,7 +561,7 @@ public void run() {

/* Open internal Browser in same Browser */
else {
final Browser tempBrowser = new Browser(fBrowser.getShell(), useMozilla ? SWT.MOZILLA : styleForLinux(SWT.NONE));
final Browser tempBrowser = new Browser(fBrowser.getShell(), useMozilla ? SWT.MOZILLA : SWT.NONE);
tempBrowser.setVisible(false);
event.browser = tempBrowser;
tempBrowser.getDisplay().timerExec(useMozilla ? MOZILLA_BROWSER_URL_DELAY : IE_BROWSER_URL_DELAY, new Runnable() {
Expand Down

0 comments on commit ca5362d

Please sign in to comment.