Bug 910189: Part 2 - Enable removing of default engines. r=margaret

This commit is contained in:
Chenxia Liu 2013-12-20 10:35:10 -08:00
parent 41bf24c887
commit 123800a73f
4 changed files with 5 additions and 39 deletions

View File

@ -40,8 +40,6 @@ public class SearchEnginePreference extends Preference implements View.OnLongCli
// Specifies if this engine is configured as the default search engine.
private boolean mIsDefaultEngine;
// Specifies if this engine is one of the ones bundled with the app, which cannot be deleted.
private boolean mIsImmutableEngine;
// Dialog element labels.
private String[] mDialogItems;
@ -121,12 +119,7 @@ public class SearchEnginePreference extends Preference implements View.OnLongCli
public void setSearchEngineFromJSON(JSONObject geckoEngineJSON) throws JSONException {
final String engineName = geckoEngineJSON.getString("name");
final SpannableString titleSpannable = new SpannableString(engineName);
mIsImmutableEngine = geckoEngineJSON.getBoolean("immutable");
if (mIsImmutableEngine) {
// Delete the "Remove" option from the menu.
mDialogItems = new String[] { getContext().getResources().getString(R.string.pref_search_set_default) };
}
setTitle(titleSpannable);
final String iconURI = geckoEngineJSON.getString("iconURI");
@ -176,11 +169,6 @@ public class SearchEnginePreference extends Preference implements View.OnLongCli
return;
}
// If we are both default and immutable, we have no enabled items to show on the menu - abort.
if (mIsDefaultEngine && mIsImmutableEngine) {
return;
}
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getTitle().toString());
builder.setItems(mDialogItems, new DialogInterface.OnClickListener() {

View File

@ -45,7 +45,7 @@ public class SearchPreferenceCategory extends PreferenceCategory implements Geck
// Request list of search engines from Gecko.
GeckoAppShell.registerEventListener("SearchEngines:Data", this);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Get", null));
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
}
@Override

View File

@ -159,7 +159,7 @@ public class testDistribution extends ContentProviderTest {
private void checkSearchPlugin() {
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("SearchEngines:Data");
mActions.sendGeckoEvent("SearchEngines:Get", null);
mActions.sendGeckoEvent("SearchEngines:GetVisible", null);
try {
JSONObject data = new JSONObject(eventExpecter.blockForEventData());

View File

@ -6666,7 +6666,6 @@ var SearchEngines = {
init: function init() {
Services.obs.addObserver(this, "SearchEngines:Add", false);
Services.obs.addObserver(this, "SearchEngines:Get", false);
Services.obs.addObserver(this, "SearchEngines:GetVisible", false);
Services.obs.addObserver(this, "SearchEngines:SetDefault", false);
Services.obs.addObserver(this, "SearchEngines:Remove", false);
@ -6709,7 +6708,6 @@ var SearchEngines = {
uninit: function uninit() {
Services.obs.removeObserver(this, "SearchEngines:Add");
Services.obs.removeObserver(this, "SearchEngines:Get");
Services.obs.removeObserver(this, "SearchEngines:GetVisible");
Services.obs.removeObserver(this, "SearchEngines:SetDefault");
Services.obs.removeObserver(this, "SearchEngines:Remove");
@ -6718,28 +6716,19 @@ var SearchEngines = {
},
// Fetch list of search engines. all ? All engines : Visible engines only.
_handleSearchEnginesGet: function _handleSearchEnginesGet(rv, all) {
_handleSearchEnginesGetVisible: function _handleSearchEnginesGetVisible(rv, all) {
if (!Components.isSuccessCode(rv)) {
Cu.reportError("Could not initialize search service, bailing out.");
return;
}
let engineData;
if (all) {
engineData = Services.search.getEngines({});
} else {
engineData = Services.search.getVisibleEngines({});
}
// These engines are the bundled ones - they may not be uninstalled.
let immutableEngines = Services.search.getDefaultEngines();
let engineData = Services.search.getVisibleEngines({});
let searchEngines = engineData.map(function (engine) {
return {
name: engine.name,
identifier: engine.identifier,
iconURI: (engine.iconURI ? engine.iconURI.spec : null),
hidden: engine.hidden,
immutable: immutableEngines.indexOf(engine) != -1
hidden: engine.hidden
};
});
@ -6776,13 +6765,6 @@ var SearchEngines = {
} catch (e) {}
},
_handleSearchEnginesGetAll: function _handleSearchEnginesGetAll(rv) {
this._handleSearchEnginesGet(rv, true);
},
_handleSearchEnginesGetVisible: function _handleSearchEnginesGetVisible(rv) {
this._handleSearchEnginesGet(rv, false)
},
// Helper method to extract the engine name from a JSON. Simplifies the observe function.
_extractEngineFromJSON: function _extractEngineFromJSON(aData) {
let data = JSON.parse(aData);
@ -6798,10 +6780,6 @@ var SearchEngines = {
case "SearchEngines:GetVisible":
Services.search.init(this._handleSearchEnginesGetVisible.bind(this));
break;
case "SearchEngines:Get":
// Return a list of all engines, including "Hidden" ones.
Services.search.init(this._handleSearchEnginesGetAll.bind(this));
break;
case "SearchEngines:SetDefault":
engine = this._extractEngineFromJSON(aData);
// Move the new default search engine to the top of the search engine list.