OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 else if (element->hasTagName(HTMLNames::embedTag)) | 92 else if (element->hasTagName(HTMLNames::embedTag)) |
93 attributeName = &HTMLNames::srcAttr; | 93 attributeName = &HTMLNames::srcAttr; |
94 | 94 |
95 if (!attributeName) | 95 if (!attributeName) |
96 return KURL(); | 96 return KURL(); |
97 | 97 |
98 String value = element->getAttribute(*attributeName); | 98 String value = element->getAttribute(*attributeName); |
99 // Ignore javascript content. | 99 // Ignore javascript content. |
100 if (value.isEmpty() || value.stripWhiteSpace().startsWith("javascript:", fal
se)) | 100 if (value.isEmpty() || value.stripWhiteSpace().startsWith("javascript:", fal
se)) |
101 return KURL(); | 101 return KURL(); |
102 | 102 |
103 return element->document()->completeURL(value); | 103 return element->document()->completeURL(value); |
104 } | 104 } |
105 | 105 |
106 void retrieveResourcesForElement(Element* element, | 106 void retrieveResourcesForElement(Element* element, |
107 Vector<Frame*>* visitedFrames, | 107 Vector<Frame*>* visitedFrames, |
108 Vector<Frame*>* framesToVisit, | 108 Vector<Frame*>* framesToVisit, |
109 Vector<KURL>* frameURLs, | 109 Vector<KURL>* frameURLs, |
110 Vector<KURL>* resourceURLs) | 110 Vector<KURL>* resourceURLs) |
111 { | 111 { |
112 // If the node is a frame, we'll process it later in retrieveResourcesForFra
me. | 112 // If the node is a frame, we'll process it later in retrieveResourcesForFra
me. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 157 } |
158 if (!isValidScheme) | 158 if (!isValidScheme) |
159 return; | 159 return; |
160 | 160 |
161 // If we have already seen that frame, ignore it. | 161 // If we have already seen that frame, ignore it. |
162 if (visitedFrames->contains(frame)) | 162 if (visitedFrames->contains(frame)) |
163 return; | 163 return; |
164 visitedFrames->append(frame); | 164 visitedFrames->append(frame); |
165 if (!frameURLs->contains(frameURL)) | 165 if (!frameURLs->contains(frameURL)) |
166 frameURLs->append(frameURL); | 166 frameURLs->append(frameURL); |
167 | 167 |
168 // Now get the resources associated with each node of the document. | 168 // Now get the resources associated with each node of the document. |
169 RefPtr<HTMLCollection> allNodes = frame->document()->all(); | 169 RefPtr<HTMLCollection> allNodes = frame->document()->all(); |
170 for (unsigned i = 0; i < allNodes->length(); ++i) { | 170 for (unsigned i = 0; i < allNodes->length(); ++i) { |
171 Node* node = allNodes->item(i); | 171 Node* node = allNodes->item(i); |
172 // We are only interested in HTML resources. | 172 // We are only interested in HTML resources. |
173 if (!node->isElementNode()) | 173 if (!node->isElementNode()) |
174 continue; | 174 continue; |
175 retrieveResourcesForElement(toElement(node), | 175 retrieveResourcesForElement(toElement(node), |
176 visitedFrames, framesToVisit, | 176 visitedFrames, framesToVisit, |
177 frameURLs, resourceURLs); | 177 frameURLs, resourceURLs); |
(...skipping 13 matching lines...) Expand all Loading... |
191 Vector<Resource> result; | 191 Vector<Resource> result; |
192 for (Vector<SerializedResource>::const_iterator iter = resources.begin(); it
er != resources.end(); ++iter) { | 192 for (Vector<SerializedResource>::const_iterator iter = resources.begin(); it
er != resources.end(); ++iter) { |
193 Resource resource; | 193 Resource resource; |
194 resource.url = iter->url; | 194 resource.url = iter->url; |
195 resource.mimeType = iter->mimeType.ascii(); | 195 resource.mimeType = iter->mimeType.ascii(); |
196 // FIXME: we are copying all the resource data here. Idealy we would hav
e a WebSharedData(). | 196 // FIXME: we are copying all the resource data here. Idealy we would hav
e a WebSharedData(). |
197 resource.data = WebCString(iter->data->data(), iter->data->size()); | 197 resource.data = WebCString(iter->data->data(), iter->data->size()); |
198 result.append(resource); | 198 result.append(resource); |
199 } | 199 } |
200 | 200 |
201 *resourcesParam = result; | 201 *resourcesParam = result; |
202 } | 202 } |
203 | 203 |
204 static PassRefPtr<SharedBuffer> serializePageToMHTML(Page* page, MHTMLArchive::E
ncodingPolicy encodingPolicy) | 204 static PassRefPtr<SharedBuffer> serializePageToMHTML(Page* page, MHTMLArchive::E
ncodingPolicy encodingPolicy) |
205 { | 205 { |
206 Vector<SerializedResource> resources; | 206 Vector<SerializedResource> resources; |
207 PageSerializer serializer(&resources); | 207 PageSerializer serializer(&resources); |
208 serializer.serialize(page); | 208 serializer.serialize(page); |
209 Document* document = page->mainFrame()->document(); | 209 Document* document = page->mainFrame()->document(); |
210 return MHTMLArchive::generateMHTMLData(resources, encodingPolicy, document->
title(), document->suggestedMIMEType()); | 210 return MHTMLArchive::generateMHTMLData(resources, encodingPolicy, document->
title(), document->suggestedMIMEType()); |
211 } | 211 } |
(...skipping 29 matching lines...) Expand all Loading... |
241 WebVector<WebURL>* resourceURLs, | 241 WebVector<WebURL>* resourceURLs, |
242 WebVector<WebURL>* frameURLs) { | 242 WebVector<WebURL>* frameURLs) { |
243 WebFrameImpl* mainFrame = static_cast<WebFrameImpl*>(view->mainFrame()); | 243 WebFrameImpl* mainFrame = static_cast<WebFrameImpl*>(view->mainFrame()); |
244 if (!mainFrame) | 244 if (!mainFrame) |
245 return false; | 245 return false; |
246 | 246 |
247 Vector<Frame*> framesToVisit; | 247 Vector<Frame*> framesToVisit; |
248 Vector<Frame*> visitedFrames; | 248 Vector<Frame*> visitedFrames; |
249 Vector<KURL> frameKURLs; | 249 Vector<KURL> frameKURLs; |
250 Vector<KURL> resourceKURLs; | 250 Vector<KURL> resourceKURLs; |
251 | 251 |
252 // Let's retrieve the resources from every frame in this page. | 252 // Let's retrieve the resources from every frame in this page. |
253 framesToVisit.append(mainFrame->frame()); | 253 framesToVisit.append(mainFrame->frame()); |
254 while (!framesToVisit.isEmpty()) { | 254 while (!framesToVisit.isEmpty()) { |
255 Frame* frame = framesToVisit[0]; | 255 Frame* frame = framesToVisit[0]; |
256 framesToVisit.remove(0); | 256 framesToVisit.remove(0); |
257 retrieveResourcesForFrame(frame, supportedSchemes, | 257 retrieveResourcesForFrame(frame, supportedSchemes, |
258 &visitedFrames, &framesToVisit, | 258 &visitedFrames, &framesToVisit, |
259 &frameKURLs, &resourceKURLs); | 259 &frameKURLs, &resourceKURLs); |
260 } | 260 } |
261 | 261 |
262 // Converts the results to WebURLs. | 262 // Converts the results to WebURLs. |
263 WebVector<WebURL> resultResourceURLs(resourceKURLs.size()); | 263 WebVector<WebURL> resultResourceURLs(resourceKURLs.size()); |
264 for (size_t i = 0; i < resourceKURLs.size(); ++i) { | 264 for (size_t i = 0; i < resourceKURLs.size(); ++i) { |
265 resultResourceURLs[i] = resourceKURLs[i]; | 265 resultResourceURLs[i] = resourceKURLs[i]; |
266 // A frame's src can point to the same URL as another resource, keep the | 266 // A frame's src can point to the same URL as another resource, keep the |
267 // resource URL only in such cases. | 267 // resource URL only in such cases. |
268 size_t index = frameKURLs.find(resourceKURLs[i]); | 268 size_t index = frameKURLs.find(resourceKURLs[i]); |
269 if (index != notFound) | 269 if (index != notFound) |
270 frameKURLs.remove(index); | 270 frameKURLs.remove(index); |
271 } | 271 } |
272 *resourceURLs = resultResourceURLs; | 272 *resourceURLs = resultResourceURLs; |
273 WebVector<WebURL> resultFrameURLs(frameKURLs.size()); | 273 WebVector<WebURL> resultFrameURLs(frameKURLs.size()); |
274 for (size_t i = 0; i < frameKURLs.size(); ++i) | 274 for (size_t i = 0; i < frameKURLs.size(); ++i) |
275 resultFrameURLs[i] = frameKURLs[i]; | 275 resultFrameURLs[i] = frameKURLs[i]; |
276 *frameURLs = resultFrameURLs; | 276 *frameURLs = resultFrameURLs; |
277 | 277 |
278 return true; | 278 return true; |
279 } | 279 } |
280 | 280 |
281 WebString WebPageSerializer::generateMetaCharsetDeclaration(const WebString& cha
rset) | 281 WebString WebPageSerializer::generateMetaCharsetDeclaration(const WebString& cha
rset) |
282 { | 282 { |
283 String charsetString = "<meta http-equiv=\"Content-Type\" content=\"text/htm
l; charset=" + static_cast<const String&>(charset) + "\">"; | 283 String charsetString = "<meta http-equiv=\"Content-Type\" content=\"text/htm
l; charset=" + static_cast<const String&>(charset) + "\">"; |
284 return charsetString; | 284 return charsetString; |
285 } | 285 } |
286 | 286 |
287 WebString WebPageSerializer::generateMarkOfTheWebDeclaration(const WebURL& url) | 287 WebString WebPageSerializer::generateMarkOfTheWebDeclaration(const WebURL& url) |
288 { | 288 { |
289 return String::format("\n<!-- saved from url=(%04d)%s -->\n", | 289 return String::format("\n<!-- saved from url=(%04d)%s -->\n", |
290 static_cast<int>(url.spec().length()), | 290 static_cast<int>(url.spec().length()), |
291 url.spec().data()); | 291 url.spec().data()); |
292 } | 292 } |
293 | 293 |
294 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar
get) | 294 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar
get) |
295 { | 295 { |
296 if (baseTarget.isEmpty()) | 296 if (baseTarget.isEmpty()) |
297 return String(ASCIILiteral("<base href=\".\">")); | 297 return String(ASCIILiteral("<base href=\".\">")); |
298 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; | 298 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; |
299 return baseString; | 299 return baseString; |
300 } | 300 } |
301 | 301 |
302 } // namespace WebKit | 302 } // namespace WebKit |
OLD | NEW |