Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
Bug 1472491: Part 5n - Add AudioPlaybackChild actor. r=felipe
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: DtGNW4riHQX
  • Loading branch information
kmaglione committed Jul 30, 2018
1 parent 41277b3 commit fc1343c
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 82 deletions.
1 change: 1 addition & 0 deletions browser/installer/package-manifest.in
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
@RESPATH@/browser/modules/*
@RESPATH@/modules/*
@RESPATH@/browser/actors/*
@RESPATH@/actors/*

; Safe Browsing
@RESPATH@/components/nsURLClassifier.manifest
Expand Down
1 change: 1 addition & 0 deletions mobile/android/installer/package-manifest.in
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@

; Modules
@BINPATH@/modules/*
@BINPATH@/actors/*

; Safe Browsing
@BINPATH@/components/nsURLClassifier.manifest
Expand Down
72 changes: 72 additions & 0 deletions toolkit/actors/AudioPlaybackChild.jsm
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

var EXPORTED_SYMBOLS = ["AudioPlaybackChild"];

ChromeUtils.import("resource://gre/modules/ActorChild.jsm");

class AudioPlaybackChild extends ActorChild {
handleMediaControlMessage(msg) {
let utils = this.content.windowUtils;
let suspendTypes = Ci.nsISuspendedTypes;
switch (msg) {
case "mute":
utils.audioMuted = true;
break;
case "unmute":
utils.audioMuted = false;
break;
case "lostAudioFocus":
utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE_DISPOSABLE;
break;
case "lostAudioFocusTransiently":
utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE;
break;
case "gainAudioFocus":
utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
break;
case "mediaControlPaused":
utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE_DISPOSABLE;
break;
case "mediaControlStopped":
utils.mediaSuspend = suspendTypes.SUSPENDED_STOP_DISPOSABLE;
break;
case "resumeMedia":
// User has clicked the tab audio indicator to play a delayed
// media. That's clear user intent to play, so gesture activate
// the content document tree so that the block-autoplay logic
// allows the media to autoplay.
this.content.document.notifyUserGestureActivation();
utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
break;
default:
dump("Error : wrong media control msg!\n");
break;
}
}

observe(subject, topic, data) {
if (topic === "audio-playback") {
if (subject && subject.top == this.content) {
let name = "AudioPlayback:";
if (data === "activeMediaBlockStart") {
name += "ActiveMediaBlockStart";
} else if (data === "activeMediaBlockStop") {
name += "ActiveMediaBlockStop";
} else {
name += (data === "active") ? "Start" : "Stop";
}
this.mm.sendAsyncMessage(name);
}
}
}

receiveMessage(msg) {
if (msg.name == "AudioPlayback") {
this.handleMediaControlMessage(msg.data.type);
}
}
}
9 changes: 9 additions & 0 deletions toolkit/actors/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

FINAL_TARGET_FILES.actors += [
'AudioPlaybackChild.jsm',
]
82 changes: 0 additions & 82 deletions toolkit/content/browser-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,88 +190,6 @@ addEventListener("WebChannelMessageToChrome", WebChannelContent,
true, true);
addMessageListener("WebChannelMessageToContent", WebChannelContent);

var AudioPlaybackListener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver]),

init() {
Services.obs.addObserver(this, "audio-playback");

addMessageListener("AudioPlayback", this);
addEventListener("unload", () => {
AudioPlaybackListener.uninit();
});
this.init = null;
},

uninit() {
Services.obs.removeObserver(this, "audio-playback");

removeMessageListener("AudioPlayback", this);
},

handleMediaControlMessage(msg) {
let utils = global.content.windowUtils;
let suspendTypes = Ci.nsISuspendedTypes;
switch (msg) {
case "mute":
utils.audioMuted = true;
break;
case "unmute":
utils.audioMuted = false;
break;
case "lostAudioFocus":
utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE_DISPOSABLE;
break;
case "lostAudioFocusTransiently":
utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE;
break;
case "gainAudioFocus":
utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
break;
case "mediaControlPaused":
utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE_DISPOSABLE;
break;
case "mediaControlStopped":
utils.mediaSuspend = suspendTypes.SUSPENDED_STOP_DISPOSABLE;
break;
case "resumeMedia":
// User has clicked the tab audio indicator to play a delayed
// media. That's clear user intent to play, so gesture activate
// the content document tree so that the block-autoplay logic
// allows the media to autoplay.
content.document.notifyUserGestureActivation();
utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
break;
default:
dump("Error : wrong media control msg!\n");
break;
}
},

observe(subject, topic, data) {
if (topic === "audio-playback") {
if (subject && subject.top == global.content) {
let name = "AudioPlayback:";
if (data === "activeMediaBlockStart") {
name += "ActiveMediaBlockStart";
} else if (data === "activeMediaBlockStop") {
name += "ActiveMediaBlockStop";
} else {
name += (data === "active") ? "Start" : "Stop";
}
sendAsyncMessage(name);
}
}
},

receiveMessage(msg) {
if (msg.name == "AudioPlayback") {
this.handleMediaControlMessage(msg.data.type);
}
},
};
AudioPlaybackListener.init();

var UnselectedTabHoverObserver = {
init() {
addMessageListener("Browser:UnselectedTabHover", this);
Expand Down
11 changes: 11 additions & 0 deletions toolkit/modules/ActorManagerParent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
const {DefaultMap} = ExtensionUtils;

let ACTORS = {
AudioPlayback: {
child: {
module: "resource://gre/actors/AudioPlaybackChild.jsm",
messages: [
"AudioPlayback",
],
observers: [
"audio-playback",
],
},
},
};

class ActorSet {
Expand Down
1 change: 1 addition & 0 deletions toolkit/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

DIRS += [
'actors',
'components',
'content',
'crashreporter',
Expand Down

0 comments on commit fc1343c

Please sign in to comment.