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