use of android.net.ParseException in project android_frameworks_base by crdroidandroid.
the class URLUtil method guessUrl.
/**
* Cleans up (if possible) user-entered web addresses
*/
public static String guessUrl(String inUrl) {
String retVal = inUrl;
WebAddress webAddress;
if (TRACE)
Log.v(LOGTAG, "guessURL before queueRequest: " + inUrl);
if (inUrl.length() == 0)
return inUrl;
if (inUrl.startsWith("about:"))
return inUrl;
// Do not try to interpret data scheme URLs
if (inUrl.startsWith("data:"))
return inUrl;
// Do not try to interpret file scheme URLs
if (inUrl.startsWith("file:"))
return inUrl;
// Do not try to interpret javascript scheme URLs
if (inUrl.startsWith("javascript:"))
return inUrl;
// bug 762454: strip period off end of url
if (inUrl.endsWith(".") == true) {
inUrl = inUrl.substring(0, inUrl.length() - 1);
}
try {
webAddress = new WebAddress(inUrl);
} catch (ParseException ex) {
if (TRACE) {
Log.v(LOGTAG, "smartUrlFilter: failed to parse url = " + inUrl);
}
return retVal;
}
// Check host
if (webAddress.getHost().indexOf('.') == -1) {
// no dot: user probably entered a bare domain. try .com
webAddress.setHost("www." + webAddress.getHost() + ".com");
}
return webAddress.toString();
}
use of android.net.ParseException in project android_frameworks_base by ParanoidAndroid.
the class RequestHandle method setupRedirect.
/**
* Create and queue a redirect request.
*
* @param redirectTo URL to redirect to
* @param statusCode HTTP status code returned from original request
* @param cacheHeaders Cache header for redirect URL
* @return true if setup succeeds, false otherwise (redirect loop
* count exceeded, body provider unable to rewind on 307 redirect)
*/
public boolean setupRedirect(String redirectTo, int statusCode, Map<String, String> cacheHeaders) {
if (HttpLog.LOGV) {
HttpLog.v("RequestHandle.setupRedirect(): redirectCount " + mRedirectCount);
}
// be careful and remove authentication headers, if any
mHeaders.remove(AUTHORIZATION_HEADER);
mHeaders.remove(PROXY_AUTHORIZATION_HEADER);
if (++mRedirectCount == MAX_REDIRECT_COUNT) {
// Way too many redirects -- fail out
if (HttpLog.LOGV)
HttpLog.v("RequestHandle.setupRedirect(): too many redirects " + mRequest);
mRequest.error(EventHandler.ERROR_REDIRECT_LOOP, com.android.internal.R.string.httpErrorRedirectLoop);
return false;
}
if (mUrl.startsWith("https:") && redirectTo.startsWith("http:")) {
// implement http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3
if (HttpLog.LOGV) {
HttpLog.v("blowing away the referer on an https -> http redirect");
}
mHeaders.remove("Referer");
}
mUrl = redirectTo;
try {
mUri = new WebAddress(mUrl);
} catch (ParseException e) {
e.printStackTrace();
}
// update the "Cookie" header based on the redirected url
mHeaders.remove("Cookie");
String cookie = CookieManager.getInstance().getCookie(mUri);
if (cookie != null && cookie.length() > 0) {
mHeaders.put("Cookie", cookie);
}
if ((statusCode == 302 || statusCode == 303) && mMethod.equals("POST")) {
if (HttpLog.LOGV) {
HttpLog.v("replacing POST with GET on redirect to " + redirectTo);
}
mMethod = "GET";
}
/* Only repost content on a 307. If 307, reset the body
provider so we can replay the body */
if (statusCode == 307) {
try {
if (mBodyProvider != null)
mBodyProvider.reset();
} catch (java.io.IOException ex) {
if (HttpLog.LOGV) {
HttpLog.v("setupRedirect() failed to reset body provider");
}
return false;
}
} else {
mHeaders.remove("Content-Type");
mBodyProvider = null;
}
// Update the cache headers for this URL
mHeaders.putAll(cacheHeaders);
createAndQueueNewRequest();
return true;
}
use of android.net.ParseException in project android_frameworks_base by ParanoidAndroid.
the class CookieManagerClassic method setCookie.
/**
* See {@link #setCookie(String, String)}
* @param url The URL for which the cookie is set
* @param value The value of the cookie, as a string, using the format of
* the 'Set-Cookie' HTTP response header
* @param privateBrowsing Whether to use the private browsing cookie jar
*/
void setCookie(String url, String value, boolean privateBrowsing) {
WebAddress uri;
try {
uri = new WebAddress(url);
} catch (ParseException ex) {
Log.e(LOGTAG, "Bad address: " + url);
return;
}
nativeSetCookie(uri.toString(), value, privateBrowsing);
}
use of android.net.ParseException in project android_frameworks_base by ParanoidAndroid.
the class BrowserFrame method maybeSavePassword.
/**
* If this looks like a POST request (form submission) containing a username
* and password, give the user the option of saving them. Will either do
* nothing, or block until the UI interaction is complete.
*
* Called directly by WebKit.
*
* @param postData The data about to be sent as the body of a POST request.
* @param username The username entered by the user (sniffed from the DOM).
* @param password The password entered by the user (sniffed from the DOM).
*/
private void maybeSavePassword(byte[] postData, String username, String password) {
if (postData == null || username == null || username.isEmpty() || password == null || password.isEmpty()) {
// No password to save.
return;
}
if (!mSettings.getSavePassword()) {
// User doesn't want to save passwords.
return;
}
try {
if (DebugFlags.BROWSER_FRAME) {
Assert.assertNotNull(mCallbackProxy.getBackForwardList().getCurrentItem());
}
WebAddress uri = new WebAddress(mCallbackProxy.getBackForwardList().getCurrentItem().getUrl());
String schemePlusHost = uri.getScheme() + uri.getHost();
// Check to see if the username & password appear in
// the post data (there could be another form on the
// page and that was posted instead.
String postString = new String(postData);
if (postString.contains(URLEncoder.encode(username)) && postString.contains(URLEncoder.encode(password))) {
String[] saved = mDatabase.getUsernamePassword(schemePlusHost);
if (saved != null) {
// save password
if (saved[0] != null) {
// non-null username implies that user has
// chosen to save password, so update the
// recorded password
mDatabase.setUsernamePassword(schemePlusHost, username, password);
}
} else {
// CallbackProxy will handle creating the resume
// message
mCallbackProxy.onSavePassword(schemePlusHost, username, password, null);
}
}
} catch (ParseException ex) {
// if it is bad uri, don't save its password
}
}
use of android.net.ParseException in project android_frameworks_base by ParanoidAndroid.
the class URLUtil method guessUrl.
/**
* Cleans up (if possible) user-entered web addresses
*/
public static String guessUrl(String inUrl) {
String retVal = inUrl;
WebAddress webAddress;
if (DebugFlags.URL_UTIL)
Log.v(LOGTAG, "guessURL before queueRequest: " + inUrl);
if (inUrl.length() == 0)
return inUrl;
if (inUrl.startsWith("about:"))
return inUrl;
// Do not try to interpret data scheme URLs
if (inUrl.startsWith("data:"))
return inUrl;
// Do not try to interpret file scheme URLs
if (inUrl.startsWith("file:"))
return inUrl;
// Do not try to interpret javascript scheme URLs
if (inUrl.startsWith("javascript:"))
return inUrl;
// bug 762454: strip period off end of url
if (inUrl.endsWith(".") == true) {
inUrl = inUrl.substring(0, inUrl.length() - 1);
}
try {
webAddress = new WebAddress(inUrl);
} catch (ParseException ex) {
if (DebugFlags.URL_UTIL) {
Log.v(LOGTAG, "smartUrlFilter: failed to parse url = " + inUrl);
}
return retVal;
}
// Check host
if (webAddress.getHost().indexOf('.') == -1) {
// no dot: user probably entered a bare domain. try .com
webAddress.setHost("www." + webAddress.getHost() + ".com");
}
return webAddress.toString();
}
Aggregations