HTMLEmbedElement.cpp [plain text]
#include "config.h"
#include "HTMLEmbedElement.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/IsoMallocInlines.h>
#include <wtf/Ref.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLEmbedElement);
using namespace HTMLNames;
inline HTMLEmbedElement::HTMLEmbedElement(const QualifiedName& tagName, Document& document)
: HTMLPlugInImageElement(tagName, document)
{
ASSERT(hasTagName(embedTag));
}
Ref<HTMLEmbedElement> HTMLEmbedElement::create(const QualifiedName& tagName, Document& document)
{
auto result = adoptRef(*new HTMLEmbedElement(tagName, document));
result->finishCreating();
return result;
}
Ref<HTMLEmbedElement> HTMLEmbedElement::create(Document& document)
{
return create(embedTag, document);
}
static inline RenderWidget* findWidgetRenderer(const Node* node)
{
if (!node->renderer()) {
do {
node = node->parentNode();
} while (node && !is<HTMLObjectElement>(*node));
}
if (node && is<RenderWidget>(node->renderer()))
return downcast<RenderWidget>(node->renderer());
return nullptr;
}
RenderWidget* HTMLEmbedElement::renderWidgetLoadingPlugin() const
{
RefPtr<FrameView> view = document().view();
if (!view || (!view->layoutContext().isInRenderTreeLayout() && !view->isPainting())) {
document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks::Synchronously);
}
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 (equalLettersIgnoringASCIICase(value, "yes") || equalLettersIgnoringASCIICase(value, "true")) {
addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 0, CSSPrimitiveValue::CSS_PX);
addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, 0, CSSPrimitiveValue::CSS_PX);
}
} else
HTMLPlugInImageElement::collectStyleForPresentationAttribute(name, value, style);
}
static bool hasTypeOrSrc(const HTMLEmbedElement& embed)
{
return embed.hasAttributeWithoutSynchronization(typeAttr) || embed.hasAttributeWithoutSynchronization(srcAttr);
}
void HTMLEmbedElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == typeAttr) {
m_serviceType = value.string().left(value.find(';')).convertToASCIILowercase();
if (renderer() && !hasTypeOrSrc(*this))
invalidateStyle();
} else if (name == codeAttr) {
m_url = stripLeadingAndTrailingHTMLSpaces(value);
} else if (name == srcAttr) {
m_url = stripLeadingAndTrailingHTMLSpaces(value);
updateImageLoaderWithNewURLSoon();
if (renderer() && !hasTypeOrSrc(*this))
invalidateStyle();
} 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(CreatePlugins createPlugins)
{
ASSERT(!renderEmbeddedObject()->isPluginUnavailable());
ASSERT(needsWidgetUpdate());
if (m_url.isEmpty() && m_serviceType.isEmpty()) {
setNeedsWidgetUpdate(false);
return;
}
if (!allowedToLoadFrameURL(m_url)) {
setNeedsWidgetUpdate(false);
return;
}
if (createPlugins == CreatePlugins::No && wouldLoadAsPlugIn(m_url, m_serviceType))
return;
setNeedsWidgetUpdate(false);
Vector<String> paramNames;
Vector<String> paramValues;
parametersForPlugin(paramNames, paramValues);
Ref<HTMLEmbedElement> protectedThis(*this); bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(m_url);
if (!beforeLoadAllowedLoad) {
if (is<PluginDocument>(document())) {
downcast<PluginDocument>(document()).cancelManualPluginLoad();
}
return;
}
if (!renderer()) return;
if (!allowedToLoadFrameURL(m_url))
return;
requestObject(m_url, m_serviceType, paramNames, paramValues);
}
bool HTMLEmbedElement::rendererIsNeeded(const RenderStyle& style)
{
if (!hasTypeOrSrc(*this))
return false;
if (isImageType())
return HTMLPlugInImageElement::rendererIsNeeded(style);
RefPtr<ContainerNode> parent = parentNode();
if (is<HTMLObjectElement>(parent)) {
if (!parent->renderer())
return false;
if (!downcast<HTMLObjectElement>(*parent).useFallbackContent()) {
ASSERT(!parent->renderer()->isEmbeddedObject());
return false;
}
}
#if ENABLE(DASHBOARD_SUPPORT)
if (document().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 attributeWithoutSynchronization(srcAttr);
}
void HTMLEmbedElement::addSubresourceAttributeURLs(ListHashSet<URL>& urls) const
{
HTMLPlugInImageElement::addSubresourceAttributeURLs(urls);
addSubresourceURL(urls, document().completeURL(attributeWithoutSynchronization(srcAttr)));
}
}