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 package org.chromium.components.safe_browsing; | 5 package org.chromium.components.safe_browsing; |
6 | 6 |
7 import android.content.Context; | 7 import org.chromium.base.ContextUtils; |
8 | |
9 import org.chromium.base.Log; | 8 import org.chromium.base.Log; |
10 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
11 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
12 | 11 |
13 /** | 12 /** |
14 * Helper for calling GMSCore Safe Browsing API from native code. | 13 * Helper for calling GMSCore Safe Browsing API from native code. |
15 */ | 14 */ |
16 @JNINamespace("safe_browsing") | 15 @JNINamespace("safe_browsing") |
17 public final class SafeBrowsingApiBridge { | 16 public final class SafeBrowsingApiBridge { |
18 private static final String TAG = "ApiBridge"; | 17 private static final String TAG = "ApiBridge"; |
(...skipping 12 matching lines...) Expand all Loading... |
31 sHandler = handler; | 30 sHandler = handler; |
32 } | 31 } |
33 | 32 |
34 /** | 33 /** |
35 * Create a SafeBrowsingApiHandler obj and initialize its client, if support
ed. | 34 * Create a SafeBrowsingApiHandler obj and initialize its client, if support
ed. |
36 * Should be called on IO thread. | 35 * Should be called on IO thread. |
37 * | 36 * |
38 * @return the handler if it's usable, or null if the API is not supported. | 37 * @return the handler if it's usable, or null if the API is not supported. |
39 */ | 38 */ |
40 @CalledByNative | 39 @CalledByNative |
41 private static SafeBrowsingApiHandler create(Context context) { | 40 private static SafeBrowsingApiHandler create() { |
42 SafeBrowsingApiHandler handler; | 41 SafeBrowsingApiHandler handler; |
43 try { | 42 try { |
44 handler = sHandler.newInstance(); | 43 handler = sHandler.newInstance(); |
45 } catch (NullPointerException | InstantiationException | IllegalAccessEx
ception e) { | 44 } catch (NullPointerException | InstantiationException | IllegalAccessEx
ception e) { |
46 Log.e(TAG, "Failed to init handler: " + e.getMessage()); | 45 Log.e(TAG, "Failed to init handler: " + e.getMessage()); |
47 return null; | 46 return null; |
48 } | 47 } |
49 boolean initSuccesssful = handler.init(context, new SafeBrowsingApiHandl
er.Observer() { | 48 boolean initSuccesssful = handler.init( |
50 @Override | 49 ContextUtils.getApplicationContext(), new SafeBrowsingApiHandler
.Observer() { |
51 public void onUrlCheckDone(long callbackId, int resultStatus, String
metadata) { | 50 @Override |
52 nativeOnUrlCheckDone(callbackId, resultStatus, metadata); | 51 public void onUrlCheckDone(long callbackId, int resultStatus
, String metadata) { |
53 } | 52 nativeOnUrlCheckDone(callbackId, resultStatus, metadata)
; |
54 }); | 53 } |
| 54 }); |
55 return initSuccesssful ? handler : null; | 55 return initSuccesssful ? handler : null; |
56 } | 56 } |
57 | 57 |
58 @CalledByNative | 58 @CalledByNative |
59 private static void startUriLookup( | 59 private static void startUriLookup( |
60 SafeBrowsingApiHandler handler, long callbackId, String uri, int[] t
hreatsOfInterest) { | 60 SafeBrowsingApiHandler handler, long callbackId, String uri, int[] t
hreatsOfInterest) { |
61 handler.startUriLookup(callbackId, uri, threatsOfInterest); | 61 handler.startUriLookup(callbackId, uri, threatsOfInterest); |
62 Log.d(TAG, "Done starting request"); | 62 Log.d(TAG, "Done starting request"); |
63 } | 63 } |
64 | 64 |
65 private static native void nativeOnUrlCheckDone( | 65 private static native void nativeOnUrlCheckDone( |
66 long callbackId, int resultStatus, String metadata); | 66 long callbackId, int resultStatus, String metadata); |
67 } | 67 } |
OLD | NEW |