| OLD | NEW |
| 1 // Copyright (c) 2012 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 "webkit/glue/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/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "content/renderer/scoped_clipboard_writer_glue.h" |
| 11 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 12 #include "net/base/escape.h" | |
| 13 #include "third_party/WebKit/public/platform/WebData.h" | 13 #include "third_party/WebKit/public/platform/WebData.h" |
| 14 #include "third_party/WebKit/public/platform/WebDragData.h" | 14 #include "third_party/WebKit/public/platform/WebDragData.h" |
| 15 #include "third_party/WebKit/public/platform/WebImage.h" | 15 #include "third_party/WebKit/public/platform/WebImage.h" |
| 16 #include "third_party/WebKit/public/platform/WebSize.h" | 16 #include "third_party/WebKit/public/platform/WebSize.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebURL.h" | 18 #include "third_party/WebKit/public/platform/WebURL.h" |
| 19 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "ui/base/clipboard/clipboard.h" | 21 #include "ui/base/clipboard/clipboard.h" |
| 22 #include "ui/base/clipboard/custom_data_helper.h" | 22 #include "ui/base/clipboard/custom_data_helper.h" |
| 23 #include "webkit/common/webdropdata.h" | 23 #include "webkit/common/webdropdata.h" |
| 24 #include "webkit/glue/scoped_clipboard_writer_glue.h" | |
| 25 #include "webkit/glue/webkit_glue.h" | 24 #include "webkit/glue/webkit_glue.h" |
| 25 #include "webkit/renderer/clipboard_utils.h" |
| 26 | 26 |
| 27 using WebKit::WebClipboard; | 27 using WebKit::WebClipboard; |
| 28 using WebKit::WebData; | 28 using WebKit::WebData; |
| 29 using WebKit::WebDragData; | 29 using WebKit::WebDragData; |
| 30 using WebKit::WebImage; | 30 using WebKit::WebImage; |
| 31 using WebKit::WebString; | 31 using WebKit::WebString; |
| 32 using WebKit::WebURL; | 32 using WebKit::WebURL; |
| 33 using WebKit::WebVector; | 33 using WebKit::WebVector; |
| 34 | 34 |
| 35 namespace webkit_glue { | 35 namespace content { |
| 36 | |
| 37 // Static | |
| 38 std::string WebClipboardImpl::URLToMarkup(const WebURL& url, | |
| 39 const WebString& title) { | |
| 40 std::string markup("<a href=\""); | |
| 41 markup.append(url.spec()); | |
| 42 markup.append("\">"); | |
| 43 // TODO(darin): HTML escape this | |
| 44 markup.append(net::EscapeForHTML(UTF16ToUTF8(title))); | |
| 45 markup.append("</a>"); | |
| 46 return markup; | |
| 47 } | |
| 48 | |
| 49 // Static | |
| 50 std::string WebClipboardImpl::URLToImageMarkup(const WebURL& url, | |
| 51 const WebString& title) { | |
| 52 std::string markup("<img src=\""); | |
| 53 markup.append(url.spec()); | |
| 54 markup.append("\""); | |
| 55 if (!title.isEmpty()) { | |
| 56 markup.append(" alt=\""); | |
| 57 markup.append(net::EscapeForHTML(UTF16ToUTF8(title))); | |
| 58 markup.append("\""); | |
| 59 } | |
| 60 markup.append("/>"); | |
| 61 return markup; | |
| 62 } | |
| 63 | 36 |
| 64 WebClipboardImpl::WebClipboardImpl(ClipboardClient* client) | 37 WebClipboardImpl::WebClipboardImpl(ClipboardClient* client) |
| 65 : client_(client) { | 38 : client_(client) { |
| 66 } | 39 } |
| 67 | 40 |
| 68 WebClipboardImpl::~WebClipboardImpl() { | 41 WebClipboardImpl::~WebClipboardImpl() { |
| 69 } | 42 } |
| 70 | 43 |
| 71 uint64 WebClipboardImpl::getSequenceNumber() { | 44 uint64 WebClipboardImpl::getSequenceNumber() { |
| 72 return sequenceNumber(BufferStandard); | 45 return sequenceNumber(BufferStandard); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 167 |
| 195 void WebClipboardImpl::writePlainText(const WebString& plain_text) { | 168 void WebClipboardImpl::writePlainText(const WebString& plain_text) { |
| 196 ScopedClipboardWriterGlue scw(client_); | 169 ScopedClipboardWriterGlue scw(client_); |
| 197 scw.WriteText(plain_text); | 170 scw.WriteText(plain_text); |
| 198 } | 171 } |
| 199 | 172 |
| 200 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { | 173 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { |
| 201 ScopedClipboardWriterGlue scw(client_); | 174 ScopedClipboardWriterGlue scw(client_); |
| 202 | 175 |
| 203 scw.WriteBookmark(title, url.spec()); | 176 scw.WriteBookmark(title, url.spec()); |
| 204 scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), std::string()); | 177 scw.WriteHTML(UTF8ToUTF16(webkit_clipboard::URLToMarkup(url, title)), |
| 178 std::string()); |
| 205 scw.WriteText(UTF8ToUTF16(std::string(url.spec()))); | 179 scw.WriteText(UTF8ToUTF16(std::string(url.spec()))); |
| 206 } | 180 } |
| 207 | 181 |
| 208 void WebClipboardImpl::writeImage( | 182 void WebClipboardImpl::writeImage( |
| 209 const WebImage& image, const WebURL& url, const WebString& title) { | 183 const WebImage& image, const WebURL& url, const WebString& title) { |
| 210 ScopedClipboardWriterGlue scw(client_); | 184 ScopedClipboardWriterGlue scw(client_); |
| 211 | 185 |
| 212 if (!image.isNull()) { | 186 if (!image.isNull()) { |
| 213 const SkBitmap& bitmap = image.getSkBitmap(); | 187 const SkBitmap& bitmap = image.getSkBitmap(); |
| 214 SkAutoLockPixels locked(bitmap); | 188 SkAutoLockPixels locked(bitmap); |
| 215 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); | 189 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); |
| 216 } | 190 } |
| 217 | 191 |
| 218 if (!url.isEmpty()) { | 192 if (!url.isEmpty()) { |
| 219 scw.WriteBookmark(title, url.spec()); | 193 scw.WriteBookmark(title, url.spec()); |
| 220 #if !defined(OS_MACOSX) | 194 #if !defined(OS_MACOSX) |
| 221 // When writing the image, we also write the image markup so that pasting | 195 // When writing the image, we also write the image markup so that pasting |
| 222 // into rich text editors, such as Gmail, reveals the image. We also don't | 196 // into rich text editors, such as Gmail, reveals the image. We also don't |
| 223 // want to call writeText(), since some applications (WordPad) don't pick | 197 // want to call writeText(), since some applications (WordPad) don't pick |
| 224 // the image if there is also a text format on the clipboard. | 198 // the image if there is also a text format on the clipboard. |
| 225 // We also don't want to write HTML on a Mac, since Mail.app prefers to use | 199 // We also don't want to write HTML on a Mac, since Mail.app prefers to use |
| 226 // the image markup over attaching the actual image. See | 200 // the image markup over attaching the actual image. See |
| 227 // http://crbug.com/33016 for details. | 201 // http://crbug.com/33016 for details. |
| 228 scw.WriteHTML(UTF8ToUTF16(URLToImageMarkup(url, title)), std::string()); | 202 scw.WriteHTML(UTF8ToUTF16(webkit_clipboard::URLToImageMarkup(url, title)), |
| 203 std::string()); |
| 229 #endif | 204 #endif |
| 230 } | 205 } |
| 231 } | 206 } |
| 232 | 207 |
| 233 void WebClipboardImpl::writeDataObject(const WebDragData& data) { | 208 void WebClipboardImpl::writeDataObject(const WebDragData& data) { |
| 234 ScopedClipboardWriterGlue scw(client_); | 209 ScopedClipboardWriterGlue scw(client_); |
| 235 | 210 |
| 236 WebDropData data_object(data); | 211 WebDropData data_object(data); |
| 237 // TODO(dcheng): Properly support text/uri-list here. | 212 // TODO(dcheng): Properly support text/uri-list here. |
| 238 if (!data_object.text.is_null()) | 213 if (!data_object.text.is_null()) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 268 break; | 243 break; |
| 269 #endif | 244 #endif |
| 270 #endif | 245 #endif |
| 271 default: | 246 default: |
| 272 NOTREACHED(); | 247 NOTREACHED(); |
| 273 return false; | 248 return false; |
| 274 } | 249 } |
| 275 return true; | 250 return true; |
| 276 } | 251 } |
| 277 | 252 |
| 278 } // namespace webkit_glue | 253 } // namespace content |
| 254 |
| OLD | NEW |