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 \""); | |
jsbell
2015/10/27 17:52:43
We could skip this if the encoding is the default
yosin_UTC9
2015/10/28 00:14:57
Really? I think default charset depends of Chrome'
jsbell
2015/10/28 18:16:55
Oh, good point. Always outputting seems sensible t
jsbell
2015/11/02 23:55:38
Done.
| |
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. | 418 // FIXME: We should check whether a charset has been specified and if no ne was found add one. |
jsbell
2015/10/27 17:52:43
Not sure if the FIXME here is referring to the lac
yosin_UTC9
2015/10/30 01:57:01
Agree. This patch always adds @charset.
jsbell
2015/11/02 23:55:38
Done.
| |
415 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); | 419 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); |
416 ASSERT(textEncoding.isValid()); | 420 ASSERT(textEncoding.isValid()); |
417 // TODO(jsbell): Ensure @charset is written out if non-UTF-8. | |
418 String textString = cssText.toString(); | 421 String textString = cssText.toString(); |
419 CString text = textEncoding.encode(textString, WTF::EntitiesForUnencodab les); | 422 CString text = textEncoding.encode(textString, WTF::EntitiesForUnencodab les); |
420 m_resources->append(SerializedResource(url, String("text/css"), SharedBu ffer::create(text.data(), text.length()))); | 423 m_resources->append(SerializedResource(url, String("text/css"), SharedBu ffer::create(text.data(), text.length()))); |
421 m_resourceURLs.add(url); | 424 m_resourceURLs.add(url); |
422 } | 425 } |
423 } | 426 } |
424 | 427 |
425 void PageSerializer::serializeCSSRule(CSSRule* rule) | 428 void PageSerializer::serializeCSSRule(CSSRule* rule) |
426 { | 429 { |
427 ASSERT(rule->parentStyleSheet()->ownerDocument()); | 430 ASSERT(rule->parentStyleSheet()->ownerDocument()); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 continue; | 598 continue; |
596 } | 599 } |
597 emitsMinus = ch == '-'; | 600 emitsMinus = ch == '-'; |
598 builder.append(ch); | 601 builder.append(ch); |
599 } | 602 } |
600 CString escapedUrl = builder.toString().ascii(); | 603 CString escapedUrl = builder.toString().ascii(); |
601 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl .length()), escapedUrl.data()); | 604 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl .length()), escapedUrl.data()); |
602 } | 605 } |
603 | 606 |
604 } // namespace blink | 607 } // namespace blink |
OLD | NEW |