| 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_android.h" | 5 #include "ui/base/clipboard/clipboard_android.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | |
| 8 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 9 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 10 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 13 #include "jni/Clipboard_jni.h" | 12 #include "jni/Clipboard_jni.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 16 | 15 |
| 17 // TODO:(andrewhayden) Support additional formats in Android: Bitmap, URI, HTML, | 16 // TODO:(andrewhayden) Support additional formats in Android: Bitmap, URI, HTML, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 void UpdateFromAndroidClipboard(); | 56 void UpdateFromAndroidClipboard(); |
| 58 std::map<std::string, std::string> map_; | 57 std::map<std::string, std::string> map_; |
| 59 base::Lock lock_; | 58 base::Lock lock_; |
| 60 | 59 |
| 61 // Java class and methods for the Android ClipboardManager. | 60 // Java class and methods for the Android ClipboardManager. |
| 62 ScopedJavaGlobalRef<jobject> clipboard_manager_; | 61 ScopedJavaGlobalRef<jobject> clipboard_manager_; |
| 63 }; | 62 }; |
| 64 base::LazyInstance<ClipboardMap>::Leaky g_map = LAZY_INSTANCE_INITIALIZER; | 63 base::LazyInstance<ClipboardMap>::Leaky g_map = LAZY_INSTANCE_INITIALIZER; |
| 65 | 64 |
| 66 ClipboardMap::ClipboardMap() { | 65 ClipboardMap::ClipboardMap() { |
| 67 clipboard_manager_.Reset(Java_Clipboard_create( | 66 clipboard_manager_.Reset(Java_Clipboard_getInstance(AttachCurrentThread())); |
| 68 AttachCurrentThread(), base::android::GetApplicationContext())); | |
| 69 DCHECK(clipboard_manager_.obj()); | 67 DCHECK(clipboard_manager_.obj()); |
| 70 } | 68 } |
| 71 | 69 |
| 72 std::string ClipboardMap::Get(const std::string& format) { | 70 std::string ClipboardMap::Get(const std::string& format) { |
| 73 base::AutoLock lock(lock_); | 71 base::AutoLock lock(lock_); |
| 74 UpdateFromAndroidClipboard(); | 72 UpdateFromAndroidClipboard(); |
| 75 std::map<std::string, std::string>::const_iterator it = map_.find(format); | 73 std::map<std::string, std::string>::const_iterator it = map_.find(format); |
| 76 return it == map_.end() ? std::string() : it->second; | 74 return it == map_.end() ? std::string() : it->second; |
| 77 } | 75 } |
| 78 | 76 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 g_map.Get().Set(kBitmapFormat, packed); | 458 g_map.Get().Set(kBitmapFormat, packed); |
| 461 } | 459 } |
| 462 | 460 |
| 463 void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, | 461 void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, |
| 464 const char* data_data, | 462 const char* data_data, |
| 465 size_t data_len) { | 463 size_t data_len) { |
| 466 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); | 464 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); |
| 467 } | 465 } |
| 468 | 466 |
| 469 } // namespace ui | 467 } // namespace ui |
| OLD | NEW |