b=478982 Gecko users may need to prevent autoplay for video/audio content in messages r=roc,dolske sr=roc

This commit is contained in:
Nochum Sossonko 2009-02-20 17:05:07 +13:00
Родитель 71db1509d5
Коммит 3adf87ea38
5 изменённых файлов: 29 добавлений и 4 удалений

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

@ -337,6 +337,10 @@ protected:
// is a result of the autoplay attribute.
PRPackedBool mAutoplaying;
// Indicates whether |autoplay| will actually autoplay based on the pref
// media.autoplay.enabled
PRPackedBool mAutoplayEnabled;
// Playback of the video is paused either due to calling the
// 'Pause' method, or playback not yet having started.
PRPackedBool mPaused;

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

@ -252,6 +252,14 @@ NS_IMPL_URI_ATTR(nsHTMLMediaElement, Src, src)
NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, Controls, controls)
NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, Autoplay, autoplay)
/* readonly attribute nsIDOMHTMLMediaElement mozAutoplayEnabled; */
NS_IMETHODIMP nsHTMLMediaElement::GetMozAutoplayEnabled(PRBool *aAutoplayEnabled)
{
*aAutoplayEnabled = mAutoplayEnabled;
return NS_OK;
}
/* readonly attribute nsIDOMHTMLMediaError error; */
NS_IMETHODIMP nsHTMLMediaElement::GetError(nsIDOMHTMLMediaError * *aError)
{
@ -619,6 +627,7 @@ nsHTMLMediaElement::nsHTMLMediaElement(nsINodeInfo *aNodeInfo, PRBool aFromParse
mBegun(PR_FALSE),
mLoadedFirstFrame(PR_FALSE),
mAutoplaying(PR_TRUE),
mAutoplayEnabled(PR_TRUE),
mPaused(PR_TRUE),
mMuted(PR_FALSE),
mIsDoneAddingChildren(!aFromParser),
@ -720,11 +729,17 @@ nsresult nsHTMLMediaElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
return rv;
}
static PRBool IsAutoplayEnabled()
{
return nsContentUtils::GetBoolPref("media.autoplay.enabled");
}
nsresult nsHTMLMediaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
PRBool aCompileEventHandlers)
{
mIsBindingToTree = PR_TRUE;
mAutoplayEnabled = IsAutoplayEnabled();
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument,
aParent,
aBindingParent,
@ -1291,7 +1306,8 @@ void nsHTMLMediaElement::ChangeReadyState(nsMediaReadyState aState)
}
if (mAutoplaying &&
mPaused &&
HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) {
HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay) &&
mAutoplayEnabled) {
mPaused = PR_FALSE;
if (mDecoder) {
mDecoder->Play();

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

@ -56,7 +56,7 @@
#endif
%}
[scriptable, uuid(c19f04dc-f09a-4b1f-b354-af65a12aa8bc)]
[scriptable, uuid(debed306-1a49-4af8-b10a-8452978a2db1)]
interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement
{
// error state
@ -87,6 +87,7 @@ interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement
readonly attribute float duration;
readonly attribute boolean paused;
readonly attribute boolean ended;
readonly attribute boolean mozAutoplayEnabled;
attribute boolean autoplay;
void play();
void pause();

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

@ -143,6 +143,9 @@ pref("media.ogg.enabled", true);
pref("media.wave.enabled", true);
#endif
// Whether to autostart a media element with an |autoplay| attribute
pref("media.autoplay.enabled", true);
// 0 = Off, 1 = Full, 2 = Tagged Images Only.
// See eCMSMode in gfx/thebes/public/gfxPlatform.h
pref("gfx.color_management.mode", 2);

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

@ -272,7 +272,8 @@
// Suppress fading out the controls until the video has rendered
// its first frame. But since autoplay videos start off with no
// controls, let them fade-out so the controls don't get stuck on.
if (!this.firstFrameShown && !isMouseOver && !this.video.autoplay)
if (!this.firstFrameShown && !isMouseOver &&
!(this.video.autoplay && this.video.mozAutoplayEnabled))
return;
// If we're already fading towards the desired state (or are
@ -403,7 +404,7 @@
// go ahead and reveal the controls now, so they're an obvious user cue.
//
// (Note: the |controls| attribute is already handled via layout/style/html.css)
if (!video.autoplay || !this.Utils.dynamicControls) {
if (!(video.autoplay && video.mozAutoplayEnabled) || !this.Utils.dynamicControls) {
this.Utils.controlBar.style.visibility = "visible";
this.Utils.controlBar.style.opacity = 1.0;
this.Utils.controlsVisible = true;