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 "ui/base/clipboard/clipboard.h" | 5 #include "ui/base/clipboard/clipboard.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 namespace { | 33 namespace { |
34 // Various formats we support. | 34 // Various formats we support. |
35 const char kPlainTextFormat[] = "text"; | 35 const char kPlainTextFormat[] = "text"; |
36 const char kHTMLFormat[] = "html"; | 36 const char kHTMLFormat[] = "html"; |
37 const char kRTFFormat[] = "rtf"; | 37 const char kRTFFormat[] = "rtf"; |
38 const char kBitmapFormat[] = "bitmap"; | 38 const char kBitmapFormat[] = "bitmap"; |
39 const char kWebKitSmartPasteFormat[] = "webkit_smart"; | 39 const char kWebKitSmartPasteFormat[] = "webkit_smart"; |
40 const char kBookmarkFormat[] = "bookmark"; | 40 const char kBookmarkFormat[] = "bookmark"; |
41 const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; | 41 const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; |
42 const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; | 42 const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; |
43 const char kSourceTagFormat[] = "source_tag"; | |
44 | 43 |
45 class ClipboardMap { | 44 class ClipboardMap { |
46 public: | 45 public: |
47 ClipboardMap(); | 46 ClipboardMap(); |
48 std::string Get(const std::string& format); | 47 std::string Get(const std::string& format); |
49 bool HasFormat(const std::string& format); | 48 bool HasFormat(const std::string& format); |
50 void Set(const std::string& format, const std::string& data); | 49 void Set(const std::string& format, const std::string& data); |
51 void Clear(); | 50 void Clear(); |
52 | 51 |
53 private: | 52 private: |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return data_ == other.data_; | 191 return data_ == other.data_; |
193 } | 192 } |
194 | 193 |
195 Clipboard::Clipboard() { | 194 Clipboard::Clipboard() { |
196 } | 195 } |
197 | 196 |
198 Clipboard::~Clipboard() { | 197 Clipboard::~Clipboard() { |
199 } | 198 } |
200 | 199 |
201 // Main entry point used to write several values in the clipboard. | 200 // Main entry point used to write several values in the clipboard. |
202 void Clipboard::WriteObjectsImpl(Buffer buffer, | 201 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { |
203 const ObjectMap& objects, | |
204 SourceTag tag) { | |
205 DCHECK_EQ(buffer, BUFFER_STANDARD); | 202 DCHECK_EQ(buffer, BUFFER_STANDARD); |
206 g_map.Get().Clear(); | 203 g_map.Get().Clear(); |
207 for (ObjectMap::const_iterator iter = objects.begin(); | 204 for (ObjectMap::const_iterator iter = objects.begin(); |
208 iter != objects.end(); ++iter) { | 205 iter != objects.end(); ++iter) { |
209 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | 206 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
210 } | 207 } |
211 WriteSourceTag(tag); | |
212 } | 208 } |
213 | 209 |
214 uint64 Clipboard::GetSequenceNumber(Clipboard::Buffer /* buffer */) { | 210 uint64 Clipboard::GetSequenceNumber(Clipboard::Buffer /* buffer */) { |
215 // TODO: implement this. For now this interface will advertise | 211 // TODO: implement this. For now this interface will advertise |
216 // that the clipboard never changes. That's fine as long as we | 212 // that the clipboard never changes. That's fine as long as we |
217 // don't rely on this signal. | 213 // don't rely on this signal. |
218 return 0; | 214 return 0; |
219 } | 215 } |
220 | 216 |
221 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, | 217 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 303 |
308 void Clipboard::ReadBookmark(string16* title, std::string* url) const { | 304 void Clipboard::ReadBookmark(string16* title, std::string* url) const { |
309 NOTIMPLEMENTED(); | 305 NOTIMPLEMENTED(); |
310 } | 306 } |
311 | 307 |
312 void Clipboard::ReadData(const Clipboard::FormatType& format, | 308 void Clipboard::ReadData(const Clipboard::FormatType& format, |
313 std::string* result) const { | 309 std::string* result) const { |
314 *result = g_map.Get().Get(format.data()); | 310 *result = g_map.Get().Get(format.data()); |
315 } | 311 } |
316 | 312 |
317 Clipboard::SourceTag Clipboard::ReadSourceTag(Buffer buffer) const { | |
318 DCHECK_EQ(buffer, BUFFER_STANDARD); | |
319 std::string result; | |
320 ReadData(GetSourceTagFormatType(), &result); | |
321 return Binary2SourceTag(result); | |
322 } | |
323 | |
324 // static | 313 // static |
325 Clipboard::FormatType Clipboard::GetFormatType( | 314 Clipboard::FormatType Clipboard::GetFormatType( |
326 const std::string& format_string) { | 315 const std::string& format_string) { |
327 return FormatType::Deserialize(format_string); | 316 return FormatType::Deserialize(format_string); |
328 } | 317 } |
329 | 318 |
330 // static | 319 // static |
331 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { | 320 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { |
332 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); | 321 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); |
333 return type; | 322 return type; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); | 357 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); |
369 return type; | 358 return type; |
370 } | 359 } |
371 | 360 |
372 // static | 361 // static |
373 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 362 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
374 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); | 363 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); |
375 return type; | 364 return type; |
376 } | 365 } |
377 | 366 |
378 // static | |
379 const Clipboard::FormatType& Clipboard::GetSourceTagFormatType() { | |
380 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kSourceTagFormat)); | |
381 return type; | |
382 } | |
383 | |
384 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 367 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
385 g_map.Get().Set(kPlainTextFormat, std::string(text_data, text_len)); | 368 g_map.Get().Set(kPlainTextFormat, std::string(text_data, text_len)); |
386 } | 369 } |
387 | 370 |
388 void Clipboard::WriteHTML(const char* markup_data, | 371 void Clipboard::WriteHTML(const char* markup_data, |
389 size_t markup_len, | 372 size_t markup_len, |
390 const char* url_data, | 373 const char* url_data, |
391 size_t url_len) { | 374 size_t url_len) { |
392 g_map.Get().Set(kHTMLFormat, std::string(markup_data, markup_len)); | 375 g_map.Get().Set(kHTMLFormat, std::string(markup_data, markup_len)); |
393 } | 376 } |
(...skipping 26 matching lines...) Expand all Loading... |
420 std::string packed(size_data, sizeof(gfx::Size)); | 403 std::string packed(size_data, sizeof(gfx::Size)); |
421 packed += std::string(pixel_data, bm_size); | 404 packed += std::string(pixel_data, bm_size); |
422 g_map.Get().Set(kBitmapFormat, packed); | 405 g_map.Get().Set(kBitmapFormat, packed); |
423 } | 406 } |
424 | 407 |
425 void Clipboard::WriteData(const Clipboard::FormatType& format, | 408 void Clipboard::WriteData(const Clipboard::FormatType& format, |
426 const char* data_data, size_t data_len) { | 409 const char* data_data, size_t data_len) { |
427 g_map.Get().Set(format.data(), std::string(data_data, data_len)); | 410 g_map.Get().Set(format.data(), std::string(data_data, data_len)); |
428 } | 411 } |
429 | 412 |
430 void Clipboard::WriteSourceTag(SourceTag tag) { | |
431 if (tag != SourceTag()) { | |
432 ObjectMapParam binary = SourceTag2Binary(tag); | |
433 WriteData(GetSourceTagFormatType(), &binary[0], binary.size()); | |
434 } | |
435 } | |
436 | |
437 } // namespace ui | 413 } // namespace ui |
OLD | NEW |