| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/glue/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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 void WebClipboardImpl::writePlainText(const WebString& plain_text) { | 195 void WebClipboardImpl::writePlainText(const WebString& plain_text) { |
| 196 ScopedClipboardWriterGlue scw(client_); | 196 ScopedClipboardWriterGlue scw(client_); |
| 197 scw.WriteText(plain_text); | 197 scw.WriteText(plain_text); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { | 200 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { |
| 201 ScopedClipboardWriterGlue scw(client_); | 201 ScopedClipboardWriterGlue scw(client_); |
| 202 | 202 |
| 203 scw.WriteBookmark(title, url.spec()); | 203 scw.WriteBookmark(title, url.spec()); |
| 204 scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), ""); | 204 scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), std::string()); |
| 205 scw.WriteText(UTF8ToUTF16(std::string(url.spec()))); | 205 scw.WriteText(UTF8ToUTF16(std::string(url.spec()))); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void WebClipboardImpl::writeImage( | 208 void WebClipboardImpl::writeImage( |
| 209 const WebImage& image, const WebURL& url, const WebString& title) { | 209 const WebImage& image, const WebURL& url, const WebString& title) { |
| 210 ScopedClipboardWriterGlue scw(client_); | 210 ScopedClipboardWriterGlue scw(client_); |
| 211 | 211 |
| 212 if (!image.isNull()) { | 212 if (!image.isNull()) { |
| 213 const SkBitmap& bitmap = image.getSkBitmap(); | 213 const SkBitmap& bitmap = image.getSkBitmap(); |
| 214 SkAutoLockPixels locked(bitmap); | 214 SkAutoLockPixels locked(bitmap); |
| 215 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); | 215 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 if (!url.isEmpty()) { | 218 if (!url.isEmpty()) { |
| 219 scw.WriteBookmark(title, url.spec()); | 219 scw.WriteBookmark(title, url.spec()); |
| 220 #if !defined(OS_MACOSX) | 220 #if !defined(OS_MACOSX) |
| 221 // When writing the image, we also write the image markup so that pasting | 221 // 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 | 222 // 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 | 223 // want to call writeText(), since some applications (WordPad) don't pick |
| 224 // the image if there is also a text format on the clipboard. | 224 // 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 | 225 // 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 | 226 // the image markup over attaching the actual image. See |
| 227 // http://crbug.com/33016 for details. | 227 // http://crbug.com/33016 for details. |
| 228 scw.WriteHTML(UTF8ToUTF16(URLToImageMarkup(url, title)), ""); | 228 scw.WriteHTML(UTF8ToUTF16(URLToImageMarkup(url, title)), std::string()); |
| 229 #endif | 229 #endif |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 void WebClipboardImpl::writeDataObject(const WebDragData& data) { | 233 void WebClipboardImpl::writeDataObject(const WebDragData& data) { |
| 234 ScopedClipboardWriterGlue scw(client_); | 234 ScopedClipboardWriterGlue scw(client_); |
| 235 | 235 |
| 236 WebDropData data_object(data); | 236 WebDropData data_object(data); |
| 237 // TODO(dcheng): Properly support text/uri-list here. | 237 // TODO(dcheng): Properly support text/uri-list here. |
| 238 if (!data_object.text.is_null()) | 238 if (!data_object.text.is_null()) |
| 239 scw.WriteText(data_object.text.string()); | 239 scw.WriteText(data_object.text.string()); |
| 240 if (!data_object.html.is_null()) | 240 if (!data_object.html.is_null()) |
| 241 scw.WriteHTML(data_object.html.string(), ""); | 241 scw.WriteHTML(data_object.html.string(), std::string()); |
| 242 // If there is no custom data, avoid calling WritePickledData. This ensures | 242 // If there is no custom data, avoid calling WritePickledData. This ensures |
| 243 // that ScopedClipboardWriterGlue's dtor remains a no-op if the page didn't | 243 // that ScopedClipboardWriterGlue's dtor remains a no-op if the page didn't |
| 244 // modify the DataTransfer object, which is important to avoid stomping on | 244 // modify the DataTransfer object, which is important to avoid stomping on |
| 245 // any clipboard contents written by extension functions such as | 245 // any clipboard contents written by extension functions such as |
| 246 // chrome.bookmarkManagerPrivate.copy. | 246 // chrome.bookmarkManagerPrivate.copy. |
| 247 if (!data_object.custom_data.empty()) { | 247 if (!data_object.custom_data.empty()) { |
| 248 Pickle pickle; | 248 Pickle pickle; |
| 249 ui::WriteCustomDataToPickle(data_object.custom_data, &pickle); | 249 ui::WriteCustomDataToPickle(data_object.custom_data, &pickle); |
| 250 scw.WritePickledData(pickle, ui::Clipboard::GetWebCustomDataFormatType()); | 250 scw.WritePickledData(pickle, ui::Clipboard::GetWebCustomDataFormatType()); |
| 251 } | 251 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 269 #endif | 269 #endif |
| 270 #endif | 270 #endif |
| 271 default: | 271 default: |
| 272 NOTREACHED(); | 272 NOTREACHED(); |
| 273 return false; | 273 return false; |
| 274 } | 274 } |
| 275 return true; | 275 return true; |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace webkit_glue | 278 } // namespace webkit_glue |
| OLD | NEW |