com.vaadin.server.UnsupportedBrowserHandler Maven / Gradle / Ivy
/*
* Copyright 2000-2014 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the 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();
}
}