Provide mechanism to suppress warning dialog when runtime and compile time user.agent propert values disagree, i.e. via
<set-property name="user.agent.runtimeWarning" value="false"/>

Fixes issues: 5861

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

Review by: jat@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9701 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/UserAgent.gwt.xml b/user/src/com/google/gwt/user/UserAgent.gwt.xml
index 5ae3b6a..f60f650 100644
--- a/user/src/com/google/gwt/user/UserAgent.gwt.xml
+++ b/user/src/com/google/gwt/user/UserAgent.gwt.xml
@@ -23,7 +23,14 @@
 
   <property-provider name="user.agent" generator="com.google.gwt.user.rebind.UserAgentPropertyGenerator"/>
 
-  <!-- Asserts the the compile time value matches the runtime user.agent value -->
+  <!-- Set to false to avoid runtime warnings for mismatched runtime and -->
+  <!-- compile time user.agent values -->
+  <define-configuration-property name="user.agent.runtimeWarning"
+    is-multi-valued="false" />
+  <set-configuration-property name="user.agent.runtimeWarning" value="true"/>
+
+  <!-- Asserts that the compile time user.agent value matches the runtime -->
+  <!-- user.agent value -->
   <entry-point class="com.google.gwt.user.client.UserAgentAsserter" />
 
   <generate-with class="com.google.gwt.user.rebind.UserAgentGenerator">
diff --git a/user/src/com/google/gwt/user/client/UserAgentAsserter.java b/user/src/com/google/gwt/user/client/UserAgentAsserter.java
index 5f04303..aadfd88 100644
--- a/user/src/com/google/gwt/user/client/UserAgentAsserter.java
+++ b/user/src/com/google/gwt/user/client/UserAgentAsserter.java
@@ -33,6 +33,8 @@
    * <code>user.agent</code> selection property value.
    */
   interface UserAgentProperty {
+    boolean getUserAgentRuntimeWarning();
+    
     String getCompileTimeValue();
 
     String getRuntimeValue();
@@ -40,6 +42,10 @@
 
   public void onModuleLoad() {
     UserAgentProperty impl = GWT.create(UserAgentProperty.class);
+    if (!impl.getUserAgentRuntimeWarning()) {
+      return;
+    }
+    
     String compileTimeValue = impl.getCompileTimeValue();
     String runtimeValue = impl.getRuntimeValue();
 
diff --git a/user/src/com/google/gwt/user/rebind/UserAgentGenerator.java b/user/src/com/google/gwt/user/rebind/UserAgentGenerator.java
index 13ea375..f0f3e8b 100644
--- a/user/src/com/google/gwt/user/rebind/UserAgentGenerator.java
+++ b/user/src/com/google/gwt/user/rebind/UserAgentGenerator.java
@@ -17,6 +17,7 @@
 package com.google.gwt.user.rebind;
 
 import com.google.gwt.core.ext.BadPropertyValueException;
+import com.google.gwt.core.ext.ConfigurationProperty;
 import com.google.gwt.core.ext.Generator;
 import com.google.gwt.core.ext.GeneratorContext;
 import com.google.gwt.core.ext.PropertyOracle;
@@ -33,7 +34,9 @@
  * Generator for {@link com.google.gwt.user.client.UserAgentAsserter}.
  */
 public class UserAgentGenerator extends Generator {
-  private static final String PROPERTY_USER_AGENT = "user.agent";
+  static final String PROPERTY_USER_AGENT = "user.agent";
+
+  static final String PROPERTY_USER_AGENT_RUNTIME_WARNING = "user.agent.runtimeWarning";
 
   @Override
   public String generate(TreeLogger logger, GeneratorContext context,
@@ -65,11 +68,22 @@
     }
 
     PropertyOracle propertyOracle = context.getPropertyOracle();
+
+    boolean userAgentRuntimeWarning = true;
+    try {
+      ConfigurationProperty property = 
+          propertyOracle.getConfigurationProperty(PROPERTY_USER_AGENT_RUNTIME_WARNING);
+      userAgentRuntimeWarning = Boolean.valueOf(property.getValues().get(0));
+    } catch (BadPropertyValueException e) {
+      logger.log(TreeLogger.WARN, "Unable to find value for '"
+          + PROPERTY_USER_AGENT_RUNTIME_WARNING + "'", e);
+    }
+
     String userAgentValue;
     try {
-      SelectionProperty userAgentProperty = propertyOracle.getSelectionProperty(
-          logger, PROPERTY_USER_AGENT);
-      userAgentValue = userAgentProperty.getCurrentValue();
+      SelectionProperty property = propertyOracle.getSelectionProperty(logger,
+          PROPERTY_USER_AGENT);
+      userAgentValue = property.getCurrentValue();
     } catch (BadPropertyValueException e) {
       logger.log(TreeLogger.ERROR, "Unable to find value for '"
           + PROPERTY_USER_AGENT + "'", e);
@@ -89,6 +103,14 @@
       SourceWriter sw = composerFactory.createSourceWriter(context, pw);
 
       sw.println();
+      sw.println("public boolean getUserAgentRuntimeWarning() {");
+      sw.indent();
+      sw.println("return " + userAgentRuntimeWarning + ";");
+      sw.outdent();
+      sw.println("}");
+      sw.println();
+
+      sw.println();
       sw.println("public native String getRuntimeValue() /*-{");
       sw.indent();
       UserAgentPropertyGenerator.writeUserAgentPropertyJavaScript(sw);
diff --git a/user/src/com/google/gwt/user/rebind/UserAgentPropertyGenerator.java b/user/src/com/google/gwt/user/rebind/UserAgentPropertyGenerator.java
index 9197e99..03c8df0 100644
--- a/user/src/com/google/gwt/user/rebind/UserAgentPropertyGenerator.java
+++ b/user/src/com/google/gwt/user/rebind/UserAgentPropertyGenerator.java
@@ -96,9 +96,13 @@
       String fallback, SortedSet<ConfigurationProperty> configProperties) {
     for (String value : possibleValues) {
       if (!VALID_VALUES.contains(value)) {
-        logger.log(TreeLogger.ERROR, "Unrecognized user.agent property value '"
+        logger.log(TreeLogger.ERROR, "Unrecognized "
+            + UserAgentGenerator.PROPERTY_USER_AGENT + " property value '"
             + value + "', possibly due to UserAgent.gwt.xml and "
-            + UserAgentPropertyGenerator.class.getName() + " being out of sync");
+            + UserAgentPropertyGenerator.class.getName()
+            + " being out of sync." + " Use <set-configuration-property name=\""
+            + UserAgentGenerator.PROPERTY_USER_AGENT_RUNTIME_WARNING
+            + "\" value=\"false\"/> to suppress this warning message.");
       }
     }