| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/renderer/webclipboard_impl.h" | 5 #include "content/renderer/webclipboard_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "content/common/clipboard_format.h" | 11 #include "content/common/clipboard_format.h" |
| 12 #include "content/public/common/drop_data.h" | 12 #include "content/public/common/drop_data.h" |
| 13 #include "content/renderer/clipboard_utils.h" | 13 #include "content/renderer/clipboard_utils.h" |
| 14 #include "content/renderer/drop_data_builder.h" | 14 #include "content/renderer/drop_data_builder.h" |
| 15 #include "content/renderer/renderer_clipboard_delegate.h" | 15 #include "content/renderer/renderer_clipboard_delegate.h" |
| 16 #include "third_party/WebKit/public/platform/StringVectorCopier.h" |
| 16 #include "third_party/WebKit/public/platform/WebDragData.h" | 17 #include "third_party/WebKit/public/platform/WebDragData.h" |
| 17 #include "third_party/WebKit/public/platform/WebImage.h" | 18 #include "third_party/WebKit/public/platform/WebImage.h" |
| 18 #include "third_party/WebKit/public/platform/WebSize.h" | 19 #include "third_party/WebKit/public/platform/WebSize.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/platform/WebURL.h" | 21 #include "third_party/WebKit/public/platform/WebURL.h" |
| 21 #include "third_party/WebKit/public/platform/WebVector.h" | 22 #include "third_party/WebKit/public/platform/WebVector.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 | 24 |
| 24 using blink::WebBlobInfo; | 25 using blink::WebBlobInfo; |
| 25 using blink::WebClipboard; | 26 using blink::WebClipboard; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return false; | 74 return false; |
| 74 } | 75 } |
| 75 | 76 |
| 76 WebVector<WebString> WebClipboardImpl::readAvailableTypes( | 77 WebVector<WebString> WebClipboardImpl::readAvailableTypes( |
| 77 Buffer buffer, bool* contains_filenames) { | 78 Buffer buffer, bool* contains_filenames) { |
| 78 ui::ClipboardType clipboard_type; | 79 ui::ClipboardType clipboard_type; |
| 79 std::vector<base::string16> types; | 80 std::vector<base::string16> types; |
| 80 if (ConvertBufferType(buffer, &clipboard_type)) { | 81 if (ConvertBufferType(buffer, &clipboard_type)) { |
| 81 delegate_->ReadAvailableTypes(clipboard_type, &types, contains_filenames); | 82 delegate_->ReadAvailableTypes(clipboard_type, &types, contains_filenames); |
| 82 } | 83 } |
| 83 return types; | 84 return blink::CopyStringVectorFromUTF16(types); |
| 84 } | 85 } |
| 85 | 86 |
| 86 WebString WebClipboardImpl::readPlainText(Buffer buffer) { | 87 WebString WebClipboardImpl::readPlainText(Buffer buffer) { |
| 87 ui::ClipboardType clipboard_type; | 88 ui::ClipboardType clipboard_type; |
| 88 if (!ConvertBufferType(buffer, &clipboard_type)) | 89 if (!ConvertBufferType(buffer, &clipboard_type)) |
| 89 return WebString(); | 90 return WebString(); |
| 90 | 91 |
| 91 base::string16 text; | 92 base::string16 text; |
| 92 delegate_->ReadText(clipboard_type, &text); | 93 delegate_->ReadText(clipboard_type, &text); |
| 93 return text; | 94 return WebString::fromUTF16(text); |
| 94 } | 95 } |
| 95 | 96 |
| 96 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url, | 97 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url, |
| 97 unsigned* fragment_start, | 98 unsigned* fragment_start, |
| 98 unsigned* fragment_end) { | 99 unsigned* fragment_end) { |
| 99 ui::ClipboardType clipboard_type; | 100 ui::ClipboardType clipboard_type; |
| 100 if (!ConvertBufferType(buffer, &clipboard_type)) | 101 if (!ConvertBufferType(buffer, &clipboard_type)) |
| 101 return WebString(); | 102 return WebString(); |
| 102 | 103 |
| 103 base::string16 html_stdstr; | 104 base::string16 html_stdstr; |
| 104 GURL gurl; | 105 GURL gurl; |
| 105 delegate_->ReadHTML(clipboard_type, &html_stdstr, &gurl, | 106 delegate_->ReadHTML(clipboard_type, &html_stdstr, &gurl, |
| 106 static_cast<uint32_t*>(fragment_start), | 107 static_cast<uint32_t*>(fragment_start), |
| 107 static_cast<uint32_t*>(fragment_end)); | 108 static_cast<uint32_t*>(fragment_end)); |
| 108 *source_url = gurl; | 109 *source_url = gurl; |
| 109 return html_stdstr; | 110 return WebString::fromUTF16(html_stdstr); |
| 110 } | 111 } |
| 111 | 112 |
| 112 WebString WebClipboardImpl::readRTF(Buffer buffer) { | 113 WebString WebClipboardImpl::readRTF(Buffer buffer) { |
| 113 ui::ClipboardType clipboard_type; | 114 ui::ClipboardType clipboard_type; |
| 114 if (!ConvertBufferType(buffer, &clipboard_type)) | 115 if (!ConvertBufferType(buffer, &clipboard_type)) |
| 115 return WebString(); | 116 return WebString(); |
| 116 | 117 |
| 117 std::string rtf; | 118 std::string rtf; |
| 118 delegate_->ReadRTF(clipboard_type, &rtf); | 119 delegate_->ReadRTF(clipboard_type, &rtf); |
| 119 return WebString::fromLatin1(rtf); | 120 return WebString::fromLatin1(rtf); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 134 size); | 135 size); |
| 135 } | 136 } |
| 136 | 137 |
| 137 WebString WebClipboardImpl::readCustomData(Buffer buffer, | 138 WebString WebClipboardImpl::readCustomData(Buffer buffer, |
| 138 const WebString& type) { | 139 const WebString& type) { |
| 139 ui::ClipboardType clipboard_type; | 140 ui::ClipboardType clipboard_type; |
| 140 if (!ConvertBufferType(buffer, &clipboard_type)) | 141 if (!ConvertBufferType(buffer, &clipboard_type)) |
| 141 return WebString(); | 142 return WebString(); |
| 142 | 143 |
| 143 base::string16 data; | 144 base::string16 data; |
| 144 delegate_->ReadCustomData(clipboard_type, type, &data); | 145 delegate_->ReadCustomData(clipboard_type, type.utf16(), &data); |
| 145 return data; | 146 return WebString::fromUTF16(data); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void WebClipboardImpl::writePlainText(const WebString& plain_text) { | 149 void WebClipboardImpl::writePlainText(const WebString& plain_text) { |
| 149 delegate_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text); | 150 delegate_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text.utf16()); |
| 150 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); | 151 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 151 } | 152 } |
| 152 | 153 |
| 153 void WebClipboardImpl::writeHTML( | 154 void WebClipboardImpl::writeHTML( |
| 154 const WebString& html_text, const WebURL& source_url, | 155 const WebString& html_text, const WebURL& source_url, |
| 155 const WebString& plain_text, bool write_smart_paste) { | 156 const WebString& plain_text, bool write_smart_paste) { |
| 156 delegate_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, html_text, source_url); | 157 delegate_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, html_text.utf16(), |
| 157 delegate_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text); | 158 source_url); |
| 159 delegate_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text.utf16()); |
| 158 | 160 |
| 159 if (write_smart_paste) | 161 if (write_smart_paste) |
| 160 delegate_->WriteSmartPasteMarker(ui::CLIPBOARD_TYPE_COPY_PASTE); | 162 delegate_->WriteSmartPasteMarker(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 161 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); | 163 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 162 } | 164 } |
| 163 | 165 |
| 164 void WebClipboardImpl::writeImage(const WebImage& image, | 166 void WebClipboardImpl::writeImage(const WebImage& image, |
| 165 const WebURL& url, | 167 const WebURL& url, |
| 166 const WebString& title) { | 168 const WebString& title) { |
| 167 DCHECK(!image.isNull()); | 169 DCHECK(!image.isNull()); |
| 168 const SkBitmap& bitmap = image.getSkBitmap(); | 170 const SkBitmap& bitmap = image.getSkBitmap(); |
| 169 if (!delegate_->WriteImage(ui::CLIPBOARD_TYPE_COPY_PASTE, bitmap)) | 171 if (!delegate_->WriteImage(ui::CLIPBOARD_TYPE_COPY_PASTE, bitmap)) |
| 170 return; | 172 return; |
| 171 | 173 |
| 172 if (!url.isEmpty()) { | 174 if (!url.isEmpty()) { |
| 173 delegate_->WriteBookmark(ui::CLIPBOARD_TYPE_COPY_PASTE, url, title); | 175 delegate_->WriteBookmark(ui::CLIPBOARD_TYPE_COPY_PASTE, url, title.utf16()); |
| 174 #if !defined(OS_MACOSX) | 176 #if !defined(OS_MACOSX) |
| 175 // When writing the image, we also write the image markup so that pasting | 177 // When writing the image, we also write the image markup so that pasting |
| 176 // into rich text editors, such as Gmail, reveals the image. We also don't | 178 // into rich text editors, such as Gmail, reveals the image. We also don't |
| 177 // want to call writeText(), since some applications (WordPad) don't pick | 179 // want to call writeText(), since some applications (WordPad) don't pick |
| 178 // the image if there is also a text format on the clipboard. | 180 // the image if there is also a text format on the clipboard. |
| 179 // We also don't want to write HTML on a Mac, since Mail.app prefers to use | 181 // We also don't want to write HTML on a Mac, since Mail.app prefers to use |
| 180 // the image markup over attaching the actual image. See | 182 // the image markup over attaching the actual image. See |
| 181 // http://crbug.com/33016 for details. | 183 // http://crbug.com/33016 for details. |
| 182 delegate_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, | 184 delegate_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, |
| 183 base::UTF8ToUTF16(URLToImageMarkup(url, title)), | 185 WebString::fromUTF8(URLToImageMarkup(url, title)), |
| 184 GURL()); | 186 GURL()); |
| 185 #endif | 187 #endif |
| 186 } | 188 } |
| 187 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); | 189 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 188 } | 190 } |
| 189 | 191 |
| 190 void WebClipboardImpl::writeDataObject(const WebDragData& data) { | 192 void WebClipboardImpl::writeDataObject(const WebDragData& data) { |
| 191 const DropData& data_object = DropDataBuilder::Build(data); | 193 const DropData& data_object = DropDataBuilder::Build(data); |
| 192 // TODO(dcheng): Properly support text/uri-list here. | 194 // TODO(dcheng): Properly support text/uri-list here. |
| 193 // Avoid calling the WriteFoo functions if there is no data associated with a | 195 // Avoid calling the WriteFoo functions if there is no data associated with a |
| (...skipping 28 matching lines...) Expand all Loading... |
| 222 return false; | 224 return false; |
| 223 #endif | 225 #endif |
| 224 default: | 226 default: |
| 225 NOTREACHED(); | 227 NOTREACHED(); |
| 226 return false; | 228 return false; |
| 227 } | 229 } |
| 228 return true; | 230 return true; |
| 229 } | 231 } |
| 230 | 232 |
| 231 } // namespace content | 233 } // namespace content |
| OLD | NEW |