Commit 40e9ebb3 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Add missing null check in PageSerializer::serializeCSSStyleSheet()

Add missing null check in PageSerializer::serializeCSSStyleSheet() for
importRule->styleSheet(). CSSImportRule::styleSheet() can return null but
the function it is being passed to expects a non-null pointer.

Also update PageSerializer::serializeCSSStyleSheet() to take its CSSStyleSheet
argument by reference, instead of pointer to make it obvious to the caller
that passing null is not OK.

R=morrita@chromium.org

Review URL: https://codereview.chromium.org/332573003

git-svn-id: svn://svn.chromium.org/blink/trunk@176123 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6dd24f28
...@@ -242,13 +242,13 @@ void PageSerializer::serializeFrame(LocalFrame* frame) ...@@ -242,13 +242,13 @@ void PageSerializer::serializeFrame(LocalFrame* frame)
HTMLLinkElement& linkElement = toHTMLLinkElement(element); HTMLLinkElement& linkElement = toHTMLLinkElement(element);
if (CSSStyleSheet* sheet = linkElement.sheet()) { if (CSSStyleSheet* sheet = linkElement.sheet()) {
KURL url = document.completeURL(linkElement.getAttribute(HTMLNames::hrefAttr)); KURL url = document.completeURL(linkElement.getAttribute(HTMLNames::hrefAttr));
serializeCSSStyleSheet(sheet, url); serializeCSSStyleSheet(*sheet, url);
ASSERT(m_resourceURLs.contains(url)); ASSERT(m_resourceURLs.contains(url));
} }
} else if (isHTMLStyleElement(element)) { } else if (isHTMLStyleElement(element)) {
HTMLStyleElement& styleElement = toHTMLStyleElement(element); HTMLStyleElement& styleElement = toHTMLStyleElement(element);
if (CSSStyleSheet* sheet = styleElement.sheet()) if (CSSStyleSheet* sheet = styleElement.sheet())
serializeCSSStyleSheet(sheet, KURL()); serializeCSSStyleSheet(*sheet, KURL());
} }
} }
...@@ -258,26 +258,27 @@ void PageSerializer::serializeFrame(LocalFrame* frame) ...@@ -258,26 +258,27 @@ void PageSerializer::serializeFrame(LocalFrame* frame)
} }
} }
void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const KURL& url) void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KURL& url)
{ {
StringBuilder cssText; StringBuilder cssText;
for (unsigned i = 0; i < styleSheet->length(); ++i) { for (unsigned i = 0; i < styleSheet.length(); ++i) {
CSSRule* rule = styleSheet->item(i); CSSRule* rule = styleSheet.item(i);
String itemText = rule->cssText(); String itemText = rule->cssText();
if (!itemText.isEmpty()) { if (!itemText.isEmpty()) {
cssText.append(itemText); cssText.append(itemText);
if (i < styleSheet->length() - 1) if (i < styleSheet.length() - 1)
cssText.append("\n\n"); cssText.append("\n\n");
} }
ASSERT(styleSheet->ownerDocument()); ASSERT(styleSheet.ownerDocument());
Document& document = *styleSheet->ownerDocument(); Document& document = *styleSheet.ownerDocument();
// Some rules have resources associated with them that we need to retrieve. // Some rules have resources associated with them that we need to retrieve.
if (rule->type() == CSSRule::IMPORT_RULE) { if (rule->type() == CSSRule::IMPORT_RULE) {
CSSImportRule* importRule = toCSSImportRule(rule); CSSImportRule* importRule = toCSSImportRule(rule);
KURL importURL = document.completeURL(importRule->href()); KURL importURL = document.completeURL(importRule->href());
if (m_resourceURLs.contains(importURL)) if (m_resourceURLs.contains(importURL))
continue; continue;
serializeCSSStyleSheet(importRule->styleSheet(), importURL); if (importRule->styleSheet())
serializeCSSStyleSheet(*importRule->styleSheet(), importURL);
} else if (rule->type() == CSSRule::FONT_FACE_RULE) { } else if (rule->type() == CSSRule::FONT_FACE_RULE) {
retrieveResourcesForProperties(&toCSSFontFaceRule(rule)->styleRule()->properties(), document); retrieveResourcesForProperties(&toCSSFontFaceRule(rule)->styleRule()->properties(), document);
} else if (rule->type() == CSSRule::STYLE_RULE) { } else if (rule->type() == CSSRule::STYLE_RULE) {
...@@ -287,7 +288,7 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const KUR ...@@ -287,7 +288,7 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const KUR
if (url.isValid() && !m_resourceURLs.contains(url)) { if (url.isValid() && !m_resourceURLs.contains(url)) {
// FIXME: We should check whether a charset has been specified and if none was found add one. // FIXME: We should check whether a charset has been specified and if none was found add one.
WTF::TextEncoding textEncoding(styleSheet->contents()->charset()); WTF::TextEncoding textEncoding(styleSheet.contents()->charset());
ASSERT(textEncoding.isValid()); ASSERT(textEncoding.isValid());
String textString = cssText.toString(); String textString = cssText.toString();
CString text = textEncoding.normalizeAndEncode(textString, WTF::EntitiesForUnencodables); CString text = textEncoding.normalizeAndEncode(textString, WTF::EntitiesForUnencodables);
......
...@@ -73,7 +73,7 @@ private: ...@@ -73,7 +73,7 @@ private:
// Serializes the stylesheet back to text and adds it to the resources if URL is not-empty. // Serializes the stylesheet back to text and adds it to the resources if URL is not-empty.
// It also adds any resources included in that stylesheet (including any imported stylesheets and their own resources). // It also adds any resources included in that stylesheet (including any imported stylesheets and their own resources).
void serializeCSSStyleSheet(CSSStyleSheet*, const KURL&); void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&);
bool shouldAddURL(const KURL&); bool shouldAddURL(const KURL&);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment