~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/html/HTMLParser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

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
    Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
7
8
 
8
9
    This library is free software; you can redistribute it and/or
9
10
    modify it under the terms of the GNU Library General Public
27
28
#include "CharacterNames.h"
28
29
#include "CSSPropertyNames.h"
29
30
#include "CSSValueKeywords.h"
 
31
#include "ChromeClient.h"
30
32
#include "Comment.h"
31
33
#include "Console.h"
32
34
#include "DOMWindow.h"
45
47
#include "HTMLIsIndexElement.h"
46
48
#include "HTMLMapElement.h"
47
49
#include "HTMLNames.h"
 
50
#include "HTMLParserQuirks.h"
48
51
#include "HTMLTableCellElement.h"
49
52
#include "HTMLTableRowElement.h"
50
53
#include "HTMLTableSectionElement.h"
51
54
#include "HTMLTokenizer.h"
52
55
#include "LocalizedStrings.h"
 
56
#include "Page.h"
53
57
#include "Settings.h"
54
58
#include "Text.h"
55
59
#include <wtf/StdLibExtras.h>
56
 
    
 
60
 
57
61
namespace WebCore {
58
62
 
59
63
using namespace HTMLNames;
61
65
static const unsigned cMaxRedundantTagDepth = 20;
62
66
static const unsigned cResidualStyleMaxDepth = 200;
63
67
 
 
68
static const int minBlockLevelTagPriority = 3;
 
69
 
 
70
// A cap on the number of tags with priority minBlockLevelTagPriority or higher
 
71
// allowed in m_blockStack. The cap is enforced by adding such new elements as
 
72
// siblings instead of children once it is reached.
 
73
static const size_t cMaxBlockDepth = 4096;
 
74
 
64
75
struct HTMLStackElem : Noncopyable {
65
76
    HTMLStackElem(const AtomicString& t, int lvl, Node* n, bool r, HTMLStackElem* nx)
66
77
        : tagName(t)
113
124
 */
114
125
 
115
126
HTMLParser::HTMLParser(HTMLDocument* doc, bool reportErrors)
116
 
    : document(doc)
117
 
    , current(doc)
118
 
    , didRefCurrent(false)
119
 
    , blockStack(0)
 
127
    : m_document(doc)
 
128
    , m_current(doc)
 
129
    , m_didRefCurrent(false)
 
130
    , m_blockStack(0)
 
131
    , m_blocksInStack(0)
120
132
    , m_hasPElementInScope(NotInScope)
121
 
    , inBody(false)
122
 
    , haveContent(false)
123
 
    , haveFrameSet(false)
 
133
    , m_inBody(false)
 
134
    , m_haveContent(false)
 
135
    , m_haveFrameSet(false)
124
136
    , m_isParsingFragment(false)
125
137
    , m_reportErrors(reportErrors)
126
138
    , m_handlingResidualStyleAcrossBlocks(false)
127
 
    , inStrayTableContent(0)
 
139
    , m_inStrayTableContent(0)
 
140
    , m_parserQuirks(m_document->page() ? m_document->page()->chrome()->client()->createHTMLParserQuirks() : 0)
128
141
{
129
142
}
130
143
 
131
144
HTMLParser::HTMLParser(DocumentFragment* frag)
132
 
    : document(frag->document())
133
 
    , current(frag)
134
 
    , didRefCurrent(true)
135
 
    , blockStack(0)
 
145
    : m_document(frag->document())
 
146
    , m_current(frag)
 
147
    , m_didRefCurrent(true)
 
148
    , m_blockStack(0)
 
149
    , m_blocksInStack(0)
136
150
    , m_hasPElementInScope(NotInScope)
137
 
    , inBody(true)
138
 
    , haveContent(false)
139
 
    , haveFrameSet(false)
 
151
    , m_inBody(true)
 
152
    , m_haveContent(false)
 
153
    , m_haveFrameSet(false)
140
154
    , m_isParsingFragment(true)
141
155
    , m_reportErrors(false)
142
156
    , m_handlingResidualStyleAcrossBlocks(false)
143
 
    , inStrayTableContent(0)
 
157
    , m_inStrayTableContent(0)
 
158
    , m_parserQuirks(m_document->page() ? m_document->page()->chrome()->client()->createHTMLParserQuirks() : 0)
144
159
{
145
160
    if (frag)
146
161
        frag->ref();
149
164
HTMLParser::~HTMLParser()
150
165
{
151
166
    freeBlock();
152
 
    if (didRefCurrent) 
153
 
        current->deref(); 
 
167
    if (m_didRefCurrent)
 
168
        m_current->deref();
154
169
}
155
170
 
156
171
void HTMLParser::reset()
157
172
{
158
173
    ASSERT(!m_isParsingFragment);
159
174
 
160
 
    setCurrent(document);
 
175
    setCurrent(m_document);
161
176
 
162
177
    freeBlock();
163
178
 
164
 
    inBody = false;
165
 
    haveFrameSet = false;
166
 
    haveContent = false;
167
 
    inStrayTableContent = 0;
 
179
    m_inBody = false;
 
180
    m_haveFrameSet = false;
 
181
    m_haveContent = false;
 
182
    m_inStrayTableContent = 0;
168
183
 
169
184
    m_currentFormElement = 0;
170
185
    m_currentMapElement = 0;
171
 
    head = 0;
 
186
    m_head = 0;
172
187
    m_isindexElement = 0;
173
188
 
174
189
    m_skipModeTag = nullAtom;
 
190
    
 
191
    if (m_parserQuirks)
 
192
        m_parserQuirks->reset();
175
193
}
176
194
 
177
195
void HTMLParser::setCurrent(Node* newCurrent) 
178
196
{
179
 
    bool didRefNewCurrent = newCurrent && newCurrent != document;
 
197
    bool didRefNewCurrent = newCurrent && newCurrent != m_document;
180
198
    if (didRefNewCurrent) 
181
199
        newCurrent->ref(); 
182
 
    if (didRefCurrent) 
183
 
        current->deref(); 
184
 
    current = newCurrent;
185
 
    didRefCurrent = didRefNewCurrent;
 
200
    if (m_didRefCurrent) 
 
201
        m_current->deref();
 
202
    m_current = newCurrent;
 
203
    m_didRefCurrent = didRefNewCurrent;
186
204
}
187
205
 
188
206
PassRefPtr<Node> HTMLParser::parseToken(Token* t)
191
209
        if (!t->beginTag && t->tagName == m_skipModeTag)
192
210
            // Found the end tag for the current skip mode, so we're done skipping.
193
211
            m_skipModeTag = nullAtom;
194
 
        else if (current->localName() == t->tagName)
 
212
        else if (m_current->localName() == t->tagName)
195
213
            // Do not skip </iframe>.
196
214
            // FIXME: What does that comment mean? How can it be right to parse a token without clearing m_skipModeTag?
197
215
            ;
200
218
    }
201
219
 
202
220
    // Apparently some sites use </br> instead of <br>. Be compatible with IE and Firefox and treat this like <br>.
203
 
