Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: Source/core/loader/DocumentWriter.cpp

Issue 69823002: Move ownership of the TextResourceDecoder to DecodedDataDocumentParser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/loader/DocumentWriter.h ('k') | Source/core/loader/TextResourceDecoderBuilder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010. Adam Barth. All rights reserved. 2 * Copyright (C) 2010. Adam Barth. 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if (DocumentParser* parser = m_document->parser()) { 79 if (DocumentParser* parser = m_document->parser()) {
80 parser->pinToMainThread(); 80 parser->pinToMainThread();
81 // Because we're pinned to the main thread we don't need to worry about 81 // Because we're pinned to the main thread we don't need to worry about
82 // passing ownership of the source string. 82 // passing ownership of the source string.
83 parser->append(source.impl()); 83 parser->append(source.impl());
84 } 84 }
85 } 85 }
86 86
87 void DocumentWriter::reportDataReceived() 87 void DocumentWriter::reportDataReceived()
88 { 88 {
89 ASSERT(m_decoder);
90 if (m_hasReceivedSomeData) 89 if (m_hasReceivedSomeData)
91 return; 90 return;
92 m_hasReceivedSomeData = true; 91 m_hasReceivedSomeData = true;
93 if (m_decoder->encoding().usesVisualOrdering()) 92 RefPtr<TextResourceDecoder> decoder = m_parser->getDecoder();
abarth-chromium 2013/11/15 00:08:39 getDecoder -> decoder
oystein (OOO til 10th of July) 2013/11/15 00:17:24 Done.
93 if (decoder && decoder->encoding().usesVisualOrdering())
94 m_document->setVisuallyOrdered(); 94 m_document->setVisuallyOrdered();
95 } 95 }
96 96
97 void DocumentWriter::addData(const char* bytes, size_t length) 97 void DocumentWriter::addData(const char* bytes, size_t length)
98 { 98 {
99 ASSERT(m_parser); 99 ASSERT(m_parser);
100 if (!m_decoder && m_parser->needsDecoder() && 0 < length) 100 if (m_parser->needsDecoder() && 0 < length) {
101 m_decoder = m_decoderBuilder.buildFor(m_document); 101 RefPtr<TextResourceDecoder> decoder = m_decoderBuilder.buildFor(m_docume nt);
102 m_parser->setDecoder(decoder);
103 }
102 // appendBytes() can result replacing DocumentLoader::m_writer. 104 // appendBytes() can result replacing DocumentLoader::m_writer.
103 RefPtr<DocumentWriter> protectingThis(this); 105 RefPtr<DocumentWriter> protectingThis(this);
104 size_t consumedChars = m_parser->appendBytes(bytes, length); 106 size_t consumedChars = m_parser->appendBytes(bytes, length);
105 if (consumedChars) 107 if (consumedChars)
106 reportDataReceived(); 108 reportDataReceived();
107 } 109 }
108 110
109 void DocumentWriter::end() 111 void DocumentWriter::end()
110 { 112 {
111 ASSERT(m_document); 113 ASSERT(m_document);
112 114
113 // http://bugs.webkit.org/show_bug.cgi?id=10854 115 // http://bugs.webkit.org/show_bug.cgi?id=10854
114 // The frame's last ref may be removed and it can be deleted by checkComplet ed(), 116 // The frame's last ref may be removed and it can be deleted by checkComplet ed(),
115 // so we'll add a protective refcount 117 // so we'll add a protective refcount
116 RefPtr<Frame> protector(m_document->frame()); 118 RefPtr<Frame> protector(m_document->frame());
117 119
118 if (!m_parser) 120 if (!m_parser)
119 return; 121 return;
120 122
121 if (!m_decoder && m_parser->needsDecoder()) 123 if (m_parser->needsDecoder()) {
122 m_decoder = m_decoderBuilder.buildFor(m_document); 124 RefPtr<TextResourceDecoder> decoder = m_decoderBuilder.buildFor(m_docume nt);
125 m_parser->setDecoder(decoder);
126 }
123 // flush() can result replacing DocumentLoader::m_writer. 127 // flush() can result replacing DocumentLoader::m_writer.
124 RefPtr<DocumentWriter> protectingThis(this); 128 RefPtr<DocumentWriter> protectingThis(this);
125 size_t consumedChars = m_parser->flush(); 129 size_t consumedChars = m_parser->flush();
126 if (consumedChars) 130 if (consumedChars)
127 reportDataReceived(); 131 reportDataReceived();
128 if (!m_parser) 132 if (!m_parser)
129 return; 133 return;
130 134
131 m_parser->finish(); 135 m_parser->finish();
132 m_parser = 0; 136 m_parser = 0;
133 m_document = 0; 137 m_document = 0;
134 } 138 }
135 139
140 void DocumentWriter::setUserChosenEncoding(const String& charset)
141 {
142 RefPtr<TextResourceDecoder> decoder = m_parser->getDecoder();
143 if (decoder)
144 decoder->setEncoding(charset, TextResourceDecoder::UserChosenEncoding);
145 }
146
136 void DocumentWriter::setDocumentWasLoadedAsPartOfNavigation() 147 void DocumentWriter::setDocumentWasLoadedAsPartOfNavigation()
137 { 148 {
138 ASSERT(m_parser && !m_parser->isStopped()); 149 ASSERT(m_parser && !m_parser->isStopped());
139 m_parser->setDocumentWasLoadedAsPartOfNavigation(); 150 m_parser->setDocumentWasLoadedAsPartOfNavigation();
140 } 151 }
141 152
142 } // namespace WebCore 153 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentWriter.h ('k') | Source/core/loader/TextResourceDecoderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698