#include "third_party/blink/renderer/modules/encryptedmedia/media_key_session.h"
#include <cmath>
#include <limits>
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/numerics/safe_conversions.h"
#include "encrypted_media_utils.h"
#include "media/base/content_decryption_module.h"
#include "media/base/eme_constants.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_content_decryption_module.h"
#include "third_party/blink/public/platform/web_content_decryption_module_exception.h"
#include "third_party/blink/public/platform/web_content_decryption_module_session.h"
#include "third_party/blink/public/platform/web_encrypted_media_key_information.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable_creation_key.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/dom/events/event_queue.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/modules/encryptedmedia/content_decryption_module_result_promise.h"
#include "third_party/blink/renderer/modules/encryptedmedia/encrypted_media_utils.h"
#include "third_party/blink/renderer/modules/encryptedmedia/media_key_message_event.h"
#include "third_party/blink/renderer/modules/encryptedmedia/media_keys.h"
#include "third_party/blink/renderer/platform/bindings/dom_wrapper_world.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/content_decryption_module_result.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/instance_counters.h"
#include "third_party/blink/renderer/platform/network/mime/content_type.h"
#include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/wtf/text/ascii_ctype.h"
#define MEDIA_KEY_SESSION_LOG_LEVEL …
namespace {
enum { … };
}
namespace blink {
static bool IsValidSessionId(const String& session_id) { … }
static bool IsPersistentSessionType(WebEncryptedMediaSessionType session_type) { … }
V8MediaKeySessionClosedReason::Enum ConvertSessionClosedReason(
media::CdmSessionClosedReason reason) { … }
static ScriptPromise<IDLUndefined> CreateRejectedPromiseNotCallable(
ExceptionState& exception_state) { … }
static void ThrowAlreadyClosed(ExceptionState& exception_state) { … }
static void ThrowAlreadyInitialized(ExceptionState& exception_state) { … }
class MediaKeySession::PendingAction final
: public GarbageCollected<MediaKeySession::PendingAction> { … };
class NewSessionResultPromise : public ContentDecryptionModuleResultPromise { … };
class LoadSessionResultPromise : public ContentDecryptionModuleResultPromise { … };
class CloseSessionResultPromise : public ContentDecryptionModuleResultPromise { … };
class SimpleResultPromise : public ContentDecryptionModuleResultPromise { … };
MediaKeySession::MediaKeySession(ScriptState* script_state,
MediaKeys* media_keys,
WebEncryptedMediaSessionType session_type,
const MediaKeysConfig& config)
: … { … }
MediaKeySession::~MediaKeySession() { … }
void MediaKeySession::Dispose() { … }
String MediaKeySession::sessionId() const { … }
ScriptPromise<V8MediaKeySessionClosedReason> MediaKeySession::closed(
ScriptState* script_state) { … }
MediaKeyStatusMap* MediaKeySession::keyStatuses() { … }
ScriptPromise<IDLUndefined> MediaKeySession::generateRequest(
ScriptState* script_state,
const String& init_data_type_string,
const DOMArrayPiece& init_data,
ExceptionState& exception_state) { … }
void MediaKeySession::GenerateRequestTask(ContentDecryptionModuleResult* result,
media::EmeInitDataType init_data_type,
DOMArrayBuffer* init_data_buffer) { … }
void MediaKeySession::FinishGenerateRequest() { … }
ScriptPromise<IDLBoolean> MediaKeySession::load(
ScriptState* script_state,
const String& session_id,
ExceptionState& exception_state) { … }
void MediaKeySession::LoadTask(ContentDecryptionModuleResult* result,
const String& session_id) { … }
void MediaKeySession::FinishLoad() { … }
ScriptPromise<IDLUndefined> MediaKeySession::update(
ScriptState* script_state,
const DOMArrayPiece& response,
ExceptionState& exception_state) { … }
void MediaKeySession::UpdateTask(ContentDecryptionModuleResult* result,
DOMArrayBuffer* sanitized_response) { … }
ScriptPromise<IDLUndefined> MediaKeySession::close(
ScriptState* script_state,
ExceptionState& exception_state) { … }
void MediaKeySession::CloseTask(ContentDecryptionModuleResult* result) { … }
void MediaKeySession::OnClosePromiseResolved() { … }
ScriptPromise<IDLUndefined> MediaKeySession::remove(
ScriptState* script_state,
ExceptionState& exception_state) { … }
void MediaKeySession::RemoveTask(ContentDecryptionModuleResult* result) { … }
void MediaKeySession::ActionTimerFired(TimerBase*) { … }
void MediaKeySession::OnSessionMessage(media::CdmMessageType message_type,
const unsigned char* message,
size_t message_length) { … }
void MediaKeySession::OnSessionClosed(media::CdmSessionClosedReason reason) { … }
void MediaKeySession::OnSessionExpirationUpdate(
double updated_expiry_time_in_ms) { … }
void MediaKeySession::OnSessionKeysChange(
const WebVector<WebEncryptedMediaKeyInformation>& keys,
bool has_additional_usable_key) { … }
const AtomicString& MediaKeySession::InterfaceName() const { … }
ExecutionContext* MediaKeySession::GetExecutionContext() const { … }
bool MediaKeySession::HasPendingActivity() const { … }
void MediaKeySession::ContextDestroyed() { … }
void MediaKeySession::Trace(Visitor* visitor) const { … }
}