2011-11-18 10:28:17 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (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.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009-2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Sriram Ramasubramanian <sriram@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
2011-11-29 19:54:07 -08:00
|
|
|
import android.graphics.Bitmap;
|
2012-01-17 10:26:58 -08:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2012-01-16 06:57:36 -08:00
|
|
|
import android.os.AsyncTask;
|
2011-11-29 19:54:07 -08:00
|
|
|
import android.util.DisplayMetrics;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2012-01-17 10:26:58 -08:00
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-01-17 10:26:58 -08:00
|
|
|
public final class Tab {
|
2011-11-18 10:28:17 -08:00
|
|
|
private static final String LOGTAG = "GeckoTab";
|
2012-01-11 00:09:48 -08:00
|
|
|
private static final int kThumbnailWidth = 120;
|
|
|
|
private static final int kThumbnailHeight = 80;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-17 10:26:58 -08:00
|
|
|
private static int sMinDim = 0;
|
|
|
|
private static float sDensity = 1;
|
2011-11-18 10:28:17 -08:00
|
|
|
private int mId;
|
|
|
|
private String mUrl;
|
|
|
|
private String mTitle;
|
|
|
|
private Drawable mFavicon;
|
|
|
|
private String mFaviconUrl;
|
|
|
|
private String mSecurityMode;
|
|
|
|
private Drawable mThumbnail;
|
|
|
|
private List<HistoryEntry> mHistory;
|
|
|
|
private int mHistoryIndex;
|
2011-12-19 10:44:52 -08:00
|
|
|
private int mParentId;
|
|
|
|
private boolean mExternal;
|
2011-11-18 10:28:17 -08:00
|
|
|
private boolean mLoading;
|
|
|
|
private boolean mBookmark;
|
|
|
|
private HashMap<String, DoorHanger> mDoorHangers;
|
|
|
|
private long mFaviconLoadId;
|
2012-01-16 06:57:36 -08:00
|
|
|
private CheckBookmarkTask mCheckBookmarkTask;
|
2011-12-13 16:23:35 -08:00
|
|
|
private String mDocumentURI;
|
|
|
|
private String mContentType;
|
2012-01-24 16:31:33 -08:00
|
|
|
private boolean mHasTouchListeners;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-17 10:26:58 -08:00
|
|
|
public static final class HistoryEntry {
|
2012-01-12 12:22:48 -08:00
|
|
|
public String mUri; // must never be null
|
2011-11-21 11:08:34 -08:00
|
|
|
public String mTitle; // must never be null
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public HistoryEntry(String uri, String title) {
|
|
|
|
mUri = uri;
|
|
|
|
mTitle = title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Tab() {
|
2011-12-20 17:41:45 -08:00
|
|
|
this(-1, "", false, -1, "");
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-20 17:41:45 -08:00
|
|
|
public Tab(int id, String url, boolean external, int parentId, String title) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mId = id;
|
|
|
|
mUrl = url;
|
2011-12-19 10:44:52 -08:00
|
|
|
mExternal = external;
|
|
|
|
mParentId = parentId;
|
2011-12-20 17:41:45 -08:00
|
|
|
mTitle = title;
|
2011-11-18 10:28:17 -08:00
|
|
|
mFavicon = null;
|
|
|
|
mFaviconUrl = null;
|
|
|
|
mSecurityMode = "unknown";
|
|
|
|
mThumbnail = null;
|
|
|
|
mHistory = new ArrayList<HistoryEntry>();
|
|
|
|
mHistoryIndex = -1;
|
|
|
|
mBookmark = false;
|
|
|
|
mDoorHangers = new HashMap<String, DoorHanger>();
|
|
|
|
mFaviconLoadId = 0;
|
2011-12-13 16:23:35 -08:00
|
|
|
mDocumentURI = "";
|
|
|
|
mContentType = "";
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getId() {
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2011-12-19 10:44:52 -08:00
|
|
|
public int getParentId() {
|
|
|
|
return mParentId;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public String getURL() {
|
|
|
|
return mUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTitle() {
|
|
|
|
return mTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDisplayTitle() {
|
|
|
|
if (mTitle != null && mTitle.length() > 0) {
|
|
|
|
return mTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Drawable getFavicon() {
|
|
|
|
return mFavicon;
|
|
|
|
}
|
|
|
|
|
2011-11-29 19:54:07 -08:00
|
|
|
public Drawable getThumbnail() {
|
|
|
|
return mThumbnail;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateThumbnail(final Bitmap b) {
|
2012-01-16 19:23:04 -08:00
|
|
|
final Tab tab = this;
|
2011-11-29 19:54:07 -08:00
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (sMinDim == 0) {
|
|
|
|
DisplayMetrics metrics = new DisplayMetrics();
|
|
|
|
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
2012-01-11 00:09:48 -08:00
|
|
|
sMinDim = Math.min(metrics.widthPixels / 3, metrics.heightPixels / 2);
|
2011-12-14 14:31:39 -08:00
|
|
|
sDensity = metrics.density;
|
2011-11-29 19:54:07 -08:00
|
|
|
}
|
2011-12-07 17:10:21 -08:00
|
|
|
if (b != null) {
|
2011-12-12 12:04:59 -08:00
|
|
|
try {
|
2012-01-11 00:09:48 -08:00
|
|
|
Bitmap cropped = Bitmap.createBitmap(b, 0, 0, sMinDim * 3, sMinDim * 2);
|
|
|
|
Bitmap bitmap = Bitmap.createScaledBitmap(cropped, (int) (kThumbnailWidth * sDensity), (int) (kThumbnailHeight * sDensity), false);
|
2011-12-14 14:31:39 -08:00
|
|
|
saveThumbnailToDB(new BitmapDrawable(bitmap));
|
|
|
|
b.recycle();
|
|
|
|
|
|
|
|
bitmap = Bitmap.createBitmap(cropped, 0, 0, (int) (138 * sDensity), (int) (78 * sDensity));
|
2011-12-12 12:04:59 -08:00
|
|
|
mThumbnail = new BitmapDrawable(bitmap);
|
2011-12-14 14:31:39 -08:00
|
|
|
cropped.recycle();
|
2011-12-12 12:04:59 -08:00
|
|
|
} catch (OutOfMemoryError oom) {
|
|
|
|
Log.e(LOGTAG, "Unable to create/scale bitmap", oom);
|
|
|
|
mThumbnail = null;
|
|
|
|
}
|
2011-12-07 17:10:21 -08:00
|
|
|
} else {
|
|
|
|
mThumbnail = null;
|
|
|
|
}
|
2012-01-16 19:23:04 -08:00
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
GeckoApp.mAppContext.onTabsChanged(tab);
|
|
|
|
}
|
|
|
|
});
|
2011-11-29 19:54:07 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public String getFaviconURL() {
|
|
|
|
return mFaviconUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSecurityMode() {
|
|
|
|
return mSecurityMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isLoading() {
|
|
|
|
return mLoading;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBookmark() {
|
|
|
|
return mBookmark;
|
|
|
|
}
|
|
|
|
|
2011-12-19 10:44:52 -08:00
|
|
|
public boolean isExternal() {
|
|
|
|
return mExternal;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public void updateURL(String url) {
|
|
|
|
if (url != null && url.length() > 0) {
|
2011-11-21 11:08:34 -08:00
|
|
|
mUrl = url;
|
2011-11-18 10:28:17 -08:00
|
|
|
Log.i(LOGTAG, "Updated url: " + url + " for tab with id: " + mId);
|
|
|
|
updateBookmark();
|
2012-01-12 12:22:48 -08:00
|
|
|
updateHistoryEntry(mUrl, mTitle);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 16:23:35 -08:00
|
|
|
public void setDocumentURI(String documentURI) {
|
|
|
|
mDocumentURI = documentURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDocumentURI() {
|
|
|
|
return mDocumentURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setContentType(String contentType) {
|
|
|
|
mContentType = contentType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getContentType() {
|
|
|
|
return mContentType;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public void updateTitle(String title) {
|
2011-11-21 11:08:34 -08:00
|
|
|
mTitle = (title == null ? "" : title);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
Log.i(LOGTAG, "Updated title: " + mTitle + " for tab with id: " + mId);
|
2012-01-12 12:22:48 -08:00
|
|
|
updateHistoryEntry(mUrl, mTitle);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-12 12:22:48 -08:00
|
|
|
private void updateHistoryEntry(final String uri, final String title) {
|
2011-11-18 10:28:17 -08:00
|
|
|
final HistoryEntry he = getLastHistoryEntry();
|
|
|
|
if (he != null) {
|
2012-01-12 12:22:48 -08:00
|
|
|
he.mUri = uri;
|
|
|
|
he.mTitle = title;
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
2012-01-12 12:22:48 -08:00
|
|
|
GlobalHistory.getInstance().update(uri, title);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Log.e(LOGTAG, "Requested title update on empty history stack");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLoading(boolean loading) {
|
|
|
|
mLoading = loading;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setBookmark(boolean bookmark) {
|
|
|
|
mBookmark = bookmark;
|
|
|
|
}
|
|
|
|
|
2012-01-24 16:31:33 -08:00
|
|
|
public void setHasTouchListeners(boolean aValue) {
|
|
|
|
mHasTouchListeners = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasTouchListeners() {
|
|
|
|
return mHasTouchListeners;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public void setFaviconLoadId(long faviconLoadId) {
|
|
|
|
mFaviconLoadId = faviconLoadId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getFaviconLoadId() {
|
|
|
|
return mFaviconLoadId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HistoryEntry getLastHistoryEntry() {
|
|
|
|
if (mHistory.isEmpty())
|
|
|
|
return null;
|
|
|
|
return mHistory.get(mHistoryIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateFavicon(Drawable favicon) {
|
|
|
|
mFavicon = favicon;
|
|
|
|
Log.i(LOGTAG, "Updated favicon for tab with id: " + mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateFaviconURL(String faviconUrl) {
|
|
|
|
mFaviconUrl = faviconUrl;
|
|
|
|
Log.i(LOGTAG, "Updated favicon URL for tab with id: " + mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateSecurityMode(String mode) {
|
|
|
|
mSecurityMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateBookmark() {
|
2012-01-16 06:57:36 -08:00
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (mCheckBookmarkTask != null)
|
|
|
|
mCheckBookmarkTask.cancel(false);
|
|
|
|
|
|
|
|
mCheckBookmarkTask = new CheckBookmarkTask(getURL());
|
|
|
|
mCheckBookmarkTask.execute();
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addBookmark() {
|
|
|
|
new AddBookmarkTask().execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeBookmark() {
|
|
|
|
new RemoveBookmarkTask().execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doReload() {
|
|
|
|
if (mHistory.isEmpty())
|
|
|
|
return false;
|
|
|
|
GeckoEvent e = new GeckoEvent("Session:Reload", "");
|
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doBack() {
|
|
|
|
if (mHistoryIndex < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
GeckoEvent e = new GeckoEvent("Session:Back", "");
|
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doStop() {
|
|
|
|
GeckoEvent e = new GeckoEvent("Session:Stop", "");
|
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canDoForward() {
|
|
|
|
return (mHistoryIndex + 1 < mHistory.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doForward() {
|
|
|
|
if (mHistoryIndex + 1 >= mHistory.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
GeckoEvent e = new GeckoEvent("Session:Forward", "");
|
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addDoorHanger(String value, DoorHanger dh) {
|
|
|
|
mDoorHangers.put(value, dh);
|
2012-01-17 10:26:58 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public void removeDoorHanger(String value) {
|
|
|
|
mDoorHangers.remove(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeAllDoorHangers() {
|
|
|
|
mDoorHangers = new HashMap<String, DoorHanger>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeTransientDoorHangers() {
|
|
|
|
for (String value : mDoorHangers.keySet()) {
|
|
|
|
DoorHanger dh = mDoorHangers.get(value);
|
|
|
|
if (dh.shouldRemove())
|
|
|
|
mDoorHangers.remove(value);
|
2012-01-17 10:26:58 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public DoorHanger getDoorHanger(String value) {
|
|
|
|
if (mDoorHangers == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (mDoorHangers.containsKey(value))
|
|
|
|
return mDoorHangers.get(value);
|
|
|
|
|
|
|
|
return null;
|
2012-01-17 10:26:58 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public HashMap<String, DoorHanger> getDoorHangers() {
|
|
|
|
return mDoorHangers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleSessionHistoryMessage(String event, JSONObject message) throws JSONException {
|
|
|
|
if (event.equals("New")) {
|
|
|
|
final String uri = message.getString("uri");
|
|
|
|
mHistoryIndex++;
|
|
|
|
while (mHistory.size() > mHistoryIndex) {
|
|
|
|
mHistory.remove(mHistoryIndex);
|
|
|
|
}
|
2011-11-21 11:08:34 -08:00
|
|
|
HistoryEntry he = new HistoryEntry(uri, "");
|
2011-11-18 10:28:17 -08:00
|
|
|
mHistory.add(he);
|
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
GlobalHistory.getInstance().add(uri);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (event.equals("Back")) {
|
|
|
|
if (mHistoryIndex - 1 < 0) {
|
|
|
|
Log.e(LOGTAG, "Received unexpected back notification");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHistoryIndex--;
|
|
|
|
} else if (event.equals("Forward")) {
|
|
|
|
if (mHistoryIndex + 1 >= mHistory.size()) {
|
|
|
|
Log.e(LOGTAG, "Received unexpected forward notification");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHistoryIndex++;
|
|
|
|
} else if (event.equals("Goto")) {
|
|
|
|
int index = message.getInt("index");
|
|
|
|
if (index < 0 || index >= mHistory.size()) {
|
|
|
|
Log.e(LOGTAG, "Received unexpected history-goto notification");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHistoryIndex = index;
|
|
|
|
} else if (event.equals("Purge")) {
|
|
|
|
mHistory.clear();
|
|
|
|
mHistoryIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-17 10:26:58 -08:00
|
|
|
private final class CheckBookmarkTask extends AsyncTask<Void, Void, Boolean> {
|
2012-01-16 06:57:36 -08:00
|
|
|
private final String mUrl;
|
|
|
|
|
|
|
|
public CheckBookmarkTask(String url) {
|
|
|
|
mUrl = url;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Void... unused) {
|
|
|
|
ContentResolver resolver = Tabs.getInstance().getContentResolver();
|
2012-01-16 06:57:36 -08:00
|
|
|
return BrowserDB.isBookmark(resolver, mUrl);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-01-16 06:57:36 -08:00
|
|
|
protected void onCancelled() {
|
|
|
|
mCheckBookmarkTask = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(final Boolean isBookmark) {
|
|
|
|
mCheckBookmarkTask = null;
|
|
|
|
|
|
|
|
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
// Ignore this task if it's not about the current
|
|
|
|
// tab URL anymore.
|
|
|
|
if (!mUrl.equals(getURL()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
setBookmark(isBookmark.booleanValue());
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-17 10:26:58 -08:00
|
|
|
private final class AddBookmarkTask extends GeckoAsyncTask<Void, Void, Void> {
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... unused) {
|
|
|
|
ContentResolver resolver = Tabs.getInstance().getContentResolver();
|
2011-12-02 09:27:56 -08:00
|
|
|
BrowserDB.addBookmark(resolver, getTitle(), getURL());
|
2011-11-18 10:28:17 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void unused) {
|
|
|
|
setBookmark(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
private void saveThumbnailToDB(BitmapDrawable thumbnail) {
|
2011-11-29 22:02:55 -08:00
|
|
|
try {
|
|
|
|
ContentResolver resolver = Tabs.getInstance().getContentResolver();
|
2011-12-02 09:27:56 -08:00
|
|
|
BrowserDB.updateThumbnailForUrl(resolver, getURL(), thumbnail);
|
2011-11-30 00:13:36 -08:00
|
|
|
} catch (Exception e) {
|
2011-11-29 22:02:55 -08:00
|
|
|
// ignore
|
|
|
|
}
|
2011-11-29 19:54:07 -08:00
|
|
|
}
|
|
|
|
|
2012-01-17 10:26:58 -08:00
|
|
|
private final class RemoveBookmarkTask extends GeckoAsyncTask<Void, Void, Void> {
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... unused) {
|
|
|
|
ContentResolver resolver = Tabs.getInstance().getContentResolver();
|
2011-12-02 09:27:56 -08:00
|
|
|
BrowserDB.removeBookmark(resolver, getURL());
|
2011-11-18 10:28:17 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void unused) {
|
|
|
|
setBookmark(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|