~ubuntu-branches/ubuntu/lucid/webkit/lucid-security

« back to all changes in this revision

Viewing changes to WebCore/dom/Element.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2010-01-20 20:09:57 UTC
  • mfrom: (1.2.7 upstream) (4.3.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100120200957-3ng8lah18c7pmm52
* New upstream release
- Fixes crashes related to clearing the clipboard, which many users were
  experiencing (Closes: #565166)

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "FrameView.h"
43
43
#include "HTMLElement.h"
44
44
#include "HTMLNames.h"
 
45
#include "InspectorController.h"
45
46
#include "NamedNodeMap.h"
46
47
#include "NodeList.h"
47
48
#include "NodeRenderStyle.h"
534
535
 
535
536
    if (localName == idAttributeName().localName())
536
537
        updateId(old ? old->value() : nullAtom, value);
537
 
    
 
538
 
538
539
    if (old && value.isNull())
539
540
        namedAttrMap->removeAttribute(old->name());
540
541
    else if (!old && !value.isNull())
543
544
        old->setValue(value);
544
545
        attributeChanged(old);
545
546
    }
 
547
 
 
548
#if ENABLE(INSPECTOR)
 
549
    if (Page* page = document()->page()) {
 
550
        if (InspectorController* inspectorController = page->inspectorController())
 
551
            inspectorController->didModifyDOMAttr(this);
 
552
    }
 
553
#endif
546
554
}
547
555
 
548
556
void Element::setAttribute(const QualifiedName& name, const AtomicString& value, ExceptionCode&)
554
562
 
555
563
    if (name == idAttributeName())
556
564
        updateId(old ? old->value() : nullAtom, value);
557
 
    
 
565
 
558
566
    if (old && value.isNull())
559
567
        namedAttrMap->removeAttribute(name);
560
568
    else if (!old && !value.isNull())
563
571
        old->setValue(value);
564
572
        attributeChanged(old);
565
573
    }
 
574
 
 
575
#if ENABLE(INSPECTOR)
 
576
    if (Page* page = document()->page()) {
 
577
        if (InspectorController* inspectorController = page->inspectorController())
 
578
            inspectorController->didModifyDOMAttr(this);
 
579
    }
 
580
#endif
566
581
}
567
582
 
568
583
PassRefPtr<Attribute> Element::createAttribute(const QualifiedName& name, const AtomicString& value)
578
593
 
579
594
void Element::updateAfterAttributeChanged(Attribute* attr)
580
595
{
581
 
    AXObjectCache* axObjectCache = document()->axObjectCache();
582
 
    if (!axObjectCache->accessibilityEnabled())
 
596
    if (!AXObjectCache::accessibilityEnabled())
583
597
        return;
584
598
 
585
599
    const QualifiedName& attrName = attr->name();
586
600
    if (attrName == aria_activedescendantAttr) {
587
601
        // any change to aria-activedescendant attribute triggers accessibility focus change, but document focus remains intact
588
 
        axObjectCache->handleActiveDescendantChanged(renderer());
 
602
        document()->axObjectCache()->handleActiveDescendantChanged(renderer());
589
603
    } else if (attrName == roleAttr) {
590
604
        // the role attribute can change at any time, and the AccessibilityObject must pick up these changes
591
 
        axObjectCache->handleAriaRoleChanged(renderer());
 
605
        document()->axObjectCache()->handleAriaRoleChanged(renderer());
592
606
    } else if (attrName == aria_valuenowAttr) {
593
607
        // If the valuenow attribute changes, AX clients need to be notified.
594
 
        axObjectCache->postNotification(renderer(), AXObjectCache::AXValueChanged, true);
 
608
        document()->axObjectCache()->postNotification(renderer(), AXObjectCache::AXValueChanged, true);
595
609
    } else if (attrName == aria_labelAttr || attrName == aria_labeledbyAttr || attrName == altAttr || attrName == titleAttr) {
596
610
        // If the content of an element changes due to an attribute change, notify accessibility.
597
 
        axObjectCache->contentChanged(renderer());
 
611
        document()->axObjectCache()->contentChanged(renderer());
598
612
    }
599
613
}
600
614
    
603
617
    if (document()->attached() && document()->styleSelector()->hasSelectorForAttribute(attr->name().localName()))
604
618
        setNeedsStyleRecalc();
605
619
}
606
 
        
607
 
