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_android.h" | 5 #include "ui/base/clipboard/clipboard_android.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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 using base::android::ClearException; | 28 using base::android::ClearException; |
29 using base::android::ConvertJavaStringToUTF8; | 29 using base::android::ConvertJavaStringToUTF8; |
30 using base::android::ConvertUTF8ToJavaString; | 30 using base::android::ConvertUTF8ToJavaString; |
31 using base::android::ScopedJavaGlobalRef; | 31 using base::android::ScopedJavaGlobalRef; |
32 using base::android::ScopedJavaLocalRef; | 32 using base::android::ScopedJavaLocalRef; |
33 | 33 |
34 namespace ui { | 34 namespace ui { |
35 | 35 |
36 namespace { | 36 namespace { |
37 // Various formats we support. | 37 // Various formats we support. |
| 38 const char kURLFormat[] = "url"; |
38 const char kPlainTextFormat[] = "text"; | 39 const char kPlainTextFormat[] = "text"; |
39 const char kHTMLFormat[] = "html"; | 40 const char kHTMLFormat[] = "html"; |
40 const char kRTFFormat[] = "rtf"; | 41 const char kRTFFormat[] = "rtf"; |
41 const char kBitmapFormat[] = "bitmap"; | 42 const char kBitmapFormat[] = "bitmap"; |
42 const char kWebKitSmartPasteFormat[] = "webkit_smart"; | 43 const char kWebKitSmartPasteFormat[] = "webkit_smart"; |
43 const char kBookmarkFormat[] = "bookmark"; | 44 const char kBookmarkFormat[] = "bookmark"; |
44 const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; | 45 const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; |
45 const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; | 46 const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; |
46 | 47 |
47 class ClipboardMap { | 48 class ClipboardMap { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 std::string Clipboard::FormatType::Serialize() const { | 192 std::string Clipboard::FormatType::Serialize() const { |
192 return data_; | 193 return data_; |
193 } | 194 } |
194 | 195 |
195 // static | 196 // static |
196 Clipboard::FormatType Clipboard::FormatType::Deserialize( | 197 Clipboard::FormatType Clipboard::FormatType::Deserialize( |
197 const std::string& serialization) { | 198 const std::string& serialization) { |
198 return FormatType(serialization); | 199 return FormatType(serialization); |
199 } | 200 } |
200 | 201 |
| 202 bool Clipboard::FormatType::operator<(const FormatType& other) const { |
| 203 return data_ < other.data_; |
| 204 } |
| 205 |
201 bool Clipboard::FormatType::Equals(const FormatType& other) const { | 206 bool Clipboard::FormatType::Equals(const FormatType& other) const { |
202 return data_ == other.data_; | 207 return data_ == other.data_; |
203 } | 208 } |
204 | 209 |
205 // Various predefined FormatTypes. | 210 // Various predefined FormatTypes. |
206 // static | 211 // static |
207 Clipboard::FormatType Clipboard::GetFormatType( | 212 Clipboard::FormatType Clipboard::GetFormatType( |
208 const std::string& format_string) { | 213 const std::string& format_string) { |
209 return FormatType::Deserialize(format_string); | 214 return FormatType::Deserialize(format_string); |
210 } | 215 } |
211 | 216 |
212 // static | 217 // static |
| 218 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { |
| 219 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kURLFormat)); |
| 220 return type; |
| 221 } |
| 222 |
| 223 // static |
213 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { | 224 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { |
214 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); | 225 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); |
215 return type; | 226 return type; |
216 } | 227 } |
217 | 228 |
218 // static | 229 // static |
219 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { | 230 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { |
220 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); | 231 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); |
221 return type; | 232 return type; |
222 } | 233 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 276 |
266 // ClipboardAndroid implementation. | 277 // ClipboardAndroid implementation. |
267 ClipboardAndroid::ClipboardAndroid() { | 278 ClipboardAndroid::ClipboardAndroid() { |
268 DCHECK(CalledOnValidThread()); | 279 DCHECK(CalledOnValidThread()); |
269 } | 280 } |
270 | 281 |
271 ClipboardAndroid::~ClipboardAndroid() { | 282 ClipboardAndroid::~ClipboardAndroid() { |
272 DCHECK(CalledOnValidThread()); | 283 DCHECK(CalledOnValidThread()); |
273 } | 284 } |
274 | 285 |
275 uint64 ClipboardAndroid::GetSequenceNumber(ClipboardType /* type */) { | 286 uint64 ClipboardAndroid::GetSequenceNumber(ClipboardType /* type */) const { |
276 DCHECK(CalledOnValidThread()); | 287 DCHECK(CalledOnValidThread()); |
277 // TODO: implement this. For now this interface will advertise | 288 // TODO: implement this. For now this interface will advertise |
278 // that the clipboard never changes. That's fine as long as we | 289 // that the clipboard never changes. That's fine as long as we |
279 // don't rely on this signal. | 290 // don't rely on this signal. |
280 return 0; | 291 return 0; |
281 } | 292 } |
282 | 293 |
283 bool ClipboardAndroid::IsFormatAvailable(const Clipboard::FormatType& format, | 294 bool ClipboardAndroid::IsFormatAvailable(const Clipboard::FormatType& format, |
284 ClipboardType type) const { | 295 ClipboardType type) const { |
285 DCHECK(CalledOnValidThread()); | 296 DCHECK(CalledOnValidThread()); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 const char* data_data, | 458 const char* data_data, |
448 size_t data_len) { | 459 size_t data_len) { |
449 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); | 460 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); |
450 } | 461 } |
451 | 462 |
452 bool RegisterClipboardAndroid(JNIEnv* env) { | 463 bool RegisterClipboardAndroid(JNIEnv* env) { |
453 return RegisterNativesImpl(env); | 464 return RegisterNativesImpl(env); |
454 } | 465 } |
455 | 466 |
456 } // namespace ui | 467 } // namespace ui |
OLD | NEW |