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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 if (type() == mimeTypeImagePng) { | 119 if (type() == mimeTypeImagePng) { |
120 // FIXME: This is pretty inefficient. We copy the data from the browser | 120 // FIXME: This is pretty inefficient. We copy the data from the browser |
121 // to the renderer. We then place it in a blob in WebKit, which | 121 // to the renderer. We then place it in a blob in WebKit, which |
122 // registers it and copies it *back* to the browser. When a consumer | 122 // registers it and copies it *back* to the browser. When a consumer |
123 // wants to read the data, we then copy the data back into the renderer. | 123 // wants to read the data, we then copy the data back into the renderer. |
124 // https://bugs.webkit.org/show_bug.cgi?id=58107 has been filed to track | 124 // https://bugs.webkit.org/show_bug.cgi?id=58107 has been filed to track |
125 // improvements to this code (in particular, add a registerClipboardBlob | 125 // improvements to this code (in particular, add a registerClipboardBlob |
126 // method to the blob registry; that way the data is only copied over | 126 // method to the blob registry; that way the data is only copied over |
127 // into the renderer when it's actually read, not when the blob is | 127 // into the renderer when it's actually read, not when the blob is |
128 // initially constructed). | 128 // initially constructed). |
129 RefPtr<SharedBuffer> data = static_cast<PassRefPtr<SharedBuffer>>(blink:
:Platform::current()->clipboard()->readImage(blink::WebClipboard::BufferStandard
)); | 129 RefPtr<SharedBuffer> data = static_cast<PassRefPtr<SharedBuffer>>(Platfo
rm::current()->clipboard()->readImage(WebClipboard::BufferStandard)); |
130 OwnPtr<BlobData> blobData = BlobData::create(); | 130 OwnPtr<BlobData> blobData = BlobData::create(); |
131 blobData->appendBytes(data->data(), data->size()); | 131 blobData->appendBytes(data->data(), data->size()); |
132 blobData->setContentType(mimeTypeImagePng); | 132 blobData->setContentType(mimeTypeImagePng); |
133 return Blob::create(BlobDataHandle::create(blobData.release(), data->siz
e())); | 133 return Blob::create(BlobDataHandle::create(blobData.release(), data->siz
e())); |
134 } | 134 } |
135 | 135 |
136 return nullptr; | 136 return nullptr; |
137 } | 137 } |
138 | 138 |
139 String DataObjectItem::getAsString() const | 139 String DataObjectItem::getAsString() const |
140 { | 140 { |
141 ASSERT(m_kind == StringKind); | 141 ASSERT(m_kind == StringKind); |
142 | 142 |
143 if (m_source == InternalSource) | 143 if (m_source == InternalSource) |
144 return m_data; | 144 return m_data; |
145 | 145 |
146 ASSERT(m_source == PasteboardSource); | 146 ASSERT(m_source == PasteboardSource); |
147 | 147 |
148 blink::WebClipboard::Buffer buffer = Pasteboard::generalPasteboard()->buffer
(); | 148 WebClipboard::Buffer buffer = Pasteboard::generalPasteboard()->buffer(); |
149 String data; | 149 String data; |
150 // This is ugly but there's no real alternative. | 150 // This is ugly but there's no real alternative. |
151 if (m_type == mimeTypeTextPlain) { | 151 if (m_type == mimeTypeTextPlain) { |
152 data = blink::Platform::current()->clipboard()->readPlainText(buffer); | 152 data = Platform::current()->clipboard()->readPlainText(buffer); |
153 } else if (m_type == mimeTypeTextHTML) { | 153 } else if (m_type == mimeTypeTextHTML) { |
154 blink::WebURL ignoredSourceURL; | 154 WebURL ignoredSourceURL; |
155 unsigned ignored; | 155 unsigned ignored; |
156 data = blink::Platform::current()->clipboard()->readHTML(buffer, &ignore
dSourceURL, &ignored, &ignored); | 156 data = Platform::current()->clipboard()->readHTML(buffer, &ignoredSource
URL, &ignored, &ignored); |
157 } else { | 157 } else { |
158 data = blink::Platform::current()->clipboard()->readCustomData(buffer, m
_type); | 158 data = Platform::current()->clipboard()->readCustomData(buffer, m_type); |
159 } | 159 } |
160 | 160 |
161 return blink::Platform::current()->clipboard()->sequenceNumber(buffer) == m_
sequenceNumber ? data : String(); | 161 return Platform::current()->clipboard()->sequenceNumber(buffer) == m_sequenc
eNumber ? data : String(); |
162 } | 162 } |
163 | 163 |
164 bool DataObjectItem::isFilename() const | 164 bool DataObjectItem::isFilename() const |
165 { | 165 { |
166 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=81261: When we properly su
pport File dragout, | 166 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=81261: When we properly su
pport File dragout, |
167 // we'll need to make sure this works as expected for DragDataChromium. | 167 // we'll need to make sure this works as expected for DragDataChromium. |
168 return m_kind == FileKind && m_file; | 168 return m_kind == FileKind && m_file; |
169 } | 169 } |
170 | 170 |
171 DEFINE_TRACE(DataObjectItem) | 171 DEFINE_TRACE(DataObjectItem) |
172 { | 172 { |
173 visitor->trace(m_file); | 173 visitor->trace(m_file); |
174 } | 174 } |
175 | 175 |
176 } // namespace blink | 176 } // namespace blink |
OLD | NEW |