You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnsupportedBrowserHandler.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.io.IOException;
  18. import java.io.Writer;
  19. /**
  20. * A {@link RequestHandler} that presents an informative page if the browser in
  21. * use is unsupported. Recognizes Chrome Frame and allow it to be used.
  22. *
  23. * <p>
  24. * This handler is usually added to the application by
  25. * {@link LegacyCommunicationManager}.
  26. * </p>
  27. */
  28. @SuppressWarnings("serial")
  29. public class UnsupportedBrowserHandler extends SynchronizedRequestHandler {
  30. /** Cookie used to ignore browser checks */
  31. public static final String FORCE_LOAD_COOKIE = "vaadinforceload=1";
  32. @Override
  33. public boolean synchronizedHandleRequest(VaadinSession session,
  34. VaadinRequest request, VaadinResponse response) throws IOException {
  35. // Check if the browser is supported
  36. // If Chrome Frame is available we'll assume it's ok
  37. WebBrowser b = session.getBrowser();
  38. if (b.isTooOldToFunctionProperly() && !b.isChromeFrameCapable()) {
  39. // bypass if cookie set
  40. String c = request.getHeader("Cookie");
  41. if (c == null || !c.contains(FORCE_LOAD_COOKIE)) {
  42. writeBrowserTooOldPage(request, response);
  43. return true; // request handled
  44. }
  45. }
  46. return false; // pass to next handler
  47. }
  48. /**
  49. * Writes a page encouraging the user to upgrade to a more current browser.
  50. *
  51. * @param request
  52. * @param response
  53. * @throws IOException
  54. */
  55. protected void writeBrowserTooOldPage(VaadinRequest request,
  56. VaadinResponse response) throws IOException {
  57. Writer page = response.getWriter();
  58. WebBrowser b = VaadinSession.getCurrent().getBrowser();
  59. page.write("<html><body><h1>I'm sorry, but your browser is not supported</h1>"
  60. + "<p>The version ("
  61. + b.getBrowserMajorVersion()
  62. + "."
  63. + b.getBrowserMinorVersion()
  64. + ") of the browser you are using "
  65. + " is outdated and not supported.</p>"
  66. + "<p>You should <b>consider upgrading</b> to a more up-to-date browser.</p> "
  67. + "<p>The most popular browsers are <b>"
  68. + " <a href=\"https://www.google.com/chrome\">Chrome</a>,"
  69. + " <a href=\"http://www.mozilla.com/firefox\">Firefox</a>,"
  70. + (b.isWindows() ? " <a href=\"http://windows.microsoft.com/en-US/internet-explorer/downloads/ie\">Internet Explorer</a>,"
  71. : "")
  72. + " <a href=\"http://www.opera.com/browser\">Opera</a>"
  73. + " and <a href=\"http://www.apple.com/safari\">Safari</a>.</b><br/>"
  74. + "Upgrading to the latest version of one of these <b>will make the web safer, faster and better looking.</b></p>"
  75. + (b.isIE() ? "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js\"></script>"
  76. + "<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>"
  77. : "") //
  78. + "<p><sub><a onclick=\"document.cookie='"
  79. + FORCE_LOAD_COOKIE
  80. + "';window.location.reload();return false;\" href=\"#\">Continue without updating</a> (not recommended)</sub></p>"
  81. + "</body>\n" + "</html>");
  82. page.close();
  83. }
  84. }