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

Unified Diff: third_party/WebKit/Source/core/frame/FrameSerializer.cpp

Issue 2397983002: MHTML saving optimization: don't generate CSS code that will be discarded. (Closed)
Patch Set: Further optimization. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698