OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/android/offline_pages/downloads/offline_page_notificati
on_bridge.h" | 5 #include "chrome/browser/android/offline_pages/downloads/offline_page_notificati
on_bridge.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 "chrome/browser/android/offline_pages/downloads/offline_page_download_b
ridge.h" | 8 #include "chrome/browser/android/offline_pages/downloads/offline_page_download_b
ridge.h" |
10 #include "jni/OfflinePageNotificationBridge_jni.h" | 9 #include "jni/OfflinePageNotificationBridge_jni.h" |
11 | 10 |
12 using base::android::AttachCurrentThread; | 11 using base::android::AttachCurrentThread; |
13 using base::android::ConvertUTF16ToJavaString; | 12 using base::android::ConvertUTF16ToJavaString; |
14 using base::android::ConvertUTF8ToJavaString; | 13 using base::android::ConvertUTF8ToJavaString; |
15 using base::android::GetApplicationContext; | |
16 | 14 |
17 namespace { | 15 namespace { |
18 | 16 |
19 base::android::ScopedJavaLocalRef<jstring> GetDisplayName( | 17 base::android::ScopedJavaLocalRef<jstring> GetDisplayName( |
20 const offline_pages::DownloadUIItem& item) { | 18 const offline_pages::DownloadUIItem& item) { |
21 JNIEnv* env = AttachCurrentThread(); | 19 JNIEnv* env = AttachCurrentThread(); |
22 if (!item.title.empty()) | 20 if (!item.title.empty()) |
23 return ConvertUTF16ToJavaString(env, item.title); | 21 return ConvertUTF16ToJavaString(env, item.title); |
24 | 22 |
25 std::string host = item.url.host(); | 23 std::string host = item.url.host(); |
26 if (!host.empty()) | 24 if (!host.empty()) |
27 return ConvertUTF8ToJavaString(env, host); | 25 return ConvertUTF8ToJavaString(env, host); |
28 | 26 |
29 return ConvertUTF8ToJavaString(env, item.url.spec()); | 27 return ConvertUTF8ToJavaString(env, item.url.spec()); |
30 } | 28 } |
31 | 29 |
32 } // namespace | 30 } // namespace |
33 | 31 |
34 namespace offline_pages { | 32 namespace offline_pages { |
35 namespace android { | 33 namespace android { |
36 | 34 |
37 void OfflinePageNotificationBridge::NotifyDownloadSuccessful( | 35 void OfflinePageNotificationBridge::NotifyDownloadSuccessful( |
38 const DownloadUIItem& item) { | 36 const DownloadUIItem& item) { |
39 JNIEnv* env = AttachCurrentThread(); | 37 JNIEnv* env = AttachCurrentThread(); |
40 Java_OfflinePageNotificationBridge_notifyDownloadSuccessful( | 38 Java_OfflinePageNotificationBridge_notifyDownloadSuccessful( |
41 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), | 39 env, ConvertUTF8ToJavaString(env, item.guid), |
42 ConvertUTF8ToJavaString(env, item.url.spec()), GetDisplayName(item)); | 40 ConvertUTF8ToJavaString(env, item.url.spec()), GetDisplayName(item)); |
43 } | 41 } |
44 | 42 |
45 void OfflinePageNotificationBridge::NotifyDownloadFailed( | 43 void OfflinePageNotificationBridge::NotifyDownloadFailed( |
46 const DownloadUIItem& item) { | 44 const DownloadUIItem& item) { |
47 JNIEnv* env = AttachCurrentThread(); | 45 JNIEnv* env = AttachCurrentThread(); |
48 Java_OfflinePageNotificationBridge_notifyDownloadFailed( | 46 Java_OfflinePageNotificationBridge_notifyDownloadFailed( |
49 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), | 47 env, ConvertUTF8ToJavaString(env, item.guid), |
50 ConvertUTF8ToJavaString(env, item.url.spec()), GetDisplayName(item)); | 48 ConvertUTF8ToJavaString(env, item.url.spec()), GetDisplayName(item)); |
51 } | 49 } |
52 | 50 |
53 void OfflinePageNotificationBridge::NotifyDownloadProgress( | 51 void OfflinePageNotificationBridge::NotifyDownloadProgress( |
54 const DownloadUIItem& item) { | 52 const DownloadUIItem& item) { |
55 JNIEnv* env = AttachCurrentThread(); | 53 JNIEnv* env = AttachCurrentThread(); |
56 Java_OfflinePageNotificationBridge_notifyDownloadProgress( | 54 Java_OfflinePageNotificationBridge_notifyDownloadProgress( |
57 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), | 55 env, ConvertUTF8ToJavaString(env, item.guid), |
58 ConvertUTF8ToJavaString(env, item.url.spec()), | 56 ConvertUTF8ToJavaString(env, item.url.spec()), |
59 item.start_time.ToJavaTime(), item.download_progress_bytes, | 57 item.start_time.ToJavaTime(), item.download_progress_bytes, |
60 GetDisplayName(item)); | 58 GetDisplayName(item)); |
61 } | 59 } |
62 | 60 |
63 void OfflinePageNotificationBridge::NotifyDownloadPaused( | 61 void OfflinePageNotificationBridge::NotifyDownloadPaused( |
64 const DownloadUIItem& item) { | 62 const DownloadUIItem& item) { |
65 JNIEnv* env = AttachCurrentThread(); | 63 JNIEnv* env = AttachCurrentThread(); |
66 Java_OfflinePageNotificationBridge_notifyDownloadPaused( | 64 Java_OfflinePageNotificationBridge_notifyDownloadPaused( |
67 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), | 65 env, ConvertUTF8ToJavaString(env, item.guid), GetDisplayName(item)); |
68 GetDisplayName(item)); | |
69 } | 66 } |
70 | 67 |
71 void OfflinePageNotificationBridge::NotifyDownloadInterrupted( | 68 void OfflinePageNotificationBridge::NotifyDownloadInterrupted( |
72 const DownloadUIItem& item) { | 69 const DownloadUIItem& item) { |
73 JNIEnv* env = AttachCurrentThread(); | 70 JNIEnv* env = AttachCurrentThread(); |
74 Java_OfflinePageNotificationBridge_notifyDownloadInterrupted( | 71 Java_OfflinePageNotificationBridge_notifyDownloadInterrupted( |
75 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), | 72 env, ConvertUTF8ToJavaString(env, item.guid), GetDisplayName(item)); |
76 GetDisplayName(item)); | |
77 } | 73 } |
78 | 74 |
79 void OfflinePageNotificationBridge::NotifyDownloadCanceled( | 75 void OfflinePageNotificationBridge::NotifyDownloadCanceled( |
80 const DownloadUIItem& item) { | 76 const DownloadUIItem& item) { |
81 JNIEnv* env = AttachCurrentThread(); | 77 JNIEnv* env = AttachCurrentThread(); |
82 Java_OfflinePageNotificationBridge_notifyDownloadCanceled( | 78 Java_OfflinePageNotificationBridge_notifyDownloadCanceled( |
83 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid)); | 79 env, ConvertUTF8ToJavaString(env, item.guid)); |
84 } | 80 } |
85 | 81 |
86 void OfflinePageNotificationBridge::ShowDownloadingToast() { | 82 void OfflinePageNotificationBridge::ShowDownloadingToast() { |
87 JNIEnv* env = AttachCurrentThread(); | 83 JNIEnv* env = AttachCurrentThread(); |
88 Java_OfflinePageNotificationBridge_showDownloadingToast( | 84 Java_OfflinePageNotificationBridge_showDownloadingToast(env); |
89 env, GetApplicationContext()); | |
90 } | 85 } |
91 | 86 |
92 } // namespace android | 87 } // namespace android |
93 } // namespace offline_pages | 88 } // namespace offline_pages |
OLD | NEW |