void Element::setAttributeMap(PassRefPtr<NamedNodeMap> list)
 
620
 
 
621
// Returns true is the given attribute is an event handler.
 
622
// We consider an event handler any attribute that begins with "on".
 
623
// It is a simple solution that has the advantage of not requiring any
 
624
// code or configuration change if a new event handler is defined.
 
625
 
 
626
static bool isEventHandlerAttribute(const QualifiedName& name)
 
627
{
 
628
    return name.namespaceURI().isNull() && name.localName().startsWith("on");
 
629
}
 
630
    
 
631
void Element::setAttributeMap(PassRefPtr<NamedNodeMap> list, FragmentScriptingPermission scriptingPermission)
608
632
{
609
633
    document()->incDOMTreeVersion();
610
634
 
624
648
 
625
649
    if (namedAttrMap) {
626
650
        namedAttrMap->m_element = this;
 
651
        // If the element is created as result of a paste or drag-n-drop operation
 
652
        // we want to remove all the script and event handlers.
 
653
        if (scriptingPermission == FragmentScriptingNotAllowed) {
 
654
            unsigned i = 0;
 
655
            while (i < namedAttrMap->length()) {
 
656
                const QualifiedName& attributeName = namedAttrMap->m_attributes[i]->name();
 
657
                if (isEventHandlerAttribute(attributeName)) {
 
658
                    namedAttrMap->m_attributes.remove(i);
 
659
                    continue;
 
660
                }
 
661
                if ((attributeName == hrefAttr || attributeName == srcAttr || attributeName == actionAttr) && protocolIsJavaScript(deprecatedParseURL(namedAttrMap->m_attributes[i]->value())))
 
662
                    namedAttrMap->m_attributes[i]->setValue(nullAtom);
 
663
                i++;
 
664
            }
 
665
        }
627
666
        unsigned len = namedAttrMap->length();
628
667
        for (unsigned i = 0; i < len; i++)
629
668
            attributeChanged(namedAttrMap->m_attributes[i].get());
654
693
    return m_tagName.toString();
655
694
}
656
695
 
657
 
void Element::setPrefix(const AtomicString &_prefix, ExceptionCode& ec)
 
696
void Element::setPrefix(const AtomicString& prefix, ExceptionCode& ec)
658
697
{
659
698
    ec = 0;
660
 
    checkSetPrefix(_prefix, ec);
 
699
    checkSetPrefix(prefix, ec);
661
700
    if (ec)
662
701
        return;
663
702
 
664
 
    m_tagName.setPrefix(_prefix);
 
703
    m_tagName.setPrefix(prefix.isEmpty() ? AtomicString() : prefix);
665
704
}
666
705
 
667
706
KURL Element::baseURI() const
1005
1044
void Element::dispatchAttrRemovalEvent(Attribute*)
1006
1045
{
1007
1046
    ASSERT(!eventDispatchForbidden());
 
1047
 
1008
1048
#if 0
1009
1049
    if (!document()->hasListenerType(Document::DOMATTRMODIFIED_LISTENER))
1010
1050
        return;
1017
1057
void Element::dispatchAttrAdditionEvent(Attribute*)
1018
1058
{
1019
1059
    ASSERT(!eventDispatchForbidden());
 
1060
 
1020
1061
#if 0
1021
1062
    if (!document()->hasListenerType(Document::DOMATTRMODIFIED_LISTENER))
1022
1063
        return;
1156
1197
        if (ec == NOT_FOUND_ERR)
1157
1198
            ec = 0;
1158
1199
    }
 
1200
    
 
1201
#if ENABLE(INSPECTOR)
 
1202
    if (Page* page = document()->page()) {
 
1203
        if (InspectorController* inspectorController = page->inspectorController())
 
1204
            inspectorController->didModifyDOMAttr(this);
 
1205
    }
 
1206
#endif
 
1207
    
1159
1208
}
1160
1209
 
1161
1210
void Element::removeAttributeNS(const String& namespaceURI, const String& localName, ExceptionCode& ec)
1427
1476
 
1428
1477
KURL Element::getURLAttribute(const QualifiedName& name) const
1429
1478
{
1430
 
#ifndef NDEBUG
 
1479
#if !ASSERT_DISABLED
1431
1480
    if (namedAttrMap) {
1432
1481
        if (Attribute* attribute = namedAttrMap->getAttributeItem(name))
1433
1482
            ASSERT(isURLAttribute(attribute));