Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 JNIEnv* env = AttachCurrentThread(); | 94 JNIEnv* env = AttachCurrentThread(); |
| 95 base::AutoLock lock(lock_); | 95 base::AutoLock lock(lock_); |
| 96 SyncWithAndroidClipboard(); | 96 SyncWithAndroidClipboard(); |
| 97 | 97 |
| 98 map_[format] = data; | 98 map_[format] = data; |
| 99 if (format == kPlainTextFormat) { | 99 if (format == kPlainTextFormat) { |
| 100 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString( | 100 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString( |
| 101 env, data.c_str()); | 101 env, data.c_str()); |
| 102 DCHECK(str.obj() && !ClearException(env)); | 102 DCHECK(str.obj() && !ClearException(env)); |
| 103 Java_Clipboard_setText(env, clipboard_manager_.obj(), str.obj()); | 103 Java_Clipboard_setText(env, clipboard_manager_.obj(), str.obj()); |
| 104 } else if (format == kHTMLFormat) { | |
| 105 // Android's API for storing HTML content on the clipboard requires a plain- | |
| 106 // text representation to be available as well. Because of an std::map's | |
| 107 // keys being ordered, any plain-text representation will be set already. | |
| 108 if (!ContainsKey(map_, kPlainTextFormat)) | |
| 109 return; | |
| 110 | |
| 111 ScopedJavaLocalRef<jstring> html = ConvertUTF8ToJavaString( | |
| 112 env, data.c_str()); | |
| 113 ScopedJavaLocalRef<jstring> text = ConvertUTF8ToJavaString( | |
| 114 env, map_[kPlainTextFormat].c_str()); | |
| 115 | |
| 116 DCHECK(html.obj() && text.obj() && !ClearException(env)); | |
| 117 Java_Clipboard_setHTMLText( | |
| 118 env, clipboard_manager_.obj(), html.obj(), text.obj()); | |
|
dcheng
2013/10/02 22:24:15
What is the expected behavior if a JS paste handle
Peter Beverloo
2013/10/23 17:11:34
That's a good question. Pasting HTML on Android r
| |
| 104 } | 119 } |
| 105 } | 120 } |
| 106 | 121 |
| 107 void ClipboardMap::Clear() { | 122 void ClipboardMap::Clear() { |
| 108 JNIEnv* env = AttachCurrentThread(); | 123 JNIEnv* env = AttachCurrentThread(); |
| 109 base::AutoLock lock(lock_); | 124 base::AutoLock lock(lock_); |
| 110 map_.clear(); | 125 map_.clear(); |
| 111 Java_Clipboard_setText(env, clipboard_manager_.obj(), NULL); | 126 Java_Clipboard_setText(env, clipboard_manager_.obj(), NULL); |
| 112 } | 127 } |
| 113 | 128 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 const char* data_data, size_t data_len) { | 423 const char* data_data, size_t data_len) { |
| 409 g_map.Get().Set(format.data(), std::string(data_data, data_len)); | 424 g_map.Get().Set(format.data(), std::string(data_data, data_len)); |
| 410 } | 425 } |
| 411 | 426 |
| 412 // See clipboard_android_initialization.h for more information. | 427 // See clipboard_android_initialization.h for more information. |
| 413 bool RegisterClipboardAndroid(JNIEnv* env) { | 428 bool RegisterClipboardAndroid(JNIEnv* env) { |
| 414 return RegisterNativesImpl(env); | 429 return RegisterNativesImpl(env); |
| 415 } | 430 } |
| 416 | 431 |
| 417 } // namespace ui | 432 } // namespace ui |
| OLD | NEW |