Bug 631058 - Part 1 - Allow specifying default preload behavior through a pref. r=cpearce, a=blocking-fennec

--HG--
extra : rebase_source : bfee19717d59bdeed864e02293c3f5ffd4718724
This commit is contained in:
Wes Johnston 2011-02-14 17:01:04 -08:00
parent ac9940ca51
commit 42e0194fd9
2 changed files with 33 additions and 6 deletions

View File

@ -846,24 +846,29 @@ void nsHTMLMediaElement::UpdatePreloadAction()
// Find the appropriate preload action by looking at the attribute.
const nsAttrValue* val = mAttrsAndChildren.GetAttr(nsGkAtoms::preload,
kNameSpaceID_None);
PRUint32 preloadDefault = nsContentUtils::GetIntPref("media.preload.default",
nsHTMLMediaElement::PRELOAD_ATTR_METADATA);
PRUint32 preloadAuto = nsContentUtils::GetIntPref("media.preload.auto",
nsHTMLMediaElement::PRELOAD_ENOUGH);
if (!val) {
// Attribute is not set. The default is to load metadata.
nextAction = nsHTMLMediaElement::PRELOAD_METADATA;
// Attribute is not set. Use the preload action specified by the
// media.preload.default pref, or just preload metadata if not present.
nextAction = static_cast<PreloadAction>(preloadDefault);
} else if (val->Type() == nsAttrValue::eEnum) {
PreloadAttrValue attr = static_cast<PreloadAttrValue>(val->GetEnumValue());
if (attr == nsHTMLMediaElement::PRELOAD_ATTR_EMPTY ||
attr == nsHTMLMediaElement::PRELOAD_ATTR_AUTO)
{
nextAction = nsHTMLMediaElement::PRELOAD_ENOUGH;
nextAction = static_cast<PreloadAction>(preloadAuto);
} else if (attr == nsHTMLMediaElement::PRELOAD_ATTR_METADATA) {
nextAction = nsHTMLMediaElement::PRELOAD_METADATA;
} else if (attr == nsHTMLMediaElement::PRELOAD_ATTR_NONE) {
nextAction = nsHTMLMediaElement::PRELOAD_NONE;
}
} else {
// There was a value, but it wasn't an enumerated value.
// Use the suggested "missing value default" of "metadata".
nextAction = nsHTMLMediaElement::PRELOAD_METADATA;
// Use the suggested "missing value default" of "metadata", or the value
// specified by the media.preload.default, if present.
nextAction = static_cast<PreloadAction>(preloadDefault);
}
}

View File

@ -394,3 +394,25 @@ function mediaTestCleanup() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
Components.utils.forceGC();
}
(function() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// Ensure that preload preferences are comsistent
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
var branch = prefService.getBranch("media.");
var oldDefault = 2;
var oldAuto = 3;
try {
oldDefault = branch.getIntPref("preload.default");
oldAuto = branch.getIntPref("preload.auto");
} catch(ex) { }
branch.setIntPref("preload.default", 2); // preload_metadata
branch.setIntPref("preload.auto", 3); // preload_enough
window.addEventListener("unload", function() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
branch.setIntPref("preload.default", oldDefault);
branch.setIntPref("preload.auto", oldAuto);
}, false);
})();