summaryrefslogtreecommitdiffstats
path: root/media/blink/webencryptedmediaclient_impl.h
blob: 5a1f3e4a040817b7ccdb8835be21ad466e0cc648 (plain)
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
// 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.

#ifndef MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_
#define MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_

#include <string>

#include "base/containers/scoped_ptr_hash_map.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "media/base/media_export.h"
#include "media/blink/key_system_config_selector.h"
#include "third_party/WebKit/public/platform/WebEncryptedMediaClient.h"

namespace blink {

class WebContentDecryptionModuleResult;
struct WebMediaKeySystemConfiguration;
class WebSecurityOrigin;

}  // namespace blink

namespace media {

class CdmFactory;
class KeySystems;
class MediaPermission;

class MEDIA_EXPORT WebEncryptedMediaClientImpl
    : public blink::WebEncryptedMediaClient {
 public:
  WebEncryptedMediaClientImpl(CdmFactory* cdm_factory,
                              MediaPermission* media_permission);
  virtual ~WebEncryptedMediaClientImpl();

  // WebEncryptedMediaClient implementation.
  virtual void requestMediaKeySystemAccess(
      blink::WebEncryptedMediaRequest request);

  // Create the CDM for |key_system| and |security_origin|. The caller owns
  // the created cdm (passed back using |result|).
  void CreateCdm(const blink::WebString& key_system,
                 bool allow_distinctive_identifier,
                 bool allow_persistent_state,
                 const blink::WebSecurityOrigin& security_origin,
                 blink::WebContentDecryptionModuleResult result);

 private:
  // Report usage of key system to UMA. There are 2 different counts logged:
  // 1. The key system is requested.
  // 2. The requested key system and options are supported.
  // Each stat is only reported once per renderer frame per key system.
  class Reporter;

  // Complete a requestMediaKeySystemAccess() request with a supported
  // accumulated configuration.
  void OnRequestSucceeded(
      blink::WebEncryptedMediaRequest request,
      const blink::WebMediaKeySystemConfiguration& accumulated_configuration);

  // Complete a requestMediaKeySystemAccess() request with an error message.
  void OnRequestNotSupported(blink::WebEncryptedMediaRequest request,
                             const blink::WebString& error_message);

  // Gets the Reporter for |key_system|. If it doesn't already exist,
  // create one.
  Reporter* GetReporter(const blink::WebString& key_system);

  // Reporter singletons.
  base::ScopedPtrHashMap<std::string, scoped_ptr<Reporter>> reporters_;

  CdmFactory* cdm_factory_;
  KeySystemConfigSelector key_system_config_selector_;
  base::WeakPtrFactory<WebEncryptedMediaClientImpl> weak_factory_;
};

}  // namespace media

#endif  // MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_