All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.client.ui.VEmbedded Maven / Gradle / Ivy

Go to download

Vaadin is a web application framework for Rich Internet Applications (RIA). Vaadin enables easy development and maintenance of fast and secure rich web applications with a stunning look and feel and a wide browser support. It features a server-side architecture with the majority of the logic running on the server. Ajax technology is used at the browser-side to ensure a rich and interactive user experience.

There is a newer version: 8.27.1
Show newest version
/*
 * Copyright 2000-2014 Vaadin Ltd.
 * 
 * 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.vaadin.client.ui;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HTML;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorMap;
import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
import com.vaadin.client.VConsole;
import com.vaadin.client.WidgetUtil;
import com.vaadin.shared.ui.embedded.EmbeddedConstants;

public class VEmbedded extends HTML {
    public static String CLASSNAME = "v-embedded";

    /** For internal use only. May be removed or replaced in the future. */
    public Element browserElement;

    /** For internal use only. May be removed or replaced in the future. */
    public String type;

    /** For internal use only. May be removed or replaced in the future. */
    public String mimetype;

    /** For internal use only. May be removed or replaced in the future. */
    public ApplicationConnection client;

    public VEmbedded() {
        setStyleName(CLASSNAME);
    }

    /**
     * Creates the Object and Embed tags for the Flash plugin so it works
     * cross-browser.
     * 

* For internal use only. May be removed or replaced in the future. * * @param uidl * The UIDL * @return Tags concatenated into a string */ public 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(""); // Ensure we have an movie parameter Map 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(""); } // Build inner EMBED tag html.append(""); if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) { html.append(uidl .getStringAttribute(EmbeddedConstants.ALTERNATE_TEXT)); } // End object tag html.append(""); return html.toString(); } /** * Returns a map (name -> value) of all parameters in the UIDL. *

* For internal use only. May be removed or replaced in the future. * * @param uidl * @return */ public static Map getParameters(UIDL uidl) { Map parameters = new HashMap(); Iterator 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 *

* For internal use only. May be removed or replaced in the future. * * @param uidl * @param client * @return */ public 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); } } }