~ubuntu-branches/ubuntu/karmic/webkit/karmic-proposed

« back to all changes in this revision

Viewing changes to WebCore/html/HTMLParser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-05-15 18:30:58 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090515183058-50q5exjo9b1kxy9s
Tags: 1.1.7-1
* New upstream release
* debian/libwebkit-1.0-2.symbols:
- updated with the new symbols in 1.1.7
* debian/libwebkit-dev.install, debian/libwebkit-dev.links,
  debian/rules:
- Build, and ship gtk-doc documentation (Closes: #526683)
* debian/copyright:
- updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
              (C) 1997 Torben Weis (weis@kde.org)
4
4
              (C) 1999,2001 Lars Knoll (knoll@kde.org)
5
5
              (C) 2000,2001 Dirk Mueller (mueller@kde.org)
6
 
    Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
 
6
    Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7
7
 
8
8
    This library is free software; you can redistribute it and/or
9
9
    modify it under the terms of the GNU Library General Public
27
27
#include "CharacterNames.h"
28
28
#include "CSSPropertyNames.h"
29
29
#include "CSSValueKeywords.h"
 
30
#include "ChromeClient.h"
30
31
#include "Comment.h"
31
32
#include "Console.h"
32
33
#include "DOMWindow.h"
45
46
#include "HTMLIsIndexElement.h"
46
47
#include "HTMLMapElement.h"
47
48
#include "HTMLNames.h"
 
49
#include "HTMLParserQuirks.h"
48
50
#include "HTMLTableCellElement.h"
49
51
#include "HTMLTableRowElement.h"
50
52
#include "HTMLTableSectionElement.h"
51
53
#include "HTMLTokenizer.h"
52
54
#include "LocalizedStrings.h"
 
55
#include "Page.h"
53
56
#include "Settings.h"
54
57
#include "Text.h"
55
58
#include <wtf/StdLibExtras.h>
56
 
    
 
59
 
57
60
namespace WebCore {
58
61
 
59
62
using namespace HTMLNames;
133
136
    , m_reportErrors(reportErrors)
134
137
    , m_handlingResidualStyleAcrossBlocks(false)
135
138
    , m_inStrayTableContent(0)
 
139
    , m_parserQuirks(m_document->page() ? m_document->page()->chrome()->client()->createHTMLParserQuirks() : 0)
136
140
{
137
141
}
138
142
 
150
154
    , m_reportErrors(false)
151
155
    , m_handlingResidualStyleAcrossBlocks(false)
152
156
    , m_inStrayTableContent(0)
 
157
    , m_parserQuirks(m_document->page() ? m_document->page()->chrome()->client()->createHTMLParserQuirks() : 0)
153
158
{
154
159
    if (frag)
155
160
        frag->ref();
159
164
{
160
165
    freeBlock();
161
166
    if (m_didRefCurrent)
162
 
        m_current->deref(); 
 
167
        m_current->deref();
163
168
}
164
169
 
165
170
void HTMLParser::reset()
181
186
    m_isindexElement = 0;
182
187
 
183
188
    m_skipModeTag = nullAtom;
 
189
    
 
190
    if (m_parserQuirks)
 
191
        m_parserQuirks->reset();
184
192
}
185
193
 
186
194
void HTMLParser::setCurrent(Node* newCurrent) 
332
340
            popBlock(m_blockStack->tagName);
333
341
    }
334
342
 
 
343
    if (m_parserQuirks && !m_parserQuirks->shouldInsertNode(m_current, n))
 
344
        return false;
 
345
 
335
346
    // let's be stupid and just try to insert it.
336
347
    // this should work if the document is well-formed
337
348
    Node* newNode = m_current->addChild(n);
428
439
                }
429
440
                return false;
430
441
            }
431
 
        } else if (h->hasLocalName(titleTag) || h->hasLocalName(styleTag)) {
 
442
        } else if (h->hasLocalName(titleTag) || h->hasLocalName(styleTag) || h->hasLocalName(scriptTag)) {
432
443
            bool createdHead = false;
433
444
            if (!m_head) {
434
445
                createHead();
516
527
                        return false;
517
528
                }
518
529
                if (!m_haveFrameSet) {
 
530
                    // Ensure that head exists.
 
531
                    // But not for older versions of Mail, where the implicit <head> isn't expected - <rdar://problem/6863795>
 
532
                    if (shouldCreateImplicitHead(m_document))
 
533
                        createHead();
 
534
 
 
535
                    popBlock(headTag);
519
536
                    e = new HTMLBodyElement(bodyTag, m_document);
520
537
                    startBody();
521
538
                    insertNode(e);
529
546
            else {
530
547
                // This means the body starts here...
531
548
                if (!m_haveFrameSet) {
 
549
                    ASSERT(currentTagName == headTag);
532
550
                    popBlock(currentTagName);
533
551
                    e = new HTMLBodyElement(bodyTag, m_document);
534
552
                    startBody();
698
716
    // body no longer allowed if we have a frameset
699
717
    if (m_haveFrameSet)
700
718
        return false;
 
719
    
 
720
    // Ensure that head exists (unless parsing a fragment).
 
721
    // But not for older versions of Mail, where the implicit <head> isn't expected - <rdar://problem/6863795>
 
722
    if (!m_isParsingFragment && shouldCreateImplicitHead(m_document))
 
723
        createHead();
 
724
    
701
725
    popBlock(headTag);
702
726
    startBody();
703
727
    return true;
1334
1358
void HTMLParser::popBlock(const AtomicString& tagName, bool reportErrors)
1335
1359
{
1336
1360
    HTMLStackElem* elem = m_blockStack;
1337
 
    
 
1361
 
 
1362
    if (m_parserQuirks && elem && !m_parserQuirks->shouldPopBlock(elem->tagName, tagName))
 
1363
        return;
 
1364
 
1338
1365
    int maxLevel = 0;
1339
1366
 
1340
1367
    while (elem && (elem->tagName != tagName)) {
1509
1536
 
1510
1537
void HTMLParser::createHead()
1511
1538
{
1512
 
    if (m_head || !m_document->documentElement())
 
1539
    if (m_head)
1513
1540
        return;
1514
1541
 
 
1542
    if (!m_document->documentElement()) {
 
1543
        insertNode(new HTMLHtmlElement(htmlTag, m_document));
 
1544
        ASSERT(m_document->documentElement());
 
1545
    }
 
1546
 
1515
1547
    m_head = new HTMLHeadElement(headTag, m_document);
1516
1548
    HTMLElement* body = m_document->body();
1517
1549
    ExceptionCode ec = 0;
1623
1655
        message, lineNumber, m_document->url().string());
1624
1656
}
1625
1657
 
 
1658
#ifdef BUILDING_ON_LEOPARD
 
1659
bool shouldCreateImplicitHead(Document* document)
 
1660
{
 
1661
    ASSERT(document);
 
1662
    
 
1663
    Settings* settings = document->page() ? document->page()->settings() : 0;
 
1664
    return settings ? !settings->needsLeopardMailQuirks() : true;
 
1665
}
 
1666
#elif defined(BUILDING_ON_TIGER)
 
1667
bool shouldCreateImplicitHead(Document* document)
 
1668
{
 
1669
    ASSERT(document);
 
1670
    
 
1671
    Settings* settings = document->page() ? document->page()->settings() : 0;
 
1672
    return settings ? !settings->needsTigerMailQuirks() : true;
 
1673
}
 
1674
#endif
 
1675
 
1626
1676
}