Bug 1409664 - P1. Add MediaCapabilities skeleton IDL. r=bz

Summary:
As per https://wicg.github.io/media-capabilities/#idl-index

Placed behind user pref media.mediacapabilities.enabled that is disabled by default

Tags: #secure-revision

Bug #: 1409664

Differential Revision: https://phabricator.services.mozilla.com/D1613
This commit is contained in:
Jean-Yves Avenard 2018-05-31 14:32:51 +02:00
parent fc03dffd3c
commit 83a8e7725c
15 changed files with 317 additions and 2 deletions

View File

@ -34,6 +34,7 @@
#include "BatteryManager.h"
#include "mozilla/dom/CredentialsContainer.h"
#include "mozilla/dom/GamepadServiceTest.h"
#include "mozilla/dom/MediaCapabilities.h"
#include "mozilla/dom/WakeLock.h"
#include "mozilla/dom/power/PowerManagerService.h"
#include "mozilla/dom/MIDIAccessManager.h"
@ -152,6 +153,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCredentials)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaDevices)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerContainer)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaCapabilities)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
@ -222,6 +224,8 @@ Navigator::Invalidate()
mVRServiceTest->Shutdown();
mVRServiceTest = nullptr;
}
mMediaCapabilities = nullptr;
}
void
@ -1795,6 +1799,16 @@ Navigator::Credentials()
return mCredentials;
}
dom::MediaCapabilities*
Navigator::MediaCapabilities()
{
if (!mMediaCapabilities) {
mMediaCapabilities =
new dom::MediaCapabilities(GetWindow()->AsGlobal());
}
return mMediaCapabilities;
}
/* static */
bool
Navigator::Webdriver()

View File

@ -76,6 +76,7 @@ class LegacyMozTCPSocket;
class VRDisplay;
class VRServiceTest;
class StorageManager;
class MediaCapabilities;
class Navigator final : public nsISupports
, public nsWrapperCache
@ -215,6 +216,8 @@ public:
static void GetAcceptLanguages(nsTArray<nsString>& aLanguages);
dom::MediaCapabilities* MediaCapabilities();
// WebIDL helper methods
static bool HasUserMediaSupport(JSContext* /* unused */,
JSObject* /* unused */);
@ -274,6 +277,7 @@ private:
RefPtr<VRServiceTest> mVRServiceTest;
nsTArray<uint32_t> mRequestedVibrationPattern;
RefPtr<StorageManager> mStorageManager;
RefPtr<dom::MediaCapabilities> mMediaCapabilities;
};
} // namespace dom

View File

@ -517,6 +517,10 @@ DOMInterfaces = {
'nativeType': 'mozilla::extensions::MatchPatternSet',
},
'MediaCapabilitiesInfo' : {
'wrapperCache': False,
},
'MediaKeys' : {
'implicitJSContext': [ 'createSession']
},

View File

