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

Unified Diff: Source/core/page/PageSerializer.cpp

Issue 1203873004: Retrieve resources from media and supports query rules while serializing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address nits Created 5 years, 6 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 | « Source/core/page/PageSerializer.h ('k') | Source/web/tests/PageSerializerTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/PageSerializer.cpp
diff --git a/Source/core/page/PageSerializer.cpp b/Source/core/page/PageSerializer.cpp
index f213024e85b45d6a60a00f0925a4b7920091a076..2f1c8d6d3e3d54010c43390a8f1f385e309cf793 100644
--- a/Source/core/page/PageSerializer.cpp
+++ b/Source/core/page/PageSerializer.cpp
@@ -37,6 +37,7 @@
#include "core/css/CSSFontFaceSrcValue.h"
#include "core/css/CSSImageValue.h"
#include "core/css/CSSImportRule.h"
+#include "core/css/CSSRuleList.h"
#include "core/css/CSSStyleDeclaration.h"
#include "core/css/CSSStyleRule.h"
#include "core/css/CSSValueList.h"
@@ -302,22 +303,9 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KUR
if (i < styleSheet.length() - 1)
cssText.appendLiteral("\n\n");
}
- ASSERT(styleSheet.ownerDocument());
- Document& document = *styleSheet.ownerDocument();
+
// Some rules have resources associated with them that we need to retrieve.
- if (rule->type() == CSSRule::IMPORT_RULE) {
- CSSImportRule* importRule = toCSSImportRule(rule);
- ASSERT(styleSheet.baseURL().isValid());
- KURL importURL = KURL(styleSheet.baseURL(), importRule->href());
- if (m_resourceURLs.contains(importURL))
- continue;
- if (importRule->styleSheet())
- serializeCSSStyleSheet(*importRule->styleSheet(), importURL);
- } else if (rule->type() == CSSRule::FONT_FACE_RULE) {
- retrieveResourcesForProperties(&toCSSFontFaceRule(rule)->styleRule()->properties(), document);
- } else if (rule->type() == CSSRule::STYLE_RULE) {
- retrieveResourcesForProperties(&toCSSStyleRule(rule)->styleRule()->properties(), document);
- }
+ serializeCSSRule(rule);
}
if (url.isValid() && !m_resourceURLs.contains(url)) {
@@ -331,6 +319,54 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KUR
}
}
+void PageSerializer::serializeCSSRule(CSSRule* rule)
+{
+ ASSERT(rule->parentStyleSheet()->ownerDocument());
+ Document& document = *rule->parentStyleSheet()->ownerDocument();
+
+ switch (rule->type()) {
+ case CSSRule::STYLE_RULE:
+ retrieveResourcesForProperties(&toCSSStyleRule(rule)->styleRule()->properties(), document);
+ break;
+
+ case CSSRule::IMPORT_RULE: {
+ CSSImportRule* importRule = toCSSImportRule(rule);
+ KURL sheetBaseURL = rule->parentStyleSheet()->baseURL();
+ ASSERT(sheetBaseURL.isValid());
+ KURL importURL = KURL(sheetBaseURL, importRule->href());
+ if (m_resourceURLs.contains(importURL))
+ break;
+ if (importRule->styleSheet())
+ serializeCSSStyleSheet(*importRule->styleSheet(), importURL);
+ break;
+ }
+
+ // Rules inheriting CSSGroupingRule
+ case CSSRule::MEDIA_RULE:
+ case CSSRule::SUPPORTS_RULE: {
+ CSSRuleList* ruleList = rule->cssRules();
+ for (unsigned i = 0; i < ruleList->length(); ++i)
+ serializeCSSRule(ruleList->item(i));
+ break;
+ }
+
+ case CSSRule::FONT_FACE_RULE:
+ retrieveResourcesForProperties(&toCSSFontFaceRule(rule)->styleRule()->properties(), document);
+ break;
+
+ // Rules in which no external resources can be referenced
+ case CSSRule::CHARSET_RULE:
+ case CSSRule::PAGE_RULE:
+ case CSSRule::KEYFRAMES_RULE:
+ case CSSRule::KEYFRAME_RULE:
+ case CSSRule::VIEWPORT_RULE:
+ break;
+
+ default:
+ ASSERT_NOT_REACHED();
+ }
+}
+
bool PageSerializer::shouldAddURL(const KURL& url)
{
return url.isValid() && !m_resourceURLs.contains(url) && !url.protocolIsData();
« no previous file with comments | « Source/core/page/PageSerializer.h ('k') | Source/web/tests/PageSerializerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698