2011-11-18 18:28:17 +00: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-30 03:54:07 +00:00
|
|
|
import android.graphics.Bitmap;
|
2012-01-17 18:26:58 +00:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2012-01-16 14:57:36 +00:00
|
|
|
import android.os.AsyncTask;
|
2011-11-30 03:54:07 +00:00
|
|
|
import android.util.DisplayMetrics;
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.util.Log;
|
2012-01-31 14:40:58 +00:00
|
|
|
import android.view.Surface;
|
2012-01-31 14:30:47 +00:00
|
|
|
import android.view.View;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2012-01-17 18:26:58 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2012-01-31 14:40:58 +00:00
|
|
|
import org.mozilla.gecko.gfx.Layer;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2012-01-31 14:40:58 +00:00
|
|
|
import java.util.Collection;
|
2011-11-18 18:28:17 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-01-17 18:26:58 +00:00
|
|
|
public final class Tab {
|
2011-11-18 18:28:17 +00:00
|
|
|
private static final String LOGTAG = "GeckoTab";
|
2012-01-26 06:02:00 +00:00
|
|
|
private static final int kThumbnailWidth = 136;
|
2012-02-07 18:30:38 +00:00
|
|
|
private static final int kThumbnailHeight = 78;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-02-07 22:04:46 +00:00
|
|
|
private static float sMinDim = 0;
|
2012-01-17 18:26:58 +00:00
|
|
|
private static float sDensity = 1;
|
2012-01-26 06:02:00 +00:00
|
|
|
private static int sMinScreenshotWidth = 0;
|
|
|
|
private static int sMinScreenshotHeight = 0;
|
2011-11-18 18:28:17 +00: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 18:44:52 +00:00
|
|
|
private int mParentId;
|
|
|
|
private boolean mExternal;
|
2011-11-18 18:28:17 +00:00
|
|
|
private boolean mLoading;
|
|
|
|
private boolean mBookmark;
|
|
|
|
private HashMap<String, DoorHanger> mDoorHangers;
|
|
|
|
private long mFaviconLoadId;
|
2012-01-16 14:57:36 +00:00
|
|
|
private CheckBookmarkTask mCheckBookmarkTask;
|
2011-12-14 00:23:35 +00:00
|
|
|
private String mDocumentURI;
|
|
|
|
private String mContentType;
|
2012-01-25 00:31:33 +00:00
|
|
|
private boolean mHasTouchListeners;
|
2012-01-31 14:30:47 +00:00
|
|
|
private ArrayList<View> mPluginViews;
|
2012-01-31 14:40:58 +00:00
|
|
|
private HashMap<Surface, Layer> mPluginLayers;
|
2012-01-31 22:13:33 +00:00
|
|
|
private boolean mHasLoaded;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-01-17 18:26:58 +00:00
|
|
|
public static final class HistoryEntry {
|
2012-01-12 20:22:48 +00:00
|
|
|
public String mUri; // must never be null
|
2011-11-21 19:08:34 +00:00
|
|
|
public String mTitle; // must never be null
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
public HistoryEntry(String uri, String title) {
|
|
|
|
mUri = uri;
|
|
|
|
mTitle = title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Tab() {
|
2011-12-21 01:41:45 +00:00
|
|
|
this(-1, "", false, -1, "");
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2011-12-21 01:41:45 +00:00
|
|
|
public Tab(int id, String url, boolean external, int parentId, String title) {
|
2011-11-18 18:28:17 +00:00
|
|
|
mId = id;
|
|
|
|
mUrl = url;
|
2011-12-19 18:44:52 +00:00
|
|
|
mExternal = external;
|
|
|
|
mParentId = parentId;
|
2011-12-21 01:41:45 +00:00
|
|
|
mTitle = title;
|
2011-11-18 18:28:17 +00: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-14 00:23:35 +00:00
|
|
|
mDocumentURI = "";
|
|
|
|
mContentType = "";
|
2012-01-31 14:30:47 +00:00
|
|
|
mPluginViews = new ArrayList<View>();
|
2012-01-31 14:40:58 +00:00
|
|
|
mPluginLayers = new HashMap<Surface, Layer>();
|
2012-01-31 22:13:33 +00:00
|
|
|
mHasLoaded = false;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getId() {
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2011-12-19 18:44:52 +00:00
|
|
|
public int getParentId() {
|
|
|
|
return mParentId;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00: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-30 03:54:07 +00:00
|
|
|
public Drawable getThumbnail() {
|
|
|
|
return mThumbnail;
|
|
|
|
}
|
|
|
|
|
2012-01-26 06:02:00 +00:00
|
|
|
void initMetrics() {
|
|
|
|
DisplayMetrics metrics = new DisplayMetrics();
|
|
|
|
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
2012-02-07 22:04:46 +00:00
|
|
|
sMinDim = Math.min(metrics.widthPixels / kThumbnailWidth, metrics.heightPixels / kThumbnailHeight);
|
2012-01-26 06:02:00 +00:00
|
|
|
sDensity = metrics.density;
|
|
|
|
}
|
|
|
|
|
2012-02-07 22:04:46 +00:00
|
|
|
float getMinDim() {
|
|
|
|
if (sMinDim == 0)
|
|
|
|
initMetrics();
|
|
|
|
return sMinDim;
|
|
|
|
}
|
|
|
|
|
2012-01-26 06:02:00 +00:00
|
|
|
float getDensity() {
|
|
|
|
if (sDensity == 0.0f)
|
|
|
|
initMetrics();
|
|
|
|
return sDensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getMinScreenshotWidth() {
|
2012-02-07 22:04:46 +00:00
|
|
|
if (sMinScreenshotWidth != 0)
|
|
|
|
return sMinScreenshotWidth;
|
|
|
|
return sMinScreenshotWidth = (int)(getMinDim() * kThumbnailWidth);
|
2012-01-26 06:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int getMinScreenshotHeight() {
|
2012-02-07 22:04:46 +00:00
|
|
|
if (sMinScreenshotHeight != 0)
|
|
|
|
return sMinScreenshotHeight;
|
|
|
|
return sMinScreenshotHeight = (int)(getMinDim() * kThumbnailHeight);
|
2012-01-26 06:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int getThumbnailWidth() {
|
|
|
|
return (int)(kThumbnailWidth * getDensity());
|
|
|
|
}
|
|
|
|
|
|
|
|
int getThumbnailHeight() {
|
|
|
|
return (int)(kThumbnailHeight * getDensity());
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:54:07 +00:00
|
|
|
public void updateThumbnail(final Bitmap b) {
|
2012-01-17 03:23:04 +00:00
|
|
|
final Tab tab = this;
|
2011-11-30 03:54:07 +00:00
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
2011-12-08 01:10:21 +00:00
|
|
|
if (b != null) {
|
2011-12-12 20:04:59 +00:00
|
|
|
try {
|
2012-01-26 06:02:00 +00:00
|
|
|
Bitmap cropped = null;
|
|
|
|
/* Crop to screen width if the bitmap is larger than the screen width or height. If smaller and the
|
|
|
|
* the aspect ratio is correct, just use the bitmap as is. Otherwise, fit the smaller
|
|
|
|
* smaller dimension, then crop the larger dimention.
|
|
|
|
*/
|
|
|
|
if (getMinScreenshotWidth() < b.getWidth() && getMinScreenshotHeight() < b.getHeight())
|
|
|
|
cropped = Bitmap.createBitmap(b, 0, 0, getMinScreenshotWidth(), getMinScreenshotHeight());
|
|
|
|
else if (b.getWidth() * getMinScreenshotHeight() == b.getHeight() * getMinScreenshotWidth())
|
|
|
|
cropped = b;
|
|
|
|
else if (b.getWidth() * getMinScreenshotHeight() < b.getHeight() * getMinScreenshotWidth())
|
|
|
|
cropped = Bitmap.createBitmap(b, 0, 0, b.getWidth(),
|
|
|
|
b.getWidth() * getMinScreenshotHeight() / getMinScreenshotWidth());
|
|
|
|
else
|
|
|
|
cropped = Bitmap.createBitmap(b, 0, 0,
|
|
|
|
b.getHeight() * getMinScreenshotWidth() / getMinScreenshotHeight(),
|
|
|
|
b.getHeight());
|
|
|
|
|
|
|
|
Bitmap bitmap = Bitmap.createScaledBitmap(cropped, getThumbnailWidth(), getThumbnailHeight(), false);
|
2011-12-14 22:31:39 +00:00
|
|
|
saveThumbnailToDB(new BitmapDrawable(bitmap));
|
|
|
|
|
2012-01-26 06:02:00 +00:00
|
|
|
if (!cropped.equals(b))
|
|
|
|
b.recycle();
|
2011-12-12 20:04:59 +00:00
|
|
|
mThumbnail = new BitmapDrawable(bitmap);
|
2011-12-14 22:31:39 +00:00
|
|
|
cropped.recycle();
|
2011-12-12 20:04:59 +00:00
|
|
|
} catch (OutOfMemoryError oom) {
|
|
|
|
Log.e(LOGTAG, "Unable to create/scale bitmap", oom);
|
|
|
|
mThumbnail = null;
|
|
|
|
}
|
2011-12-08 01:10:21 +00:00
|
|
|
} else {
|
|
|
|
mThumbnail = null;
|
|
|
|
}
|
2012-01-17 03:23:04 +00:00
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
GeckoApp.mAppContext.onTabsChanged(tab);
|
|
|
|
}
|
|
|
|
});
|
2011-11-30 03:54:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
public String getFaviconURL() {
|
|
|
|
return mFaviconUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSecurityMode() {
|
|
|
|
return mSecurityMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isLoading() {
|
|
|
|
return mLoading;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBookmark() {
|
|
|
|
return mBookmark;
|
|
|
|
}
|
|
|
|
|
2011-12-19 18:44:52 +00:00
|
|
|
public boolean isExternal() {
|
|
|
|
return mExternal;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
public void updateURL(String url) {
|
|
|
|
if (url != null && url.length() > 0) {
|
2011-11-21 19:08:34 +00:00
|
|
|
mUrl = url;
|
2011-11-18 18:28:17 +00:00
|
|
|
Log.i(LOGTAG, "Updated url: " + url + " for tab with id: " + mId);
|
|
|
|
updateBookmark();
|
2012-01-12 20:22:48 +00:00
|
|
|
updateHistoryEntry(mUrl, mTitle);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:35 +00: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 18:28:17 +00:00
|
|
|
public void updateTitle(String title) {
|
2011-11-21 19:08:34 +00:00
|
|
|
mTitle = (title == null ? "" : title);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
Log.i(LOGTAG, "Updated title: " + mTitle + " for tab with id: " + mId);
|
2012-01-12 20:22:48 +00:00
|
|
|
updateHistoryEntry(mUrl, mTitle);
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-01-12 20:22:48 +00:00
|
|
|
private void updateHistoryEntry(final String uri, final String title) {
|
2011-11-18 18:28:17 +00:00
|
|
|
final HistoryEntry he = getLastHistoryEntry();
|
|
|
|
if (he != null) {
|
2012-01-12 20:22:48 +00:00
|
|
|
he.mUri = uri;
|
|
|
|
he.mTitle = title;
|
2011-11-18 18:28:17 +00:00
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
2012-01-12 20:22:48 +00:00
|
|
|
GlobalHistory.getInstance().update(uri, title);
|
2011-11-18 18:28:17 +00: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-25 00:31:33 +00:00
|
|
|
public void setHasTouchListeners(boolean aValue) {
|
|
|
|
mHasTouchListeners = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasTouchListeners() {
|
|
|
|
return mHasTouchListeners;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00: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 14:57:36 +00: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 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addBookmark() {
|
|
|
|
new AddBookmarkTask().execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeBookmark() {
|
|
|
|
new RemoveBookmarkTask().execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doReload() {
|
|
|
|
if (mHistory.isEmpty())
|
|
|
|
return false;
|
2012-02-09 07:18:27 +00:00
|
|
|
GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Reload", "");
|
2011-11-18 18:28:17 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doBack() {
|
|
|
|
if (mHistoryIndex < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-09 07:18:27 +00:00
|
|
|
GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Back", "");
|
2011-11-18 18:28:17 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doStop() {
|
2012-02-09 07:18:27 +00:00
|
|
|
GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Stop", "");
|
2011-11-18 18:28:17 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canDoForward() {
|
|
|
|
return (mHistoryIndex + 1 < mHistory.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doForward() {
|
|
|
|
if (mHistoryIndex + 1 >= mHistory.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-09 07:18:27 +00:00
|
|
|
GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Forward", "");
|
2011-11-18 18:28:17 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addDoorHanger(String value, DoorHanger dh) {
|
|
|
|
mDoorHangers.put(value, dh);
|
2012-01-17 18:26:58 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00: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 18:26:58 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public DoorHanger getDoorHanger(String value) {
|
|
|
|
if (mDoorHangers == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (mDoorHangers.containsKey(value))
|
|
|
|
return mDoorHangers.get(value);
|
|
|
|
|
|
|
|
return null;
|
2012-01-17 18:26:58 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
public HashMap<String, DoorHanger> getDoorHangers() {
|
|
|
|
return mDoorHangers;
|
|
|
|
}
|
|
|
|
|
2012-01-31 22:13:33 +00:00
|
|
|
public void setHasLoaded(boolean hasLoaded) {
|
|
|
|
mHasLoaded = hasLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasLoaded() {
|
|
|
|
return mHasLoaded;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
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 19:08:34 +00:00
|
|
|
HistoryEntry he = new HistoryEntry(uri, "");
|
2011-11-18 18:28:17 +00: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 18:26:58 +00:00
|
|
|
private final class CheckBookmarkTask extends AsyncTask<Void, Void, Boolean> {
|
2012-01-16 14:57:36 +00:00
|
|
|
private final String mUrl;
|
|
|
|
|
|
|
|
public CheckBookmarkTask(String url) {
|
|
|
|
mUrl = url;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Void... unused) {
|
|
|
|
ContentResolver resolver = Tabs.getInstance().getContentResolver();
|
2012-01-16 14:57:36 +00:00
|
|
|
return BrowserDB.isBookmark(resolver, mUrl);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-01-16 14:57:36 +00: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 18:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-17 18:26:58 +00:00
|
|
|
private final class AddBookmarkTask extends GeckoAsyncTask<Void, Void, Void> {
|
2011-11-18 18:28:17 +00:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... unused) {
|
|
|
|
ContentResolver resolver = Tabs.getInstance().getContentResolver();
|
2011-12-02 17:27:56 +00:00
|
|
|
BrowserDB.addBookmark(resolver, getTitle(), getURL());
|
2011-11-18 18:28:17 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void unused) {
|
|
|
|
setBookmark(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 17:27:56 +00:00
|
|
|
private void saveThumbnailToDB(BitmapDrawable thumbnail) {
|
2011-11-30 06:02:55 +00:00
|
|
|
try {
|
|
|
|
ContentResolver resolver = Tabs.getInstance().getContentResolver();
|
2011-12-02 17:27:56 +00:00
|
|
|
BrowserDB.updateThumbnailForUrl(resolver, getURL(), thumbnail);
|
2011-11-30 08:13:36 +00:00
|
|
|
} catch (Exception e) {
|
2011-11-30 06:02:55 +00:00
|
|
|
// ignore
|
|
|
|
}
|
2011-11-30 03:54:07 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 18:26:58 +00:00
|
|
|
private final class RemoveBookmarkTask extends GeckoAsyncTask<Void, Void, Void> {
|
2011-11-18 18:28:17 +00:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... unused) {
|
|
|
|
ContentResolver resolver = Tabs.getInstance().getContentResolver();
|
2012-02-09 18:01:57 +00:00
|
|
|
|
|
|
|
// We want to remove all bookmarks with this URL
|
|
|
|
BrowserDB.removeBookmarksWithURL(resolver, getURL());
|
2011-11-18 18:28:17 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void unused) {
|
|
|
|
setBookmark(false);
|
|
|
|
}
|
|
|
|
}
|
2012-01-31 14:30:47 +00:00
|
|
|
|
|
|
|
public void addPluginView(View view) {
|
|
|
|
mPluginViews.add(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removePluginView(View view) {
|
|
|
|
mPluginViews.remove(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
public View[] getPluginViews() {
|
|
|
|
return mPluginViews.toArray(new View[mPluginViews.size()]);
|
|
|
|
}
|
2012-01-31 14:40:58 +00:00
|
|
|
|
|
|
|
public void addPluginLayer(Surface surface, Layer layer) {
|
|
|
|
mPluginLayers.put(surface, layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Layer getPluginLayer(Surface surface) {
|
|
|
|
return mPluginLayers.get(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Layer> getPluginLayers() {
|
|
|
|
return mPluginLayers.values();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Layer removePluginLayer(Surface surface) {
|
|
|
|
return mPluginLayers.remove(surface);
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|