Bug 1041080 - Fix OpenH264Provider path registration, default enabled state and logging r=Unfocused a=kwierso

This commit is contained in:
Georg Fritzsche 2014-07-19 20:01:01 +02:00
parent 8b4da763a2
commit 56d298233e
7 changed files with 98 additions and 13 deletions

View File

@ -1653,4 +1653,4 @@ pref("experiments.manifest.certs.1.issuerName", "CN=Cybertrust Public SureServer
pref("experiments.supported", true);
// Enable the OpenH264 plugin support in the addon manager.
pref("media.gmp-gmpopenh264.providerEnabled", true);
pref("media.gmp-gmpopenh264.provider.enabled", true);

View File

@ -875,10 +875,12 @@ GMPDownloader.prototype = {
// Success, set the prefs
let now = Math.round(Date.now() / 1000);
GMPPrefs.set(GMPPrefs.KEY_ADDON_LAST_UPDATE, now, gmpAddon.id);
GMPPrefs.set(GMPPrefs.KEY_ADDON_PATH,
installToDirPath.path, gmpAddon.id);
// Setting the path pref signals installation completion to consumers,
// so set the version and potential other information they use first.
GMPPrefs.set(GMPPrefs.KEY_ADDON_VERSION, gmpAddon.version,
gmpAddon.id);
GMPPrefs.set(GMPPrefs.KEY_ADDON_PATH,
installToDirPath.path, gmpAddon.id);
this._deferred.resolve(extractedPaths);
}, err => {
this._deferred.reject(err);

View File

@ -15,6 +15,7 @@ Cu.import("resource://gre/modules/AddonManager.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/osfile.jsm");
Cu.import("resource://gre/modules/Log.jsm");
const URI_EXTENSION_STRINGS = "chrome://mozapps/locale/extensions/extensions.properties";
const STRING_TYPE_NAME = "type.%ID%.name";
@ -26,7 +27,10 @@ const OPENH264_PREF_PATH = "path";
const OPENH264_PREF_VERSION = "version";
const OPENH264_PREF_LASTUPDATE = "lastUpdate";
const OPENH264_PREF_AUTOUPDATE = "autoupdate";
const OPENH264_PREF_PROVIDERENABLED = "providerEnabled";
const OPENH264_PREF_PROVIDERENABLED = "provider.enabled";
const OPENH264_PREF_LOGGING = "provider.logging";
const OPENH264_PREF_LOGGING_LEVEL = OPENH264_PREF_LOGGING + ".level"; // media.gmp-gmpopenh264.provider.logging.level
const OPENH264_PREF_LOGGING_DUMP = OPENH264_PREF_LOGGING + ".dump"; // media.gmp-gmpopenh264.provider.logging.dump
const OPENH264_HOMEPAGE_URL = "http://www.openh264.org/";
const OPENH264_OPTIONS_URL = "chrome://mozapps/content/extensions/openH264Prefs.xul";
@ -37,6 +41,30 @@ XPCOMUtils.defineLazyGetter(this, "prefs",
XPCOMUtils.defineLazyGetter(this, "gmpService",
() => Cc["@mozilla.org/gecko-media-plugin-service;1"].getService(Ci.mozIGeckoMediaPluginService));
let gLogger;
let gLogDumping = false;
let gLogAppenderDump = null;
function configureLogging() {
if (!gLogger) {
gLogger = Log.repository.getLogger("Toolkit.OpenH264Provider");
gLogger.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter()));
}
gLogger.level = prefs.get(OPENH264_PREF_LOGGING_LEVEL, Log.Level.Warn);
let logDumping = prefs.get(OPENH264_PREF_LOGGING_DUMP, false);
if (logDumping != gLogDumping) {
if (logDumping) {
gLogAppenderDump = new Log.DumpAppender(new Log.BasicFormatter());
gLogger.addAppender(gLogAppenderDump);
} else {
gLogger.removeAppender(gLogAppenderDump);
gLogAppenderDump = null;
}
gLogDumping = logDumping;
}
}
/**
* The OpenH264Wrapper provides the info for the OpenH264 GMP plugin to public callers through the API.
*/
@ -63,7 +91,7 @@ let OpenH264Wrapper = Object.freeze({
get isActive() { return !this.userDisabled; },
get appDisabled() { return false; },
get userDisabled() { return !prefs.get(OPENH264_PREF_ENABLED, false); },
get userDisabled() { return !prefs.get(OPENH264_PREF_ENABLED, true); },
set userDisabled(aVal) { prefs.set(OPENH264_PREF_ENABLED, aVal === false); },
get blocklistState() { return Ci.nsIBlocklistService.STATE_NOT_BLOCKED; },
@ -85,7 +113,7 @@ let OpenH264Wrapper = Object.freeze({
get updateDate() {
let time = Number(prefs.get(OPENH264_PREF_LASTUPDATE, null));
if (time !== NaN && this.isInstalled) {
return new Date(time)
return new Date(time * 1000)
}
return null;
},
@ -158,20 +186,30 @@ let OpenH264Wrapper = Object.freeze({
let OpenH264Provider = {
startup: function() {
configureLogging();
this._log = Log.repository.getLogger("Toolkit.OpenH264Provider");
this.gmpPath = prefs.get(OPENH264_PREF_PATH, null);
let enabled = prefs.get(OPENH264_PREF_ENABLED, true);
this._log.trace("startup() - enabled=" + enabled + ", gmpPath="+this.gmpPath);
Services.obs.addObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, false);
prefs.observe(OPENH264_PREF_ENABLED, this.onPrefEnabledChanged, this);
prefs.observe(OPENH264_PREF_PATH, this.onPrefPathChanged, this);
prefs.observe(OPENH264_PREF_LOGGING, configureLogging);
this.gmpPath = prefs.get(OPENH264_PREF_PATH, null);
if (this.gmpPath) {
if (this.gmpPath && enabled) {
this._log.info("startup() - adding gmp directory " + this.gmpPath);
gmpService.addPluginDirectory(this.gmpPath);
}
},
shutdown: function() {
this._log.trace("shutdown()");
Services.obs.removeObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED);
prefs.ignore(OPENH264_PREF_ENABLED, this.onPrefEnabledChanged, this);
prefs.ignore(OPENH264_PREF_PATH, this.onPrefPathChanged, this);
prefs.ignore(OPENH264_PREF_LOGGING, configureLogging);
},
onPrefEnabledChanged: function() {
@ -180,6 +218,15 @@ let OpenH264Provider = {
AddonManagerPrivate.callAddonListeners(wrapper.isActive ?
"onEnabling" : "onDisabling",
wrapper, false);
if (this.gmpPath) {
if (wrapper.isActive) {
this._log.info("onPrefEnabledChanged() - adding gmp directory " + this.gmpPath);
gmpService.addPluginDirectory(this.gmpPath);
} else {
this._log.info("onPrefEnabledChanged() - removing gmp directory " + this.gmpPath);
gmpService.removePluginDirectory(this.gmpPath);
}
}
AddonManagerPrivate.callAddonListeners(wrapper.isActive ?
"onEnabled" : "onDisabled",
wrapper);
@ -190,13 +237,15 @@ let OpenH264Provider = {
AddonManagerPrivate.callAddonListeners("onUninstalling", wrapper, false);
if (this.gmpPath) {
this._log.info("onPrefPathChanged() - removing gmp directory " + this.gmpPath);
gmpService.removePluginDirectory(this.gmpPath);
}
AddonManagerPrivate.callAddonListeners("onUninstalled", wrapper);
AddonManagerPrivate.callInstallListeners("onExternalInstall", null, wrapper, null, false);
this.gmpPath = prefs.get(OPENH264_PREF_PATH, null);
if (this.gmpPath) {
if (this.gmpPath && wrapper.isActive) {
this._log.info("onPrefPathChanged() - adding gmp directory " + this.gmpPath);
gmpService.addPluginDirectory(this.gmpPath);
}
AddonManagerPrivate.callAddonListeners("onInstalled", wrapper);

View File

@ -11,6 +11,9 @@ const OPENH264_PREF_PATH = OPENH264_PREF_BRANCH + "path";
const OPENH264_PREF_VERSION = OPENH264_PREF_BRANCH + "version";
const OPENH264_PREF_LASTUPDATE = OPENH264_PREF_BRANCH + "lastUpdate";
const OPENH264_PREF_AUTOUPDATE = OPENH264_PREF_BRANCH + "autoupdate";
const PREF_LOGGING = OPENH264_PREF_BRANCH + "provider.logging";
const PREF_LOGGING_LEVEL = PREF_LOGGING + ".level";
const PREF_LOGGING_DUMP = PREF_LOGGING + ".dump";
const TEST_DATE = new Date(2013, 0, 1, 12);
@ -56,6 +59,9 @@ function openDetailsView(aId) {
}
add_task(function* initializeState() {
Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true);
Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0);
gManagerWindow = yield open_manager();
gCategoryUtilities = new CategoryUtilities(gManagerWindow);
@ -67,6 +73,8 @@ add_task(function* initializeState() {
Services.prefs.clearUserPref(OPENH264_PREF_VERSION);
Services.prefs.clearUserPref(OPENH264_PREF_LASTUPDATE);
Services.prefs.clearUserPref(OPENH264_PREF_AUTOUPDATE);
Services.prefs.clearUserPref(PREF_LOGGING_DUMP);
Services.prefs.clearUserPref(PREF_LOGGING_LEVEL);
});
let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);

View File

@ -102,7 +102,7 @@ var gPluginIDs = [null, null, null, null, null];
function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
Services.prefs.setBoolPref("media.gmp-gmpopenh264.providerEnabled", false);
Services.prefs.setBoolPref("media.gmp-gmpopenh264.provider.enabled", false);
startupManager();

View File

@ -12,6 +12,9 @@ const OPENH264_PREF_PATH = OPENH264_PREF_BRANCH + "path";
const OPENH264_PREF_VERSION = OPENH264_PREF_BRANCH + "version";
const OPENH264_PREF_LASTUPDATE = OPENH264_PREF_BRANCH + "lastUpdate";
const OPENH264_PREF_AUTOUPDATE = OPENH264_PREF_BRANCH + "autoupdate";
const PREF_LOGGING = OPENH264_PREF_BRANCH + "provider.logging";
const PREF_LOGGING_LEVEL = PREF_LOGGING + ".level";
const PREF_LOGGING_DUMP = PREF_LOGGING + ".dump";
XPCOMUtils.defineLazyGetter(this, "pluginsBundle",
() => Services.strings.createBundle("chrome://global/locale/plugins.properties"));
@ -27,6 +30,8 @@ function run_test() {
add_task(function* test_notInstalled() {
Services.prefs.setCharPref(OPENH264_PREF_PATH, "");
Services.prefs.setBoolPref(OPENH264_PREF_ENABLED, false);
Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true);
Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0);
let addons = yield promiseAddonsByIDs([OPENH264_PLUGIN_ID]);
Assert.equal(addons.length, 1);
@ -73,13 +78,14 @@ add_task(function* test_notInstalled() {
add_task(function* test_installed() {
const TEST_DATE = new Date(2013, 0, 1, 12);
const TEST_VERSION = "1.2.3.4";
const TEST_TIME_SEC = Math.round(TEST_DATE.getTime() / 1000);
let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
file.append("openh264");
file.append("testDir");
Services.prefs.setBoolPref(OPENH264_PREF_ENABLED, false);
Services.prefs.setCharPref(OPENH264_PREF_LASTUPDATE, "" + TEST_DATE.getTime());
Services.prefs.setCharPref(OPENH264_PREF_LASTUPDATE, "" + TEST_TIME_SEC);
Services.prefs.setCharPref(OPENH264_PREF_VERSION, TEST_VERSION);
Services.prefs.setCharPref(OPENH264_PREF_PATH, file.path);
@ -100,7 +106,7 @@ add_task(function* test_installed() {
Assert.equal(addon.permissions, AddonManager.PERM_CAN_UPGRADE |
AddonManager.PERM_CAN_ENABLE);
Assert.equal(addon.updateDate.getTime(), TEST_DATE.getTime());
Assert.equal(addon.updateDate.getTime(), TEST_TIME_SEC * 1000);
let mimetypes = addon.pluginMimeTypes;
Assert.ok(mimetypes);
@ -163,6 +169,7 @@ add_task(function* test_pluginRegistration() {
let OpenH264Scope = Cu.import("resource://gre/modules/addons/OpenH264Provider.jsm");
OpenH264Scope.gmpService = MockGMPService;
Services.prefs.setBoolPref(OPENH264_PREF_ENABLED, true);
// Check that the OpenH264 plugin gets registered after startup.
Services.prefs.setCharPref(OPENH264_PREF_PATH, file.path);
@ -191,4 +198,23 @@ add_task(function* test_pluginRegistration() {
Services.prefs.setCharPref(OPENH264_PREF_PATH, file2.path);
Assert.equal(addedPath, file2.path);
Assert.equal(removedPath, file.path);
// Disabling OpenH264 should cause unregistration.
Services.prefs.setCharPref(OPENH264_PREF_PATH, file.path);
clearPaths();
Services.prefs.setBoolPref(OPENH264_PREF_ENABLED, false);
Assert.equal(addedPath, null);
Assert.equal(removedPath, file.path);
// Restarting with OpenH264 disabled should not cause registration.
clearPaths();
yield promiseRestartManager();
Assert.equal(addedPath, null);
Assert.equal(removedPath, null);
// Re-enabling OpenH264 should cause registration.
clearPaths();
Services.prefs.setBoolPref(OPENH264_PREF_ENABLED, true);
Assert.equal(addedPath, file.path);
Assert.equal(removedPath, null);
});

View File

@ -67,7 +67,7 @@ function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
Services.prefs.setBoolPref("media.gmp-gmpopenh264.providerEnabled", false);
Services.prefs.setBoolPref("media.gmp-gmpopenh264.provider.enabled", false);
startupManager();
AddonManager.addAddonListener(AddonListener);