Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: Source/core/html/HTMLElement.cpp

Issue 24469004: Amusingly deprecate the generic version of 'ExceptionState::throwDOMException'. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLDialogElement.cpp ('k') | Source/core/html/HTMLFrameOwnerElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 RefPtr<Text> textNext = toText(next); 344 RefPtr<Text> textNext = toText(next);
345 textNode->appendData(textNext->data()); 345 textNode->appendData(textNext->data());
346 if (textNext->parentNode()) // Might have been removed by mutation event. 346 if (textNext->parentNode()) // Might have been removed by mutation event.
347 textNext->remove(es); 347 textNext->remove(es);
348 } 348 }
349 349
350 void HTMLElement::setOuterHTML(const String& html, ExceptionState& es) 350 void HTMLElement::setOuterHTML(const String& html, ExceptionState& es)
351 { 351 {
352 Node* p = parentNode(); 352 Node* p = parentNode();
353 if (!p || !p->isHTMLElement()) { 353 if (!p || !p->isHTMLElement()) {
354 es.throwDOMException(NoModificationAllowedError); 354 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
355 return; 355 return;
356 } 356 }
357 RefPtr<HTMLElement> parent = toHTMLElement(p); 357 RefPtr<HTMLElement> parent = toHTMLElement(p);
358 RefPtr<Node> prev = previousSibling(); 358 RefPtr<Node> prev = previousSibling();
359 RefPtr<Node> next = nextSibling(); 359 RefPtr<Node> next = nextSibling();
360 360
361 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, pa rent.get(), AllowScriptingContent, es); 361 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, pa rent.get(), AllowScriptingContent, es);
362 if (es.hadException()) 362 if (es.hadException())
363 return; 363 return;
364 364
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 400
401 start = i + 1; // Character after line break. 401 start = i + 1; // Character after line break.
402 } 402 }
403 403
404 return fragment; 404 return fragment;
405 } 405 }
406 406
407 void HTMLElement::setInnerText(const String& text, ExceptionState& es) 407 void HTMLElement::setInnerText(const String& text, ExceptionState& es)
408 { 408 {
409 if (ieForbidsInsertHTML()) { 409 if (ieForbidsInsertHTML()) {
410 es.throwDOMException(NoModificationAllowedError); 410 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
411 return; 411 return;
412 } 412 }
413 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames etTag) || 413 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames etTag) ||
414 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) || 414 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) ||
415 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa g) || 415 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa g) ||
416 hasLocalName(trTag)) { 416 hasLocalName(trTag)) {
417 es.throwDOMException(NoModificationAllowedError); 417 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
418 return; 418 return;
419 } 419 }
420 420
421 // FIXME: This doesn't take whitespace collapsing into account at all. 421 // FIXME: This doesn't take whitespace collapsing into account at all.
422 422
423 if (!text.contains('\n') && !text.contains('\r')) { 423 if (!text.contains('\n') && !text.contains('\r')) {
424 if (text.isEmpty()) { 424 if (text.isEmpty()) {
425 removeChildren(); 425 removeChildren();
426 return; 426 return;
427 } 427 }
(...skipping 19 matching lines...) Expand all
447 447
448 // Add text nodes and <br> elements. 448 // Add text nodes and <br> elements.
449 RefPtr<DocumentFragment> fragment = textToFragment(text, es); 449 RefPtr<DocumentFragment> fragment = textToFragment(text, es);
450 if (!es.hadException()) 450 if (!es.hadException())
451 replaceChildrenWithFragment(this, fragment.release(), es); 451 replaceChildrenWithFragment(this, fragment.release(), es);
452 } 452 }
453 453
454 void HTMLElement::setOuterText(const String &text, ExceptionState& es) 454 void HTMLElement::setOuterText(const String &text, ExceptionState& es)
455 { 455 {
456 if (ieForbidsInsertHTML()) { 456 if (ieForbidsInsertHTML()) {
457 es.throwDOMException(NoModificationAllowedError); 457 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
458 return; 458 return;
459 } 459 }
460 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames etTag) || 460 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames etTag) ||
461 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) || 461 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) ||
462 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa g) || 462 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa g) ||
463 hasLocalName(trTag)) { 463 hasLocalName(trTag)) {
464 es.throwDOMException(NoModificationAllowedError); 464 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
465 return; 465 return;
466 } 466 }
467 467
468 ContainerNode* parent = parentNode(); 468 ContainerNode* parent = parentNode();
469 if (!parent) { 469 if (!parent) {
470 es.throwDOMException(NoModificationAllowedError); 470 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
471 return; 471 return;
472 } 472 }
473 473
474 RefPtr<Node> prev = previousSibling(); 474 RefPtr<Node> prev = previousSibling();
475 RefPtr<Node> next = nextSibling(); 475 RefPtr<Node> next = nextSibling();
476 RefPtr<Node> newChild; 476 RefPtr<Node> newChild;
477 477
478 // Convert text to fragment with <br> tags instead of linebreaks if needed. 478 // Convert text to fragment with <br> tags instead of linebreaks if needed.
479 if (text.contains('\r') || text.contains('\n')) 479 if (text.contains('\r') || text.contains('\n'))
480 newChild = textToFragment(text, es); 480 newChild = textToFragment(text, es);
481 else 481 else
482 newChild = Text::create(document(), text); 482 newChild = Text::create(document(), text);
483 483
484 if (!this || !parentNode()) 484 if (!this || !parentNode())
485 es.throwDOMException(HierarchyRequestError); 485 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
486 if (es.hadException()) 486 if (es.hadException())
487 return; 487 return;
488 parent->replaceChild(newChild.release(), this, es); 488 parent->replaceChild(newChild.release(), this, es);
489 489
490 RefPtr<Node> node = next ? next->previousSibling() : 0; 490 RefPtr<Node> node = next ? next->previousSibling() : 0;
491 if (!es.hadException() && node && node->isTextNode()) 491 if (!es.hadException() && node && node->isTextNode())
492 mergeWithNextTextNode(node.release(), es); 492 mergeWithNextTextNode(node.release(), es);
493 493
494 if (!es.hadException() && prev && prev->isTextNode()) 494 if (!es.hadException() && prev && prev->isTextNode())
495 mergeWithNextTextNode(prev.release(), es); 495 mergeWithNextTextNode(prev.release(), es);
(...skipping 30 matching lines...) Expand all
526 if (equalIgnoringCase(where, "afterEnd")) { 526 if (equalIgnoringCase(where, "afterEnd")) {
527 if (ContainerNode* parent = this->parentNode()) { 527 if (ContainerNode* parent = this->parentNode()) {
528 parent->insertBefore(newChild, nextSibling(), es); 528 parent->insertBefore(newChild, nextSibling(), es);
529 if (!es.hadException()) 529 if (!es.hadException())
530 return newChild; 530 return newChild;
531 } 531 }
532 return 0; 532 return 0;
533 } 533 }
534 534
535 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alte rnative. 535 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alte rnative.
536 es.throwDOMException(NotSupportedError); 536 es.throwUninformativeAndGenericDOMException(NotSupportedError);
537 return 0; 537 return 0;
538 } 538 }
539 539
540 Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChi ld, ExceptionState& es) 540 Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChi ld, ExceptionState& es)
541 { 541 {
542 if (!newChild) { 542 if (!newChild) {
543 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative. 543 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative.
544 es.throwDOMException(TypeMismatchError); 544 es.throwUninformativeAndGenericDOMException(TypeMismatchError);
545 return 0; 545 return 0;
546 } 546 }
547 547
548 Node* returnValue = insertAdjacent(where, newChild, es); 548 Node* returnValue = insertAdjacent(where, newChild, es);
549 return toElement(returnValue); 549 return toElement(returnValue);
550 } 550 }
551 551
552 // Step 3 of http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in -html-documents.html#insertadjacenthtml() 552 // Step 3 of http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in -html-documents.html#insertadjacenthtml()
553 static Element* contextElementForInsertion(const String& where, Element* element , ExceptionState& es) 553 static Element* contextElementForInsertion(const String& where, Element* element , ExceptionState& es)
554 { 554 {
555 if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "aft erEnd")) { 555 if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "aft erEnd")) {
556 ContainerNode* parent = element->parentNode(); 556 ContainerNode* parent = element->parentNode();
557 if (parent && !parent->isElementNode()) { 557 if (parent && !parent->isElementNode()) {
558 es.throwDOMException(NoModificationAllowedError); 558 es.throwUninformativeAndGenericDOMException(NoModificationAllowedErr or);
559 return 0; 559 return 0;
560 } 560 }
561 return toElement(parent); 561 return toElement(parent);
562 } 562 }
563 if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "befo reEnd")) 563 if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "befo reEnd"))
564 return element; 564 return element;
565 es.throwDOMException(SyntaxError); 565 es.throwUninformativeAndGenericDOMException(SyntaxError);
566 return 0; 566 return 0;
567 } 567 }
568 568
569 void HTMLElement::insertAdjacentHTML(const String& where, const String& markup, ExceptionState& es) 569 void HTMLElement::insertAdjacentHTML(const String& where, const String& markup, ExceptionState& es)
570 { 570 {
571 Element* contextElement = contextElementForInsertion(where, this, es); 571 Element* contextElement = contextElementForInsertion(where, this, es);
572 if (!contextElement) 572 if (!contextElement)
573 return; 573 return;
574 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, contextElement, AllowScriptingContent, es); 574 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, contextElement, AllowScriptingContent, es);
575 if (!fragment) 575 if (!fragment)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 { 670 {
671 if (equalIgnoringCase(enabled, "true")) 671 if (equalIgnoringCase(enabled, "true"))
672 setAttribute(contenteditableAttr, "true"); 672 setAttribute(contenteditableAttr, "true");
673 else if (equalIgnoringCase(enabled, "false")) 673 else if (equalIgnoringCase(enabled, "false"))
674 setAttribute(contenteditableAttr, "false"); 674 setAttribute(contenteditableAttr, "false");
675 else if (equalIgnoringCase(enabled, "plaintext-only")) 675 else if (equalIgnoringCase(enabled, "plaintext-only"))
676 setAttribute(contenteditableAttr, "plaintext-only"); 676 setAttribute(contenteditableAttr, "plaintext-only");
677 else if (equalIgnoringCase(enabled, "inherit")) 677 else if (equalIgnoringCase(enabled, "inherit"))
678 removeAttribute(contenteditableAttr); 678 removeAttribute(contenteditableAttr);
679 else 679 else
680 es.throwDOMException(SyntaxError); 680 es.throwUninformativeAndGenericDOMException(SyntaxError);
681 } 681 }
682 682
683 bool HTMLElement::draggable() const 683 bool HTMLElement::draggable() const
684 { 684 {
685 return equalIgnoringCase(getAttribute(draggableAttr), "true"); 685 return equalIgnoringCase(getAttribute(draggableAttr), "true");
686 } 686 }
687 687
688 void HTMLElement::setDraggable(bool value) 688 void HTMLElement::setDraggable(bool value)
689 { 689 {
690 setAttribute(draggableAttr, value ? "true" : "false"); 690 setAttribute(draggableAttr, value ? "true" : "false");
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 #ifndef NDEBUG 1112 #ifndef NDEBUG
1113 1113
1114 // For use in the debugger 1114 // For use in the debugger
1115 void dumpInnerHTML(WebCore::HTMLElement*); 1115 void dumpInnerHTML(WebCore::HTMLElement*);
1116 1116
1117 void dumpInnerHTML(WebCore::HTMLElement* element) 1117 void dumpInnerHTML(WebCore::HTMLElement* element)
1118 { 1118 {
1119 printf("%s\n", element->innerHTML().ascii().data()); 1119 printf("%s\n", element->innerHTML().ascii().data());
1120 } 1120 }
1121 #endif 1121 #endif
OLDNEW
« no previous file with comments | « Source/core/html/HTMLDialogElement.cpp ('k') | Source/core/html/HTMLFrameOwnerElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698