Bug 702653 - Add prefs for flash activation on demand/always on/off. r=mfinkle a=no-cpp

This commit is contained in:
Margaret Leibovic 2011-12-13 14:28:45 -08:00
Родитель 1436be7d06
Коммит ae65383be1
7 изменённых файлов: 83 добавлений и 2 удалений

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

@ -38,6 +38,7 @@
package org.mozilla.gecko;
import java.lang.CharSequence;
import java.util.ArrayList;
import android.os.Build;
@ -131,8 +132,12 @@ public class GeckoPreferences
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefName = preference.getKey();
setPreference(prefName, newValue);
if (preference instanceof ListPreference)
((ListPreference)preference).setSummary((String)newValue);
if (preference instanceof ListPreference) {
// We need to find the entry for the new value
int newIndex = ((ListPreference)preference).findIndexOfValue((String) newValue);
CharSequence newEntry = ((ListPreference)preference).getEntries()[newIndex];
((ListPreference)preference).setSummary(newEntry);
}
if (preference instanceof LinkPreference)
finish();
return true;
@ -177,6 +182,9 @@ public class GeckoPreferences
GeckoAppShell.getMainHandler().post(new Runnable() {
public void run() {
((ListPreference)pref).setValue(value);
// Set the summary string to the current entry
CharSequence selectedEntry = ((ListPreference)pref).getEntry();
((ListPreference)pref).setSummary(selectedEntry);
}
});
}

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

@ -206,6 +206,7 @@ RES_LAYOUT_V11 = \
RES_VALUES = \
res/values/defaults.xml \
res/values/arrays.xml \
res/values/colors.xml \
res/values/styles.xml \
res/values/themes.xml \
@ -453,6 +454,7 @@ $(RES_VALUES): \
$(srcdir)/resources/values/colors.xml \
$(srcdir)/resources/values/styles.xml \
$(srcdir)/resources/values/themes.xml \
$(srcdir)/resources/values/arrays.xml \
$(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/res/values/defaults.xml
$(NSINSTALL) -D res/values
$(NSINSTALL) $^ res/values

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

@ -62,6 +62,10 @@
<!ENTITY pref_clear_history_confirm "Browsing history will be deleted">
<!ENTITY pref_clear_private_data "Clear private data">
<!ENTITY pref_clear_private_data_confirm "Browsing settings, including passwords and cookies, will be deleted">
<!ENTITY pref_enable_flash "Enable Flash">
<!ENTITY pref_enable_flash_yes "Yes">
<!ENTITY pref_enable_flash_tap_to_play "Tap To Play">
<!ENTITY pref_enable_flash_no "No">
<!ENTITY quit "Quit">

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

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="pref_enable_flash_entries">
<item>@string/pref_enable_flash_yes</item>
<item>@string/pref_enable_flash_tap_to_play</item>
<item>@string/pref_enable_flash_no</item>
</string-array>
<string-array name="pref_enable_flash_values">
<item>1</item>
<item>2</item>
<item>0</item>
</string-array>
</resources>

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

@ -19,6 +19,12 @@
android:title="@string/pref_char_encoding"
android:persistent="false" />
<ListPreference android:key="plugin.enable"
android:title="@string/pref_enable_flash"
android:entries="@array/pref_enable_flash_entries"
android:entryValues="@array/pref_enable_flash_values"
android:persistent="false" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_privacy">

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

@ -68,6 +68,10 @@
<string name="pref_clear_history_confirm">&pref_clear_history_confirm;</string>
<string name="pref_clear_private_data">&pref_clear_private_data;</string>
<string name="pref_clear_private_data_confirm">&pref_clear_private_data_confirm;</string>
<string name="pref_enable_flash">&pref_enable_flash;</string>
<string name="pref_enable_flash_yes">&pref_enable_flash_yes;</string>
<string name="pref_enable_flash_tap_to_play">&pref_enable_flash_tap_to_play;</string>
<string name="pref_enable_flash_no">&pref_enable_flash_no;</string>
<string name="reload">&reload;</string>
<string name="forward">&forward;</string>

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

@ -435,6 +435,16 @@ var BrowserApp = {
name: prefName
};
// The plugin pref is actually two separate prefs, so
// we need to handle it differently
if (prefName == "plugin.enable") {
// Use a string type for java's ListPreference
pref.type = "string";
pref.value = PluginHelper.getPluginPreference();
prefs.push(pref);
continue;
}
try {
switch (Services.prefs.getPrefType(prefName)) {
case Ci.nsIPrefBranch.PREF_BOOL:
@ -490,6 +500,13 @@ var BrowserApp = {
setPreferences: function setPreferences(aPref) {
let json = JSON.parse(aPref);
// The plugin pref is actually two separate prefs, so
// we need to handle it differently
if (json.name == "plugin.enable") {
PluginHelper.setPluginPreference(json.value);
return;
}
// when sending to java, we normalized special preferences that use
// integers and strings to represent booleans. here, we convert them back
// to their actual types so we can store them.
@ -2926,6 +2943,32 @@ var PluginHelper = {
}
},
getPluginPreference: function getPluginPreference() {
let pluginDisable = Services.prefs.getBoolPref("plugin.disable");
if (pluginDisable)
return "0";
let clickToPlay = Services.prefs.getBoolPref("plugins.click_to_play");
return clickToPlay ? "2" : "1";
},
setPluginPreference: function setPluginPreference(aValue) {
switch (aValue) {
case "0": // Enable Plugins = No
Services.prefs.setBoolPref("plugin.disable", true);
Services.prefs.clearUserPref("plugins.click_to_play");
break;
case "1": // Enable Plugins = Yes
Services.prefs.clearUserPref("plugin.disable");
Services.prefs.setBoolPref("plugins.click_to_play", false);
break;
case "2": // Enable Plugins = Tap to Play (default)
Services.prefs.clearUserPref("plugin.disable");
Services.prefs.clearUserPref("plugins.click_to_play");
break;
}
},
// Mostly copied from /browser/base/content/browser.js
addPluginClickCallback: function (plugin, callbackName /*callbackArgs...*/) {
// XXX just doing (callback)(arg) was giving a same-origin error. bug?