Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_audio_channel_agent_h__
8
#define mozilla_dom_audio_channel_agent_h__
9
10
#include "nsIAudioChannelAgent.h"
11
#include "nsCycleCollectionParticipant.h"
12
#include "nsCOMPtr.h"
13
#include "nsIWeakReferenceUtils.h"
14
15
class nsPIDOMWindowInner;
16
class nsPIDOMWindowOuter;
17
18
namespace mozilla {
19
namespace dom {
20
21
class AudioPlaybackConfig;
22
23
/* Header file */
24
class AudioChannelAgent : public nsIAudioChannelAgent {
25
public:
26
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27
NS_DECL_NSIAUDIOCHANNELAGENT
28
29
NS_DECL_CYCLE_COLLECTION_CLASS(AudioChannelAgent)
30
31
AudioChannelAgent();
32
33
// nsIAudioChannelAgentCallback MUST call this function after calling
34
// NotifyStartedPlaying() to require the initial update for
35
// volume/suspend/audio-capturing which might set before starting the agent.
36
// Ex. starting the agent in a tab which has been muted before, so the agent
37
// should apply mute state to its callback.
38
void PullInitialUpdate();
39
40
uint64_t WindowID() const;
41
42
bool IsWindowAudioCapturingEnabled() const;
43
bool IsPlayingStarted() const;
44
bool ShouldBlockMedia() const;
45
46
private:
47
virtual ~AudioChannelAgent();
48
49
friend class AudioChannelService;
50
void WindowVolumeChanged(float aVolume, bool aMuted);
51
void WindowSuspendChanged(nsSuspendedTypes aSuspend);
52
void WindowAudioCaptureChanged(uint64_t aInnerWindowID, bool aCapture);
53
54
nsPIDOMWindowOuter* Window() const { return mWindow; }
55
uint64_t InnerWindowID() const;
56
AudioPlaybackConfig GetMediaConfig() const;
57
bool IsDisposableSuspend(nsSuspendedTypes aSuspend) const;
58
59
// Returns mCallback if that's non-null, or otherwise tries to get an
60
// nsIAudioChannelAgentCallback out of mWeakCallback.
61
already_AddRefed<nsIAudioChannelAgentCallback> GetCallback();
62
63
nsresult InitInternal(nsPIDOMWindowInner* aWindow,
64
nsIAudioChannelAgentCallback* aCallback,
65
bool aUseWeakRef);
66
67
void Shutdown();
68
69
nsresult FindCorrectWindow(nsPIDOMWindowInner* aWindow);
70
71
nsCOMPtr<nsPIDOMWindowOuter> mWindow;
72
nsCOMPtr<nsIAudioChannelAgentCallback> mCallback;
73
74
nsWeakPtr mWeakCallback;
75
76
uint64_t mInnerWindowID;
77
bool mIsRegToService;
78
};
79
80
} // namespace dom
81
} // namespace mozilla
82
83
#endif