2015-01-31 00:23:07 +00:00
|
|
|
/* -*- 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 "mozilla/dom/MediaKeyStatusMap.h"
|
2015-02-13 19:52:42 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2015-01-31 00:23:07 +00:00
|
|
|
#include "mozilla/dom/UnionTypes.h"
|
2015-02-13 00:26:00 +00:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2015-11-24 00:13:21 +00:00
|
|
|
#include "mozilla/EMEUtils.h"
|
2017-08-08 08:36:01 +00:00
|
|
|
#include "GMPUtils.h"
|
2015-01-31 00:23:07 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaKeyStatusMap)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaKeyStatusMap)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaKeyStatusMap)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2015-11-24 00:13:21 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaKeyStatusMap, mParent)
|
2015-01-31 00:23:07 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
MediaKeyStatusMap::MediaKeyStatusMap(nsPIDOMWindowInner* aParent)
|
2015-01-31 00:23:07 +00:00
|
|
|
: mParent(aParent) {}
|
|
|
|
|
|
|
|
MediaKeyStatusMap::~MediaKeyStatusMap() {}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
JSObject* MediaKeyStatusMap::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return MediaKeyStatusMap_Binding::Wrap(aCx, this, aGivenProto);
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindowInner* MediaKeyStatusMap::GetParentObject() const {
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
2016-07-28 02:03:01 +00:00
|
|
|
void MediaKeyStatusMap::Get(JSContext* aCx,
|
|
|
|
const ArrayBufferViewOrArrayBuffer& aKey,
|
|
|
|
JS::MutableHandle<JS::Value> aOutValue,
|
|
|
|
ErrorResult& aOutRv) const {
|
2015-11-24 00:13:21 +00:00
|
|
|
ArrayData keyId = GetArrayBufferViewOrArrayBufferData(aKey);
|
|
|
|
if (!keyId.IsValid()) {
|
2016-07-28 02:03:01 +00:00
|
|
|
aOutValue.setUndefined();
|
|
|
|
return;
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
2015-11-24 00:13:21 +00:00
|
|
|
for (const KeyStatus& status : mStatuses) {
|
|
|
|
if (keyId == status.mKeyId) {
|
2017-03-02 21:08:29 +00:00
|
|
|
bool ok = ToJSValue(aCx, status.mStatus, aOutValue);
|
|
|
|
if (!ok) {
|
|
|
|
aOutRv.NoteJSContextException(aCx);
|
|
|
|
}
|
2016-07-28 02:03:01 +00:00
|
|
|
return;
|
2015-11-24 00:13:21 +00:00
|
|
|
}
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
2016-07-28 02:03:01 +00:00
|
|
|
aOutValue.setUndefined();
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:13:21 +00:00
|
|
|
bool MediaKeyStatusMap::Has(const ArrayBufferViewOrArrayBuffer& aKey) const {
|
|
|
|
ArrayData keyId = GetArrayBufferViewOrArrayBufferData(aKey);
|
|
|
|
if (!keyId.IsValid()) {
|
2015-01-31 00:23:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-24 00:13:21 +00:00
|
|
|
for (const KeyStatus& status : mStatuses) {
|
|
|
|
if (keyId == status.mKeyId) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:13:21 +00:00
|
|
|
return false;
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:13:21 +00:00
|
|
|
uint32_t MediaKeyStatusMap::GetIterableLength() const {
|
|
|
|
return mStatuses.Length();
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:13:21 +00:00
|
|
|
TypedArrayCreator<ArrayBuffer> MediaKeyStatusMap::GetKeyAtIndex(
|
|
|
|
uint32_t aIndex) const {
|
|
|
|
MOZ_ASSERT(aIndex < GetIterableLength());
|
|
|
|
return TypedArrayCreator<ArrayBuffer>(mStatuses[aIndex].mKeyId);
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 23:56:29 +00:00
|
|
|
nsString MediaKeyStatusMap::GetKeyIDAsHexString(uint32_t aIndex) const {
|
|
|
|
MOZ_ASSERT(aIndex < GetIterableLength());
|
|
|
|
return NS_ConvertUTF8toUTF16(ToHexString(mStatuses[aIndex].mKeyId));
|
|
|
|
}
|
|
|
|
|
2015-11-24 00:13:21 +00:00
|
|
|
MediaKeyStatus MediaKeyStatusMap::GetValueAtIndex(uint32_t aIndex) const {
|
|
|
|
MOZ_ASSERT(aIndex < GetIterableLength());
|
|
|
|
return mStatuses[aIndex].mStatus;
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:13:21 +00:00
|
|
|
uint32_t MediaKeyStatusMap::Size() const { return mStatuses.Length(); }
|
2015-01-31 00:23:07 +00:00
|
|
|
|
2015-11-24 00:13:21 +00:00
|
|
|
void MediaKeyStatusMap::Update(const nsTArray<CDMCaps::KeyStatus>& aKeys) {
|
|
|
|
mStatuses.Clear();
|
|
|
|
for (const auto& key : aKeys) {
|
2016-08-02 07:05:21 +00:00
|
|
|
mStatuses.InsertElementSorted(KeyStatus(key.mId, key.mStatus));
|
2015-11-24 00:13:21 +00:00
|
|
|
}
|
2015-01-31 00:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|