1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h"
#include "bindings/core/v8/ScriptPromise.h"
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/DOMException.h"
#include "public/platform/WebString.h"
#include "wtf/Assertions.h"
namespace blink {
ExceptionCode WebCdmExceptionToExceptionCode(WebContentDecryptionModuleException cdmException)
{
switch (cdmException) {
case WebContentDecryptionModuleExceptionNotSupportedError:
return NotSupportedError;
case WebContentDecryptionModuleExceptionInvalidStateError:
return InvalidStateError;
case WebContentDecryptionModuleExceptionInvalidAccessError:
return InvalidAccessError;
case WebContentDecryptionModuleExceptionQuotaExceededError:
return QuotaExceededError;
case WebContentDecryptionModuleExceptionUnknownError:
return UnknownError;
case WebContentDecryptionModuleExceptionClientError:
case WebContentDecryptionModuleExceptionOutputError:
// Currently no matching DOMException for these 2 errors.
// FIXME: Update DOMException to handle these if actually added to
// the EME spec.
return UnknownError;
}
ASSERT_NOT_REACHED();
return UnknownError;
}
ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise(ScriptState* scriptState)
: m_resolver(ScriptPromiseResolver::create(scriptState))
{
}
ContentDecryptionModuleResultPromise::~ContentDecryptionModuleResultPromise()
{
}
void ContentDecryptionModuleResultPromise::complete()
{
ASSERT_NOT_REACHED();
reject(InvalidStateError, "Unexpected completion.");
}
void ContentDecryptionModuleResultPromise::completeWithContentDecryptionModule(WebContentDecryptionModule* cdm)
{
ASSERT_NOT_REACHED();
reject(InvalidStateError, "Unexpected completion.");
}
void ContentDecryptionModuleResultPromise::completeWithSession(WebContentDecryptionModuleResult::SessionStatus status)
{
ASSERT_NOT_REACHED();
reject(InvalidStateError, "Unexpected completion.");
}
void ContentDecryptionModuleResultPromise::completeWithError(WebContentDecryptionModuleException exceptionCode, unsigned long systemCode, const WebString& errorMessage)
{
// The error string is in the format of: OriginalMessage (systemCode)
String errorString = errorMessage;
errorString.append(" (" + String::number(systemCode) + ")");
reject(WebCdmExceptionToExceptionCode(exceptionCode), errorString);
}
ScriptPromise ContentDecryptionModuleResultPromise::promise()
{
return m_resolver->promise();
}
void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, const String& errorMessage)
{
m_resolver->reject(DOMException::create(code, errorMessage));
m_resolver.clear();
}
ExecutionContext* ContentDecryptionModuleResultPromise::executionContext() const
{
return m_resolver->executionContext();
}
void ContentDecryptionModuleResultPromise::trace(Visitor* visitor)
{
visitor->trace(m_resolver);
ContentDecryptionModuleResult::trace(visitor);
}
} // namespace blink
|