| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // know those old base tags are original content or added by JavaScript. If | 72 // know those old base tags are original content or added by JavaScript. If |
| 73 // they are added by JavaScript, it means when loading saved page, the script(s) | 73 // they are added by JavaScript, it means when loading saved page, the script(s) |
| 74 // will still insert base tag(s) to DOM, so the new added base tag(s) can | 74 // will still insert base tag(s) to DOM, so the new added base tag(s) can |
| 75 // override the incorrect base URL and make sure we alway load correct local | 75 // override the incorrect base URL and make sure we alway load correct local |
| 76 // saved resource files. | 76 // saved resource files. |
| 77 | 77 |
| 78 #include "config.h" | 78 #include "config.h" |
| 79 #include "WebPageSerializerImpl.h" | 79 #include "WebPageSerializerImpl.h" |
| 80 | 80 |
| 81 #include "HTMLNames.h" | 81 #include "HTMLNames.h" |
| 82 #include "WebFrameImpl.h" | 82 #include "WebLocalFrameImpl.h" |
| 83 #include "core/dom/Document.h" | 83 #include "core/dom/Document.h" |
| 84 #include "core/dom/DocumentType.h" | 84 #include "core/dom/DocumentType.h" |
| 85 #include "core/dom/Element.h" | 85 #include "core/dom/Element.h" |
| 86 #include "core/editing/markup.h" | 86 #include "core/editing/markup.h" |
| 87 #include "core/html/HTMLAllCollection.h" | 87 #include "core/html/HTMLAllCollection.h" |
| 88 #include "core/html/HTMLElement.h" | 88 #include "core/html/HTMLElement.h" |
| 89 #include "core/html/HTMLFormElement.h" | 89 #include "core/html/HTMLFormElement.h" |
| 90 #include "core/html/HTMLHtmlElement.h" | 90 #include "core/html/HTMLHtmlElement.h" |
| 91 #include "core/html/HTMLMetaElement.h" | 91 #include "core/html/HTMLMetaElement.h" |
| 92 #include "core/loader/DocumentLoader.h" | 92 #include "core/loader/DocumentLoader.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 // Check whether we need to replace some resource links | 316 // Check whether we need to replace some resource links |
| 317 // with local resource paths. | 317 // with local resource paths. |
| 318 const QualifiedName& attrName = attribute.name(); | 318 const QualifiedName& attrName = attribute.name(); |
| 319 if (element->hasLegalLinkAttribute(attrName)) { | 319 if (element->hasLegalLinkAttribute(attrName)) { |
| 320 // For links start with "javascript:", we do not change it. | 320 // For links start with "javascript:", we do not change it. |
| 321 if (attrValue.startsWith("javascript:", false)) | 321 if (attrValue.startsWith("javascript:", false)) |
| 322 result.append(attrValue); | 322 result.append(attrValue); |
| 323 else { | 323 else { |
| 324 // Get the absolute link | 324 // Get the absolute link |
| 325 WebFrameImpl* subFrame = WebFrameImpl::fromFrameOwnerEle
ment(element); | 325 WebLocalFrameImpl* subFrame = WebLocalFrameImpl::fromFra
meOwnerElement(element); |
| 326 String completeURL = subFrame ? subFrame->frame()->docum
ent()->url() : | 326 String completeURL = subFrame ? subFrame->frame()->docum
ent()->url() : |
| 327 param->document->complet
eURL(attrValue); | 327 param->document->complet
eURL(attrValue); |
| 328 // Check whether we have local files for those link. | 328 // Check whether we have local files for those link. |
| 329 if (m_localLinks.contains(completeURL)) { | 329 if (m_localLinks.contains(completeURL)) { |
| 330 if (!param->directoryName.isEmpty()) { | 330 if (!param->directoryName.isEmpty()) { |
| 331 result.appendLiteral("./"); | 331 result.appendLiteral("./"); |
| 332 result.append(param->directoryName); | 332 result.append(param->directoryName); |
| 333 result.append('/'); | 333 result.append('/'); |
| 334 } | 334 } |
| 335 result.append(m_localLinks.get(completeURL)); | 335 result.append(m_localLinks.get(completeURL)); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 const WebString& localDirectoryName
) | 435 const WebString& localDirectoryName
) |
| 436 : m_client(client) | 436 : m_client(client) |
| 437 , m_recursiveSerialization(recursiveSerialization) | 437 , m_recursiveSerialization(recursiveSerialization) |
| 438 , m_framesCollected(false) | 438 , m_framesCollected(false) |
| 439 , m_localDirectoryName(localDirectoryName) | 439 , m_localDirectoryName(localDirectoryName) |
| 440 , m_htmlEntities(false) | 440 , m_htmlEntities(false) |
| 441 , m_xmlEntities(true) | 441 , m_xmlEntities(true) |
| 442 { | 442 { |
| 443 // Must specify available webframe. | 443 // Must specify available webframe. |
| 444 ASSERT(frame); | 444 ASSERT(frame); |
| 445 m_specifiedWebFrameImpl = toWebFrameImpl(frame); | 445 m_specifiedWebLocalFrameImpl = toWebLocalFrameImpl(frame); |
| 446 // Make sure we have non 0 client. | 446 // Make sure we have non 0 client. |
| 447 ASSERT(client); | 447 ASSERT(client); |
| 448 // Build local resources map. | 448 // Build local resources map. |
| 449 ASSERT(links.size() == localPaths.size()); | 449 ASSERT(links.size() == localPaths.size()); |
| 450 for (size_t i = 0; i < links.size(); i++) { | 450 for (size_t i = 0; i < links.size(); i++) { |
| 451 KURL url = links[i]; | 451 KURL url = links[i]; |
| 452 ASSERT(!m_localLinks.contains(url.string())); | 452 ASSERT(!m_localLinks.contains(url.string())); |
| 453 m_localLinks.set(url.string(), localPaths[i]); | 453 m_localLinks.set(url.string(), localPaths[i]); |
| 454 } | 454 } |
| 455 | 455 |
| 456 ASSERT(m_dataBuffer.isEmpty()); | 456 ASSERT(m_dataBuffer.isEmpty()); |
| 457 } | 457 } |
| 458 | 458 |
| 459 void WebPageSerializerImpl::collectTargetFrames() | 459 void WebPageSerializerImpl::collectTargetFrames() |
| 460 { | 460 { |
| 461 ASSERT(!m_framesCollected); | 461 ASSERT(!m_framesCollected); |
| 462 m_framesCollected = true; | 462 m_framesCollected = true; |
| 463 | 463 |
| 464 // First, process main frame. | 464 // First, process main frame. |
| 465 m_frames.append(m_specifiedWebFrameImpl); | 465 m_frames.append(m_specifiedWebLocalFrameImpl); |
| 466 // Return now if user only needs to serialize specified frame, not including | 466 // Return now if user only needs to serialize specified frame, not including |
| 467 // all sub-frames. | 467 // all sub-frames. |
| 468 if (!m_recursiveSerialization) | 468 if (!m_recursiveSerialization) |
| 469 return; | 469 return; |
| 470 // Collect all frames inside the specified frame. | 470 // Collect all frames inside the specified frame. |
| 471 for (int i = 0; i < static_cast<int>(m_frames.size()); ++i) { | 471 for (int i = 0; i < static_cast<int>(m_frames.size()); ++i) { |
| 472 WebFrameImpl* currentFrame = m_frames[i]; | 472 WebLocalFrameImpl* currentFrame = m_frames[i]; |
| 473 // Get current using document. | 473 // Get current using document. |
| 474 Document* currentDoc = currentFrame->frame()->document(); | 474 Document* currentDoc = currentFrame->frame()->document(); |
| 475 // Go through sub-frames. | 475 // Go through sub-frames. |
| 476 RefPtr<HTMLCollection> all = currentDoc->all(); | 476 RefPtr<HTMLCollection> all = currentDoc->all(); |
| 477 | 477 |
| 478 for (unsigned i = 0; Element* element = all->item(i); i++) { | 478 for (unsigned i = 0; Element* element = all->item(i); i++) { |
| 479 if (!element->isHTMLElement()) | 479 if (!element->isHTMLElement()) |
| 480 continue; | 480 continue; |
| 481 WebFrameImpl* webFrame = | 481 WebLocalFrameImpl* webFrame = |
| 482 WebFrameImpl::fromFrameOwnerElement(element); | 482 WebLocalFrameImpl::fromFrameOwnerElement(element); |
| 483 if (webFrame) | 483 if (webFrame) |
| 484 m_frames.append(webFrame); | 484 m_frames.append(webFrame); |
| 485 } | 485 } |
| 486 } | 486 } |
| 487 } | 487 } |
| 488 | 488 |
| 489 bool WebPageSerializerImpl::serialize() | 489 bool WebPageSerializerImpl::serialize() |
| 490 { | 490 { |
| 491 if (!m_framesCollected) | 491 if (!m_framesCollected) |
| 492 collectTargetFrames(); | 492 collectTargetFrames(); |
| 493 | 493 |
| 494 bool didSerialization = false; | 494 bool didSerialization = false; |
| 495 KURL mainURL = m_specifiedWebFrameImpl->frame()->document()->url(); | 495 KURL mainURL = m_specifiedWebLocalFrameImpl->frame()->document()->url(); |
| 496 | 496 |
| 497 for (unsigned i = 0; i < m_frames.size(); ++i) { | 497 for (unsigned i = 0; i < m_frames.size(); ++i) { |
| 498 WebFrameImpl* webFrame = m_frames[i]; | 498 WebLocalFrameImpl* webFrame = m_frames[i]; |
| 499 Document* document = webFrame->frame()->document(); | 499 Document* document = webFrame->frame()->document(); |
| 500 const KURL& url = document->url(); | 500 const KURL& url = document->url(); |
| 501 | 501 |
| 502 if (!url.isValid() || !m_localLinks.contains(url.string())) | 502 if (!url.isValid() || !m_localLinks.contains(url.string())) |
| 503 continue; | 503 continue; |
| 504 | 504 |
| 505 didSerialization = true; | 505 didSerialization = true; |
| 506 | 506 |
| 507 const WTF::TextEncoding& textEncoding = document->encoding().isValid() ?
document->encoding() : UTF8Encoding(); | 507 const WTF::TextEncoding& textEncoding = document->encoding().isValid() ?
document->encoding() : UTF8Encoding(); |
| 508 String directoryName = url == mainURL ? m_localDirectoryName : ""; | 508 String directoryName = url == mainURL ? m_localDirectoryName : ""; |
| 509 | 509 |
| 510 SerializeDomParam param(url, textEncoding, document, directoryName); | 510 SerializeDomParam param(url, textEncoding, document, directoryName); |
| 511 | 511 |
| 512 Element* documentElement = document->documentElement(); | 512 Element* documentElement = document->documentElement(); |
| 513 if (documentElement) | 513 if (documentElement) |
| 514 buildContentForNode(documentElement, ¶m); | 514 buildContentForNode(documentElement, ¶m); |
| 515 | 515 |
| 516 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p
aram, ForceFlush); | 516 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p
aram, ForceFlush); |
| 517 } | 517 } |
| 518 | 518 |
| 519 ASSERT(m_dataBuffer.isEmpty()); | 519 ASSERT(m_dataBuffer.isEmpty()); |
| 520 m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSeriali
zerClient::AllFramesAreFinished); | 520 m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSeriali
zerClient::AllFramesAreFinished); |
| 521 return didSerialization; | 521 return didSerialization; |
| 522 } | 522 } |
| 523 | 523 |
| 524 } // namespace blink | 524 } // namespace blink |
| OLD | NEW |