зеркало из https://github.com/mozilla/gecko-dev.git
Bug 910189: Part 3 - Restore default search engines (no dialog). r=margaret
This commit is contained in:
Родитель
d200044abf
Коммит
a054d4ae70
2
CLOBBER
2
CLOBBER
|
@ -22,4 +22,4 @@
|
|||
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
|
||||
# don't change CLOBBER for WebIDL changes any more.
|
||||
|
||||
Bug 878935 landed without a UUID change (and was since backed out)
|
||||
Bug 910189 requires a clobber due to Proguard inner class errors from bug 946083.
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.os.Bundle;
|
|||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
/* A simple implementation of PreferenceFragment for large screen devices
|
||||
|
|
|
@ -77,7 +77,9 @@ public class GeckoPreferences
|
|||
private boolean mInitialized = false;
|
||||
private int mPrefsRequestId = 0;
|
||||
|
||||
// These match keys in resources/xml/preferences.xml.in.
|
||||
// These match keys in resources/xml*/preferences*.xml
|
||||
private static String PREFS_SEARCH_RESTORE_DEFAULTS = NON_PREF_PREFIX + "search.restore_defaults";
|
||||
|
||||
private static String PREFS_ANNOUNCEMENTS_ENABLED = NON_PREF_PREFIX + "privacy.announcements.enabled";
|
||||
private static String PREFS_DATA_REPORTING_PREFERENCES = NON_PREF_PREFIX + "datareporting.preferences";
|
||||
private static String PREFS_TELEMETRY_ENABLED = "datareporting.telemetry.enabled";
|
||||
|
@ -389,6 +391,14 @@ public class GeckoPreferences
|
|||
preferences.removePreference(pref);
|
||||
i--;
|
||||
continue;
|
||||
} else if (PREFS_SEARCH_RESTORE_DEFAULTS.equals(key)) {
|
||||
pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
GeckoPreferences.this.restoreDefaultSearchEngines();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Some Preference UI elements are not actually preferences,
|
||||
|
@ -404,14 +414,31 @@ public class GeckoPreferences
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore default search engines in Gecko and retrigger a search engine refresh.
|
||||
*/
|
||||
protected void restoreDefaultSearchEngines() {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:RestoreDefaults", null));
|
||||
|
||||
// Send message to Gecko to get engines. SearchPreferenceCategory listens for the response.
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
int itemId = item.getItemId();
|
||||
switch (itemId) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Generated R.id.* apparently aren't constant expressions, so they can't be switched.
|
||||
if (itemId == R.id.restore_defaults) {
|
||||
restoreDefaultSearchEngines();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,18 +43,19 @@ public class SearchPreferenceCategory extends PreferenceCategory implements Geck
|
|||
// Ensures default engine remains at top of list.
|
||||
setOrderingAsAdded(true);
|
||||
|
||||
// Request list of search engines from Gecko.
|
||||
// Register for SearchEngines messages and request list of search engines from Gecko.
|
||||
GeckoAppShell.registerEventListener("SearchEngines:Data", this);
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareForRemoval() {
|
||||
GeckoAppShell.unregisterEventListener("SearchEngines:Data", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(String event, final JSONObject data) {
|
||||
if (event.equals("SearchEngines:Data")) {
|
||||
// We are no longer interested in this event from Gecko, as we do not request it again with
|
||||
// this instance.
|
||||
GeckoAppShell.unregisterEventListener("SearchEngines:Data", this);
|
||||
|
||||
// Parse engines array from JSON.
|
||||
JSONArray engines;
|
||||
try {
|
||||
|
@ -64,6 +65,9 @@ public class SearchPreferenceCategory extends PreferenceCategory implements Geck
|
|||
return;
|
||||
}
|
||||
|
||||
// Clear the preferences category from this thread.
|
||||
this.removeAll();
|
||||
|
||||
// Create an element in this PreferenceCategory for each engine.
|
||||
for (int i = 0; i < engines.length(); i++) {
|
||||
try {
|
||||
|
|
|
@ -6667,8 +6667,9 @@ var SearchEngines = {
|
|||
init: function init() {
|
||||
Services.obs.addObserver(this, "SearchEngines:Add", false);
|
||||
Services.obs.addObserver(this, "SearchEngines:GetVisible", false);
|
||||
Services.obs.addObserver(this, "SearchEngines:SetDefault", false);
|
||||
Services.obs.addObserver(this, "SearchEngines:Remove", false);
|
||||
Services.obs.addObserver(this, "SearchEngines:RestoreDefaults", false);
|
||||
Services.obs.addObserver(this, "SearchEngines:SetDefault", false);
|
||||
|
||||
let filter = {
|
||||
matches: function (aElement) {
|
||||
|
@ -6709,8 +6710,9 @@ var SearchEngines = {
|
|||
uninit: function uninit() {
|
||||
Services.obs.removeObserver(this, "SearchEngines:Add");
|
||||
Services.obs.removeObserver(this, "SearchEngines:GetVisible");
|
||||
Services.obs.removeObserver(this, "SearchEngines:SetDefault");
|
||||
Services.obs.removeObserver(this, "SearchEngines:Remove");
|
||||
Services.obs.removeObserver(this, "SearchEngines:RestoreDefaults");
|
||||
Services.obs.removeObserver(this, "SearchEngines:SetDefault");
|
||||
if (this._contextMenuId != null)
|
||||
NativeWindow.contextmenus.remove(this._contextMenuId);
|
||||
},
|
||||
|
@ -6780,12 +6782,6 @@ var SearchEngines = {
|
|||
case "SearchEngines:GetVisible":
|
||||
Services.search.init(this._handleSearchEnginesGetVisible.bind(this));
|
||||
break;
|
||||
case "SearchEngines:SetDefault":
|
||||
engine = this._extractEngineFromJSON(aData);
|
||||
// Move the new default search engine to the top of the search engine list.
|
||||
Services.search.moveEngine(engine, 0);
|
||||
Services.search.defaultEngine = engine;
|
||||
break;
|
||||
case "SearchEngines:Remove":
|
||||
// Make sure the engine isn't hidden before removing it, to make sure it's
|
||||
// visible if the user later re-adds it (works around bug 341833)
|
||||
|
@ -6793,6 +6789,17 @@ var SearchEngines = {
|
|||
engine.hidden = false;
|
||||
Services.search.removeEngine(engine);
|
||||
break;
|
||||
case "SearchEngines:RestoreDefaults":
|
||||
// Un-hides all default engines.
|
||||
Services.search.restoreDefaultEngines();
|
||||
break;
|
||||
case "SearchEngines:SetDefault":
|
||||
engine = this._extractEngineFromJSON(aData);
|
||||
// Move the new default search engine to the top of the search engine list.
|
||||
Services.search.moveEngine(engine, 0);
|
||||
Services.search.defaultEngine = engine;
|
||||
break;
|
||||
|
||||
default:
|
||||
dump("Unexpected message type observed: " + aTopic);
|
||||
break;
|
||||
|
|
Загрузка…
Ссылка в новой задаче