final ContentResolver cr = getContentResolver();
Bookmarks.addBookmark(null, cr, url, title, thumbnail, true);
if (touchIconUrl != null) {
- final Cursor c
- = BrowserBookmarksAdapter.queryBookmarksForUrl(cr,
- null, url, true);
- new DownloadTouchIcon(cr, c, url).execute(mTouchIconUrl);
+ new DownloadTouchIcon(cr, url).execute(mTouchIconUrl);
}
mMessage.arg1 = 1;
} catch (IllegalStateException e) {
class DownloadTouchIcon extends AsyncTask<String, Void, Void> {
private final ContentResolver mContentResolver;
- private final Cursor mCursor;
+ private Cursor mCursor;
private final String mOriginalUrl;
private final String mUrl;
private final String mUserAgent;
/* package */ Tab mTab;
- public DownloadTouchIcon(Tab tab, ContentResolver cr, Cursor c, WebView view) {
+ public DownloadTouchIcon(Tab tab, ContentResolver cr, WebView view) {
mTab = tab;
mContentResolver = cr;
- mCursor = c;
// Store these in case they change.
mOriginalUrl = view.getOriginalUrl();
mUrl = view.getUrl();
mUserAgent = view.getSettings().getUserAgentString();
}
- public DownloadTouchIcon(ContentResolver cr, Cursor c, String url) {
+ public DownloadTouchIcon(ContentResolver cr, String url) {
mTab = null;
mContentResolver = cr;
- mCursor = c;
mOriginalUrl = null;
mUrl = url;
mUserAgent = null;
@Override
public Void doInBackground(String... values) {
- String url = values[0];
-
- AndroidHttpClient client = AndroidHttpClient.newInstance(
- mUserAgent);
- HttpGet request = new HttpGet(url);
-
- // Follow redirects
- HttpClientParams.setRedirecting(client.getParams(), true);
-
- try {
- HttpResponse response = client.execute(request);
-
- if (response.getStatusLine().getStatusCode() == 200) {
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- InputStream content = entity.getContent();
- if (content != null) {
- Bitmap icon = BitmapFactory.decodeStream(
- content, null, null);
- storeIcon(icon);
+ mCursor = BrowserBookmarksAdapter.queryBookmarksForUrl(mContentResolver,
+ mOriginalUrl, mUrl, true);
+ if (mCursor != null && mCursor.getCount() > 0) {
+ String url = values[0];
+
+ AndroidHttpClient client = AndroidHttpClient.newInstance(
+ mUserAgent);
+ HttpGet request = new HttpGet(url);
+
+ // Follow redirects
+ HttpClientParams.setRedirecting(client.getParams(), true);
+
+ try {
+ HttpResponse response = client.execute(request);
+
+ if (response.getStatusLine().getStatusCode() == 200) {
+ HttpEntity entity = response.getEntity();
+ if (entity != null) {
+ InputStream content = entity.getContent();
+ if (content != null) {
+ Bitmap icon = BitmapFactory.decodeStream(
+ content, null, null);
+ storeIcon(icon);
+ }
}
}
+ } catch (IllegalArgumentException ex) {
+ request.abort();
+ } catch (IOException ex) {
+ request.abort();
+ } finally {
+ client.close();
}
- } catch (IllegalArgumentException ex) {
- request.abort();
- } catch (IOException ex) {
- request.abort();
- } finally {
- client.close();
}
if (mCursor != null) {
mCursor.close();
public void onReceivedTouchIconUrl(WebView view, String url,
boolean precomposed) {
final ContentResolver cr = mActivity.getContentResolver();
- final Cursor c = BrowserBookmarksAdapter.queryBookmarksForUrl(cr,
- view.getOriginalUrl(), view.getUrl(), true);
- if (c != null) {
- if (c.getCount() > 0) {
- // Let precomposed icons take precedence over non-composed
- // icons.
- if (precomposed && mTouchIconLoader != null) {
- mTouchIconLoader.cancel(false);
- mTouchIconLoader = null;
- }
- // Have only one async task at a time.
- if (mTouchIconLoader == null) {
- mTouchIconLoader = new DownloadTouchIcon(Tab.this, cr,
- c, view);
- mTouchIconLoader.execute(url);
- } else {
- c.close();
- }
- } else {
- c.close();
- }
+ // Let precomposed icons take precedence over non-composed
+ // icons.
+ if (precomposed && mTouchIconLoader != null) {
+ mTouchIconLoader.cancel(false);
+ mTouchIconLoader = null;
+ }
+ // Have only one async task at a time.
+ if (mTouchIconLoader == null) {
+ mTouchIconLoader = new DownloadTouchIcon(Tab.this, cr, view);
+ mTouchIconLoader.execute(url);
}
}