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/Ref.h>
namespace WebCore {
using namespace HTMLNames;
inline HTMLEmbedElement::HTMLEmbedElement(const QualifiedName& tagName, Document& document, bool createdByParser)
: HTMLPlugInImageElement(tagName, document, createdByParser)
{
ASSERT(hasTagName(embedTag));
}
Ref<HTMLEmbedElement> HTMLEmbedElement::create(const QualifiedName& tagName, Document& document, bool createdByParser)
{
return adoptRef(*new HTMLEmbedElement(tagName, document, createdByParser));
}
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
{
FrameView* view = document().view();
if (!view || (!view->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);
}
void HTMLEmbedElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == typeAttr) {
m_serviceType = value.string().left(value.find(';')).convertToASCIILowercase();
} 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> protectedThis(*this); bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(m_url);
if (!beforeLoadAllowedLoad) {
if (is<PluginDocument>(document())) {
downcast<PluginDocument>(document()).cancelManualPluginLoad();
}
return;
}
if (!renderer()) return;
requestObject(m_url, m_serviceType, paramNames, paramValues);
}
bool HTMLEmbedElement::rendererIsNeeded(const RenderStyle& style)
{
if (!hasAttributeWithoutSynchronization(typeAttr) && !hasAttributeWithoutSynchronization(srcAttr))
return false;
if (isImageType())
return HTMLPlugInImageElement::rendererIsNeeded(style);
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().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 attributeWithoutSynchronization(srcAttr);
}
void HTMLEmbedElement::addSubresourceAttributeURLs(ListHashSet<URL>& urls) const
{
HTMLPlugInImageElement::addSubresourceAttributeURLs(urls);
addSubresourceURL(urls, document().completeURL(attributeWithoutSynchronization(srcAttr)));
}
}