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

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: Upload *all* the files Created 7 years 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') | ui/base/clipboard/clipboard_unittest.cc » ('j') | 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..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);
}
}
« no previous file with comments | « ui/android/java/src/org/chromium/ui/base/Clipboard.java ('k') | ui/base/clipboard/clipboard_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698