| 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/safe_browsing/safe_browsing_api_handler_bridge.
h" | 5 #include "components/safe_browsing_db/android/safe_browsing_api_handler_bridge.h
" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/android/context_utils.h" | 10 #include "base/android/context_utils.h" |
| 11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/android/jni_array.h" | 12 #include "base/android/jni_array.h" |
| 13 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | |
| 16 #include "components/safe_browsing_db/safe_browsing_api_handler_util.h" | 15 #include "components/safe_browsing_db/safe_browsing_api_handler_util.h" |
| 17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 18 #include "jni/SafeBrowsingApiBridge_jni.h" | 17 #include "jni/SafeBrowsingApiBridge_jni.h" |
| 19 | 18 |
| 20 using base::android::AttachCurrentThread; | 19 using base::android::AttachCurrentThread; |
| 21 using base::android::ConvertJavaStringToUTF8; | 20 using base::android::ConvertJavaStringToUTF8; |
| 22 using base::android::ConvertUTF8ToJavaString; | 21 using base::android::ConvertUTF8ToJavaString; |
| 23 using base::android::GetApplicationContext; | 22 using base::android::GetApplicationContext; |
| 24 using base::android::JavaParamRef; | 23 using base::android::JavaParamRef; |
| 25 using base::android::ScopedJavaLocalRef; | 24 using base::android::ScopedJavaLocalRef; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 int int_threat_types[threat_types.size()]; | 65 int int_threat_types[threat_types.size()]; |
| 67 int* itr = &int_threat_types[0]; | 66 int* itr = &int_threat_types[0]; |
| 68 for (auto threat_type : threat_types) { | 67 for (auto threat_type : threat_types) { |
| 69 *itr++ = SBThreatTypeToJavaThreatType(threat_type); | 68 *itr++ = SBThreatTypeToJavaThreatType(threat_type); |
| 70 } | 69 } |
| 71 return ToJavaIntArray(env, int_threat_types, threat_types.size()); | 70 return ToJavaIntArray(env, int_threat_types, threat_types.size()); |
| 72 } | 71 } |
| 73 | 72 |
| 74 } // namespace | 73 } // namespace |
| 75 | 74 |
| 76 | |
| 77 bool RegisterSafeBrowsingApiBridge(JNIEnv* env) { | 75 bool RegisterSafeBrowsingApiBridge(JNIEnv* env) { |
| 78 return RegisterNativesImpl(env); | 76 return RegisterNativesImpl(env); |
| 79 } | 77 } |
| 80 | 78 |
| 81 // Java->Native call, invoked when a check is done. | 79 // Java->Native call, invoked when a check is done. |
| 82 // |callback_id| is an int form of pointer to a URLCheckCallbackMeta | 80 // |callback_id| is an int form of pointer to a URLCheckCallbackMeta |
| 83 // that will be called and then deleted here. | 81 // that will be called and then deleted here. |
| 84 // |result_status| is one of those from SafeBrowsingApiHandler.java | 82 // |result_status| is one of those from SafeBrowsingApiHandler.java |
| 85 // |metadata| is a JSON string classifying the threat if there is one. | 83 // |metadata| is a JSON string classifying the threat if there is one. |
| 86 void OnUrlCheckDone(JNIEnv* env, | 84 void OnUrlCheckDone(JNIEnv* env, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 RunCallbackOnIOThread(callback.release(), worst_threat, threat_metadata); | 136 RunCallbackOnIOThread(callback.release(), worst_threat, threat_metadata); |
| 139 } | 137 } |
| 140 } | 138 } |
| 141 | 139 |
| 142 // | 140 // |
| 143 // SafeBrowsingApiHandlerBridge | 141 // SafeBrowsingApiHandlerBridge |
| 144 // | 142 // |
| 145 SafeBrowsingApiHandlerBridge::SafeBrowsingApiHandlerBridge() | 143 SafeBrowsingApiHandlerBridge::SafeBrowsingApiHandlerBridge() |
| 146 : checked_api_support_(false) {} | 144 : checked_api_support_(false) {} |
| 147 | 145 |
| 148 SafeBrowsingApiHandlerBridge::~SafeBrowsingApiHandlerBridge() { | 146 SafeBrowsingApiHandlerBridge::~SafeBrowsingApiHandlerBridge() {} |
| 149 } | |
| 150 | 147 |
| 151 bool SafeBrowsingApiHandlerBridge::CheckApiIsSupported() { | 148 bool SafeBrowsingApiHandlerBridge::CheckApiIsSupported() { |
| 152 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 149 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 153 if (!checked_api_support_) { | 150 if (!checked_api_support_) { |
| 154 DVLOG(1) << "Checking API support."; | 151 DVLOG(1) << "Checking API support."; |
| 155 j_api_handler_ = Java_SafeBrowsingApiBridge_create( | 152 j_api_handler_ = Java_SafeBrowsingApiBridge_create(AttachCurrentThread(), |
| 156 AttachCurrentThread(), GetApplicationContext()); | 153 GetApplicationContext()); |
| 157 checked_api_support_ = true; | 154 checked_api_support_ = true; |
| 158 } | 155 } |
| 159 return j_api_handler_.obj() != nullptr; | 156 return j_api_handler_.obj() != nullptr; |
| 160 } | 157 } |
| 161 | 158 |
| 162 void SafeBrowsingApiHandlerBridge::StartURLCheck( | 159 void SafeBrowsingApiHandlerBridge::StartURLCheck( |
| 163 const SafeBrowsingApiHandler::URLCheckCallbackMeta& callback, | 160 const SafeBrowsingApiHandler::URLCheckCallbackMeta& callback, |
| 164 const GURL& url, | 161 const GURL& url, |
| 165 const std::vector<SBThreatType>& threat_types) { | 162 const std::vector<SBThreatType>& threat_types) { |
| 166 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 163 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 190 JNIEnv* env = AttachCurrentThread(); | 187 JNIEnv* env = AttachCurrentThread(); |
| 191 ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, url.spec()); | 188 ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, url.spec()); |
| 192 ScopedJavaLocalRef<jintArray> j_threat_types = | 189 ScopedJavaLocalRef<jintArray> j_threat_types = |
| 193 SBThreatTypesToJavaArray(env, local_threat_types); | 190 SBThreatTypesToJavaArray(env, local_threat_types); |
| 194 | 191 |
| 195 Java_SafeBrowsingApiBridge_startUriLookup(env, j_api_handler_, callback_id, | 192 Java_SafeBrowsingApiBridge_startUriLookup(env, j_api_handler_, callback_id, |
| 196 j_url, j_threat_types); | 193 j_url, j_threat_types); |
| 197 } | 194 } |
| 198 | 195 |
| 199 } // namespace safe_browsing | 196 } // namespace safe_browsing |
| OLD | NEW |