added http proxy authentication (see #819)
This commit is contained in:
parent
4781ea9627
commit
578c367f5b
62
mobile/res/layout/http_authentication.xml
Normal file
62
mobile/res/layout/http_authentication.xml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="@string/username"
|
||||||
|
android:layout_marginTop="12dip"
|
||||||
|
android:layout_marginLeft="20dip"
|
||||||
|
android:layout_marginRight="20dip" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/username_edit"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:scrollHorizontally="true"
|
||||||
|
android:inputType="text"
|
||||||
|
android:layout_marginLeft="20dip"
|
||||||
|
android:layout_marginRight="20dip"
|
||||||
|
android:layout_marginBottom="12dip"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:imeOptions="actionNext" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="@string/password"
|
||||||
|
android:layout_marginLeft="20dip"
|
||||||
|
android:layout_marginRight="20dip" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/password_edit"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:scrollHorizontally="true"
|
||||||
|
android:inputType="textPassword"
|
||||||
|
android:layout_marginLeft="20dip"
|
||||||
|
android:layout_marginRight="20dip"
|
||||||
|
android:layout_marginBottom="12dip"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:imeOptions="actionDone" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -219,6 +219,23 @@
|
|||||||
<string name="msg_copied">Copied to clipboard…</string>
|
<string name="msg_copied">Copied to clipboard…</string>
|
||||||
<string name="notice_do_not_show_again">Do not show again</string>
|
<string name="notice_do_not_show_again">Do not show again</string>
|
||||||
|
|
||||||
|
<!-- Sign-in dialog -->
|
||||||
|
<string name="sign_in_to">Sign in to %1$s %2$s"</string>
|
||||||
|
<!-- Prompt for an input box that allows the user to enter their login name -->
|
||||||
|
<string name="username">Name</string>
|
||||||
|
<!-- Prompt for an input box that allows the user to enter their password -->
|
||||||
|
<string name="password">Password</string>
|
||||||
|
<!-- The label on the "sign in" button -->
|
||||||
|
<string name="action">Sign in</string>
|
||||||
|
<!-- The name of the add bookmark page activity.-->
|
||||||
|
<string name="bookmarks_add_page">Save bookmark</string>
|
||||||
|
<!-- The name of the bookmarks and history search suggestion source. -->
|
||||||
|
<string name="bookmarks_search">Browser</string>
|
||||||
|
<!-- Label for a cancel button. It is used for multiple cancel buttons in different contexts -->
|
||||||
|
<string name="cancel">Cancel</string>
|
||||||
|
<!-- Label for a confirm button. Used in multiple contexts. -->
|
||||||
|
<string name="ok">OK</string>
|
||||||
|
|
||||||
<string name="tab_map">Locate</string>
|
<string name="tab_map">Locate</string>
|
||||||
<string name="tab_share">Share</string>
|
<string name="tab_share">Share</string>
|
||||||
<string name="tab_browser">Intel</string>
|
<string name="tab_browser">Intel</string>
|
||||||
|
166
mobile/src/com/cradle/iitc_mobile/HttpAuthenticationDialog.java
Normal file
166
mobile/src/com/cradle/iitc_mobile/HttpAuthenticationDialog.java
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP authentication dialog.
|
||||||
|
*/
|
||||||
|
public class HttpAuthenticationDialog {
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
private final String mHost;
|
||||||
|
private final String mRealm;
|
||||||
|
|
||||||
|
private AlertDialog mDialog;
|
||||||
|
private TextView mUsernameView;
|
||||||
|
private TextView mPasswordView;
|
||||||
|
|
||||||
|
private OkListener mOkListener;
|
||||||
|
private CancelListener mCancelListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an HTTP authentication dialog.
|
||||||
|
*/
|
||||||
|
public HttpAuthenticationDialog(Context context, String host, String realm) {
|
||||||
|
mContext = context;
|
||||||
|
mHost = host;
|
||||||
|
mRealm = realm;
|
||||||
|
createDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getUsername() {
|
||||||
|
return mUsernameView.getText().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPassword() {
|
||||||
|
return mPasswordView.getText().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the listener that will be notified when the user submits the credentials.
|
||||||
|
*/
|
||||||
|
public void setOkListener(OkListener okListener) {
|
||||||
|
mOkListener = okListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the listener that will be notified when the user cancels the authentication
|
||||||
|
* dialog.
|
||||||
|
*/
|
||||||
|
public void setCancelListener(CancelListener cancelListener) {
|
||||||
|
mCancelListener = cancelListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the dialog.
|
||||||
|
*/
|
||||||
|
public void show() {
|
||||||
|
mDialog.show();
|
||||||
|
mUsernameView.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hides, recreates, and shows the dialog. This can be used to handle configuration changes.
|
||||||
|
*/
|
||||||
|
public void reshow() {
|
||||||
|
String username = getUsername();
|
||||||
|
String password = getPassword();
|
||||||
|
int focusId = mDialog.getCurrentFocus().getId();
|
||||||
|
mDialog.dismiss();
|
||||||
|
createDialog();
|
||||||
|
mDialog.show();
|
||||||
|
if (username != null) {
|
||||||
|
mUsernameView.setText(username);
|
||||||
|
}
|
||||||
|
if (password != null) {
|
||||||
|
mPasswordView.setText(password);
|
||||||
|
}
|
||||||
|
if (focusId != 0) {
|
||||||
|
mDialog.findViewById(focusId).requestFocus();
|
||||||
|
} else {
|
||||||
|
mUsernameView.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createDialog() {
|
||||||
|
LayoutInflater factory = LayoutInflater.from(mContext);
|
||||||
|
View v = factory.inflate(R.layout.http_authentication, null);
|
||||||
|
mUsernameView = (TextView) v.findViewById(R.id.username_edit);
|
||||||
|
mPasswordView = (TextView) v.findViewById(R.id.password_edit);
|
||||||
|
mPasswordView.setOnEditorActionListener(new OnEditorActionListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||||
|
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
String title = mContext.getText(R.string.sign_in_to).toString();
|
||||||
|
title = String.format(title, mHost, mRealm);
|
||||||
|
|
||||||
|
mDialog = new AlertDialog.Builder(mContext)
|
||||||
|
.setTitle(title)
|
||||||
|
.setIconAttribute(android.R.attr.alertDialogIcon)
|
||||||
|
.setView(v)
|
||||||
|
.setPositiveButton(R.string.action, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
if (mOkListener != null) {
|
||||||
|
mOkListener.onOk(mHost, mRealm, getUsername(), getPassword());
|
||||||
|
}
|
||||||
|
}})
|
||||||
|
.setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
if (mCancelListener != null) mCancelListener.onCancel();
|
||||||
|
}})
|
||||||
|
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
if (mCancelListener != null) mCancelListener.onCancel();
|
||||||
|
}})
|
||||||
|
.create();
|
||||||
|
|
||||||
|
// Make the IME appear when the dialog is displayed if applicable.
|
||||||
|
mDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for listeners that are notified when the user submits the credentials.
|
||||||
|
*/
|
||||||
|
public interface OkListener {
|
||||||
|
void onOk(String host, String realm, String username, String password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for listeners that are notified when the user cancels the dialog.
|
||||||
|
*/
|
||||||
|
public interface CancelListener {
|
||||||
|
void onCancel();
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,7 @@ import android.view.Window;
|
|||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.webkit.CookieManager;
|
import android.webkit.CookieManager;
|
||||||
|
import android.webkit.HttpAuthHandler;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
|
import android.app.ActionBar;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -7,6 +8,7 @@ import android.net.http.SslError;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.webkit.HttpAuthHandler;
|
||||||
import android.webkit.SslErrorHandler;
|
import android.webkit.SslErrorHandler;
|
||||||
import android.webkit.WebResourceResponse;
|
import android.webkit.WebResourceResponse;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -168,6 +170,44 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler,
|
||||||
|
final String host, final String realm) {
|
||||||
|
String username = null;
|
||||||
|
String password = null;
|
||||||
|
|
||||||
|
boolean reuseHttpAuthUsernamePassword
|
||||||
|
= handler.useHttpAuthUsernamePassword();
|
||||||
|
|
||||||
|
if (reuseHttpAuthUsernamePassword && view != null) {
|
||||||
|
String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
|
||||||
|
if (credentials != null && credentials.length == 2) {
|
||||||
|
username = credentials[0];
|
||||||
|
password = credentials[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (username != null && password != null) {
|
||||||
|
handler.proceed(username, password);
|
||||||
|
} else {
|
||||||
|
HttpAuthenticationDialog dialog = new HttpAuthenticationDialog(mIitc, host, realm);
|
||||||
|
|
||||||
|
dialog.setOkListener(new HttpAuthenticationDialog.OkListener() {
|
||||||
|
public void onOk(String host, String realm, String username, String password) {
|
||||||
|
handler.proceed(username, password);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.setCancelListener(new HttpAuthenticationDialog.CancelListener() {
|
||||||
|
public void onCancel() {
|
||||||
|
handler.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
mIitcInjected = false;
|
mIitcInjected = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user