OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) | 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) |
6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, Exception Code& ec) | 487 Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, Exception Code& ec) |
488 { | 488 { |
489 // In Internet Explorer if the element has no parent and where is "beforeBeg in" or "afterEnd", | 489 // In Internet Explorer if the element has no parent and where is "beforeBeg in" or "afterEnd", |
490 // a document fragment is created and the elements appended in the correct o rder. This document | 490 // a document fragment is created and the elements appended in the correct o rder. This document |
491 // fragment isn't returned anywhere. | 491 // fragment isn't returned anywhere. |
492 // | 492 // |
493 // This is impossible for us to implement as the DOM tree does not allow for such structures, | 493 // This is impossible for us to implement as the DOM tree does not allow for such structures, |
494 // Opera also appears to disallow such usage. | 494 // Opera also appears to disallow such usage. |
495 | 495 |
496 if (equalIgnoringCase(where, "beforeBegin")) { | 496 if (equalIgnoringCase(where, "beforeBegin")) { |
497 ContainerNode* parent = this->parentNode(); | 497 if (ContainerNode* parent = this->parentNode()) { |
498 if (parent) { | 498 parent->insertBefore(newChild, this, ec, AttachLazily); |
499 parent->insertBefore(newChild, this, ec); | |
500 if (!ec) | 499 if (!ec) |
501 return newChild; | 500 return newChild; |
502 } | 501 } |
503 return 0; | 502 return 0; |
504 } | 503 } |
505 | 504 |
506 if (equalIgnoringCase(where, "afterBegin")) { | 505 if (equalIgnoringCase(where, "afterBegin")) { |
507 insertBefore(newChild, firstChild(), ec); | 506 insertBefore(newChild, firstChild(), ec, AttachLazily); |
508 return ec ? 0 : newChild; | 507 return ec ? 0 : newChild; |
509 } | 508 } |
510 | 509 |
511 if (equalIgnoringCase(where, "beforeEnd")) { | 510 if (equalIgnoringCase(where, "beforeEnd")) { |
512 appendChild(newChild, ec); | 511 appendChild(newChild, ec, AttachLazily); |
513 return ec ? 0 : newChild; | 512 return ec ? 0 : newChild; |
514 } | 513 } |
515 | 514 |
516 if (equalIgnoringCase(where, "afterEnd")) { | 515 if (equalIgnoringCase(where, "afterEnd")) { |
517 ContainerNode* parent = this->parentNode(); | 516 if (ContainerNode* parent = this->parentNode()) { |
518 if (parent) { | 517 parent->insertBefore(newChild, nextSibling(), ec, AttachLazily); |
519 parent->insertBefore(newChild, nextSibling(), ec); | |
520 if (!ec) | 518 if (!ec) |
521 return newChild; | 519 return newChild; |
522 } | 520 } |
523 return 0; | 521 return 0; |
524 } | 522 } |
525 | 523 |
526 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alte rnative. | 524 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alte rnative. |
527 ec = NotSupportedError; | 525 ec = NotSupportedError; |
528 return 0; | 526 return 0; |
529 } | 527 } |
530 | 528 |
531 Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChi ld, ExceptionCode& ec) | 529 Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChi ld, ExceptionCode& ec) |
532 { | 530 { |
533 if (!newChild) { | 531 if (!newChild) { |
534 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative. | 532 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative. |
535 ec = TypeMismatchError; | 533 ec = TypeMismatchError; |
536 return 0; | 534 return 0; |
537 } | 535 } |
538 | 536 |
539 Node* returnValue = insertAdjacent(where, newChild, ec); | 537 Node* returnValue = insertAdjacent(where, newChild, ec); |
540 ASSERT_WITH_SECURITY_IMPLICATION(!returnValue || returnValue->isElementNode( )); | |
ojan
2013/07/12 05:12:44
What's wrong with these asserts?
| |
541 return toElement(returnValue); | 538 return toElement(returnValue); |
542 } | 539 } |
543 | 540 |
544 // Step 3 of http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in -html-documents.html#insertadjacenthtml() | 541 // Step 3 of http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in -html-documents.html#insertadjacenthtml() |
545 static Element* contextElementForInsertion(const String& where, Element* element , ExceptionCode& ec) | 542 static Element* contextElementForInsertion(const String& where, Element* element , ExceptionCode& ec) |
546 { | 543 { |
547 if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "aft erEnd")) { | 544 if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "aft erEnd")) { |
548 ContainerNode* parent = element->parentNode(); | 545 ContainerNode* parent = element->parentNode(); |
549 if (parent && !parent->isElementNode()) { | 546 if (parent && !parent->isElementNode()) { |
550 ec = NoModificationAllowedError; | 547 ec = NoModificationAllowedError; |
551 return 0; | 548 return 0; |
552 } | 549 } |
553 ASSERT_WITH_SECURITY_IMPLICATION(!parent || parent->isElementNode()); | |
554 return toElement(parent); | 550 return toElement(parent); |
555 } | 551 } |
556 if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "befo reEnd")) | 552 if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "befo reEnd")) |
557 return element; | 553 return element; |
558 ec = SyntaxError; | 554 ec = SyntaxError; |
559 return 0; | 555 return 0; |
560 } | 556 } |
561 | 557 |
562 void HTMLElement::insertAdjacentHTML(const String& where, const String& markup, ExceptionCode& ec) | 558 void HTMLElement::insertAdjacentHTML(const String& where, const String& markup, ExceptionCode& ec) |
563 { | 559 { |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1092 #ifndef NDEBUG | 1088 #ifndef NDEBUG |
1093 | 1089 |
1094 // For use in the debugger | 1090 // For use in the debugger |
1095 void dumpInnerHTML(WebCore::HTMLElement*); | 1091 void dumpInnerHTML(WebCore::HTMLElement*); |
1096 | 1092 |
1097 void dumpInnerHTML(WebCore::HTMLElement* element) | 1093 void dumpInnerHTML(WebCore::HTMLElement* element) |
1098 { | 1094 { |
1099 printf("%s\n", element->innerHTML().ascii().data()); | 1095 printf("%s\n", element->innerHTML().ascii().data()); |
1100 } | 1096 } |
1101 #endif | 1097 #endif |
OLD | NEW |