1/*
2 * Copyright (C) 2013-2017 Apple Inc. 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 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "DocumentFragment.h"
29#include "Frame.h"
30#include "Pasteboard.h"
31#include "Range.h"
32#include "markup.h"
33
34namespace WebCore {
35
36class ArchiveResource;
37class Blob;
38
39class FrameWebContentReader : public PasteboardWebContentReader {
40public:
41 Frame& frame;
42
43 FrameWebContentReader(Frame& frame)
44 : frame(frame)
45 {
46 }
47
48protected:
49 bool shouldSanitize() const;
50 MSOListQuirks msoListQuirksForMarkup() const;
51};
52
53class WebContentReader final : public FrameWebContentReader {
54public:
55 Range& context;
56 const bool allowPlainText;
57
58 RefPtr<DocumentFragment> fragment;
59 bool madeFragmentFromPlainText;
60
61 WebContentReader(Frame& frame, Range& context, bool allowPlainText)
62 : FrameWebContentReader(frame)
63 , context(context)
64 , allowPlainText(allowPlainText)
65 , madeFragmentFromPlainText(false)
66 {
67 }
68
69 void addFragment(Ref<DocumentFragment>&&);
70
71private:
72#if PLATFORM(COCOA)
73 bool readWebArchive(SharedBuffer&) override;
74 bool readFilePaths(const Vector<String>&) override;
75 bool readHTML(const String&) override;
76 bool readRTFD(SharedBuffer&) override;
77 bool readRTF(SharedBuffer&) override;
78 bool readImage(Ref<SharedBuffer>&&, const String& type) override;
79 bool readURL(const URL&, const String& title) override;
80 bool readDataBuffer(SharedBuffer&, const String& type, const String& name) override;
81#endif
82 bool readPlainText(const String&) override;
83};
84
85class WebContentMarkupReader final : public FrameWebContentReader {
86public:
87 String markup;
88
89 explicit WebContentMarkupReader(Frame& frame)
90 : FrameWebContentReader(frame)
91 {
92 }
93
94private:
95#if PLATFORM(COCOA)
96 bool readWebArchive(SharedBuffer&) override;
97 bool readFilePaths(const Vector<String>&) override { return false; }
98 bool readHTML(const String&) override;
99 bool readRTFD(SharedBuffer&) override;
100 bool readRTF(SharedBuffer&) override;
101 bool readImage(Ref<SharedBuffer>&&, const String&) override { return false; }
102 bool readURL(const URL&, const String&) override { return false; }
103 bool readDataBuffer(SharedBuffer&, const String&, const String&) override { return false; }
104#endif
105 bool readPlainText(const String&) override { return false; }
106};
107
108#if PLATFORM(COCOA) && defined(__OBJC__)
109struct FragmentAndResources {
110 RefPtr<DocumentFragment> fragment;
111 Vector<Ref<ArchiveResource>> resources;
112};
113
114RefPtr<DocumentFragment> createFragmentAndAddResources(Frame&, NSAttributedString *);
115#endif
116
117}
118