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 | m_insertionState = InsertionState::NotInserted; |
76 | } |
77 | |
78 | #if !PLATFORM(COCOA) |
79 | |
80 | bool Attachment::isEmpty() const |
81 | { |
82 | return true; |
83 | } |
84 | |
85 | WTF::String Attachment::mimeType() const |
86 | { |
87 | return m_contentType; |
88 | } |
89 | |
90 | WTF::String Attachment::fileName() const |
91 | { |
92 | return { }; |
93 | } |
94 | |
95 | Optional<uint64_t> Attachment::fileSizeForDisplay() const |
96 | { |
97 | return WTF::nullopt; |
98 | } |
99 | |
100 | RefPtr<WebCore::SharedBuffer> Attachment::enclosingImageData() const |
101 | { |
102 | return nullptr; |
103 | } |
104 | |
105 | RefPtr<WebCore::SharedBuffer> Attachment::createSerializedRepresentation() const |
106 | { |
107 | return nullptr; |
108 | } |
109 | |
110 | void Attachment::updateFromSerializedRepresentation(Ref<WebCore::SharedBuffer>&&, const WTF::String&) |
111 | { |
112 | } |
113 | |
114 | #endif // !PLATFORM(COCOA) |
115 | |
116 | } |
117 | |
118 | #endif // ENABLE(ATTACHMENT_ELEMENT) |
119 | |