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

Side by Side Diff: Source/core/page/PageSerializer.cpp

Issue 332573003: Add missing null check in PageSerializer::serializeCSSStyleSheet() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/page/PageSerializer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 HTMLInputElement& inputElement = toHTMLInputElement(element); 235 HTMLInputElement& inputElement = toHTMLInputElement(element);
236 if (inputElement.isImageButton() && inputElement.hasImageLoader()) { 236 if (inputElement.isImageButton() && inputElement.hasImageLoader()) {
237 KURL url = inputElement.src(); 237 KURL url = inputElement.src();
238 ImageResource* cachedImage = inputElement.imageLoader()->image() ; 238 ImageResource* cachedImage = inputElement.imageLoader()->image() ;
239 addImageToResources(cachedImage, inputElement.renderer(), url); 239 addImageToResources(cachedImage, inputElement.renderer(), url);
240 } 240 }
241 } else if (isHTMLLinkElement(element)) { 241 } else if (isHTMLLinkElement(element)) {
242 HTMLLinkElement& linkElement = toHTMLLinkElement(element); 242 HTMLLinkElement& linkElement = toHTMLLinkElement(element);
243 if (CSSStyleSheet* sheet = linkElement.sheet()) { 243 if (CSSStyleSheet* sheet = linkElement.sheet()) {
244 KURL url = document.completeURL(linkElement.getAttribute(HTMLNam es::hrefAttr)); 244 KURL url = document.completeURL(linkElement.getAttribute(HTMLNam es::hrefAttr));
245 serializeCSSStyleSheet(sheet, url); 245 serializeCSSStyleSheet(*sheet, url);
246 ASSERT(m_resourceURLs.contains(url)); 246 ASSERT(m_resourceURLs.contains(url));
247 } 247 }
248 } else if (isHTMLStyleElement(element)) { 248 } else if (isHTMLStyleElement(element)) {
249 HTMLStyleElement& styleElement = toHTMLStyleElement(element); 249 HTMLStyleElement& styleElement = toHTMLStyleElement(element);
250 if (CSSStyleSheet* sheet = styleElement.sheet()) 250 if (CSSStyleSheet* sheet = styleElement.sheet())
251 serializeCSSStyleSheet(sheet, KURL()); 251 serializeCSSStyleSheet(*sheet, KURL());
252 } 252 }
253 } 253 }
254 254
255 for (Frame* childFrame = frame->tree().firstChild(); childFrame; childFrame = childFrame->tree().nextSibling()) { 255 for (Frame* childFrame = frame->tree().firstChild(); childFrame; childFrame = childFrame->tree().nextSibling()) {
256 if (childFrame->isLocalFrame()) 256 if (childFrame->isLocalFrame())
257 serializeFrame(toLocalFrame(childFrame)); 257 serializeFrame(toLocalFrame(childFrame));
258 } 258 }
259 } 259 }
260 260
261 void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const KUR L& url) 261 void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KUR L& url)
262 { 262 {
263 StringBuilder cssText; 263 StringBuilder cssText;
264 for (unsigned i = 0; i < styleSheet->length(); ++i) { 264 for (unsigned i = 0; i < styleSheet.length(); ++i) {
265 CSSRule* rule = styleSheet->item(i); 265 CSSRule* rule = styleSheet.item(i);
266 String itemText = rule->cssText(); 266 String itemText = rule->cssText();
267 if (!itemText.isEmpty()) { 267 if (!itemText.isEmpty()) {
268 cssText.append(itemText); 268 cssText.append(itemText);
269 if (i < styleSheet->length() - 1) 269 if (i < styleSheet.length() - 1)
270 cssText.append("\n\n"); 270 cssText.append("\n\n");
271 } 271 }
272 ASSERT(styleSheet->ownerDocument()); 272 ASSERT(styleSheet.ownerDocument());
273 Document& document = *styleSheet->ownerDocument(); 273 Document& document = *styleSheet.ownerDocument();
274 // Some rules have resources associated with them that we need to retrie ve. 274 // Some rules have resources associated with them that we need to retrie ve.
275 if (rule->type() == CSSRule::IMPORT_RULE) { 275 if (rule->type() == CSSRule::IMPORT_RULE) {
276 CSSImportRule* importRule = toCSSImportRule(rule); 276 CSSImportRule* importRule = toCSSImportRule(rule);
277 KURL importURL = document.completeURL(importRule->href()); 277 KURL importURL = document.completeURL(importRule->href());
278 if (m_resourceURLs.contains(importURL)) 278 if (m_resourceURLs.contains(importURL))
279 continue; 279 continue;
280 serializeCSSStyleSheet(importRule->styleSheet(), importURL); 280 if (importRule->styleSheet())
281 serializeCSSStyleSheet(*importRule->styleSheet(), importURL);
281 } else if (rule->type() == CSSRule::FONT_FACE_RULE) { 282 } else if (rule->type() == CSSRule::FONT_FACE_RULE) {
282 retrieveResourcesForProperties(&toCSSFontFaceRule(rule)->styleRule() ->properties(), document); 283 retrieveResourcesForProperties(&toCSSFontFaceRule(rule)->styleRule() ->properties(), document);
283 } else if (rule->type() == CSSRule::STYLE_RULE) { 284 } else if (rule->type() == CSSRule::STYLE_RULE) {
284 retrieveResourcesForProperties(&toCSSStyleRule(rule)->styleRule()->p roperties(), document); 285 retrieveResourcesForProperties(&toCSSStyleRule(rule)->styleRule()->p roperties(), document);
285 } 286 }
286 } 287 }
287 288
288 if (url.isValid() && !m_resourceURLs.contains(url)) { 289 if (url.isValid() && !m_resourceURLs.contains(url)) {
289 // FIXME: We should check whether a charset has been specified and if no ne was found add one. 290 // FIXME: We should check whether a charset has been specified and if no ne was found add one.
290 WTF::TextEncoding textEncoding(styleSheet->contents()->charset()); 291 WTF::TextEncoding textEncoding(styleSheet.contents()->charset());
291 ASSERT(textEncoding.isValid()); 292 ASSERT(textEncoding.isValid());
292 String textString = cssText.toString(); 293 String textString = cssText.toString();
293 CString text = textEncoding.normalizeAndEncode(textString, WTF::Entities ForUnencodables); 294 CString text = textEncoding.normalizeAndEncode(textString, WTF::Entities ForUnencodables);
294 m_resources->append(SerializedResource(url, String("text/css"), SharedBu ffer::create(text.data(), text.length()))); 295 m_resources->append(SerializedResource(url, String("text/css"), SharedBu ffer::create(text.data(), text.length())));
295 m_resourceURLs.add(url); 296 m_resourceURLs.add(url);
296 } 297 }
297 } 298 }
298 299
299 bool PageSerializer::shouldAddURL(const KURL& url) 300 bool PageSerializer::shouldAddURL(const KURL& url)
300 { 301 {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (iter != m_blankFrameURLs.end()) 384 if (iter != m_blankFrameURLs.end())
384 return iter->value; 385 return iter->value;
385 String url = "wyciwyg://frame/" + String::number(m_blankFrameCounter++); 386 String url = "wyciwyg://frame/" + String::number(m_blankFrameCounter++);
386 KURL fakeURL(ParsedURLString, url); 387 KURL fakeURL(ParsedURLString, url);
387 m_blankFrameURLs.add(frame, fakeURL); 388 m_blankFrameURLs.add(frame, fakeURL);
388 389
389 return fakeURL; 390 return fakeURL;
390 } 391 }
391 392
392 } 393 }
OLDNEW
« no previous file with comments | « Source/core/page/PageSerializer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698