Browse Source

Initial unsupported-browser-warning-page for #7985

Includes support for checking isChromeFrame and isChromeFrameCapable. Warning page can be bypassed with cookie.
Works, but needs more thought, and it seems the (V)BrowserDetails and WebBrowser mess should be simplified somehow.
tags/7.0.0.alpha1
Marc Englund 12 years ago
parent
commit
ca51ee58ac

+ 28
- 1
src/com/vaadin/terminal/gwt/client/VBrowserDetails.java View File

@@ -22,6 +22,9 @@ public class VBrowserDetails implements Serializable {
private boolean isWebKit = false;
private boolean isPresto = false;
private boolean isChromeFrameCapable = false;
private boolean isChromeFrame = false;
private boolean isSafari = false;
private boolean isChrome = false;
private boolean isFirefox = false;
@@ -59,6 +62,10 @@ public class VBrowserDetails implements Serializable {
&& (userAgent.indexOf("webtv") == -1);
isFirefox = userAgent.indexOf(" firefox/") != -1;
// chromeframe
isChromeFrameCapable = userAgent.indexOf("chromeframe") != -1;
isChromeFrame = isChromeFrameCapable && !isIE;
// Rendering engine version
try {
if (isGecko) {
@@ -209,6 +216,24 @@ public class VBrowserDetails implements Serializable {
return isChrome;
}
/**
* Tests if the browser is capable of running ChromeFrame.
*
* @return true if it has ChromeFrame, false otherwise
*/
public boolean isChromeFrameCapable() {
return isChromeFrameCapable;
}
/**
* Tests if the browser is running ChromeFrame.
*
* @return true if it is ChromeFrame, false otherwise
*/
public boolean isChromeFrame() {
return isChromeFrame;
}
/**
* Tests if the browser is Opera.
*
@@ -304,7 +329,9 @@ public class VBrowserDetails implements Serializable {
/**
* Checks if the browser is so old that it simply won't work with a Vaadin
* application.
* application. NOTE that the browser might still be capable of running
* Crome Frame, so you might still want to check
* {@link #isChromeFrameCapable()} if this returns true.
*
* @return true if the browser won't work, false if not the browser is
* supported or might work

+ 57
- 0
src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java View File

@@ -26,6 +26,9 @@ import com.vaadin.ui.Root;

public abstract class AjaxPageHandler implements RequestHandler {

/** Cookie used to ignore browser checks */
private static final String FORCE_LOAD_COOKIE = "vaadinforceload=1";

protected class AjaxPageContext implements Serializable {
private final WrappedResponse response;
private final WrappedRequest request;
@@ -114,6 +117,21 @@ public abstract class AjaxPageHandler implements RequestHandler {
WrappedRequest request, WrappedResponse response)
throws IOException {

if (request.getBrowserDetails() != null) {
// Check if the browser is supported; we'll activate Chrome Frame
// silently if available.
WebBrowser b = request.getBrowserDetails().getWebBrowser();
if (b.isTooOldToFunctionProperly() && !b.isChromeFrameCapable()) {
// bypass if cookie set
String c = request.getHeader("Cookie");
if (c == null || !c.contains(FORCE_LOAD_COOKIE)) {
writeBrowserTooOldPage(request, response);
return true;
}

}
}

// TODO Should all urls be handled here?
int rootId;
try {
@@ -137,6 +155,45 @@ public abstract class AjaxPageHandler implements RequestHandler {
return true;
}

/**
* Writes a page encouraging the user to upgrade to a more current browser.
*
* @param request
* @param response
* @throws IOException
*/
protected void writeBrowserTooOldPage(WrappedRequest request,
WrappedResponse response) throws IOException {
Writer page = response.getWriter();
WebBrowser b = request.getBrowserDetails().getWebBrowser();

page.write("<html><body><h1>I'm sorry, but your browser is not supported</h1>"
+ "<p>The version ("
+ b.getBrowserMajorVersion()
+ "."
+ b.getBrowserMinorVersion()
+ ") of the browser you are using "
+ " is outdated and not supported.</p>"
+ "<p>You should <b>consider upgrading</b> to a more up-to-date browser.</p> "
+ "<p>The most popular browsers are <b>"
+ " <a href=\"https://www.google.com/chrome\">Chrome</a>,"
+ " <a href=\"http://www.mozilla.com/firefox\">Firefox</a>,"
+ (b.isWindows() ? " <a href=\"http://windows.microsoft.com/en-US/internet-explorer/downloads/ie\">Internet Explorer</a>,"
: "")
+ " <a href=\"http://www.opera.com/browser\">Opera</a>"
+ " and <a href=\"http://www.apple.com/safari\">Safari</a>.</b><br/>"
+ "Upgrading to the latest version of one of these <b>will make the web safer, faster and better looking.</b></p>"
+ (b.isIE() ? "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js\"></script>"
+ "<p>If you can not upgrade your browser, please consider trying <a onclick=\"CFInstall.check({mode:'overlay'});return false;\" href=\"http://www.google.com/chromeframe\">Chrome Frame</a>.</p>"
: "") //
+ "<p><sub><a onclick=\"document.cookie='"
+ FORCE_LOAD_COOKIE
+ "';window.location.reload();return false;\" href=\"#\">Continue without updating</a> (not recommended)</sub></p>"
+ "</body>\n" + "</html>");

page.close();
}

protected final void writeAjaxPage(WrappedRequest request,
WrappedResponse response, Application application, int rootId)
throws IOException, JSONException {

+ 28
- 0
src/com/vaadin/terminal/gwt/server/WebBrowser.java View File

@@ -183,6 +183,34 @@ public class WebBrowser implements Terminal {
return browserDetails.isChrome();
}

/**
* Tests whether the user is using Chrome Frame.
*
* @return true if the user is using Chrome Frame, false if the user is not
* using Chrome or if no information on the browser is present
*/
public boolean isChromeFrame() {
if (browserDetails == null) {
return false;
}

return browserDetails.isChromeFrame();
}

/**
* Tests whether the user's browser is Chrome Frame capable.
*
* @return true if the user can use Chrome Frame, false if the user can not
* or if no information on the browser is present
*/
public boolean isChromeFrameCapable() {
if (browserDetails == null) {
return false;
}

return browserDetails.isChromeFrameCapable();
}

/**
* Gets the major version of the browser the user is using.
*

+ 16
- 2
src/com/vaadin/terminal/gwt/server/WrappedHttpServletRequest.java View File

@@ -11,6 +11,7 @@ import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.vaadin.Application;
import com.vaadin.terminal.CombinedRequest;
import com.vaadin.terminal.DeploymentConfiguration;
import com.vaadin.terminal.WrappedRequest;
@@ -102,8 +103,21 @@ public class WrappedHttpServletRequest implements WrappedRequest {
}

public BrowserDetails getBrowserDetails() {
// No browserDetails available for normal requests
return null;
return new BrowserDetails() {
public String getUriFragment() {
return null;
}

public String getWindowName() {
return null;
}

public WebBrowser getWebBrowser() {
WebApplicationContext context = (WebApplicationContext) Application
.getCurrentApplication().getContext();
return context.getBrowser();
}
};
}

public Locale getLocale() {

Loading…
Cancel
Save