Bug 724756 - removeBookmark can remove an arbitrary number of bookmarks. r=lucasr

This commit is contained in:
Margaret Leibovic 2012-02-09 10:01:57 -08:00
parent ae85a7084c
commit b40c38d30f
5 changed files with 29 additions and 7 deletions

View File

@ -76,6 +76,7 @@ import android.widget.Toast;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Map; import java.util.Map;
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserDB.URLColumns; import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.db.BrowserDB;
@ -472,16 +473,19 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
if (mContextMenuSubject == null) if (mContextMenuSubject == null)
return false; return false;
final int id;
final String url; final String url;
byte[] b = null; byte[] b = null;
String title = ""; String title = "";
if (mContextMenuSubject instanceof Cursor) { if (mContextMenuSubject instanceof Cursor) {
Cursor cursor = (Cursor)mContextMenuSubject; Cursor cursor = (Cursor)mContextMenuSubject;
id = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL)); url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON)); b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON));
title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE)); title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE));
} else if (mContextMenuSubject instanceof Map) { } else if (mContextMenuSubject instanceof Map) {
Map map = (Map)mContextMenuSubject; Map map = (Map)mContextMenuSubject;
id = -1;
url = (String)map.get(URLColumns.URL); url = (String)map.get(URLColumns.URL);
b = (byte[]) map.get(URLColumns.FAVICON); b = (byte[]) map.get(URLColumns.FAVICON);
title = (String)map.get(URLColumns.TITLE); title = (String)map.get(URLColumns.TITLE);
@ -500,7 +504,7 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
case R.id.remove_bookmark: { case R.id.remove_bookmark: {
GeckoAppShell.getHandler().post(new Runnable() { GeckoAppShell.getHandler().post(new Runnable() {
public void run() { public void run() {
BrowserDB.removeBookmark(mResolver, url); BrowserDB.removeBookmark(mResolver, id);
GeckoApp.mAppContext.mMainHandler.post(new Runnable() { GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() { public void run() {

View File

@ -552,7 +552,9 @@ public final class Tab {
@Override @Override
protected Void doInBackground(Void... unused) { protected Void doInBackground(Void... unused) {
ContentResolver resolver = Tabs.getInstance().getContentResolver(); ContentResolver resolver = Tabs.getInstance().getContentResolver();
BrowserDB.removeBookmark(resolver, getURL());
// We want to remove all bookmarks with this URL
BrowserDB.removeBookmarksWithURL(resolver, getURL());
return null; return null;
} }

View File

@ -330,7 +330,11 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface {
new String[] { uri }); new String[] { uri });
} }
public void removeBookmark(ContentResolver cr, String uri) { public void removeBookmark(ContentResolver cr, int id) {
// Not implemented
}
public void removeBookmarksWithURL(ContentResolver cr, String uri) {
if (Build.VERSION.SDK_INT >= 11) if (Build.VERSION.SDK_INT >= 11)
removeBookmarkPost11(cr, uri); removeBookmarkPost11(cr, uri);
else else

View File

@ -88,7 +88,9 @@ public class BrowserDB {
public void addBookmark(ContentResolver cr, String title, String uri); public void addBookmark(ContentResolver cr, String title, String uri);
public void removeBookmark(ContentResolver cr, String uri); public void removeBookmark(ContentResolver cr, int id);
public void removeBookmarksWithURL(ContentResolver cr, String uri);
public void updateBookmark(ContentResolver cr, String oldUri, String uri, String title, String keyword); public void updateBookmark(ContentResolver cr, String oldUri, String uri, String title, String keyword);
@ -167,8 +169,12 @@ public class BrowserDB {
sDb.addBookmark(cr, title, uri); sDb.addBookmark(cr, title, uri);
} }
public static void removeBookmark(ContentResolver cr, String uri) { public static void removeBookmark(ContentResolver cr, int id) {
sDb.removeBookmark(cr, uri); sDb.removeBookmark(cr, id);
}
public static void removeBookmarksWithURL(ContentResolver cr, String uri) {
sDb.removeBookmarksWithURL(cr, uri);
} }
public static void updateBookmark(ContentResolver cr, String oldUri, String uri, String title, String keyword) { public static void updateBookmark(ContentResolver cr, String oldUri, String uri, String title, String keyword) {

View File

@ -380,7 +380,13 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
cr.insert(appendProfile(Bookmarks.CONTENT_URI), values); cr.insert(appendProfile(Bookmarks.CONTENT_URI), values);
} }
public void removeBookmark(ContentResolver cr, String uri) { public void removeBookmark(ContentResolver cr, int id) {
cr.delete(appendProfile(Bookmarks.CONTENT_URI),
Bookmarks._ID + " = ?",
new String[] { String.valueOf(id) });
}
public void removeBookmarksWithURL(ContentResolver cr, String uri) {
cr.delete(appendProfile(Bookmarks.CONTENT_URI), cr.delete(appendProfile(Bookmarks.CONTENT_URI),
Bookmarks.URL + " = ?", Bookmarks.URL + " = ?",
new String[] { uri }); new String[] { uri });