зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1580602 - P1: Implement a blank MediaSession interface. r=bzbarsky
Create dummy implementations for the MediaSession interfaces. The files are generated by running `./mach webidl-example` with necessary changes to make it buildable. The internal implementations are blank in this patch. They will be done in the following patches. Due to some spec issues, the final implementations only support some basic operations like "play" and "pause". Differential Revision: https://phabricator.services.mozilla.com/D45456 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
7b15e6f065
Коммит
8f0d0a884e
|
@ -41,6 +41,7 @@
|
|||
#include "mozilla/dom/FeaturePolicyUtils.h"
|
||||
#include "mozilla/dom/GamepadServiceTest.h"
|
||||
#include "mozilla/dom/MediaCapabilities.h"
|
||||
#include "mozilla/dom/MediaSession.h"
|
||||
#include "mozilla/dom/WakeLock.h"
|
||||
#include "mozilla/dom/power/PowerManagerService.h"
|
||||
#include "mozilla/dom/MIDIAccessManager.h"
|
||||
|
@ -160,6 +161,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaDevices)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerContainer)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaCapabilities)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaSession)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddonManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWebGpu)
|
||||
|
||||
|
@ -233,6 +235,7 @@ void Navigator::Invalidate() {
|
|||
}
|
||||
|
||||
mMediaCapabilities = nullptr;
|
||||
mMediaSession = nullptr;
|
||||
|
||||
mAddonManager = nullptr;
|
||||
|
||||
|
@ -1937,6 +1940,13 @@ dom::MediaCapabilities* Navigator::MediaCapabilities() {
|
|||
return mMediaCapabilities;
|
||||
}
|
||||
|
||||
dom::MediaSession* Navigator::MediaSession() {
|
||||
if (!mMediaSession) {
|
||||
mMediaSession = new dom::MediaSession();
|
||||
}
|
||||
return mMediaSession;
|
||||
}
|
||||
|
||||
Clipboard* Navigator::Clipboard() {
|
||||
if (!mClipboard) {
|
||||
mClipboard = new dom::Clipboard(GetWindow());
|
||||
|
|
|
@ -80,6 +80,7 @@ class VRDisplay;
|
|||
class VRServiceTest;
|
||||
class StorageManager;
|
||||
class MediaCapabilities;
|
||||
class MediaSession;
|
||||
struct ShareData;
|
||||
class WindowGlobalChild;
|
||||
|
||||
|
@ -217,6 +218,7 @@ class Navigator final : public nsISupports, public nsWrapperCache {
|
|||
static void GetAcceptLanguages(nsTArray<nsString>& aLanguages);
|
||||
|
||||
dom::MediaCapabilities* MediaCapabilities();
|
||||
dom::MediaSession* MediaSession();
|
||||
|
||||
AddonManager* GetMozAddonManager(ErrorResult& aRv);
|
||||
|
||||
|
@ -278,6 +280,7 @@ class Navigator final : public nsISupports, public nsWrapperCache {
|
|||
nsTArray<uint32_t> mRequestedVibrationPattern;
|
||||
RefPtr<StorageManager> mStorageManager;
|
||||
RefPtr<dom::MediaCapabilities> mMediaCapabilities;
|
||||
RefPtr<dom::MediaSession> mMediaSession;
|
||||
RefPtr<AddonManager> mAddonManager;
|
||||
RefPtr<webgpu::Instance> mWebGpu;
|
||||
RefPtr<Promise> mSharePromise; // Web Share API related
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 "mozilla/dom/MediaMetadata.h"
|
||||
#include "mozilla/dom/MediaSessionBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
// Only needed for refcounted objects.
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaMetadata)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaMetadata)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaMetadata)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaMetadata)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsIGlobalObject* MediaMetadata::GetParentObject() const { return nullptr; }
|
||||
|
||||
JSObject* MediaMetadata::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return MediaMetadata_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
already_AddRefed<MediaMetadata> MediaMetadata::Constructor(
|
||||
const GlobalObject& aGlobal, const MediaMetadataInit& aInit,
|
||||
ErrorResult& aRv) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MediaMetadata::GetTitle(nsString& aRetVal) const {}
|
||||
|
||||
void MediaMetadata::SetTitle(const nsAString& aTitle) {}
|
||||
|
||||
void MediaMetadata::GetArtist(nsString& aRetVal) const {}
|
||||
|
||||
void MediaMetadata::SetArtist(const nsAString& aArtist) {}
|
||||
|
||||
void MediaMetadata::GetAlbum(nsString& aRetVal) const {}
|
||||
|
||||
void MediaMetadata::SetAlbum(const nsAString& aAlbum) {}
|
||||
|
||||
void MediaMetadata::GetArtwork(JSContext* aCx, nsTArray<JSObject*>& aRetVal,
|
||||
ErrorResult& aRv) const {}
|
||||
|
||||
void MediaMetadata::SetArtwork(JSContext* aCx,
|
||||
const Sequence<JSObject*>& aArtwork,
|
||||
ErrorResult& aRv){};
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,67 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_MediaMetadata_h
|
||||
#define mozilla_dom_MediaMetadata_h
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsIGlobalObject;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
struct MediaImage;
|
||||
struct MediaMetadataInit;
|
||||
|
||||
class MediaMetadata final : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
// Ref counting and cycle collection
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaMetadata)
|
||||
|
||||
// WebIDL methods
|
||||
nsIGlobalObject* GetParentObject() const;
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
static already_AddRefed<MediaMetadata> Constructor(
|
||||
const GlobalObject& aGlobal, const MediaMetadataInit& aInit,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void GetTitle(nsString& aRetVal) const;
|
||||
|
||||
void SetTitle(const nsAString& aTitle);
|
||||
|
||||
void GetArtist(nsString& aRetVal) const;
|
||||
|
||||
void SetArtist(const nsAString& aArtist);
|
||||
|
||||
void GetAlbum(nsString& aRetVal) const;
|
||||
|
||||
void SetAlbum(const nsAString& aAlbum);
|
||||
|
||||
void GetArtwork(JSContext* aCx, nsTArray<JSObject*>& aRetVal,
|
||||
ErrorResult& aRv) const;
|
||||
|
||||
void SetArtwork(JSContext* aCx, const Sequence<JSObject*>& aArtwork,
|
||||
ErrorResult& aRv);
|
||||
|
||||
private:
|
||||
MediaMetadata() = default;
|
||||
~MediaMetadata() = default;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_MediaMetadata_h
|
|
@ -0,0 +1,37 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 "mozilla/dom/MediaMetadata.h"
|
||||
#include "mozilla/dom/MediaSession.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
// Only needed for refcounted objects.
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaSession)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaSession)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaSession)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaSession)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsIGlobalObject* MediaSession::GetParentObject() const { return nullptr; }
|
||||
|
||||
JSObject* MediaSession::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return MediaSession_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
MediaMetadata* MediaSession::GetMetadata() const { return nullptr; }
|
||||
|
||||
void MediaSession::SetMetadata(MediaMetadata* aMetadata) {}
|
||||
|
||||
void MediaSession::SetActionHandler(MediaSessionAction aAction,
|
||||
MediaSessionActionHandler* aHandler) {}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,51 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_MediaSession_h
|
||||
#define mozilla_dom_MediaSession_h
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/MediaSessionBinding.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsIGlobalObject;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class MediaSession final : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
// Ref counting and cycle collection
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaSession)
|
||||
|
||||
MediaSession() = default;
|
||||
|
||||
// WebIDL methods
|
||||
nsIGlobalObject* GetParentObject() const;
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
MediaMetadata* GetMetadata() const;
|
||||
|
||||
void SetMetadata(MediaMetadata* aMetadata);
|
||||
|
||||
void SetActionHandler(MediaSessionAction aAction,
|
||||
MediaSessionActionHandler* aHandler);
|
||||
|
||||
private:
|
||||
~MediaSession() = default;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_MediaSession_h
|
|
@ -0,0 +1,17 @@
|
|||
# -*- 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/.
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'MediaMetadata.h',
|
||||
'MediaSession.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'MediaMetadata.cpp',
|
||||
'MediaSession.cpp',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
|
@ -45,6 +45,7 @@ DIRS += [
|
|||
'mediacontrol',
|
||||
'mediasink',
|
||||
'mediasource',
|
||||
'mediasession',
|
||||
'mp3',
|
||||
'ogg',
|
||||
'platforms',
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* https://w3c.github.io/mediasession/#idl-index
|
||||
*/
|
||||
|
||||
// TODO: Implement MediaSessionPlaybackState (bug 1582508)
|
||||
|
||||
// TODO: Implement the missing seek* (bug 1580623) and skipad (bug 1582569) actions
|
||||
enum MediaSessionAction {
|
||||
"play",
|
||||
"pause",
|
||||
"previoustrack",
|
||||
"nexttrack",
|
||||
"stop",
|
||||
};
|
||||
|
||||
callback MediaSessionActionHandler = void(MediaSessionActionDetails details);
|
||||
|
||||
[Exposed=Window, Pref="dom.media.mediasession.enabled"]
|
||||
interface MediaSession {
|
||||
attribute MediaMetadata? metadata;
|
||||
|
||||
// TODO: attribute MediaSessionPlaybackState playbackState; (bug 1582508)
|
||||
|
||||
void setActionHandler(MediaSessionAction action, MediaSessionActionHandler? handler);
|
||||
|
||||
// TODO: void setPositionState(optional MediaPositionState? state); (bug 1582509)
|
||||
};
|
||||
|
||||
[Exposed=Window, Pref="dom.media.mediasession.enabled"]
|
||||
interface MediaMetadata {
|
||||
[Throws]
|
||||
constructor(optional MediaMetadataInit init = {});
|
||||
|
||||
attribute DOMString title;
|
||||
attribute DOMString artist;
|
||||
attribute DOMString album;
|
||||
// https://github.com/w3c/mediasession/issues/237
|
||||
// Take and return `MediaImage` on setter and getter.
|
||||
[Frozen, Cached, Pure, Throws]
|
||||
attribute sequence<object> artwork;
|
||||
};
|
||||
|
||||
dictionary MediaMetadataInit {
|
||||
DOMString title = "";
|
||||
DOMString artist = "";
|
||||
DOMString album = "";
|
||||
sequence<MediaImage> artwork = [];
|
||||
};
|
||||
|
||||
dictionary MediaImage {
|
||||
required USVString src;
|
||||
DOMString sizes = "";
|
||||
DOMString type = "";
|
||||
};
|
||||
|
||||
dictionary MediaSessionActionDetails {
|
||||
required MediaSessionAction action;
|
||||
};
|
||||
|
||||
// TODO: Implement MediaPositionState (bug 1582509)
|
|
@ -17,6 +17,7 @@
|
|||
* https://w3c.github.io/webappsec-credential-management/#framework-credential-management
|
||||
* https://w3c.github.io/webdriver/webdriver-spec.html#interface
|
||||
* https://wicg.github.io/media-capabilities/#idl-index
|
||||
* https://w3c.github.io/mediasession/#idl-index
|
||||
*
|
||||
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
|
||||
* Opera Software ASA. You are granted a license to use, reproduce
|
||||
|
@ -334,3 +335,10 @@ dictionary ShareData {
|
|||
USVString text;
|
||||
USVString url;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/mediasession/#idl-index
|
||||
[Exposed=Window]
|
||||
partial interface Navigator {
|
||||
[Pref="dom.media.mediasession.enabled", SameObject]
|
||||
readonly attribute MediaSession mediaSession;
|
||||
};
|
|
@ -657,6 +657,7 @@ WEBIDL_FILES = [
|
|||
'MediaList.webidl',
|
||||
'MediaQueryList.webidl',
|
||||
'MediaRecorder.webidl',
|
||||
'MediaSession.webidl',
|
||||
'MediaSource.webidl',
|
||||
'MediaStream.webidl',
|
||||
'MediaStreamAudioDestinationNode.webidl',
|
||||
|
|
|
@ -1742,6 +1742,12 @@
|
|||
value: false
|
||||
mirror: always
|
||||
|
||||
# Media Session API
|
||||
- name: dom.media.mediasession.enabled
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Enable meta-viewport support in remote APZ-enabled frames.
|
||||
- name: dom.meta-viewport.enabled
|
||||
type: RelaxedAtomicBool
|
||||
|
|
Загрузка…
Ссылка в новой задаче