Support withCredentials attribute for XHR requests (Chrome 3+, Firefox 3.5+, Opera12+, Safari 4+, Internet Explorer 10+)

Review at http://gwt-code-reviews.appspot.com/1879804

Review by: cromwellian@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11471 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/http/client/RequestBuilder.java b/user/src/com/google/gwt/http/client/RequestBuilder.java
index 27685cd..3168a8d 100644
--- a/user/src/com/google/gwt/http/client/RequestBuilder.java
+++ b/user/src/com/google/gwt/http/client/RequestBuilder.java
@@ -91,6 +91,11 @@
   private final String httpMethod;
 
   /**
+   * Whether to include credentials for a Cross Origin Request.
+   */
+  private boolean includeCredentials;
+
+  /**
    * Password to use when opening a JavaScript XmlHttpRequest object.
    */
   private String password;
@@ -355,6 +360,15 @@
   }
 
   /**
+   * Sets whether the cross origin request will include credentials.
+   *
+   * @param withCredentials whether to include credentials in XHR
+   */
+  public void setIncludeCredentials(boolean includeCredentials) {
+    this.includeCredentials = includeCredentials;
+  }
+
+  /**
    * Sends an HTTP request based on the current builder configuration. If no
    * request headers have been set, the header "Content-Type" will be used with
    * a value of "text/plain; charset=utf-8".
@@ -384,6 +398,9 @@
     }
 
     setHeaders(xmlHttpRequest);
+    if (includeCredentials) {
+      xmlHttpRequest.setWithCredentials(true);
+    }
 
     final Request request = new Request(xmlHttpRequest, timeoutMillis, callback);
 
diff --git a/user/src/com/google/gwt/xhr/client/XMLHttpRequest.java b/user/src/com/google/gwt/xhr/client/XMLHttpRequest.java
index d3e4c95..11584a9 100644
--- a/user/src/com/google/gwt/xhr/client/XMLHttpRequest.java
+++ b/user/src/com/google/gwt/xhr/client/XMLHttpRequest.java
@@ -366,6 +366,18 @@
   }-*/;
 
   /**
+   * Sets withCredentials attribute.
+   * <p>
+   * See <a href="http://www.w3.org/TR/XMLHttpRequest/#the-withcredentials-attribute"
+   * >http://www.w3.org/TR/XMLHttpRequest/#the-withcredentials-attribute</a>.
+   *
+   * @param withCredentials whether to include credentials in XHR
+   */
+  public final native void setWithCredentials(boolean withCredentials) /*-{
+    this.xmlHttpRequest.withCredentials = withCredentials;
+  }-*/;
+
+  /**
    * Sets the response type.
    * <p>
    * See <a href="http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute"