Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Unified Diff: ui/base/clipboard/clipboard_android.cc

Issue 59023007: Enable pasting HTML content from the Android clipboard (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/android/java/src/org/chromium/ui/base/Clipboard.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d1e0635faf4109eed40189552798e94b1da60e0d 100644
--- a/ui/base/clipboard/clipboard_android.cc
+++ b/ui/base/clipboard/clipboard_android.cc
@@ -129,39 +129,38 @@ 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();
Kristian Monsen 2013/11/27 00:34:04 This should probably just erase the text entry?
- 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()) {
+ map_[kHTMLFormat] = ConvertJavaStringToUTF8(java_string_html);
newt (away) 2013/11/26 18:36:14 what if map_ contains an HTML clipboard entry, but
Kristian Monsen 2013/11/26 22:47:39 Updated to do that, and check if the HTML string i
Kristian Monsen 2013/11/27 00:34:04 For slightly complicated reasons we can't do both
}
}
« no previous file with comments | « ui/android/java/src/org/chromium/ui/base/Clipboard.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698