| /* |
| * Copyright 2011 Google Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| * use this file except in compliance with the License. You may obtain a copy of |
| * the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations under |
| * the License. |
| */ |
| |
| package com.google.gwt.user.client; |
| |
| import com.google.gwt.core.client.EntryPoint; |
| import com.google.gwt.core.client.GWT; |
| |
| /** |
| * Helper class, which, during startup, asserts that the specified user.agent |
| * selection property value indeed matches the expected value for this browser / |
| * user agent, thus avoid long hours debugging strange error messages when a |
| * single user agent compile, typically created for testing purposes, ends up |
| * being executed in the wrong browser. |
| */ |
| public class UserAgentAsserter implements EntryPoint { |
| |
| /** |
| * Interface to provide both the compile time and runtime |
| * <code>user.agent</code> selection property value. |
| */ |
| interface UserAgentProperty { |
| String getCompileTimeValue(); |
| |
| String getRuntimeValue(); |
| } |
| |
| @Override |
| public void onModuleLoad() { |
| UserAgentProperty impl = GWT.create(UserAgentProperty.class); |
| String compileTimeValue = impl.getCompileTimeValue(); |
| String runtimeValue = impl.getRuntimeValue(); |
| |
| if (!compileTimeValue.equals(runtimeValue)) { |
| displayMismatchWarning(runtimeValue, compileTimeValue); |
| } |
| } |
| |
| /** |
| * Implemented as a JSNI method to avoid potentially using any user agent |
| * specific deferred binding code, since this method is called precisely when |
| * we're somehow executing code from the wrong user.agent permutation. |
| */ |
| private native void displayMismatchWarning(String runtimeValue, |
| String compileTimeValue) /*-{ |
| $wnd.alert("ERROR: Possible problem with your *.gwt.xml module file." |
| + "\nThe compile time user.agent value (" + compileTimeValue |
| + ") does not match the runtime user.agent value (" + runtimeValue |
| + "). Expect more errors.\n"); |
| }-*/; |
| } |