1// Copyright 2012 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 org.chromium.base.CalledByNative;
8import org.chromium.base.JNINamespace;
9
10@JNINamespace("android_webview")
11public class AwHttpAuthHandler {
12
13    private long mNativeAwHttpAuthHandler;
14    private final boolean mFirstAttempt;
15
16    public void proceed(String username, String password) {
17        if (mNativeAwHttpAuthHandler != 0) {
18            nativeProceed(mNativeAwHttpAuthHandler, username, password);
19            mNativeAwHttpAuthHandler = 0;
20        }
21    }
22
23    public void cancel() {
24        if (mNativeAwHttpAuthHandler != 0) {
25            nativeCancel(mNativeAwHttpAuthHandler);
26            mNativeAwHttpAuthHandler = 0;
27        }
28    }
29
30    public boolean isFirstAttempt() {
31         return mFirstAttempt;
32    }
33
34    @CalledByNative
35    public static AwHttpAuthHandler create(long nativeAwAuthHandler, boolean firstAttempt) {
36        return new AwHttpAuthHandler(nativeAwAuthHandler, firstAttempt);
37    }
38
39    private AwHttpAuthHandler(long nativeAwHttpAuthHandler, boolean firstAttempt) {
40        mNativeAwHttpAuthHandler = nativeAwHttpAuthHandler;
41        mFirstAttempt = firstAttempt;
42    }
43
44    @CalledByNative
45    void handlerDestroyed() {
46        mNativeAwHttpAuthHandler = 0;
47    }
48
49    private native void nativeProceed(long nativeAwHttpAuthHandler,
50            String username, String password);
51    private native void nativeCancel(long nativeAwHttpAuthHandler);
52}
53