@ -0,0 +1,76 @@
/* -*- 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 "MediaCapabilities.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/dom/MediaCapabilitiesBinding.h"
#include "mozilla/dom/Promise.h"
namespace mozilla {
namespace dom {
already_AddRefed<Promise>
MediaCapabilities::DecodingInfo(
const MediaDecodingConfiguration& aConfiguration,
ErrorResult& aRv)
{
RefPtr<Promise> promise = Promise::Create(mParent, aRv);
if (aRv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_DOM_TYPE_ERR);
return promise.forget();
}
already_AddRefed<Promise>
MediaCapabilities::EncodingInfo(
const MediaEncodingConfiguration& aConfiguration,
ErrorResult& aRv)
{
RefPtr<Promise> promise = Promise::Create(mParent, aRv);
if (aRv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_DOM_TYPE_ERR);
return promise.forget();
}
bool
MediaCapabilities::Enabled(JSContext* aCx, JSObject* aGlobal)
{
return StaticPrefs::MediaCapabilitiesEnabled();
}
JSObject*
MediaCapabilities::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return MediaCapabilities_Binding::Wrap(aCx, this, aGivenProto);
}
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaCapabilities)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaCapabilities)
NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaCapabilities)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaCapabilities, mParent)
// MediaCapabilitiesInfo
bool
MediaCapabilitiesInfo::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto,
JS::MutableHandle<JSObject*> aReflector)
{
return MediaCapabilitiesInfo_Binding::Wrap(
aCx, this, aGivenProto, aReflector);
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,91 @@
/* -*- 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/. */
#ifndef mozilla_dom_MediaCapabilities_h_
#define mozilla_dom_MediaCapabilities_h_
#include "js/TypeDecls.h"
#include "mozilla/dom/BindingUtils.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionNoteChild.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIGlobalObject.h"
#include "nsISupports.h"
#include "nsWrapperCache.h"
namespace mozilla {
namespace dom {
struct MediaDecodingConfiguration;
struct MediaEncodingConfiguration;
class Promise;
class MediaCapabilities final
: public nsISupports
, public nsWrapperCache
{
public:
// Ref counting and cycle collection
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaCapabilities)
// WebIDL Methods
already_AddRefed<Promise> DecodingInfo(
const MediaDecodingConfiguration& aConfiguration,
ErrorResult& aRv);
already_AddRefed<Promise> EncodingInfo(
const MediaEncodingConfiguration& aConfiguration,
ErrorResult& aRv);
// End WebIDL Methods
explicit MediaCapabilities(nsIGlobalObject* aParent)
: mParent(aParent)
{
}
nsIGlobalObject* GetParentObject() const { return mParent; }
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
static bool Enabled(JSContext* aCx, JSObject* aGlobal);
private:
virtual ~MediaCapabilities() = default;
nsCOMPtr<nsIGlobalObject> mParent;
};
class MediaCapabilitiesInfo final : public NonRefcountedDOMObject
{
public:
// WebIDL methods
bool Supported() const { return mSupported; }
bool Smooth() const { return mSmooth; }
bool PowerEfficient() const { return mPowerEfficient; }
// End WebIDL methods
MediaCapabilitiesInfo(bool aSupported, bool aSmooth, bool aPowerEfficient)
: mSupported(aSupported)
, mSmooth(aSmooth)
, mPowerEfficient(aPowerEfficient)
{
}
bool WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto,
JS::MutableHandle<JSObject*> aReflector);
private:
bool mSupported;
bool mSmooth;
bool mPowerEfficient;
};
} // namespace dom
} // namespace mozilla
#endif /* mozilla_dom_MediaCapabilities_h_ */

View File

@ -0,0 +1,14 @@
# 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 += [
'MediaCapabilities.h',
]
UNIFIED_SOURCES += [
'MediaCapabilities.cpp',
]
FINAL_LIBRARY = 'xul'

View File

