Home | History | Annotate | Download | only in media
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
      6 #define CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/callback.h"
     13 #include "base/memory/ref_counted.h"
     14 #include "base/memory/weak_ptr.h"
     15 #include "media/base/media_keys.h"
     16 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h"
     17 #include "third_party/WebKit/public/platform/WebString.h"
     18 
     19 namespace media {
     20 class MediaKeys;
     21 }
     22 
     23 namespace content {
     24 class CdmSessionAdapter;
     25 
     26 class WebContentDecryptionModuleSessionImpl
     27     : public blink::WebContentDecryptionModuleSession {
     28  public:
     29   WebContentDecryptionModuleSessionImpl(
     30       Client* client,
     31       const scoped_refptr<CdmSessionAdapter>& adapter);
     32   virtual ~WebContentDecryptionModuleSessionImpl();
     33 
     34   // blink::WebContentDecryptionModuleSession implementation.
     35   virtual blink::WebString sessionId() const;
     36   virtual void initializeNewSession(const blink::WebString& mime_type,
     37                                     const uint8* init_data,
     38                                     size_t init_data_length);
     39   virtual void update(const uint8* response, size_t response_length);
     40   virtual void release();
     41 
     42   // Callbacks.
     43   void OnSessionMessage(const std::vector<uint8>& message,
     44                         const GURL& destination_url);
     45   void OnSessionReady();
     46   void OnSessionClosed();
     47   void OnSessionError(media::MediaKeys::Exception exception_code,
     48                       uint32 system_code,
     49                       const std::string& error_message);
     50 
     51  private:
     52   void SessionCreated(const std::string& web_session_id);
     53 
     54   scoped_refptr<CdmSessionAdapter> adapter_;
     55 
     56   // Non-owned pointer.
     57   Client* client_;
     58 
     59   // Web session ID is the app visible ID for this session generated by the CDM.
     60   // This value is not set until the CDM resolves the initializeNewSession()
     61   // promise.
     62   std::string web_session_id_;
     63 
     64   // Don't pass more than 1 close() event to blink::
     65   // TODO(jrummell): Remove this once blink tests handle close() promise and
     66   // closed() event.
     67   bool is_closed_;
     68 
     69   // Since promises will live until they are fired, use a weak reference when
     70   // creating a promise in case this class disappears before the promise
     71   // actually fires.
     72   base::WeakPtrFactory<WebContentDecryptionModuleSessionImpl> weak_ptr_factory_;
     73 
     74   DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl);
     75 };
     76 
     77 }  // namespace content
     78 
     79 #endif  // CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
     80