Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1600)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ChromeHttpAuthHandler.java

Issue 10821116: Upstream ChromeHttpAuthHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Check DEPS fix (working this time) Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ChromeHttpAuthHandler.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeHttpAuthHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeHttpAuthHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..a298c27cbdcba1773a1abd0d23ff41137b878277
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeHttpAuthHandler.java
@@ -0,0 +1,129 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.content.browser.ContentHttpAuthHandler;
+
+/**
+ * Represents an HTTP authentication request to be handled by the UI.
+ * The request can be fulfilled or canceled using setAuth() or cancelAuth().
+ * This class also provides strings for building a login form.
+ *
+ * Note: this class supercedes android.webkit.HttpAuthHandler, but does not
+ * extend HttpAuthHandler due to the private access of HttpAuthHandler's
+ * constructor.
+ */
+public class ChromeHttpAuthHandler implements ContentHttpAuthHandler {
+ private final int mNativeChromeHttpAuthHandler;
+ private AutofillObserver mAutofillObserver;
+ private String mAutofillUsername;
+ private String mAutofillPassword;
+
+ private ChromeHttpAuthHandler(int nativeChromeHttpAuthHandler) {
+ assert nativeChromeHttpAuthHandler != 0;
+ mNativeChromeHttpAuthHandler = nativeChromeHttpAuthHandler;
+ }
+
+ @CalledByNative
+ private static ChromeHttpAuthHandler create(int nativeChromeHttpAuthHandler) {
+ return new ChromeHttpAuthHandler(nativeChromeHttpAuthHandler);
+ }
+
+ // ---------------------------------------------
+ // HttpAuthHandler methods
+ // ---------------------------------------------
+
+ // Note on legacy useHttpAuthUsernamePassword() method:
Yaron 2012/08/02 20:50:24 Nit: odd comment style. Please fix.
+ // * For reference, the existing WebView (when using the chromium stack) returns true here
+ // iff this is the first auth challenge attempt for this connection.
+ // (see WebUrlLoaderClient::authRequired call to didReceiveAuthenticationChallenge)
+ // * In ChromeHttpAuthHandler this mechanism is superseded by the
+ // AutofillObserver.onAutofillDataAvailable mechanism below, however the legacy WebView
+ // implementation will need to handle the API mismatch between the legacy
+ // WebView.getHttpAuthUsernamePassword synchronous call and the credentials arriving
+ // asynchronously in onAutofillDataAvailable.
+
+ /**
+ * Cancel the authorization request.
+ */
+ public void cancel() {
+ nativeCancelAuth(mNativeChromeHttpAuthHandler);
+ }
+
+ /**
+ * Proceed with the authorization with the given credentials.
+ */
+ public void proceed(String username, String password) {
+ nativeSetAuth(mNativeChromeHttpAuthHandler, username, password);
+ }
+
+ public String getMessageTitle() {
+ return nativeGetMessageTitle(mNativeChromeHttpAuthHandler);
+ }
+
+ public String getMessageBody() {
+ return nativeGetMessageBody(mNativeChromeHttpAuthHandler);
+ }
+
+ public String getUsernameLabelText() {
+ return nativeGetUsernameLabelText(mNativeChromeHttpAuthHandler);
+ }
+
+ public String getPasswordLabelText() {
+ return nativeGetPasswordLabelText(mNativeChromeHttpAuthHandler);
+ }
+
+ public String getOkButtonText() {
+ return nativeGetOkButtonText(mNativeChromeHttpAuthHandler);
+ }
+
+ public String getCancelButtonText() {
+ return nativeGetCancelButtonText(mNativeChromeHttpAuthHandler);
+ }
+
+ // ---------------------------------------------
+ // Autofill-related
+ // ---------------------------------------------
+
+ public static interface AutofillObserver {
Yaron 2012/08/02 20:50:24 You should document this interface better. It seem
+ public void onAutofillDataAvailable(String username, String password);
+ }
+
+ /**
+ * Register for onAutofillDataAvailable callbacks. |observer| can be null,
+ * in which case no callback is made.
+ */
+ public void setAutofillObserver(AutofillObserver observer) {
+ mAutofillObserver = observer;
+ // In case the autofill data arrives before the observer is set.
+ if (mAutofillUsername != null && mAutofillPassword != null) {
+ mAutofillObserver.onAutofillDataAvailable(mAutofillUsername, mAutofillPassword);
+ }
+ }
+
+ @CalledByNative
+ private void onAutofillDataAvailable(String username, String password) {
+ mAutofillUsername = username;
+ mAutofillPassword = password;
+ if (mAutofillObserver != null) {
+ mAutofillObserver.onAutofillDataAvailable(username, password);
+ }
+ }
+
+ // ---------------------------------------------
+ // Native side calls
+ // ---------------------------------------------
+
+ private native void nativeSetAuth(int nativeChromeHttpAuthHandler,
Yaron 2012/08/02 20:50:24 Nit: sort
+ String username, String password);
+ private native void nativeCancelAuth(int nativeChromeHttpAuthHandler);
+ private native String nativeGetMessageTitle(int nativeChromeHttpAuthHandler);
+ private native String nativeGetMessageBody(int nativeChromeHttpAuthHandler);
+ private native String nativeGetUsernameLabelText(int nativeChromeHttpAuthHandler);
+ private native String nativeGetPasswordLabelText(int nativeChromeHttpAuthHandler);
+ private native String nativeGetOkButtonText(int nativeChromeHttpAuthHandler);
+ private native String nativeGetCancelButtonText(int nativeChromeHttpAuthHandler);
+}

Powered by Google App Engine
This is Rietveld 408576698