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

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

Issue 2707973002: Remove blacklist on .innerHTML and .outerHTML (Closed)
Patch Set: Typo fix Created 3 years, 10 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
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-2008, 2013, 2014 Apple Inc. All rights reserved. 4 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved.
5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved.
6 * (http://www.torchmobile.com/) 6 * (http://www.torchmobile.com/)
7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // FIXME: We should have a way to detect XHTML elements and replace the 129 // FIXME: We should have a way to detect XHTML elements and replace the
130 // hasPrefix() check with it. 130 // hasPrefix() check with it.
131 if (document().isHTMLDocument()) { 131 if (document().isHTMLDocument()) {
132 if (!tagQName().hasPrefix()) 132 if (!tagQName().hasPrefix())
133 return tagQName().localNameUpper(); 133 return tagQName().localNameUpper();
134 return Element::nodeName().upper(); 134 return Element::nodeName().upper();
135 } 135 }
136 return Element::nodeName(); 136 return Element::nodeName();
137 } 137 }
138 138
139 bool HTMLElement::ieForbidsInsertHTML() const { 139 bool HTMLElement::shouldSerializeEndTag() const {
140 // FIXME: Supposedly IE disallows settting innerHTML, outerHTML 140 // See https://www.w3.org/TR/DOM-Parsing/
141 // and createContextualFragment on these tags. We have no tests to
142 // verify this however, so this list could be totally wrong.
143 // This list was moved from the previous endTagRequirement() implementation.
144 // This is also called from editing and assumed to be the list of tags
145 // for which no end tag should be serialized. It's unclear if the list for
146 // IE compat and the list for serialization sanity are the same.
147 if (hasTagName(areaTag) || hasTagName(baseTag) || hasTagName(basefontTag) || 141 if (hasTagName(areaTag) || hasTagName(baseTag) || hasTagName(basefontTag) ||
148 hasTagName(brTag) || hasTagName(colTag) || hasTagName(embedTag) || 142 hasTagName(bgsoundTag) || hasTagName(brTag) || hasTagName(colTag) ||
149 hasTagName(frameTag) || hasTagName(hrTag) || hasTagName(imageTag) || 143 hasTagName(embedTag) || hasTagName(frameTag) || hasTagName(hrTag) ||
150 hasTagName(imgTag) || hasTagName(inputTag) || hasTagName(keygenTag) || 144 hasTagName(imgTag) || hasTagName(inputTag) || hasTagName(keygenTag) ||
151 hasTagName(linkTag) || (RuntimeEnabledFeatures::contextMenuEnabled() && 145 hasTagName(linkTag) || hasTagName(menuitemTag) || hasTagName(metaTag) ||
152 hasTagName(menuitemTag)) || 146 hasTagName(paramTag) || hasTagName(sourceTag) || hasTagName(trackTag) ||
153 hasTagName(metaTag) || hasTagName(paramTag) || hasTagName(sourceTag) || 147 hasTagName(wbrTag))
154 hasTagName(trackTag) || hasTagName(wbrTag)) 148 return false;
155 return true; 149 return true;
156 return false;
157 } 150 }
158 151
159 static inline CSSValueID unicodeBidiAttributeForDirAuto(HTMLElement* element) { 152 static inline CSSValueID unicodeBidiAttributeForDirAuto(HTMLElement* element) {
160 if (element->hasTagName(preTag) || element->hasTagName(textareaTag)) 153 if (element->hasTagName(preTag) || element->hasTagName(textareaTag))
161 return CSSValueWebkitPlaintext; 154 return CSSValueWebkitPlaintext;
162 // FIXME: For bdo element, dir="auto" should result in "bidi-override isolate" 155 // FIXME: For bdo element, dir="auto" should result in "bidi-override isolate"
163 // but we don't support having multiple values in unicode-bidi yet. 156 // but we don't support having multiple values in unicode-bidi yet.
164 // See https://bugs.webkit.org/show_bug.cgi?id=73164. 157 // See https://bugs.webkit.org/show_bug.cgi?id=73164.
165 return CSSValueWebkitIsolate; 158 return CSSValueWebkitIsolate;
166 } 159 }
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 if (c == '\r' && i + 1 < length && text[i + 1] == '\n') 493 if (c == '\r' && i + 1 < length && text[i + 1] == '\n')
501 i++; 494 i++;
502 } 495 }
503 496
504 start = i + 1; // Character after line break. 497 start = i + 1; // Character after line break.
505 } 498 }
506 499
507 return fragment; 500 return fragment;
508 } 501 }
509 502
510 static inline bool shouldProhibitSetInnerOuterText(const HTMLElement& element) {
511 return element.hasTagName(colTag) || element.hasTagName(colgroupTag) ||
512 element.hasTagName(framesetTag) || element.hasTagName(headTag) ||
513 element.hasTagName(htmlTag) || element.hasTagName(tableTag) ||
514 element.hasTagName(tbodyTag) || element.hasTagName(tfootTag) ||
515 element.hasTagName(theadTag) || element.hasTagName(trTag);
516 }
517
518 void HTMLElement::setInnerText(const String& text, 503 void HTMLElement::setInnerText(const String& text,
519 ExceptionState& exceptionState) { 504 ExceptionState& exceptionState) {
520 if (ieForbidsInsertHTML()) {
521 exceptionState.throwDOMException(
522 NoModificationAllowedError,
523 "The '" + localName() + "' element does not support text insertion.");
524 return;
525 }
526 if (shouldProhibitSetInnerOuterText(*this)) {
527 exceptionState.throwDOMException(
528 NoModificationAllowedError,
529 "The '" + localName() + "' element does not support text insertion.");
530 return;
531 }
532
533 // FIXME: This doesn't take whitespace collapsing into account at all. 505 // FIXME: This doesn't take whitespace collapsing into account at all.
534 506
535 if (!text.contains('\n') && !text.contains('\r')) { 507 if (!text.contains('\n') && !text.contains('\r')) {
536 if (text.isEmpty()) { 508 if (text.isEmpty()) {
537 removeChildren(); 509 removeChildren();
538 return; 510 return;
539 } 511 }
540 replaceChildrenWithText(this, text, exceptionState); 512 replaceChildrenWithText(this, text, exceptionState);
541 return; 513 return;
542 } 514 }
(...skipping 17 matching lines...) Expand all
560 } 532 }
561 533
562 // Add text nodes and <br> elements. 534 // Add text nodes and <br> elements.
563 DocumentFragment* fragment = textToFragment(text, exceptionState); 535 DocumentFragment* fragment = textToFragment(text, exceptionState);
564 if (!exceptionState.hadException()) 536 if (!exceptionState.hadException())
565 replaceChildrenWithFragment(this, fragment, exceptionState); 537 replaceChildrenWithFragment(this, fragment, exceptionState);
566 } 538 }
567 539
568 void HTMLElement::setOuterText(const String& text, 540 void HTMLElement::setOuterText(const String& text,
569 ExceptionState& exceptionState) { 541 ExceptionState& exceptionState) {
570 if (ieForbidsInsertHTML()) {
571 exceptionState.throwDOMException(
572 NoModificationAllowedError,
573 "The '" + localName() + "' element does not support text insertion.");
574 return;
575 }
576 if (shouldProhibitSetInnerOuterText(*this)) {
577 exceptionState.throwDOMException(
578 NoModificationAllowedError,
579 "The '" + localName() + "' element does not support text insertion.");
580 return;
581 }
582
583 ContainerNode* parent = parentNode(); 542 ContainerNode* parent = parentNode();
584 if (!parent) { 543 if (!parent) {
585 exceptionState.throwDOMException(NoModificationAllowedError, 544 exceptionState.throwDOMException(NoModificationAllowedError,
586 "The element has no parent."); 545 "The element has no parent.");
587 return; 546 return;
588 } 547 }
589 548
590 Node* prev = previousSibling(); 549 Node* prev = previousSibling();
591 Node* next = nextSibling(); 550 Node* next = nextSibling();
592 Node* newChild = nullptr; 551 Node* newChild = nullptr;
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 1179
1221 #ifndef NDEBUG 1180 #ifndef NDEBUG
1222 1181
1223 // For use in the debugger 1182 // For use in the debugger
1224 void dumpInnerHTML(blink::HTMLElement*); 1183 void dumpInnerHTML(blink::HTMLElement*);
1225 1184
1226 void dumpInnerHTML(blink::HTMLElement* element) { 1185 void dumpInnerHTML(blink::HTMLElement* element) {
1227 printf("%s\n", element->innerHTML().ascii().data()); 1186 printf("%s\n", element->innerHTML().ascii().data());
1228 } 1187 }
1229 #endif 1188 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLElement.h ('k') | third_party/WebKit/Source/web/WebFrameSerializerImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698