| 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/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/public/common/drop_data.h" | 11 #include "content/public/common/drop_data.h" |
| 12 #include "content/renderer/clipboard_utils.h" |
| 12 #include "content/renderer/drop_data_builder.h" | 13 #include "content/renderer/drop_data_builder.h" |
| 13 #include "content/renderer/scoped_clipboard_writer_glue.h" | 14 #include "content/renderer/scoped_clipboard_writer_glue.h" |
| 14 #include "third_party/WebKit/public/platform/WebData.h" | 15 #include "third_party/WebKit/public/platform/WebData.h" |
| 15 #include "third_party/WebKit/public/platform/WebDragData.h" | 16 #include "third_party/WebKit/public/platform/WebDragData.h" |
| 16 #include "third_party/WebKit/public/platform/WebImage.h" | 17 #include "third_party/WebKit/public/platform/WebImage.h" |
| 17 #include "third_party/WebKit/public/platform/WebSize.h" | 18 #include "third_party/WebKit/public/platform/WebSize.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebURL.h" | 20 #include "third_party/WebKit/public/platform/WebURL.h" |
| 20 #include "third_party/WebKit/public/platform/WebVector.h" | 21 #include "third_party/WebKit/public/platform/WebVector.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "ui/base/clipboard/clipboard.h" | 23 #include "ui/base/clipboard/clipboard.h" |
| 23 #include "ui/base/clipboard/custom_data_helper.h" | 24 #include "ui/base/clipboard/custom_data_helper.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
| 26 #include "webkit/renderer/clipboard_utils.h" | |
| 27 | 27 |
| 28 using WebKit::WebClipboard; | 28 using WebKit::WebClipboard; |
| 29 using WebKit::WebData; | 29 using WebKit::WebData; |
| 30 using WebKit::WebDragData; | 30 using WebKit::WebDragData; |
| 31 using WebKit::WebImage; | 31 using WebKit::WebImage; |
| 32 using WebKit::WebString; | 32 using WebKit::WebString; |
| 33 using WebKit::WebURL; | 33 using WebKit::WebURL; |
| 34 using WebKit::WebVector; | 34 using WebKit::WebVector; |
| 35 | 35 |
| 36 namespace content { | 36 namespace content { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 void WebClipboardImpl::writePlainText(const WebString& plain_text) { | 169 void WebClipboardImpl::writePlainText(const WebString& plain_text) { |
| 170 ScopedClipboardWriterGlue scw(client_); | 170 ScopedClipboardWriterGlue scw(client_); |
| 171 scw.WriteText(plain_text); | 171 scw.WriteText(plain_text); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { | 174 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { |
| 175 ScopedClipboardWriterGlue scw(client_); | 175 ScopedClipboardWriterGlue scw(client_); |
| 176 | 176 |
| 177 scw.WriteBookmark(title, url.spec()); | 177 scw.WriteBookmark(title, url.spec()); |
| 178 scw.WriteHTML(UTF8ToUTF16(webkit_clipboard::URLToMarkup(url, title)), | 178 scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), std::string()); |
| 179 std::string()); | |
| 180 scw.WriteText(UTF8ToUTF16(std::string(url.spec()))); | 179 scw.WriteText(UTF8ToUTF16(std::string(url.spec()))); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void WebClipboardImpl::writeImage( | 182 void WebClipboardImpl::writeImage(const WebImage& image, |
| 184 const WebImage& image, const WebURL& url, const WebString& title) { | 183 const WebURL& url, |
| 184 const WebString& title) { |
| 185 ScopedClipboardWriterGlue scw(client_); | 185 ScopedClipboardWriterGlue scw(client_); |
| 186 | 186 |
| 187 if (!image.isNull()) { | 187 if (!image.isNull()) { |
| 188 const SkBitmap& bitmap = image.getSkBitmap(); | 188 const SkBitmap& bitmap = image.getSkBitmap(); |
| 189 SkAutoLockPixels locked(bitmap); | 189 SkAutoLockPixels locked(bitmap); |
| 190 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); | 190 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (!url.isEmpty()) { | 193 if (!url.isEmpty()) { |
| 194 scw.WriteBookmark(title, url.spec()); | 194 scw.WriteBookmark(title, url.spec()); |
| 195 #if !defined(OS_MACOSX) | 195 #if !defined(OS_MACOSX) |
| 196 // When writing the image, we also write the image markup so that pasting | 196 // When writing the image, we also write the image markup so that pasting |
| 197 // into rich text editors, such as Gmail, reveals the image. We also don't | 197 // into rich text editors, such as Gmail, reveals the image. We also don't |
| 198 // want to call writeText(), since some applications (WordPad) don't pick | 198 // want to call writeText(), since some applications (WordPad) don't pick |
| 199 // the image if there is also a text format on the clipboard. | 199 // the image if there is also a text format on the clipboard. |
| 200 // We also don't want to write HTML on a Mac, since Mail.app prefers to use | 200 // We also don't want to write HTML on a Mac, since Mail.app prefers to use |
| 201 // the image markup over attaching the actual image. See | 201 // the image markup over attaching the actual image. See |
| 202 // http://crbug.com/33016 for details. | 202 // http://crbug.com/33016 for details. |
| 203 scw.WriteHTML(UTF8ToUTF16(webkit_clipboard::URLToImageMarkup(url, title)), | 203 scw.WriteHTML(UTF8ToUTF16(URLToImageMarkup(url, title)), std::string()); |
| 204 std::string()); | |
| 205 #endif | 204 #endif |
| 206 } | 205 } |
| 207 } | 206 } |
| 208 | 207 |
| 209 void WebClipboardImpl::writeDataObject(const WebDragData& data) { | 208 void WebClipboardImpl::writeDataObject(const WebDragData& data) { |
| 210 ScopedClipboardWriterGlue scw(client_); | 209 ScopedClipboardWriterGlue scw(client_); |
| 211 | 210 |
| 212 const DropData& data_object = DropDataBuilder::Build(data); | 211 const DropData& data_object = DropDataBuilder::Build(data); |
| 213 // TODO(dcheng): Properly support text/uri-list here. | 212 // TODO(dcheng): Properly support text/uri-list here. |
| 214 if (!data_object.text.is_null()) | 213 if (!data_object.text.is_null()) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 245 #endif | 244 #endif |
| 246 #endif | 245 #endif |
| 247 default: | 246 default: |
| 248 NOTREACHED(); | 247 NOTREACHED(); |
| 249 return false; | 248 return false; |
| 250 } | 249 } |
| 251 return true; | 250 return true; |
| 252 } | 251 } |
| 253 | 252 |
| 254 } // namespace content | 253 } // namespace content |
| 255 | |
| OLD | NEW |