[iOS] Expose SPI to access the current sentence boundary and selection state
[WebKit-https.git] / Source / WebKit / UIProcess / API / APIAttachment.cpp
1 /*
2  * Copyright (C) 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 #include "config.h"
27 #include "APIAttachment.h"
28
29 #if ENABLE(ATTACHMENT_ELEMENT)
30
31 #include <WebCore/SharedBuffer.h>
32 #include <wtf/text/WTFString.h>
33
34 namespace API {
35
36 Ref<Attachment> Attachment::create(const WTF::String& identifier, WebKit::WebPageProxy& webPage)
37 {
38     return adoptRef(*new Attachment(identifier, webPage));
39 }
40
41 Attachment::Attachment(const WTF::String& identifier, WebKit::WebPageProxy& webPage)
42     : m_identifier(identifier)
43     , m_webPage(makeWeakPtr(webPage))
44 {
45 }
46
47 Attachment::~Attachment()
48 {
49 }
50
51 void Attachment::updateAttributes(Function<void(WebKit::CallbackBase::Error)>&& callback)
52 {
53     if (!m_webPage) {
54         callback(WebKit::CallbackBase::Error::OwnerWasInvalidated);
55         return;
56     }
57
58     if (m_webPage->willUpdateAttachmentAttributes(*this) == WebKit::WebPageProxy::ShouldUpdateAttachmentAttributes::No) {
59         callback(WebKit::CallbackBase::Error::None);
60         return;
61     }
62
63     m_webPage->updateAttachmentAttributes(*this, WTFMove(callback));
64 }
65
66 void Attachment::invalidate()
67 {
68     m_identifier = { };
69     m_filePath = { };
70     m_contentType = { };
71     m_webPage.clear();
72 #if PLATFORM(COCOA)
73     m_fileWrapper.clear();
74 #endif
75 }
76
77 #if !PLATFORM(COCOA)
78
79 bool Attachment::isEmpty() const
80 {
81     return true;
82 }
83
84 WTF::String Attachment::mimeType() const
85 {
86     return m_contentType;
87 }
88
89 WTF::String Attachment::fileName() const
90 {
91     return { };
92 }
93
94 Optional<uint64_t> Attachment::fileSizeForDisplay() const
95 {
96     return WTF::nullopt;
97 }
98
99 RefPtr<WebCore::SharedBuffer> Attachment::enclosingImageData() const
100 {
101     return nullptr;
102 }
103
104 RefPtr<WebCore::SharedBuffer> Attachment::createSerializedRepresentation() const
105 {
106     return nullptr;
107 }
108
109 void Attachment::updateFromSerializedRepresentation(Ref<WebCore::SharedBuffer>&&, const WTF::String&)
110 {
111 }
112
113 #endif // !PLATFORM(COCOA)
114
115 }
116
117 #endif // ENABLE(ATTACHMENT_ELEMENT)