Upstream version 8.36.161.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core_internal / src / org / xwalk / core / internal / XWalkHttpAuthHandler.java
1 // Copyright (c) 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
5 package org.xwalk.core.internal;
6
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace;
9
10 /**
11  * It's for http auth handling.
12  * @hide
13  */
14 @JNINamespace("xwalk")
15 public class XWalkHttpAuthHandler {
16
17     private long mNativeXWalkHttpAuthHandler;
18     private final boolean mFirstAttempt;
19
20     public void proceed(String username, String password) {
21         if (mNativeXWalkHttpAuthHandler != 0) {
22             nativeProceed(mNativeXWalkHttpAuthHandler, username, password);
23             mNativeXWalkHttpAuthHandler = 0;
24         }
25     }
26
27     public void cancel() {
28         if (mNativeXWalkHttpAuthHandler != 0) {
29             nativeCancel(mNativeXWalkHttpAuthHandler);
30             mNativeXWalkHttpAuthHandler = 0;
31         }
32     }
33
34     public boolean isFirstAttempt() {
35          return mFirstAttempt;
36     }
37
38     @CalledByNative
39     public static XWalkHttpAuthHandler create(long nativeXWalkAuthHandler, boolean firstAttempt) {
40         return new XWalkHttpAuthHandler(nativeXWalkAuthHandler, firstAttempt);
41     }
42
43     private XWalkHttpAuthHandler(long nativeXWalkHttpAuthHandler, boolean firstAttempt) {
44         mNativeXWalkHttpAuthHandler = nativeXWalkHttpAuthHandler;
45         mFirstAttempt = firstAttempt;
46     }
47
48     @CalledByNative
49     void handlerDestroyed() {
50         mNativeXWalkHttpAuthHandler = 0;
51     }
52
53     private native void nativeProceed(long nativeXWalkHttpAuthHandler,
54             String username, String password);
55     private native void nativeCancel(long nativeXWalkHttpAuthHandler);
56 }
57