1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*
@VaadinApache2LicenseForJavaFiles@
*/
package com.vaadin.terminal.gwt.client.ui.embedded;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HTML;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ComponentConnector;
import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VConsole;
public class VEmbedded extends HTML {
public static String CLASSNAME = "v-embedded";
protected Element browserElement;
protected String type;
protected String mimetype;
protected ApplicationConnection client;
public VEmbedded() {
setStyleName(CLASSNAME);
}
/**
* 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
*/
protected String createFlashEmbed(UIDL uidl) {
/*
* 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. Allow user to override
* this by setting his own classid.
*/
if (uidl.hasAttribute("classid")) {
html.append("classid=\""
+ Util.escapeAttribute(uidl.getStringAttribute("classid"))
+ "\" ");
} else {
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
* 6.0.0.0 and above. Allow user to override this by setting his own
* codebase
*/
if (uidl.hasAttribute("codebase")) {
html.append("codebase=\""
+ Util.escapeAttribute(uidl.getStringAttribute("codebase"))
+ "\" ");
} else {
html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
}
ComponentConnector paintable = ConnectorMap.get(client).getConnector(
this);
String height = paintable.getState().getHeight();
String width = paintable.getState().getWidth();
// Add width and height
html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
html.append("type=\"application/x-shockwave-flash\" ");
// Codetype
if (uidl.hasAttribute("codetype")) {
html.append("codetype=\""
+ Util.escapeAttribute(uidl.getStringAttribute("codetype"))
+ "\" ");
}
// Standby
if (uidl.hasAttribute("standby")) {
html.append("standby=\""
+ Util.escapeAttribute(uidl.getStringAttribute("standby"))
+ "\" ");
}
// Archive
if (uidl.hasAttribute("archive")) {
html.append("archive=\""
+ Util.escapeAttribute(uidl.getStringAttribute("archive"))
+ "\" ");
}
// 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=\"" + Util.escapeAttribute(name) + "\" ");
html.append("value=\"" + Util.escapeAttribute(parameters.get(name))
+ "\" ");
html.append("/>");
}
// Build inner EMBED tag
html.append("<embed ");
html.append("src=\"" + Util.escapeAttribute(getSrc(uidl, client))
+ "\" ");
html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
html.append("type=\"application/x-shockwave-flash\" ");
// Add the parameters to the Embed
for (String name : parameters.keySet()) {
html.append(Util.escapeAttribute(name));
html.append("=");
html.append("\"" + Util.escapeAttribute(parameters.get(name))
+ "\"");
}
// End embed tag
html.append("></embed>");
if (uidl.hasAttribute(EmbeddedConnector.ALTERNATE_TEXT)) {
html.append(uidl
.getStringAttribute(EmbeddedConnector.ALTERNATE_TEXT));
}
// End object tag
html.append("</object>");
return html.toString();
}
/**
* Returns a map (name -> value) of all parameters in the UIDL.
*
* @param uidl
* @return
*/
protected static Map<String, String> getParameters(UIDL uidl) {
Map<String, String> parameters = new HashMap<String, String>();
Iterator<Object> childIterator = uidl.getChildIterator();
while (childIterator.hasNext()) {
Object child = childIterator.next();
if (child instanceof UIDL) {
UIDL childUIDL = (UIDL) child;
if (childUIDL.getTag().equals("embeddedparam")) {
String name = childUIDL.getStringAttribute("name");
String value = childUIDL.getStringAttribute("value");
parameters.put(name, value);
}
}
}
return parameters;
}
/**
* Helper to return translated src-attribute from embedded's UIDL
*
* @param uidl
* @param client
* @return
*/
protected String getSrc(UIDL uidl, ApplicationConnection client) {
String url = client.translateVaadinUri(uidl.getStringAttribute("src"));
if (url == null) {
return "";
}
return url;
}
@Override
protected void onDetach() {
if (BrowserInfo.get().isIE()) {
// Force browser to fire unload event when component is detached
// from the view (IE doesn't do this automatically)
if (browserElement != null) {
/*
* src was previously set to javascript:false, but this was not
* enough to overcome a bug when detaching an iframe with a pdf
* loaded in IE9. about:blank seems to cause the adobe reader
* plugin to unload properly before the iframe is removed. See
* #7855
*/
DOM.setElementAttribute(browserElement, "src", "about:blank");
}
}
super.onDetach();
}
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
if (DOM.eventGetType(event) == Event.ONLOAD) {
VConsole.log("Embeddable onload");
Util.notifyParentOfSizeChange(this, true);
}
}
}
|