diff --git a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/clippy/client/CopyableLabel.java b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/clippy/client/CopyableLabel.java index e34814f6ae..a9f437a00d 100644 --- a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/clippy/client/CopyableLabel.java +++ b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/clippy/client/CopyableLabel.java @@ -127,7 +127,7 @@ public class CopyableLabel extends Composite implements HasText { } private void embedMovie() { - if (flashEnabled && UserAgent.hasFlash && text.length() > 0) { + if (flashEnabled && !text.isEmpty() && UserAgent.Flash.isInstalled()) { final String flashVars = "text=" + URL.encodeQueryString(getText()); final SafeHtmlBuilder h = new SafeHtmlBuilder(); diff --git a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/user/client/UserAgent.java b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/user/client/UserAgent.java index 02ba9aeac5..15983050fe 100644 --- a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/user/client/UserAgent.java +++ b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/user/client/UserAgent.java @@ -27,26 +27,42 @@ import com.google.gwt.user.client.Window; * 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(); + public static class Flash { + private static boolean checked; + private static boolean installed; - 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) {} + /** + * Does the browser have ShockwaveFlash plugin installed? + *

+ * This method may still return true if the user has disabled Flash or set + * the plugin to "click to run". + */ + public static boolean isInstalled() { + if (!checked) { + installed = hasFlash(); + checked = true; + } + return installed; } - return false; - }-*/; + + 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; + }-*/; + } /** * Test for and disallow running this application in an <iframe>.