Chromium Code Reviews| 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, | 329 void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, |
| 330 const KURL& url) { | 330 const KURL& url) { |
| 331 TRACE_EVENT2("page-serialization", "FrameSerializer::serializeCSSStyleSheet", | 331 TRACE_EVENT2("page-serialization", "FrameSerializer::serializeCSSStyleSheet", |
| 332 "type", "CSS", "url", url.elidedString().utf8().data()); | 332 "type", "CSS", "url", url.elidedString().utf8().data()); |
| 333 // Only report UMA metric if this is not a reentrant CSS serialization call. | 333 // Only report UMA metric if this is not a reentrant CSS serialization call. |
| 334 double cssStartTime = 0; | 334 double cssStartTime = 0; |
| 335 if (!m_isSerializingCss) { | 335 if (!m_isSerializingCss) { |
| 336 m_isSerializingCss = true; | 336 m_isSerializingCss = true; |
| 337 cssStartTime = monotonicallyIncreasingTime(); | 337 cssStartTime = monotonicallyIncreasingTime(); |
| 338 } | 338 } |
| 339 bool willAppendResource = shouldAddURL(url); | |
| 339 | 340 |
| 340 StringBuilder cssText; | 341 if (willAppendResource) { |
| 341 cssText.append("@charset \""); | 342 StringBuilder cssText; |
| 342 cssText.append(styleSheet.contents()->charset().lower()); | 343 cssText.append("@charset \""); |
| 343 cssText.append("\";\n\n"); | 344 cssText.append(styleSheet.contents()->charset().lower()); |
| 345 cssText.append("\";\n\n"); | |
| 344 | 346 |
| 345 for (unsigned i = 0; i < styleSheet.length(); ++i) { | 347 for (unsigned i = 0; i < styleSheet.length(); ++i) { |
| 346 CSSRule* rule = styleSheet.item(i); | 348 CSSRule* rule = styleSheet.item(i); |
| 347 String itemText = rule->cssText(); | 349 String itemText = rule->cssText(); |
| 348 if (!itemText.isEmpty()) { | 350 if (!itemText.isEmpty()) { |
| 349 cssText.append(itemText); | 351 cssText.append(itemText); |
| 350 if (i < styleSheet.length() - 1) | 352 if (i < styleSheet.length() - 1) |
| 351 cssText.append("\n\n"); | 353 cssText.append("\n\n"); |
| 354 } | |
| 355 | |
| 356 // Some rules have resources associated with them that we need to | |
| 357 // retrieve. | |
| 358 serializeCSSRule(rule); | |
| 352 } | 359 } |
| 353 | 360 |
| 354 // Some rules have resources associated with them that we need to retrieve. | |
| 355 serializeCSSRule(rule); | |
| 356 } | |
| 357 | |
| 358 if (shouldAddURL(url)) { | |
| 359 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); | 361 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); |
| 360 ASSERT(textEncoding.isValid()); | 362 ASSERT(textEncoding.isValid()); |
| 361 String textString = cssText.toString(); | 363 String textString = cssText.toString(); |
| 362 CString text = | 364 CString text = |
| 363 textEncoding.encode(textString, WTF::CSSEncodedEntitiesForUnencodables); | 365 textEncoding.encode(textString, WTF::CSSEncodedEntitiesForUnencodables); |
| 364 m_resources->append( | 366 m_resources->append( |
| 365 SerializedResource(url, String("text/css"), | 367 SerializedResource(url, String("text/css"), |
| 366 SharedBuffer::create(text.data(), text.length()))); | 368 SharedBuffer::create(text.data(), text.length()))); |
| 367 m_resourceURLs.add(url); | 369 m_resourceURLs.add(url); |
| 370 } else { | |
| 371 // Even if no text is needed, associated resources must be fetched. | |
|
Łukasz Anforowicz
2016/10/06 17:21:55
Today if 2 frames serialize CSS with the same URIs
carlosk
2016/10/06 18:07:24
I think the process you are describing is the comb
carlosk
2016/10/07 18:47:29
After an offline talk I understood lukasza@'s sugg
| |
| 372 for (unsigned i = 0; i < styleSheet.length(); ++i) | |
| 373 serializeCSSRule(styleSheet.item(i)); | |
| 368 } | 374 } |
| 369 | 375 |
| 370 if (cssStartTime != 0) { | 376 if (cssStartTime != 0) { |
| 371 m_isSerializingCss = false; | 377 m_isSerializingCss = false; |
| 372 DEFINE_STATIC_LOCAL(CustomCountHistogram, cssHistogram, | 378 DEFINE_STATIC_LOCAL(CustomCountHistogram, cssHistogram, |
| 373 ("PageSerialization.SerializationTime.CSSElement", 0, | 379 ("PageSerialization.SerializationTime.CSSElement", 0, |
| 374 maxSerializationTimeUmaMicroseconds, 50)); | 380 maxSerializationTimeUmaMicroseconds, 50)); |
| 375 cssHistogram.count( | 381 cssHistogram.count( |
| 376 static_cast<int64_t>((monotonicallyIncreasingTime() - cssStartTime) * | 382 static_cast<int64_t>((monotonicallyIncreasingTime() - cssStartTime) * |
| 377 secondsToMicroseconds)); | 383 secondsToMicroseconds)); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 emitsMinus = ch == '-'; | 547 emitsMinus = ch == '-'; |
| 542 builder.append(ch); | 548 builder.append(ch); |
| 543 } | 549 } |
| 544 CString escapedUrl = builder.toString().ascii(); | 550 CString escapedUrl = builder.toString().ascii(); |
| 545 return String::format("saved from url=(%04d)%s", | 551 return String::format("saved from url=(%04d)%s", |
| 546 static_cast<int>(escapedUrl.length()), | 552 static_cast<int>(escapedUrl.length()), |
| 547 escapedUrl.data()); | 553 escapedUrl.data()); |
| 548 } | 554 } |
| 549 | 555 |
| 550 } // namespace blink | 556 } // namespace blink |
| OLD | NEW |