| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/views/mus/clipboard_mus.h" | 5 #include "ui/views/mus/clipboard_mus.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 ClipboardMus::~ClipboardMus() {} | 47 ClipboardMus::~ClipboardMus() {} |
| 48 | 48 |
| 49 void ClipboardMus::Init(service_manager::Connector* connector) { | 49 void ClipboardMus::Init(service_manager::Connector* connector) { |
| 50 connector->ConnectToInterface(ui::mojom::kServiceName, &clipboard_); | 50 connector->ConnectToInterface(ui::mojom::kServiceName, &clipboard_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // TODO(erg): This isn't optimal. It would be better to move the entire | 53 // TODO(erg): This isn't optimal. It would be better to move the entire |
| 54 // FormatType system to mime types throughout chrome, but that's a very large | 54 // FormatType system to mime types throughout chrome, but that's a very large |
| 55 // change. | 55 // change. |
| 56 mojo::String ClipboardMus::GetMimeTypeFor(const FormatType& format) { | 56 std::string ClipboardMus::GetMimeTypeFor(const FormatType& format) { |
| 57 if (format.Equals(GetUrlFormatType()) || format.Equals(GetUrlWFormatType())) | 57 if (format.Equals(GetUrlFormatType()) || format.Equals(GetUrlWFormatType())) |
| 58 return ui::mojom::kMimeTypeURIList; | 58 return ui::mojom::kMimeTypeURIList; |
| 59 if (format.Equals(GetMozUrlFormatType())) | 59 if (format.Equals(GetMozUrlFormatType())) |
| 60 return ui::mojom::kMimeTypeMozillaURL; | 60 return ui::mojom::kMimeTypeMozillaURL; |
| 61 if (format.Equals(GetPlainTextFormatType()) || | 61 if (format.Equals(GetPlainTextFormatType()) || |
| 62 format.Equals(GetPlainTextWFormatType())) { | 62 format.Equals(GetPlainTextWFormatType())) { |
| 63 return ui::mojom::kMimeTypeText; | 63 return ui::mojom::kMimeTypeText; |
| 64 } | 64 } |
| 65 if (format.Equals(GetHtmlFormatType())) | 65 if (format.Equals(GetHtmlFormatType())) |
| 66 return ui::mojom::kMimeTypeHTML; | 66 return ui::mojom::kMimeTypeHTML; |
| 67 if (format.Equals(GetRtfFormatType())) | 67 if (format.Equals(GetRtfFormatType())) |
| 68 return ui::mojom::kMimeTypeRTF; | 68 return ui::mojom::kMimeTypeRTF; |
| 69 if (format.Equals(GetBitmapFormatType())) | 69 if (format.Equals(GetBitmapFormatType())) |
| 70 return ui::mojom::kMimeTypePNG; | 70 return ui::mojom::kMimeTypePNG; |
| 71 if (format.Equals(GetWebKitSmartPasteFormatType())) | 71 if (format.Equals(GetWebKitSmartPasteFormatType())) |
| 72 return kMimeTypeWebkitSmartPaste; | 72 return kMimeTypeWebkitSmartPaste; |
| 73 if (format.Equals(GetWebCustomDataFormatType())) | 73 if (format.Equals(GetWebCustomDataFormatType())) |
| 74 return kMimeTypeWebCustomData; | 74 return kMimeTypeWebCustomData; |
| 75 if (format.Equals(GetPepperCustomDataFormatType())) | 75 if (format.Equals(GetPepperCustomDataFormatType())) |
| 76 return kMimeTypePepperCustomData; | 76 return kMimeTypePepperCustomData; |
| 77 | 77 |
| 78 // TODO(erg): This isn't optimal, but it's the best we can do. On windows, | 78 // TODO(erg): This isn't optimal, but it's the best we can do. On windows, |
| 79 // this will return strings that aren't MIME types, though they'll be | 79 // this will return strings that aren't MIME types, though they'll be |
| 80 // unique and should be serializable on the other side of the mojo | 80 // unique and should be serializable on the other side of the mojo |
| 81 // connection. | 81 // connection. |
| 82 return format.Serialize(); | 82 return format.Serialize(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool ClipboardMus::HasMimeType(const mojo::Array<mojo::String>& available_types, | 85 bool ClipboardMus::HasMimeType(const std::vector<std::string>& available_types, |
| 86 const std::string& type) const { | 86 const std::string& type) const { |
| 87 return base::ContainsValue(available_types, type); | 87 return base::ContainsValue(available_types, type); |
| 88 } | 88 } |
| 89 | 89 |
| 90 uint64_t ClipboardMus::GetSequenceNumber(ui::ClipboardType type) const { | 90 uint64_t ClipboardMus::GetSequenceNumber(ui::ClipboardType type) const { |
| 91 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 91 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 92 uint64_t sequence_number = 0; | 92 uint64_t sequence_number = 0; |
| 93 clipboard_->GetSequenceNumber(GetType(type), &sequence_number); | 93 clipboard_->GetSequenceNumber(GetType(type), &sequence_number); |
| 94 return sequence_number; | 94 return sequence_number; |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool ClipboardMus::IsFormatAvailable(const FormatType& format, | 97 bool ClipboardMus::IsFormatAvailable(const FormatType& format, |
| 98 ui::ClipboardType type) const { | 98 ui::ClipboardType type) const { |
| 99 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 99 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 100 | 100 |
| 101 uint64_t sequence_number = 0; | 101 uint64_t sequence_number = 0; |
| 102 mojo::Array<mojo::String> available_types; | 102 std::vector<std::string> available_types; |
| 103 clipboard_->GetAvailableMimeTypes(GetType(type), &sequence_number, | 103 clipboard_->GetAvailableMimeTypes(GetType(type), &sequence_number, |
| 104 &available_types); | 104 &available_types); |
| 105 | 105 |
| 106 mojo::String format_in_mime = GetMimeTypeFor(format); | 106 std::string format_in_mime = GetMimeTypeFor(format); |
| 107 return base::ContainsValue(available_types, format_in_mime); | 107 return base::ContainsValue(available_types, format_in_mime); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void ClipboardMus::Clear(ui::ClipboardType type) { | 110 void ClipboardMus::Clear(ui::ClipboardType type) { |
| 111 // Sends the data to mus server. | 111 // Sends the data to mus server. |
| 112 uint64_t sequence_number = 0; | 112 uint64_t sequence_number = 0; |
| 113 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 113 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 114 clipboard_->WriteClipboardData(GetType(type), nullptr, | 114 clipboard_->WriteClipboardData(GetType(type), base::nullopt, |
| 115 &sequence_number); | 115 &sequence_number); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void ClipboardMus::ReadAvailableTypes(ui::ClipboardType type, | 118 void ClipboardMus::ReadAvailableTypes(ui::ClipboardType type, |
| 119 std::vector<base::string16>* types, | 119 std::vector<base::string16>* types, |
| 120 bool* contains_filenames) const { | 120 bool* contains_filenames) const { |
| 121 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 121 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 122 | 122 |
| 123 uint64_t sequence_number = 0; | 123 uint64_t sequence_number = 0; |
| 124 mojo::Array<mojo::String> available_types; | 124 std::vector<std::string> available_types; |
| 125 clipboard_->GetAvailableMimeTypes(GetType(type), &sequence_number, | 125 clipboard_->GetAvailableMimeTypes(GetType(type), &sequence_number, |
| 126 &available_types); | 126 &available_types); |
| 127 | 127 |
| 128 types->clear(); | 128 types->clear(); |
| 129 if (HasMimeType(available_types, ui::mojom::kMimeTypeText)) | 129 if (HasMimeType(available_types, ui::mojom::kMimeTypeText)) |
| 130 types->push_back(base::UTF8ToUTF16(ui::mojom::kMimeTypeText)); | 130 types->push_back(base::UTF8ToUTF16(ui::mojom::kMimeTypeText)); |
| 131 if (HasMimeType(available_types, ui::mojom::kMimeTypeHTML)) | 131 if (HasMimeType(available_types, ui::mojom::kMimeTypeHTML)) |
| 132 types->push_back(base::UTF8ToUTF16(ui::mojom::kMimeTypeHTML)); | 132 types->push_back(base::UTF8ToUTF16(ui::mojom::kMimeTypeHTML)); |
| 133 if (HasMimeType(available_types, ui::mojom::kMimeTypeRTF)) | 133 if (HasMimeType(available_types, ui::mojom::kMimeTypeRTF)) |
| 134 types->push_back(base::UTF8ToUTF16(ui::mojom::kMimeTypeRTF)); | 134 types->push_back(base::UTF8ToUTF16(ui::mojom::kMimeTypeRTF)); |
| 135 if (HasMimeType(available_types, ui::mojom::kMimeTypePNG)) | 135 if (HasMimeType(available_types, ui::mojom::kMimeTypePNG)) |
| 136 types->push_back(base::UTF8ToUTF16(ui::mojom::kMimeTypePNG)); | 136 types->push_back(base::UTF8ToUTF16(ui::mojom::kMimeTypePNG)); |
| 137 | 137 |
| 138 if (HasMimeType(available_types, kMimeTypeWebCustomData)) { | 138 if (HasMimeType(available_types, kMimeTypeWebCustomData)) { |
| 139 mojo::Array<uint8_t> custom_data; | 139 base::Optional<std::vector<uint8_t>> custom_data; |
| 140 uint64_t sequence_number = 0; | 140 uint64_t sequence_number = 0; |
| 141 if (clipboard_->ReadClipboardData(GetType(type), kMimeTypeWebCustomData, | 141 if (clipboard_->ReadClipboardData(GetType(type), kMimeTypeWebCustomData, |
| 142 &sequence_number, &custom_data)) { | 142 &sequence_number, &custom_data) && |
| 143 ui::ReadCustomDataTypes(&custom_data.front(), custom_data.size(), types); | 143 custom_data.has_value()) { |
| 144 ui::ReadCustomDataTypes(&custom_data->front(), custom_data->size(), |
| 145 types); |
| 144 } | 146 } |
| 145 } | 147 } |
| 146 | 148 |
| 147 *contains_filenames = false; | 149 *contains_filenames = false; |
| 148 } | 150 } |
| 149 | 151 |
| 150 void ClipboardMus::ReadText(ui::ClipboardType type, | 152 void ClipboardMus::ReadText(ui::ClipboardType type, |
| 151 base::string16* result) const { | 153 base::string16* result) const { |
| 152 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 154 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 153 mojo::Array<uint8_t> text_data; | 155 base::Optional<std::vector<uint8_t>> text_data; |
| 154 uint64_t sequence_number = 0; | 156 uint64_t sequence_number = 0; |
| 155 if (clipboard_->ReadClipboardData(GetType(type), | 157 if (clipboard_->ReadClipboardData(GetType(type), ui::mojom::kMimeTypeText, |
| 156 mojo::String(ui::mojom::kMimeTypeText), | |
| 157 &sequence_number, &text_data)) { | 158 &sequence_number, &text_data)) { |
| 158 std::string text = text_data.To<std::string>(); | 159 std::string text = |
| 160 mojo::Array<uint8_t>(std::move(text_data)).To<std::string>(); |
| 159 *result = base::UTF8ToUTF16(text); | 161 *result = base::UTF8ToUTF16(text); |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 163 void ClipboardMus::ReadAsciiText(ui::ClipboardType type, | 165 void ClipboardMus::ReadAsciiText(ui::ClipboardType type, |
| 164 std::string* result) const { | 166 std::string* result) const { |
| 165 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 167 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 166 mojo::Array<uint8_t> text_data; | 168 base::Optional<std::vector<uint8_t>> text_data; |
| 167 uint64_t sequence_number = 0; | 169 uint64_t sequence_number = 0; |
| 168 if (clipboard_->ReadClipboardData(GetType(type), | 170 if (clipboard_->ReadClipboardData(GetType(type), ui::mojom::kMimeTypeText, |
| 169 mojo::String(ui::mojom::kMimeTypeText), | |
| 170 &sequence_number, &text_data)) { | 171 &sequence_number, &text_data)) { |
| 171 *result = text_data.To<std::string>(); | 172 *result = mojo::Array<uint8_t>(std::move(text_data)).To<std::string>(); |
| 172 } | 173 } |
| 173 } | 174 } |
| 174 | 175 |
| 175 void ClipboardMus::ReadHTML(ui::ClipboardType type, | 176 void ClipboardMus::ReadHTML(ui::ClipboardType type, |
| 176 base::string16* markup, | 177 base::string16* markup, |
| 177 std::string* src_url, | 178 std::string* src_url, |
| 178 uint32_t* fragment_start, | 179 uint32_t* fragment_start, |
| 179 uint32_t* fragment_end) const { | 180 uint32_t* fragment_end) const { |
| 180 markup->clear(); | 181 markup->clear(); |
| 181 if (src_url) | 182 if (src_url) |
| 182 src_url->clear(); | 183 src_url->clear(); |
| 183 *fragment_start = 0; | 184 *fragment_start = 0; |
| 184 *fragment_end = 0; | 185 *fragment_end = 0; |
| 185 | 186 |
| 186 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 187 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 187 mojo::Array<uint8_t> html_data; | 188 base::Optional<std::vector<uint8_t>> html_data; |
| 188 uint64_t sequence_number = 0; | 189 uint64_t sequence_number = 0; |
| 189 if (clipboard_->ReadClipboardData(GetType(type), | 190 if (clipboard_->ReadClipboardData(GetType(type), ui::mojom::kMimeTypeHTML, |
| 190 mojo::String(ui::mojom::kMimeTypeHTML), | |
| 191 &sequence_number, &html_data)) { | 191 &sequence_number, &html_data)) { |
| 192 *markup = base::UTF8ToUTF16(html_data.To<std::string>()); | 192 *markup = base::UTF8ToUTF16( |
| 193 mojo::Array<uint8_t>(std::move(html_data)).To<std::string>()); |
| 193 *fragment_end = static_cast<uint32_t>(markup->length()); | 194 *fragment_end = static_cast<uint32_t>(markup->length()); |
| 194 | 195 |
| 195 // We only bother fetching the source url if we were the ones who wrote | 196 // We only bother fetching the source url if we were the ones who wrote |
| 196 // this html data to the clipboard. | 197 // this html data to the clipboard. |
| 197 mojo::Array<uint8_t> url_data; | 198 base::Optional<std::vector<uint8_t>> url_data; |
| 198 if (clipboard_->ReadClipboardData(GetType(type), kInternalSourceURL, | 199 if (clipboard_->ReadClipboardData(GetType(type), kInternalSourceURL, |
| 199 &sequence_number, &url_data)) { | 200 &sequence_number, &url_data)) { |
| 200 *src_url = url_data.To<std::string>(); | 201 *src_url = mojo::Array<uint8_t>(std::move(url_data)).To<std::string>(); |
| 201 } | 202 } |
| 202 } | 203 } |
| 203 } | 204 } |
| 204 | 205 |
| 205 void ClipboardMus::ReadRTF(ui::ClipboardType type, std::string* result) const { | 206 void ClipboardMus::ReadRTF(ui::ClipboardType type, std::string* result) const { |
| 206 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 207 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 207 mojo::Array<uint8_t> rtf_data; | 208 base::Optional<std::vector<uint8_t>> rtf_data; |
| 208 uint64_t sequence_number = 0; | 209 uint64_t sequence_number = 0; |
| 209 if (clipboard_->ReadClipboardData(GetType(type), | 210 if (clipboard_->ReadClipboardData(GetType(type), ui::mojom::kMimeTypeRTF, |
| 210 mojo::String(ui::mojom::kMimeTypeRTF), | |
| 211 &sequence_number, &rtf_data)) { | 211 &sequence_number, &rtf_data)) { |
| 212 *result = rtf_data.To<std::string>(); | 212 *result = mojo::Array<uint8_t>(std::move(rtf_data)).To<std::string>(); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 SkBitmap ClipboardMus::ReadImage(ui::ClipboardType type) const { | 216 SkBitmap ClipboardMus::ReadImage(ui::ClipboardType type) const { |
| 217 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 217 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 218 mojo::Array<uint8_t> data; | 218 base::Optional<std::vector<uint8_t>> data; |
| 219 uint64_t sequence_number = 0; | 219 uint64_t sequence_number = 0; |
| 220 if (clipboard_->ReadClipboardData(GetType(type), | 220 if (clipboard_->ReadClipboardData(GetType(type), ui::mojom::kMimeTypePNG, |
| 221 mojo::String(ui::mojom::kMimeTypePNG), | 221 &sequence_number, &data) && |
| 222 &sequence_number, &data)) { | 222 data.has_value()) { |
| 223 SkBitmap bitmap; | 223 SkBitmap bitmap; |
| 224 if (gfx::PNGCodec::Decode(&data.front(), data.size(), &bitmap)) | 224 if (gfx::PNGCodec::Decode(&data->front(), data->size(), &bitmap)) |
| 225 return SkBitmap(bitmap); | 225 return SkBitmap(bitmap); |
| 226 } | 226 } |
| 227 | 227 |
| 228 return SkBitmap(); | 228 return SkBitmap(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void ClipboardMus::ReadCustomData(ui::ClipboardType clipboard_type, | 231 void ClipboardMus::ReadCustomData(ui::ClipboardType clipboard_type, |
| 232 const base::string16& type, | 232 const base::string16& type, |
| 233 base::string16* result) const { | 233 base::string16* result) const { |
| 234 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 234 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 235 mojo::Array<uint8_t> custom_data; | 235 base::Optional<std::vector<uint8_t>> custom_data; |
| 236 uint64_t sequence_number = 0; | 236 uint64_t sequence_number = 0; |
| 237 if (clipboard_->ReadClipboardData(GetType(clipboard_type), | 237 if (clipboard_->ReadClipboardData(GetType(clipboard_type), |
| 238 mojo::String(kMimeTypeWebCustomData), | 238 kMimeTypeWebCustomData, &sequence_number, |
| 239 &sequence_number, &custom_data)) { | 239 &custom_data) && |
| 240 ui::ReadCustomDataForType(&custom_data.front(), custom_data.size(), type, | 240 custom_data.has_value()) { |
| 241 ui::ReadCustomDataForType(&custom_data->front(), custom_data->size(), type, |
| 241 result); | 242 result); |
| 242 } | 243 } |
| 243 } | 244 } |
| 244 | 245 |
| 245 void ClipboardMus::ReadBookmark(base::string16* title, std::string* url) const { | 246 void ClipboardMus::ReadBookmark(base::string16* title, std::string* url) const { |
| 246 // TODO(erg): This is NOTIMPLEMENTED() on all linux platforms? | 247 // TODO(erg): This is NOTIMPLEMENTED() on all linux platforms? |
| 247 NOTIMPLEMENTED(); | 248 NOTIMPLEMENTED(); |
| 248 } | 249 } |
| 249 | 250 |
| 250 void ClipboardMus::ReadData(const FormatType& format, | 251 void ClipboardMus::ReadData(const FormatType& format, |
| 251 std::string* result) const { | 252 std::string* result) const { |
| 252 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 253 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 253 mojo::Array<uint8_t> data; | 254 base::Optional<std::vector<uint8_t>> data; |
| 254 uint64_t sequence_number = 0; | 255 uint64_t sequence_number = 0; |
| 255 if (clipboard_->ReadClipboardData(ui::mojom::Clipboard::Type::COPY_PASTE, | 256 if (clipboard_->ReadClipboardData(ui::mojom::Clipboard::Type::COPY_PASTE, |
| 256 GetMimeTypeFor(format), &sequence_number, | 257 GetMimeTypeFor(format), &sequence_number, |
| 257 &data)) { | 258 &data)) { |
| 258 *result = data.To<std::string>(); | 259 *result = mojo::Array<uint8_t>(std::move(data)).To<std::string>(); |
| 259 } | 260 } |
| 260 } | 261 } |
| 261 | 262 |
| 262 void ClipboardMus::WriteObjects(ui::ClipboardType type, | 263 void ClipboardMus::WriteObjects(ui::ClipboardType type, |
| 263 const ObjectMap& objects) { | 264 const ObjectMap& objects) { |
| 264 current_clipboard_ = | 265 current_clipboard_.emplace(); |
| 265 base::MakeUnique<mojo::Map<mojo::String, mojo::Array<uint8_t>>>(); | |
| 266 for (const auto& p : objects) | 266 for (const auto& p : objects) |
| 267 DispatchObject(static_cast<ObjectType>(p.first), p.second); | 267 DispatchObject(static_cast<ObjectType>(p.first), p.second); |
| 268 | 268 |
| 269 // Sends the data to mus server. | 269 // Sends the data to mus server. |
| 270 uint64_t sequence_number = 0; | 270 uint64_t sequence_number = 0; |
| 271 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 271 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 272 clipboard_->WriteClipboardData(GetType(type), std::move(*current_clipboard_), | 272 clipboard_->WriteClipboardData(GetType(type), std::move(current_clipboard_), |
| 273 &sequence_number); | 273 &sequence_number); |
| 274 current_clipboard_.reset(); | |
| 275 } | 274 } |
| 276 | 275 |
| 277 void ClipboardMus::WriteText(const char* text_data, size_t text_len) { | 276 void ClipboardMus::WriteText(const char* text_data, size_t text_len) { |
| 278 DCHECK(current_clipboard_); | 277 DCHECK(current_clipboard_); |
| 279 current_clipboard_->insert( | 278 current_clipboard_.value()[ui::mojom::kMimeTypeText] = |
| 280 ui::mojom::kMimeTypeText, | 279 mojo::Array<uint8_t>::From(base::StringPiece(text_data, text_len)) |
| 281 mojo::Array<uint8_t>::From(base::StringPiece(text_data, text_len))); | 280 .PassStorage(); |
| 282 } | 281 } |
| 283 | 282 |
| 284 void ClipboardMus::WriteHTML(const char* markup_data, | 283 void ClipboardMus::WriteHTML(const char* markup_data, |
| 285 size_t markup_len, | 284 size_t markup_len, |
| 286 const char* url_data, | 285 const char* url_data, |
| 287 size_t url_len) { | 286 size_t url_len) { |
| 288 DCHECK(current_clipboard_); | 287 DCHECK(current_clipboard_); |
| 289 current_clipboard_->insert( | 288 current_clipboard_.value()[ui::mojom::kMimeTypeHTML] = |
| 290 ui::mojom::kMimeTypeHTML, | 289 mojo::Array<uint8_t>::From(base::StringPiece(markup_data, markup_len)) |
| 291 mojo::Array<uint8_t>::From(base::StringPiece(markup_data, markup_len))); | 290 .PassStorage(); |
| 292 if (url_len > 0) { | 291 if (url_len > 0) { |
| 293 current_clipboard_->insert( | 292 current_clipboard_.value()[kInternalSourceURL] = |
| 294 kInternalSourceURL, | 293 mojo::Array<uint8_t>::From(base::StringPiece(url_data, url_len)) |
| 295 mojo::Array<uint8_t>::From(base::StringPiece(url_data, url_len))); | 294 .PassStorage(); |
| 296 } | 295 } |
| 297 } | 296 } |
| 298 | 297 |
| 299 void ClipboardMus::WriteRTF(const char* rtf_data, size_t data_len) { | 298 void ClipboardMus::WriteRTF(const char* rtf_data, size_t data_len) { |
| 300 DCHECK(current_clipboard_); | 299 DCHECK(current_clipboard_); |
| 301 current_clipboard_->insert( | 300 current_clipboard_.value()[ui::mojom::kMimeTypeRTF] = |
| 302 ui::mojom::kMimeTypeRTF, | 301 mojo::Array<uint8_t>::From(base::StringPiece(rtf_data, data_len)) |
| 303 mojo::Array<uint8_t>::From(base::StringPiece(rtf_data, data_len))); | 302 .PassStorage(); |
| 304 } | 303 } |
| 305 | 304 |
| 306 void ClipboardMus::WriteBookmark(const char* title_data, | 305 void ClipboardMus::WriteBookmark(const char* title_data, |
| 307 size_t title_len, | 306 size_t title_len, |
| 308 const char* url_data, | 307 const char* url_data, |
| 309 size_t url_len) { | 308 size_t url_len) { |
| 310 // Writes a Mozilla url (UTF16: URL, newline, title) | 309 // Writes a Mozilla url (UTF16: URL, newline, title) |
| 311 base::string16 bookmark = | 310 base::string16 bookmark = |
| 312 base::UTF8ToUTF16(base::StringPiece(url_data, url_len)) + | 311 base::UTF8ToUTF16(base::StringPiece(url_data, url_len)) + |
| 313 base::ASCIIToUTF16("\n") + | 312 base::ASCIIToUTF16("\n") + |
| 314 base::UTF8ToUTF16(base::StringPiece(title_data, title_len)); | 313 base::UTF8ToUTF16(base::StringPiece(title_data, title_len)); |
| 315 | 314 |
| 316 DCHECK(current_clipboard_); | 315 DCHECK(current_clipboard_); |
| 317 current_clipboard_->insert(ui::mojom::kMimeTypeMozillaURL, | 316 current_clipboard_.value()[ui::mojom::kMimeTypeMozillaURL] = |
| 318 mojo::Array<uint8_t>::From(bookmark)); | 317 mojo::Array<uint8_t>::From(bookmark).PassStorage(); |
| 319 } | 318 } |
| 320 | 319 |
| 321 void ClipboardMus::WriteWebSmartPaste() { | 320 void ClipboardMus::WriteWebSmartPaste() { |
| 322 DCHECK(current_clipboard_); | 321 DCHECK(current_clipboard_); |
| 323 current_clipboard_->insert(kMimeTypeWebkitSmartPaste, mojo::Array<uint8_t>()); | 322 current_clipboard_.value()[kMimeTypeWebkitSmartPaste] = |
| 323 std::vector<uint8_t>(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void ClipboardMus::WriteBitmap(const SkBitmap& bitmap) { | 326 void ClipboardMus::WriteBitmap(const SkBitmap& bitmap) { |
| 327 DCHECK(current_clipboard_); | 327 DCHECK(current_clipboard_); |
| 328 // Encode the bitmap as a PNG for transport. | 328 // Encode the bitmap as a PNG for transport. |
| 329 std::vector<unsigned char> output; | 329 std::vector<unsigned char> output; |
| 330 if (gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, false, &output)) { | 330 if (gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, false, &output)) { |
| 331 current_clipboard_->insert(ui::mojom::kMimeTypePNG, | 331 current_clipboard_.value()[ui::mojom::kMimeTypePNG] = |
| 332 mojo::Array<uint8_t>::From(output)); | 332 mojo::Array<uint8_t>::From(output).PassStorage(); |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 | 335 |
| 336 void ClipboardMus::WriteData(const FormatType& format, | 336 void ClipboardMus::WriteData(const FormatType& format, |
| 337 const char* data_data, | 337 const char* data_data, |
| 338 size_t data_len) { | 338 size_t data_len) { |
| 339 DCHECK(current_clipboard_); | 339 DCHECK(current_clipboard_); |
| 340 current_clipboard_->insert( | 340 current_clipboard_.value()[GetMimeTypeFor(format)] = |
| 341 GetMimeTypeFor(format), | 341 mojo::Array<uint8_t>::From(base::StringPiece(data_data, data_len)) |
| 342 mojo::Array<uint8_t>::From(base::StringPiece(data_data, data_len))); | 342 .PassStorage(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 } // namespace views | 345 } // namespace views |
| OLD | NEW |