| 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/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // text representation to be available as well. | 95 // text representation to be available as well. |
| 96 if (!base::ContainsKey(map_, kPlainTextFormat)) | 96 if (!base::ContainsKey(map_, kPlainTextFormat)) |
| 97 return; | 97 return; |
| 98 | 98 |
| 99 ScopedJavaLocalRef<jstring> html = | 99 ScopedJavaLocalRef<jstring> html = |
| 100 ConvertUTF8ToJavaString(env, map_[kHTMLFormat].c_str()); | 100 ConvertUTF8ToJavaString(env, map_[kHTMLFormat].c_str()); |
| 101 ScopedJavaLocalRef<jstring> text = | 101 ScopedJavaLocalRef<jstring> text = |
| 102 ConvertUTF8ToJavaString(env, map_[kPlainTextFormat].c_str()); | 102 ConvertUTF8ToJavaString(env, map_[kPlainTextFormat].c_str()); |
| 103 | 103 |
| 104 DCHECK(html.obj() && text.obj()); | 104 DCHECK(html.obj() && text.obj()); |
| 105 Java_Clipboard_setHTMLText(env, clipboard_manager_.obj(), html.obj(), | 105 Java_Clipboard_setHTMLText(env, clipboard_manager_, html, text); |
| 106 text.obj()); | |
| 107 } else if (base::ContainsKey(map_, kPlainTextFormat)) { | 106 } else if (base::ContainsKey(map_, kPlainTextFormat)) { |
| 108 ScopedJavaLocalRef<jstring> str = | 107 ScopedJavaLocalRef<jstring> str = |
| 109 ConvertUTF8ToJavaString(env, map_[kPlainTextFormat].c_str()); | 108 ConvertUTF8ToJavaString(env, map_[kPlainTextFormat].c_str()); |
| 110 DCHECK(str.obj()); | 109 DCHECK(str.obj()); |
| 111 Java_Clipboard_setText(env, clipboard_manager_.obj(), str.obj()); | 110 Java_Clipboard_setText(env, clipboard_manager_, str); |
| 112 } else { | 111 } else { |
| 113 Java_Clipboard_clear(env, clipboard_manager_.obj()); | 112 Java_Clipboard_clear(env, clipboard_manager_); |
| 114 NOTIMPLEMENTED(); | 113 NOTIMPLEMENTED(); |
| 115 } | 114 } |
| 116 } | 115 } |
| 117 | 116 |
| 118 void ClipboardMap::Clear() { | 117 void ClipboardMap::Clear() { |
| 119 JNIEnv* env = AttachCurrentThread(); | 118 JNIEnv* env = AttachCurrentThread(); |
| 120 base::AutoLock lock(lock_); | 119 base::AutoLock lock(lock_); |
| 121 map_.clear(); | 120 map_.clear(); |
| 122 Java_Clipboard_clear(env, clipboard_manager_.obj()); | 121 Java_Clipboard_clear(env, clipboard_manager_); |
| 123 } | 122 } |
| 124 | 123 |
| 125 // Add a key:jstr pair to map, but only if jstr is not null, and also | 124 // Add a key:jstr pair to map, but only if jstr is not null, and also |
| 126 // not empty. | 125 // not empty. |
| 127 void AddMapEntry(JNIEnv* env, | 126 void AddMapEntry(JNIEnv* env, |
| 128 std::map<std::string, std::string>* map, | 127 std::map<std::string, std::string>* map, |
| 129 const char* key, | 128 const char* key, |
| 130 const ScopedJavaLocalRef<jstring>& jstr) { | 129 const ScopedJavaLocalRef<jstring>& jstr) { |
| 131 if (!jstr.is_null()) { | 130 if (!jstr.is_null()) { |
| 132 std::string str = ConvertJavaStringToUTF8(env, jstr.obj()); | 131 std::string str = ConvertJavaStringToUTF8(env, jstr.obj()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 148 | 147 |
| 149 void ClipboardMap::UpdateFromAndroidClipboard() { | 148 void ClipboardMap::UpdateFromAndroidClipboard() { |
| 150 // Fetch the current Android clipboard state. Replace our state with | 149 // Fetch the current Android clipboard state. Replace our state with |
| 151 // the Android state if the Android state has been changed. | 150 // the Android state if the Android state has been changed. |
| 152 lock_.AssertAcquired(); | 151 lock_.AssertAcquired(); |
| 153 JNIEnv* env = AttachCurrentThread(); | 152 JNIEnv* env = AttachCurrentThread(); |
| 154 | 153 |
| 155 std::map<std::string, std::string> android_clipboard_state; | 154 std::map<std::string, std::string> android_clipboard_state; |
| 156 | 155 |
| 157 ScopedJavaLocalRef<jstring> jtext = | 156 ScopedJavaLocalRef<jstring> jtext = |
| 158 Java_Clipboard_getCoercedText(env, clipboard_manager_.obj()); | 157 Java_Clipboard_getCoercedText(env, clipboard_manager_); |
| 159 ScopedJavaLocalRef<jstring> jhtml = | 158 ScopedJavaLocalRef<jstring> jhtml = |
| 160 Java_Clipboard_getHTMLText(env, clipboard_manager_.obj()); | 159 Java_Clipboard_getHTMLText(env, clipboard_manager_); |
| 161 | 160 |
| 162 AddMapEntry(env, &android_clipboard_state, kPlainTextFormat, jtext); | 161 AddMapEntry(env, &android_clipboard_state, kPlainTextFormat, jtext); |
| 163 AddMapEntry(env, &android_clipboard_state, kHTMLFormat, jhtml); | 162 AddMapEntry(env, &android_clipboard_state, kHTMLFormat, jhtml); |
| 164 | 163 |
| 165 if (!MapIsSubset(android_clipboard_state, map_)) | 164 if (!MapIsSubset(android_clipboard_state, map_)) |
| 166 android_clipboard_state.swap(map_); | 165 android_clipboard_state.swap(map_); |
| 167 } | 166 } |
| 168 | 167 |
| 169 } // namespace | 168 } // namespace |
| 170 | 169 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 g_map.Get().Set(kBitmapFormat, packed); | 458 g_map.Get().Set(kBitmapFormat, packed); |
| 460 } | 459 } |
| 461 | 460 |
| 462 void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, | 461 void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, |
| 463 const char* data_data, | 462 const char* data_data, |
| 464 size_t data_len) { | 463 size_t data_len) { |
| 465 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); | 464 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); |
| 466 } | 465 } |
| 467 | 466 |
| 468 } // namespace ui | 467 } // namespace ui |
| OLD | NEW |