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..f0971c448a007ddf37b5393fe5bd7e04bf1da205 100644 |
--- a/ui/base/clipboard/clipboard_android.cc |
+++ b/ui/base/clipboard/clipboard_android.cc |
@@ -129,39 +129,50 @@ 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()) |
+ ScopedJavaLocalRef<jstring> java_string_text = |
+ Java_Clipboard_getCoercedText(env, clipboard_manager_.obj()); |
+ 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; |
+ } |
} |
- ScopedJavaLocalRef<jstring> java_string = |
- 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()) |
- // We have plain text on this side, but Android doesn't. Nuke ours. |
- map_.clear(); |
+ if (!Java_Clipboard_isHTMLClipboardSupported(env)) { |
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] = android_string; |
+ return; |
+ } |
+ } |
+ it = map_.find(kHTMLFormat); |
+ if (it != map_.end()) { |
+ map_.erase(kHTMLFormat); |
} |
} |