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

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameSerializer.cpp

Issue 2858963002: Replace ASSERT with DCHECK in core/ (Closed)
Patch Set: WorkerBackingThread Created 3 years, 7 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 attribute.GetName() == HTMLNames::srcdocAttr; 199 attribute.GetName() == HTMLNames::srcdocAttr;
200 if (is_link_attribute || is_src_doc_attribute) { 200 if (is_link_attribute || is_src_doc_attribute) {
201 // Check if the delegate wants to do link rewriting for the element. 201 // Check if the delegate wants to do link rewriting for the element.
202 String new_link_for_the_element; 202 String new_link_for_the_element;
203 if (delegate_.RewriteLink(element, new_link_for_the_element)) { 203 if (delegate_.RewriteLink(element, new_link_for_the_element)) {
204 if (is_link_attribute) { 204 if (is_link_attribute) {
205 // Rewrite element links. 205 // Rewrite element links.
206 AppendRewrittenAttribute(out, element, attribute.GetName().ToString(), 206 AppendRewrittenAttribute(out, element, attribute.GetName().ToString(),
207 new_link_for_the_element); 207 new_link_for_the_element);
208 } else { 208 } else {
209 ASSERT(is_src_doc_attribute); 209 DCHECK(is_src_doc_attribute);
210 // Emit src instead of srcdoc attribute for frame elements - we want the 210 // Emit src instead of srcdoc attribute for frame elements - we want the
211 // serialized subframe to use html contents from the link provided by 211 // serialized subframe to use html contents from the link provided by
212 // Delegate::rewriteLink rather than html contents from srcdoc 212 // Delegate::rewriteLink rather than html contents from srcdoc
213 // attribute. 213 // attribute.
214 AppendRewrittenAttribute(out, element, HTMLNames::srcAttr.LocalName(), 214 AppendRewrittenAttribute(out, element, HTMLNames::srcAttr.LocalName(),
215 new_link_for_the_element); 215 new_link_for_the_element);
216 } 216 }
217 return; 217 return;
218 } 218 }
219 } 219 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // url(...) statements in CSS might not work when rewriting links for the 264 // url(...) statements in CSS might not work when rewriting links for the
265 // "Webpage, Complete" method of saving a page. It will take some work but it 265 // "Webpage, Complete" method of saving a page. It will take some work but it
266 // needs to be done if we want to continue to support non-MHTML saved pages. 266 // needs to be done if we want to continue to support non-MHTML saved pages.
267 267
268 FrameSerializer::FrameSerializer(Deque<SerializedResource>& resources, 268 FrameSerializer::FrameSerializer(Deque<SerializedResource>& resources,
269 Delegate& delegate) 269 Delegate& delegate)
270 : resources_(&resources), is_serializing_css_(false), delegate_(delegate) {} 270 : resources_(&resources), is_serializing_css_(false), delegate_(delegate) {}
271 271
272 void FrameSerializer::SerializeFrame(const LocalFrame& frame) { 272 void FrameSerializer::SerializeFrame(const LocalFrame& frame) {
273 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame"); 273 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame");
274 ASSERT(frame.GetDocument()); 274 DCHECK(frame.GetDocument());
275 Document& document = *frame.GetDocument(); 275 Document& document = *frame.GetDocument();
276 KURL url = document.Url(); 276 KURL url = document.Url();
277 277
278 // If frame is an image document, add the image and don't continue 278 // If frame is an image document, add the image and don't continue
279 if (document.IsImageDocument()) { 279 if (document.IsImageDocument()) {
280 ImageDocument& image_document = ToImageDocument(document); 280 ImageDocument& image_document = ToImageDocument(document);
281 AddImageToResources(image_document.CachedImage(), url); 281 AddImageToResources(image_document.CachedImage(), url);
282 return; 282 return;
283 } 283 }
284 284
285 HeapVector<Member<Node>> serialized_nodes; 285 HeapVector<Member<Node>> serialized_nodes;
286 { 286 {
287 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame HTML"); 287 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame HTML");
288 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 288 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
289 "PageSerialization.SerializationTime.Html"); 289 "PageSerialization.SerializationTime.Html");
290 SerializerMarkupAccumulator accumulator(delegate_, document, 290 SerializerMarkupAccumulator accumulator(delegate_, document,
291 serialized_nodes); 291 serialized_nodes);
292 String text = 292 String text =
293 SerializeNodes<EditingStrategy>(accumulator, document, kIncludeNode); 293 SerializeNodes<EditingStrategy>(accumulator, document, kIncludeNode);
294 294
295 CString frame_html = 295 CString frame_html =
296 document.Encoding().Encode(text, WTF::kEntitiesForUnencodables); 296 document.Encoding().Encode(text, WTF::kEntitiesForUnencodables);
297 resources_->push_back(SerializedResource( 297 resources_->push_back(SerializedResource(
298 url, document.SuggestedMIMEType(), 298 url, document.SuggestedMIMEType(),
299 SharedBuffer::Create(frame_html.data(), frame_html.length()))); 299 SharedBuffer::Create(frame_html.data(), frame_html.length())));
300 } 300 }
301 301
302 for (Node* node : serialized_nodes) { 302 for (Node* node : serialized_nodes) {
303 ASSERT(node); 303 DCHECK(node);
304 if (!node->IsElementNode()) 304 if (!node->IsElementNode())
305 continue; 305 continue;
306 306
307 Element& element = ToElement(*node); 307 Element& element = ToElement(*node);
308 // We have to process in-line style as it might contain some resources 308 // We have to process in-line style as it might contain some resources
309 // (typically background images). 309 // (typically background images).
310 if (element.IsStyledElement()) { 310 if (element.IsStyledElement()) {
311 RetrieveResourcesForProperties(element.InlineStyle(), document); 311 RetrieveResourcesForProperties(element.InlineStyle(), document);
312 RetrieveResourcesForProperties(element.PresentationAttributeStyle(), 312 RetrieveResourcesForProperties(element.PresentationAttributeStyle(),
313 document); 313 document);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 CSSRule* rule = style_sheet.item(i); 376 CSSRule* rule = style_sheet.item(i);
377 String item_text = rule->cssText(); 377 String item_text = rule->cssText();
378 if (!item_text.IsEmpty()) { 378 if (!item_text.IsEmpty()) {
379 css_text.Append(item_text); 379 css_text.Append(item_text);
380 if (i < style_sheet.length() - 1) 380 if (i < style_sheet.length() - 1)
381 css_text.Append("\n\n"); 381 css_text.Append("\n\n");
382 } 382 }
383 } 383 }
384 384
385 WTF::TextEncoding text_encoding(style_sheet.Contents()->Charset()); 385 WTF::TextEncoding text_encoding(style_sheet.Contents()->Charset());
386 ASSERT(text_encoding.IsValid()); 386 DCHECK(text_encoding.IsValid());
387 String text_string = css_text.ToString(); 387 String text_string = css_text.ToString();
388 CString text = text_encoding.Encode( 388 CString text = text_encoding.Encode(
389 text_string, WTF::kCSSEncodedEntitiesForUnencodables); 389 text_string, WTF::kCSSEncodedEntitiesForUnencodables);
390 resources_->push_back( 390 resources_->push_back(
391 SerializedResource(url, String("text/css"), 391 SerializedResource(url, String("text/css"),
392 SharedBuffer::Create(text.data(), text.length()))); 392 SharedBuffer::Create(text.data(), text.length())));
393 resource_urls_.insert(url); 393 resource_urls_.insert(url);
394 } 394 }
395 395
396 // Sub resources need to be serialized even if the CSS definition doesn't 396 // Sub resources need to be serialized even if the CSS definition doesn't
397 // need to be. 397 // need to be.
398 for (unsigned i = 0; i < style_sheet.length(); ++i) 398 for (unsigned i = 0; i < style_sheet.length(); ++i)
399 SerializeCSSRule(style_sheet.item(i)); 399 SerializeCSSRule(style_sheet.item(i));
400 400
401 if (css_start_time != 0) { 401 if (css_start_time != 0) {
402 is_serializing_css_ = false; 402 is_serializing_css_ = false;
403 DEFINE_STATIC_LOCAL(CustomCountHistogram, css_histogram, 403 DEFINE_STATIC_LOCAL(CustomCountHistogram, css_histogram,
404 ("PageSerialization.SerializationTime.CSSElement", 0, 404 ("PageSerialization.SerializationTime.CSSElement", 0,
405 maxSerializationTimeUmaMicroseconds, 50)); 405 maxSerializationTimeUmaMicroseconds, 50));
406 css_histogram.Count( 406 css_histogram.Count(
407 static_cast<int64_t>((MonotonicallyIncreasingTime() - css_start_time) * 407 static_cast<int64_t>((MonotonicallyIncreasingTime() - css_start_time) *
408 secondsToMicroseconds)); 408 secondsToMicroseconds));
409 } 409 }
410 } 410 }
411 411
412 void FrameSerializer::SerializeCSSRule(CSSRule* rule) { 412 void FrameSerializer::SerializeCSSRule(CSSRule* rule) {
413 ASSERT(rule->parentStyleSheet()->OwnerDocument()); 413 DCHECK(rule->parentStyleSheet()->OwnerDocument());
414 Document& document = *rule->parentStyleSheet()->OwnerDocument(); 414 Document& document = *rule->parentStyleSheet()->OwnerDocument();
415 415
416 switch (rule->type()) { 416 switch (rule->type()) {
417 case CSSRule::kStyleRule: 417 case CSSRule::kStyleRule:
418 RetrieveResourcesForProperties( 418 RetrieveResourcesForProperties(
419 &ToCSSStyleRule(rule)->GetStyleRule()->Properties(), document); 419 &ToCSSStyleRule(rule)->GetStyleRule()->Properties(), document);
420 break; 420 break;
421 421
422 case CSSRule::kImportRule: { 422 case CSSRule::kImportRule: {
423 CSSImportRule* import_rule = ToCSSImportRule(rule); 423 CSSImportRule* import_rule = ToCSSImportRule(rule);
424 KURL sheet_base_url = rule->parentStyleSheet()->BaseURL(); 424 KURL sheet_base_url = rule->parentStyleSheet()->BaseURL();
425 ASSERT(sheet_base_url.IsValid()); 425 DCHECK(sheet_base_url.IsValid());
426 KURL import_url = KURL(sheet_base_url, import_rule->href()); 426 KURL import_url = KURL(sheet_base_url, import_rule->href());
427 if (import_rule->styleSheet()) 427 if (import_rule->styleSheet())
428 SerializeCSSStyleSheet(*import_rule->styleSheet(), import_url); 428 SerializeCSSStyleSheet(*import_rule->styleSheet(), import_url);
429 break; 429 break;
430 } 430 }
431 431
432 // Rules inheriting CSSGroupingRule 432 // Rules inheriting CSSGroupingRule
433 case CSSRule::kMediaRule: 433 case CSSRule::kMediaRule:
434 case CSSRule::kSupportsRule: { 434 case CSSRule::kSupportsRule: {
435 CSSRuleList* rule_list = rule->cssRules(); 435 CSSRuleList* rule_list = rule->cssRules();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 emits_minus = ch == '-'; 579 emits_minus = ch == '-';
580 builder.Append(ch); 580 builder.Append(ch);
581 } 581 }
582 CString escaped_url = builder.ToString().Ascii(); 582 CString escaped_url = builder.ToString().Ascii();
583 return String::Format("saved from url=(%04d)%s", 583 return String::Format("saved from url=(%04d)%s",
584 static_cast<int>(escaped_url.length()), 584 static_cast<int>(escaped_url.length()),
585 escaped_url.data()); 585 escaped_url.data());
586 } 586 }
587 587
588 } // namespace blink 588 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/Frame.cpp ('k') | third_party/WebKit/Source/core/frame/FrameView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698