bug 866390 - add plugin.default.state pref r=bsmedberg

This commit is contained in:
David Keeler 2013-05-15 13:30:40 -07:00
Родитель 5e3f06d12c
Коммит 1737cd8ab9
6 изменённых файлов: 57 добавлений и 5 удалений

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

@ -377,9 +377,25 @@ nsPluginTag::GetClicktoplay(bool *aClicktoplay)
NS_IMETHODIMP
nsPluginTag::GetEnabledState(uint32_t *aEnabledState) {
*aEnabledState = Preferences::GetInt(GetStatePrefNameForPlugin(this).get(),
ePluginState_Enabled);
return NS_OK;
int32_t enabledState;
nsresult rv = Preferences::GetInt(GetStatePrefNameForPlugin(this).get(),
&enabledState);
if (NS_SUCCEEDED(rv) &&
enabledState >= nsIPluginTag::STATE_DISABLED &&
enabledState <= nsIPluginTag::STATE_ENABLED) {
*aEnabledState = (uint32_t)enabledState;
return rv;
}
enabledState = Preferences::GetInt("plugin.default.state",
nsIPluginTag::STATE_ENABLED);
if (enabledState >= nsIPluginTag::STATE_DISABLED &&
enabledState <= nsIPluginTag::STATE_ENABLED) {
*aEnabledState = (uint32_t)enabledState;
return NS_OK;
}
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP

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

@ -42,16 +42,17 @@ function get_test_plugin() {
}
// Finds the test nsIPluginTag
function get_test_plugintag() {
function get_test_plugintag(aName) {
const Cc = Components.classes;
const Ci = Components.interfaces;
var name = aName || "Test Plug-in";
var host = Cc["@mozilla.org/plugin/host;1"].
getService(Ci.nsIPluginHost);
var tags = host.getPluginTags();
for (var i = 0; i < tags.length; i++) {
if (tags[i].name == "Test Plug-in")
if (tags[i].name == name)
return tags[i];
}
return null;

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

@ -0,0 +1,30 @@
Components.utils.import("resource://gre/modules/Services.jsm");
function run_test() {
let pluginDefaultState = Services.prefs.getIntPref("plugin.default.state");
// if this fails, we just have to switch around the values we're testing
do_check_neq(pluginDefaultState, Ci.nsIPluginTag.STATE_DISABLED);
let nonDefaultState = (pluginDefaultState != Ci.nsIPluginTag.STATE_ENABLED ?
Ci.nsIPluginTag.STATE_ENABLED :
Ci.nsIPluginTag.STATE_CLICKTOPLAY);
let ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
let testPlugin = get_test_plugintag();
// the test plugin should have the default enabledState
do_check_eq(testPlugin.enabledState, pluginDefaultState);
let secondTestPlugin = get_test_plugintag("Second Test Plug-in");
// set an enabledState for the second test plugin
secondTestPlugin.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
// change what the default enabledState is
Services.prefs.setIntPref("plugin.default.state", nonDefaultState);
// the test plugin should follow the default (it has no individual pref yet)
do_check_eq(testPlugin.enabledState, nonDefaultState);
// the second test plugin should retain its preferred state
do_check_eq(secondTestPlugin.enabledState, Ci.nsIPluginTag.STATE_DISABLED);
// clean up
testPlugin.enabledState = pluginDefaultState;
secondTestPlugin.enabledState = pluginDefaultState;
Services.prefs.clearUserPref("plugin.default.state");
Services.prefs.clearUserPref("plugin.importedState");
}

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

@ -16,3 +16,4 @@ fail-if = os == "android"
fail-if = os == "android"
[test_persist_in_prefs.js]
[test_bug854467.js]
[test_plugin_default_state.js]

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

@ -442,6 +442,8 @@ pref("plugin.disable", false);
pref("dom.ipc.plugins.enabled", false);
pref("plugins.click_to_play", true);
// The default value for nsIPluginTag.enabledState (STATE_CLICKTOPLAY = 1)
pref("plugin.default.state", 1);
// product URLs
// The breakpad report server to link to in about:crashes

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

@ -1825,6 +1825,8 @@ pref("hangmonitor.timeout", 0);
pref("plugins.load_appdir_plugins", false);
// If true, plugins will be click to play
pref("plugins.click_to_play", false);
// The default value for nsIPluginTag.enabledState (STATE_ENABLED = 2)
pref("plugin.default.state", 2);
#ifndef DEBUG
// How long a plugin is allowed to process a synchronous IPC message