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" | 7 #include "base/android/context_utils.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 void UpdateFromAndroidClipboard(); | 57 void UpdateFromAndroidClipboard(); |
58 std::map<std::string, std::string> map_; | 58 std::map<std::string, std::string> map_; |
59 base::Lock lock_; | 59 base::Lock lock_; |
60 | 60 |
61 // Java class and methods for the Android ClipboardManager. | 61 // Java class and methods for the Android ClipboardManager. |
62 ScopedJavaGlobalRef<jobject> clipboard_manager_; | 62 ScopedJavaGlobalRef<jobject> clipboard_manager_; |
63 }; | 63 }; |
64 base::LazyInstance<ClipboardMap>::Leaky g_map = LAZY_INSTANCE_INITIALIZER; | 64 base::LazyInstance<ClipboardMap>::Leaky g_map = LAZY_INSTANCE_INITIALIZER; |
65 | 65 |
66 ClipboardMap::ClipboardMap() { | 66 ClipboardMap::ClipboardMap() { |
67 JNIEnv* env = AttachCurrentThread(); | 67 clipboard_manager_.Reset(Java_Clipboard_create( |
68 DCHECK(env); | 68 AttachCurrentThread(), base::android::GetApplicationContext())); |
69 | |
70 // Get the context. | |
71 jobject context = base::android::GetApplicationContext(); | |
72 DCHECK(context); | |
73 | |
74 clipboard_manager_.Reset(Java_Clipboard_create(env, context)); | |
75 DCHECK(clipboard_manager_.obj()); | 69 DCHECK(clipboard_manager_.obj()); |
76 } | 70 } |
77 | 71 |
78 std::string ClipboardMap::Get(const std::string& format) { | 72 std::string ClipboardMap::Get(const std::string& format) { |
79 base::AutoLock lock(lock_); | 73 base::AutoLock lock(lock_); |
80 UpdateFromAndroidClipboard(); | 74 UpdateFromAndroidClipboard(); |
81 std::map<std::string, std::string>::const_iterator it = map_.find(format); | 75 std::map<std::string, std::string>::const_iterator it = map_.find(format); |
82 return it == map_.end() ? std::string() : it->second; | 76 return it == map_.end() ? std::string() : it->second; |
83 } | 77 } |
84 | 78 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 g_map.Get().Set(kBitmapFormat, packed); | 459 g_map.Get().Set(kBitmapFormat, packed); |
466 } | 460 } |
467 | 461 |
468 void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, | 462 void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, |
469 const char* data_data, | 463 const char* data_data, |
470 size_t data_len) { | 464 size_t data_len) { |
471 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); | 465 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); |
472 } | 466 } |
473 | 467 |
474 } // namespace ui | 468 } // namespace ui |
OLD | NEW |