HTMLEmbedElement.cpp [plain text]
#include "config.h"
#include "HTMLEmbedElement.h"
#include "Attribute.h"
#include "CSSPropertyNames.h"
#include "DocumentLoader.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "HTMLDocument.h"
#include "HTMLImageLoader.h"
#include "HTMLNames.h"
#include "HTMLObjectElement.h"
#include "HTMLParserIdioms.h"
#include "PluginDocument.h"
#include "RenderEmbeddedObject.h"
#include "RenderImage.h"
#include "RenderWidget.h"
#include "Settings.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
{
document()->updateLayoutIgnorePendingStylesheets();
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, MutableStylePropertySet* 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().lower();
size_t pos = m_serviceType.find(";");
if (pos != notFound)
m_serviceType = m_serviceType.left(pos);
} else if (name == codeAttr)
m_url = stripLeadingAndTrailingHTMLSpaces(value);
else if (name == srcAttr) {
m_url = stripLeadingAndTrailingHTMLSpaces(value);
if (renderer() && isImageType()) {
if (!m_imageLoader)
m_imageLoader = adoptPtr(new HTMLImageLoader(this));
m_imageLoader->updateFromElementIgnoringPreviousError();
}
} else
HTMLPlugInImageElement::parseAttribute(name, value);
}
void HTMLEmbedElement::parametersForPlugin(Vector<String>& paramNames, Vector<String>& paramValues)
{
if (!hasAttributes())
return;
for (unsigned i = 0; i < attributeCount(); ++i) {
const Attribute* attribute = attributeItem(i);
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);
RefPtr<HTMLEmbedElement> protect(this); bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(m_url);
if (!beforeLoadAllowedLoad) {
if (document()->isPluginDocument()) {
toPluginDocument(document())->cancelManualPluginLoad();
}
return;
}
if (!renderer()) return;
SubframeLoader* loader = document()->frame()->loader()->subframeLoader();
loader->requestObject(this, m_url, getNameAttribute(), m_serviceType, paramNames, paramValues);
}
bool HTMLEmbedElement::rendererIsNeeded(const NodeRenderingContext& context)
{
if (isImageType())
return HTMLPlugInImageElement::rendererIsNeeded(context);
Frame* frame = document()->frame();
if (!frame)
return false;
ContainerNode* p = parentNode();
if (p && p->hasTagName(objectTag)) {
ASSERT(p->renderer());
if (!static_cast<HTMLObjectElement*>(p)->useFallbackContent()) {
ASSERT(!p->renderer()->isEmbeddedObject());
return false;
}
}
#if ENABLE(DASHBOARD_SUPPORT)
if (Settings* settings = frame->settings()) {
if (settings->usesDashboardBackwardCompatibilityMode())
return true;
}
#endif
return HTMLPlugInImageElement::rendererIsNeeded(context);
}
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<KURL>& urls) const
{
HTMLPlugInImageElement::addSubresourceAttributeURLs(urls);
addSubresourceURL(urls, document()->completeURL(getAttribute(srcAttr)));
}
#if ENABLE(MICRODATA)
String HTMLEmbedElement::itemValueText() const
{
return getURLAttribute(srcAttr);
}
void HTMLEmbedElement::setItemValueText(const String& value, ExceptionCode&)
{
setAttribute(srcAttr, value);
}
#endif
}