2011-11-18 18:28:17 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2014-02-23 03:53:00 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2014-02-12 19:50:35 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
|
2013-02-07 03:53:01 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
|
|
|
import org.mozilla.gecko.gfx.Layer;
|
2013-03-15 10:52:53 +00:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
2012-07-28 00:53:54 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.content.ContentResolver;
|
2013-04-16 21:34:46 +00:00
|
|
|
import android.content.Context;
|
2011-11-30 03:54:07 +00:00
|
|
|
import android.graphics.Bitmap;
|
2012-04-23 17:29:14 +00:00
|
|
|
import android.graphics.Color;
|
2012-01-17 18:26:58 +00:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2012-10-31 15:44:53 +00:00
|
|
|
import android.os.Build;
|
2013-02-25 04:51:05 +00:00
|
|
|
import android.text.TextUtils;
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.util.Log;
|
2012-01-31 14:30:47 +00:00
|
|
|
import android.view.View;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-10-09 18:26:33 +00:00
|
|
|
public class Tab {
|
2011-11-18 18:28:17 +00:00
|
|
|
private static final String LOGTAG = "GeckoTab";
|
|
|
|
|
2012-04-23 17:29:14 +00:00
|
|
|
private static Pattern sColorPattern;
|
2012-08-09 20:52:58 +00:00
|
|
|
private final int mId;
|
|
|
|
private long mLastUsed;
|
2011-11-18 18:28:17 +00:00
|
|
|
private String mUrl;
|
2013-04-26 23:17:37 +00:00
|
|
|
private String mBaseDomain;
|
2013-04-10 18:02:05 +00:00
|
|
|
private String mUserSearch;
|
2011-11-18 18:28:17 +00:00
|
|
|
private String mTitle;
|
2012-11-05 11:42:25 +00:00
|
|
|
private Bitmap mFavicon;
|
2011-11-18 18:28:17 +00:00
|
|
|
private String mFaviconUrl;
|
2012-05-29 21:10:48 +00:00
|
|
|
private int mFaviconSize;
|
2013-11-06 23:21:56 +00:00
|
|
|
private boolean mHasFeeds;
|
|
|
|
private boolean mHasOpenSearch;
|
2013-12-12 00:28:15 +00:00
|
|
|
private SiteIdentity mSiteIdentity;
|
2012-06-02 18:23:45 +00:00
|
|
|
private boolean mReaderEnabled;
|
2012-07-24 17:31:51 +00:00
|
|
|
private BitmapDrawable mThumbnail;
|
2011-11-18 18:28:17 +00:00
|
|
|
private int mHistoryIndex;
|
2012-05-17 06:07:55 +00:00
|
|
|
private int mHistorySize;
|
2011-12-19 18:44:52 +00:00
|
|
|
private int mParentId;
|
|
|
|
private boolean mExternal;
|
2011-11-18 18:28:17 +00:00
|
|
|
private boolean mBookmark;
|
2012-06-20 18:10:08 +00:00
|
|
|
private boolean mReadingListItem;
|
2013-09-12 14:50:03 +00:00
|
|
|
private int mFaviconLoadId;
|
2011-12-14 00:23:35 +00:00
|
|
|
private String mContentType;
|
2012-01-25 00:31:33 +00:00
|
|
|
private boolean mHasTouchListeners;
|
2012-08-07 14:39:03 +00:00
|
|
|
private ZoomConstraints mZoomConstraints;
|
2013-04-25 17:47:08 +00:00
|
|
|
private boolean mIsRTL;
|
2012-01-31 14:30:47 +00:00
|
|
|
private ArrayList<View> mPluginViews;
|
2012-04-27 20:04:47 +00:00
|
|
|
private HashMap<Object, Layer> mPluginLayers;
|
2013-04-16 21:34:46 +00:00
|
|
|
private int mBackgroundColor;
|
2012-03-07 21:58:31 +00:00
|
|
|
private int mState;
|
2012-06-14 16:08:51 +00:00
|
|
|
private Bitmap mThumbnailBitmap;
|
2012-06-22 19:53:40 +00:00
|
|
|
private boolean mDesktopMode;
|
2012-09-11 17:51:44 +00:00
|
|
|
private boolean mEnteringReaderMode;
|
2013-07-15 19:12:15 +00:00
|
|
|
private Context mAppContext;
|
2013-08-19 22:14:37 +00:00
|
|
|
private ErrorType mErrorType = ErrorType.NONE;
|
2013-02-07 03:53:01 +00:00
|
|
|
private static final int MAX_HISTORY_LIST_SIZE = 50;
|
2014-03-07 17:54:52 +00:00
|
|
|
private volatile int mLoadProgress;
|
2012-03-07 21:58:31 +00:00
|
|
|
|
|
|
|
public static final int STATE_DELAYED = 0;
|
|
|
|
public static final int STATE_LOADING = 1;
|
2012-03-07 21:58:31 +00:00
|
|
|
public static final int STATE_SUCCESS = 2;
|
|
|
|
public static final int STATE_ERROR = 3;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2014-02-26 19:02:21 +00:00
|
|
|
public static final int LOAD_PROGRESS_INIT = 10;
|
2014-02-26 19:02:21 +00:00
|
|
|
public static final int LOAD_PROGRESS_START = 20;
|
|
|
|
public static final int LOAD_PROGRESS_LOCATION_CHANGE = 60;
|
|
|
|
public static final int LOAD_PROGRESS_LOADED = 80;
|
|
|
|
public static final int LOAD_PROGRESS_STOP = 100;
|
|
|
|
|
2013-05-29 18:31:52 +00:00
|
|
|
private static final int DEFAULT_BACKGROUND_COLOR = Color.WHITE;
|
|
|
|
|
2013-08-19 22:14:37 +00:00
|
|
|
public enum ErrorType {
|
|
|
|
CERT_ERROR, // Pages with certificate problems
|
|
|
|
BLOCKED, // Pages blocked for phishing or malware warnings
|
2013-08-20 10:50:04 +00:00
|
|
|
NET_ERROR, // All other types of error
|
2013-08-19 22:14:37 +00:00
|
|
|
NONE // Non error pages
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:34:46 +00:00
|
|
|
public Tab(Context context, int id, String url, boolean external, int parentId, String title) {
|
2013-07-15 19:12:15 +00:00
|
|
|
mAppContext = context.getApplicationContext();
|
2011-11-18 18:28:17 +00:00
|
|
|
mId = id;
|
2012-08-09 20:52:58 +00:00
|
|
|
mLastUsed = 0;
|
2011-11-18 18:28:17 +00:00
|
|
|
mUrl = url;
|
2013-04-26 23:17:37 +00:00
|
|
|
mBaseDomain = "";
|
2013-04-10 18:02:05 +00:00
|
|
|
mUserSearch = "";
|
2011-12-19 18:44:52 +00:00
|
|
|
mExternal = external;
|
|
|
|
mParentId = parentId;
|
2012-08-09 20:52:58 +00:00
|
|
|
mTitle = title == null ? "" : title;
|
2011-11-18 18:28:17 +00:00
|
|
|
mFavicon = null;
|
|
|
|
mFaviconUrl = null;
|
2012-05-29 21:10:48 +00:00
|
|
|
mFaviconSize = 0;
|
2013-11-06 23:21:56 +00:00
|
|
|
mHasFeeds = false;
|
|
|
|
mHasOpenSearch = false;
|
2013-12-12 00:28:15 +00:00
|
|
|
mSiteIdentity = new SiteIdentity();
|
2012-06-02 18:23:45 +00:00
|
|
|
mReaderEnabled = false;
|
2012-09-11 17:51:44 +00:00
|
|
|
mEnteringReaderMode = false;
|
2011-11-18 18:28:17 +00:00
|
|
|
mThumbnail = null;
|
|
|
|
mHistoryIndex = -1;
|
2012-05-17 06:07:55 +00:00
|
|
|
mHistorySize = 0;
|
2011-11-18 18:28:17 +00:00
|
|
|
mBookmark = false;
|
2012-06-20 18:10:08 +00:00
|
|
|
mReadingListItem = false;
|
2011-11-18 18:28:17 +00:00
|
|
|
mFaviconLoadId = 0;
|
2011-12-14 00:23:35 +00:00
|
|
|
mContentType = "";
|
2012-08-07 14:39:03 +00:00
|
|
|
mZoomConstraints = new ZoomConstraints(false);
|
2012-01-31 14:30:47 +00:00
|
|
|
mPluginViews = new ArrayList<View>();
|
2012-04-27 20:04:47 +00:00
|
|
|
mPluginLayers = new HashMap<Object, Layer>();
|
2014-03-19 12:47:45 +00:00
|
|
|
mState = shouldShowProgress(url) ? STATE_LOADING : STATE_SUCCESS;
|
2014-02-26 19:02:21 +00:00
|
|
|
mLoadProgress = LOAD_PROGRESS_INIT;
|
2013-04-16 21:34:46 +00:00
|
|
|
|
|
|
|
// At startup, the background is set to a color specified by LayerView
|
|
|
|
// when the LayerView is created. Shortly after, this background color
|
|
|
|
// will be used before the tab's content is shown.
|
2013-05-29 18:31:52 +00:00
|
|
|
mBackgroundColor = DEFAULT_BACKGROUND_COLOR;
|
2014-02-11 02:08:03 +00:00
|
|
|
|
|
|
|
updateBookmark();
|
2013-01-25 18:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private ContentResolver getContentResolver() {
|
2013-07-15 19:12:15 +00:00
|
|
|
return mAppContext.getContentResolver();
|
2012-02-15 00:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDestroy() {
|
2012-10-25 16:57:06 +00:00
|
|
|
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.CLOSED);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getId() {
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2012-08-09 20:52:58 +00:00
|
|
|
public synchronized void onChange() {
|
|
|
|
mLastUsed = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized long getLastUsed() {
|
|
|
|
return mLastUsed;
|
|
|
|
}
|
|
|
|
|
2011-12-19 18:44:52 +00:00
|
|
|
public int getParentId() {
|
|
|
|
return mParentId;
|
|
|
|
}
|
|
|
|
|
2012-03-05 21:20:04 +00:00
|
|
|
// may be null if user-entered query hasn't yet been resolved to a URI
|
2012-08-09 20:52:58 +00:00
|
|
|
public synchronized String getURL() {
|
2011-11-18 18:28:17 +00:00
|
|
|
return mUrl;
|
|
|
|
}
|
|
|
|
|
2013-04-10 18:02:05 +00:00
|
|
|
// mUserSearch should never be null, but it may be an empty string
|
|
|
|
public synchronized String getUserSearch() {
|
|
|
|
return mUserSearch;
|
|
|
|
}
|
|
|
|
|
2012-08-09 20:52:58 +00:00
|
|
|
// mTitle should never be null, but it may be an empty string
|
|
|
|
public synchronized String getTitle() {
|
|
|
|
return mTitle;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
public String getDisplayTitle() {
|
|
|
|
if (mTitle != null && mTitle.length() > 0) {
|
|
|
|
return mTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mUrl;
|
|
|
|
}
|
|
|
|
|
2013-04-26 23:17:37 +00:00
|
|
|
public String getBaseDomain() {
|
|
|
|
return mBaseDomain;
|
|
|
|
}
|
|
|
|
|
2012-11-05 11:42:25 +00:00
|
|
|
public Bitmap getFavicon() {
|
2011-11-18 18:28:17 +00:00
|
|
|
return mFavicon;
|
|
|
|
}
|
|
|
|
|
2013-09-17 14:27:37 +00:00
|
|
|
public BitmapDrawable getThumbnail() {
|
2011-11-30 03:54:07 +00:00
|
|
|
return mThumbnail;
|
|
|
|
}
|
|
|
|
|
2012-12-03 19:27:34 +00:00
|
|
|
public Bitmap getThumbnailBitmap(int width, int height) {
|
|
|
|
if (mThumbnailBitmap != null) {
|
|
|
|
// Bug 787318 - Honeycomb has a bug with bitmap caching, we can't
|
|
|
|
// reuse the bitmap there.
|
|
|
|
boolean honeycomb = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
|
|
|
|
&& Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR2);
|
|
|
|
boolean sizeChange = mThumbnailBitmap.getWidth() != width
|
|
|
|
|| mThumbnailBitmap.getHeight() != height;
|
|
|
|
if (honeycomb || sizeChange) {
|
|
|
|
mThumbnailBitmap = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mThumbnailBitmap == null) {
|
2013-07-04 13:53:25 +00:00
|
|
|
Bitmap.Config config = (GeckoAppShell.getScreenDepth() == 24) ?
|
|
|
|
Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
|
|
|
|
mThumbnailBitmap = Bitmap.createBitmap(width, height, config);
|
2012-10-31 15:44:53 +00:00
|
|
|
}
|
2012-06-14 16:08:51 +00:00
|
|
|
|
2012-12-03 19:27:34 +00:00
|
|
|
return mThumbnailBitmap;
|
2012-06-14 16:08:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 03:54:07 +00:00
|
|
|
public void updateThumbnail(final Bitmap b) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-30 03:54:07 +00:00
|
|
|
public void run() {
|
2011-12-08 01:10:21 +00:00
|
|
|
if (b != null) {
|
2011-12-12 20:04:59 +00:00
|
|
|
try {
|
2014-01-07 22:12:04 +00:00
|
|
|
mThumbnail = new BitmapDrawable(mAppContext.getResources(), b);
|
2012-07-24 17:31:51 +00:00
|
|
|
if (mState == Tab.STATE_SUCCESS)
|
|
|
|
saveThumbnailToDB();
|
2011-12-12 20:04:59 +00:00
|
|
|
} catch (OutOfMemoryError oom) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Unable to create/scale bitmap.", oom);
|
2011-12-12 20:04:59 +00:00
|
|
|
mThumbnail = null;
|
|
|
|
}
|
2011-12-08 01:10:21 +00:00
|
|
|
} else {
|
|
|
|
mThumbnail = null;
|
|
|
|
}
|
2012-10-25 16:57:06 +00:00
|
|
|
|
|
|
|
Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.THUMBNAIL);
|
2011-11-30 03:54:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-08-09 20:52:58 +00:00
|
|
|
public synchronized String getFaviconURL() {
|
2011-11-18 18:28:17 +00:00
|
|
|
return mFaviconUrl;
|
|
|
|
}
|
|
|
|
|
2013-11-06 23:21:56 +00:00
|
|
|
public boolean hasFeeds() {
|
|
|
|
return mHasFeeds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasOpenSearch() {
|
|
|
|
return mHasOpenSearch;
|
2013-04-03 19:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 00:28:15 +00:00
|
|
|
public SiteIdentity getSiteIdentity() {
|
|
|
|
return mSiteIdentity;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
public boolean getReaderEnabled() {
|
|
|
|
return mReaderEnabled;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
public boolean isBookmark() {
|
|
|
|
return mBookmark;
|
|
|
|
}
|
|
|
|
|
2012-06-20 18:10:08 +00:00
|
|
|
public boolean isReadingListItem() {
|
|
|
|
return mReadingListItem;
|
|
|
|
}
|
|
|
|
|
2011-12-19 18:44:52 +00:00
|
|
|
public boolean isExternal() {
|
|
|
|
return mExternal;
|
|
|
|
}
|
|
|
|
|
2012-08-09 20:52:58 +00:00
|
|
|
public synchronized void updateURL(String url) {
|
2011-11-18 18:28:17 +00:00
|
|
|
if (url != null && url.length() > 0) {
|
2011-11-21 19:08:34 +00:00
|
|
|
mUrl = url;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 18:02:05 +00:00
|
|
|
private synchronized void updateUserSearch(String userSearch) {
|
|
|
|
mUserSearch = userSearch;
|
|
|
|
}
|
|
|
|
|
2013-08-19 22:14:37 +00:00
|
|
|
public void setErrorType(String type) {
|
|
|
|
if ("blocked".equals(type))
|
|
|
|
setErrorType(ErrorType.BLOCKED);
|
|
|
|
else if ("certerror".equals(type))
|
|
|
|
setErrorType(ErrorType.CERT_ERROR);
|
|
|
|
else if ("neterror".equals(type))
|
|
|
|
setErrorType(ErrorType.NET_ERROR);
|
|
|
|
else
|
|
|
|
setErrorType(ErrorType.NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setErrorType(ErrorType type) {
|
|
|
|
mErrorType = type;
|
2011-12-14 00:23:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-19 22:14:37 +00:00
|
|
|
public ErrorType getErrorType() {
|
|
|
|
return mErrorType;
|
2011-12-14 00:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setContentType(String contentType) {
|
2012-09-24 23:42:53 +00:00
|
|
|
mContentType = (contentType == null) ? "" : contentType;
|
2011-12-14 00:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getContentType() {
|
|
|
|
return mContentType;
|
|
|
|
}
|
|
|
|
|
2012-08-09 20:52:58 +00:00
|
|
|
public synchronized void updateTitle(String title) {
|
2013-11-23 01:12:19 +00:00
|
|
|
// Keep the title unchanged while entering reader mode.
|
|
|
|
if (mEnteringReaderMode) {
|
2012-09-11 17:51:44 +00:00
|
|
|
return;
|
2013-11-23 01:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there was a title, but it hasn't changed, do nothing.
|
|
|
|
if (mTitle != null &&
|
|
|
|
TextUtils.equals(mTitle, title)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-11 17:51:44 +00:00
|
|
|
|
2011-11-21 19:08:34 +00:00
|
|
|
mTitle = (title == null ? "" : title);
|
2012-10-25 16:57:06 +00:00
|
|
|
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.TITLE);
|
2012-01-12 20:22:48 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-03-07 21:58:31 +00:00
|
|
|
public void setState(int state) {
|
2012-04-27 17:52:21 +00:00
|
|
|
mState = state;
|
2012-09-11 17:51:44 +00:00
|
|
|
|
|
|
|
if (mState != Tab.STATE_LOADING)
|
|
|
|
mEnteringReaderMode = false;
|
2012-10-24 16:04:44 +00:00
|
|
|
}
|
2012-03-07 21:58:31 +00:00
|
|
|
|
|
|
|
public int getState() {
|
|
|
|
return mState;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 14:39:03 +00:00
|
|
|
public void setZoomConstraints(ZoomConstraints constraints) {
|
|
|
|
mZoomConstraints = constraints;
|
2012-05-18 15:24:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 14:39:03 +00:00
|
|
|
public ZoomConstraints getZoomConstraints() {
|
|
|
|
return mZoomConstraints;
|
2012-05-18 15:24:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
public void setIsRTL(boolean aIsRTL) {
|
|
|
|
mIsRTL = aIsRTL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getIsRTL() {
|
|
|
|
return mIsRTL;
|
|
|
|
}
|
|
|
|
|
2012-01-25 00:31:33 +00:00
|
|
|
public void setHasTouchListeners(boolean aValue) {
|
|
|
|
mHasTouchListeners = aValue;
|
|
|
|
}
|
|
|
|
|
2012-02-29 17:09:43 +00:00
|
|
|
public boolean getHasTouchListeners() {
|
2012-01-25 00:31:33 +00:00
|
|
|
return mHasTouchListeners;
|
|
|
|
}
|
|
|
|
|
2013-09-12 14:50:03 +00:00
|
|
|
public void setFaviconLoadId(int faviconLoadId) {
|
2011-11-18 18:28:17 +00:00
|
|
|
mFaviconLoadId = faviconLoadId;
|
|
|
|
}
|
|
|
|
|
2013-09-12 14:50:03 +00:00
|
|
|
public int getFaviconLoadId() {
|
2011-11-18 18:28:17 +00:00
|
|
|
return mFaviconLoadId;
|
|
|
|
}
|
|
|
|
|
2013-11-04 19:48:58 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the favicon changed.
|
|
|
|
*/
|
|
|
|
public boolean updateFavicon(Bitmap favicon) {
|
|
|
|
if (mFavicon == favicon) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
mFavicon = favicon;
|
2013-11-04 19:48:58 +00:00
|
|
|
return true;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 20:52:58 +00:00
|
|
|
public synchronized void updateFaviconURL(String faviconUrl, int size) {
|
2012-05-29 21:10:48 +00:00
|
|
|
// If we already have an "any" sized icon, don't update the icon.
|
|
|
|
if (mFaviconSize == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Only update the favicon if it's bigger than the current favicon.
|
|
|
|
// We use -1 to represent icons with sizes="any".
|
2012-06-08 00:19:34 +00:00
|
|
|
if (size == -1 || size >= mFaviconSize) {
|
2012-05-29 21:10:48 +00:00
|
|
|
mFaviconUrl = faviconUrl;
|
|
|
|
mFaviconSize = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 20:52:58 +00:00
|
|
|
public synchronized void clearFavicon() {
|
2012-09-11 17:51:44 +00:00
|
|
|
// Keep the favicon unchanged while entering reader mode
|
|
|
|
if (mEnteringReaderMode)
|
|
|
|
return;
|
|
|
|
|
2012-05-29 21:10:48 +00:00
|
|
|
mFavicon = null;
|
|
|
|
mFaviconUrl = null;
|
|
|
|
mFaviconSize = 0;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 23:21:56 +00:00
|
|
|
public void setHasFeeds(boolean hasFeeds) {
|
|
|
|
mHasFeeds = hasFeeds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHasOpenSearch(boolean hasOpenSearch) {
|
|
|
|
mHasOpenSearch = hasOpenSearch;
|
2013-04-03 19:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 16:07:58 +00:00
|
|
|
public void updateIdentityData(JSONObject identityData) {
|
2013-12-12 00:28:15 +00:00
|
|
|
mSiteIdentity.update(identityData);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
public void setReaderEnabled(boolean readerEnabled) {
|
|
|
|
mReaderEnabled = readerEnabled;
|
2012-10-25 16:57:06 +00:00
|
|
|
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.MENU_UPDATED);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 18:51:41 +00:00
|
|
|
void updateBookmark() {
|
2014-02-11 02:08:03 +00:00
|
|
|
if (getURL() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-10-25 16:57:06 +00:00
|
|
|
public void run() {
|
|
|
|
final String url = getURL();
|
2014-02-11 02:08:03 +00:00
|
|
|
if (url == null) {
|
2012-10-25 16:57:06 +00:00
|
|
|
return;
|
2012-06-20 18:10:08 +00:00
|
|
|
}
|
2012-07-24 23:12:12 +00:00
|
|
|
|
2014-02-12 19:50:35 +00:00
|
|
|
final int flags = BrowserDB.getItemFlags(getContentResolver(), url);
|
|
|
|
mBookmark = (flags & Bookmarks.FLAG_BOOKMARK) > 0;
|
|
|
|
mReadingListItem = (flags & Bookmarks.FLAG_READING) > 0;
|
2012-07-24 23:12:12 +00:00
|
|
|
Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.MENU_UPDATED);
|
|
|
|
}
|
2012-10-25 16:57:06 +00:00
|
|
|
});
|
2012-06-20 18:10:08 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
public void addBookmark() {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-02-15 00:23:06 +00:00
|
|
|
public void run() {
|
2012-03-05 21:20:04 +00:00
|
|
|
String url = getURL();
|
|
|
|
if (url == null)
|
|
|
|
return;
|
|
|
|
|
2013-01-25 18:51:41 +00:00
|
|
|
BrowserDB.addBookmark(getContentResolver(), mTitle, url);
|
2012-02-15 00:23:06 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removeBookmark() {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-02-15 00:23:06 +00:00
|
|
|
public void run() {
|
2012-03-05 21:20:04 +00:00
|
|
|
String url = getURL();
|
|
|
|
if (url == null)
|
|
|
|
return;
|
|
|
|
|
2013-01-25 18:51:41 +00:00
|
|
|
BrowserDB.removeBookmarksWithURL(getContentResolver(), url);
|
2012-02-15 00:23:06 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2014-03-24 22:38:57 +00:00
|
|
|
public void addToReadingList() {
|
|
|
|
if (!mReaderEnabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
try {
|
|
|
|
json.put("tabID", String.valueOf(getId()));
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "JSON error - failing to add to reading list", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Add", json.toString());
|
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
}
|
|
|
|
|
2013-05-20 17:35:03 +00:00
|
|
|
public void toggleReaderMode() {
|
2013-11-22 07:33:28 +00:00
|
|
|
if (AboutPages.isAboutReader(mUrl)) {
|
2013-05-30 23:26:38 +00:00
|
|
|
Tabs.getInstance().loadUrl(ReaderModeUtils.getUrlFromAboutReader(mUrl));
|
2013-05-20 17:35:03 +00:00
|
|
|
} else if (mReaderEnabled) {
|
|
|
|
mEnteringReaderMode = true;
|
2013-10-14 13:58:16 +00:00
|
|
|
Tabs.getInstance().loadUrl(ReaderModeUtils.getAboutReaderForUrl(mUrl, mId));
|
2013-05-20 17:35:03 +00:00
|
|
|
}
|
2012-06-02 18:23:45 +00:00
|
|
|
}
|
|
|
|
|
2012-09-11 17:51:44 +00:00
|
|
|
public boolean isEnteringReaderMode() {
|
|
|
|
return mEnteringReaderMode;
|
|
|
|
}
|
|
|
|
|
2012-08-02 21:15:17 +00:00
|
|
|
public void doReload() {
|
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);
|
|
|
|
}
|
|
|
|
|
2012-08-02 21:15:17 +00:00
|
|
|
// Our version of nsSHistory::GetCanGoBack
|
2012-05-24 22:47:49 +00:00
|
|
|
public boolean canDoBack() {
|
2012-08-02 21:15:17 +00:00
|
|
|
return mHistoryIndex > 0;
|
2012-05-24 22:47:49 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
public boolean doBack() {
|
2012-08-02 21:15:17 +00:00
|
|
|
if (!canDoBack())
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
2012-08-02 21:15:17 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-07 03:53:01 +00:00
|
|
|
public boolean showBackHistory() {
|
|
|
|
if (!canDoBack())
|
|
|
|
return false;
|
|
|
|
return this.showHistory(Math.max(mHistoryIndex - MAX_HISTORY_LIST_SIZE, 0), mHistoryIndex, mHistoryIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean showForwardHistory() {
|
|
|
|
if (!canDoForward())
|
|
|
|
return false;
|
|
|
|
return this.showHistory(mHistoryIndex, Math.min(mHistorySize - 1, mHistoryIndex + MAX_HISTORY_LIST_SIZE), mHistoryIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean showAllHistory() {
|
|
|
|
if (!canDoForward() && !canDoBack())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int min = mHistoryIndex - MAX_HISTORY_LIST_SIZE / 2;
|
|
|
|
int max = mHistoryIndex + MAX_HISTORY_LIST_SIZE / 2;
|
|
|
|
if (min < 0) {
|
|
|
|
max -= min;
|
|
|
|
}
|
|
|
|
if (max > mHistorySize - 1) {
|
|
|
|
min -= max - (mHistorySize - 1);
|
|
|
|
max = mHistorySize - 1;
|
|
|
|
}
|
|
|
|
min = Math.max(min, 0);
|
|
|
|
|
|
|
|
return this.showHistory(min, max, mHistoryIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method will show the history starting on fromIndex until toIndex of the history.
|
|
|
|
*/
|
|
|
|
public boolean showHistory(int fromIndex, int toIndex, int selIndex) {
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
try {
|
|
|
|
json.put("fromIndex", fromIndex);
|
|
|
|
json.put("toIndex", toIndex);
|
|
|
|
json.put("selIndex", selIndex);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "JSON error", e);
|
|
|
|
}
|
|
|
|
GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:ShowHistory", json.toString());
|
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-02 21:15:17 +00:00
|
|
|
public void 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);
|
|
|
|
}
|
|
|
|
|
2012-08-02 21:15:17 +00:00
|
|
|
// Our version of nsSHistory::GetCanGoForward
|
2011-11-18 18:28:17 +00:00
|
|
|
public boolean canDoForward() {
|
2012-08-02 21:15:17 +00:00
|
|
|
return mHistoryIndex < mHistorySize - 1;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean doForward() {
|
2012-08-02 21:15:17 +00:00
|
|
|
if (!canDoForward())
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
2012-08-02 21:15:17 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleSessionHistoryMessage(String event, JSONObject message) throws JSONException {
|
|
|
|
if (event.equals("New")) {
|
2012-08-02 21:15:17 +00:00
|
|
|
final String url = message.getString("url");
|
2011-11-18 18:28:17 +00:00
|
|
|
mHistoryIndex++;
|
2012-05-17 06:07:55 +00:00
|
|
|
mHistorySize = mHistoryIndex + 1;
|
2011-11-18 18:28:17 +00:00
|
|
|
} else if (event.equals("Back")) {
|
2012-08-02 21:15:17 +00:00
|
|
|
if (!canDoBack()) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Received unexpected back notification");
|
2011-11-18 18:28:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHistoryIndex--;
|
|
|
|
} else if (event.equals("Forward")) {
|
2012-08-02 21:15:17 +00:00
|
|
|
if (!canDoForward()) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Received unexpected forward notification");
|
2011-11-18 18:28:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHistoryIndex++;
|
|
|
|
} else if (event.equals("Goto")) {
|
|
|
|
int index = message.getInt("index");
|
2012-05-17 06:07:55 +00:00
|
|
|
if (index < 0 || index >= mHistorySize) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Received unexpected history-goto notification");
|
2011-11-18 18:28:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHistoryIndex = index;
|
|
|
|
} else if (event.equals("Purge")) {
|
2012-08-02 21:15:17 +00:00
|
|
|
int numEntries = message.getInt("numEntries");
|
|
|
|
if (numEntries > mHistorySize) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Received unexpectedly large number of history entries to purge");
|
2012-05-17 06:07:55 +00:00
|
|
|
mHistoryIndex = -1;
|
2012-08-02 21:15:17 +00:00
|
|
|
mHistorySize = 0;
|
|
|
|
return;
|
2012-05-17 06:07:55 +00:00
|
|
|
}
|
2012-08-02 21:15:17 +00:00
|
|
|
|
|
|
|
mHistorySize -= numEntries;
|
|
|
|
mHistoryIndex -= numEntries;
|
|
|
|
|
|
|
|
// If we weren't at the last history entry, mHistoryIndex may have become too small
|
|
|
|
if (mHistoryIndex < -1)
|
2013-02-07 03:53:01 +00:00
|
|
|
mHistoryIndex = -1;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-27 20:44:51 +00:00
|
|
|
void handleLocationChange(JSONObject message) throws JSONException {
|
|
|
|
final String uri = message.getString("uri");
|
2013-11-22 22:11:08 +00:00
|
|
|
final String oldUrl = getURL();
|
2014-02-11 02:08:03 +00:00
|
|
|
final boolean sameDocument = message.getBoolean("sameDocument");
|
2013-11-22 22:11:08 +00:00
|
|
|
mEnteringReaderMode = ReaderModeUtils.isEnteringReaderMode(oldUrl, uri);
|
2013-11-27 03:48:30 +00:00
|
|
|
|
2014-02-11 02:08:03 +00:00
|
|
|
if (!TextUtils.equals(oldUrl, uri)) {
|
|
|
|
updateURL(uri);
|
|
|
|
updateBookmark();
|
|
|
|
if (!sameDocument) {
|
|
|
|
// We can unconditionally clear the favicon and title here: we
|
|
|
|
// already filtered both cases in which this was a (pseudo-)
|
|
|
|
// spurious location change, so we're definitely loading a new
|
|
|
|
// page.
|
|
|
|
clearFavicon();
|
|
|
|
updateTitle(null);
|
|
|
|
}
|
2013-11-27 03:48:30 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 02:08:03 +00:00
|
|
|
if (sameDocument) {
|
2012-08-27 20:44:51 +00:00
|
|
|
// We can get a location change event for the same document with an anchor tag
|
2013-04-16 22:07:11 +00:00
|
|
|
// Notify listeners so that buttons like back or forward will update themselves
|
2013-11-22 22:11:08 +00:00
|
|
|
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, oldUrl);
|
2012-08-27 20:44:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setContentType(message.getString("contentType"));
|
2014-02-11 02:08:03 +00:00
|
|
|
updateUserSearch(message.getString("userSearch"));
|
|
|
|
mBaseDomain = message.optString("baseDomain");
|
2013-11-27 03:48:30 +00:00
|
|
|
|
2013-11-06 23:21:56 +00:00
|
|
|
setHasFeeds(false);
|
2013-12-29 03:14:13 +00:00
|
|
|
setHasOpenSearch(false);
|
2012-08-27 20:44:51 +00:00
|
|
|
updateIdentityData(null);
|
|
|
|
setReaderEnabled(false);
|
|
|
|
setZoomConstraints(new ZoomConstraints(true));
|
|
|
|
setHasTouchListeners(false);
|
2013-05-29 18:31:52 +00:00
|
|
|
setBackgroundColor(DEFAULT_BACKGROUND_COLOR);
|
2013-08-19 22:14:37 +00:00
|
|
|
setErrorType(ErrorType.NONE);
|
2014-03-07 17:54:52 +00:00
|
|
|
setLoadProgressIfLoading(LOAD_PROGRESS_LOCATION_CHANGE);
|
2012-08-27 20:44:51 +00:00
|
|
|
|
2013-11-22 22:11:08 +00:00
|
|
|
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, oldUrl);
|
2012-08-27 20:44:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 07:33:28 +00:00
|
|
|
private static boolean shouldShowProgress(final String url) {
|
2014-03-19 12:47:45 +00:00
|
|
|
return !AboutPages.isAboutPage(url);
|
2013-02-25 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 14:08:05 +00:00
|
|
|
void handleDocumentStart(boolean restoring, String url) {
|
2014-02-26 19:02:21 +00:00
|
|
|
setLoadProgress(LOAD_PROGRESS_START);
|
2014-03-19 14:08:05 +00:00
|
|
|
setState((!restoring && shouldShowProgress(url)) ? STATE_LOADING : STATE_SUCCESS);
|
2013-02-25 04:51:05 +00:00
|
|
|
updateIdentityData(null);
|
|
|
|
setReaderEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleDocumentStop(boolean success) {
|
|
|
|
setState(success ? STATE_SUCCESS : STATE_ERROR);
|
|
|
|
|
|
|
|
final String oldURL = getURL();
|
|
|
|
final Tab tab = this;
|
2014-02-26 19:02:21 +00:00
|
|
|
tab.setLoadProgress(LOAD_PROGRESS_STOP);
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.getBackgroundHandler().postDelayed(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2013-02-25 04:51:05 +00:00
|
|
|
public void run() {
|
|
|
|
// tab.getURL() may return null
|
|
|
|
if (!TextUtils.equals(oldURL, getURL()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ThumbnailHelper.getInstance().getAndProcessThumbnailFor(tab);
|
|
|
|
}
|
|
|
|
}, 500);
|
2014-02-26 19:02:21 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 19:06:21 +00:00
|
|
|
void handleContentLoaded() {
|
2014-03-07 17:54:52 +00:00
|
|
|
setLoadProgressIfLoading(LOAD_PROGRESS_LOADED);
|
2014-02-26 19:02:21 +00:00
|
|
|
}
|
2013-02-25 04:51:05 +00:00
|
|
|
|
2012-10-09 18:26:33 +00:00
|
|
|
protected void saveThumbnailToDB() {
|
2011-11-30 06:02:55 +00:00
|
|
|
try {
|
2012-03-05 21:20:04 +00:00
|
|
|
String url = getURL();
|
|
|
|
if (url == null)
|
|
|
|
return;
|
|
|
|
|
2013-01-25 18:51:41 +00:00
|
|
|
BrowserDB.updateThumbnailForUrl(getContentResolver(), url, mThumbnail);
|
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-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
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
public void addPluginLayer(Object surfaceOrView, Layer layer) {
|
2012-06-15 15:27:40 +00:00
|
|
|
synchronized(mPluginLayers) {
|
|
|
|
mPluginLayers.put(surfaceOrView, layer);
|
|
|
|
}
|
2012-01-31 14:40:58 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
public Layer getPluginLayer(Object surfaceOrView) {
|
2012-06-15 15:27:40 +00:00
|
|
|
synchronized(mPluginLayers) {
|
|
|
|
return mPluginLayers.get(surfaceOrView);
|
|
|
|
}
|
2012-01-31 14:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Layer> getPluginLayers() {
|
2012-06-15 15:27:40 +00:00
|
|
|
synchronized(mPluginLayers) {
|
|
|
|
return new ArrayList<Layer>(mPluginLayers.values());
|
|
|
|
}
|
2012-01-31 14:40:58 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
public Layer removePluginLayer(Object surfaceOrView) {
|
2012-06-15 15:27:40 +00:00
|
|
|
synchronized(mPluginLayers) {
|
|
|
|
return mPluginLayers.remove(surfaceOrView);
|
|
|
|
}
|
2012-01-31 14:40:58 +00:00
|
|
|
}
|
2012-04-23 17:29:14 +00:00
|
|
|
|
2012-12-15 15:43:57 +00:00
|
|
|
public int getBackgroundColor() {
|
|
|
|
return mBackgroundColor;
|
2012-04-23 17:29:14 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 15:43:57 +00:00
|
|
|
/** Sets a new color for the background. */
|
|
|
|
public void setBackgroundColor(int color) {
|
|
|
|
mBackgroundColor = color;
|
2012-04-23 17:29:14 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 15:43:57 +00:00
|
|
|
/** Parses and sets a new color for the background. */
|
|
|
|
public void setBackgroundColor(String newColor) {
|
|
|
|
setBackgroundColor(parseColorFromGecko(newColor));
|
2012-04-23 17:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parses a color from an RGB triple of the form "rgb([0-9]+, [0-9]+, [0-9]+)". If the color
|
|
|
|
// cannot be parsed, returns white.
|
|
|
|
private static int parseColorFromGecko(String string) {
|
|
|
|
if (sColorPattern == null) {
|
|
|
|
sColorPattern = Pattern.compile("rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)");
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher matcher = sColorPattern.matcher(string);
|
|
|
|
if (!matcher.matches()) {
|
|
|
|
return Color.WHITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int r = Integer.parseInt(matcher.group(1));
|
|
|
|
int g = Integer.parseInt(matcher.group(2));
|
|
|
|
int b = Integer.parseInt(matcher.group(3));
|
|
|
|
return Color.rgb(r, g, b);
|
|
|
|
}
|
2012-06-22 19:53:40 +00:00
|
|
|
|
|
|
|
public void setDesktopMode(boolean enabled) {
|
|
|
|
mDesktopMode = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getDesktopMode() {
|
|
|
|
return mDesktopMode;
|
|
|
|
}
|
2012-10-09 18:26:33 +00:00
|
|
|
|
|
|
|
public boolean isPrivate() {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-18 04:03:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the tab load progress to the given percentage.
|
|
|
|
*
|
|
|
|
* @param progressPercentage Percentage to set progress to (0-100)
|
|
|
|
*/
|
|
|
|
void setLoadProgress(int progressPercentage) {
|
|
|
|
mLoadProgress = progressPercentage;
|
|
|
|
}
|
|
|
|
|
2014-03-07 17:54:52 +00:00
|
|
|
/**
|
|
|
|
* Sets the tab load progress to the given percentage only if the tab is
|
|
|
|
* currently loading.
|
|
|
|
*
|
|
|
|
* about:neterror can trigger a STOP before other page load events (bug
|
|
|
|
* 976426), so any post-START events should make sure the page is loading
|
|
|
|
* before updating progress.
|
|
|
|
*
|
|
|
|
* @param progressPercentage Percentage to set progress to (0-100)
|
|
|
|
*/
|
|
|
|
void setLoadProgressIfLoading(int progressPercentage) {
|
|
|
|
if (getState() == STATE_LOADING) {
|
|
|
|
setLoadProgress(progressPercentage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-18 04:03:59 +00:00
|
|
|
/**
|
|
|
|
* Gets the tab load progress percentage.
|
|
|
|
*
|
|
|
|
* @return Current progress percentage
|
|
|
|
*/
|
|
|
|
public int getLoadProgress() {
|
|
|
|
return mLoadProgress;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|