@ -41,6 +41,7 @@ DIRS += [
'gmp-plugin-openh264',
'imagecapture',
'ipc',
'mediacapabilities',
'mediasink',
'mediasource',
'mp3',

View File

@ -0,0 +1,66 @@
/* -*- 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://wicg.github.io/media-capabilities/
*
* Copyright © 2018 the Contributors to the Media Capabilities Specification
*/
dictionary MediaConfiguration {
VideoConfiguration video;
AudioConfiguration audio;
};
dictionary MediaDecodingConfiguration : MediaConfiguration {
required MediaDecodingType type;
};
dictionary MediaEncodingConfiguration : MediaConfiguration {
required MediaEncodingType type;
};
enum MediaDecodingType {
"file",
"media-source",
};
enum MediaEncodingType {
"record",
"transmission"
};
dictionary VideoConfiguration {
required DOMString contentType;
required unsigned long width;
required unsigned long height;
required unsigned long long bitrate;
required DOMString framerate;
};
dictionary AudioConfiguration {
required DOMString contentType;
DOMString channels;
unsigned long long bitrate;
unsigned long samplerate;
};
[Exposed=(Window, Worker), Func="mozilla::dom::MediaCapabilities::Enabled",
HeaderFile="mozilla/dom/MediaCapabilities.h"]
interface MediaCapabilitiesInfo {
readonly attribute boolean supported;
readonly attribute boolean smooth;
readonly attribute boolean powerEfficient;
};
[Exposed=(Window, Worker), Func="mozilla::dom::MediaCapabilities::Enabled"]
interface MediaCapabilities {
// As per https://github.com/WICG/media-capabilities/issues/91 we mark the
// methods as always returning a new object.
[NewObject]
Promise<MediaCapabilitiesInfo> decodingInfo(MediaDecodingConfiguration configuration);
[NewObject]
Promise<MediaCapabilitiesInfo> encodingInfo(MediaEncodingConfiguration configuration);
};

View File

@ -16,6 +16,7 @@
* http://wicg.github.io/netinfo/#extensions-to-the-navigator-interface
* 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
*
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
* Opera Software ASA. You are granted a license to use, reproduce
@ -150,6 +151,13 @@ partial interface Navigator {
readonly attribute long maxTouchPoints;
};
// https://wicg.github.io/media-capabilities/#idl-index
[Exposed=Window]
partial interface Navigator {
[SameObject, Func="mozilla::dom::MediaCapabilities::Enabled"]
readonly attribute MediaCapabilities mediaCapabilities;
};
// Mozilla-specific extensions
// Chrome-only interface for Vibration API permission handling.

View File

@ -14,8 +14,15 @@ WorkerNavigator implements NavigatorConcurrentHardware;
WorkerNavigator implements NavigatorStorage;
// http://wicg.github.io/netinfo/#extensions-to-the-navigator-interface
[Exposed=(Worker)]
[Exposed=Worker]
partial interface WorkerNavigator {
[Func="mozilla::dom::DOMPrefs::NetworkInformationEnabled", Throws]
readonly attribute NetworkInformation connection;
};
// https://wicg.github.io/media-capabilities/#idl-index
[Exposed=Worker]
partial interface WorkerNavigator {
[SameObject, Func="mozilla::dom::MediaCapabilities::Enabled"]
readonly attribute MediaCapabilities mediaCapabilities;
};

View File

@ -633,6 +633,7 @@ WEBIDL_FILES = [
'ListBoxObject.webidl',
'LocalMediaStream.webidl',
'Location.webidl',
'MediaCapabilities.webidl',
'MediaDeviceInfo.webidl',
'MediaDevices.webidl',
'MediaElementAudioSourceNode.webidl',

View File

@ -6,6 +6,7 @@
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMPrefs.h"
#include "mozilla/dom/MediaCapabilities.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseWorkerProxy.h"
#include "mozilla/dom/StorageManager.h"
@ -31,7 +32,7 @@ namespace dom {
using namespace workerinternals;
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WorkerNavigator, mStorageManager,
mConnection);
mConnection, mMediaCapabilities);
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release)
@ -216,6 +217,20 @@ WorkerNavigator::GetConnection(ErrorResult& aRv)
return mConnection;
}
dom::MediaCapabilities*
WorkerNavigator::MediaCapabilities()
{
if (!mMediaCapabilities) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
nsIGlobalObject* global = workerPrivate->GlobalScope();
MOZ_ASSERT(global);
mMediaCapabilities = new dom::MediaCapabilities(global);
}
return mMediaCapabilities;
}
} // namespace dom
} // namespace mozilla

View File

@ -18,6 +18,7 @@ namespace mozilla {
namespace dom {
class Promise;
class StorageManager;
class MediaCapabilities;
namespace network {
class Connection;
@ -107,6 +108,11 @@ public:
StorageManager* Storage();
network::Connection* GetConnection(ErrorResult& aRv);
dom::MediaCapabilities* MediaCapabilities();
private:
RefPtr<dom::MediaCapabilities> mMediaCapabilities;
};
} // namespace dom

View File

@ -890,6 +890,12 @@ VARCACHE_PREF(
bool, false
)
VARCACHE_PREF(
"media.media-capabilities.enabled",
MediaCapabilitiesEnabled,
RelaxedAtomicBool, false
)
//---------------------------------------------------------------------------
// Network prefs
//---------------------------------------------------------------------------

View File

@ -547,6 +547,8 @@ pref("media.benchmark.vp9.threshold", 150);
pref("media.benchmark.frames", 300);
pref("media.benchmark.timeout", 1000);
pref("media.media-capabilities.enabled", false);
#ifdef MOZ_WEBSPEECH
pref("media.webspeech.synth.enabled", false);
#endif