Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/page/PageSerializer.h" | 32 #include "core/page/PageSerializer.h" |
| 33 | 33 |
| 34 #include "core/HTMLNames.h" | 34 #include "core/HTMLNames.h" |
| 35 #include "core/InputTypeNames.h" | 35 #include "core/InputTypeNames.h" |
| 36 #include "core/css/CSSFontFaceRule.h" | 36 #include "core/css/CSSFontFaceRule.h" |
| 37 #include "core/css/CSSFontFaceSrcValue.h" | 37 #include "core/css/CSSFontFaceSrcValue.h" |
| 38 #include "core/css/CSSImageValue.h" | 38 #include "core/css/CSSImageValue.h" |
| 39 #include "core/css/CSSImportRule.h" | 39 #include "core/css/CSSImportRule.h" |
| 40 #include "core/css/CSSMediaRule.h" | |
| 41 #include "core/css/CSSRuleList.h" | |
| 40 #include "core/css/CSSStyleDeclaration.h" | 42 #include "core/css/CSSStyleDeclaration.h" |
| 41 #include "core/css/CSSStyleRule.h" | 43 #include "core/css/CSSStyleRule.h" |
| 42 #include "core/css/CSSValueList.h" | 44 #include "core/css/CSSValueList.h" |
| 43 #include "core/css/StylePropertySet.h" | 45 #include "core/css/StylePropertySet.h" |
| 44 #include "core/css/StyleRule.h" | 46 #include "core/css/StyleRule.h" |
| 45 #include "core/css/StyleSheetContents.h" | 47 #include "core/css/StyleSheetContents.h" |
| 46 #include "core/dom/Document.h" | 48 #include "core/dom/Document.h" |
| 47 #include "core/dom/Element.h" | 49 #include "core/dom/Element.h" |
| 48 #include "core/dom/Text.h" | 50 #include "core/dom/Text.h" |
| 49 #include "core/editing/MarkupAccumulator.h" | 51 #include "core/editing/MarkupAccumulator.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 { | 297 { |
| 296 StringBuilder cssText; | 298 StringBuilder cssText; |
| 297 for (unsigned i = 0; i < styleSheet.length(); ++i) { | 299 for (unsigned i = 0; i < styleSheet.length(); ++i) { |
| 298 CSSRule* rule = styleSheet.item(i); | 300 CSSRule* rule = styleSheet.item(i); |
| 299 String itemText = rule->cssText(); | 301 String itemText = rule->cssText(); |
| 300 if (!itemText.isEmpty()) { | 302 if (!itemText.isEmpty()) { |
| 301 cssText.append(itemText); | 303 cssText.append(itemText); |
| 302 if (i < styleSheet.length() - 1) | 304 if (i < styleSheet.length() - 1) |
| 303 cssText.appendLiteral("\n\n"); | 305 cssText.appendLiteral("\n\n"); |
| 304 } | 306 } |
| 305 ASSERT(styleSheet.ownerDocument()); | 307 |
| 306 Document& document = *styleSheet.ownerDocument(); | |
| 307 // Some rules have resources associated with them that we need to retrie ve. | 308 // Some rules have resources associated with them that we need to retrie ve. |
| 308 if (rule->type() == CSSRule::IMPORT_RULE) { | 309 serializeCSSRule(rule); |
| 309 CSSImportRule* importRule = toCSSImportRule(rule); | |
| 310 ASSERT(styleSheet.baseURL().isValid()); | |
| 311 KURL importURL = KURL(styleSheet.baseURL(), importRule->href()); | |
| 312 if (m_resourceURLs.contains(importURL)) | |
| 313 continue; | |
| 314 if (importRule->styleSheet()) | |
| 315 serializeCSSStyleSheet(*importRule->styleSheet(), importURL); | |
| 316 } else if (rule->type() == CSSRule::FONT_FACE_RULE) { | |
| 317 retrieveResourcesForProperties(&toCSSFontFaceRule(rule)->styleRule() ->properties(), document); | |
| 318 } else if (rule->type() == CSSRule::STYLE_RULE) { | |
| 319 retrieveResourcesForProperties(&toCSSStyleRule(rule)->styleRule()->p roperties(), document); | |
| 320 } | |
| 321 } | 310 } |
| 322 | 311 |
| 323 if (url.isValid() && !m_resourceURLs.contains(url)) { | 312 if (url.isValid() && !m_resourceURLs.contains(url)) { |
| 324 // FIXME: We should check whether a charset has been specified and if no ne was found add one. | 313 // FIXME: We should check whether a charset has been specified and if no ne was found add one. |
| 325 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); | 314 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); |
| 326 ASSERT(textEncoding.isValid()); | 315 ASSERT(textEncoding.isValid()); |
| 327 String textString = cssText.toString(); | 316 String textString = cssText.toString(); |
| 328 CString text = textEncoding.normalizeAndEncode(textString, WTF::Entities ForUnencodables); | 317 CString text = textEncoding.normalizeAndEncode(textString, WTF::Entities ForUnencodables); |
| 329 m_resources->append(SerializedResource(url, String("text/css"), SharedBu ffer::create(text.data(), text.length()))); | 318 m_resources->append(SerializedResource(url, String("text/css"), SharedBu ffer::create(text.data(), text.length()))); |
| 330 m_resourceURLs.add(url); | 319 m_resourceURLs.add(url); |
| 331 } | 320 } |
| 332 } | 321 } |
| 333 | 322 |
| 323 void PageSerializer::serializeCSSRule(CSSRule* rule) | |
| 324 { | |
| 325 ASSERT(rule->parentStyleSheet()->ownerDocument()); | |
| 326 Document& document = *rule->parentStyleSheet()->ownerDocument(); | |
| 327 | |
| 328 if (rule->type() == CSSRule::IMPORT_RULE) { | |
|
hajimehoshi
2015/06/25 02:27:05
switch-case seems better
| |
| 329 CSSImportRule* importRule = toCSSImportRule(rule); | |
| 330 KURL sheetBaseURL = rule->parentStyleSheet()->baseURL(); | |
| 331 ASSERT(sheetBaseURL.isValid()); | |
| 332 KURL importURL = KURL(sheetBaseURL, importRule->href()); | |
| 333 if (m_resourceURLs.contains(importURL)) | |
| 334 return; | |
| 335 if (importRule->styleSheet()) | |
| 336 serializeCSSStyleSheet(*importRule->styleSheet(), importURL); | |
| 337 } else if (rule->type() == CSSRule::FONT_FACE_RULE) { | |
| 338 retrieveResourcesForProperties(&toCSSFontFaceRule(rule)->styleRule()->pr operties(), document); | |
| 339 } else if (rule->type() == CSSRule::STYLE_RULE) { | |
| 340 retrieveResourcesForProperties(&toCSSStyleRule(rule)->styleRule()->prope rties(), document); | |
| 341 } else if (rule->type() == CSSRule::MEDIA_RULE) { | |
| 342 CSSRuleList* ruleList = toCSSMediaRule(rule)->cssRules(); | |
| 343 for (unsigned i = 0; i < ruleList->length(); ++i) { | |
|
hajimehoshi
2015/06/25 02:27:05
nit: no {}
| |
| 344 serializeCSSRule(ruleList->item(i)); | |
| 345 } | |
| 346 } | |
| 347 } | |
| 348 | |
| 334 bool PageSerializer::shouldAddURL(const KURL& url) | 349 bool PageSerializer::shouldAddURL(const KURL& url) |
| 335 { | 350 { |
| 336 return url.isValid() && !m_resourceURLs.contains(url) && !url.protocolIsData (); | 351 return url.isValid() && !m_resourceURLs.contains(url) && !url.protocolIsData (); |
| 337 } | 352 } |
| 338 | 353 |
| 339 void PageSerializer::addToResources(Resource* resource, PassRefPtr<SharedBuffer> data, const KURL& url) | 354 void PageSerializer::addToResources(Resource* resource, PassRefPtr<SharedBuffer> data, const KURL& url) |
| 340 { | 355 { |
| 341 if (!data) { | 356 if (!data) { |
| 342 WTF_LOG_ERROR("No data for resource %s", url.string().utf8().data()); | 357 WTF_LOG_ERROR("No data for resource %s", url.string().utf8().data()); |
| 343 return; | 358 return; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 | 438 |
| 424 return fakeURL; | 439 return fakeURL; |
| 425 } | 440 } |
| 426 | 441 |
| 427 PageSerializer::Delegate* PageSerializer::delegate() | 442 PageSerializer::Delegate* PageSerializer::delegate() |
| 428 { | 443 { |
| 429 return m_delegate.get(); | 444 return m_delegate.get(); |
| 430 } | 445 } |
| 431 | 446 |
| 432 } // namespace blink | 447 } // namespace blink |
| OLD | NEW |