| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } else if (isHTMLStyleElement(element)) { | 325 } else if (isHTMLStyleElement(element)) { |
| 326 HTMLStyleElement& styleElement = toHTMLStyleElement(element); | 326 HTMLStyleElement& styleElement = toHTMLStyleElement(element); |
| 327 if (CSSStyleSheet* sheet = styleElement.sheet()) | 327 if (CSSStyleSheet* sheet = styleElement.sheet()) |
| 328 serializeCSSStyleSheet(*sheet, KURL()); | 328 serializeCSSStyleSheet(*sheet, KURL()); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, | 333 void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, |
| 334 const KURL& url) { | 334 const KURL& url) { |
| 335 // If the URL is invalid or if it is a data URL this means that this CSS is |
| 336 // defined inline, respectively in a <style> tag or in the data URL itself. |
| 337 bool isInlineCss = !url.isValid() || url.protocolIsData(); |
| 338 // If this CSS is not inline then it is identifiable by its URL. So just skip |
| 339 // it if it has already been analyzed before. |
| 340 if (!isInlineCss && (m_resourceURLs.contains(url) || |
| 341 m_delegate.shouldSkipResourceWithURL(url))) { |
| 342 return; |
| 343 } |
| 344 |
| 335 TRACE_EVENT2("page-serialization", "FrameSerializer::serializeCSSStyleSheet", | 345 TRACE_EVENT2("page-serialization", "FrameSerializer::serializeCSSStyleSheet", |
| 336 "type", "CSS", "url", url.elidedString().utf8().data()); | 346 "type", "CSS", "url", url.elidedString().utf8().data()); |
| 337 // Only report UMA metric if this is not a reentrant CSS serialization call. | 347 // Only report UMA metric if this is not a reentrant CSS serialization call. |
| 338 double cssStartTime = 0; | 348 double cssStartTime = 0; |
| 339 if (!m_isSerializingCss) { | 349 if (!m_isSerializingCss) { |
| 340 m_isSerializingCss = true; | 350 m_isSerializingCss = true; |
| 341 cssStartTime = monotonicallyIncreasingTime(); | 351 cssStartTime = monotonicallyIncreasingTime(); |
| 342 } | 352 } |
| 343 | 353 |
| 344 StringBuilder cssText; | 354 // If this CSS is inlined its definition was already serialized with the frame |
| 345 cssText.append("@charset \""); | 355 // HTML code that was previously generated. No need to regenerate it here. |
| 346 cssText.append(styleSheet.contents()->charset().lower()); | 356 if (!isInlineCss) { |
| 347 cssText.append("\";\n\n"); | 357 StringBuilder cssText; |
| 358 cssText.append("@charset \""); |
| 359 cssText.append(styleSheet.contents()->charset().lower()); |
| 360 cssText.append("\";\n\n"); |
| 348 | 361 |
| 349 for (unsigned i = 0; i < styleSheet.length(); ++i) { | 362 for (unsigned i = 0; i < styleSheet.length(); ++i) { |
| 350 CSSRule* rule = styleSheet.item(i); | 363 CSSRule* rule = styleSheet.item(i); |
| 351 String itemText = rule->cssText(); | 364 String itemText = rule->cssText(); |
| 352 if (!itemText.isEmpty()) { | 365 if (!itemText.isEmpty()) { |
| 353 cssText.append(itemText); | 366 cssText.append(itemText); |
| 354 if (i < styleSheet.length() - 1) | 367 if (i < styleSheet.length() - 1) |
| 355 cssText.append("\n\n"); | 368 cssText.append("\n\n"); |
| 369 } |
| 356 } | 370 } |
| 357 | 371 |
| 358 // Some rules have resources associated with them that we need to retrieve. | |
| 359 serializeCSSRule(rule); | |
| 360 } | |
| 361 | |
| 362 if (shouldAddURL(url)) { | |
| 363 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); | 372 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); |
| 364 ASSERT(textEncoding.isValid()); | 373 ASSERT(textEncoding.isValid()); |
| 365 String textString = cssText.toString(); | 374 String textString = cssText.toString(); |
| 366 CString text = | 375 CString text = |
| 367 textEncoding.encode(textString, WTF::CSSEncodedEntitiesForUnencodables); | 376 textEncoding.encode(textString, WTF::CSSEncodedEntitiesForUnencodables); |
| 368 m_resources->append( | 377 m_resources->append( |
| 369 SerializedResource(url, String("text/css"), | 378 SerializedResource(url, String("text/css"), |
| 370 SharedBuffer::create(text.data(), text.length()))); | 379 SharedBuffer::create(text.data(), text.length()))); |
| 371 m_resourceURLs.add(url); | 380 m_resourceURLs.add(url); |
| 372 } | 381 } |
| 373 | 382 |
| 383 // Sub resources need to be serialized even if the CSS definition doesn't |
| 384 // need to be. |
| 385 for (unsigned i = 0; i < styleSheet.length(); ++i) |
| 386 serializeCSSRule(styleSheet.item(i)); |
| 387 |
| 374 if (cssStartTime != 0) { | 388 if (cssStartTime != 0) { |
| 375 m_isSerializingCss = false; | 389 m_isSerializingCss = false; |
| 376 DEFINE_STATIC_LOCAL(CustomCountHistogram, cssHistogram, | 390 DEFINE_STATIC_LOCAL(CustomCountHistogram, cssHistogram, |
| 377 ("PageSerialization.SerializationTime.CSSElement", 0, | 391 ("PageSerialization.SerializationTime.CSSElement", 0, |
| 378 maxSerializationTimeUmaMicroseconds, 50)); | 392 maxSerializationTimeUmaMicroseconds, 50)); |
| 379 cssHistogram.count( | 393 cssHistogram.count( |
| 380 static_cast<int64_t>((monotonicallyIncreasingTime() - cssStartTime) * | 394 static_cast<int64_t>((monotonicallyIncreasingTime() - cssStartTime) * |
| 381 secondsToMicroseconds)); | 395 secondsToMicroseconds)); |
| 382 } | 396 } |
| 383 } | 397 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 emitsMinus = ch == '-'; | 559 emitsMinus = ch == '-'; |
| 546 builder.append(ch); | 560 builder.append(ch); |
| 547 } | 561 } |
| 548 CString escapedUrl = builder.toString().ascii(); | 562 CString escapedUrl = builder.toString().ascii(); |
| 549 return String::format("saved from url=(%04d)%s", | 563 return String::format("saved from url=(%04d)%s", |
| 550 static_cast<int>(escapedUrl.length()), | 564 static_cast<int>(escapedUrl.length()), |
| 551 escapedUrl.data()); | 565 escapedUrl.data()); |
| 552 } | 566 } |
| 553 | 567 |
| 554 } // namespace blink | 568 } // namespace blink |
| OLD | NEW |