| 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/common/clipboard_message_enums.h" |
| 11 #include "content/public/common/drop_data.h" | 12 #include "content/public/common/drop_data.h" |
| 12 #include "content/renderer/clipboard_utils.h" | 13 #include "content/renderer/clipboard_utils.h" |
| 13 #include "content/renderer/drop_data_builder.h" | 14 #include "content/renderer/drop_data_builder.h" |
| 14 #include "content/renderer/scoped_clipboard_writer_glue.h" | 15 #include "content/renderer/scoped_clipboard_writer_glue.h" |
| 15 #include "third_party/WebKit/public/platform/WebData.h" | 16 #include "third_party/WebKit/public/platform/WebData.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" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { | 53 bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { |
| 53 ui::ClipboardType clipboard_type = ui::CLIPBOARD_TYPE_COPY_PASTE; | 54 ui::ClipboardType clipboard_type = ui::CLIPBOARD_TYPE_COPY_PASTE; |
| 54 | 55 |
| 55 if (!ConvertBufferType(buffer, &clipboard_type)) | 56 if (!ConvertBufferType(buffer, &clipboard_type)) |
| 56 return false; | 57 return false; |
| 57 | 58 |
| 58 switch (format) { | 59 switch (format) { |
| 59 case FormatPlainText: | 60 case FormatPlainText: |
| 60 return client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), | 61 return client_->IsFormatAvailable(kClipboardFormatPlaintext, |
| 61 clipboard_type) || | 62 clipboard_type); |
| 62 client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), | |
| 63 clipboard_type); | |
| 64 case FormatHTML: | 63 case FormatHTML: |
| 65 return client_->IsFormatAvailable(ui::Clipboard::GetHtmlFormatType(), | 64 return client_->IsFormatAvailable(kClipboardFormatHTML, clipboard_type); |
| 65 case FormatSmartPaste: |
| 66 return client_->IsFormatAvailable(kClipboardFormatSmartPaste, |
| 66 clipboard_type); | 67 clipboard_type); |
| 67 case FormatSmartPaste: | |
| 68 return client_->IsFormatAvailable( | |
| 69 ui::Clipboard::GetWebKitSmartPasteFormatType(), clipboard_type); | |
| 70 case FormatBookmark: | 68 case FormatBookmark: |
| 71 #if defined(OS_WIN) || defined(OS_MACOSX) | 69 return client_->IsFormatAvailable(kClipboardFormatBookmark, |
| 72 return client_->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), | |
| 73 clipboard_type); | 70 clipboard_type); |
| 74 #endif | |
| 75 default: | 71 default: |
| 76 NOTREACHED(); | 72 NOTREACHED(); |
| 77 } | 73 } |
| 78 | 74 |
| 79 return false; | 75 return false; |
| 80 } | 76 } |
| 81 | 77 |
| 82 WebVector<WebString> WebClipboardImpl::readAvailableTypes( | 78 WebVector<WebString> WebClipboardImpl::readAvailableTypes( |
| 83 Buffer buffer, bool* contains_filenames) { | 79 Buffer buffer, bool* contains_filenames) { |
| 84 ui::ClipboardType clipboard_type; | 80 ui::ClipboardType clipboard_type; |
| 85 std::vector<base::string16> types; | 81 std::vector<base::string16> types; |
| 86 if (ConvertBufferType(buffer, &clipboard_type)) { | 82 if (ConvertBufferType(buffer, &clipboard_type)) { |
| 87 client_->ReadAvailableTypes(clipboard_type, &types, contains_filenames); | 83 client_->ReadAvailableTypes(clipboard_type, &types, contains_filenames); |
| 88 } | 84 } |
| 89 return types; | 85 return types; |
| 90 } | 86 } |
| 91 | 87 |
| 92 WebString WebClipboardImpl::readPlainText(Buffer buffer) { | 88 WebString WebClipboardImpl::readPlainText(Buffer buffer) { |
| 93 ui::ClipboardType clipboard_type; | 89 ui::ClipboardType clipboard_type; |
| 94 if (!ConvertBufferType(buffer, &clipboard_type)) | 90 if (!ConvertBufferType(buffer, &clipboard_type)) |
| 95 return WebString(); | 91 return WebString(); |
| 96 | 92 |
| 97 if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), | 93 base::string16 text; |
| 98 clipboard_type)) { | 94 client_->ReadText(clipboard_type, &text); |
| 99 base::string16 text; | 95 return text; |
| 100 client_->ReadText(clipboard_type, &text); | |
| 101 if (!text.empty()) | |
| 102 return text; | |
| 103 } | |
| 104 | |
| 105 if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), | |
| 106 clipboard_type)) { | |
| 107 std::string text; | |
| 108 client_->ReadAsciiText(clipboard_type, &text); | |
| 109 if (!text.empty()) | |
| 110 return base::ASCIIToUTF16(text); | |
| 111 } | |
| 112 | |
| 113 return WebString(); | |
| 114 } | 96 } |
| 115 | 97 |
| 116 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url, | 98 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url, |
| 117 unsigned* fragment_start, | 99 unsigned* fragment_start, |
| 118 unsigned* fragment_end) { | 100 unsigned* fragment_end) { |
| 119 ui::ClipboardType clipboard_type; | 101 ui::ClipboardType clipboard_type; |
| 120 if (!ConvertBufferType(buffer, &clipboard_type)) | 102 if (!ConvertBufferType(buffer, &clipboard_type)) |
| 121 return WebString(); | 103 return WebString(); |
| 122 | 104 |
| 123 base::string16 html_stdstr; | 105 base::string16 html_stdstr; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 #endif | 214 #endif |
| 233 #endif | 215 #endif |
| 234 default: | 216 default: |
| 235 NOTREACHED(); | 217 NOTREACHED(); |
| 236 return false; | 218 return false; |
| 237 } | 219 } |
| 238 return true; | 220 return true; |
| 239 } | 221 } |
| 240 | 222 |
| 241 } // namespace content | 223 } // namespace content |
| OLD | NEW |