Ver código fonte

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 anos atrás
pai
commit
ca51ee58ac

+ 28
- 1
src/com/vaadin/terminal/gwt/client/VBrowserDetails.java Ver arquivo

private boolean isWebKit = false; private boolean isWebKit = false;
private boolean isPresto = false; private boolean isPresto = false;
private boolean isChromeFrameCapable = false;
private boolean isChromeFrame = false;
private boolean isSafari = false; private boolean isSafari = false;
private boolean isChrome = false; private boolean isChrome = false;
private boolean isFirefox = false; private boolean isFirefox = false;
&& (userAgent.indexOf("webtv") == -1); && (userAgent.indexOf("webtv") == -1);
isFirefox = userAgent.indexOf(" firefox/") != -1; isFirefox = userAgent.indexOf(" firefox/") != -1;
// chromeframe
isChromeFrameCapable = userAgent.indexOf("chromeframe") != -1;
isChromeFrame = isChromeFrameCapable && !isIE;
// Rendering engine version // Rendering engine version
try { try {
if (isGecko) { if (isGecko) {
return isChrome; 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. * Tests if the browser is Opera.
* *
/** /**
* Checks if the browser is so old that it simply won't work with a Vaadin * 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 * @return true if the browser won't work, false if not the browser is
* supported or might work * supported or might work

+ 57
- 0
src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java Ver arquivo



public abstract class AjaxPageHandler implements RequestHandler { 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 { protected class AjaxPageContext implements Serializable {
private final WrappedResponse response; private final WrappedResponse response;
private final WrappedRequest request; private final WrappedRequest request;
WrappedRequest request, WrappedResponse response) WrappedRequest request, WrappedResponse response)
throws IOException { 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? // TODO Should all urls be handled here?
int rootId; int rootId;
try { try {
return true; 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, protected final void writeAjaxPage(WrappedRequest request,
WrappedResponse response, Application application, int rootId) WrappedResponse response, Application application, int rootId)
throws IOException, JSONException { throws IOException, JSONException {

+ 28
- 0
src/com/vaadin/terminal/gwt/server/WebBrowser.java Ver arquivo

return browserDetails.isChrome(); 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. * Gets the major version of the browser the user is using.
* *

+ 16
- 2
src/com/vaadin/terminal/gwt/server/WrappedHttpServletRequest.java Ver arquivo



import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;


import com.vaadin.Application;
import com.vaadin.terminal.CombinedRequest; import com.vaadin.terminal.CombinedRequest;
import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.DeploymentConfiguration;
import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedRequest;
} }


public BrowserDetails getBrowserDetails() { 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() { public Locale getLocale() {

Carregando…
Cancelar
Salvar