| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/services/html_viewer/webclipboard_impl.h" | 5 #include "mojo/services/html_viewer/webclipboard_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "mojo/services/html_viewer/blink_basic_type_converters.h" | 8 #include "mojo/services/html_viewer/blink_basic_type_converters.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 clipboard_->ReadMimeType( | 161 clipboard_->ReadMimeType( |
| 162 clipboard_type, mime_type.utf8(), base::Bind(&CopyWebString, &data)); | 162 clipboard_type, mime_type.utf8(), base::Bind(&CopyWebString, &data)); |
| 163 | 163 |
| 164 // Force this to be synchronous. | 164 // Force this to be synchronous. |
| 165 clipboard_.WaitForIncomingMethodCall(); | 165 clipboard_.WaitForIncomingMethodCall(); |
| 166 | 166 |
| 167 return data; | 167 return data; |
| 168 } | 168 } |
| 169 | 169 |
| 170 void WebClipboardImpl::writePlainText(const blink::WebString& text) { | 170 void WebClipboardImpl::writePlainText(const blink::WebString& text) { |
| 171 Array<MimeTypePairPtr> data; | 171 Map<String, Array<uint8_t>> data; |
| 172 MimeTypePairPtr text_data(MimeTypePair::New()); | 172 data[mojo::Clipboard::MIME_TYPE_TEXT] = Array<uint8_t>::From(text); |
| 173 text_data->mime_type = mojo::Clipboard::MIME_TYPE_TEXT; | |
| 174 text_data->data = Array<uint8_t>::From(text).Pass(); | |
| 175 data.push_back(text_data.Pass()); | |
| 176 | 173 |
| 177 clipboard_->WriteClipboardData(mojo::Clipboard::TYPE_COPY_PASTE, data.Pass()); | 174 clipboard_->WriteClipboardData(mojo::Clipboard::TYPE_COPY_PASTE, data.Pass()); |
| 178 } | 175 } |
| 179 | 176 |
| 180 void WebClipboardImpl::writeHTML(const blink::WebString& htmlText, | 177 void WebClipboardImpl::writeHTML(const blink::WebString& htmlText, |
| 181 const blink::WebURL& url, | 178 const blink::WebURL& url, |
| 182 const blink::WebString& plainText, | 179 const blink::WebString& plainText, |
| 183 bool writeSmartPaste) { | 180 bool writeSmartPaste) { |
| 184 Array<MimeTypePairPtr> data; | 181 Map<String, Array<uint8_t>> data; |
| 185 MimeTypePairPtr text_data(MimeTypePair::New()); | 182 data[mojo::Clipboard::MIME_TYPE_TEXT] = Array<uint8_t>::From(plainText); |
| 186 text_data->mime_type = mojo::Clipboard::MIME_TYPE_TEXT; | 183 data[mojo::Clipboard::MIME_TYPE_HTML] = Array<uint8_t>::From(htmlText); |
| 187 text_data->data = Array<uint8_t>::From(plainText).Pass(); | 184 data[mojo::Clipboard::MIME_TYPE_URL] = Array<uint8_t>::From(url.string()); |
| 188 data.push_back(text_data.Pass()); | |
| 189 | 185 |
| 190 MimeTypePairPtr html_data(MimeTypePair::New()); | 186 if (writeSmartPaste) |
| 191 text_data->mime_type = mojo::Clipboard::MIME_TYPE_HTML; | 187 data[kMimeTypeWebkitSmartPaste] = Array<uint8_t>::From(blink::WebString()); |
| 192 text_data->data = Array<uint8_t>::From(htmlText).Pass(); | |
| 193 data.push_back(html_data.Pass()); | |
| 194 | |
| 195 MimeTypePairPtr url_data(MimeTypePair::New()); | |
| 196 url_data->mime_type = mojo::Clipboard::MIME_TYPE_URL; | |
| 197 url_data->data = Array<uint8_t>::From(url.string()).Pass(); | |
| 198 data.push_back(url_data.Pass()); | |
| 199 | |
| 200 if (writeSmartPaste) { | |
| 201 MimeTypePairPtr smart_paste(MimeTypePair::New()); | |
| 202 url_data->mime_type = kMimeTypeWebkitSmartPaste; | |
| 203 url_data->data = Array<uint8_t>::From(blink::WebString()).Pass(); | |
| 204 data.push_back(smart_paste.Pass()); | |
| 205 } | |
| 206 | 188 |
| 207 clipboard_->WriteClipboardData(mojo::Clipboard::TYPE_COPY_PASTE, data.Pass()); | 189 clipboard_->WriteClipboardData(mojo::Clipboard::TYPE_COPY_PASTE, data.Pass()); |
| 208 } | 190 } |
| 209 | 191 |
| 210 mojo::Clipboard::Type WebClipboardImpl::ConvertBufferType(Buffer buffer) { | 192 mojo::Clipboard::Type WebClipboardImpl::ConvertBufferType(Buffer buffer) { |
| 211 switch (buffer) { | 193 switch (buffer) { |
| 212 case BufferStandard: | 194 case BufferStandard: |
| 213 return mojo::Clipboard::TYPE_COPY_PASTE; | 195 return mojo::Clipboard::TYPE_COPY_PASTE; |
| 214 case BufferSelection: | 196 case BufferSelection: |
| 215 return mojo::Clipboard::TYPE_SELECTION; | 197 return mojo::Clipboard::TYPE_SELECTION; |
| 216 } | 198 } |
| 217 | 199 |
| 218 NOTREACHED(); | 200 NOTREACHED(); |
| 219 return mojo::Clipboard::TYPE_COPY_PASTE; | 201 return mojo::Clipboard::TYPE_COPY_PASTE; |
| 220 } | 202 } |
| 221 | 203 |
| 222 } // namespace mojo | 204 } // namespace mojo |
| OLD | NEW |