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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // TODO(lukasza): This causes incomplete MHTML for OOPIFs. | 390 // TODO(lukasza): This causes incomplete MHTML for OOPIFs. |
391 // (crbug.com/538766) | 391 // (crbug.com/538766) |
392 if (childFrame->isLocalFrame()) | 392 if (childFrame->isLocalFrame()) |
393 serializeFrame(toLocalFrame(childFrame)); | 393 serializeFrame(toLocalFrame(childFrame)); |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KUR
L& url) | 397 void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KUR
L& url) |
398 { | 398 { |
399 StringBuilder cssText; | 399 StringBuilder cssText; |
| 400 cssText.appendLiteral("@charset \""); |
| 401 cssText.append(styleSheet.contents()->charset().lower()); |
| 402 cssText.appendLiteral("\";\n\n"); |
| 403 |
400 for (unsigned i = 0; i < styleSheet.length(); ++i) { | 404 for (unsigned i = 0; i < styleSheet.length(); ++i) { |
401 CSSRule* rule = styleSheet.item(i); | 405 CSSRule* rule = styleSheet.item(i); |
402 String itemText = rule->cssText(); | 406 String itemText = rule->cssText(); |
403 if (!itemText.isEmpty()) { | 407 if (!itemText.isEmpty()) { |
404 cssText.append(itemText); | 408 cssText.append(itemText); |
405 if (i < styleSheet.length() - 1) | 409 if (i < styleSheet.length() - 1) |
406 cssText.appendLiteral("\n\n"); | 410 cssText.appendLiteral("\n\n"); |
407 } | 411 } |
408 | 412 |
409 // Some rules have resources associated with them that we need to retrie
ve. | 413 // Some rules have resources associated with them that we need to retrie
ve. |
410 serializeCSSRule(rule); | 414 serializeCSSRule(rule); |
411 } | 415 } |
412 | 416 |
413 if (url.isValid() && !m_resourceURLs.contains(url)) { | 417 if (url.isValid() && !m_resourceURLs.contains(url)) { |
414 // FIXME: We should check whether a charset has been specified and if no
ne was found add one. | |
415 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); | 418 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); |
416 ASSERT(textEncoding.isValid()); | 419 ASSERT(textEncoding.isValid()); |
417 // TODO(jsbell): Ensure @charset is written out if non-UTF-8. | |
418 String textString = cssText.toString(); | 420 String textString = cssText.toString(); |
419 CString text = textEncoding.encode(textString, WTF::EntitiesForUnencodab
les); | 421 CString text = textEncoding.encode(textString, WTF::EntitiesForUnencodab
les); |
420 m_resources->append(SerializedResource(url, String("text/css"), SharedBu
ffer::create(text.data(), text.length()))); | 422 m_resources->append(SerializedResource(url, String("text/css"), SharedBu
ffer::create(text.data(), text.length()))); |
421 m_resourceURLs.add(url); | 423 m_resourceURLs.add(url); |
422 } | 424 } |
423 } | 425 } |
424 | 426 |
425 void PageSerializer::serializeCSSRule(CSSRule* rule) | 427 void PageSerializer::serializeCSSRule(CSSRule* rule) |
426 { | 428 { |
427 ASSERT(rule->parentStyleSheet()->ownerDocument()); | 429 ASSERT(rule->parentStyleSheet()->ownerDocument()); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 continue; | 597 continue; |
596 } | 598 } |
597 emitsMinus = ch == '-'; | 599 emitsMinus = ch == '-'; |
598 builder.append(ch); | 600 builder.append(ch); |
599 } | 601 } |
600 CString escapedUrl = builder.toString().ascii(); | 602 CString escapedUrl = builder.toString().ascii(); |
601 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl
.length()), escapedUrl.data()); | 603 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl
.length()), escapedUrl.data()); |
602 } | 604 } |
603 | 605 |
604 } // namespace blink | 606 } // namespace blink |
OLD | NEW |