Skip to content

Commit d12c2d5

Browse files
committed
Make mini-browser better - fixes for #373
* use preferred cookiemanager stuff for new non-deprecated api * fix pinch-to-zoom * add URL bar * add status/progress bar Quick and dirty. Still not 100%, but better.
1 parent de4bcec commit d12c2d5

2 files changed

Lines changed: 121 additions & 22 deletions

File tree

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="fill_parent"
4-
android:layout_height="fill_parent"
5-
android:orientation="vertical">
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical">
6+
7+
<ProgressBar
8+
android:id="@+id/webprogress"
9+
style="?android:attr/progressBarStyleHorizontal"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:layout_alignParentRight="true"
13+
android:layout_alignParentTop="true"
14+
android:maxHeight="4dp"
15+
android:visibility="visible"
16+
android:layout_marginTop="-6dp"/>
17+
18+
<EditText
19+
android:id="@+id/url"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:layout_alignParentLeft="true"
23+
android:layout_alignParentStart="true"
24+
android:layout_alignParentTop="true"
25+
android:background="@android:color/transparent"
26+
android:singleLine="true"
27+
android:layout_marginLeft="6dp"
28+
android:layout_marginStart="6dp"
29+
android:translationZ="-6dp"/>
630

731
<WebView
8-
android:id="@+id/webView"
9-
android:layout_width="match_parent"
10-
android:layout_height="match_parent"
11-
android:layout_alignParentLeft="true"
12-
android:layout_alignParentTop="true"/>
32+
android:id="@+id/webView"
33+
android:layout_width="match_parent"
34+
android:layout_height="match_parent"
35+
android:layout_alignParentEnd="true"
36+
android:layout_alignParentBottom="true"
37+
android:layout_alignParentRight="true"
38+
android:layout_below="@+id/url" />
1339

1440
</RelativeLayout>

cSploit/src/org/csploit/android/plugins/mitm/hijacker/HijackerWebView.java

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,29 @@
1818
*/
1919
package org.csploit.android.plugins.mitm.hijacker;
2020

21+
import android.content.Context;
2122
import android.content.SharedPreferences;
23+
import android.os.Build;
2224
import android.os.Bundle;
2325
import android.support.v7.app.AppCompatActivity;
2426
import android.util.Patterns;
27+
import android.view.KeyEvent;
2528
import android.view.Menu;
2629
import android.view.MenuInflater;
2730
import android.view.MenuItem;
31+
import android.view.View;
2832
import android.view.Window;
33+
import android.view.inputmethod.EditorInfo;
34+
import android.view.inputmethod.InputMethodManager;
2935
import android.webkit.CookieManager;
3036
import android.webkit.CookieSyncManager;
3137
import android.webkit.WebChromeClient;
3238
import android.webkit.WebSettings;
3339
import android.webkit.WebView;
3440
import android.webkit.WebViewClient;
41+
import android.widget.EditText;
42+
import android.widget.ProgressBar;
43+
import android.widget.TextView;
3544

