зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1308153 - part1 : notify tabbrowser when the tab was blocked. r=baku,jaws
We need to notify tabbrowser about media-blocking so that we can show the unblocking tab icon. See bug1308399 for more UX details. MozReview-Commit-ID: E25lEhZLCZk --HG-- extra : rebase_source : dcb6cb520bb0983010dfcc728f7251994a886612
This commit is contained in:
Родитель
3a3ce1cac9
Коммит
b2b31d2a59
|
@ -474,6 +474,22 @@
|
|||
</body>
|
||||
</method>
|
||||
|
||||
<method name="getTabFromAudioEvent">
|
||||
<parameter name="aEvent"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
if (!Services.prefs.getBoolPref("browser.tabs.showAudioPlayingIcon") ||
|
||||
!aEvent.isTrusted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var browser = aEvent.originalTarget;
|
||||
var tab = this.getTabForBrowser(browser);
|
||||
return tab;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="_callProgressListeners">
|
||||
<parameter name="aBrowser"/>
|
||||
<parameter name="aMethod"/>
|
||||
|
@ -5064,14 +5080,10 @@
|
|||
</handler>
|
||||
<handler event="DOMAudioPlaybackStarted">
|
||||
<![CDATA[
|
||||
if (!Services.prefs.getBoolPref("browser.tabs.showAudioPlayingIcon") ||
|
||||
!event.isTrusted)
|
||||
return;
|
||||
|
||||
var browser = event.originalTarget;
|
||||
var tab = this.getTabForBrowser(browser);
|
||||
if (!tab)
|
||||
var tab = getTabFromAudioEvent(event)
|
||||
if (!tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(tab._soundPlayingAttrRemovalTimer);
|
||||
tab._soundPlayingAttrRemovalTimer = 0;
|
||||
|
@ -5092,14 +5104,10 @@
|
|||
</handler>
|
||||
<handler event="DOMAudioPlaybackStopped">
|
||||
<![CDATA[
|
||||
if (!Services.prefs.getBoolPref("browser.tabs.showAudioPlayingIcon") ||
|
||||
!event.isTrusted)
|
||||
return;
|
||||
|
||||
var browser = event.originalTarget;
|
||||
var tab = this.getTabForBrowser(browser);
|
||||
if (!tab)
|
||||
var tab = getTabFromAudioEvent(event)
|
||||
if (!tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tab.hasAttribute("soundplaying")) {
|
||||
let removalDelay = Services.prefs.getIntPref("browser.tabs.delayHidingAudioPlayingIconMS");
|
||||
|
@ -5116,6 +5124,26 @@
|
|||
}
|
||||
]]>
|
||||
</handler>
|
||||
<handler event="DOMAudioPlaybackBlockStarted">
|
||||
<![CDATA[
|
||||
var tab = getTabFromAudioEvent(event)
|
||||
if (!tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO : implement media-blocking icon in next patch.
|
||||
]]>
|
||||
</handler>
|
||||
<handler event="DOMAudioPlaybackBlockStopped">
|
||||
<![CDATA[
|
||||
var tab = getTabFromAudioEvent(event)
|
||||
if (!tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO : implement media-blocking icon in next patch.
|
||||
]]>
|
||||
</handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
|
|
|
@ -1251,6 +1251,7 @@ AudioChannelService::AudioChannelWindow::AppendAgent(AudioChannelAgent* aAgent,
|
|||
} else if (IsEnableAudioCompetingForAllAgents() && !aAudible) {
|
||||
NotifyAudioCompetingChanged(aAgent, true);
|
||||
}
|
||||
MaybeNotifyMediaBlocked(aAgent);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1399,3 +1400,30 @@ AudioChannelService::AudioChannelWindow::NotifyChannelActive(uint64_t aWindowID,
|
|||
DebugOnly<nsresult> rv = NS_DispatchToCurrentThread(runnable);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToCurrentThread failed");
|
||||
}
|
||||
|
||||
void
|
||||
AudioChannelService::AudioChannelWindow::MaybeNotifyMediaBlocked(AudioChannelAgent* aAgent)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = aAgent->Window();
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(window->IsOuterWindow());
|
||||
if (window->GetMediaSuspend() != nsISuspendedTypes::SUSPENDED_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
NS_DispatchToCurrentThread(NS_NewRunnableFunction([window] () -> void {
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
services::GetObserverService();
|
||||
if (NS_WARN_IF(!observerService)) {
|
||||
return;
|
||||
}
|
||||
|
||||
observerService->NotifyObservers(ToSupports(window),
|
||||
"audio-playback",
|
||||
u"block");
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -298,6 +298,7 @@ private:
|
|||
|
||||
void NotifyChannelActive(uint64_t aWindowID, AudioChannel aChannel,
|
||||
bool aActive);
|
||||
void MaybeNotifyMediaBlocked(AudioChannelAgent* aAgent);
|
||||
|
||||
void RequestAudioFocus(AudioChannelAgent* aAgent);
|
||||
void NotifyAudioCompetingChanged(AudioChannelAgent* aAgent, bool aActive);
|
||||
|
|
|
@ -1013,7 +1013,11 @@ var AudioPlaybackListener = {
|
|||
if (topic === "audio-playback") {
|
||||
if (subject && subject.top == global.content) {
|
||||
let name = "AudioPlayback:";
|
||||
name += (data === "active") ? "Start" : "Stop";
|
||||
if (data === "block") {
|
||||
name += "Block";
|
||||
} else {
|
||||
name += (data === "active") ? "Start" : "Stop";
|
||||
}
|
||||
sendAsyncMessage(name);
|
||||
}
|
||||
} else if (topic == "AudioFocusChanged" || topic == "MediaControl") {
|
||||
|
|
|
@ -690,6 +690,12 @@
|
|||
let event = document.createEvent("Events");
|
||||
event.initEvent("DOMAudioPlaybackStarted", true, false);
|
||||
this.dispatchEvent(event);
|
||||
if (this._audioBlocked) {
|
||||
this._audioBlocked = false;
|
||||
event = document.createEvent("Events");
|
||||
event.initEvent("DOMAudioPlaybackBlockStopped", true, false);
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -704,11 +710,28 @@
|
|||
</body>
|
||||
</method>
|
||||
|
||||
<method name="audioPlaybackBlocked">
|
||||
<body>
|
||||
<![CDATA[
|
||||
this._audioBlocked = true;
|
||||
let event = document.createEvent("Events");
|
||||
event.initEvent("DOMAudioPlaybackBlockStarted", true, false);
|
||||
this.dispatchEvent(event);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<field name="_audioMuted">false</field>
|
||||
<property name="audioMuted"
|
||||
onget="return this._audioMuted;"
|
||||
readonly="true"/>
|
||||
|
||||
|
||||
<field name="_audioBlocked">false</field>
|
||||
<property name="audioBlocked"
|
||||
onget="return this._audioBlocked;"
|
||||
readonly="true"/>
|
||||
|
||||
<method name="mute">
|
||||
<body>
|
||||
<![CDATA[
|
||||
|
@ -758,6 +781,7 @@
|
|||
<method name="blockMedia">
|
||||
<body>
|
||||
<![CDATA[
|
||||
this._audioBlocked = true;
|
||||
this.messageManager.sendAsyncMessage("AudioPlayback",
|
||||
{type: "blockInactivePageMedia"});
|
||||
]]>
|
||||
|
@ -767,8 +791,12 @@
|
|||
<method name="resumeMedia">
|
||||
<body>
|
||||
<![CDATA[
|
||||
this._audioBlocked = false;
|
||||
this.messageManager.sendAsyncMessage("AudioPlayback",
|
||||
{type: "resumeMedia"});
|
||||
let event = document.createEvent("Events");
|
||||
event.initEvent("DOMAudioPlaybackBlockStopped", true, false);
|
||||
this.dispatchEvent(event);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -922,6 +950,7 @@
|
|||
this.messageManager.addMessageListener("Autoscroll:Cancel", this);
|
||||
this.messageManager.addMessageListener("AudioPlayback:Start", this);
|
||||
this.messageManager.addMessageListener("AudioPlayback:Stop", this);
|
||||
this.messageManager.addMessageListener("AudioPlayback:Block", this);
|
||||
}
|
||||
]]>
|
||||
</constructor>
|
||||
|
@ -1008,6 +1037,9 @@
|
|||
case "AudioPlayback:Stop":
|
||||
this.audioPlaybackStopped();
|
||||
break;
|
||||
case "AudioPlayback:Block":
|
||||
this.audioPlaybackBlocked();
|
||||
break;
|
||||
}
|
||||
return undefined;
|
||||
]]></body>
|
||||
|
|
Загрузка…
Ссылка в новой задаче