Revision: 7055
Author: jlaba...@google.com
Date: Fri Nov 20 06:35:24 2009
Log: tr...@7054 was merged into this branch
   isCookieEnabled sets and retrieves a cookie instead of using  
navigator.cookieEnabled
   svn merge --ignore-ancestry -c7054  
https://google-web-toolkit.googlecode.com/svn/trunk .

Patch by: jlabanca


http://code.google.com/p/google-web-toolkit/source/detail?r=7055

Modified:
  /releases/2.0/branch-info.txt
  /releases/2.0/user/src/com/google/gwt/user/client/Cookies.java
  /releases/2.0/user/src/com/google/gwt/user/client/Window.java
  /releases/2.0/user/test/com/google/gwt/user/client/CookieTest.java

=======================================
--- /releases/2.0/branch-info.txt       Thu Nov 19 20:36:53 2009
+++ /releases/2.0/branch-info.txt       Fri Nov 20 06:35:24 2009
@@ -858,3 +858,7 @@
    Make -remoteUI flag to DevMode undocumented. Clean up other flag help  
text in the compiler.
    svn merge --ignore-ancestry -c7050  
https://google-web-toolkit.googlecode.com/svn/trunk .

+tr...@7054 was merged into this branch
+  isCookieEnabled sets and retrieves a cookie instead of using  
navigator.cookieEnabled
+  svn merge --ignore-ancestry -c7054  
https://google-web-toolkit.googlecode.com/svn/trunk .
+
=======================================
--- /releases/2.0/user/src/com/google/gwt/user/client/Cookies.java      Mon Jun 
  
8 13:11:55 2009
+++ /releases/2.0/user/src/com/google/gwt/user/client/Cookies.java      Fri Nov 
 
20 06:35:24 2009
@@ -39,6 +39,16 @@
    // Used only in JSNI.
    static String rawCookies;

+  /**
+   * Indicates whether or not cookies are enabled.
+   */
+  private static boolean isCookieEnabled = false;
+
+  /**
+   * Indicates whether or not we've checked if cookies are enabled.
+   */
+  private static boolean isCookieChecked = false;
+
    /**
     * Flag that indicates whether cookies should be URIencoded (when set)  
and
     * URIdecoded (when retrieved). Defaults to URIencoding.
@@ -72,6 +82,26 @@
    public static boolean getUriEncode() {
      return uriEncoding;
    }
+
+  /**
+   * Checks whether or not cookies are enabled or disabled.
+   *
+   * @return true if a cookie can be set, false if not
+   */
+  public static boolean isCookieEnabled() {
+    if (!isCookieChecked) {
+      // The only way to know for sure that cookies are enabled is to set  
and
+      // retrieve one. Checking navigator.cookieEnabled may return the  
wrong
+      // value if the browser has security software installed. In IE, it  
alerts
+      // the user of an unspecified security risk when the app is embedded  
in an
+      // iframe.
+      isCookieChecked = true;
+      Cookies.setCookie("__gwtCookieCheck", "isEnabled");
+      isCookieEnabled  
= "isEnabled".equals(Cookies.getCookie("__gwtCookieCheck"));
+      Cookies.removeCookie("__gwtCookieCheck");
+    }
+    return isCookieEnabled;
+  }

    /**
     * Removes the cookie associated with the given name.
=======================================
--- /releases/2.0/user/src/com/google/gwt/user/client/Window.java       Wed Nov 
 
18 15:11:38 2009
+++ /releases/2.0/user/src/com/google/gwt/user/client/Window.java       Fri Nov 
 
20 06:35:24 2009
@@ -389,13 +389,13 @@
      }-*/;

      /**
-     * Gets the navigator.cookieEnabled.
+     * Checks whether or not cookies are enabled or disabled.
       *
-     * @return the window's navigator.cookieEnabled.
+     * @return true if a cookie can be set, false if not
       */
-    public static native boolean isCookieEnabled() /*-{
-      return $wnd.navigator.cookieEnabled;
-    }-*/;
+    public static boolean isCookieEnabled() {
+      return Cookies.isCookieEnabled();
+    }

      /**
       * Tests whether Java is enabled in the current browser.
=======================================
--- /releases/2.0/user/test/com/google/gwt/user/client/CookieTest.java  Thu  
Nov 19 14:17:04 2009
+++ /releases/2.0/user/test/com/google/gwt/user/client/CookieTest.java  Fri  
Nov 20 06:35:24 2009
@@ -99,6 +99,10 @@
      };
      timer.schedule(6000);
    }
+
+  public void testIsCookieEnabled() {
+    assertTrue(Cookies.isCookieEnabled());
+  }

    /**
     * Test that removing cookies works correctly.

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to