Chromium Code Reviews| Index: ui/base/clipboard/clipboard_android.cc |
| diff --git a/ui/base/clipboard/clipboard_android.cc b/ui/base/clipboard/clipboard_android.cc |
| index fc9ba00bbbf1c483d57986ae2eed77b02192d06e..827cfffb3c0ecf384e0740f6e89b090d02677e61 100644 |
| --- a/ui/base/clipboard/clipboard_android.cc |
| +++ b/ui/base/clipboard/clipboard_android.cc |
| @@ -129,39 +129,46 @@ void ClipboardMap::Clear() { |
| // If the internal map contains a plain-text entry and it does not match that |
| // in the Android clipboard, clear the map and insert the Android text into it. |
| +// If there is an HTML entry in the Android clipboard it gets inserted in the |
| +// map. |
| void ClipboardMap::SyncWithAndroidClipboard() { |
| lock_.AssertAcquired(); |
| JNIEnv* env = AttachCurrentThread(); |
| + // Update the plain text clipboard entry |
| std::map<std::string, std::string>::const_iterator it = |
| map_.find(kPlainTextFormat); |
| - |
| - if (!Java_Clipboard_hasPlainText(env, clipboard_manager_.obj())) { |
| - if (it != map_.end()) |
| - // We have plain text on this side, but Android doesn't. Nuke ours. |
| - map_.clear(); |
| - return; |
| - } |
| - |
| - ScopedJavaLocalRef<jstring> java_string = |
| + ScopedJavaLocalRef<jstring> java_string_text = |
| Java_Clipboard_getCoercedText(env, clipboard_manager_.obj()); |
| - |
| - if (!java_string.obj()) { |
| - // Tolerate a null value from the Java side, even though that should not |
| - // happen since hasPlainText has already returned true. |
| - // Should only happen if someone is using the clipboard on multiple |
| - // threads and clears it out after hasPlainText but before we get here... |
| - if (it != map_.end()) |
| + if (java_string_text.obj()) { |
| + std::string android_string = ConvertJavaStringToUTF8(java_string_text); |
| + if (!android_string.empty() && |
| + (it == map_.end() || it->second != android_string)) { |
| + // There is a different string in the Android clipboard than we have. |
| + // Clear the map on our side. |
| + map_.clear(); |
| + map_[kPlainTextFormat] = android_string; |
| + } |
| + } else { |
| + if (it != map_.end()) { |
| // We have plain text on this side, but Android doesn't. Nuke ours. |
| map_.clear(); |
| - return; |
| + } |
| } |
| - // If Android text differs from ours (or we have none), then copy Android's. |
| - std::string android_string = ConvertJavaStringToUTF8(java_string); |
| - if (it == map_.end() || it->second != android_string) { |
| - map_.clear(); |
| - map_[kPlainTextFormat] = android_string; |
| + // Update the html clipboard entry |
| + ScopedJavaLocalRef<jstring> java_string_html = |
| + Java_Clipboard_getHtmlText(env, clipboard_manager_.obj()); |
| + if (java_string_html.obj()) { |
| + std::string android_string = ConvertJavaStringToUTF8(java_string_html); |
| + if (!android_string.empty()) { |
| + map_[kHTMLFormat] = ConvertJavaStringToUTF8(java_string_html); |
|
bulach
2013/11/27 16:26:38
nit: s/ConvertJavaStringToUTF8(java_string_html)/a
Kristian Monsen
2013/12/03 17:11:17
Done.
|
| + return; |
| + } |
| + } |
| + it = map_.find(kHTMLFormat); |
| + if (it != map_.end()) { |
| + map_.erase(kHTMLFormat); |
| } |
| } |