X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=libeap%2Fwpadebug%2Fsrc%2Fw1%2Ffi%2Fwpadebug%2FWpaWebViewActivity.java;fp=libeap%2Fwpadebug%2Fsrc%2Fw1%2Ffi%2Fwpadebug%2FWpaWebViewActivity.java;h=a7c54fc680c9d54ad00d0a8c4dbe74911f9e9420;hb=88e34eecb5769da6526361b35df00fdbe823eac5;hp=0000000000000000000000000000000000000000;hpb=2394142e4bf89e0a9e2a0091ac16bd6442e3d4c7;p=mech_eap.git diff --git a/libeap/wpadebug/src/w1/fi/wpadebug/WpaWebViewActivity.java b/libeap/wpadebug/src/w1/fi/wpadebug/WpaWebViewActivity.java new file mode 100644 index 0000000..a7c54fc --- /dev/null +++ b/libeap/wpadebug/src/w1/fi/wpadebug/WpaWebViewActivity.java @@ -0,0 +1,146 @@ +/* + * wpadebug - wpa_supplicant and Wi-Fi debugging app for Android + * Copyright (c) 2013, Jouni Malinen + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ + +package w1.fi.wpadebug; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.Configuration; +import android.net.http.SslError; +import android.os.Bundle; +import android.util.Log; +import android.view.Window; +import android.webkit.SslErrorHandler; +import android.webkit.WebChromeClient; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.Toast; + +public class WpaWebViewActivity extends Activity +{ + private static final String TAG = "wpadebug"; + private static final String EXTRA_MESSAGE = "w1.fi.wpadebug.URL"; + private WebView mWebView; + final Activity activity = this; + + @Override + public void onCreate(Bundle savedInstanceState) + { + Log.d(TAG, "WpaWebViewActivity::onCreate"); + super.onCreate(savedInstanceState); + + Intent intent = getIntent(); + String url = intent.getStringExtra(EXTRA_MESSAGE); + Log.d(TAG, "url=" + url); + if (url.equals("FINISH")) { + finish(); + return; + } + + mWebView = new WebView(this); + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.setWebViewClient(new WpaWebViewClient()); + + getWindow().requestFeature(Window.FEATURE_PROGRESS); + + mWebView.setWebChromeClient(new WebChromeClient() + { + public void onProgressChanged(WebView view, int progress) + { + Log.d(TAG, "progress=" + progress); + activity.setProgress(progress * 1000); + } + }); + + setContentView(mWebView); + + mWebView.loadUrl(url); + } + + @Override + public void onResume() + { + Log.d(TAG, "WpaWebViewActivity::onResume"); + super.onResume(); + } + + @Override + protected void onNewIntent(Intent intent) + { + Log.d(TAG, "WpaWebViewActivity::onNewIntent"); + super.onNewIntent(intent); + String url = intent.getStringExtra(EXTRA_MESSAGE); + Log.d(TAG, "url=" + url); + setIntent(intent); + if (url.equals("FINISH")) { + finish(); + return; + } + mWebView.loadUrl(url); + } + + private class WpaWebViewClient extends WebViewClient { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) + { + Log.d(TAG, "shouldOverrideUrlLoading: url=" + url); + Intent intent = getIntent(); + intent.putExtra(EXTRA_MESSAGE, url); + + view.loadUrl(url); + return true; + } + + @Override + public void onPageFinished(WebView view, String url) + { + Log.d(TAG, "onPageFinished: url=" + url); + } + + public void onReceivedError(WebView view, int errorCode, + String description, String failingUrl) + { + Log.d(TAG, "Failed to load page: errorCode=" + + errorCode + " description=" + description + + " URL=" + failingUrl); + Toast.makeText(activity, "Failed to load page: " + + description + " (URL=" + failingUrl + ")", + Toast.LENGTH_LONG).show(); + } + + @Override + public void onReceivedSslError(WebView view, SslErrorHandler handler, + SslError error) + { + Log.d(TAG, "SSL error: " + error); + + final SslErrorHandler h = handler; + AlertDialog.Builder alert = new AlertDialog.Builder(activity); + alert.setTitle("SSL error - Continue?"); + alert.setMessage(error.toString()) + .setCancelable(false) + .setPositiveButton("Yes", new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int id) + { + h.proceed(); + } + }) + .setNegativeButton("No", new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int id) + { + h.cancel(); + } + }); + alert.show(); + } + } +}