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

Side by Side Diff: Source/core/dom/DecodedDataDocumentParser.cpp

Issue 69823002: Move ownership of the TextResourceDecoder to DecodedDataDocumentParser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes 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/dom/DecodedDataDocumentParser.h ('k') | Source/core/dom/Document.h » ('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 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/dom/DecodedDataDocumentParser.h" 27 #include "core/dom/DecodedDataDocumentParser.h"
28 28
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/dom/DocumentEncodingData.h"
30 #include "core/fetch/TextResourceDecoder.h" 31 #include "core/fetch/TextResourceDecoder.h"
31 32
32 namespace WebCore { 33 namespace WebCore {
33 34
34 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document) 35 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document)
35 : DocumentParser(document) 36 : DocumentParser(document)
36 { 37 {
37 } 38 }
38 39
40 DecodedDataDocumentParser::~DecodedDataDocumentParser()
41 {
42 }
43
44 void DecodedDataDocumentParser::setDecoder(PassRefPtr<TextResourceDecoder> decod er)
45 {
46 m_decoder = decoder;
47 }
48
49 PassRefPtr<TextResourceDecoder> DecodedDataDocumentParser::decoder()
50 {
51 return m_decoder;
52 }
53
39 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length) 54 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length)
40 { 55 {
41 if (!length) 56 if (!length)
42 return 0; 57 return 0;
43 58
44 // This should be checking isStopped(), but XMLDocumentParser prematurely 59 // This should be checking isStopped(), but XMLDocumentParser prematurely
45 // stops parsing when handling an XSLT processing instruction and still 60 // stops parsing when handling an XSLT processing instruction and still
46 // needs to receive decoded bytes. 61 // needs to receive decoded bytes.
47 if (isDetached()) 62 if (isDetached())
48 return 0; 63 return 0;
49 64
50 String decoded = document()->decoder()->decode(data, length); 65 String decoded = m_decoder->decode(data, length);
51 document()->setEncoding(document()->decoder()->encoding()); 66 updateDocumentEncoding();
52 67
53 if (decoded.isEmpty()) 68 if (decoded.isEmpty())
54 return 0; 69 return 0;
55 70
56 size_t consumedChars = decoded.length(); 71 size_t consumedChars = decoded.length();
57 append(decoded.releaseImpl()); 72 append(decoded.releaseImpl());
58 73
59 return consumedChars; 74 return consumedChars;
60 } 75 }
61 76
62 size_t DecodedDataDocumentParser::flush() 77 size_t DecodedDataDocumentParser::flush()
63 { 78 {
64 // This should be checking isStopped(), but XMLDocumentParser prematurely 79 // This should be checking isStopped(), but XMLDocumentParser prematurely
65 // stops parsing when handling an XSLT processing instruction and still 80 // stops parsing when handling an XSLT processing instruction and still
66 // needs to receive decoded bytes. 81 // needs to receive decoded bytes.
67 if (isDetached()) 82 if (isDetached())
68 return 0; 83 return 0;
69 84
70 // null decoder indicates there is no data received. 85 // null decoder indicates there is no data received.
71 // We have nothing to do in that case. 86 // We have nothing to do in that case.
72 TextResourceDecoder* decoder = document()->decoder(); 87 if (!m_decoder)
73 if (!decoder)
74 return 0; 88 return 0;
75 String remainingData = decoder->flush(); 89 String remainingData = m_decoder->flush();
76 document()->setEncoding(document()->decoder()->encoding()); 90 updateDocumentEncoding();
91
77 if (remainingData.isEmpty()) 92 if (remainingData.isEmpty())
78 return 0; 93 return 0;
79 94
80 size_t consumedChars = remainingData.length(); 95 size_t consumedChars = remainingData.length();
81 append(remainingData.releaseImpl()); 96 append(remainingData.releaseImpl());
82 97
83 return consumedChars; 98 return consumedChars;
84 } 99 }
85 100
101 void DecodedDataDocumentParser::updateDocumentEncoding()
102 {
103 DocumentEncodingData encodingData;
104 encodingData.encoding = m_decoder->encoding();
105 encodingData.wasDetectedHeuristically = m_decoder->encodingWasDetectedHeuris tically();
106 encodingData.sawDecodingError = m_decoder->sawError();
107 document()->setEncodingData(encodingData);
108 }
109
86 }; 110 };
OLDNEW
« no previous file with comments | « Source/core/dom/DecodedDataDocumentParser.h ('k') | Source/core/dom/Document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698