// Copyright 2009 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.gwtexpui.user.client;

/**
 * User agent feature tests we don't create permutations for.
 * <p>
 * Some features aren't worth creating full permutations in GWT for, as each new
 * boolean permutation (only two settings) doubles the compile time required. If
 * the setting only affects a couple of lines of JavaScript code, the slightly
 * larger cache files for user agents that lack the functionality requested is
 * trivial compared to the time developers lose building their application.
 */
public class UserAgent {
  /** Does the browser have ShockwaveFlash plugin enabled? */
  public static final boolean hasFlash = hasFlash();

  private static native boolean hasFlash()
  /*-{
    if (navigator.plugins && navigator.plugins.length) {
      if (navigator.plugins['Shockwave Flash'])     return true;
      if (navigator.plugins['Shockwave Flash 2.0']) return true;

    } else if (navigator.mimeTypes && navigator.mimeTypes.length) {
      var mimeType = navigator.mimeTypes['application/x-shockwave-flash'];
      if (mimeType && mimeType.enabledPlugin) return true;

    } else {
      try { new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7'); return true; } catch (e) {}
      try { new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); return true; } catch (e) {}
      try { new ActiveXObject('ShockwaveFlash.ShockwaveFlash');   return true; } catch (e) {}
    }
    return false;
  }-*/;

  private UserAgent() {
  }
}

@@ -620,16 +620,98 @@
 lient;%0A%0A
+import com.google.gwt.core.client.GWT;%0Aimport com.google.gwt.user.client.Window;%0A%0A
 /**%0A * U
@@ -2085,16 +2085,1257 @@
  %7D-*/;%0A%0A
+  /**%0A   * Test for and disallow running this application in an &lt;iframe&gt;.%0A   * %3Cp%3E%0A   * If the application is running within an iframe this method requests a%0A   * browser generated redirect to pop the application out of the iframe into%0A   * the top level window, and then aborts execution by throwing an exception.%0A   * This is call should be placed early within the module's onLoad() method,%0A   * before any real UI can be initialized that an attacking site could try to%0A   * snip out and present in a confusing context.%0A   * %3Cp%3E%0A   * If the break out works, execution will restart automatically in a proper%0A   * top level window, where the script has full control over the display. If%0A   * the break out fails, execution will abort and stop immediately, preventing%0A   * UI widgets from being created, leaving the user with an empty frame.%0A   */%0A  public static void assertNotInIFrame() %7B%0A    if (GWT.isScript() && amInsideIFrame()) %7B%0A      bustOutOfIFrame(Window.Location.getHref());%0A      throw new RuntimeException();%0A    %7D%0A  %7D%0A%0A  private static native boolean amInsideIFrame()%0A  /*-%7B return top.location != $wnd.location; %7D-*/;%0A%0A  private static native void bustOutOfIFrame(String newloc)%0A  /*-%7B top.location.href = newloc %7D-*/;%0A%0A
   privat

Add the break out magic used by Gerrit to prevent embedding in iframes