3645
import org.csploit.android.R;
3746
import org.csploit.android.core.System;
@@ -43,6 +52,8 @@ public class HijackerWebView extends AppCompatActivity {
4352

4453
private WebSettings mSettings = null;
4554
private WebView mWebView = null;
55+
private ProgressBar mProgressBar = null;
56+
private EditText mURLet = null;
4657

4758
@Override
4859
protected void onCreate(Bundle savedInstanceState) {
@@ -58,42 +69,88 @@ protected void onCreate(Bundle savedInstanceState) {
5869
setTitle(System.getCurrentTarget() + " > MITM > Session Hijacker");
5970
setContentView(R.layout.plugin_mitm_hijacker_webview);
6071
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
61-
setSupportProgressBarIndeterminateVisibility(false);
6272

6373
mWebView = (WebView) findViewById(R.id.webView);
74+
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
75+
mProgressBar = (ProgressBar) findViewById(R.id.webprogress);
76+
mURLet = (EditText) findViewById(R.id.url);
77+
mProgressBar.setVisibility(View.GONE);
78+
mProgressBar.setMax(100);
6479
mSettings = mWebView.getSettings();
6580

6681
mSettings.setJavaScriptEnabled(true);
82+
mSettings.setJavaScriptCanOpenWindowsAutomatically(true);
6783
mSettings.setBuiltInZoomControls(true);
6884
mSettings.setAppCacheEnabled(false);
6985
mSettings.setUserAgentString(DEFAULT_USER_AGENT);
86+
mSettings.setUseWideViewPort(true);
87+
88+
mURLet.setOnEditorActionListener(new EditText.OnEditorActionListener() {
89+
@Override
90+
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
91+
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT) {
92+
mWebView.loadUrl(mURLet.getText().toString());
93+
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
94+
imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
95+
mWebView.requestFocus();
96+
return true;
97+
}
98+
return false;
99+
}
100+
});
101+
102+
mURLet.setOnKeyListener(new EditText.OnKeyListener() {
103+
@Override
104+
public boolean onKey(View v, int keyCode, KeyEvent event) {
105+
if (event.getAction() == KeyEvent.ACTION_DOWN
106+
&& event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
107+
mWebView.loadUrl(mURLet.getText().toString());
108+
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
109+
imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
110+
mWebView.requestFocus();
111+
return true;
112+
}
113+
return false;
114+
}
115+
});
70116

71117
mWebView.setWebViewClient(new WebViewClient() {
72118
@Override
73119
public boolean shouldOverrideUrlLoading(WebView view, String url) {
74120
view.loadUrl(url);
121+
mURLet.setText(url);
75122
return true;
76123
}
77124
});
78125

79126
mWebView.setWebChromeClient(new WebChromeClient() {
127+
80128
public void onProgressChanged(WebView view, int progress) {
81-
if (mWebView != null)
129+
if ((mWebView != null) && (mURLet != null) && (progress == 0)); {
82130
getSupportActionBar().setSubtitle(mWebView.getUrl());
131+
mURLet.setText(mWebView.getUrl());
132+
}
83133

84-
setSupportProgressBarIndeterminateVisibility(true);
85-
// Normalize our progress along the progress bar's scale
86-
int mmprogress = (Window.PROGRESS_END - Window.PROGRESS_START)
87-
/ 100 * progress;
88-
setProgress(mmprogress);
134+
if (mProgressBar != null) {
135+
mProgressBar.setVisibility(View.VISIBLE);
136+
// Normalize our progress along the progress bar's scale
89137

90-
if (progress == 100)
91-
setSupportProgressBarIndeterminateVisibility(false);
138+
mProgressBar.setProgress(progress);
139+
140+
if (progress == 100) {
141+
mProgressBar.setVisibility(View.GONE);
142+
}
143+
}
92144
}
93145
});
94146

95-
CookieSyncManager.createInstance(this);
96-
CookieManager.getInstance().removeAllCookie();
147+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
148+
CookieManager cm = CookieManager.getInstance();
149+
cm.flush();
150+
} else {
151+
CookieSyncManager.createInstance(this);
152+
CookieManager.getInstance().removeAllCookie();
153+
}
97154

98155
Session session = (Session) System.getCustomData();
99156
if (session != null) {
@@ -108,7 +165,12 @@ public void onProgressChanged(WebView view, int progress) {
108165
CookieManager.getInstance().setCookie(domain, rawcookie);
109166
}
110167

111-
CookieSyncManager.getInstance().sync();
168+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
169+
CookieManager cm = CookieManager.getInstance();
170+
cm.flush();
171+
} else {
172+
CookieSyncManager.getInstance().startSync();
173+
}
112174

113175
if (session.mUserAgent != null
114176
&& session.mUserAgent.isEmpty() == false)
@@ -122,21 +184,32 @@ public void onProgressChanged(WebView view, int progress) {
122184
url += domain;
123185

124186
mWebView.loadUrl(url);
187+
mWebView.requestFocus();
125188
}
126189
}
127190

128191
@Override
129192
protected void onResume() {
130193
super.onResume();
131194

132-
CookieSyncManager.getInstance().startSync();
195+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
196+
CookieManager cm = CookieManager.getInstance();
197+
cm.flush();
198+
} else {
199+
CookieSyncManager.getInstance().startSync();
200+
}
133201
}
134202

135203
@Override
136204
protected void onPause() {
137205
super.onPause();
138206

139-
CookieSyncManager.getInstance().stopSync();
207+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
208+
CookieManager cm = CookieManager.getInstance();
209+
cm.flush();
210+
} else {
211+
CookieSyncManager.getInstance().startSync();
212+
}
140213
}
141214

142215
@Override

0 commit comments

Comments
 (0)