    if (t->isCloseTag(brTag) && document->inCompatMode()) {
 
221
    if (t->isCloseTag(brTag) && m_document->inCompatMode()) {
204
222
        reportError(MalformedBRError);
205
223
        t->beginTag = true;
206
224
    }
212
230
 
213
231
    // Ignore spaces, if we're not inside a paragraph or other inline code.
214
232
    // Do not alter the text if it is part of a scriptTag.
215
 
    if (t->tagName == textAtom && t->text && current->localName() != scriptTag) {
216
 
        if (inBody && !skipMode() && current->localName() != styleTag &&
217
 
            current->localName() != titleTag && !t->text->containsOnlyWhitespace())
218
 
            haveContent = true;
 
233
    if (t->tagName == textAtom && t->text && m_current->localName() != scriptTag) {
 
234
        if (m_inBody && !skipMode() && m_current->localName() != styleTag &&
 
235
            m_current->localName() != titleTag && !t->text->containsOnlyWhitespace())
 
236
            m_haveContent = true;
219
237
        
220
238
        RefPtr<Node> n;
221
239
        String text = t->text.get();
222
240
        unsigned charsLeft = text.length();
223
241
        while (charsLeft) {
224
242
            // split large blocks of text to nodes of manageable size
225
 
            n = Text::createWithLengthLimit(document, text, charsLeft);
 
243
            n = Text::createWithLengthLimit(m_document, text, charsLeft);
226
244
            if (!insertNode(n.get(), t->selfClosingTag))
227
245
                return 0;
228
246
        }
267
285
        if (m_currentFormElement == n)
268
286
            m_currentFormElement = 0;
269
287
 
270
 
        if (head == n)
271
 
            head = 0;
 
288
        if (m_head == n)
 
289
            m_head = 0;
272
290
 
273
291
        return 0;
274
292
    }
278
296
void HTMLParser::parseDoctypeToken(DoctypeToken* t)
279
297
{
280
298
    // Ignore any doctype after the first.  Ignore doctypes in fragments.
281
 
    if (document->doctype() || m_isParsingFragment || current != document)
 
299
    if (m_document->doctype() || m_isParsingFragment || m_current != m_document)
282
300
        return;
283
301
        
284
302
    // Make a new doctype node and set it as our doctype.
285
 
    document->addChild(DocumentType::create(document, String::adopt(t->m_name), String::adopt(t->m_publicID), String::adopt(t->m_systemID)));
 
303
    m_document->addChild(DocumentType::create(m_document, String::adopt(t->m_name), String::adopt(t->m_publicID), String::adopt(t->m_systemID)));
286
304
}
287
305
 
288
 
static bool isTableSection(Node* n)
 
306
static bool isTableSection(const Node* n)
289
307
{
290
308
    return n->hasTagName(tbodyTag) || n->hasTagName(tfootTag) || n->hasTagName(theadTag);
291
309
}
292
310
 
293
 
static bool isTablePart(Node* n)
 
311
static bool isTablePart(const Node* n)
294
312
{
295
313
    return n->hasTagName(trTag) || n->hasTagName(tdTag) || n->hasTagName(thTag) ||
296
314
           isTableSection(n);
297
315
}
298
316
 
299
 
static bool isTableRelated(Node* n)
 
317
static bool isTableRelated(const Node* n)
300
318
{
301
319
    return n->hasTagName(tableTag) || isTablePart(n);
302
320
}
315
333
    
316
334
    // <table> is never allowed inside stray table content.  Always pop out of the stray table content
317
335
    // and close up the first table, and then start the second table as a sibling.
318
 
    if (inStrayTableContent && localName == tableTag)
 
336
    if (m_inStrayTableContent && localName == tableTag)
319
337
        popBlock(tableTag);
320
 
    
 
338
 
 
339
    if (tagPriority >= minBlockLevelTagPriority) {
 
340
        while (m_blocksInStack >= cMaxBlockDepth)
 
341
            popBlock(m_blockStack->tagName);
 
342
    }
 
343
 
 
344
    if (m_parserQuirks && !m_parserQuirks->shouldInsertNode(m_current, n))
 
345
        return false;
 
346
 
321
347
    // let's be stupid and just try to insert it.
322
348
    // this should work if the document is well-formed
323
 
    Node* newNode = current->addChild(n);
 
349
    Node* newNode = m_current->addChild(n);
324
350
    if (!newNode)
325
351
        return handleError(n, flat, localName, tagPriority); // Try to handle the error.
326
352
 
327
353
    // don't push elements without end tags (e.g., <img>) on the stack
328
 
    bool parentAttached = current->attached();
 
354
    bool parentAttached = m_current->attached();
329
355
    if (tagPriority > 0 && !flat) {
330
 
        if (newNode == current) {
 
356
        if (newNode == m_current) {
331
357
            // This case should only be hit when a demoted <form> is placed inside a table.
332
358
            ASSERT(localName == formTag);
333
 
            reportError(FormInsideTablePartError, &current->localName());
 
359
            reportError(FormInsideTablePartError, &m_current->localName());
 
360
            HTMLFormElement* form = static_cast<HTMLFormElement*>(n);
 
361
            form->setDemoted(true);
334
362
        } else {
335
363
            // The pushBlock function transfers ownership of current to the block stack
336
 
            // so we're guaranteed that didRefCurrent is false. The code below is an
 
364
            // so we're guaranteed that m_didRefCurrent is false. The code below is an
337
365
            // optimized version of setCurrent that takes advantage of that fact and also
338
366
            // assumes that newNode is neither 0 nor a pointer to the document.
339
367
            pushBlock(localName, tagPriority);
340
368
            newNode->beginParsingChildren();
341
 
            ASSERT(!didRefCurrent);
 
369
            ASSERT(!m_didRefCurrent);
342
370
            newNode->ref(); 
343
 
            current = newNode;
344
 
            didRefCurrent = true;
 
371
            m_current = newNode;
 
372
            m_didRefCurrent = true;
345
373
        }
346
374
        if (parentAttached && !n->attached() && !m_isParsingFragment)
347
375
            n->attach();
351
379
        n->finishParsingChildren();
352
380
    }
353
381
 
 
382
    if (localName == htmlTag && m_document->frame())
 
383
        m_document->frame()->loader()->dispatchDocumentElementAvailable();
 
384
 
354
385
    return true;
355
386
}
356
387
 
364
395
    if (n->isHTMLElement()) {
365
396
        HTMLElement* h = static_cast<HTMLElement*>(n);
366
397
        if (h->hasLocalName(trTag) || h->hasLocalName(thTag) || h->hasLocalName(tdTag)) {
367
 
            if (inStrayTableContent && !isTableRelated(current)) {
368
 
                reportError(MisplacedTablePartError, &localName, &current->localName());
 
398
            if (m_inStrayTableContent && !isTableRelated(m_current)) {
 
399
                reportError(MisplacedTablePartError, &localName, &m_current->localName());
369
400
                // pop out to the nearest enclosing table-related tag.
370
 
                while (blockStack && !isTableRelated(current))
 
401
                while (m_blockStack && !isTableRelated(m_current))
371
402
                    popOneBlock();
372
403
                return insertNode(n);
373
404
            }
374
405
        } else if (h->hasLocalName(headTag)) {
375
 
            if (!current->isDocumentNode() && !current->hasTagName(htmlTag)) {
 
406
            if (!m_current->isDocumentNode() && !m_current->hasTagName(htmlTag)) {
376
407
                reportError(MisplacedHeadError);
377
408
                return false;
378
409
            }
379
410
        } else if (h->hasLocalName(metaTag) || h->hasLocalName(linkTag) || h->hasLocalName(baseTag)) {
380
411
            bool createdHead = false;
381
 
            if (!head) {
 
412
            if (!m_head) {
382
413
                createHead();
383
414
                createdHead = true;
384
415
            }
385
 
            if (head) {
 
416
            if (m_head) {
386
417
                if (!createdHead)
387
 
                    reportError(MisplacedHeadContentError, &localName, &current->localName());
388
 
                if (head->addChild(n)) {
 
418
                    reportError(MisplacedHeadContentError, &localName, &m_current->localName());
 
419
                if (m_head->addChild(n)) {
389
420
                    if (!n->attached() && !m_isParsingFragment)
390
421
                        n->attach();
391
422
                    return true;
393
424
                    return false;
394
425
            }
395
426
        } else if (h->hasLocalName(htmlTag)) {
396
 
            if (!current->isDocumentNode() ) {
397
 
                if (document->documentElement() && document->documentElement()->hasTagName(htmlTag)) {
 
427
            if (!m_current->isDocumentNode() ) {
 
428
                if (m_document->documentElement() && m_document->documentElement()->hasTagName(htmlTag)) {
398
429
                    reportError(RedundantHTMLBodyError, &localName);
399
430
                    // we have another <HTML> element.... apply attributes to existing one
400
431
                    // make sure we don't overwrite already existing attributes
401
 
                    NamedAttrMap* map = static_cast<Element*>(n)->attributes(true);
402
 
                    Element* existingHTML = static_cast<Element*>(document->documentElement());
403
 
                    NamedAttrMap* bmap = existingHTML->attributes(false);
 
432
                    NamedNodeMap* map = static_cast<Element*>(n)->attributes(true);
 
433
                    Element* existingHTML = static_cast<Element*>(m_document->documentElement());
 
434
                    NamedNodeMap* bmap = existingHTML->attributes(false);
404
435
                    for (unsigned l = 0; map && l < map->length(); ++l) {
405
436
                        Attribute* it = map->attributeItem(l);
406
437
                        if (!bmap->getAttributeItem(it->name()))
409
440
                }
410
441
                return false;
411
442
            }
412
 
        } else if (h->hasLocalName(titleTag) || h->hasLocalName(styleTag)) {
 
443
        } else if (h->hasLocalName(titleTag) || h->hasLocalName(styleTag) || h->hasLocalName(scriptTag)) {
413
444
            bool createdHead = false;
414
 
            if (!head) {
 
445
            if (!m_head) {
415
446
                createHead();
416
447
                createdHead = true;
417
448
            }
418
 
            if (head) {
419
 
                Node* newNode = head->addChild(n);
 
449
            if (m_head) {
 
450
                Node* newNode = m_head->addChild(n);
420
451
                if (!newNode) {
421
452
                    setSkipMode(h->tagQName());
422
453
                    return false;
423
454
                }
424
455
                
425
456
                if (!createdHead)
426
 
                    reportError(MisplacedHeadContentError, &localName, &current->localName());
 
457
                    reportError(MisplacedHeadContentError, &localName, &m_current->localName());
427
458
                
428
459
                pushBlock(localName, tagPriority);
429
460
                newNode->beginParsingChildren();
432
463
                    n->attach();
433
464
                return true;
434
465
            }
435
 
            if (inBody) {
 
466
            if (m_inBody) {
436
467
                setSkipMode(h->tagQName());
437
468
                return false;
438
469
            }
439
470
        } else if (h->hasLocalName(bodyTag)) {
440
 
            if (inBody && document->body()) {
 
471
            if (m_inBody && m_document->body()) {
441
472
                // we have another <BODY> element.... apply attributes to existing one
442
473
                // make sure we don't overwrite already existing attributes
443
474
                // some sites use <body bgcolor=rightcolor>...<body bgcolor=wrongcolor>
444
475
                reportError(RedundantHTMLBodyError, &localName);
445
 
                NamedAttrMap* map = static_cast<Element*>(n)->attributes(true);
446
 
                Element* existingBody = document->body();
447
 
                NamedAttrMap* bmap = existingBody->attributes(false);
 
476
                NamedNodeMap* map = static_cast<Element*>(n)->attributes(true);
 
477
                Element* existingBody = m_document->body();
 
478
                NamedNodeMap* bmap = existingBody->attributes(false);
448
479
                for (unsigned l = 0; map && l < map->length(); ++l) {
449
480
                    Attribute* it = map->attributeItem(l);
450
481
                    if (!bmap->getAttributeItem(it->name()))
452
483
                }
453
484
                return false;
454
485
            }
455
 
            else if (!current->isDocumentNode())
 
486
            else if (!m_current->isDocumentNode())
456
487
                return false;
457
488
        } else if (h->hasLocalName(areaTag)) {
458
489
            if (m_currentMapElement) {
459
 
                reportError(MisplacedAreaError, &current->localName());
 
490
                reportError(MisplacedAreaError, &m_current->localName());
460
491
                m_currentMapElement->addChild(n);
461
492
                if (!n->attached() && !m_isParsingFragment)
462
493
                    n->attach();
465
496
            }
466
497
            return false;
467
498
        } else if (h->hasLocalName(colgroupTag) || h->hasLocalName(captionTag)) {
468
 
            if (isTableRelated(current)) {
469
 
                while (blockStack && isTablePart(current))
 
499
            if (isTableRelated(m_current)) {
 
500
                while (m_blockStack && isTablePart(m_current))
470
501
                    popOneBlock();
471
502
                return insertNode(n);
472
503
            }
473
504
        }
474
 
    } else if (n->isCommentNode() && !head)
 
505
    } else if (n->isCommentNode() && !m_head)
475
506
        return false;
476
507
 
477
508
    // 2. Next we examine our currently active element to do some further error handling.
478
 
    if (current->isHTMLElement()) {
479
 
        HTMLElement* h = static_cast<HTMLElement*>(current);
 
509
    if (m_current->isHTMLElement()) {
 
510
        HTMLElement* h = static_cast<HTMLElement*>(m_current);
480
511
        const AtomicString& currentTagName = h->localName();
481
512
        if (h->hasLocalName(htmlTag)) {
482
513
            HTMLElement* elt = n->isHTMLElement() ? static_cast<HTMLElement*>(n) : 0;
485
516
                elt->hasLocalName(objectTag) || elt->hasLocalName(embedTag) ||
486
517
                elt->hasLocalName(titleTag) || elt->hasLocalName(isindexTag) ||
487
518
                elt->hasLocalName(baseTag))) {
488
 
                if (!head) {
489
 
                    head = new HTMLHeadElement(headTag, document);
490
 
                    insertNode(head.get());
 
519
                if (!m_head) {
 
520
                    m_head = new HTMLHeadElement(headTag, m_document);
 
521
                    insertNode(m_head.get());
491
522
                    handled = true;
492
523
                }
493
524
            } else {
496
527
                    if (t->containsOnlyWhitespace())
497
528
                        return false;
498
529
                }
499
 
                if (!haveFrameSet) {
500
 
                    e = new HTMLBodyElement(bodyTag, document);
 
530
                if (!m_haveFrameSet) {
 
531
                    // Ensure that head exists.
 
532
                    // But not for older versions of Mail, where the implicit <head> isn't expected - <rdar://problem/6863795>
 
533
                    if (shouldCreateImplicitHead(m_document))
 
534
                        createHead();
 
535
 
 
536
                    popBlock(headTag);
 
537
                    e = new HTMLBodyElement(bodyTag, m_document);
501
538
                    startBody();
502
539
                    insertNode(e);
503
540
                    handled = true;
509
546
                return false;
510
547
            else {
511
548
                // This means the body starts here...
512
 
                if (!haveFrameSet) {
 
549
                if (!m_haveFrameSet) {
 
550
                    ASSERT(currentTagName == headTag);
513
551
                    popBlock(currentTagName);
514
 
                    e = new HTMLBodyElement(bodyTag, document);
 
552
                    e = new HTMLBodyElement(bodyTag, m_document);
515
553
                    startBody();
516
554
                    insertNode(e);
517
555
                    handled = true;
539
577
                handled = true;      // ...and start a new one
540
578
            } else {
541
579
                ExceptionCode ec = 0;
542
 
                Node* node = current;
 
580
                Node* node = m_current;
543
581
                Node* parent = node->parentNode();
544
582
                // A script may have removed the current node's parent from the DOM
545
583
                // http://bugs.webkit.org/show_bug.cgi?id=7137
571
609
                            pushBlock(localName, tagPriority);
572
610
                            n->beginParsingChildren();
573
611
                            setCurrent(n);
574
 
                            inStrayTableContent++;
575
 
                            blockStack->strayTableContent = true;
 
612
                            m_inStrayTableContent++;
 
613
                            m_blockStack->strayTableContent = true;
576
614
                        }
577
615
                        return true;
578
616
                    }
579
617
                }
580
618
 
581
619
                if (!ec) {
582
 
                    if (current->hasTagName(trTag)) {
 
620
                    if (m_current->hasTagName(trTag)) {
583
621
                        reportError(TablePartRequiredError, &localName, &tdTag.localName());
584
 
                        e = new HTMLTableCellElement(tdTag, document);
585
 
                    } else if (current->hasTagName(tableTag)) {
 
622
                        e = new HTMLTableCellElement(tdTag, m_document);
 
623
                    } else if (m_current->hasTagName(tableTag)) {
586
624
                        // Don't report an error in this case, since making a <tbody> happens all the time when you have <table><tr>,
587
625
                        // and it isn't really a parse error per se.
588
 
                        e = new HTMLTableSectionElement(tbodyTag, document); 
 
626
                        e = new HTMLTableSectionElement(tbodyTag, m_document);
589
627
                    } else {
590
628
                        reportError(TablePartRequiredError, &localName, &trTag.localName());
591
 
                        e = new HTMLTableRowElement(trTag, document);
 
629
                        e = new HTMLTableRowElement(trTag, m_document);
592
630
                    }
593
631
 
594
632
                    insertNode(e);
622
660
            popBlock(currentTagName);
623
661
            handled = true;
624
662
        } else if (!h->hasLocalName(bodyTag)) {
625
 
            if (isInline(current)) {
 
663
            if (isInline(m_current)) {
626
664
                popInlineBlocks();
627
665
                handled = true;
628
666
            }
629
667
        }
630
 
    } else if (current->isDocumentNode()) {
 
668
    } else if (m_current->isDocumentNode()) {
631
669
        if (n->isTextNode()) {
632
670
            Text* t = static_cast<Text*>(n);
633
671
            if (t->containsOnlyWhitespace())
634
672
                return false;
635
673
        }
636
674
 
637
 
        if (!document->documentElement()) {
638
 
            e = new HTMLHtmlElement(htmlTag, document);
 
675
        if (!m_document->documentElement()) {
 
676
            e = new HTMLHtmlElement(htmlTag, m_document);
639
677
            insertNode(e);
640
678
            handled = true;
641
679
        }
643
681
 
644
682
    // 3. If we couldn't handle the error, just return false and attempt to error-correct again.
645
683
    if (!handled) {
646
 
        reportError(IgnoredContentError, &localName, &current->localName());
 
684
        reportError(IgnoredContentError, &localName, &m_current->localName());
647
685
        return false;
648
686
    }
649
687
    return insertNode(n);
654
692
 
655
693
bool HTMLParser::textCreateErrorCheck(Token* t, RefPtr<Node>& result)
656
694
{
657
 
    result = new Text(document, t->text.get());
 
695
    result = Text::create(m_document, t->text.get());
658
696
    return false;
659
697
}
660
698
 
661
699
bool HTMLParser::commentCreateErrorCheck(Token* t, RefPtr<Node>& result)
662
700
{
663
 
    result = new Comment(document, t->text.get());
 
701
    result = Comment::create(m_document, t->text.get());
664
702
    return false;
665
703
}
666
704
 
667
705
bool HTMLParser::headCreateErrorCheck(Token*, RefPtr<Node>& result)
668
706
{
669
 
    if (!head || current->localName() == htmlTag) {
670
 
        head = new HTMLHeadElement(headTag, document);
671
 
        result = head;
 
707
    if (!m_head || m_current->localName() == htmlTag) {
 
708
        m_head = new HTMLHeadElement(headTag, m_document);
 
709
        result = m_head;
672
710
    } else
673
711
        reportError(MisplacedHeadError);
674
712
    return false;
677
715
bool HTMLParser::bodyCreateErrorCheck(Token*, RefPtr<Node>&)
678
716
{
679
717
    // body no longer allowed if we have a frameset
680
 
    if (haveFrameSet)
 
718
    if (m_haveFrameSet)
681
719
        return false;
 
720
    
 
721
    // Ensure that head exists (unless parsing a fragment).
 
722
    // But not for older versions of Mail, where the implicit <head> isn't expected - <rdar://problem/6863795>
 
723
    if (!m_isParsingFragment && shouldCreateImplicitHead(m_document))
 
724
        createHead();
 
725
    
682
726
    popBlock(headTag);
683
727
    startBody();
684
728
    return true;
687
731
bool HTMLParser::framesetCreateErrorCheck(Token*, RefPtr<Node>&)
688
732
{
689
733
    popBlock(headTag);
690
 
    if (inBody && !haveFrameSet && !haveContent) {
 
734
    if (m_inBody && !m_haveFrameSet && !m_haveContent) {
691
735
        popBlock(bodyTag);
692
736
        // ### actually for IE document.body returns the now hidden "body" element
693
737
        // we can't implement that behaviour now because it could cause too many
694
738
        // regressions and the headaches are not worth the work as long as there is
695
739
        // no site actually relying on that detail (Dirk)
696
 
        if (document->body())
697
 
            document->body()->setAttribute(styleAttr, "display:none");
698
 
        inBody = false;
 
740
        if (m_document->body())
 
741
            m_document->body()->setAttribute(styleAttr, "display:none");
 
742
        m_inBody = false;
699
743
    }
700
 
    if ((haveContent || haveFrameSet) && current->localName() == htmlTag)
 
744
    if ((m_haveContent || m_haveFrameSet) && m_current->localName() == htmlTag)
701
745
        return false;
702
 
    haveFrameSet = true;
 
746
    m_haveFrameSet = true;
703
747
    startBody();
704
748
    return true;
705
749
}
709
753
    // Only create a new form if we're not already inside one.
710
754
    // This is consistent with other browsers' behavior.
711
755
    if (!m_currentFormElement) {
712
 
        m_currentFormElement = new HTMLFormElement(formTag, document);
 
756
        m_currentFormElement = new HTMLFormElement(formTag, m_document);
713
757
        result = m_currentFormElement;
714
758
        pCloserCreateErrorCheck(t, result);
715
759
    }
719
763
bool HTMLParser::isindexCreateErrorCheck(Token* t, RefPtr<Node>& result)
720
764
{
721
765
    RefPtr<Node> n = handleIsindex(t);
722
 
    if (!inBody)
 
766
    if (!m_inBody)
723
767
        m_isindexElement = n.release();
724
768
    else {
725
769
        t->selfClosingTag = true;
749
793
    return true;
750
794
}
751
795
 
 
796
bool HTMLParser::rpCreateErrorCheck(Token*, RefPtr<Node>&)
 
797
{
 
798
    popBlock(rpTag);
 
799
    popBlock(rtTag);
 
800
    return true;
 
801
}
 
802
 
 
803
bool HTMLParser::rtCreateErrorCheck(Token*, RefPtr<Node>&)
 
804
{
 
805
    popBlock(rpTag);
 
806
    popBlock(rtTag);
 
807
    return true;
 
808
}
 
809
 
752
810
bool HTMLParser::nestedCreateErrorCheck(Token* t, RefPtr<Node>&)
753
811
{
754
812
    popBlock(t->tagName);
797
855
bool HTMLParser::noscriptCreateErrorCheck(Token*, RefPtr<Node>&)
798
856
{
799
857
    if (!m_isParsingFragment) {
800
 
        Settings* settings = document->settings();
 
858
        Settings* settings = m_document->settings();
801
859
        if (settings && settings->isJavaScriptEnabled())
802
860
            setSkipMode(noscriptTag);
803
861
    }
813
871
 
814
872
bool HTMLParser::pCloserStrictCreateErrorCheck(Token*, RefPtr<Node>&)
815
873
{
816
 
    if (document->inCompatMode())
 
874
    if (m_document->inCompatMode())
817
875
        return true;
818
876
    if (hasPElementInScope())
819
877
        popBlock(pTag);
822
880
 
823
881
bool HTMLParser::mapCreateErrorCheck(Token*, RefPtr<Node>& result)
824
882
{
825
 
    m_currentMapElement = new HTMLMapElement(mapTag, document);
 
883
    m_currentMapElement = new HTMLMapElement(mapTag, m_document);
826
884
    result = m_currentMapElement;
827
885
    return false;
828
886
}
863
921
        gFunctionMap.set(listingTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck);
864
922
        gFunctionMap.set(mapTag.localName().impl(), &HTMLParser::mapCreateErrorCheck);
865
923
        gFunctionMap.set(menuTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck);
 
924
        gFunctionMap.set(navTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck);
866
925
        gFunctionMap.set(nobrTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
867
926
        gFunctionMap.set(noembedTag.localName().impl(), &HTMLParser::noembedCreateErrorCheck);
868
927
        gFunctionMap.set(noframesTag.localName().impl(), &HTMLParser::noframesCreateErrorCheck);
 
928
#if !ENABLE(XHTMLMP)
869
929
        gFunctionMap.set(noscriptTag.localName().impl(), &HTMLParser::noscriptCreateErrorCheck);
 
930
#endif
870
931
        gFunctionMap.set(olTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck);
871
932
        gFunctionMap.set(pTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck);
872
933
        gFunctionMap.set(plaintextTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck);
873
934
        gFunctionMap.set(preTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck);
 
935
        gFunctionMap.set(rpTag.localName().impl(), &HTMLParser::rpCreateErrorCheck);
 
936
        gFunctionMap.set(rtTag.localName().impl(), &HTMLParser::rtCreateErrorCheck);
874
937
        gFunctionMap.set(sTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
875
938
        gFunctionMap.set(selectTag.localName().impl(), &HTMLParser::selectCreateErrorCheck);
876
939
        gFunctionMap.set(smallTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
893
956
    if (CreateErrorCheckFunc errorCheckFunc = gFunctionMap.get(t->tagName.impl()))
894
957
        proceed = (this->*errorCheckFunc)(t, result);
895
958
    if (proceed)
896
 
        result = HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, t->tagName, xhtmlNamespaceURI), document, m_currentFormElement.get());
 
959
        result = HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, t->tagName, xhtmlNamespaceURI), m_document, m_currentFormElement.get());
897
960
    return result.release();
898
961
}
899
962
 
903
966
    // about 1500 tags, all from a bunch of <b>s.  We will only allow at most 20
904
967
    // nested tags of the same type before just ignoring them all together.
905
968
    unsigned i = 0;
906
 
    for (HTMLStackElem* curr = blockStack;
 
969
    for (HTMLStackElem* curr = m_blockStack;
907
970
         i < cMaxRedundantTagDepth && curr && curr->tagName == tagName;
908
971
         curr = curr->next, i++) { }
909
972
    return i != cMaxRedundantTagDepth;
926
989
    else if (t->tagName == pTag)
927
990
        checkForCloseTagErrors = false;
928
991
        
929
 
    HTMLStackElem* oldElem = blockStack;
 
992
    HTMLStackElem* oldElem = m_blockStack;
930
993
    popBlock(t->tagName, checkForCloseTagErrors);
931
 
    if (oldElem == blockStack && t->tagName == pTag) {
 
994
    if (oldElem == m_blockStack && t->tagName == pTag) {
932
995
        // We encountered a stray </p>.  Amazingly Gecko, WinIE, and MacIE all treat
933
996
        // this as a valid break, i.e., <p></p>.  So go ahead and make the empty
934
997
        // paragraph.
972
1035
            e->hasLocalName(noframesTag) || e->hasLocalName(nolayerTag) ||
973
1036
            e->hasLocalName(noembedTag))
974
1037
            return true;
 
1038
#if !ENABLE(XHTMLMP)
975
1039
        if (e->hasLocalName(noscriptTag) && !m_isParsingFragment) {
976
 
            Settings* settings = document->settings();
 
1040
            Settings* settings = m_document->settings();
977
1041
            if (settings && settings->isJavaScriptEnabled())
978
1042
                return true;
979
1043
        }
 
1044
#endif
980
1045
    }
981
1046
    
982
1047
    return false;
1028
1093
        unaffectedTags.add(optgroupTag.localName().impl());
1029
1094
        unaffectedTags.add(selectTag.localName().impl());
1030
1095
        unaffectedTags.add(objectTag.localName().impl());
 
1096
        unaffectedTags.add(datagridTag.localName().impl());
 
1097
        unaffectedTags.add(datalistTag.localName().impl());
1031
1098
    }
1032
1099
    
1033
1100
    return !unaffectedTags.contains(tagName.impl());
1044
1111
        // Find the outermost element that crosses over to a higher level. If there exists another higher-level
1045
1112
        // element, we will do another pass, until we have corrected the innermost one.
1046
1113
        ExceptionCode ec = 0;
1047
 
        HTMLStackElem* curr = blockStack;
 
1114
        HTMLStackElem* curr = m_blockStack;
1048
1115
        HTMLStackElem* prev = 0;
1049
1116
        HTMLStackElem* prevMaxElem = 0;
1050
1117
        maxElem = 0;
1068
1135
            return;
1069
1136
 
1070
1137
        Node* residualElem = prev->node;
1071
 
        Node* blockElem = prevMaxElem ? prevMaxElem->node : current;
 
1138
        Node* blockElem = prevMaxElem ? prevMaxElem->node : m_current;
1072
1139
        Node* parentElem = elem->node;
1073
1140
 
1074
1141
        // Check to see if the reparenting that is going to occur is allowed according to the DOM.
1217
1284
    // <table><b><i><form></b></form></i></table>
1218
1285
    // Then this check will be too simplistic.  Right now the <i><form> chain will end up inside the <tbody>, which is pretty crazy.
1219
1286
    if (strayTableContent)
1220
 
        inStrayTableContent--;
 
1287
        m_inStrayTableContent--;
1221
1288
 
1222
1289
    // Step 7: Reopen intermediate inlines, e.g., <b><p><i>Foo</b>Goo</p>.
1223
1290
    // In the above example, Goo should stay italic.
1224
1291
    // We cap the number of tags we're willing to reopen based off cResidualStyleMaxDepth.
1225
1292
    
1226
 
    HTMLStackElem* curr = blockStack;
 
1293
    HTMLStackElem* curr = m_blockStack;
1227
1294
    HTMLStackElem* residualStyleStack = 0;
1228
1295
    unsigned stackDepth = 1;
1229
1296
    unsigned redundantStyleCount = 0;
1251
1318
        } else
1252
1319
            popOneBlock();
1253
1320
 
1254
 
        curr = blockStack;
 
1321
        curr = m_blockStack;
1255
1322
    }
1256
1323
 
1257
1324
    reopenResidualStyleTags(residualStyleStack, 0); // Stray table content can't be an issue here, since some element above will always become the root of new stray table content.
1273
1340
        if (malformedTableParent)
1274
1341
            malformedTableParent->insertBefore(newNode, malformedTableParent->lastChild(), ec);
1275
1342
        else
1276
 
            current->appendChild(newNode, ec);
 
1343
            m_current->appendChild(newNode, ec);
1277
1344
        // FIXME: Is it really OK to ignore the exceptions here?
1278
1345
 
1279
1346
        // Now push a new stack element for this node we just created.
1282
1349
 
1283
1350
        // Set our strayTableContent boolean if needed, so that the reopened tag also knows
1284
1351
        // that it is inside a malformed table.
1285
 
        blockStack->strayTableContent = malformedTableParent != 0;
1286
 
        if (blockStack->strayTableContent)
1287
 
            inStrayTableContent++;
 
1352
        m_blockStack->strayTableContent = malformedTableParent != 0;
 
1353
        if (m_blockStack->strayTableContent)
 
1354
            m_inStrayTableContent++;
1288
1355
 
1289
1356
        // Clear our malformed table parent variable.
1290
1357
        malformedTableParent = 0;
1302
1369
 
1303
1370
void HTMLParser::pushBlock(const AtomicString& tagName, int level)
1304
1371
{
1305
 
    blockStack = new HTMLStackElem(tagName, level, current, didRefCurrent, blockStack);
1306
 
    didRefCurrent = false;
 
1372
    m_blockStack = new HTMLStackElem(tagName, level, m_current, m_didRefCurrent, m_blockStack);
 
1373
    if (level >= minBlockLevelTagPriority)
 
1374
        m_blocksInStack++;
 
1375
    m_didRefCurrent = false;
1307
1376
    if (tagName == pTag)
1308
1377
        m_hasPElementInScope = InScope;
1309
1378
    else if (isScopingTag(tagName))
1312
1381
 
1313
1382
void HTMLParser::popBlock(const AtomicString& tagName, bool reportErrors)
1314
1383
{
1315
 
    HTMLStackElem* elem = blockStack;
1316
 
    
 
1384
    HTMLStackElem* elem = m_blockStack;
 
1385
 
 
1386
    if (m_parserQuirks && elem && !m_parserQuirks->shouldPopBlock(elem->tagName, tagName))
 
1387
        return;
 
1388
 
1317
1389
    int maxLevel = 0;
1318
1390
 
1319
1391
    while (elem && (elem->tagName != tagName)) {
1340
1412
    HTMLStackElem* residualStyleStack = 0;
1341
1413
    Node* malformedTableParent = 0;
1342
1414
    
1343
 
    elem = blockStack;
 
1415
    elem = m_blockStack;
1344
1416
    unsigned stackDepth = 1;
1345
1417
    unsigned redundantStyleCount = 0;
1346
1418
    while (elem) {
1347
1419
        if (elem->tagName == tagName) {
1348
 
            int strayTable = inStrayTableContent;
 
1420
            int strayTable = m_inStrayTableContent;
1349
1421
            popOneBlock();
1350
1422
            elem = 0;
1351
1423
 
1353
1425
            // explicit <tbody> or <tr>.
1354
1426
            // If we end up needing to reopen residual style tags, the root of the reopened chain
1355
1427
            // must also know that it is the root of malformed content inside a <tbody>/<tr>.
1356
 
            if (strayTable && (inStrayTableContent < strayTable) && residualStyleStack) {
1357
 
                Node* curr = current;
 
1428
            if (strayTable && (m_inStrayTableContent < strayTable) && residualStyleStack) {
 
1429
                Node* curr = m_current;
1358
1430
                while (curr && !curr->hasTagName(tableTag))
1359
1431
                    curr = curr->parentNode();
1360
1432
                malformedTableParent = curr ? curr->parentNode() : 0;
1389
1461
                    popOneBlock();
1390
1462
            } else
1391
1463
                popOneBlock();
1392
 
            elem = blockStack;
 
1464
            elem = m_blockStack;
1393
1465
        }
1394
1466
    }
1395
1467
 
1398
1470
 
1399
1471
inline HTMLStackElem* HTMLParser::popOneBlockCommon()
1400
1472
{
1401
 
    HTMLStackElem* elem = blockStack;
 
1473
    HTMLStackElem* elem = m_blockStack;
1402
1474
 
1403
1475
    // Form elements restore their state during the parsing process.
1404
1476
    // Also, a few elements (<applet>, <object>) need to know when all child elements (<param>s) are available.
1405
 
    if (current && elem->node != current)
1406
 
        current->finishParsingChildren();
 
1477
    if (m_current && elem->node != m_current)
 
1478
        m_current->finishParsingChildren();
1407
1479
 
1408
 
    blockStack = elem->next;
1409
 
    current = elem->node;
1410
 
    didRefCurrent = elem->didRefNode;
 
1480
    if (m_blockStack->level >= minBlockLevelTagPriority) {
 
1481
        ASSERT(m_blocksInStack > 0);
 
1482
        m_blocksInStack--;
 
1483
    }
 
1484
    m_blockStack = elem->next;
 
1485
    m_current = elem->node;
 
1486
    m_didRefCurrent = elem->didRefNode;
1411
1487
 
1412
1488
    if (elem->strayTableContent)
1413
 
        inStrayTableContent--;
 
1489
        m_inStrayTableContent--;
1414
1490
 
1415
1491
    if (elem->tagName == pTag)
1416
1492
        m_hasPElementInScope = NotInScope;
1423
1499
void HTMLParser::popOneBlock()
1424
1500
{
1425
1501
    // Store the current node before popOneBlockCommon overwrites it.
1426
 
    Node* lastCurrent = current;
1427
 
    bool didRefLastCurrent = didRefCurrent;
 
1502
    Node* lastCurrent = m_current;
 
1503
    bool didRefLastCurrent = m_didRefCurrent;
1428
1504
 
1429
1505
    delete popOneBlockCommon();
1430
1506
 
1438
1514
    // See the two callers for details.
1439
1515
 
1440
1516
    // Store the current node before popOneBlockCommon overwrites it.
1441
 
    Node* lastCurrent = current;
1442
 
    bool didRefLastCurrent = didRefCurrent;
 
1517
    Node* lastCurrent = m_current;
 
1518
    bool didRefLastCurrent = m_didRefCurrent;
1443
1519
 
1444
1520
    // Pop the block, but don't deref the current node as popOneBlock does because
1445
1521
    // we'll be using the pointer in the new stack element.
1447
1523
 
1448
1524
    // Transfer the current node into the stack element.
1449
1525
    // No need to deref the old elem->node because popOneBlockCommon transferred
1450
 
    // it into the current/didRefCurrent fields.
 
1526
    // it into the m_current/m_didRefCurrent fields.
1451
1527
    elem->node = lastCurrent;
1452
1528
    elem->didRefNode = didRefLastCurrent;
1453
1529
    elem->next = head;
1457
1533
void HTMLParser::checkIfHasPElementInScope()
1458
1534
{
1459
1535
    m_hasPElementInScope = NotInScope;
1460
 
    HTMLStackElem* elem = blockStack;
 
1536
    HTMLStackElem* elem = m_blockStack;
1461
1537
    while (elem) {
1462
1538
        const AtomicString& tagName = elem->tagName;
1463
1539
        if (tagName == pTag) {
1471
1547
 
1472
1548
void HTMLParser::popInlineBlocks()
1473
1549
{
1474
 
    while (blockStack && isInline(current))
 
1550
    while (m_blockStack && isInline(m_current))
1475
1551
        popOneBlock();
1476
1552
}
1477
1553
 
1478
1554
void HTMLParser::freeBlock()
1479
1555
{
1480
 
    while (blockStack)
 
1556
    while (m_blockStack)
1481
1557
        popOneBlock();
 
1558
    ASSERT(!m_blocksInStack);
1482
1559
}
1483
1560
 
1484
1561
void HTMLParser::createHead()
1485
1562
{
1486
 
    if (head || !document->documentElement())
 
1563
    if (m_head)
1487
1564
        return;
1488
1565
 
1489
 
    head = new HTMLHeadElement(headTag, document);
1490
 
    HTMLElement* body = document->body();
 
1566
    if (!m_document->documentElement()) {
 
1567
        insertNode(new HTMLHtmlElement(htmlTag, m_document));
 
1568
        ASSERT(m_document->documentElement());
 
1569
    }
 
1570
 
 
1571
    m_head = new HTMLHeadElement(headTag, m_document);
 
1572
    HTMLElement* body = m_document->body();
1491
1573
    ExceptionCode ec = 0;
1492
 
    document->documentElement()->insertBefore(head.get(), body, ec);
 
1574
    m_document->documentElement()->insertBefore(m_head.get(), body, ec);
1493
1575
    if (ec)
1494
 
        head = 0;
 
1576
        m_head = 0;
1495
1577
        
1496
1578
    // If the body does not exist yet, then the <head> should be pushed as the current block.
1497
 
    if (head && !body) {
1498
 
        pushBlock(head->localName(), head->tagPriority());
1499
 
        setCurrent(head.get());
 
1579
    if (m_head && !body) {
 
1580
        pushBlock(m_head->localName(), m_head->tagPriority());
 
1581
        setCurrent(m_head.get());
1500
1582
    }
1501
1583
}
1502
1584
 
1503
1585
PassRefPtr<Node> HTMLParser::handleIsindex(Token* t)
1504
1586
{
1505
 
    RefPtr<Node> n = new HTMLDivElement(divTag, document);
 
1587
    RefPtr<Node> n = new HTMLDivElement(divTag, m_document);
1506
1588
 
1507
1589
    NamedMappedAttrMap* attrs = t->attrs.get();
1508
1590
 
1509
 
    RefPtr<HTMLIsIndexElement> isIndex = new HTMLIsIndexElement(isindexTag, document, m_currentFormElement.get());
 
1591
    RefPtr<HTMLIsIndexElement> isIndex = new HTMLIsIndexElement(isindexTag, m_document, m_currentFormElement.get());
1510
1592
    isIndex->setAttributeMap(attrs);
1511
1593
    isIndex->setAttribute(typeAttr, "khtml_isindex");
1512
1594
 
1517
1599
        t->attrs = 0;
1518
1600
    }
1519
1601
 
1520
 
    n->addChild(new HTMLHRElement(hrTag, document));
1521
 
    n->addChild(new Text(document, text));
 
1602
    n->addChild(new HTMLHRElement(hrTag, m_document));
 
1603
    n->addChild(Text::create(m_document, text));
1522
1604
    n->addChild(isIndex.release());
1523
 
    n->addChild(new HTMLHRElement(hrTag, document));
 
1605
    n->addChild(new HTMLHRElement(hrTag, m_document));
1524
1606
 
1525
1607
    return n.release();
1526
1608
}
1527
1609
 
1528
1610
void HTMLParser::startBody()
1529
1611
{
1530
 
    if (inBody)
 
1612
    if (m_inBody)
1531
1613
        return;
1532
1614
 
1533
 
    inBody = true;
 
1615
    m_inBody = true;
1534
1616
 
1535
1617
    if (m_isindexElement) {
1536
1618
        insertNode(m_isindexElement.get(), true /* don't descend into this node */);
1541
1623
void HTMLParser::finished()
1542
1624
{
1543
1625
    // In the case of a completely empty document, here's the place to create the HTML element.
1544
 
    if (current && current->isDocumentNode() && !document->documentElement())
1545
 
        insertNode(new HTMLHtmlElement(htmlTag, document));
 
1626
    if (m_current && m_current->isDocumentNode() && !m_document->documentElement())
 
1627
        insertNode(new HTMLHtmlElement(htmlTag, m_document));
1546
1628
 
1547
1629
    // This ensures that "current" is not left pointing to a node when the document is destroyed.
1548
1630
    freeBlock();
1550
1632
 
1551
1633
    // Warning, this may delete the tokenizer and parser, so don't try to do anything else after this.
1552
1634
    if (!m_isParsingFragment)
1553
 
        document->finishedParsing();
 
1635
        m_document->finishedParsing();
1554
1636
}
1555
1637
 
1556
1638
void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const AtomicString* tagName1, const AtomicString* tagName2, bool closeTags)
1557
1639
{    
1558
 
    Frame* frame = document->frame();
 
1640
    Frame* frame = m_document->frame();
1559
1641
    if (!frame)
1560
1642
        return;
1561
1643
    
1562
 
    HTMLTokenizer* htmlTokenizer = static_cast<HTMLTokenizer*>(document->tokenizer());
 
1644
    HTMLTokenizer* htmlTokenizer = static_cast<HTMLTokenizer*>(m_document->tokenizer());
1563
1645
    int lineNumber = htmlTokenizer->lineNumber() + 1;
1564
1646
 
1565
1647
    AtomicString tag1;
1592
1674
    message.replace("%tag1", tag1);
1593
1675
    message.replace("%tag2", tag2);
1594
1676
 
1595
 
    frame->domWindow()->console()->addMessage(HTMLMessageSource,
 
1677
    frame->domWindow()->console()->addMessage(HTMLMessageSource, LogMessageType, 
1596
1678
        isWarning(errorCode) ? WarningMessageLevel : ErrorMessageLevel,
1597
 
        message, lineNumber, document->url().string());
1598
 
}
 
1679
        message, lineNumber, m_document->url().string());
 
1680
}
 
1681
 
 
1682
#ifdef BUILDING_ON_LEOPARD
 
1683
bool shouldCreateImplicitHead(Document* document)
 
1684
{
 
1685
    ASSERT(document);
 
1686
    
 
1687
    Settings* settings = document->page() ? document->page()->settings() : 0;
 
1688
    return settings ? !settings->needsLeopardMailQuirks() : true;
 
1689
}
 
1690
#elif defined(BUILDING_ON_TIGER)
 
1691
bool shouldCreateImplicitHead(Document* document)
 
1692
{
 
1693
    ASSERT(document);
 
1694
    
 
1695
    Settings* settings = document->page() ? document->page()->settings() : 0;
 
1696
    return settings ? !settings->needsTigerMailQuirks() : true;
 
1697
}
 
1698
#endif
1599
1699
 
1600
1700
}