Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/clipboard/DataTransferItem.h" | 31 #include "core/clipboard/DataTransferItem.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/V8Binding.h" | 33 #include "bindings/core/v8/V8Binding.h" |
| 34 #include "core/clipboard/DataObjectItem.h" | 34 #include "core/clipboard/DataObjectItem.h" |
| 35 #include "core/clipboard/DataTransfer.h" | 35 #include "core/clipboard/DataTransfer.h" |
| 36 #include "core/dom/ExecutionContext.h" | |
| 37 #include "core/dom/ExecutionContextTask.h" | |
| 38 #include "core/dom/StringCallback.h" | 36 #include "core/dom/StringCallback.h" |
| 39 #include "core/dom/TaskRunnerHelper.h" | 37 #include "core/dom/TaskRunnerHelper.h" |
| 38 #include "core/inspector/InspectorInstrumentation.h" | |
| 40 #include "public/platform/WebTraceLocation.h" | 39 #include "public/platform/WebTraceLocation.h" |
| 41 #include "wtf/StdLibExtras.h" | 40 #include "wtf/StdLibExtras.h" |
| 42 #include "wtf/text/WTFString.h" | 41 #include "wtf/text/WTFString.h" |
| 43 | 42 |
| 44 namespace blink { | 43 namespace blink { |
| 45 | 44 |
| 46 DataTransferItem* DataTransferItem::create(DataTransfer* dataTransfer, | 45 DataTransferItem* DataTransferItem::create(DataTransfer* dataTransfer, |
| 47 DataObjectItem* item) { | 46 DataObjectItem* item) { |
| 48 return new DataTransferItem(dataTransfer, item); | 47 return new DataTransferItem(dataTransfer, item); |
| 49 } | 48 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 62 ASSERT_NOT_REACHED(); | 61 ASSERT_NOT_REACHED(); |
| 63 return String(); | 62 return String(); |
| 64 } | 63 } |
| 65 | 64 |
| 66 String DataTransferItem::type() const { | 65 String DataTransferItem::type() const { |
| 67 if (!m_dataTransfer->canReadTypes()) | 66 if (!m_dataTransfer->canReadTypes()) |
| 68 return String(); | 67 return String(); |
| 69 return m_item->type(); | 68 return m_item->type(); |
| 70 } | 69 } |
| 71 | 70 |
| 71 static void runGetAsStringTask(ExecutionContext* context, | |
| 72 StringCallback* callback, | |
| 73 const String& data) { | |
| 74 InspectorInstrumentation::AsyncTask(context, callback); | |
| 75 callback->handleEvent(data); | |
| 76 } | |
| 77 | |
| 72 void DataTransferItem::getAsString(ScriptState* scriptState, | 78 void DataTransferItem::getAsString(ScriptState* scriptState, |
| 73 StringCallback* callback) const { | 79 StringCallback* callback) const { |
| 74 if (!m_dataTransfer->canReadData()) | 80 if (!m_dataTransfer->canReadData()) |
| 75 return; | 81 return; |
| 76 if (!callback || m_item->kind() != DataObjectItem::StringKind) | 82 if (!callback || m_item->kind() != DataObjectItem::StringKind) |
| 77 return; | 83 return; |
| 78 | 84 |
| 79 scriptState->getExecutionContext()->postTask( | 85 ExecutionContext* context = scriptState->getExecutionContext(); |
| 80 TaskType::UserInteraction, BLINK_FROM_HERE, | 86 InspectorInstrumentation::asyncTaskScheduled( |
| 81 createSameThreadTask(&StringCallback::handleEvent, | 87 context, "DataTransferItem.getAsString", callback); |
| 82 wrapPersistent(callback), m_item->getAsString()), | 88 TaskRunnerHelper::get(TaskType::UserInteraction, context) |
| 83 "DataTransferItem.getAsString"); | 89 ->postTask(BLINK_FROM_HERE, |
| 90 WTF::bind(&runGetAsStringTask, wrapPersistent(context), | |
|
tzik
2017/02/09 12:15:34
Could you replace wrapPersistent(context) here wit
yuryu
2017/02/09 12:56:43
Done.
| |
| 91 wrapPersistent(callback), m_item->getAsString())); | |
| 84 } | 92 } |
| 85 | 93 |
| 86 File* DataTransferItem::getAsFile() const { | 94 File* DataTransferItem::getAsFile() const { |
| 87 if (!m_dataTransfer->canReadData()) | 95 if (!m_dataTransfer->canReadData()) |
| 88 return nullptr; | 96 return nullptr; |
| 89 | 97 |
| 90 return m_item->getAsFile(); | 98 return m_item->getAsFile(); |
| 91 } | 99 } |
| 92 | 100 |
| 93 DataTransferItem::DataTransferItem(DataTransfer* dataTransfer, | 101 DataTransferItem::DataTransferItem(DataTransfer* dataTransfer, |
| 94 DataObjectItem* item) | 102 DataObjectItem* item) |
| 95 : m_dataTransfer(dataTransfer), m_item(item) {} | 103 : m_dataTransfer(dataTransfer), m_item(item) {} |
| 96 | 104 |
| 97 DEFINE_TRACE(DataTransferItem) { | 105 DEFINE_TRACE(DataTransferItem) { |
| 98 visitor->trace(m_dataTransfer); | 106 visitor->trace(m_dataTransfer); |
| 99 visitor->trace(m_item); | 107 visitor->trace(m_item); |
| 100 } | 108 } |
| 101 | 109 |
| 102 } // namespace blink | 110 } // namespace blink |
| OLD | NEW |