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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 return ContainsKey(map_, format); | 90 return ContainsKey(map_, format); |
91 } | 91 } |
92 | 92 |
93 void ClipboardMap::Set(const std::string& format, const std::string& data) { | 93 void ClipboardMap::Set(const std::string& format, const std::string& data) { |
94 JNIEnv* env = AttachCurrentThread(); | 94 JNIEnv* env = AttachCurrentThread(); |
95 base::AutoLock lock(lock_); | 95 base::AutoLock lock(lock_); |
96 SyncWithAndroidClipboard(); | 96 SyncWithAndroidClipboard(); |
97 | 97 |
98 map_[format] = data; | 98 map_[format] = data; |
99 if (format == kPlainTextFormat) { | 99 if (format == kPlainTextFormat) { |
100 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString( | 100 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, data); |
101 env, data.c_str()); | 101 DCHECK(str.obj()); |
102 DCHECK(str.obj() && !ClearException(env)); | 102 |
103 Java_Clipboard_setText(env, clipboard_manager_.obj(), str.obj()); | 103 Java_Clipboard_setText(env, clipboard_manager_.obj(), str.obj()); |
104 } else if (format == kHTMLFormat) { | |
105 // Android's API for storing HTML content on the clipboard requires a plain- | |
106 // text representation to be available as well. Because of an std::map's | |
107 // keys being ordered, any plain-text representation will be set already. | |
bulach
2013/10/25 14:32:47
I'm not quite sure what std::map order has to do h
Peter Beverloo
2013/10/25 15:29:37
Done.
| |
108 if (!ContainsKey(map_, kPlainTextFormat)) | |
109 return; | |
110 | |
111 ScopedJavaLocalRef<jstring> html = ConvertUTF8ToJavaString(env, data); | |
112 ScopedJavaLocalRef<jstring> text = ConvertUTF8ToJavaString( | |
113 env, map_[kPlainTextFormat].c_str()); | |
114 | |
115 DCHECK(html.obj() && text.obj()); | |
116 Java_Clipboard_setHTMLText( | |
117 env, clipboard_manager_.obj(), html.obj(), text.obj()); | |
104 } | 118 } |
105 } | 119 } |
106 | 120 |
107 void ClipboardMap::Clear() { | 121 void ClipboardMap::Clear() { |
108 JNIEnv* env = AttachCurrentThread(); | 122 JNIEnv* env = AttachCurrentThread(); |
109 base::AutoLock lock(lock_); | 123 base::AutoLock lock(lock_); |
110 map_.clear(); | 124 map_.clear(); |
111 Java_Clipboard_setText(env, clipboard_manager_.obj(), NULL); | 125 Java_Clipboard_setText(env, clipboard_manager_.obj(), NULL); |
112 } | 126 } |
113 | 127 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 const char* data_data, size_t data_len) { | 422 const char* data_data, size_t data_len) { |
409 g_map.Get().Set(format.data(), std::string(data_data, data_len)); | 423 g_map.Get().Set(format.data(), std::string(data_data, data_len)); |
410 } | 424 } |
411 | 425 |
412 // See clipboard_android_initialization.h for more information. | 426 // See clipboard_android_initialization.h for more information. |
413 bool RegisterClipboardAndroid(JNIEnv* env) { | 427 bool RegisterClipboardAndroid(JNIEnv* env) { |
414 return RegisterNativesImpl(env); | 428 return RegisterNativesImpl(env); |
415 } | 429 } |
416 | 430 |
417 } // namespace ui | 431 } // namespace ui |
OLD | NEW |