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

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: 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
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
(...skipping 18 matching lines...) Expand all
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/fetch/TextResourceDecoder.h" 30 #include "core/fetch/TextResourceDecoder.h"
31 31
32 namespace WebCore { 32 namespace WebCore {
33 33
34 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document) 34 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document)
35 : DocumentParser(document) 35 : DocumentParser(document)
36 { 36 {
37 } 37 }
38 38
39 DecodedDataDocumentParser::~DecodedDataDocumentParser()
40 {
41 }
42
43 void DecodedDataDocumentParser::setDecoder(PassRefPtr<TextResourceDecoder> decod er)
44 {
45 m_decoder = decoder;
46 }
47
39 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length) 48 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length)
40 { 49 {
41 if (!length) 50 if (!length)
42 return 0; 51 return 0;
43 52
44 // This should be checking isStopped(), but XMLDocumentParser prematurely 53 // This should be checking isStopped(), but XMLDocumentParser prematurely
45 // stops parsing when handling an XSLT processing instruction and still 54 // stops parsing when handling an XSLT processing instruction and still
46 // needs to receive decoded bytes. 55 // needs to receive decoded bytes.
47 if (isDetached()) 56 if (isDetached())
48 return 0; 57 return 0;
49 58
50 String decoded = document()->decoder()->decode(data, length); 59 String decoded = m_decoder->decode(data, length);
51 document()->setEncoding(document()->decoder()->encoding()); 60 updateDocumentEncoding();
52 61
53 if (decoded.isEmpty()) 62 if (decoded.isEmpty())
54 return 0; 63 return 0;
55 64
56 size_t consumedChars = decoded.length(); 65 size_t consumedChars = decoded.length();
57 append(decoded.releaseImpl()); 66 append(decoded.releaseImpl());
58 67
59 return consumedChars; 68 return consumedChars;
60 } 69 }
61 70
62 size_t DecodedDataDocumentParser::flush() 71 size_t DecodedDataDocumentParser::flush()
63 { 72 {
64 // This should be checking isStopped(), but XMLDocumentParser prematurely 73 // This should be checking isStopped(), but XMLDocumentParser prematurely
65 // stops parsing when handling an XSLT processing instruction and still 74 // stops parsing when handling an XSLT processing instruction and still
66 // needs to receive decoded bytes. 75 // needs to receive decoded bytes.
67 if (isDetached()) 76 if (isDetached())
68 return 0; 77 return 0;
69 78
70 // null decoder indicates there is no data received. 79 // null decoder indicates there is no data received.
71 // We have nothing to do in that case. 80 // We have nothing to do in that case.
72 TextResourceDecoder* decoder = document()->decoder(); 81 if (!m_decoder)
73 if (!decoder)
74 return 0; 82 return 0;
75 String remainingData = decoder->flush(); 83 String remainingData = m_decoder->flush();
76 document()->setEncoding(document()->decoder()->encoding()); 84 updateDocumentEncoding();
85
77 if (remainingData.isEmpty()) 86 if (remainingData.isEmpty())
78 return 0; 87 return 0;
79 88
80 size_t consumedChars = remainingData.length(); 89 size_t consumedChars = remainingData.length();
81 append(remainingData.releaseImpl()); 90 append(remainingData.releaseImpl());
82 91
83 return consumedChars; 92 return consumedChars;
84 } 93 }
85 94
95 void DecodedDataDocumentParser::updateDocumentEncoding()
96 {
97 Document::DocumentEncodingData encodingData;
98 encodingData.encoding = m_decoder->encoding();
99 encodingData.wasDetectedHeuristically = m_decoder->encodingWasDetectedHeuris tically();
100 encodingData.sawDecodingError = m_decoder->sawError();
101 document()->setEncodingData(encodingData);
102 }
103
86 }; 104 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698