Home | History | Annotate | Download | only in crypto
      1 // Copyright 2014 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_CRYPTO_PEPPER_CDM_WRAPPER_IMPL_H_
      6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PEPPER_CDM_WRAPPER_IMPL_H_
      7 
      8 #if !defined(ENABLE_PEPPER_CDMS)
      9 #error This file should only be included when ENABLE_PEPPER_CDMS is defined
     10 #endif
     11 
     12 #include "base/callback.h"
     13 #include "base/memory/ref_counted.h"
     14 #include "base/memory/scoped_ptr.h"
     15 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h"
     16 
     17 namespace blink {
     18 class WebHelperPlugin;
     19 class WebLocalFrame;
     20 }
     21 
     22 namespace content {
     23 
     24 class ContentDecryptorDelegate;
     25 class PepperPluginInstanceImpl;
     26 
     27 // Deleter for blink::WebHelperPlugin.
     28 struct WebHelperPluginDeleter {
     29   void operator()(blink::WebHelperPlugin* plugin) const;
     30 };
     31 
     32 // Implements a wrapper on blink::WebHelperPlugin so that the plugin gets
     33 // destroyed properly. It owns all the objects derived from WebHelperPlugin
     34 // (WebPlugin, PepperPluginInstanceImpl, ContentDecryptionDelegate), and will
     35 // free them as necessary when this wrapper is destroyed. In particular, it
     36 // takes a reference to PepperPluginInstanceImpl so it won't go away until
     37 // this object is destroyed.
     38 //
     39 // Implemented so that lower layers in Chromium don't need to be aware of
     40 // blink:: objects.
     41 class PepperCdmWrapperImpl : public PepperCdmWrapper {
     42  public:
     43   static scoped_ptr<PepperCdmWrapper> Create(blink::WebLocalFrame* frame,
     44                                              const std::string& pluginType,
     45                                              const GURL& security_origin);
     46 
     47   virtual ~PepperCdmWrapperImpl();
     48 
     49   // Returns the ContentDecryptorDelegate* associated with this plugin.
     50   virtual ContentDecryptorDelegate* GetCdmDelegate() OVERRIDE;
     51 
     52  private:
     53   typedef scoped_ptr<blink::WebHelperPlugin, WebHelperPluginDeleter>
     54       ScopedHelperPlugin;
     55 
     56   // Takes ownership of |helper_plugin| and |plugin_instance|.
     57   PepperCdmWrapperImpl(
     58       ScopedHelperPlugin helper_plugin,
     59       const scoped_refptr<PepperPluginInstanceImpl>& plugin_instance);
     60 
     61   ScopedHelperPlugin helper_plugin_;
     62   scoped_refptr<PepperPluginInstanceImpl> plugin_instance_;
     63 
     64   DISALLOW_COPY_AND_ASSIGN(PepperCdmWrapperImpl);
     65 };
     66 
     67 }  // namespace content
     68 
     69 #endif  // CONTENT_RENDERER_MEDIA_CRYPTO_PEPPER_CDM_WRAPPER_IMPL_H_
     70