diff options
author | Konstantin Tokarev <annulen@yandex.ru> | 2016-08-25 19:20:41 +0300 |
---|---|---|
committer | Konstantin Tokarev <annulen@yandex.ru> | 2017-02-02 12:30:55 +0000 |
commit | 6882a04fb36642862b11efe514251d32070c3d65 (patch) | |
tree | b7959826000b061fd5ccc7512035c7478742f7b0 /Source/WebCore/html/HTMLEmbedElement.cpp | |
parent | ab6df191029eeeb0b0f16f127d553265659f739e (diff) | |
download | qtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz |
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WebCore/html/HTMLEmbedElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLEmbedElement.cpp | 128 |
1 files changed, 61 insertions, 67 deletions
diff --git a/Source/WebCore/html/HTMLEmbedElement.cpp b/Source/WebCore/html/HTMLEmbedElement.cpp index 1758a45d3..01b59e7db 100644 --- a/Source/WebCore/html/HTMLEmbedElement.cpp +++ b/Source/WebCore/html/HTMLEmbedElement.cpp @@ -24,7 +24,6 @@ #include "config.h" #include "HTMLEmbedElement.h" -#include "Attribute.h" #include "CSSPropertyNames.h" #include "Frame.h" #include "FrameLoader.h" @@ -37,40 +36,47 @@ #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) +inline HTMLEmbedElement::HTMLEmbedElement(const QualifiedName& tagName, Document& document, bool createdByParser) + : HTMLPlugInImageElement(tagName, document, createdByParser) { ASSERT(hasTagName(embedTag)); } -PassRefPtr<HTMLEmbedElement> HTMLEmbedElement::create(const QualifiedName& tagName, Document* document, bool createdByParser) +Ref<HTMLEmbedElement> HTMLEmbedElement::create(const QualifiedName& tagName, Document& document, bool createdByParser) { - return adoptRef(new HTMLEmbedElement(tagName, document, createdByParser)); + return adoptRef(*new HTMLEmbedElement(tagName, document, createdByParser)); } -static inline RenderWidget* findWidgetRenderer(const Node* n) +static inline RenderWidget* findWidgetRenderer(const Node* node) { - if (!n->renderer()) - do - n = n->parentNode(); - while (n && !n->hasTagName(objectTag)); + if (!node->renderer()) { + do { + node = node->parentNode(); + } while (node && !is<HTMLObjectElement>(*node)); + } - if (n && n->renderer() && n->renderer()->isWidget()) - return toRenderWidget(n->renderer()); + if (node && is<RenderWidget>(node->renderer())) + return downcast<RenderWidget>(node->renderer()); - return 0; + return nullptr; } -RenderWidget* HTMLEmbedElement::renderWidgetForJSBindings() const +RenderWidget* HTMLEmbedElement::renderWidgetLoadingPlugin() const { - FrameView* view = document()->view(); - if (!view || (!view->isInLayout() && !view->isPainting())) - document()->updateLayoutIgnorePendingStylesheets(); + FrameView* view = document().view(); + if (!view || (!view->isInRenderTreeLayout() && !view->isPainting())) { + // Needs to load the plugin immediatedly because this function is called + // when JavaScript code accesses the plugin. + // FIXME: <rdar://16893708> Check if dispatching events here is safe. + document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks::Synchronously); + } return findWidgetRenderer(this); } @@ -81,10 +87,10 @@ bool HTMLEmbedElement::isPresentationAttribute(const QualifiedName& name) const return HTMLPlugInImageElement::isPresentationAttribute(name); } -void HTMLEmbedElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style) +void HTMLEmbedElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) { if (name == hiddenAttr) { - if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, "true")) { + if (equalLettersIgnoringASCIICase(value, "yes") || equalLettersIgnoringASCIICase(value, "true")) { addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 0, CSSPrimitiveValue::CSS_PX); addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, 0, CSSPrimitiveValue::CSS_PX); } @@ -95,19 +101,23 @@ void HTMLEmbedElement::collectStyleForPresentationAttribute(const QualifiedName& 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_serviceType = value.string().left(value.find(';')).convertToASCIILowercase(); + // FIXME: The only difference between this and HTMLObjectElement's corresponding + // code is that HTMLObjectElement does setNeedsWidgetUpdate(true). Consider moving + // this up to the HTMLPlugInImageElement to be shared. + } else if (name == codeAttr) { m_url = stripLeadingAndTrailingHTMLSpaces(value); - else if (name == srcAttr) { + // FIXME: Why no call to the image loader? + // FIXME: If both code and src attributes are specified, last one parsed/changed wins. That can't be right! + } else if (name == srcAttr) { m_url = stripLeadingAndTrailingHTMLSpaces(value); + document().updateStyleIfNeeded(); if (renderer() && isImageType()) { if (!m_imageLoader) - m_imageLoader = adoptPtr(new HTMLImageLoader(this)); + m_imageLoader = std::make_unique<HTMLImageLoader>(*this); m_imageLoader->updateFromElementIgnoringPreviousError(); } + // FIXME: If both code and src attributes are specified, last one parsed/changed wins. That can't be right! } else HTMLPlugInImageElement::parseAttribute(name, value); } @@ -117,10 +127,9 @@ void HTMLEmbedElement::parametersForPlugin(Vector<String>& paramNames, Vector<St 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()); + for (const Attribute& attribute : attributesIterator()) { + paramNames.append(attribute.localName().string()); + paramValues.append(attribute.value().string()); } } @@ -154,54 +163,51 @@ void HTMLEmbedElement::updateWidget(PluginCreationOption pluginCreationOption) Vector<String> paramValues; parametersForPlugin(paramNames, paramValues); - RefPtr<HTMLEmbedElement> protect(this); // Loading the plugin might remove us from the document. + Ref<HTMLEmbedElement> protect(*this); // Loading the plugin might remove us from the document. bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(m_url); if (!beforeLoadAllowedLoad) { - if (document()->isPluginDocument()) { + if (is<PluginDocument>(document())) { // Plugins inside plugin documents load differently than other plugins. By the time // we are here in a plugin document, the load of the plugin (which is the plugin document's // main resource) has already started. We need to explicitly cancel the main resource load here. - toPluginDocument(document())->cancelManualPluginLoad(); + downcast<PluginDocument>(document()).cancelManualPluginLoad(); } return; } if (!renderer()) // Do not load the plugin if beforeload removed this element or its renderer. return; - SubframeLoader* loader = document()->frame()->loader()->subframeLoader(); // FIXME: beforeLoad could have detached the renderer! Just like in the <object> case above. - loader->requestObject(this, m_url, getNameAttribute(), m_serviceType, paramNames, paramValues); + requestObject(m_url, m_serviceType, paramNames, paramValues); } -bool HTMLEmbedElement::rendererIsNeeded(const NodeRenderingContext& context) +bool HTMLEmbedElement::rendererIsNeeded(const RenderStyle& style) { - if (isImageType()) - return HTMLPlugInImageElement::rendererIsNeeded(context); - - Frame* frame = document()->frame(); - if (!frame) + if (!fastHasAttribute(typeAttr) && !fastHasAttribute(srcAttr)) return false; + if (isImageType()) + return HTMLPlugInImageElement::rendererIsNeeded(style); + // If my parent is an <object> and is not set to use fallback content, I // should be ignored and not get a renderer. - ContainerNode* p = parentNode(); - if (p && p->hasTagName(objectTag)) { - ASSERT(p->renderer()); - if (!static_cast<HTMLObjectElement*>(p)->useFallbackContent()) { - ASSERT(!p->renderer()->isEmbeddedObject()); + 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) - // Workaround for <rdar://problem/6642221>. - if (Settings* settings = frame->settings()) { - if (settings->usesDashboardBackwardCompatibilityMode()) - return true; - } + // Workaround for <rdar://problem/6642221>. + if (document().frame()->settings().usesDashboardBackwardCompatibilityMode()) + return true; #endif - return HTMLPlugInImageElement::rendererIsNeeded(context); + return HTMLPlugInImageElement::rendererIsNeeded(style); } bool HTMLEmbedElement::isURLAttribute(const Attribute& attribute) const @@ -211,26 +217,14 @@ bool HTMLEmbedElement::isURLAttribute(const Attribute& attribute) const const AtomicString& HTMLEmbedElement::imageSourceURL() const { - return getAttribute(srcAttr); + return fastGetAttribute(srcAttr); } -void HTMLEmbedElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const +void HTMLEmbedElement::addSubresourceAttributeURLs(ListHashSet<URL>& 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); + addSubresourceURL(urls, document().completeURL(fastGetAttribute(srcAttr))); } -#endif } |