2014-06-06 20:52:15 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_mediakeys_h__
|
|
|
|
#define mozilla_dom_mediakeys_h__
|
|
|
|
|
|
|
|
#include "nsIDOMMediaError.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "mozilla/dom/MediaKeysBinding.h"
|
2014-10-12 22:53:43 +00:00
|
|
|
#include "mozIGeckoMediaPluginService.h"
|
2014-06-06 20:52:15 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class CDMProxy;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2014-10-01 18:43:26 +00:00
|
|
|
class ArrayBufferViewOrArrayBuffer;
|
2014-06-06 20:52:15 +00:00
|
|
|
class MediaKeySession;
|
2014-10-12 22:53:43 +00:00
|
|
|
class HTMLMediaElement;
|
2014-06-06 20:52:15 +00:00
|
|
|
|
|
|
|
typedef nsRefPtrHashtable<nsStringHashKey, MediaKeySession> KeySessionHashMap;
|
|
|
|
typedef nsRefPtrHashtable<nsUint32HashKey, dom::Promise> PromiseHashMap;
|
|
|
|
typedef nsRefPtrHashtable<nsUint32HashKey, MediaKeySession> PendingKeySessionsHashMap;
|
|
|
|
typedef uint32_t PromiseId;
|
|
|
|
|
2014-08-27 08:46:56 +00:00
|
|
|
// Helper function to extract data coming in from JS in an
|
|
|
|
// (ArrayBuffer or ArrayBufferView) IDL typed function argument.
|
|
|
|
bool
|
|
|
|
CopyArrayBufferViewOrArrayBufferData(const ArrayBufferViewOrArrayBuffer& aBufferOrView,
|
|
|
|
nsTArray<uint8_t>& aOutData);
|
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
// This class is used on the main thread only.
|
|
|
|
// Note: it's addref/release is not (and can't be) thread safe!
|
|
|
|
class MediaKeys MOZ_FINAL : public nsISupports,
|
|
|
|
public nsWrapperCache
|
|
|
|
{
|
2014-06-24 16:36:43 +00:00
|
|
|
~MediaKeys();
|
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaKeys)
|
|
|
|
|
|
|
|
MediaKeys(nsPIDOMWindow* aParentWindow, const nsAString& aKeySystem);
|
|
|
|
|
2014-11-18 09:13:02 +00:00
|
|
|
already_AddRefed<Promise> Init(ErrorResult& aRv);
|
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
nsPIDOMWindow* GetParentObject() const;
|
|
|
|
|
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
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) MOZ_OVERRIDE;
|
2014-06-06 20:52:15 +00:00
|
|
|
|
2014-10-12 22:53:43 +00:00
|
|
|
nsresult Bind(HTMLMediaElement* aElement);
|
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
// Javascript: readonly attribute DOMString keySystem;
|
|
|
|
void GetKeySystem(nsString& retval) const;
|
|
|
|
|
|
|
|
// JavaScript: MediaKeys.createSession()
|
2015-02-01 18:12:00 +00:00
|
|
|
already_AddRefed<MediaKeySession> CreateSession(JSContext* aCx,
|
|
|
|
SessionType aSessionType,
|
2014-09-23 22:04:49 +00:00
|
|
|
ErrorResult& aRv);
|
2014-06-06 20:52:15 +00:00
|
|
|
|
|
|
|
// JavaScript: MediaKeys.SetServerCertificate()
|
2014-08-27 08:46:56 +00:00
|
|
|
already_AddRefed<Promise> SetServerCertificate(const ArrayBufferViewOrArrayBuffer& aServerCertificate,
|
2014-07-19 01:31:11 +00:00
|
|
|
ErrorResult& aRv);
|
2014-06-06 20:52:15 +00:00
|
|
|
|
|
|
|
already_AddRefed<MediaKeySession> GetSession(const nsAString& aSessionId);
|
|
|
|
|
2015-01-09 01:30:07 +00:00
|
|
|
// Removes and returns MediaKeySession from the set of sessions awaiting
|
|
|
|
// their sessionId to be assigned.
|
|
|
|
already_AddRefed<MediaKeySession> GetPendingSession(uint32_t aToken);
|
|
|
|
|
|
|
|
// Called once a Init() operation succeeds.
|
2014-10-12 22:53:43 +00:00
|
|
|
void OnCDMCreated(PromiseId aId, const nsACString& aNodeId);
|
2015-01-09 01:30:07 +00:00
|
|
|
|
|
|
|
// Called once the CDM generates a sessionId while servicing a
|
|
|
|
// MediaKeySession.generateRequest() or MediaKeySession.load() call,
|
|
|
|
// once the sessionId of a MediaKeySession is known.
|
|
|
|
void OnSessionIdReady(MediaKeySession* aSession);
|
|
|
|
|
2014-09-23 22:04:49 +00:00
|
|
|
// Called once a LoadSession succeeds.
|
|
|
|
void OnSessionLoaded(PromiseId aId, bool aSuccess);
|
2015-01-09 01:30:07 +00:00
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
// Called once a session has closed.
|
|
|
|
void OnSessionClosed(MediaKeySession* aSession);
|
|
|
|
|
|
|
|
CDMProxy* GetCDMProxy() { return mProxy; }
|
|
|
|
|
|
|
|
// Makes a new promise, or nullptr on failure.
|
2014-07-19 01:31:11 +00:00
|
|
|
already_AddRefed<Promise> MakePromise(ErrorResult& aRv);
|
2014-06-06 20:52:15 +00:00
|
|
|
// Stores promise in mPromises, returning an ID that can be used to retrieve
|
|
|
|
// it later. The ID is passed to the CDM, so that it can signal specific
|
|
|
|
// promises to be resolved.
|
|
|
|
PromiseId StorePromise(Promise* aPromise);
|
|
|
|
|
|
|
|
// Reject promise with DOMException corresponding to aExceptionCode.
|
|
|
|
void RejectPromise(PromiseId aId, nsresult aExceptionCode);
|
|
|
|
// Resolves promise with "undefined".
|
|
|
|
void ResolvePromise(PromiseId aId);
|
|
|
|
|
2014-10-12 22:53:43 +00:00
|
|
|
const nsCString& GetNodeId() const;
|
2014-07-30 06:53:28 +00:00
|
|
|
|
2014-08-17 21:41:50 +00:00
|
|
|
void Shutdown();
|
2014-12-17 01:01:00 +00:00
|
|
|
|
|
|
|
// Called by CDMProxy when CDM crashes or shuts down. It is different from
|
|
|
|
// Shutdown which is called from the script/dom side.
|
|
|
|
void Terminated();
|
2014-08-17 21:41:50 +00:00
|
|
|
|
2014-10-12 22:53:43 +00:00
|
|
|
// Returns true if this MediaKeys has been bound to a media element.
|
|
|
|
bool IsBoundToMediaElement() const;
|
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
private:
|
|
|
|
|
2014-10-12 22:53:43 +00:00
|
|
|
bool IsInPrivateBrowsing();
|
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
// Removes promise from mPromises, and returns it.
|
|
|
|
already_AddRefed<Promise> RetrievePromise(PromiseId aId);
|
|
|
|
|
|
|
|
// Owning ref to proxy. The proxy has a weak reference back to the MediaKeys,
|
|
|
|
// and the MediaKeys destructor clears the proxy's reference to the MediaKeys.
|
|
|
|
nsRefPtr<CDMProxy> mProxy;
|
|
|
|
|
2014-10-12 22:53:43 +00:00
|
|
|
nsRefPtr<HTMLMediaElement> mElement;
|
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> mParent;
|
|
|
|
nsString mKeySystem;
|
2014-10-12 22:53:43 +00:00
|
|
|
nsCString mNodeId;
|
2014-06-06 20:52:15 +00:00
|
|
|
KeySessionHashMap mKeySessions;
|
|
|
|
PromiseHashMap mPromises;
|
|
|
|
PendingKeySessionsHashMap mPendingSessions;
|
2014-07-30 06:53:28 +00:00
|
|
|
PromiseId mCreatePromiseId;
|
2014-10-12 22:53:43 +00:00
|
|
|
|
|
|
|
nsRefPtr<nsIPrincipal> mPrincipal;
|
|
|
|
nsRefPtr<nsIPrincipal> mTopLevelPrincipal;
|
|
|
|
|
2014-06-06 20:52:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_mediakeys_h__
|