blob: bf33d066dbc7ade983b55f9cf79c5fb82a41c625 [file] [log] [blame]
// Copyright 2013 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.
#ifndef COBALT_MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
#define COBALT_MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "cobalt/media/base/media_keys.h"
#include "cobalt/media/blink/new_session_cdm_result_promise.h"
#include "starboard/types.h"
#include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h"
#include "third_party/WebKit/public/platform/WebString.h"
namespace cobalt {
namespace media {
class CdmSessionAdapter;
class MediaKeys;
class WebContentDecryptionModuleSessionImpl
: public blink::WebContentDecryptionModuleSession {
public:
WebContentDecryptionModuleSessionImpl(
const scoped_refptr<CdmSessionAdapter>& adapter);
~WebContentDecryptionModuleSessionImpl() OVERRIDE;
// blink::WebContentDecryptionModuleSession implementation.
void setClientInterface(Client* client) OVERRIDE;
blink::WebString sessionId() const OVERRIDE;
void initializeNewSession(
blink::WebEncryptedMediaInitDataType init_data_type,
const unsigned char* initData, size_t initDataLength,
blink::WebEncryptedMediaSessionType session_type,
blink::WebContentDecryptionModuleResult result) OVERRIDE;
void load(const blink::WebString& session_id,
blink::WebContentDecryptionModuleResult result) OVERRIDE;
void update(const uint8_t* response, size_t response_length,
blink::WebContentDecryptionModuleResult result) OVERRIDE;
void close(blink::WebContentDecryptionModuleResult result) OVERRIDE;
void remove(blink::WebContentDecryptionModuleResult result) OVERRIDE;
// Callbacks.
void OnSessionMessage(MediaKeys::MessageType message_type,
const std::vector<uint8_t>& message);
void OnSessionKeysChange(bool has_additional_usable_key,
CdmKeysInfo keys_info);
void OnSessionExpirationUpdate(const base::Time& new_expiry_time);
void OnSessionClosed();
private:
// Called when a new session is created or loaded. |status| is set as
// appropriate, depending on whether the session already exists or not.
void OnSessionInitialized(const std::string& session_id,
SessionInitStatus* status);
scoped_refptr<CdmSessionAdapter> adapter_;
// Non-owned pointer.
Client* client_;
// Session ID is the app visible ID for this session generated by the CDM.
// This value is not set until the CDM resolves the initializeNewSession()
// promise.
std::string session_id_;
// Don't pass more than 1 close() event to blink::
// TODO(jrummell): Remove this once blink tests handle close() promise and
// closed() event.
bool is_closed_;
base::ThreadChecker thread_checker_;
// Since promises will live until they are fired, use a weak reference when
// creating a promise in case this class disappears before the promise
// actually fires.
base::WeakPtrFactory<WebContentDecryptionModuleSessionImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl);
};
} // namespace media
} // namespace cobalt
#endif // COBALT_MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_