2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de)
5 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #include "core/html/HTMLEmbedElement.h"
27 #include "core/CSSPropertyNames.h"
28 #include "core/HTMLNames.h"
29 #include "core/dom/Attribute.h"
30 #include "core/dom/ElementTraversal.h"
31 #include "core/dom/shadow/ShadowRoot.h"
32 #include "core/html/HTMLImageLoader.h"
33 #include "core/html/HTMLObjectElement.h"
34 #include "core/html/PluginDocument.h"
35 #include "core/html/parser/HTMLParserIdioms.h"
36 #include "core/rendering/RenderEmbeddedObject.h"
37 #include "core/rendering/RenderWidget.h"
41 using namespace HTMLNames;
43 inline HTMLEmbedElement::HTMLEmbedElement(Document& document, bool createdByParser)
44 : HTMLPlugInElement(embedTag, document, createdByParser, ShouldPreferPlugInsForImages)
46 ScriptWrappable::init(this);
49 PassRefPtrWillBeRawPtr<HTMLEmbedElement> HTMLEmbedElement::create(Document& document, bool createdByParser)
51 RefPtrWillBeRawPtr<HTMLEmbedElement> element = adoptRefWillBeNoop(new HTMLEmbedElement(document, createdByParser));
52 element->ensureUserAgentShadowRoot();
53 return element.release();
56 static inline RenderWidget* findWidgetRenderer(const Node* n)
59 n = Traversal<HTMLObjectElement>::firstAncestor(*n);
61 if (n && n->renderer() && n->renderer()->isWidget())
62 return toRenderWidget(n->renderer());
67 RenderWidget* HTMLEmbedElement::existingRenderWidget() const
69 return findWidgetRenderer(this);
72 bool HTMLEmbedElement::isPresentationAttribute(const QualifiedName& name) const
74 if (name == hiddenAttr)
76 return HTMLPlugInElement::isPresentationAttribute(name);
79 void HTMLEmbedElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
81 if (name == hiddenAttr) {
82 if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, "true")) {
83 addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 0, CSSPrimitiveValue::CSS_PX);
84 addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, 0, CSSPrimitiveValue::CSS_PX);
87 HTMLPlugInElement::collectStyleForPresentationAttribute(name, value, style);
91 void HTMLEmbedElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
93 if (name == typeAttr) {
94 m_serviceType = value.string().lower();
95 size_t pos = m_serviceType.find(";");
97 m_serviceType = m_serviceType.left(pos);
99 requestPluginCreationWithoutRendererIfPossible();
100 } else if (name == codeAttr) {
101 m_url = stripLeadingAndTrailingHTMLSpaces(value);
102 } else if (name == srcAttr) {
103 m_url = stripLeadingAndTrailingHTMLSpaces(value);
104 if (renderer() && isImageType()) {
106 m_imageLoader = HTMLImageLoader::create(this);
107 m_imageLoader->updateFromElement(ImageLoader::UpdateIgnorePreviousError);
110 HTMLPlugInElement::parseAttribute(name, value);
114 void HTMLEmbedElement::parametersForPlugin(Vector<String>& paramNames, Vector<String>& paramValues)
116 AttributeCollection attributes = this->attributes();
117 AttributeCollection::iterator end = attributes.end();
118 for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it) {
119 paramNames.append(it->localName().string());
120 paramValues.append(it->value().string());
124 // FIXME: This should be unified with HTMLObjectElement::updateWidget and
125 // moved down into HTMLPluginElement.cpp
126 void HTMLEmbedElement::updateWidgetInternal()
128 ASSERT(!renderEmbeddedObject()->showsUnavailablePluginIndicator());
129 ASSERT(needsWidgetUpdate());
130 setNeedsWidgetUpdate(false);
132 if (m_url.isEmpty() && m_serviceType.isEmpty())
135 // Note these pass m_url and m_serviceType to allow better code sharing with
136 // <object> which modifies url and serviceType before calling these.
137 if (!allowedToLoadFrameURL(m_url))
140 // FIXME: These should be joined into a PluginParameters class.
141 Vector<String> paramNames;
142 Vector<String> paramValues;
143 parametersForPlugin(paramNames, paramValues);
145 RefPtrWillBeRawPtr<HTMLEmbedElement> protect(this); // Loading the plugin might remove us from the document.
147 // FIXME: Can we not have renderer here now that beforeload events are gone?
151 requestObject(m_url, m_serviceType, paramNames, paramValues);
154 bool HTMLEmbedElement::rendererIsNeeded(const RenderStyle& style)
157 return HTMLPlugInElement::rendererIsNeeded(style);
159 LocalFrame* frame = document().frame();
163 // If my parent is an <object> and is not set to use fallback content, I
164 // should be ignored and not get a renderer.
165 ContainerNode* p = parentNode();
166 if (isHTMLObjectElement(p)) {
167 ASSERT(p->renderer());
168 if (!toHTMLObjectElement(p)->useFallbackContent()) {
169 ASSERT(!p->renderer()->isEmbeddedObject());
173 return HTMLPlugInElement::rendererIsNeeded(style);
176 bool HTMLEmbedElement::isURLAttribute(const Attribute& attribute) const
178 return attribute.name() == srcAttr || HTMLPlugInElement::isURLAttribute(attribute);
181 const QualifiedName& HTMLEmbedElement::subResourceAttributeName() const
186 bool HTMLEmbedElement::isInteractiveContent() const
191 bool HTMLEmbedElement::isExposed() const
193 // http://www.whatwg.org/specs/web-apps/current-work/#exposed
194 for (HTMLObjectElement* object = Traversal<HTMLObjectElement>::firstAncestor(*this); object; object = Traversal<HTMLObjectElement>::firstAncestor(*object)) {
195 if (object->isExposed())