OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #ifndef DocumentWriter_h | 29 #ifndef DocumentWriter_h |
30 #define DocumentWriter_h | 30 #define DocumentWriter_h |
31 | 31 |
32 #include "core/loader/TextResourceDecoderBuilder.h" | 32 #include "core/loader/TextResourceDecoderBuilder.h" |
| 33 #include "wtf/RefCounted.h" |
33 #include "wtf/text/WTFString.h" | 34 #include "wtf/text/WTFString.h" |
34 | 35 |
35 namespace WebCore { | 36 namespace WebCore { |
36 | 37 |
37 class Document; | 38 class Document; |
38 class DocumentParser; | 39 class DocumentParser; |
39 class Frame; | 40 class Frame; |
40 class KURL; | 41 class KURL; |
41 class SecurityOrigin; | 42 class SecurityOrigin; |
42 class TextResourceDecoder; | 43 class TextResourceDecoder; |
43 | 44 |
44 class DocumentWriter { | 45 class DocumentWriter : public RefCounted<DocumentWriter> { |
45 WTF_MAKE_NONCOPYABLE(DocumentWriter); | 46 WTF_MAKE_NONCOPYABLE(DocumentWriter); |
46 public: | 47 public: |
47 explicit DocumentWriter(Frame*); | 48 static PassRefPtr<DocumentWriter> create(Document*, const String& mimeType =
"", const String& encoding = "", bool encodingUserChoosen = false); |
| 49 |
| 50 ~DocumentWriter(); |
| 51 |
| 52 void end(); |
48 | 53 |
49 // This is only called by ScriptController::executeScriptIfJavaScriptURL | 54 // This is only called by ScriptController::executeScriptIfJavaScriptURL |
50 // and always contains the result of evaluating a javascript: url. | 55 // and always contains the result of evaluating a javascript: url. |
51 void replaceDocument(const String&, Document* ownerDocument); | 56 void replaceDocument(const String&, Document* ownerDocument); |
52 | 57 |
53 void begin(); | |
54 void begin(const KURL&, bool dispatchWindowObjectAvailable = true, Document*
ownerDocument = 0); | |
55 void addData(const char* bytes, size_t length); | 58 void addData(const char* bytes, size_t length); |
56 void end(); | |
57 | 59 |
58 void setFrame(Frame* frame) { m_frame = frame; } | |
59 | |
60 const String& mimeType() const { return m_decoderBuilder.mimeType(); } | 60 const String& mimeType() const { return m_decoderBuilder.mimeType(); } |
61 void setMIMEType(const String& type) { m_decoderBuilder.setMIMEType(type); } | 61 const String& encoding() const { return m_decoderBuilder.encoding(); } |
62 void setEncoding(const String& encoding, bool userChosen) { m_decoderBuilder
.setEncoding(encoding, userChosen); } | 62 bool encodingWasChosenByUser() const { return m_decoderBuilder.encodingWasCh
osenByUser(); } |
63 | 63 |
64 // Exposed for DocumentParser::appendBytes. | 64 // Exposed for DocumentParser::appendBytes. |
65 void reportDataReceived(); | 65 void reportDataReceived(); |
| 66 // Exposed for DocumentLoader::replaceDocument. |
| 67 void appendReplacingData(const String&); |
66 | 68 |
67 void setDocumentWasLoadedAsPartOfNavigation(); | 69 void setDocumentWasLoadedAsPartOfNavigation(); |
68 | 70 |
69 private: | 71 private: |
| 72 DocumentWriter(Document*, const String& mimeType, const String& encoding, bo
ol encodingUserChoosen); |
| 73 |
70 PassRefPtr<Document> createDocument(const KURL&); | 74 PassRefPtr<Document> createDocument(const KURL&); |
71 void clear(); | |
72 | 75 |
73 Frame* m_frame; | 76 Document* m_document; |
74 | |
75 bool m_hasReceivedSomeData; | 77 bool m_hasReceivedSomeData; |
76 TextResourceDecoderBuilder m_decoderBuilder; | 78 TextResourceDecoderBuilder m_decoderBuilder; |
77 | 79 |
78 RefPtr<TextResourceDecoder> m_decoder; | 80 RefPtr<TextResourceDecoder> m_decoder; |
79 RefPtr<DocumentParser> m_parser; | 81 RefPtr<DocumentParser> m_parser; |
80 | |
81 enum WriterState { | |
82 NotStartedWritingState, | |
83 StartedWritingState, | |
84 FinishedWritingState, | |
85 }; | |
86 WriterState m_state; | |
87 }; | 82 }; |
88 | 83 |
89 } // namespace WebCore | 84 } // namespace WebCore |
90 | 85 |
91 #endif // DocumentWriter_h | 86 #endif // DocumentWriter_h |
OLD | NEW |