QT分析之WebKit(六)

來源:互聯網
上載者:User

程式人生 2010-02-24 21:44:30 閱讀310 評論0   字型大小:大小 訂閱

在繼續分析FrameLoader::write()之前,先回到《QT分析之WebKit(二)》。那裡曾經儲存了一個完整的呼叫堆疊,
……
QtWebKitd4.dll!WebCore::HTMLTokenizer::write(const WebCore::SegmentedString & str={...}, bool appendData=true)  行1730 + 0x23 位元組    C++
QtWebKitd4.dll!WebCore::FrameLoader::write(const char *
可知調用的次序為:FrameLoader::write()調用了HTMLTokenizer::write()。
下面是FrameLoader::write()的定義:
        void write(const char* str, int len = -1, bool flush = false);
這裡包含了兩個預設值調用定義,在前一篇,調用的形式是:write(bytes, length);
實際傳遞的的是:write(bytes, length, false);
接著看write()的實現:
void FrameLoader::write(const char* str, int len, bool flush)
{
    if (len == 0 && !flush)
        return;
   
    if (len == -1)
        len = strlen(str);

    Tokenizer* tokenizer = m_frame->document()->tokenizer();
    if (tokenizer && tokenizer->wantsRawData()) {
        if (len > 0)
            tokenizer->writeRawData(str, len);
        return;
    }
   
    if (!m_decoder) {
        Settings* settings = m_frame->settings();
        m_decoder = TextResourceDecoder::create(m_responseMIMEType, settings ? settings->defaultTextEncodingName() : String());
        if (m_encoding.isEmpty()) {
            Frame* parentFrame = m_frame->tree()->parent();
            if (parentFrame && parentFrame->document()->securityOrigin()->canAccess(m_frame->document()->securityOrigin()))
                m_decoder->setEncoding(parentFrame->document()->inputEncoding(), TextResourceDecoder::DefaultEncoding);
        } else {
            m_decoder->setEncoding(m_encoding,
                m_encodingWasChosenByUser ? TextResourceDecoder::UserChosenEncoding : TextResourceDecoder::EncodingFromHTTPHeader);
        }
        m_frame->document()->setDecoder(m_decoder.get());
    }

    String decoded = m_decoder->decode(str, len);
    if (flush)
        decoded += m_decoder->flush();
    if (decoded.isEmpty())
        return;

#if USE(LOW_BANDWIDTH_DISPLAY)
    if (m_frame->document()->inLowBandwidthDisplay())
        m_pendingSourceInLowBandwidthDisplay.append(decoded);  
#endif

    if (!m_receivedData) {
        m_receivedData = true;
        if (m_decoder->encoding().usesVisualOrdering())
            m_frame->document()->setVisuallyOrdered();
        m_frame->document()->recalcStyle(Node::Force);
    }

    if (tokenizer) {
        ASSERT(!tokenizer->wantsRawData());
        tokenizer->write(decoded, true);
    }
}
怎麼和HTMLTokenizer關聯的呢?就是在《QT分析之WebKit(三)》初始化Document對象的時候關聯上的。
DOMImplementation::createDocument()
上面程式做了一些邊緣的工作,例如設定編碼(因為可以在HTTP協議、HTML的TITLE部分或者瀏覽器特別指定編碼),主要是建立一個decoder另外一個是調用tokenizer->write()

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.