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

Side by Side 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: Using coerceToHtmlText 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/android/java/src/org/chromium/ui/Clipboard.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "ui/base/clipboard/clipboard.h"
6 6
7 #include "base/android/jni_string.h" 7 #include "base/android/jni_string.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 void ClipboardMap::Clear() { 123 void ClipboardMap::Clear() {
124 JNIEnv* env = AttachCurrentThread(); 124 JNIEnv* env = AttachCurrentThread();
125 base::AutoLock lock(lock_); 125 base::AutoLock lock(lock_);
126 map_.clear(); 126 map_.clear();
127 Java_Clipboard_setText(env, clipboard_manager_.obj(), NULL); 127 Java_Clipboard_setText(env, clipboard_manager_.obj(), NULL);
128 } 128 }
129 129
130 // If the internal map contains a plain-text entry and it does not match that 130 // If the internal map contains a plain-text entry and it does not match that
131 // in the Android clipboard, clear the map and insert the Android text into it. 131 // in the Android clipboard, clear the map and insert the Android text into it.
132 // If there is an HTML entry in the Android clipboard it gets inserted in the
133 // map.
132 void ClipboardMap::SyncWithAndroidClipboard() { 134 void ClipboardMap::SyncWithAndroidClipboard() {
133 lock_.AssertAcquired(); 135 lock_.AssertAcquired();
134 JNIEnv* env = AttachCurrentThread(); 136 JNIEnv* env = AttachCurrentThread();
135 137
138 // Update the plain text clipboard entry
136 std::map<std::string, std::string>::const_iterator it = 139 std::map<std::string, std::string>::const_iterator it =
137 map_.find(kPlainTextFormat); 140 map_.find(kPlainTextFormat);
138 141 ScopedJavaLocalRef<jstring> java_string_text =
139 if (!Java_Clipboard_hasPlainText(env, clipboard_manager_.obj())) { 142 Java_Clipboard_getCoercedText(env, clipboard_manager_.obj());
140 if (it != map_.end()) 143 if (java_string_text.obj()) {
144 std::string android_string = ConvertJavaStringToUTF8(java_string_text);
145 if (it == map_.end() || it->second != android_string) {
146 // There is a different string in the Android clipboard than we have.
147 // Clear the map on our side.
148 map_.clear();
149 map_[kPlainTextFormat] = android_string;
150 }
151 } else {
152 if (it != map_.end()) {
141 // We have plain text on this side, but Android doesn't. Nuke ours. 153 // We have plain text on this side, but Android doesn't. Nuke ours.
142 map_.clear(); 154 map_.clear();
143 return; 155 }
144 } 156 }
145 157
146 ScopedJavaLocalRef<jstring> java_string = 158 // Update the html clipboard entry
147 Java_Clipboard_getCoercedText(env, clipboard_manager_.obj()); 159 ScopedJavaLocalRef<jstring> java_string_html =
148 160 Java_Clipboard_getHtmlText(env, clipboard_manager_.obj());
149 if (!java_string.obj()) { 161 if (java_string_html.obj()) {
150 // Tolerate a null value from the Java side, even though that should not 162 map_[kHTMLFormat] = ConvertJavaStringToUTF8(java_string_html);
joth 2013/11/12 04:50:29 as the java side now uses coerce, whenever the pri
Kristian Monsen 2013/11/12 06:08:06 I don't know, hopefully one of the other reviewers
tony 2013/11/12 17:26:31 AFAIK, you won't be making some other code path un
151 // happen since hasPlainText has already returned true.
152 // Should only happen if someone is using the clipboard on multiple
153 // threads and clears it out after hasPlainText but before we get here...
154 if (it != map_.end())
155 // We have plain text on this side, but Android doesn't. Nuke ours.
156 map_.clear();
157 return;
158 }
159
160 // If Android text differs from ours (or we have none), then copy Android's.
161 std::string android_string = ConvertJavaStringToUTF8(java_string);
162 if (it == map_.end() || it->second != android_string) {
163 map_.clear();
164 map_[kPlainTextFormat] = android_string;
165 } 163 }
166 } 164 }
167 165
168 } // namespace 166 } // namespace
169 167
170 Clipboard::FormatType::FormatType() { 168 Clipboard::FormatType::FormatType() {
171 } 169 }
172 170
173 Clipboard::FormatType::FormatType(const std::string& native_format) 171 Clipboard::FormatType::FormatType(const std::string& native_format)
174 : data_(native_format) { 172 : data_(native_format) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 const char* data_data, size_t data_len) { 422 const char* data_data, size_t data_len) {
425 g_map.Get().Set(format.data(), std::string(data_data, data_len)); 423 g_map.Get().Set(format.data(), std::string(data_data, data_len));
426 } 424 }
427 425
428 // See clipboard_android_initialization.h for more information. 426 // See clipboard_android_initialization.h for more information.
429 bool RegisterClipboardAndroid(JNIEnv* env) { 427 bool RegisterClipboardAndroid(JNIEnv* env) {
430 return RegisterNativesImpl(env); 428 return RegisterNativesImpl(env);
431 } 429 }
432 430
433 } // namespace ui 431 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/java/src/org/chromium/ui/Clipboard.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698