Ejemplo n.º 1
0
bool WebPageSerializerImpl::serialize()
{
    if (!m_framesCollected)
        collectTargetFrames();

    bool didSerialization = false;
    KURL mainURL = m_specifiedWebLocalFrameImpl->frame()->document()->url();

    for (unsigned i = 0; i < m_frames.size(); ++i) {
        WebLocalFrameImpl* webFrame = m_frames[i];
        Document* document = webFrame->frame()->document();
        const KURL& url = document->url();

        if (!url.isValid() || !m_localLinks.contains(url.string()))
            continue;

        didSerialization = true;

        const WTF::TextEncoding& textEncoding = document->encoding().isValid() ? document->encoding() : UTF8Encoding();
        String directoryName = url == mainURL ? m_localDirectoryName : "";

        SerializeDomParam param(url, textEncoding, document, directoryName);

        Element* documentElement = document->documentElement();
        if (documentElement)
            buildContentForNode(documentElement, &param);

        encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &param, ForceFlush);
    }

    ASSERT(m_dataBuffer.isEmpty());
    m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSerializerClient::AllFramesAreFinished);
    return didSerialization;
}
Ejemplo n.º 2
0
bool WebPageSerializerImpl::serialize()
{
    // Collect target frames.
    if (!m_framesCollected)
        collectTargetFrames();
    bool didSerialization = false;
    // Get KURL for main frame.
    KURL mainPageURL = m_specifiedWebFrameImpl->frame()->loader()->url();

    // Go through all frames for serializing DOM for whole page, include
    // sub-frames.
    for (int i = 0; i < static_cast<int>(m_frames.size()); ++i) {
        // Get current serializing frame.
        WebFrameImpl* currentFrame = m_frames[i];
        // Get current using document.
        Document* currentDoc = currentFrame->frame()->document();
        // Get current frame's URL.
        const KURL& currentFrameURL = currentFrame->frame()->loader()->url();

        // Check whether we have done this document.
        if (currentFrameURL.isValid() && m_localLinks.contains(currentFrameURL.string())) {
            // A new document, we will serialize it.
            didSerialization = true;
            // Get target encoding for current document.
            String encoding = currentFrame->frame()->loader()->writer()->encoding();
            // Create the text encoding object with target encoding.
            TextEncoding textEncoding(encoding);
            // Construct serialize parameter for late processing document.
            SerializeDomParam param(currentFrameURL,
                                    encoding.length() ? textEncoding : UTF8Encoding(),
                                    currentDoc,
                                    currentFrameURL == mainPageURL ? m_localDirectoryName : "");

            // Process current document.
            Element* rootElement = currentDoc->documentElement();
            if (rootElement)
                buildContentForNode(rootElement, &param);

            // Flush the remainder data and finish serializing current frame.
            encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished,
                                 &param,
                                 1);
        }
    }

    // We have done call frames, so we send message to embedder to tell it that
    // frames are finished serializing.
    ASSERT(m_dataBuffer.isEmpty());
    m_client->didSerializeDataForFrame(KURL(),
                                       WebCString("", 0),
                                       WebPageSerializerClient::AllFramesAreFinished);
    return didSerialization;
}