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 readFilePath(const String&, PresentationSize preferredPresentationSize = { }, const String& contentType = { }) override;
75 bool readFilePaths(const Vector<String>&) override;
76 bool readHTML(const String&) override;
77 bool readRTFD(SharedBuffer&) override;
78 bool readRTF(SharedBuffer&) override;
79 bool readImage(Ref<SharedBuffer>&&, const String& type, PresentationSize preferredPresentationSize = { }) override;
80 bool readURL(const URL&, const String& title) override;
81 bool readDataBuffer(SharedBuffer&, const String& type, const String& name, PresentationSize preferredPresentationSize = { }) override;
82#endif
83 bool readPlainText(const String&) override;
84};
85
86class WebContentMarkupReader final : public FrameWebContentReader {
87public:
88 String markup;
89
90 explicit WebContentMarkupReader(Frame& frame)
91 : FrameWebContentReader(frame)
92 {
93 }
94
95private:
96#if PLATFORM(COCOA)
97 bool readWebArchive(SharedBuffer&) override;
98 bool readFilePath(const String&, PresentationSize = { }, const String& = { }) override { return false; }
99 bool readFilePaths(const Vector<String>&) override { return false; }
100 bool readHTML(const String&) override;
101 bool readRTFD(SharedBuffer&) override;
102 bool readRTF(SharedBuffer&) override;
103 bool readImage(Ref<SharedBuffer>&&, const String&, PresentationSize = { }) override { return false; }
104 bool readURL(const URL&, const String&) override { return false; }
105 bool readDataBuffer(SharedBuffer&, const String&, const String&, PresentationSize = { }) override { return false; }
106#endif
107 bool readPlainText(const String&) override { return false; }
108};
109
110#if PLATFORM(COCOA) && defined(__OBJC__)
111struct FragmentAndResources {
112 RefPtr<DocumentFragment> fragment;
113 Vector<Ref<ArchiveResource>> resources;
114};
115
116RefPtr<DocumentFragment> createFragmentAndAddResources(Frame&, NSAttributedString *);
117#endif
118
119}
120