HTMLEmbedElement.cpp [plain text]
#include "config.h"
#include "HTMLEmbedElement.h"
#include "Attribute.h"
#include "CSSPropertyNames.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameView.h"
#include "HTMLImageLoader.h"
#include "HTMLNames.h"
#include "HTMLObjectElement.h"
#include "HTMLParserIdioms.h"
#include "PluginDocument.h"
#include "RenderEmbeddedObject.h"
#include "RenderWidget.h"
#include "Settings.h"
#include "SubframeLoader.h"
#include <wtf/Ref.h>
namespace WebCore {
using namespace HTMLNames;
inline HTMLEmbedElement::HTMLEmbedElement(const QualifiedName& tagName, Document& document, bool createdByParser)
: HTMLPlugInImageElement(tagName, document, createdByParser, ShouldPreferPlugInsForImages)
{
ASSERT(hasTagName(embedTag));
}
PassRefPtr<HTMLEmbedElement> HTMLEmbedElement::create(const QualifiedName& tagName, Document& document, bool createdByParser)
{
return adoptRef(new HTMLEmbedElement(tagName, document, createdByParser));
}
static inline RenderWidget* findWidgetRenderer(const Node* n)
{
if (!n->renderer())
do
n = n->parentNode();
while (n && !n->hasTagName(objectTag));
if (n && n->renderer() && n->renderer()->isWidget())
return toRenderWidget(n->renderer());
return 0;
}
RenderWidget* HTMLEmbedElement::renderWidgetForJSBindings() const
{
FrameView* view = document().view();
if (!view || (!view->isInLayout() && !view->isPainting())) {
document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksSynchronously);
}
return findWidgetRenderer(this);
}
bool HTMLEmbedElement::isPresentationAttribute(const QualifiedName& name) const
{
if (name == hiddenAttr)
return true;
return HTMLPlugInImageElement::isPresentationAttribute(name);
}
void HTMLEmbedElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style)
{
if (name == hiddenAttr) {
if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, "true")) {
addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 0, CSSPrimitiveValue::CSS_PX);
addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, 0, CSSPrimitiveValue::CSS_PX);
}
} else
HTMLPlugInImageElement::collectStyleForPresentationAttribute(name, value, style);
}
void HTMLEmbedElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == typeAttr) {
m_serviceType = value.string().left(value.find(";")).lower();
} else if (name == codeAttr) {
m_url = stripLeadingAndTrailingHTMLSpaces(value);
} else if (name == srcAttr) {
m_url = stripLeadingAndTrailingHTMLSpaces(value);
document().updateStyleIfNeeded();
if (renderer() && isImageType()) {
if (!m_imageLoader)
m_imageLoader = std::make_unique<HTMLImageLoader>(*this);
m_imageLoader->updateFromElementIgnoringPreviousError();
}
} else
HTMLPlugInImageElement::parseAttribute(name, value);
}
void HTMLEmbedElement::parametersForPlugin(Vector<String>& paramNames, Vector<String>& paramValues)
{
if (!hasAttributes())
return;
for (const Attribute& attribute : attributesIterator()) {
paramNames.append(attribute.localName().string());
paramValues.append(attribute.value().string());
}
}
void HTMLEmbedElement::updateWidget(PluginCreationOption pluginCreationOption)
{
ASSERT(!renderEmbeddedObject()->isPluginUnavailable());
ASSERT(needsWidgetUpdate());
setNeedsWidgetUpdate(false);
if (m_url.isEmpty() && m_serviceType.isEmpty())
return;
if (!allowedToLoadFrameURL(m_url))
return;
if (pluginCreationOption == CreateOnlyNonNetscapePlugins && wouldLoadAsNetscapePlugin(m_url, m_serviceType)) {
setNeedsWidgetUpdate(true);
return;
}
Vector<String> paramNames;
Vector<String> paramValues;
parametersForPlugin(paramNames, paramValues);
Ref<HTMLEmbedElement> protect(*this); bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(m_url);
if (!beforeLoadAllowedLoad) {
if (document().isPluginDocument()) {
toPluginDocument(&document())->cancelManualPluginLoad();
}
return;
}
if (!renderer()) return;
requestObject(m_url, m_serviceType, paramNames, paramValues);
}
bool HTMLEmbedElement::rendererIsNeeded(const RenderStyle& style)
{
if (isImageType())
return HTMLPlugInImageElement::rendererIsNeeded(style);
ContainerNode* p = parentNode();
if (p && p->hasTagName(objectTag)) {
if (!p->renderer())
return false;
if (!toHTMLObjectElement(p)->useFallbackContent()) {
ASSERT(!p->renderer()->isEmbeddedObject());
return false;
}
}
#if ENABLE(DASHBOARD_SUPPORT)
if (document().frame()->settings().usesDashboardBackwardCompatibilityMode())
return true;
#endif
return HTMLPlugInImageElement::rendererIsNeeded(style);
}
bool HTMLEmbedElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name() == srcAttr || HTMLPlugInImageElement::isURLAttribute(attribute);
}
const AtomicString& HTMLEmbedElement::imageSourceURL() const
{
return getAttribute(srcAttr);
}
void HTMLEmbedElement::addSubresourceAttributeURLs(ListHashSet<URL>& urls) const
{
HTMLPlugInImageElement::addSubresourceAttributeURLs(urls);
addSubresourceURL(urls, document().completeURL(getAttribute(srcAttr)));
}
}