com.vaadin.server.UnsupportedBrowserHandler Maven / Gradle / Ivy
/*
* Vaadin Framework 7
*
* Copyright (C) 2000-2024 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See for the full
* license.
*/
package com.vaadin.server;
import java.io.IOException;
import java.io.Writer;
/**
* A {@link RequestHandler} that presents an informative page if the browser in
* use is unsupported. Recognizes Chrome Frame and allow it to be used.
*
*
* This handler is usually added to the application by
* {@link LegacyCommunicationManager}.
*
*/
@SuppressWarnings("serial")
public class UnsupportedBrowserHandler extends SynchronizedRequestHandler {
/** Cookie used to ignore browser checks */
public static final String FORCE_LOAD_COOKIE = "vaadinforceload=1";
@Override
public boolean synchronizedHandleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response) throws IOException {
// Check if the browser is supported
// If Chrome Frame is available we'll assume it's ok
WebBrowser b = session.getBrowser();
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; // request handled
}
}
return false; // pass to next handler
}
/**
* Writes a page encouraging the user to upgrade to a more current browser.
*
* @param request
* @param response
* @throws IOException
*/
protected void writeBrowserTooOldPage(VaadinRequest request,
VaadinResponse response) throws IOException {
Writer page = response.getWriter();
WebBrowser b = VaadinSession.getCurrent().getBrowser();
page.write(
"I'm sorry, but your browser is not supported
"
+ "The version (" + b.getBrowserMajorVersion() + "."
+ b.getBrowserMinorVersion()
+ ") of the browser you are using "
+ " is outdated and not supported.
"
+ "You should consider upgrading to a more up-to-date browser.
"
+ "The most popular browsers are "
+ " Chrome,"
+ " Firefox,"
+ (b.isWindows()
? " Internet Explorer,"
: "")
+ " Opera"
+ " and Safari.
"
+ "Upgrading to the latest version of one of these will make the web safer, faster and better looking.
"
+ (b.isIE()
? ""
+ "If you can not upgrade your browser, please consider trying Chrome Frame.
"
: "") //
+ "Continue without updating (not recommended)
"
+ "\n" + "");
page.close();
}
}