summaryrefslogtreecommitdiff
path: root/chromium/content/public/browser/media_session.h
blob: 8a0fe0aceabe01294bf51f00e41ec46b29807e79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_H_
#define CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_H_

#include "base/macros.h"
#include "content/common/content_export.h"

namespace blink {
namespace mojom {
enum class MediaSessionAction;
}  // namespace mojom
}  // namespace blink

namespace content {

class MediaSessionObserver;
class WebContents;

// MediaSession manages the media session and audio focus for a given
// WebContents. There is only one MediaSession per WebContents.
//
// MediaSession allows clients to observe its changes via MediaSessionObserver,
// and allows clients to resume/suspend/stop the managed players.
class MediaSession {
 public:
  enum class SuspendType {
    // Suspended by the system because a transient sound needs to be played.
    SYSTEM,
    // Suspended by the UI.
    UI,
    // Suspended by the page via script or user interaction.
    CONTENT,
  };

  // Returns the MediaSession associated to this WebContents. Creates one if
  // none is currently available.
  CONTENT_EXPORT static MediaSession* Get(WebContents* contents);

  virtual ~MediaSession() = default;

  // Resume the media session.
  // |type| represents the origin of the request.
  virtual void Resume(SuspendType suspend_type) = 0;

  // Resume the media session.
  // |type| represents the origin of the request.
  virtual void Suspend(SuspendType suspend_type) = 0;

  // Resume the media session.
  // |type| represents the origin of the request.
  virtual void Stop(SuspendType suspend_type) = 0;

  // Tell the media session a user action has performed.
  virtual void DidReceiveAction(blink::mojom::MediaSessionAction action) = 0;

  // Let the media session start ducking such that the volume multiplier is
  // reduced.
  virtual void StartDucking() = 0;

  // Let the media session stop ducking such that the volume multiplier is
  // recovered.
  virtual void StopDucking() = 0;

 protected:
  MediaSession() = default;

 private:
  friend class MediaSessionObserver;

  virtual void AddObserver(MediaSessionObserver* observer) = 0;
  virtual void RemoveObserver(MediaSessionObserver* observer) = 0;
};

}  // namespace content

#endif  // CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_H_