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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return m_delegate.shouldIgnoreAttribute(attribute); | 139 return m_delegate.shouldIgnoreAttribute(attribute); |
140 } | 140 } |
141 | 141 |
142 void SerializerMarkupAccumulator::appendElement(StringBuilder& result, Element&
element, Namespaces* namespaces) | 142 void SerializerMarkupAccumulator::appendElement(StringBuilder& result, Element&
element, Namespaces* namespaces) |
143 { | 143 { |
144 if (!shouldIgnoreElement(element)) | 144 if (!shouldIgnoreElement(element)) |
145 MarkupAccumulator::appendElement(result, element, namespaces); | 145 MarkupAccumulator::appendElement(result, element, namespaces); |
146 | 146 |
147 // TODO(tiger): Refactor MarkupAccumulator so it is easier to append an elem
ent like this, without special cases for XHTML | 147 // TODO(tiger): Refactor MarkupAccumulator so it is easier to append an elem
ent like this, without special cases for XHTML |
148 if (isHTMLHeadElement(element)) { | 148 if (isHTMLHeadElement(element)) { |
149 result.appendLiteral("<meta http-equiv=\"Content-Type\" content=\""); | 149 result.append("<meta http-equiv=\"Content-Type\" content=\""); |
150 appendAttributeValue(result, m_document->suggestedMIMEType()); | 150 appendAttributeValue(result, m_document->suggestedMIMEType()); |
151 result.appendLiteral("; charset="); | 151 result.append("; charset="); |
152 appendAttributeValue(result, m_document->characterSet()); | 152 appendAttributeValue(result, m_document->characterSet()); |
153 if (m_document->isXHTMLDocument()) | 153 if (m_document->isXHTMLDocument()) |
154 result.appendLiteral("\" />"); | 154 result.append("\" />"); |
155 else | 155 else |
156 result.appendLiteral("\">"); | 156 result.append("\">"); |
157 } | 157 } |
158 | 158 |
159 // FIXME: For object (plugins) tags and video tag we could replace them by a
n image of their current contents. | 159 // FIXME: For object (plugins) tags and video tag we could replace them by a
n image of their current contents. |
160 } | 160 } |
161 | 161 |
162 void SerializerMarkupAccumulator::appendAttribute( | 162 void SerializerMarkupAccumulator::appendAttribute( |
163 StringBuilder& out, | 163 StringBuilder& out, |
164 const Element& element, | 164 const Element& element, |
165 const Attribute& attribute, | 165 const Attribute& attribute, |
166 Namespaces* namespaces) | 166 Namespaces* namespaces) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 const String& attributeValue) | 220 const String& attributeValue) |
221 { | 221 { |
222 if (m_elementsWithRewrittenLinks.contains(&element)) | 222 if (m_elementsWithRewrittenLinks.contains(&element)) |
223 return; | 223 return; |
224 m_elementsWithRewrittenLinks.add(&element); | 224 m_elementsWithRewrittenLinks.add(&element); |
225 | 225 |
226 // Append the rewritten attribute. | 226 // Append the rewritten attribute. |
227 // TODO(tiger): Refactor MarkupAccumulator so it is easier to append an attr
ibute like this. | 227 // TODO(tiger): Refactor MarkupAccumulator so it is easier to append an attr
ibute like this. |
228 out.append(' '); | 228 out.append(' '); |
229 out.append(attributeName); | 229 out.append(attributeName); |
230 out.appendLiteral("=\""); | 230 out.append("=\""); |
231 appendAttributeValue(out, attributeValue); | 231 appendAttributeValue(out, attributeValue); |
232 out.appendLiteral("\""); | 232 out.append("\""); |
233 } | 233 } |
234 | 234 |
235 // TODO(tiger): Right now there is no support for rewriting URLs inside CSS | 235 // TODO(tiger): Right now there is no support for rewriting URLs inside CSS |
236 // documents which leads to bugs like <https://crbug.com/251898>. Not being | 236 // documents which leads to bugs like <https://crbug.com/251898>. Not being |
237 // able to rewrite URLs inside CSS documents means that resources imported from | 237 // able to rewrite URLs inside CSS documents means that resources imported from |
238 // url(...) statements in CSS might not work when rewriting links for the | 238 // url(...) statements in CSS might not work when rewriting links for the |
239 // "Webpage, Complete" method of saving a page. It will take some work but it | 239 // "Webpage, Complete" method of saving a page. It will take some work but it |
240 // needs to be done if we want to continue to support non-MHTML saved pages. | 240 // needs to be done if we want to continue to support non-MHTML saved pages. |
241 | 241 |
242 FrameSerializer::FrameSerializer( | 242 FrameSerializer::FrameSerializer( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 HTMLStyleElement& styleElement = toHTMLStyleElement(element); | 301 HTMLStyleElement& styleElement = toHTMLStyleElement(element); |
302 if (CSSStyleSheet* sheet = styleElement.sheet()) | 302 if (CSSStyleSheet* sheet = styleElement.sheet()) |
303 serializeCSSStyleSheet(*sheet, KURL()); | 303 serializeCSSStyleSheet(*sheet, KURL()); |
304 } | 304 } |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KU
RL& url) | 308 void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KU
RL& url) |
309 { | 309 { |
310 StringBuilder cssText; | 310 StringBuilder cssText; |
311 cssText.appendLiteral("@charset \""); | 311 cssText.append("@charset \""); |
312 cssText.append(styleSheet.contents()->charset().lower()); | 312 cssText.append(styleSheet.contents()->charset().lower()); |
313 cssText.appendLiteral("\";\n\n"); | 313 cssText.append("\";\n\n"); |
314 | 314 |
315 for (unsigned i = 0; i < styleSheet.length(); ++i) { | 315 for (unsigned i = 0; i < styleSheet.length(); ++i) { |
316 CSSRule* rule = styleSheet.item(i); | 316 CSSRule* rule = styleSheet.item(i); |
317 String itemText = rule->cssText(); | 317 String itemText = rule->cssText(); |
318 if (!itemText.isEmpty()) { | 318 if (!itemText.isEmpty()) { |
319 cssText.append(itemText); | 319 cssText.append(itemText); |
320 if (i < styleSheet.length() - 1) | 320 if (i < styleSheet.length() - 1) |
321 cssText.appendLiteral("\n\n"); | 321 cssText.append("\n\n"); |
322 } | 322 } |
323 | 323 |
324 // Some rules have resources associated with them that we need to retrie
ve. | 324 // Some rules have resources associated with them that we need to retrie
ve. |
325 serializeCSSRule(rule); | 325 serializeCSSRule(rule); |
326 } | 326 } |
327 | 327 |
328 if (shouldAddURL(url)) { | 328 if (shouldAddURL(url)) { |
329 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); | 329 WTF::TextEncoding textEncoding(styleSheet.contents()->charset()); |
330 ASSERT(textEncoding.isValid()); | 330 ASSERT(textEncoding.isValid()); |
331 String textString = cssText.toString(); | 331 String textString = cssText.toString(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 continue; | 479 continue; |
480 } | 480 } |
481 emitsMinus = ch == '-'; | 481 emitsMinus = ch == '-'; |
482 builder.append(ch); | 482 builder.append(ch); |
483 } | 483 } |
484 CString escapedUrl = builder.toString().ascii(); | 484 CString escapedUrl = builder.toString().ascii(); |
485 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl
.length()), escapedUrl.data()); | 485 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl
.length()), escapedUrl.data()); |
486 } | 486 } |
487 | 487 |
488 } // namespace blink | 488 } // namespace blink |
OLD | NEW |