Bug 1262053 - part1 : unblock window's media when the page was first visited. r=baku

MozReview-Commit-ID: 5g5cYdgC8sg

--HG--
extra : rebase_source : 5af18ff846f464b1d3d195d7dc2634e03601cfcc
This commit is contained in:
Dan Glastonbury 2016-08-29 10:41:02 +08:00
Родитель 4460ee8698
Коммит b194d26e61
5 изменённых файлов: 33 добавлений и 1 удалений

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

@ -1498,6 +1498,8 @@ nsDocument::nsDocument(const char* aContentType)
// Add the base queue sentinel to the processing stack.
sProcessingStack->AppendElement((CustomElementData*) nullptr);
}
mEverInForeground = false;
}
void
@ -12603,6 +12605,10 @@ nsDocument::UpdateVisibilityState()
EnumerateActivityObservers(NotifyActivityChanged, nullptr);
}
if (mVisibilityState == dom::VisibilityState::Visible) {
MaybeActiveMediaComponents();
}
}
VisibilityState
@ -12638,6 +12644,23 @@ nsDocument::PostVisibilityUpdateEvent()
NS_DispatchToMainThread(event);
}
void
nsDocument::MaybeActiveMediaComponents()
{
if (mEverInForeground) {
return;
}
if (!mWindow) {
return;
}
mEverInForeground = true;
if (GetWindow()->GetMediaSuspend() == nsISuspendedTypes::SUSPENDED_BLOCK) {
GetWindow()->SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
}
}
NS_IMETHODIMP
nsDocument::GetMozHidden(bool* aHidden)
{

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

@ -1209,6 +1209,10 @@ public:
// Posts an event to call UpdateVisibilityState
virtual void PostVisibilityUpdateEvent() override;
// Since we wouldn't automatically play media from non-visited page, we need
// to notify window when the page was first visited.
void MaybeActiveMediaComponents();
virtual void DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const override;
// DocAddSizeOfIncludingThis is inherited from nsIDocument.

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

@ -618,7 +618,8 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow)
mInnerObjectsFreed(false),
mIsModalContentWindow(false),
mIsActive(false), mIsBackground(false),
mMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED),
mMediaSuspend(Preferences::GetBool("media.block-autoplay-until-in-foreground", true) ?
nsISuspendedTypes::SUSPENDED_BLOCK : nsISuspendedTypes::NONE_SUSPENDED),
mAudioMuted(false), mAudioVolume(1.0), mAudioCaptured(false),
mDesktopModeViewport(false), mInnerWindow(nullptr),
mOuterWindow(aOuterWindow),

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

@ -3069,6 +3069,9 @@ protected:
// Do we currently have an event posted to call FlushUserFontSet?
bool mPostedFlushUserFontSet : 1;
// True is document has ever been in a foreground window.
bool mEverInForeground : 1;
enum Type {
eUnknown, // should never be used
eHTML,

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

@ -5532,6 +5532,7 @@ pref("dom.webkitBlink.dirPicker.enabled", true);
pref("dom.webkitBlink.filesystem.enabled", true);
#endif
pref("media.block-autoplay-until-in-foreground", true);
#ifdef MOZ_STYLO
// Is the Servo-backed style system enabled?
pref("layout.css.servo.enabled", true);