summaryrefslogtreecommitdiffstats
path: root/WebCore/html/HTMLObjectElement.cpp
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
commit1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch)
tree4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebCore/html/HTMLObjectElement.cpp
parent9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff)
downloadexternal_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebCore/html/HTMLObjectElement.cpp')
-rw-r--r--WebCore/html/HTMLObjectElement.cpp174
1 files changed, 70 insertions, 104 deletions
diff --git a/WebCore/html/HTMLObjectElement.cpp b/WebCore/html/HTMLObjectElement.cpp
index 810496c..694f2d3 100644
--- a/WebCore/html/HTMLObjectElement.cpp
+++ b/WebCore/html/HTMLObjectElement.cpp
@@ -2,8 +2,8 @@
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2000 Stefan Schimanski (1Stein@gmx.de)
- * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
- * Copyright (C) 2007 Trolltech ASA
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -28,30 +28,27 @@
#include "EventNames.h"
#include "ExceptionCode.h"
#include "Frame.h"
-#include "FrameLoader.h"
-#include "FrameLoaderClient.h"
-#include "FrameView.h"
#include "HTMLDocument.h"
#include "HTMLFormElement.h"
#include "HTMLImageLoader.h"
#include "HTMLNames.h"
-#include "Image.h"
#include "MIMETypeRegistry.h"
#include "RenderImage.h"
#include "RenderPartObject.h"
#include "RenderWidget.h"
+#include "ScriptController.h"
#include "Text.h"
+
namespace WebCore {
-using namespace EventNames;
using namespace HTMLNames;
HTMLObjectElement::HTMLObjectElement(Document* doc, bool createdByParser)
- : HTMLPlugInElement(objectTag, doc)
+ : HTMLPlugInImageElement(objectTag, doc)
+ , m_docNamedItem(true)
, m_needWidgetUpdate(!createdByParser)
, m_useFallbackContent(false)
- , m_docNamedItem(true)
{
}
@@ -59,40 +56,24 @@ HTMLObjectElement::~HTMLObjectElement()
{
#ifdef ANDROID_FIX
// addressing webkit bug, http://bugs.webkit.org/show_bug.cgi?id=16512
- // ensure the oldNameAttr and oldIdAttr are removed from HTMLDocument's NameCountMap
+ // ensure that m_name and m_id are removed from HTMLDocument's NameCountMap
if (oldNameIdCount && document()->isHTMLDocument()) {
HTMLDocument* doc = static_cast<HTMLDocument*>(document());
- doc->removeNamedItem(oldNameAttr);
- doc->removeDocExtraNamedItem(oldIdAttr);
+ doc->removeNamedItem(m_name);
+ doc->removeExtraNamedItem(m_id);
}
#endif
-#if USE(JAVASCRIPTCORE_BINDINGS)
- // m_instance should have been cleaned up in detach().
- ASSERT(!m_instance);
-#endif
}
-#if USE(JAVASCRIPTCORE_BINDINGS)
-KJS::Bindings::Instance *HTMLObjectElement::getInstance() const
+RenderWidget* HTMLObjectElement::renderWidgetForJSBindings() const
{
- Frame* frame = document()->frame();
- if (!frame)
- return 0;
-
- if (m_instance)
- return m_instance.get();
-
RenderWidget* renderWidget = (renderer() && renderer()->isWidget()) ? static_cast<RenderWidget*>(renderer()) : 0;
if (renderWidget && !renderWidget->widget()) {
document()->updateLayoutIgnorePendingStylesheets();
renderWidget = (renderer() && renderer()->isWidget()) ? static_cast<RenderWidget*>(renderer()) : 0;
- }
- if (renderWidget && renderWidget->widget())
- m_instance = frame->createScriptInstanceForWidget(renderWidget->widget());
-
- return m_instance.get();
+ }
+ return renderWidget;
}
-#endif
void HTMLObjectElement::parseMappedAttribute(MappedAttribute *attr)
{
@@ -121,25 +102,23 @@ void HTMLObjectElement::parseMappedAttribute(MappedAttribute *attr)
if (renderer())
m_needWidgetUpdate = true;
} else if (attr->name() == onloadAttr) {
- setHTMLEventListener(loadEvent, attr);
- } else if (attr->name() == onunloadAttr) {
- setHTMLEventListener(unloadEvent, attr);
+ setInlineEventListenerForTypeAndAttribute(eventNames().loadEvent, attr);
} else if (attr->name() == nameAttr) {
- String newNameAttr = attr->value();
- if (isDocNamedItem() && inDocument() && document()->isHTMLDocument()) {
- HTMLDocument *doc = static_cast<HTMLDocument *>(document());
- doc->removeNamedItem(oldNameAttr);
- doc->addNamedItem(newNameAttr);
- }
- oldNameAttr = newNameAttr;
+ const AtomicString& newName = attr->value();
+ if (isDocNamedItem() && inDocument() && document()->isHTMLDocument()) {
+ HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+ document->removeNamedItem(m_name);
+ document->addNamedItem(newName);
+ }
+ m_name = newName;
} else if (attr->name() == idAttr) {
- String newIdAttr = attr->value();
+ const AtomicString& newId = attr->value();
if (isDocNamedItem() && inDocument() && document()->isHTMLDocument()) {
- HTMLDocument* doc = static_cast<HTMLDocument*>(document());
- doc->removeDocExtraNamedItem(oldIdAttr);
- doc->addDocExtraNamedItem(newIdAttr);
+ HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+ document->removeExtraNamedItem(m_id);
+ document->addExtraNamedItem(newId);
}
- oldIdAttr = newIdAttr;
+ m_id = newId;
// also call superclass
HTMLPlugInElement::parseMappedAttribute(attr);
} else
@@ -180,15 +159,18 @@ void HTMLObjectElement::attach()
if (!m_imageLoader)
m_imageLoader.set(new HTMLImageLoader(this));
m_imageLoader->updateFromElement();
- if (renderer()) {
- RenderImage* imageObj = static_cast<RenderImage*>(renderer());
- imageObj->setCachedImage(m_imageLoader->image());
- }
+ // updateForElement() may have changed us to use fallback content and called detach() and attach().
+ if (m_useFallbackContent)
+ return;
+
+ if (renderer())
+ static_cast<RenderImage*>(renderer())->setCachedImage(m_imageLoader->image());
}
}
void HTMLObjectElement::updateWidget()
{
+ document()->updateRendering();
if (m_needWidgetUpdate && renderer() && !m_useFallbackContent && !isImageType())
static_cast<RenderPartObject*>(renderer())->updateWidget(true);
}
@@ -205,26 +187,21 @@ void HTMLObjectElement::finishParsingChildren()
void HTMLObjectElement::detach()
{
- if (attached() && renderer() && !m_useFallbackContent) {
+ if (attached() && renderer() && !m_useFallbackContent)
// Update the widget the next time we attach (detaching destroys the plugin).
m_needWidgetUpdate = true;
- }
-
-#if USE(JAVASCRIPTCORE_BINDINGS)
- m_instance = 0;
-#endif
HTMLPlugInElement::detach();
}
void HTMLObjectElement::insertedIntoDocument()
{
if (isDocNamedItem() && document()->isHTMLDocument()) {
- HTMLDocument *doc = static_cast<HTMLDocument *>(document());
- doc->addNamedItem(oldNameAttr);
- doc->addDocExtraNamedItem(oldIdAttr);
+ HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+ document->addNamedItem(m_name);
+ document->addExtraNamedItem(m_id);
#ifdef ANDROID_FIX
// addressing webkit bug, http://bugs.webkit.org/show_bug.cgi?id=16512
- // ensure the oldNameAttr and oldIdAttr are removed from HTMLDocument's NameCountMap
+ // ensure that m_name and m_id are removed from HTMLDocument's NameCountMap
oldNameIdCount++;
#endif
}
@@ -235,12 +212,12 @@ void HTMLObjectElement::insertedIntoDocument()
void HTMLObjectElement::removedFromDocument()
{
if (isDocNamedItem() && document()->isHTMLDocument()) {
- HTMLDocument *doc = static_cast<HTMLDocument *>(document());
- doc->removeNamedItem(oldNameAttr);
- doc->removeDocExtraNamedItem(oldIdAttr);
+ HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+ document->removeNamedItem(m_name);
+ document->removeExtraNamedItem(m_id);
#ifdef ANDROID_FIX
// addressing webkit bug, http://bugs.webkit.org/show_bug.cgi?id=16512
- // ensure the oldNameAttr and oldIdAttr are removed from HTMLDocument's NameCountMap
+ // ensure that m_name and m_id are removed from HTMLDocument's NameCountMap
oldNameIdCount--;
#endif
}
@@ -257,19 +234,19 @@ void HTMLObjectElement::recalcStyle(StyleChange ch)
HTMLPlugInElement::recalcStyle(ch);
}
-void HTMLObjectElement::childrenChanged(bool changedByParser)
+void HTMLObjectElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
updateDocNamedItem();
if (inDocument() && !m_useFallbackContent) {
m_needWidgetUpdate = true;
setChanged();
}
- HTMLPlugInElement::childrenChanged(changedByParser);
+ HTMLPlugInElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
}
bool HTMLObjectElement::isURLAttribute(Attribute *attr) const
{
- return (attr->name() == dataAttr || (attr->name() == usemapAttr && attr->value().domString()[0] != '#'));
+ return (attr->name() == dataAttr || (attr->name() == usemapAttr && attr->value().string()[0] != '#'));
}
const QualifiedName& HTMLObjectElement::imageSourceAttributeName() const
@@ -277,34 +254,23 @@ const QualifiedName& HTMLObjectElement::imageSourceAttributeName() const
return dataAttr;
}
-bool HTMLObjectElement::isImageType()
-{
- if (m_serviceType.isEmpty() && m_url.startsWith("data:")) {
- // Extract the MIME type from the data URL.
- int index = m_url.find(';');
- if (index == -1)
- index = m_url.find(',');
- if (index != -1) {
- int len = index - 5;
- if (len > 0)
- m_serviceType = m_url.substring(5, len);
- else
- m_serviceType = "text/plain"; // Data URLs with no MIME type are considered text/plain.
- }
- }
- if (Frame* frame = document()->frame()) {
- KURL completedURL(frame->loader()->completeURL(m_url));
- return frame->loader()->client()->objectContentType(completedURL, m_serviceType) == ObjectContentImage;
- }
-
- return Image::supportsType(m_serviceType);
-}
-
void HTMLObjectElement::renderFallbackContent()
{
if (m_useFallbackContent)
return;
+ // Before we give up and use fallback content, check to see if this is a MIME type issue.
+ if (m_imageLoader && m_imageLoader->image()) {
+ m_serviceType = m_imageLoader->image()->response().mimeType();
+ if (!isImageType()) {
+ // If we don't think we have an image type anymore, then ditch the image loader.
+ m_imageLoader.clear();
+ detach();
+ attach();
+ return;
+ }
+ }
+
// Mark ourselves as using the fallback content.
m_useFallbackContent = true;
@@ -335,13 +301,13 @@ void HTMLObjectElement::updateDocNamedItem()
child = child->nextSibling();
}
if (isNamedItem != wasNamedItem && document()->isHTMLDocument()) {
- HTMLDocument* doc = static_cast<HTMLDocument*>(document());
+ HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
if (isNamedItem) {
- doc->addNamedItem(oldNameAttr);
- doc->addDocExtraNamedItem(oldIdAttr);
+ document->addNamedItem(m_name);
+ document->addExtraNamedItem(m_id);
} else {
- doc->removeNamedItem(oldNameAttr);
- doc->removeDocExtraNamedItem(oldIdAttr);
+ document->removeNamedItem(m_name);
+ document->removeExtraNamedItem(m_id);
}
}
m_docNamedItem = isNamedItem;
@@ -397,7 +363,7 @@ void HTMLObjectElement::setCodeType(const String& value)
setAttribute(codetypeAttr, value);
}
-String HTMLObjectElement::data() const
+KURL HTMLObjectElement::data() const
{
return document()->completeURL(getAttribute(dataAttr));
}
@@ -437,11 +403,6 @@ void HTMLObjectElement::setStandby(const String& value)
setAttribute(standbyAttr, value);
}
-void HTMLObjectElement::setTabIndex(int tabIndex)
-{
- setAttribute(tabindexAttr, String::number(tabIndex));
-}
-
String HTMLObjectElement::type() const
{
return getAttribute(typeAttr);
@@ -481,9 +442,7 @@ bool HTMLObjectElement::containsJavaApplet() const
while (child) {
if (child->isElementNode()) {
Element* e = static_cast<Element*>(child);
- if (e->hasTagName(paramTag) &&
- e->getAttribute(nameAttr).domString().lower() == "type" &&
- MIMETypeRegistry::isJavaAppletMIMEType(e->getAttribute(valueAttr).domString()))
+ if (e->hasTagName(paramTag) && equalIgnoringCase(e->getAttribute(nameAttr), "type") && MIMETypeRegistry::isJavaAppletMIMEType(e->getAttribute(valueAttr).string()))
return true;
else if (e->hasTagName(objectTag) && static_cast<HTMLObjectElement*>(e)->containsJavaApplet())
return true;
@@ -496,4 +455,11 @@ bool HTMLObjectElement::containsJavaApplet() const
return false;
}
+void HTMLObjectElement::getSubresourceAttributeStrings(Vector<String>& urls) const
+{
+ urls.append(data().string());
+ if (useMap().startsWith("#"))
+ urls.append(useMap());
+}
+
}