Bug 1598968 - Make MediaControlUtils a proper header. r=MeFisto94,alwu

Differential Revision: https://phabricator.services.mozilla.com/D54643

--HG--
rename : dom/media/mediacontrol/MediaControlUtils.h => dom/media/mediacontrol/MediaControlUtils.cpp
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-11-26 09:25:33 +00:00
Родитель ab0ac8c7e6
Коммит 008850fba9
10 изменённых файлов: 103 добавлений и 96 удалений

Просмотреть файл

@ -10,8 +10,6 @@
#include "mozilla/Logging.h"
#include "mozilla/StaticPrefs_media.h"
extern mozilla::LazyLogModule gMediaControlLog;
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \

Просмотреть файл

@ -10,8 +10,6 @@
#include "MediaControlService.h"
#include "mozilla/Logging.h"
extern mozilla::LazyLogModule gMediaControlLog;
namespace mozilla {
namespace dom {
@ -36,12 +34,10 @@ static const char* ToMediaControlKeysEventStr(MediaControlKeysEvent aKeyEvent) {
("MediaControlKeysEventSource=%p, " msg, this, ##__VA_ARGS__))
#undef LOG_KEY
#define LOG_KEY(msg, key, ...) \
if (MOZ_LOG_TEST(gMediaControlLog, mozilla::LogLevel::Debug)) { \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlKeysHandler=%p, " msg, this, \
ToMediaControlKeysEventStr(key), ##__VA_ARGS__)); \
}
#define LOG_KEY(msg, key, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlKeysHandler=%p, " msg, this, \
ToMediaControlKeysEventStr(key), ##__VA_ARGS__));
NS_IMPL_ISUPPORTS0(MediaControlKeysHandler)

Просмотреть файл

@ -5,16 +5,16 @@
#include "MediaControlKeysManager.h"
#include "MediaControlUtils.h"
#include "MediaControlService.h"
#include "mozilla/AbstractThread.h"
#include "mozilla/Assertions.h"
#include "mozilla/Logging.h"
#include "mozilla/StaticPrefs_media.h"
#ifdef MOZ_APPLEMEDIA
# include "MediaHardwareKeysEventSourceMac.h"
#endif
extern mozilla::LazyLogModule gMediaControlLog;
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \

Просмотреть файл

@ -5,6 +5,7 @@
#include "MediaControlService.h"
#include "MediaController.h"
#include "MediaControlUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/Logging.h"
@ -13,8 +14,6 @@
#include "nsIObserverService.h"
#include "nsXULAppAPI.h"
extern mozilla::LazyLogModule gMediaControlLog;
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \

Просмотреть файл

@ -0,0 +1,86 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 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/. */
#include "MediaControlUtils.h"
#include "MediaControlService.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/ContentChild.h"
#include "nsGlobalWindowOuter.h"
mozilla::LazyLogModule gMediaControlLog("MediaControl");
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlUtils, " msg, ##__VA_ARGS__))
namespace mozilla {
namespace dom {
static RefPtr<BrowsingContext> GetBrowingContextByWindowID(uint64_t aWindowID) {
RefPtr<nsGlobalWindowOuter> window =
nsGlobalWindowOuter::GetOuterWindowWithId(aWindowID);
if (!window) {
return nullptr;
}
return window->GetBrowsingContext();
}
static void NotifyMediaActiveChanged(const RefPtr<BrowsingContext>& aBc,
bool aActive) {
if (XRE_IsContentProcess()) {
ContentChild* contentChild = ContentChild::GetSingleton();
Unused << contentChild->SendNotifyMediaActiveChanged(aBc, aActive);
} else {
MediaControlService::GetService()
->GetOrCreateControllerById(aBc->Id())
->NotifyMediaActiveChanged(aActive);
}
}
void NotifyMediaStarted(uint64_t aWindowID) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc || bc->IsDiscarded()) {
return;
}
LOG("Notify media started in BC %" PRId64, bc->Id());
bc = bc->Top();
NotifyMediaActiveChanged(bc, true);
}
void NotifyMediaStopped(uint64_t aWindowID) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc || bc->IsDiscarded()) {
return;
}
LOG("Notify media stopped in BC %" PRId64, bc->Id());
bc = bc->Top();
NotifyMediaActiveChanged(bc, false);
}
void NotifyMediaAudibleChanged(uint64_t aWindowID, bool aAudible) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc || bc->IsDiscarded()) {
return;
}
LOG("Notify media became %s in BC %" PRId64,
aAudible ? "audible" : "inaudible", bc->Id());
bc = bc->Top();
if (XRE_IsContentProcess()) {
ContentChild* contentChild = ContentChild::GetSingleton();
Unused << contentChild->SendNotifyMediaAudibleChanged(bc, aAudible);
} else {
RefPtr<MediaController> controller =
MediaControlService::GetService()->GetControllerById(bc->Id());
if (controller) {
controller->NotifyMediaAudibleChanged(aAudible);
}
}
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -7,47 +7,15 @@
#ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLUTILS_H_
#define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLUTILS_H_
#include "mozilla/Logging.h"
#include "MediaController.h"
#include "MediaControlService.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/ContentChild.h"
#include "nsGlobalWindowOuter.h"
#include "nsXULAppAPI.h"
mozilla::LazyLogModule gMediaControlLog("MediaControl");
#undef LOG
#define LOG(msg, ...) \
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
("MediaControlUtils, " msg, ##__VA_ARGS__))
extern mozilla::LazyLogModule gMediaControlLog;
namespace mozilla {
namespace dom {
static void NotifyMediaActiveChanged(const RefPtr<BrowsingContext>& aBc,
bool aActive) {
if (XRE_IsContentProcess()) {
ContentChild* contentChild = ContentChild::GetSingleton();
Unused << contentChild->SendNotifyMediaActiveChanged(aBc, aActive);
} else {
MediaControlService::GetService()
->GetOrCreateControllerById(aBc->Id())
->NotifyMediaActiveChanged(aActive);
}
}
static RefPtr<BrowsingContext> GetBrowingContextByWindowID(uint64_t aWindowID) {
RefPtr<nsGlobalWindowOuter> window =
nsGlobalWindowOuter::GetOuterWindowWithId(aWindowID);
if (!window) {
return nullptr;
}
return window->GetBrowsingContext();
}
const char* ToMediaControlActionsStr(
mozilla::dom::MediaControlActions aAction) {
inline const char* ToMediaControlActionsStr(MediaControlActions aAction){
switch (aAction) {
case MediaControlActions::ePlay:
return "Play";
@ -61,45 +29,9 @@ const char* ToMediaControlActionsStr(
return "UNKNOWN";
}
void NotifyMediaStarted(uint64_t aWindowID) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc || bc->IsDiscarded()) {
return;
}
LOG("Notify media started in BC %" PRId64, bc->Id());
bc = bc->Top();
NotifyMediaActiveChanged(bc, true);
}
void NotifyMediaStopped(uint64_t aWindowID) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc || bc->IsDiscarded()) {
return;
}
LOG("Notify media stopped in BC %" PRId64, bc->Id());
bc = bc->Top();
NotifyMediaActiveChanged(bc, false);
}
void NotifyMediaAudibleChanged(uint64_t aWindowID, bool aAudible) {
RefPtr<BrowsingContext> bc = GetBrowingContextByWindowID(aWindowID);
if (!bc || bc->IsDiscarded()) {
return;
}
LOG("Notify media became %s in BC %" PRId64,
aAudible ? "audible" : "inaudible", bc->Id());
bc = bc->Top();
if (XRE_IsContentProcess()) {
ContentChild* contentChild = ContentChild::GetSingleton();
Unused << contentChild->SendNotifyMediaAudibleChanged(bc, aAudible);
} else {
RefPtr<MediaController> controller =
MediaControlService::GetService()->GetControllerById(bc->Id());
if (controller) {
controller->NotifyMediaAudibleChanged(aAudible);
}
}
}
void NotifyMediaStarted(uint64_t aWindowID);
void NotifyMediaStopped(uint64_t aWindowID);
void NotifyMediaAudibleChanged(uint64_t aWindowID, bool aAudible);
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -7,11 +7,10 @@
#include "MediaController.h"
#include "MediaControlService.h"
#include "MediaControlUtils.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
extern mozilla::LazyLogModule gMediaControlLog;
// avoid redefined macro in unified build
#undef LOG
#define LOG(msg, ...) \

Просмотреть файл

@ -7,10 +7,7 @@
#import <IOKit/hidsystem/ev_keymap.h>
#include "MediaHardwareKeysEventSourceMac.h"
#include "mozilla/Logging.h"
extern mozilla::LazyLogModule gMediaControlLog;
#include "MediaControlUtils.h"
// avoid redefined macro in unified build
#undef LOG

Просмотреть файл

@ -5,8 +5,7 @@
#include "PlaybackController.h"
#include "nsIAudioChannelAgent.h"
extern mozilla::LazyLogModule gMediaControlLog;
#include "MediaControlUtils.h"
// avoid redefined macro in unified build
#undef LOG

Просмотреть файл

@ -31,6 +31,7 @@ UNIFIED_SOURCES += [
'MediaControlKeysManager.cpp',
'MediaController.cpp',
'MediaControlService.cpp',
'MediaControlUtils.cpp',
'PlaybackController.cpp',
]