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 "CSSPropertyNames.h"
28 #include "HTMLNames.h"
29 #include "core/dom/Attribute.h"
30 #include "core/dom/shadow/ShadowRoot.h"
31 #include "core/html/HTMLImageLoader.h"
32 #include "core/html/HTMLObjectElement.h"
33 #include "core/html/PluginDocument.h"
34 #include "core/html/parser/HTMLParserIdioms.h"
35 #include "core/rendering/RenderEmbeddedObject.h"
36 #include "core/rendering/RenderWidget.h"
40 using namespace HTMLNames;
42 inline HTMLEmbedElement::HTMLEmbedElement(Document& document, bool createdByParser)
43 : HTMLPlugInElement(embedTag, document, createdByParser, ShouldPreferPlugInsForImages)
45 ScriptWrappable::init(this);
48 PassRefPtrWillBeRawPtr<HTMLEmbedElement> HTMLEmbedElement::create(Document& document, bool createdByParser)
50 RefPtrWillBeRawPtr<HTMLEmbedElement> element = adoptRefWillBeRefCountedGarbageCollected(new HTMLEmbedElement(document, createdByParser));
51 element->ensureUserAgentShadowRoot();
52 return element.release();
55 static inline RenderWidget* findWidgetRenderer(const Node* n)
58 n = Traversal<HTMLObjectElement>::firstAncestor(*n);
60 if (n && n->renderer() && n->renderer()->isWidget())
61 return toRenderWidget(n->renderer());
66 RenderWidget* HTMLEmbedElement::existingRenderWidget() const
68 return findWidgetRenderer(this);
71 bool HTMLEmbedElement::isPresentationAttribute(const QualifiedName& name) const
73 if (name == hiddenAttr)
75 return HTMLPlugInElement::isPresentationAttribute(name);
78 void HTMLEmbedElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
80 if (name == hiddenAttr) {
81 if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, "true")) {
82 addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 0, CSSPrimitiveValue::CSS_PX);
83 addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, 0, CSSPrimitiveValue::CSS_PX);
86 HTMLPlugInElement::collectStyleForPresentationAttribute(name, value, style);
90 void HTMLEmbedElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
92 if (name == typeAttr) {
93 m_serviceType = value.string().lower();
94 size_t pos = m_serviceType.find(";");
96 m_serviceType = m_serviceType.left(pos);
98 requestPluginCreationWithoutRendererIfPossible();
99 } else if (name == codeAttr) {
100 m_url = stripLeadingAndTrailingHTMLSpaces(value);
101 } else if (name == srcAttr) {
102 m_url = stripLeadingAndTrailingHTMLSpaces(value);
103 if (renderer() && isImageType()) {
105 m_imageLoader = adoptPtr(new HTMLImageLoader(this));
106 m_imageLoader->updateFromElementIgnoringPreviousError();
109 HTMLPlugInElement::parseAttribute(name, value);
113 void HTMLEmbedElement::parametersForPlugin(Vector<String>& paramNames, Vector<String>& paramValues)
115 if (!hasAttributes())
118 unsigned attributeCount = this->attributeCount();
119 for (unsigned i = 0; i < attributeCount; ++i) {
120 const Attribute& attribute = attributeItem(i);
121 paramNames.append(attribute.localName().string());
122 paramValues.append(attribute.value().string());
126 // FIXME: This should be unified with HTMLObjectElement::updateWidget and
127 // moved down into HTMLPluginElement.cpp
128 void HTMLEmbedElement::updateWidgetInternal()
130 ASSERT(!renderEmbeddedObject()->showsUnavailablePluginIndicator());
131 ASSERT(needsWidgetUpdate());
132 setNeedsWidgetUpdate(false);
134 if (m_url.isEmpty() && m_serviceType.isEmpty())
137 // Note these pass m_url and m_serviceType to allow better code sharing with
138 // <object> which modifies url and serviceType before calling these.
139 if (!allowedToLoadFrameURL(m_url))
142 // FIXME: These should be joined into a PluginParameters class.
143 Vector<String> paramNames;
144 Vector<String> paramValues;
145 parametersForPlugin(paramNames, paramValues);
147 RefPtr<HTMLEmbedElement> protect(this); // Loading the plugin might remove us from the document.
149 // FIXME: Can we not have renderer here now that beforeload events are gone?
153 requestObject(m_url, m_serviceType, paramNames, paramValues);
156 bool HTMLEmbedElement::rendererIsNeeded(const RenderStyle& style)
159 return HTMLPlugInElement::rendererIsNeeded(style);
161 LocalFrame* frame = document().frame();
165 // If my parent is an <object> and is not set to use fallback content, I
166 // should be ignored and not get a renderer.
167 ContainerNode* p = parentNode();
168 if (isHTMLObjectElement(p)) {
169 ASSERT(p->renderer());
170 if (!toHTMLObjectElement(p)->useFallbackContent()) {
171 ASSERT(!p->renderer()->isEmbeddedObject());
175 return HTMLPlugInElement::rendererIsNeeded(style);
178 bool HTMLEmbedElement::isURLAttribute(const Attribute& attribute) const
180 return attribute.name() == srcAttr || HTMLPlugInElement::isURLAttribute(attribute);
183 const QualifiedName& HTMLEmbedElement::subResourceAttributeName() const
188 const AtomicString HTMLEmbedElement::imageSourceURL() const
190 return getAttribute(srcAttr);
193 bool HTMLEmbedElement::isInteractiveContent() const
198 bool HTMLEmbedElement::isExposed() const
200 // http://www.whatwg.org/specs/web-apps/current-work/#exposed
201 for (HTMLObjectElement* object = Traversal<HTMLObjectElement>::firstAncestor(*this); object; object = Traversal<HTMLObjectElement>::firstAncestor(*object)) {
202 if (object->isExposed())