Commit c60852ce authored by Vi Nguyen's avatar Vi Nguyen Committed by Commit Bot

Pass MediaKeySessionType in createSession()

Courtesy of jrummell's TODO: Now that there are 2 types of persistent
sessions, the session type should be passed from blink. Type should also
be passed in the constructor (and removed from initializeNewSession()).

Bug: 1085463
Change-Id: Ic6f5f496d7f696d1563c0af0c80e42c8d54ec060
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212685Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Commit-Queue: Vi Nguyen <ving@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#771612}
parent 09baa4da
...@@ -76,8 +76,10 @@ void CdmSessionAdapter::GetStatusForPolicy( ...@@ -76,8 +76,10 @@ void CdmSessionAdapter::GetStatusForPolicy(
} }
std::unique_ptr<WebContentDecryptionModuleSessionImpl> std::unique_ptr<WebContentDecryptionModuleSessionImpl>
CdmSessionAdapter::CreateSession() { CdmSessionAdapter::CreateSession(
return std::make_unique<WebContentDecryptionModuleSessionImpl>(this); blink::WebEncryptedMediaSessionType session_type) {
return std::make_unique<WebContentDecryptionModuleSessionImpl>(this,
session_type);
} }
bool CdmSessionAdapter::RegisterSession( bool CdmSessionAdapter::RegisterSession(
......
...@@ -60,7 +60,8 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { ...@@ -60,7 +60,8 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> {
// Creates a new session and adds it to the internal map. RemoveSession() // Creates a new session and adds it to the internal map. RemoveSession()
// must be called when destroying it, if RegisterSession() was called. // must be called when destroying it, if RegisterSession() was called.
std::unique_ptr<WebContentDecryptionModuleSessionImpl> CreateSession(); std::unique_ptr<WebContentDecryptionModuleSessionImpl> CreateSession(
blink::WebEncryptedMediaSessionType session_type);
// Adds a session to the internal map. Called once the session is successfully // Adds a session to the internal map. Called once the session is successfully
// initialized. Returns true if the session was registered, false if there is // initialized. Returns true if the session was registered, false if there is
......
...@@ -119,8 +119,9 @@ WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( ...@@ -119,8 +119,9 @@ WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl(
WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() = default; WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() = default;
std::unique_ptr<blink::WebContentDecryptionModuleSession> std::unique_ptr<blink::WebContentDecryptionModuleSession>
WebContentDecryptionModuleImpl::CreateSession() { WebContentDecryptionModuleImpl::CreateSession(
return adapter_->CreateSession(); blink::WebEncryptedMediaSessionType session_type) {
return adapter_->CreateSession(session_type);
} }
void WebContentDecryptionModuleImpl::SetServerCertificate( void WebContentDecryptionModuleImpl::SetServerCertificate(
......
...@@ -46,8 +46,8 @@ class MEDIA_BLINK_EXPORT WebContentDecryptionModuleImpl ...@@ -46,8 +46,8 @@ class MEDIA_BLINK_EXPORT WebContentDecryptionModuleImpl
~WebContentDecryptionModuleImpl() override; ~WebContentDecryptionModuleImpl() override;
// blink::WebContentDecryptionModule implementation. // blink::WebContentDecryptionModule implementation.
std::unique_ptr<blink::WebContentDecryptionModuleSession> CreateSession() std::unique_ptr<blink::WebContentDecryptionModuleSession> CreateSession(
override; blink::WebEncryptedMediaSessionType session_type) override;
void SetServerCertificate( void SetServerCertificate(
const uint8_t* server_certificate, const uint8_t* server_certificate,
size_t server_certificate_length, size_t server_certificate_length,
......
...@@ -226,11 +226,12 @@ class IgnoreResponsePromise : public SimpleCdmPromise { ...@@ -226,11 +226,12 @@ class IgnoreResponsePromise : public SimpleCdmPromise {
} // namespace } // namespace
WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
const scoped_refptr<CdmSessionAdapter>& adapter) const scoped_refptr<CdmSessionAdapter>& adapter,
blink::WebEncryptedMediaSessionType session_type)
: adapter_(adapter), : adapter_(adapter),
session_type_(convertSessionType(session_type)),
has_close_been_called_(false), has_close_been_called_(false),
is_closed_(false), is_closed_(false) {}
is_persistent_session_(false) {}
WebContentDecryptionModuleSessionImpl:: WebContentDecryptionModuleSessionImpl::
~WebContentDecryptionModuleSessionImpl() { ~WebContentDecryptionModuleSessionImpl() {
...@@ -269,7 +270,6 @@ void WebContentDecryptionModuleSessionImpl::InitializeNewSession( ...@@ -269,7 +270,6 @@ void WebContentDecryptionModuleSessionImpl::InitializeNewSession(
EmeInitDataType eme_init_data_type, EmeInitDataType eme_init_data_type,
const unsigned char* init_data, const unsigned char* init_data,
size_t init_data_length, size_t init_data_length,
blink::WebEncryptedMediaSessionType session_type,
blink::WebContentDecryptionModuleResult result) { blink::WebContentDecryptionModuleResult result) {
DCHECK(init_data); DCHECK(init_data);
DCHECK(session_id_.empty()); DCHECK(session_id_.empty());
...@@ -334,10 +334,8 @@ void WebContentDecryptionModuleSessionImpl::InitializeNewSession( ...@@ -334,10 +334,8 @@ void WebContentDecryptionModuleSessionImpl::InitializeNewSession(
// 10.8 Let cdm be the CDM instance represented by this object's cdm // 10.8 Let cdm be the CDM instance represented by this object's cdm
// instance value. // instance value.
// 10.9 Use the cdm to execute the following steps: // 10.9 Use the cdm to execute the following steps:
CdmSessionType cdm_session_type = convertSessionType(session_type);
is_persistent_session_ = cdm_session_type != CdmSessionType::kTemporary;
adapter_->InitializeNewSession( adapter_->InitializeNewSession(
eme_init_data_type, sanitized_init_data, cdm_session_type, eme_init_data_type, sanitized_init_data, session_type_,
std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise(
result, adapter_->GetKeySystemUMAPrefix(), kGenerateRequestUMAName, result, adapter_->GetKeySystemUMAPrefix(), kGenerateRequestUMAName,
base::BindOnce( base::BindOnce(
...@@ -352,6 +350,8 @@ void WebContentDecryptionModuleSessionImpl::Load( ...@@ -352,6 +350,8 @@ void WebContentDecryptionModuleSessionImpl::Load(
DCHECK(!session_id.IsEmpty()); DCHECK(!session_id.IsEmpty());
DCHECK(session_id_.empty()); DCHECK(session_id_.empty());
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(session_type_ == CdmSessionType::kPersistentLicense ||
session_type_ == CdmSessionType::kPersistentUsageRecord);
// From https://w3c.github.io/encrypted-media/#load. // From https://w3c.github.io/encrypted-media/#load.
// 8.1 Let sanitized session ID be a validated and/or sanitized version of // 8.1 Let sanitized session ID be a validated and/or sanitized version of
...@@ -368,12 +368,8 @@ void WebContentDecryptionModuleSessionImpl::Load( ...@@ -368,12 +368,8 @@ void WebContentDecryptionModuleSessionImpl::Load(
return; return;
} }
// TODO(jrummell): Now that there are 2 types of persistent sessions, the
// session type should be passed from blink. Type should also be passed in the
// constructor (and removed from initializeNewSession()).
is_persistent_session_ = true;
adapter_->LoadSession( adapter_->LoadSession(
CdmSessionType::kPersistentLicense, sanitized_session_id, session_type_, sanitized_session_id,
std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise(
result, adapter_->GetKeySystemUMAPrefix(), kLoadSessionUMAName, result, adapter_->GetKeySystemUMAPrefix(), kLoadSessionUMAName,
base::BindOnce( base::BindOnce(
......
...@@ -29,7 +29,8 @@ class WebContentDecryptionModuleSessionImpl ...@@ -29,7 +29,8 @@ class WebContentDecryptionModuleSessionImpl
: public blink::WebContentDecryptionModuleSession { : public blink::WebContentDecryptionModuleSession {
public: public:
WebContentDecryptionModuleSessionImpl( WebContentDecryptionModuleSessionImpl(
const scoped_refptr<CdmSessionAdapter>& adapter); const scoped_refptr<CdmSessionAdapter>& adapter,
blink::WebEncryptedMediaSessionType session_type);
~WebContentDecryptionModuleSessionImpl() override; ~WebContentDecryptionModuleSessionImpl() override;
// blink::WebContentDecryptionModuleSession implementation. // blink::WebContentDecryptionModuleSession implementation.
...@@ -40,7 +41,6 @@ class WebContentDecryptionModuleSessionImpl ...@@ -40,7 +41,6 @@ class WebContentDecryptionModuleSessionImpl
EmeInitDataType init_data_type, EmeInitDataType init_data_type,
const unsigned char* initData, const unsigned char* initData,
size_t initDataLength, size_t initDataLength,
blink::WebEncryptedMediaSessionType session_type,
blink::WebContentDecryptionModuleResult result) override; blink::WebContentDecryptionModuleResult result) override;
void Load(const blink::WebString& session_id, void Load(const blink::WebString& session_id,
blink::WebContentDecryptionModuleResult result) override; blink::WebContentDecryptionModuleResult result) override;
...@@ -66,6 +66,10 @@ class WebContentDecryptionModuleSessionImpl ...@@ -66,6 +66,10 @@ class WebContentDecryptionModuleSessionImpl
scoped_refptr<CdmSessionAdapter> adapter_; scoped_refptr<CdmSessionAdapter> adapter_;
// Keep track of the session type to be passed into InitializeNewSession() and
// LoadSession().
const CdmSessionType session_type_;
// Non-owned pointer. // Non-owned pointer.
Client* client_; Client* client_;
...@@ -84,9 +88,6 @@ class WebContentDecryptionModuleSessionImpl ...@@ -84,9 +88,6 @@ class WebContentDecryptionModuleSessionImpl
bool has_close_been_called_; bool has_close_been_called_;
bool is_closed_; bool is_closed_;
// Keep track of whether this is a persistent session or not.
bool is_persistent_session_;
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
// Since promises will live until they are fired, use a weak reference when // Since promises will live until they are fired, use a weak reference when
// creating a promise in case this class disappears before the promise // creating a promise in case this class disappears before the promise
......
...@@ -43,8 +43,8 @@ class BLINK_PLATFORM_EXPORT WebContentDecryptionModule { ...@@ -43,8 +43,8 @@ class BLINK_PLATFORM_EXPORT WebContentDecryptionModule {
virtual ~WebContentDecryptionModule(); virtual ~WebContentDecryptionModule();
// Must return non-null. // Must return non-null.
virtual std::unique_ptr<WebContentDecryptionModuleSession> virtual std::unique_ptr<WebContentDecryptionModuleSession> CreateSession(
CreateSession() = 0; WebEncryptedMediaSessionType session_type) = 0;
virtual void SetServerCertificate(const unsigned char* certificate, virtual void SetServerCertificate(const unsigned char* certificate,
size_t certificate_length, size_t certificate_length,
......
...@@ -88,7 +88,6 @@ class BLINK_PLATFORM_EXPORT WebContentDecryptionModuleSession { ...@@ -88,7 +88,6 @@ class BLINK_PLATFORM_EXPORT WebContentDecryptionModuleSession {
virtual void InitializeNewSession(media::EmeInitDataType, virtual void InitializeNewSession(media::EmeInitDataType,
const unsigned char* init_data, const unsigned char* init_data,
size_t init_data_length, size_t init_data_length,
WebEncryptedMediaSessionType,
WebContentDecryptionModuleResult) = 0; WebContentDecryptionModuleResult) = 0;
virtual void Load(const WebString& session_id, virtual void Load(const WebString& session_id,
WebContentDecryptionModuleResult) = 0; WebContentDecryptionModuleResult) = 0;
......
...@@ -355,7 +355,7 @@ MediaKeySession::MediaKeySession(ScriptState* script_state, ...@@ -355,7 +355,7 @@ MediaKeySession::MediaKeySession(ScriptState* script_state,
// initializeNewSession() is called in response to the user calling // initializeNewSession() is called in response to the user calling
// generateRequest(). // generateRequest().
WebContentDecryptionModule* cdm = media_keys->ContentDecryptionModule(); WebContentDecryptionModule* cdm = media_keys->ContentDecryptionModule();
session_ = cdm->CreateSession(); session_ = cdm->CreateSession(session_type);
session_->SetClientInterface(this); session_->SetClientInterface(this);
// From https://w3c.github.io/encrypted-media/#createSession: // From https://w3c.github.io/encrypted-media/#createSession:
...@@ -501,7 +501,7 @@ void MediaKeySession::GenerateRequestTask(ContentDecryptionModuleResult* result, ...@@ -501,7 +501,7 @@ void MediaKeySession::GenerateRequestTask(ContentDecryptionModuleResult* result,
// initializeNewSession() in Chromium will execute steps 10.1 to 10.9. // initializeNewSession() in Chromium will execute steps 10.1 to 10.9.
session_->InitializeNewSession( session_->InitializeNewSession(
init_data_type, static_cast<unsigned char*>(init_data_buffer->Data()), init_data_type, static_cast<unsigned char*>(init_data_buffer->Data()),
init_data_buffer->ByteLengthAsSizeT(), session_type_, result->Result()); init_data_buffer->ByteLengthAsSizeT(), result->Result());
// Remaining steps (10.10) executed in finishGenerateRequest(), // Remaining steps (10.10) executed in finishGenerateRequest(),
// called when |result| is resolved. // called when |result| is resolved.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment