DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (c68fe15a81fc)

VCS Links

Line Code
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
/* 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/. */
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DOM_MEDIA_MEDIACONTROL_CONTENTMEDIACONTROLLER_H_
#define DOM_MEDIA_MEDIACONTROL_CONTENTMEDIACONTROLLER_H_

#include "MediaControlKeySource.h"
#include "MediaControlKeysEvent.h"
#include "MediaStatusManager.h"

namespace mozilla {
namespace dom {

class BrowsingContext;
/**

/**
 * ContentMediaControlKeyReceiver is an interface which is used to receive media
 * control key sent from the chrome process, this class MUST only be used
 * in PlaybackController.
 * `ePaused` : media has paused playing, but still can be resumed by content
 *
 * Each browsing context tree would only have one ContentMediaControlKeyReceiver
 * that is used to handle media control key for that browsing context tree.
 */
class ContentMediaControlKeyReceiver {
 * MUST follow (1) `eStart` MUST be the first state and `eStop` MUST be the last
 public:
  NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING

  // Return nullptr if the top level browsing context is no longer alive.
  static ContentMediaControlKeyReceiver* Get(BrowsingContext* aBC);

  eStarted,
  // Use this method to handle the event from `ContentMediaAgent`.
  virtual void HandleMediaKey(MediaControlKey aKey) = 0;
};

/**

 * ContentMediaAgent is an interface which we use to (1) propoagate media
 * related information from the content process to the chrome process (2) act an
 * event source to dispatch media control key to its listeners.
 *
 * If the media would like to know the media control key, then media MUST
enum class MediaAudibleState : bool {
 * inherit from ContentMediaControlKeyReceiver, and register themselves to
 * ContentMediaAgent. Whenever media control key delivers, ContentMediaAgent
 * would notify all its receivers. In addition, whenever controlled media
 * changes its playback status or audible state, they should update their status
 * update via ContentMediaAgent.
/**
 *
 * control key events sent from the chrome process, this class MUST only be used
 * Each browsing context tree would only have one ContentMediaAgent that is used
 * to update controlled media status existing in that browsing context tree.
 */
class ContentMediaAgent : public IMediaInfoUpdater {
 public:
 * tree.
  // Return nullptr if the top level browsing context is no longer alive.
  static ContentMediaAgent* Get(BrowsingContext* aBC);

  // IMediaInfoUpdater Methods
  void NotifyMediaPlaybackChanged(uint64_t aBrowsingContextId,

                                  MediaPlaybackState aState) override;
  void NotifyMediaAudibleChanged(uint64_t aBrowsingContextId,
                                 MediaAudibleState aState) override;
  void SetIsInPictureInPictureMode(uint64_t aBrowsingContextId,
                                   bool aIsInPictureInPictureMode) override;
  virtual void HandleEvent(MediaControlKeysEvent aKeyEvent) = 0;
  void SetDeclaredPlaybackState(uint64_t aBrowsingContextId,
                                MediaSessionPlaybackState aState) override;
  void NotifySessionCreated(uint64_t aBrowsingContextId) override;
  void NotifySessionDestroyed(uint64_t aBrowsingContextId) override;
  void UpdateMetadata(uint64_t aBrowsingContextId,
                      const Maybe<MediaMetadataBase>& aMetadata) override;
};
  void EnableAction(uint64_t aBrowsingContextId,
                    MediaSessionAction aAction) override;
  void DisableAction(uint64_t aBrowsingContextId,
                     MediaSessionAction aAction) override;

 * source to dispatch control key events to its listeners.
  // Use these methods to register/unregister `ContentMediaControlKeyReceiver`
  // in order to listen to media control key events.
  virtual void AddReceiver(ContentMediaControlKeyReceiver* aReceiver) = 0;
 * ContentMediaAgent. Whenever media key events occur, ContentMediaAgent would
  virtual void RemoveReceiver(ContentMediaControlKeyReceiver* aReceiver) = 0;
};

/**
 * ContentMediaController has a responsibility to update the content media state
 * Each browsing context tree would only have one ContentMediaAgent that is used
 * to MediaController that exists in the chrome process and control all media
 * within a tab. It also delivers control commands from MediaController in order
 * to control media in the content page.
 *
 * Each ContentMediaController has its own ID that is corresponding to the top
  NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
 * level browsing context ID. That means we share same the
 * ContentMediaController for those media existing in the same browsing context
 * tree and same process.
 *
 * So if the content of a page are all in the same process, then we would only
 * create one ContentMediaController. However, if the content of a page are
  // Use this method to update the media playback state of controlled media, and
 * running in different processes because a page has cross-origin iframes, then
 * we would have multiple ContentMediaController at the same time, creating one
 * ContentMediaController in each process to manage media.
      MediaPlaybackState aState) = 0;
 */
class ContentMediaController final : public ContentMediaAgent,
                                     public ContentMediaControlKeyReceiver {
 public:
  NS_INLINE_DECL_REFCOUNTING(ContentMediaController, override)
  // media paused, `inaudible` should be notified

  explicit ContentMediaController(uint64_t aId);
  // ContentMediaAgent methods
  void AddReceiver(ContentMediaControlKeyReceiver* aListener) override;
  void RemoveReceiver(ContentMediaControlKeyReceiver* aListener) override;
  virtual void NotifyAudibleStateChanged(

  // ContentMediaControlKeyReceiver method
  void HandleMediaKey(MediaControlKey aKey) override;

 private:
  // media, and it's safe to notify same state again.
  ~ContentMediaController() = default;

  nsTArray<RefPtr<ContentMediaControlKeyReceiver>> mReceivers;
  uint64_t mTopLevelBrowsingContextId;
};

}  // namespace dom
}  // namespace mozilla
};

#endif  // DOM_MEDIA_MEDIACONTROL_CONTENTMEDIACONTROLLER_H_
 * within a tab. It also delivers control commands from MediaController in order
 *
 * ContentMediaController in each process to manage media.
 public:
  void AddReceiver(ContentControlKeyEventReceiver* aListener) override;
                                 MediaAudibleState aState) override;
  void HandleEvent(MediaControlKeysEvent aEvent) override;
  nsTArray<RefPtr<ContentControlKeyEventReceiver>> mReceivers;
  uint64_t mTopLevelBrowsingContextId;
}  // namespace mozilla