blob: b2413b86b49eb64c8d44c07eaf654798615f9d26 [file] [log] [blame]
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +00001/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
rniwa@webkit.org863da802017-08-12 22:14:53 +00003 * Copyright (C) 2017 Apple Inc. All rights reserved.
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
darin@apple.com506afe012016-10-30 02:56:39 +000032#pragma once
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +000033
rniwa@webkit.org863da802017-08-12 22:14:53 +000034#include "DataTransfer.h"
35#include "ExceptionOr.h"
rniwa@webkit.orgc7bff372017-08-16 02:23:41 +000036#include "ScriptWrappable.h"
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +000037#include <wtf/Forward.h>
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000038#include <wtf/Ref.h>
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +000039#include <wtf/RefCounted.h>
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000040#include <wtf/WeakPtr.h>
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +000041
42namespace WebCore {
43
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000044class DataTransferItem;
kinuko@chromium.orga98fb9f2012-01-20 12:08:56 +000045class File;
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +000046
cdumez@apple.com72332a62018-06-08 03:56:04 +000047class DataTransferItemList : public ScriptWrappable, public CanMakeWeakPtr<DataTransferItemList> {
rniwa@webkit.org863da802017-08-12 22:14:53 +000048 WTF_MAKE_NONCOPYABLE(DataTransferItemList); WTF_MAKE_FAST_ALLOCATED;
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +000049public:
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000050 DataTransferItemList(DataTransfer&);
51 ~DataTransferItemList();
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +000052
rniwa@webkit.org863da802017-08-12 22:14:53 +000053 // DataTransfer owns DataTransferItemList, and DataTransfer is kept alive as long as DataTransferItemList is alive.
54 void ref() { m_dataTransfer.ref(); }
55 void deref() { m_dataTransfer.deref(); }
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000056 DataTransfer& dataTransfer() { return m_dataTransfer; }
rniwa@webkit.org863da802017-08-12 22:14:53 +000057
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000058 // DOM API
rniwa@webkit.org863da802017-08-12 22:14:53 +000059 unsigned length() const;
60 RefPtr<DataTransferItem> item(unsigned index);
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000061 ExceptionOr<RefPtr<DataTransferItem>> add(const String& data, const String& type);
62 RefPtr<DataTransferItem> add(Ref<File>&&);
63 ExceptionOr<void> remove(unsigned index);
rniwa@webkit.org863da802017-08-12 22:14:53 +000064 void clear();
65
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000066 void didClearStringData(const String& type);
67 void didSetStringData(const String& type);
cdumez@apple.com455463f2018-12-21 00:40:09 +000068 bool hasItems() const { return m_items.hasValue(); }
wenson_hsieh@apple.com1b386072017-10-04 22:28:08 +000069 const Vector<Ref<DataTransferItem>>& items() const
70 {
71 ASSERT(m_items);
72 return *m_items;
73 }
rniwa@webkit.orgc7bff372017-08-16 02:23:41 +000074
rniwa@webkit.orgbf17e4b2017-08-17 06:17:09 +000075private:
76 Vector<Ref<DataTransferItem>>& ensureItems() const;
77
rniwa@webkit.org863da802017-08-12 22:14:53 +000078 DataTransfer& m_dataTransfer;
cdumez@apple.com8b7a0222018-12-20 04:41:11 +000079 mutable Optional<Vector<Ref<DataTransferItem>>> m_items;
dcheng@chromium.orgd3fc3e92011-03-08 05:48:33 +000080};
81
82} // namespace WebCore