blob: f3da31f112b6571752d0006d2e8893f43dce21f1 [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * Copyright (C) 2010. Adam Barth. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
Ben Murdoch02772c62013-07-26 10:21:05 +01009 * notice, this list of conditions and the following disclaimer.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010010 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
Ben Murdoch02772c62013-07-26 10:21:05 +010012 * documentation and/or other materials provided with the distribution.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010013 * 3. Neither the name of Adam Barth. ("Adam Barth") nor the names of
14 * its contributors may be used to endorse or promote products derived
Ben Murdoch02772c62013-07-26 10:21:05 +010015 * from this software without specific prior written permission.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010016 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
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
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.
27 */
28
29#ifndef DocumentWriter_h
30#define DocumentWriter_h
31
Ben Murdoch591b9582013-07-10 11:41:44 +010032#include "core/loader/TextResourceDecoderBuilder.h"
33#include "wtf/RefCounted.h"
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +010034#include "wtf/text/WTFString.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010035
36namespace WebCore {
37
38class Document;
39class DocumentParser;
40class Frame;
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +010041class KURL;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010042class SecurityOrigin;
43class TextResourceDecoder;
44
Ben Murdoch591b9582013-07-10 11:41:44 +010045class DocumentWriter : public RefCounted<DocumentWriter> {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010046 WTF_MAKE_NONCOPYABLE(DocumentWriter);
47public:
Ben Murdoch591b9582013-07-10 11:41:44 +010048 static PassRefPtr<DocumentWriter> create(Document*, const String& mimeType = "", const String& encoding = "", bool encodingUserChoosen = false);
49
50 ~DocumentWriter();
51
52 void end();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010053
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +010054 // This is only called by ScriptController::executeScriptIfJavaScriptURL
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010055 // and always contains the result of evaluating a javascript: url.
56 void replaceDocument(const String&, Document* ownerDocument);
57
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010058 void addData(const char* bytes, size_t length);
Ben Murdoch02772c62013-07-26 10:21:05 +010059
Ben Murdoch591b9582013-07-10 11:41:44 +010060 const String& mimeType() const { return m_decoderBuilder.mimeType(); }
61 const String& encoding() const { return m_decoderBuilder.encoding(); }
62 bool encodingWasChosenByUser() const { return m_decoderBuilder.encodingWasChosenByUser(); }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010063
64 // Exposed for DocumentParser::appendBytes.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010065 void reportDataReceived();
Ben Murdoch591b9582013-07-10 11:41:44 +010066 // Exposed for DocumentLoader::replaceDocument.
67 void appendReplacingData(const String&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010068
69 void setDocumentWasLoadedAsPartOfNavigation();
70
71private:
Ben Murdoch591b9582013-07-10 11:41:44 +010072 DocumentWriter(Document*, const String& mimeType, const String& encoding, bool encodingUserChoosen);
73
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010074 PassRefPtr<Document> createDocument(const KURL&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010075
Ben Murdoch591b9582013-07-10 11:41:44 +010076 Document* m_document;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010077 bool m_hasReceivedSomeData;
Ben Murdoch591b9582013-07-10 11:41:44 +010078 TextResourceDecoderBuilder m_decoderBuilder;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010079
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010080 RefPtr<TextResourceDecoder> m_decoder;
81 RefPtr<DocumentParser> m_parser;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010082};
83
84} // namespace WebCore
85
86#endif // DocumentWriter_h