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