Bug 582244 - Part 2: Add private browsing checks to native UI. r=mfinkle

This commit is contained in:
Brian Nicholson 2012-10-09 11:26:33 -07:00
Родитель 0c64f22d71
Коммит d5909ebe33
7 изменённых файлов: 61 добавлений и 17 удалений

Просмотреть файл

@ -483,7 +483,7 @@ public class AboutHomeContent extends ScrollView
});
Favicons favicons = mActivity.getFavicons();
favicons.loadFavicon(pageUrl, iconUrl,
favicons.loadFavicon(pageUrl, iconUrl, true,
new Favicons.OnFaviconLoadedListener() {
public void onFaviconLoaded(String url, Drawable favicon) {
if (favicon != null) {

Просмотреть файл

@ -543,7 +543,7 @@ abstract public class BrowserApp extends GeckoApp
private void loadFavicon(final Tab tab) {
maybeCancelFaviconLoad(tab);
long id = getFavicons().loadFavicon(tab.getURL(), tab.getFaviconURL(),
long id = getFavicons().loadFavicon(tab.getURL(), tab.getFaviconURL(), !tab.isPrivate(),
new Favicons.OnFaviconLoadedListener() {
public void onFaviconLoaded(String pageUrl, Drawable favicon) {

Просмотреть файл

@ -153,7 +153,7 @@ public class Favicons {
return mDbHelper.getFaviconUrlForPageUrl(pageUrl);
}
public long loadFavicon(String pageUrl, String faviconUrl,
public long loadFavicon(String pageUrl, String faviconUrl, boolean persist,
OnFaviconLoadedListener listener) {
// Handle the case where page url is empty
@ -162,7 +162,7 @@ public class Favicons {
listener.onFaviconLoaded(null, null);
}
LoadFaviconTask task = new LoadFaviconTask(pageUrl, faviconUrl, listener);
LoadFaviconTask task = new LoadFaviconTask(pageUrl, faviconUrl, persist, listener);
long taskId = task.getId();
mLoadTasks.put(taskId, task);
@ -214,8 +214,10 @@ public class Favicons {
private String mPageUrl;
private String mFaviconUrl;
private OnFaviconLoadedListener mListener;
private boolean mPersist;
public LoadFaviconTask(String pageUrl, String faviconUrl, OnFaviconLoadedListener listener) {
public LoadFaviconTask(String pageUrl, String faviconUrl, boolean persist,
OnFaviconLoadedListener listener) {
synchronized(this) {
mId = ++mNextFaviconLoadId;
}
@ -223,6 +225,7 @@ public class Favicons {
mPageUrl = pageUrl;
mFaviconUrl = faviconUrl;
mListener = listener;
mPersist = persist;
}
// Runs in background thread
@ -235,6 +238,10 @@ public class Favicons {
// Runs in background thread
private void saveFaviconToDb(BitmapDrawable favicon) {
if (!mPersist) {
return;
}
// since the Async task can run this on any number of threads in the
// pool, we need to protect against inserting the same url twice
synchronized(mDbHelper) {

Просмотреть файл

@ -101,6 +101,7 @@ FENNEC_JAVA_FILES = \
OnInterceptTouchListener.java \
PrefsHelper.java \
PrivateDataPreference.java \
PrivateTab.java \
PropertyAnimator.java \
ProfileMigrator.java \
PromptService.java \

Просмотреть файл

@ -0,0 +1,26 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* 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/. */
package org.mozilla.gecko;
public class PrivateTab extends Tab {
public PrivateTab(int id, String url, boolean external, int parentId, String title) {
super(id, url, external, parentId, title);
}
@Override
protected void addHistory(final String uri) {}
@Override
protected void updateHistory(final String uri, final String title) {}
@Override
protected void saveThumbnailToDB() {}
@Override
public boolean isPrivate() {
return true;
}
}

Просмотреть файл

@ -32,7 +32,7 @@ import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class Tab {
public class Tab {
private static final String LOGTAG = "GeckoTab";
private static Pattern sColorPattern;
@ -288,7 +288,15 @@ public final class Tab {
});
}
private void updateHistory(final String uri, final String title) {
protected void addHistory(final String uri) {
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {
GlobalHistory.getInstance().add(uri);
}
});
}
protected void updateHistory(final String uri, final String title) {
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {
GlobalHistory.getInstance().update(uri, title);
@ -504,11 +512,7 @@ public final class Tab {
final String url = message.getString("url");
mHistoryIndex++;
mHistorySize = mHistoryIndex + 1;
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {
GlobalHistory.getInstance().add(url);
}
});
addHistory(url);
} else if (event.equals("Back")) {
if (!canDoBack()) {
Log.e(LOGTAG, "Received unexpected back notification");
@ -573,7 +577,7 @@ public final class Tab {
});
}
private void saveThumbnailToDB() {
protected void saveThumbnailToDB() {
try {
String url = getURL();
if (url == null)
@ -660,4 +664,8 @@ public final class Tab {
public boolean getDesktopMode() {
return mDesktopMode;
}
public boolean isPrivate() {
return false;
}
}

Просмотреть файл

@ -72,8 +72,9 @@ public class Tabs implements GeckoEventListener {
return mTabs.size();
}
private Tab addTab(int id, String url, boolean external, int parentId, String title) {
final Tab tab = new Tab(id, url, external, parentId, title);
private Tab addTab(int id, String url, boolean external, int parentId, String title, boolean isPrivate) {
final Tab tab = isPrivate ? new PrivateTab(id, url, external, parentId, title) :
new Tab(id, url, external, parentId, title);
mTabs.put(id, tab);
mOrder.add(tab);
@ -250,7 +251,8 @@ public class Tabs implements GeckoEventListener {
message.isNull("uri") ? null : message.getString("uri"),
message.getBoolean("external"),
message.getInt("parentId"),
message.getString("title"));
message.getString("title"),
message.getBoolean("isPrivate"));
}
if (message.getBoolean("selected"))
@ -468,7 +470,7 @@ public class Tabs implements GeckoEventListener {
if ((flags & LOADURL_NEW_TAB) != 0) {
tabId = getNextTabId();
args.put("tabID", tabId);
addTab(tabId, null, false, parentId, url);
addTab(tabId, null, false, parentId, url, isPrivate);
}
} catch (Exception e) {
Log.e(LOGTAG, "error building JSON arguments");