]> source.dussan.org Git - vaadin-framework.git/commitdiff
Initial unsupported-browser-warning-page for #7985
authorMarc Englund <marc@vaadin.com>
Tue, 20 Dec 2011 13:34:03 +0000 (15:34 +0200)
committerMarc Englund <marc@vaadin.com>
Wed, 21 Dec 2011 07:21:36 +0000 (09:21 +0200)
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.

src/com/vaadin/terminal/gwt/client/VBrowserDetails.java
src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java
src/com/vaadin/terminal/gwt/server/WebBrowser.java
src/com/vaadin/terminal/gwt/server/WrappedHttpServletRequest.java

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