Chromium Code Reviews| Index: third_party/WebKit/Source/core/frame/FrameSerializer.cpp |
| diff --git a/third_party/WebKit/Source/core/frame/FrameSerializer.cpp b/third_party/WebKit/Source/core/frame/FrameSerializer.cpp |
| index d1bf4cba20e6f4314bd41c492e9f2a175b5d358f..49f7d8f5549f08fbb612211ae642d9df9b95505d 100644 |
| --- a/third_party/WebKit/Source/core/frame/FrameSerializer.cpp |
| +++ b/third_party/WebKit/Source/core/frame/FrameSerializer.cpp |
| @@ -328,6 +328,14 @@ void FrameSerializer::serializeFrame(const LocalFrame& frame) { |
| void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, |
| const KURL& url) { |
| + bool acceptableUrl = url.isValid() && !url.protocolIsData(); |
|
Łukasz Anforowicz
2016/10/07 19:07:48
nit: Maybe add a comment what is the meaning of |a
carlosk
2016/10/07 21:54:24
Done.
|
| + // If this CSS is identifiable by its URL and it has already been analyzed |
| + // before then just skip it. |
| + if (acceptableUrl && (m_resourceURLs.contains(url) || |
| + m_delegate.shouldSkipResourceWithURL(url))) { |
| + return; |
| + } |
| + |
| TRACE_EVENT2("page-serialization", "FrameSerializer::serializeCSSStyleSheet", |
| "type", "CSS", "url", url.elidedString().utf8().data()); |
| // Only report UMA metric if this is not a reentrant CSS serialization call. |
| @@ -337,25 +345,26 @@ void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, |
| cssStartTime = monotonicallyIncreasingTime(); |
| } |
| - StringBuilder cssText; |
| - cssText.append("@charset \""); |
| - cssText.append(styleSheet.contents()->charset().lower()); |
| - cssText.append("\";\n\n"); |
| - |
| - for (unsigned i = 0; i < styleSheet.length(); ++i) { |
| - CSSRule* rule = styleSheet.item(i); |
| - String itemText = rule->cssText(); |
| - if (!itemText.isEmpty()) { |
| - cssText.append(itemText); |
| - if (i < styleSheet.length() - 1) |
| - cssText.append("\n\n"); |
| - } |
| + if (acceptableUrl) { |
| + StringBuilder cssText; |
| + cssText.append("@charset \""); |
| + cssText.append(styleSheet.contents()->charset().lower()); |
| + cssText.append("\";\n\n"); |
| + |
| + for (unsigned i = 0; i < styleSheet.length(); ++i) { |
| + CSSRule* rule = styleSheet.item(i); |
| + String itemText = rule->cssText(); |
| + if (!itemText.isEmpty()) { |
| + cssText.append(itemText); |
| + if (i < styleSheet.length() - 1) |
| + cssText.append("\n\n"); |
| + } |
| - // Some rules have resources associated with them that we need to retrieve. |
| - serializeCSSRule(rule); |
| - } |
| + // Some rules have resources associated with them that we need to |
| + // retrieve. |
| + serializeCSSRule(rule); |
| + } |
| - if (shouldAddURL(url)) { |
| WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); |
| ASSERT(textEncoding.isValid()); |
| String textString = cssText.toString(); |
| @@ -365,6 +374,10 @@ void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, |
| SerializedResource(url, String("text/css"), |
| SharedBuffer::create(text.data(), text.length()))); |
| m_resourceURLs.add(url); |
| + } else { |
|
Łukasz Anforowicz
2016/10/07 19:07:48
nit: Maybe code would be cleaner if the loop below
carlosk
2016/10/07 21:54:24
I considered that but thought it would make the me
|
| + // Even if no text is needed, associated resources must be fetched. |
|
Łukasz Anforowicz
2016/10/07 19:07:48
nit: I am not sure if this comment will be easy to
carlosk
2016/10/07 21:54:24
Indeed, this was unclear. I improved the overall c
|
| + for (unsigned i = 0; i < styleSheet.length(); ++i) |
| + serializeCSSRule(styleSheet.item(i)); |
| } |
| if (cssStartTime != 0) { |