dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Google Inc. All rights reserved. |
rniwa@webkit.org | 863da80 | 2017-08-12 22:14:53 +0000 | [diff] [blame] | 3 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 4 | * |
| 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.com | 506afe01 | 2016-10-30 02:56:39 +0000 | [diff] [blame] | 32 | #pragma once |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 33 | |
rniwa@webkit.org | 863da80 | 2017-08-12 22:14:53 +0000 | [diff] [blame] | 34 | #include "DataTransfer.h" |
| 35 | #include "ExceptionOr.h" |
rniwa@webkit.org | c7bff37 | 2017-08-16 02:23:41 +0000 | [diff] [blame] | 36 | #include "ScriptWrappable.h" |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 37 | #include <wtf/Forward.h> |
rniwa@webkit.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 38 | #include <wtf/Ref.h> |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 39 | #include <wtf/RefCounted.h> |
rniwa@webkit.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 40 | #include <wtf/WeakPtr.h> |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 41 | |
| 42 | namespace WebCore { |
| 43 | |
rniwa@webkit.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 44 | class DataTransferItem; |
kinuko@chromium.org | a98fb9f | 2012-01-20 12:08:56 +0000 | [diff] [blame] | 45 | class File; |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 46 | |
cdumez@apple.com | 72332a6 | 2018-06-08 03:56:04 +0000 | [diff] [blame] | 47 | class DataTransferItemList : public ScriptWrappable, public CanMakeWeakPtr<DataTransferItemList> { |
rniwa@webkit.org | 863da80 | 2017-08-12 22:14:53 +0000 | [diff] [blame] | 48 | WTF_MAKE_NONCOPYABLE(DataTransferItemList); WTF_MAKE_FAST_ALLOCATED; |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 49 | public: |
rniwa@webkit.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 50 | DataTransferItemList(DataTransfer&); |
| 51 | ~DataTransferItemList(); |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 52 | |
rniwa@webkit.org | 863da80 | 2017-08-12 22:14:53 +0000 | [diff] [blame] | 53 | // 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.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 56 | DataTransfer& dataTransfer() { return m_dataTransfer; } |
rniwa@webkit.org | 863da80 | 2017-08-12 22:14:53 +0000 | [diff] [blame] | 57 | |
rniwa@webkit.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 58 | // DOM API |
rniwa@webkit.org | 863da80 | 2017-08-12 22:14:53 +0000 | [diff] [blame] | 59 | unsigned length() const; |
| 60 | RefPtr<DataTransferItem> item(unsigned index); |
rniwa@webkit.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 61 | ExceptionOr<RefPtr<DataTransferItem>> add(const String& data, const String& type); |
| 62 | RefPtr<DataTransferItem> add(Ref<File>&&); |
| 63 | ExceptionOr<void> remove(unsigned index); |
rniwa@webkit.org | 863da80 | 2017-08-12 22:14:53 +0000 | [diff] [blame] | 64 | void clear(); |
| 65 | |
rniwa@webkit.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 66 | void didClearStringData(const String& type); |
| 67 | void didSetStringData(const String& type); |
cdumez@apple.com | 455463f | 2018-12-21 00:40:09 +0000 | [diff] [blame] | 68 | bool hasItems() const { return m_items.hasValue(); } |
wenson_hsieh@apple.com | 1b38607 | 2017-10-04 22:28:08 +0000 | [diff] [blame] | 69 | const Vector<Ref<DataTransferItem>>& items() const |
| 70 | { |
| 71 | ASSERT(m_items); |
| 72 | return *m_items; |
| 73 | } |
rniwa@webkit.org | c7bff37 | 2017-08-16 02:23:41 +0000 | [diff] [blame] | 74 | |
rniwa@webkit.org | bf17e4b | 2017-08-17 06:17:09 +0000 | [diff] [blame] | 75 | private: |
| 76 | Vector<Ref<DataTransferItem>>& ensureItems() const; |
| 77 | |
rniwa@webkit.org | 863da80 | 2017-08-12 22:14:53 +0000 | [diff] [blame] | 78 | DataTransfer& m_dataTransfer; |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 79 | mutable Optional<Vector<Ref<DataTransferItem>>> m_items; |
dcheng@chromium.org | d3fc3e9 | 2011-03-08 05:48:33 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } // namespace WebCore |