| OLD | NEW |
| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 void FrameSerializer::SerializeCSSStyleSheet(CSSStyleSheet& style_sheet, | 346 void FrameSerializer::SerializeCSSStyleSheet(CSSStyleSheet& style_sheet, |
| 347 const KURL& url) { | 347 const KURL& url) { |
| 348 // If the URL is invalid or if it is a data URL this means that this CSS is | 348 // If the URL is invalid or if it is a data URL this means that this CSS is |
| 349 // defined inline, respectively in a <style> tag or in the data URL itself. | 349 // defined inline, respectively in a <style> tag or in the data URL itself. |
| 350 bool is_inline_css = !url.IsValid() || url.ProtocolIsData(); | 350 bool is_inline_css = !url.IsValid() || url.ProtocolIsData(); |
| 351 // If this CSS is not inline then it is identifiable by its URL. So just skip | 351 // If this CSS is not inline then it is identifiable by its URL. So just skip |
| 352 // it if it has already been analyzed before. | 352 // it if it has already been analyzed before. |
| 353 if (!is_inline_css && (resource_ur_ls_.Contains(url) || | 353 if (!is_inline_css && (resource_urls_.Contains(url) || |
| 354 delegate_.ShouldSkipResourceWithURL(url))) { | 354 delegate_.ShouldSkipResourceWithURL(url))) { |
| 355 return; | 355 return; |
| 356 } | 356 } |
| 357 | 357 |
| 358 TRACE_EVENT2("page-serialization", "FrameSerializer::serializeCSSStyleSheet", | 358 TRACE_EVENT2("page-serialization", "FrameSerializer::serializeCSSStyleSheet", |
| 359 "type", "CSS", "url", url.ElidedString().Utf8().Data()); | 359 "type", "CSS", "url", url.ElidedString().Utf8().Data()); |
| 360 // Only report UMA metric if this is not a reentrant CSS serialization call. | 360 // Only report UMA metric if this is not a reentrant CSS serialization call. |
| 361 double css_start_time = 0; | 361 double css_start_time = 0; |
| 362 if (!is_serializing_css_) { | 362 if (!is_serializing_css_) { |
| 363 is_serializing_css_ = true; | 363 is_serializing_css_ = true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 ASSERT(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_ur_ls_.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, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 case CSSRule::kPageRule: | 448 case CSSRule::kPageRule: |
| 449 case CSSRule::kKeyframesRule: | 449 case CSSRule::kKeyframesRule: |
| 450 case CSSRule::kKeyframeRule: | 450 case CSSRule::kKeyframeRule: |
| 451 case CSSRule::kNamespaceRule: | 451 case CSSRule::kNamespaceRule: |
| 452 case CSSRule::kViewportRule: | 452 case CSSRule::kViewportRule: |
| 453 break; | 453 break; |
| 454 } | 454 } |
| 455 } | 455 } |
| 456 | 456 |
| 457 bool FrameSerializer::ShouldAddURL(const KURL& url) { | 457 bool FrameSerializer::ShouldAddURL(const KURL& url) { |
| 458 return url.IsValid() && !resource_ur_ls_.Contains(url) && | 458 return url.IsValid() && !resource_urls_.Contains(url) && |
| 459 !url.ProtocolIsData() && !delegate_.ShouldSkipResourceWithURL(url); | 459 !url.ProtocolIsData() && !delegate_.ShouldSkipResourceWithURL(url); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void FrameSerializer::AddToResources( | 462 void FrameSerializer::AddToResources( |
| 463 const String& mime_type, | 463 const String& mime_type, |
| 464 ResourceHasCacheControlNoStoreHeader has_cache_control_no_store_header, | 464 ResourceHasCacheControlNoStoreHeader has_cache_control_no_store_header, |
| 465 PassRefPtr<const SharedBuffer> data, | 465 PassRefPtr<const SharedBuffer> data, |
| 466 const KURL& url) { | 466 const KURL& url) { |
| 467 if (delegate_.ShouldSkipResource(has_cache_control_no_store_header)) | 467 if (delegate_.ShouldSkipResource(has_cache_control_no_store_header)) |
| 468 return; | 468 return; |
| 469 | 469 |
| 470 if (!data) { | 470 if (!data) { |
| 471 DLOG(ERROR) << "No data for resource " << url.GetString(); | 471 DLOG(ERROR) << "No data for resource " << url.GetString(); |
| 472 return; | 472 return; |
| 473 } | 473 } |
| 474 | 474 |
| 475 resources_->push_back(SerializedResource(url, mime_type, std::move(data))); | 475 resources_->push_back(SerializedResource(url, mime_type, std::move(data))); |
| 476 resource_ur_ls_.insert(url); | 476 resource_urls_.insert(url); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void FrameSerializer::AddImageToResources(ImageResourceContent* image, | 479 void FrameSerializer::AddImageToResources(ImageResourceContent* image, |
| 480 const KURL& url) { | 480 const KURL& url) { |
| 481 if (!image || !image->HasImage() || image->ErrorOccurred() || | 481 if (!image || !image->HasImage() || image->ErrorOccurred() || |
| 482 !ShouldAddURL(url)) | 482 !ShouldAddURL(url)) |
| 483 return; | 483 return; |
| 484 | 484 |
| 485 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", | 485 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", |
| 486 "type", "image", "url", url.ElidedString().Utf8().Data()); | 486 "type", "image", "url", url.ElidedString().Utf8().Data()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |