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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameSerializerImpl.cpp

Issue 2707973002: Remove blacklist on .innerHTML and .outerHTML (Closed)
Patch Set: Add HTMLElement::shouldSerializeEndTag 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 #include "core/html/HTMLMetaElement.h" 92 #include "core/html/HTMLMetaElement.h"
93 #include "core/loader/DocumentLoader.h" 93 #include "core/loader/DocumentLoader.h"
94 #include "core/loader/FrameLoader.h" 94 #include "core/loader/FrameLoader.h"
95 #include "public/platform/WebCString.h" 95 #include "public/platform/WebCString.h"
96 #include "public/platform/WebVector.h" 96 #include "public/platform/WebVector.h"
97 #include "web/WebLocalFrameImpl.h" 97 #include "web/WebLocalFrameImpl.h"
98 #include "wtf/text/TextEncoding.h" 98 #include "wtf/text/TextEncoding.h"
99 99
100 namespace blink { 100 namespace blink {
101 101
102 using namespace HTMLNames;
tkent 2017/02/22 00:31:55 This is unnecessary.
103
102 // Maximum length of data buffer which is used to temporary save generated 104 // Maximum length of data buffer which is used to temporary save generated
103 // html content data. This is a soft limit which might be passed if a very large 105 // html content data. This is a soft limit which might be passed if a very large
104 // contegious string is found in the html document. 106 // contegious string is found in the html document.
105 static const unsigned dataBufferCapacity = 65536; 107 static const unsigned dataBufferCapacity = 65536;
106 108
107 WebFrameSerializerImpl::SerializeDomParam::SerializeDomParam( 109 WebFrameSerializerImpl::SerializeDomParam::SerializeDomParam(
108 const KURL& url, 110 const KURL& url,
109 const WTF::TextEncoding& textEncoding, 111 const WTF::TextEncoding& textEncoding,
110 Document* document) 112 Document* document)
111 : url(url), 113 : url(url),
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 String addedContents = postActionAfterSerializeOpenTag(element, param); 360 String addedContents = postActionAfterSerializeOpenTag(element, param);
359 // Complete the open tag for element when it has child/children. 361 // Complete the open tag for element when it has child/children.
360 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) 362 if (element->hasChildren() || param->haveAddedContentsBeforeEnd)
361 result.append('>'); 363 result.append('>');
362 // Append the added contents generate in post action of open tag. 364 // Append the added contents generate in post action of open tag.
363 result.append(addedContents); 365 result.append(addedContents);
364 // Save the result to data buffer. 366 // Save the result to data buffer.
365 saveHTMLContentToBuffer(result.toString(), param); 367 saveHTMLContentToBuffer(result.toString(), param);
366 } 368 }
367 369
370 static inline bool canHaveEndTag(Element* element) {
tkent 2017/02/22 00:31:55 I don't think we need to introduce new function.
371 if (!element->isHTMLElement()) {
372 return true;
373 }
374
375 return toHTMLElement(element)->shouldSerializeEndTag();
376 }
377
368 // Serialize end tag of an specified element. 378 // Serialize end tag of an specified element.
369 void WebFrameSerializerImpl::endTagToString(Element* element, 379 void WebFrameSerializerImpl::endTagToString(Element* element,
370 SerializeDomParam* param) { 380 SerializeDomParam* param) {
371 bool needSkip; 381 bool needSkip;
372 StringBuilder result; 382 StringBuilder result;
373 // Do pre action for end tag. 383 // Do pre action for end tag.
374 result.append(preActionBeforeSerializeEndTag(element, param, &needSkip)); 384 result.append(preActionBeforeSerializeEndTag(element, param, &needSkip));
375 if (needSkip) 385 if (needSkip)
376 return; 386 return;
377 // Write end tag when element has child/children. 387 // Write end tag when element has child/children.
378 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) { 388 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) {
379 result.append("</"); 389 result.append("</");
380 result.append(element->nodeName().lower()); 390 result.append(element->nodeName().lower());
381 result.append('>'); 391 result.append('>');
382 } else { 392 } else {
383 // Check whether we have to write end tag for empty element. 393 // Check whether we have to write end tag for empty element.
384 if (param->isHTMLDocument) { 394 if (param->isHTMLDocument) {
385 result.append('>'); 395 result.append('>');
386 // FIXME: This code is horribly wrong. WebFrameSerializerImpl must die. 396 // FIXME: This code is horribly wrong. WebFrameSerializerImpl must die.
387 if (!element->isHTMLElement() || 397 if (canHaveEndTag(element)) {
388 !toHTMLElement(element)->ieForbidsInsertHTML()) {
389 // We need to write end tag when it is required. 398 // We need to write end tag when it is required.
390 result.append("</"); 399 result.append("</");
391 result.append(element->nodeName().lower()); 400 result.append(element->nodeName().lower());
392 result.append('>'); 401 result.append('>');
393 } 402 }
394 } else { 403 } else {
395 // For xml base document. 404 // For xml base document.
396 result.append(" />"); 405 result.append(" />");
397 } 406 }
398 } 407 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // Report empty contents for invalid URLs. 489 // Report empty contents for invalid URLs.
481 m_client->didSerializeDataForFrame( 490 m_client->didSerializeDataForFrame(
482 WebCString(), WebFrameSerializerClient::CurrentFrameIsFinished); 491 WebCString(), WebFrameSerializerClient::CurrentFrameIsFinished);
483 } 492 }
484 493
485 DCHECK(m_dataBuffer.isEmpty()); 494 DCHECK(m_dataBuffer.isEmpty());
486 return didSerialization; 495 return didSerialization;
487 } 496 }
488 497
489 } // namespace blink 498 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698