Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / android / chrome_http_auth_handler.h
blob4be4031097d814311ab2f83366f539fbe6ed9b0e
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.
5 #ifndef CHROME_BROWSER_UI_ANDROID_CHROME_HTTP_AUTH_HANDLER_H_
6 #define CHROME_BROWSER_UI_ANDROID_CHROME_HTTP_AUTH_HANDLER_H_
8 #include <jni.h>
10 #include "base/android/scoped_java_ref.h"
11 #include "base/strings/string16.h"
12 #include "chrome/browser/ui/login/login_prompt.h"
14 // This class facilitates communication between a native LoginHandler
15 // and a Java land ChromeHttpAuthHandler, which is passed to a
16 // ContentViewClient to allow it to respond to HTTP authentication requests
17 // by, e.g., showing the user a login dialog.
18 class ChromeHttpAuthHandler {
19 public:
20 explicit ChromeHttpAuthHandler(const base::string16& explanation);
21 ~ChromeHttpAuthHandler();
23 // This must be called before using the object.
24 // Constructs a corresponding Java land ChromeHttpAuthHandler.
25 void Init();
27 // Registers an observer to receive callbacks when SetAuth() and CancelAuth()
28 // are called. |observer| may be NULL in which case the callbacks are skipped.
29 void SetObserver(LoginHandler* observer);
31 // Show the dialog prompting for login credentials.
32 void ShowDialog(jobject window_android);
34 // Forwards the autofill data to the Java land object.
35 void OnAutofillDataAvailable(
36 const base::string16& username,
37 const base::string16& password);
39 // --------------------------------------------------------------
40 // JNI Methods
41 // --------------------------------------------------------------
43 // Submits the username and password to the observer.
44 void SetAuth(JNIEnv* env, jobject, jstring username, jstring password);
46 // Cancels the authentication attempt of the observer.
47 void CancelAuth(JNIEnv* env, jobject);
49 // These functions return the strings needed to display a login form.
50 base::android::ScopedJavaLocalRef<jstring> GetMessageBody(
51 JNIEnv* env, jobject);
52 // Registers the ChromeHttpAuthHandler native methods.
53 static bool RegisterChromeHttpAuthHandler(JNIEnv* env);
54 private:
55 LoginHandler* observer_;
56 base::android::ScopedJavaGlobalRef<jobject> java_chrome_http_auth_handler_;
57 // e.g. "The server example.com:80 requires a username and password."
58 base::string16 explanation_;
60 DISALLOW_COPY_AND_ASSIGN(ChromeHttpAuthHandler);
63 #endif // CHROME_BROWSER_UI_ANDROID_CHROME_HTTP_AUTH_HANDLER_H_