| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008, 2009 Google Inc. | 3 * Copyright (C) 2008, 2009 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "core/clipboard/DataTransferItemList.h" | 28 #include "core/clipboard/DataTransferItemList.h" |
| 29 | 29 |
| 30 #include "bindings/v8/ExceptionState.h" | 30 #include "bindings/v8/ExceptionState.h" |
| 31 #include "core/clipboard/Clipboard.h" | 31 #include "core/clipboard/Clipboard.h" |
| 32 #include "core/clipboard/DataObject.h" | 32 #include "core/clipboard/DataObject.h" |
| 33 #include "core/clipboard/DataTransferItem.h" | 33 #include "core/clipboard/DataTransferItem.h" |
| 34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 PassRefPtr<DataTransferItemList> DataTransferItemList::create(PassRefPtr<Clipboa
rd> clipboard, PassRefPtr<DataObject> list) | 38 DEFINE_GC_INFO(DataTransferItemList); |
| 39 |
| 40 PassRefPtrWillBeRawPtr<DataTransferItemList> DataTransferItemList::create(PassRe
fPtrWillBeRawPtr<Clipboard> clipboard, PassRefPtrWillBeRawPtr<DataObject> list) |
| 39 { | 41 { |
| 40 return adoptRef(new DataTransferItemList(clipboard, list)); | 42 return adoptRefWillBeNoop(new DataTransferItemList(clipboard, list)); |
| 41 } | 43 } |
| 42 | 44 |
| 43 DataTransferItemList::~DataTransferItemList() | 45 DataTransferItemList::~DataTransferItemList() |
| 44 { | 46 { |
| 45 } | 47 } |
| 46 | 48 |
| 47 size_t DataTransferItemList::length() const | 49 size_t DataTransferItemList::length() const |
| 48 { | 50 { |
| 49 if (!m_clipboard->canReadTypes()) | 51 if (!m_clipboard->canReadTypes()) |
| 50 return 0; | 52 return 0; |
| 51 return m_dataObject->length(); | 53 return m_dataObject->length(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 PassRefPtr<DataTransferItem> DataTransferItemList::item(unsigned long index) | 56 PassRefPtrWillBeRawPtr<DataTransferItem> DataTransferItemList::item(unsigned lon
g index) |
| 55 { | 57 { |
| 56 if (!m_clipboard->canReadTypes()) | 58 if (!m_clipboard->canReadTypes()) |
| 57 return nullptr; | 59 return nullptr; |
| 58 RefPtr<DataObjectItem> item = m_dataObject->item(index); | 60 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->item(index); |
| 59 if (!item) | 61 if (!item) |
| 60 return nullptr; | 62 return nullptr; |
| 61 | 63 |
| 62 return DataTransferItem::create(m_clipboard, item); | 64 return DataTransferItem::create(m_clipboard, item); |
| 63 } | 65 } |
| 64 | 66 |
| 65 void DataTransferItemList::deleteItem(unsigned long index, ExceptionState& excep
tionState) | 67 void DataTransferItemList::deleteItem(unsigned long index, ExceptionState& excep
tionState) |
| 66 { | 68 { |
| 67 if (!m_clipboard->canWriteData()) { | 69 if (!m_clipboard->canWriteData()) { |
| 68 exceptionState.throwDOMException(InvalidStateError, "The list is not wri
table."); | 70 exceptionState.throwDOMException(InvalidStateError, "The list is not wri
table."); |
| 69 return; | 71 return; |
| 70 } | 72 } |
| 71 m_dataObject->deleteItem(index); | 73 m_dataObject->deleteItem(index); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void DataTransferItemList::clear() | 76 void DataTransferItemList::clear() |
| 75 { | 77 { |
| 76 if (!m_clipboard->canWriteData()) | 78 if (!m_clipboard->canWriteData()) |
| 77 return; | 79 return; |
| 78 m_dataObject->clearAll(); | 80 m_dataObject->clearAll(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 PassRefPtr<DataTransferItem> DataTransferItemList::add(const String& data, const
String& type, ExceptionState& exceptionState) | 83 PassRefPtrWillBeRawPtr<DataTransferItem> DataTransferItemList::add(const String&
data, const String& type, ExceptionState& exceptionState) |
| 82 { | 84 { |
| 83 if (!m_clipboard->canWriteData()) | 85 if (!m_clipboard->canWriteData()) |
| 84 return nullptr; | 86 return nullptr; |
| 85 RefPtr<DataObjectItem> item = m_dataObject->add(data, type); | 87 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->add(data, type); |
| 86 if (!item) { | 88 if (!item) { |
| 87 exceptionState.throwDOMException(NotSupportedError, "An item already exi
sts for type '" + type + "'."); | 89 exceptionState.throwDOMException(NotSupportedError, "An item already exi
sts for type '" + type + "'."); |
| 88 return nullptr; | 90 return nullptr; |
| 89 } | 91 } |
| 90 return DataTransferItem::create(m_clipboard, item); | 92 return DataTransferItem::create(m_clipboard, item); |
| 91 } | 93 } |
| 92 | 94 |
| 93 PassRefPtr<DataTransferItem> DataTransferItemList::add(PassRefPtr<File> file) | 95 PassRefPtrWillBeRawPtr<DataTransferItem> DataTransferItemList::add(PassRefPtr<Fi
le> file) |
| 94 { | 96 { |
| 95 if (!m_clipboard->canWriteData()) | 97 if (!m_clipboard->canWriteData()) |
| 96 return nullptr; | 98 return nullptr; |
| 97 RefPtr<DataObjectItem> item = m_dataObject->add(file); | 99 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->add(file); |
| 98 if (!item) | 100 if (!item) |
| 99 return nullptr; | 101 return nullptr; |
| 100 return DataTransferItem::create(m_clipboard, item); | 102 return DataTransferItem::create(m_clipboard, item); |
| 101 } | 103 } |
| 102 | 104 |
| 103 DataTransferItemList::DataTransferItemList(PassRefPtr<Clipboard> clipboard, Pass
RefPtr<DataObject> dataObject) | 105 DataTransferItemList::DataTransferItemList(PassRefPtrWillBeRawPtr<Clipboard> cli
pboard, PassRefPtrWillBeRawPtr<DataObject> dataObject) |
| 104 : m_clipboard(clipboard) | 106 : m_clipboard(clipboard) |
| 105 , m_dataObject(dataObject) | 107 , m_dataObject(dataObject) |
| 106 { | 108 { |
| 107 ScriptWrappable::init(this); | 109 ScriptWrappable::init(this); |
| 108 } | 110 } |
| 109 | 111 |
| 112 void DataTransferItemList::trace(Visitor* visitor) |
| 113 { |
| 114 visitor->trace(m_clipboard); |
| 115 visitor->trace(m_dataObject); |
| 116 } |
| 117 |
| 110 } // namespace WebCore | 118 } // namespace WebCore |
| OLD | NEW |