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 17 matching lines...) Expand all Loading... |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "platform/mhtml/MHTMLArchive.h" | 32 #include "platform/mhtml/MHTMLArchive.h" |
33 | 33 |
34 #include "platform/DateComponents.h" | 34 #include "platform/DateComponents.h" |
35 #include "platform/MIMETypeRegistry.h" | 35 #include "platform/MIMETypeRegistry.h" |
36 #include "platform/SerializedResource.h" | 36 #include "platform/SerializedResource.h" |
37 #include "platform/SharedBuffer.h" | 37 #include "platform/SharedBuffer.h" |
| 38 #include "platform/mhtml/ArchiveResource.h" |
38 #include "platform/mhtml/MHTMLParser.h" | 39 #include "platform/mhtml/MHTMLParser.h" |
39 #include "platform/text/QuotedPrintable.h" | 40 #include "platform/text/QuotedPrintable.h" |
40 #include "platform/weborigin/SchemeRegistry.h" | 41 #include "platform/weborigin/SchemeRegistry.h" |
41 #include "wtf/CryptographicallyRandomNumber.h" | 42 #include "wtf/CryptographicallyRandomNumber.h" |
42 #include "wtf/DateMath.h" | 43 #include "wtf/DateMath.h" |
43 #include "wtf/text/Base64.h" | 44 #include "wtf/text/Base64.h" |
44 #include "wtf/text/StringBuilder.h" | 45 #include "wtf/text/StringBuilder.h" |
45 | 46 |
46 namespace WebCore { | 47 namespace WebCore { |
47 | 48 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 80 } |
80 return stringBuilder.toString(); | 81 return stringBuilder.toString(); |
81 } | 82 } |
82 | 83 |
83 MHTMLArchive::MHTMLArchive() | 84 MHTMLArchive::MHTMLArchive() |
84 { | 85 { |
85 } | 86 } |
86 | 87 |
87 MHTMLArchive::~MHTMLArchive() | 88 MHTMLArchive::~MHTMLArchive() |
88 { | 89 { |
| 90 #if !ENABLE(OILPAN) |
89 // Because all frames know about each other we need to perform a deep cleari
ng of the archives graph. | 91 // Because all frames know about each other we need to perform a deep cleari
ng of the archives graph. |
90 clearAllSubframeArchives(); | 92 clearAllSubframeArchives(); |
| 93 #endif |
91 } | 94 } |
92 | 95 |
93 PassRefPtr<MHTMLArchive> MHTMLArchive::create() | 96 PassRefPtrWillBeRawPtr<MHTMLArchive> MHTMLArchive::create() |
94 { | 97 { |
95 return adoptRef(new MHTMLArchive); | 98 return adoptRefWillBeNoop(new MHTMLArchive); |
96 } | 99 } |
97 | 100 |
98 PassRefPtr<MHTMLArchive> MHTMLArchive::create(const KURL& url, SharedBuffer* dat
a) | 101 PassRefPtrWillBeRawPtr<MHTMLArchive> MHTMLArchive::create(const KURL& url, Share
dBuffer* data) |
99 { | 102 { |
100 // For security reasons we only load MHTML pages from local URLs. | 103 // For security reasons we only load MHTML pages from local URLs. |
101 if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol())) | 104 if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol())) |
102 return nullptr; | 105 return nullptr; |
103 | 106 |
104 MHTMLParser parser(data); | 107 MHTMLParser parser(data); |
105 RefPtr<MHTMLArchive> mainArchive = parser.parseArchive(); | 108 RefPtrWillBeRawPtr<MHTMLArchive> mainArchive = parser.parseArchive(); |
106 if (!mainArchive) | 109 if (!mainArchive) |
107 return nullptr; // Invalid MHTML file. | 110 return nullptr; // Invalid MHTML file. |
108 | 111 |
109 // Since MHTML is a flat format, we need to make all frames aware of all res
ources. | 112 // Since MHTML is a flat format, we need to make all frames aware of all res
ources. |
110 for (size_t i = 0; i < parser.frameCount(); ++i) { | 113 for (size_t i = 0; i < parser.frameCount(); ++i) { |
111 RefPtr<MHTMLArchive> archive = parser.frameAt(i); | 114 RefPtrWillBeRawPtr<MHTMLArchive> archive = parser.frameAt(i); |
112 for (size_t j = 1; j < parser.frameCount(); ++j) { | 115 for (size_t j = 1; j < parser.frameCount(); ++j) { |
113 if (i != j) | 116 if (i != j) |
114 archive->addSubframeArchive(parser.frameAt(j)); | 117 archive->addSubframeArchive(parser.frameAt(j)); |
115 } | 118 } |
116 for (size_t j = 0; j < parser.subResourceCount(); ++j) | 119 for (size_t j = 0; j < parser.subResourceCount(); ++j) |
117 archive->addSubresource(parser.subResourceAt(j)); | 120 archive->addSubresource(parser.subResourceAt(j)); |
118 } | 121 } |
119 return mainArchive.release(); | 122 return mainArchive.release(); |
120 } | 123 } |
121 | 124 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 210 } |
208 } | 211 } |
209 } | 212 } |
210 | 213 |
211 asciiString = String("--" + boundary + "--\r\n").utf8(); | 214 asciiString = String("--" + boundary + "--\r\n").utf8(); |
212 mhtmlData->append(asciiString.data(), asciiString.length()); | 215 mhtmlData->append(asciiString.data(), asciiString.length()); |
213 | 216 |
214 return mhtmlData.release(); | 217 return mhtmlData.release(); |
215 } | 218 } |
216 | 219 |
| 220 #if !ENABLE(OILPAN) |
217 void MHTMLArchive::clearAllSubframeArchives() | 221 void MHTMLArchive::clearAllSubframeArchives() |
218 { | 222 { |
219 Vector<RefPtr<MHTMLArchive> > clearedArchives; | 223 SubFrameArchives clearedArchives; |
220 clearAllSubframeArchivesImpl(&clearedArchives); | 224 clearAllSubframeArchivesImpl(&clearedArchives); |
221 } | 225 } |
222 | 226 |
223 void MHTMLArchive::clearAllSubframeArchivesImpl(Vector<RefPtr<MHTMLArchive> >* c
learedArchives) | 227 void MHTMLArchive::clearAllSubframeArchivesImpl(SubFrameArchives* clearedArchive
s) |
224 { | 228 { |
225 for (Vector<RefPtr<MHTMLArchive> >::iterator it = m_subframeArchives.begin()
; it != m_subframeArchives.end(); ++it) { | 229 for (SubFrameArchives::iterator it = m_subframeArchives.begin(); it != m_sub
frameArchives.end(); ++it) { |
226 if (!clearedArchives->contains(*it)) { | 230 if (!clearedArchives->contains(*it)) { |
227 clearedArchives->append(*it); | 231 clearedArchives->append(*it); |
228 (*it)->clearAllSubframeArchivesImpl(clearedArchives); | 232 (*it)->clearAllSubframeArchivesImpl(clearedArchives); |
229 } | 233 } |
230 } | 234 } |
231 m_subframeArchives.clear(); | 235 m_subframeArchives.clear(); |
232 } | 236 } |
| 237 #endif |
| 238 |
| 239 void MHTMLArchive::setMainResource(PassRefPtrWillBeRawPtr<ArchiveResource> mainR
esource) |
| 240 { |
| 241 m_mainResource = mainResource; |
| 242 } |
| 243 |
| 244 void MHTMLArchive::addSubresource(PassRefPtrWillBeRawPtr<ArchiveResource> subRes
ource) |
| 245 { |
| 246 m_subresources.append(subResource); |
| 247 } |
| 248 |
| 249 void MHTMLArchive::addSubframeArchive(PassRefPtrWillBeRawPtr<MHTMLArchive> subfr
ameArchive) |
| 250 { |
| 251 m_subframeArchives.append(subframeArchive); |
| 252 } |
| 253 |
| 254 void MHTMLArchive::trace(Visitor* visitor) |
| 255 { |
| 256 visitor->trace(m_mainResource); |
| 257 visitor->trace(m_subresources); |
| 258 visitor->trace(m_subframeArchives); |
| 259 } |
233 | 260 |
234 } | 261 } |
OLD | NEW |