| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Google 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 are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "core/dom/DataTransferItem.h" | |
| 33 | |
| 34 #include "bindings/v8/V8Binding.h" | |
| 35 #include "core/dom/Clipboard.h" | |
| 36 #include "core/dom/DataObjectItem.h" | |
| 37 #include "core/dom/StringCallback.h" | |
| 38 #include "wtf/StdLibExtras.h" | |
| 39 | |
| 40 namespace WebCore { | |
| 41 | |
| 42 PassRefPtr<DataTransferItem> DataTransferItem::create(PassRefPtr<Clipboard> clip
board, PassRefPtr<DataObjectItem> item) | |
| 43 { | |
| 44 return adoptRef(new DataTransferItem(clipboard, item)); | |
| 45 } | |
| 46 | |
| 47 DataTransferItem::~DataTransferItem() | |
| 48 { | |
| 49 } | |
| 50 | |
| 51 String DataTransferItem::kind() const | |
| 52 { | |
| 53 DEFINE_STATIC_LOCAL(const String, kindString, ("string")); | |
| 54 DEFINE_STATIC_LOCAL(const String, kindFile, ("file")); | |
| 55 if (!m_clipboard->canReadTypes()) | |
| 56 return String(); | |
| 57 switch (m_item->kind()) { | |
| 58 case DataObjectItem::StringKind: | |
| 59 return kindString; | |
| 60 case DataObjectItem::FileKind: | |
| 61 return kindFile; | |
| 62 } | |
| 63 ASSERT_NOT_REACHED(); | |
| 64 return String(); | |
| 65 } | |
| 66 | |
| 67 String DataTransferItem::type() const | |
| 68 { | |
| 69 if (!m_clipboard->canReadTypes()) | |
| 70 return String(); | |
| 71 return m_item->type(); | |
| 72 } | |
| 73 | |
| 74 void DataTransferItem::getAsString(ExecutionContext* context, PassOwnPtr<StringC
allback> callback) const | |
| 75 { | |
| 76 if (!m_clipboard->canReadData()) | |
| 77 return; | |
| 78 if (!callback || m_item->kind() != DataObjectItem::StringKind) | |
| 79 return; | |
| 80 | |
| 81 StringCallback::scheduleCallback(callback, context, m_item->getAsString()); | |
| 82 } | |
| 83 | |
| 84 PassRefPtr<Blob> DataTransferItem::getAsFile() const | |
| 85 { | |
| 86 if (!m_clipboard->canReadData()) | |
| 87 return 0; | |
| 88 | |
| 89 return m_item->getAsFile(); | |
| 90 } | |
| 91 | |
| 92 DataTransferItem::DataTransferItem(PassRefPtr<Clipboard> clipboard, PassRefPtr<D
ataObjectItem> item) | |
| 93 : m_clipboard(clipboard) | |
| 94 , m_item(item) | |
| 95 { | |
| 96 ScriptWrappable::init(this); | |
| 97 } | |
| 98 | |
| 99 | |
| 100 } // namespace WebCore | |
| 101 | |
| OLD | NEW |