]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed flash issues and cleans up the Flash related code. #6501
authorJohn Alhroos <john.ahlroos@itmill.com>
Tue, 8 Mar 2011 07:45:14 +0000 (07:45 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Tue, 8 Mar 2011 07:45:14 +0000 (07:45 +0000)
svn changeset:17651/svn branch:6.5

src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java

index f1d61029d49e85aba021a0bb5a511913cf7ab370..8b18439b52738b9605db51269c97c6ec7dc6f78b 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 @ITMillApache2LicenseForJavaFiles@
  */
 
@@ -137,35 +137,9 @@ public class VEmbedded extends HTML implements Paintable {
         } else if (uidl.hasAttribute("mimetype")) {
             final String mime = uidl.getStringAttribute("mimetype");
             if (mime.equals("application/x-shockwave-flash")) {
-                addStyleName(CLASSNAME + "-flash");
-                String html = "<object "
-                        + "type=\"application/x-shockwave-flash\" "
-                        + "width=\"" + width + "\" height=\"" + height + "\">";
+                // Handle embedding of Flash
+                setHTML(createFlashEmbed(uidl));
 
-                Map<String, String> parameters = getParameters(uidl);
-                if (parameters.get("movie") == null) {
-                    parameters.put("movie", getSrc(uidl, client));
-                }
-
-                // Add the parameters to the Object
-                for (String name : parameters.keySet()) {
-                    html += "<param name=\"" + escapeAttribute(name)
-                            + "\" value=\""
-                            + escapeAttribute(parameters.get(name)) + "\"/>";
-                }
-
-                html += "<embed src=\"" + getSrc(uidl, client) + "\" width=\""
-                        + width + "\" height=\"" + height + "\" "
-                        + "type=\"application/x-shockwave-flash\" ";
-
-                // Add the parameters to the Embed
-                for (String name : parameters.keySet()) {
-                    html += escapeAttribute(name) + "=\""
-                            + escapeAttribute(parameters.get(name)) + "\" ";
-                }
-
-                html += "></embed></object>";
-                setHTML(html);
             } else if (mime.equals("image/svg+xml")) {
                 addStyleName(CLASSNAME + "-svg");
                 String data;
@@ -200,6 +174,92 @@ public class VEmbedded extends HTML implements Paintable {
 
     }
 
+    /**
+     * Creates the Object and Embed tags for the Flash plugin so it works
+     * cross-browser
+     * 
+     * @param uidl
+     *            The UIDL
+     * @return Tags concatenated into a string
+     */
+    private String createFlashEmbed(UIDL uidl) {
+        addStyleName(CLASSNAME + "-flash");
+
+        /*
+         * To ensure cross-browser compatibility we are using the twice-cooked
+         * method to embed flash i.e. we add a OBJECT tag for IE ActiveX and
+         * inside it a EMBED for all other browsers.
+         */
+
+        StringBuilder html = new StringBuilder();
+
+        // Start the object tag
+        html.append("<object ");
+
+        /*
+         * Add classid required for ActiveX to recognize the flash. This is a
+         * predefined value which ActiveX recognizes and must be the given
+         * value. More info can be found on
+         * http://kb2.adobe.com/cps/415/tn_4150.html.
+         */
+        html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
+
+        /*
+         * Add codebase required for ActiveX and must be exactly this according
+         * to http://kb2.adobe.com/cps/415/tn_4150.html to work with the above
+         * given classid. Again, see more info on
+         * http://kb2.adobe.com/cps/415/tn_4150.html. Limiting Flash version to
+         * 9.0.0.0 and above.
+         */
+        html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" ");
+
+        // Add width and height
+        html.append("width=\"" + width + "\" ");
+        html.append("height=\"" + height + "\" ");
+
+        html.append("type=\"application/x-shockwave-flash\" ");
+
+        // End object tag
+        html.append(">");
+
+        // Ensure we have an movie parameter
+        Map<String, String> parameters = getParameters(uidl);
+        if (parameters.get("movie") == null) {
+            parameters.put("movie", getSrc(uidl, client));
+        }
+
+        // Add parameters to OBJECT
+        for (String name : parameters.keySet()) {
+            html.append("<param ");
+            html.append("name=\"" + escapeAttribute(name) + "\" ");
+            html.append("value=\"" + escapeAttribute(parameters.get(name))
+                    + "\" ");
+            html.append("/>");
+        }
+
+        // Build inner EMBED tag
+        html.append("<embed ");
+        html.append("src=\"" + getSrc(uidl, client) + "\" ");
+        html.append("width=\"" + width + "\" ");
+        html.append("height=\"" + height + "\" ");
+        html.append("type=\"application/x-shockwave-flash\" ");
+
+        // Add the parameters to the Embed
+        for (String name : parameters.keySet()) {
+            html.append(escapeAttribute(name));
+            html.append("=");
+            html.append("\"" + escapeAttribute(parameters.get(name)) + "\"");
+        }
+
+        // End embed tag
+        html.append("</embed>");
+
+        // End object tag
+        html.append("</object>");
+
+        return html.toString();
+    }
+
     /**
      * Escapes the string so it is safe to write inside an HTML attribute.
      *