EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.android_webview]

COVERAGE SUMMARY FOR SOURCE FILE [AwContentsClientBridge.java]

nameclass, %method, %block, %line, %
AwContentsClientBridge.java50%  (1/2)64%  (9/14)58%  (92/158)63%  (23.8/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AwContentsClientBridge$10%   (0/1)0%   (0/2)0%   (0/17)0%   (0/3)
AwContentsClientBridge$1 (AwContentsClientBridge, int): void 0%   (0/1)0%   (0/9)0%   (0/1)
onReceiveValue (Boolean): void 0%   (0/1)0%   (0/8)0%   (0/2)
     
class AwContentsClientBridge100% (1/1)75%  (9/12)65%  (92/141)66%  (23.8/36)
access$000 (AwContentsClientBridge, boolean, int): void 0%   (0/1)0%   (0/5)0%   (0/1)
allowCertificateError (int, byte [], String, int): boolean 0%   (0/1)0%   (0/25)0%   (0/7)
proceedSslError (boolean, int): void 0%   (0/1)0%   (0/11)0%   (0/3)
AwContentsClientBridge (AwContentsClient): void 100% (1/1)71%  (10/14)90%  (3.6/4)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
cancelJsResult (int): void 100% (1/1)90%  (9/10)92%  (2.8/3)
confirmJsResult (int, String): void 100% (1/1)91%  (10/11)92%  (2.8/3)
handleJsAlert (String, String, int): void 100% (1/1)100% (13/13)100% (3/3)
handleJsBeforeUnload (String, String, int): void 100% (1/1)100% (13/13)100% (3/3)
handleJsConfirm (String, String, int): void 100% (1/1)100% (13/13)100% (3/3)
handleJsPrompt (String, String, String, int): void 100% (1/1)100% (14/14)100% (3/3)
setNativeContentsClientBridge (int): void 100% (1/1)100% (4/4)100% (2/2)

1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4 
5package org.chromium.android_webview;
6 
7import android.net.http.SslCertificate;
8import android.net.http.SslError;
9import android.webkit.ValueCallback;
10 
11import org.chromium.base.CalledByNative;
12import org.chromium.base.JNINamespace;
13import org.chromium.base.ThreadUtils;
14 
15/**
16 * This class handles the JNI communication logic for the the AwContentsClient class.
17 * Both the Java and the native peers of AwContentsClientBridge are owned by the
18 * corresponding AwContents instances. This class and its native peer are connected
19 * via weak references. The native AwContentsClientBridge sets up and clear these weak
20 * references.
21 */
22@JNINamespace("android_webview")
23public class AwContentsClientBridge {
24 
25    private AwContentsClient mClient;
26    // The native peer of this object.
27    private int mNativeContentsClientBridge;
28 
29    public AwContentsClientBridge(AwContentsClient client) {
30        assert client != null;
31        mClient = client;
32    }
33 
34    // Used by the native peer to set/reset a weak ref to the native peer.
35    @CalledByNative
36    private void setNativeContentsClientBridge(int nativeContentsClientBridge) {
37        mNativeContentsClientBridge = nativeContentsClientBridge;
38    }
39 
40    // If returns false, the request is immediately canceled, and any call to proceedSslError
41    // has no effect. If returns true, the request should be canceled or proceeded using
42    // proceedSslError().
43    // Unlike the webview classic, we do not keep keep a database of certificates that
44    // are allowed by the user, because this functionality is already handled via
45    // ssl_policy in native layers.
46    @CalledByNative
47    private boolean allowCertificateError(int certError, byte[] derBytes, final String url,
48            final int id) {
49        final SslCertificate cert = SslUtil.getCertificateFromDerBytes(derBytes);
50        if (cert == null) {
51            // if the certificate or the client is null, cancel the request
52            return false;
53        }
54        final SslError sslError = SslUtil.sslErrorFromNetErrorCode(certError, cert, url);
55        ValueCallback<Boolean> callback = new ValueCallback<Boolean>() {
56            @Override
57            public void onReceiveValue(Boolean value) {
58                proceedSslError(value.booleanValue(), id);
59            }
60        };
61        mClient.onReceivedSslError(callback, sslError);
62        return true;
63    }
64 
65    private void proceedSslError(boolean proceed, int id) {
66        if (mNativeContentsClientBridge == 0) return;
67        nativeProceedSslError(mNativeContentsClientBridge, proceed, id);
68    }
69 
70    @CalledByNative
71    private void handleJsAlert(String url, String message, int id) {
72        JsResultHandler handler = new JsResultHandler(this, id);
73        mClient.handleJsAlert(url, message, handler);
74    }
75 
76    @CalledByNative
77    private void handleJsConfirm(String url, String message, int id) {
78        JsResultHandler handler = new JsResultHandler(this, id);
79        mClient.handleJsConfirm(url, message, handler);
80    }
81 
82    @CalledByNative
83    private void handleJsPrompt(String url, String message, String defaultValue, int id) {
84        JsResultHandler handler = new JsResultHandler(this, id);
85        mClient.handleJsPrompt(url, message, defaultValue, handler);
86    }
87 
88    @CalledByNative
89    private void handleJsBeforeUnload(String url, String message, int id) {
90        JsResultHandler handler = new JsResultHandler(this, id);
91        mClient.handleJsBeforeUnload(url, message, handler);
92    }
93 
94    void confirmJsResult(int id, String prompt) {
95        if (mNativeContentsClientBridge == 0) return;
96        nativeConfirmJsResult(mNativeContentsClientBridge, id, prompt);
97    }
98 
99    void cancelJsResult(int id) {
100        if (mNativeContentsClientBridge == 0) return;
101        nativeCancelJsResult(mNativeContentsClientBridge, id);
102    }
103 
104    //--------------------------------------------------------------------------------------------
105    //  Native methods
106    //--------------------------------------------------------------------------------------------
107    private native void nativeProceedSslError(int nativeAwContentsClientBridge, boolean proceed,
108            int id);
109 
110    private native void nativeConfirmJsResult(int nativeAwContentsClientBridge, int id,
111            String prompt);
112    private native void nativeCancelJsResult(int nativeAwContentsClientBridge, int id);
113}

[all classes][org.chromium.android_webview]
EMMA 2.0.5312 (C) Vladimir Roubtsov