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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// 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.
#include "content/renderer/media/crypto/render_cdm_factory.h"
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "media/base/cdm_promise.h"
#include "media/base/key_systems.h"
#include "media/base/media_keys.h"
#include "media/cdm/aes_decryptor.h"
#include "url/gurl.h"
#if defined(ENABLE_PEPPER_CDMS)
#include "content/renderer/media/crypto/ppapi_decryptor.h"
#elif defined(ENABLE_BROWSER_CDMS)
#include "content/renderer/media/crypto/proxy_media_keys.h"
#endif // defined(ENABLE_PEPPER_CDMS)
namespace content {
RenderCdmFactory::RenderCdmFactory(
#if defined(ENABLE_PEPPER_CDMS)
const CreatePepperCdmCB& create_pepper_cdm_cb,
#elif defined(ENABLE_BROWSER_CDMS)
RendererCdmManager* manager,
#endif // defined(ENABLE_PEPPER_CDMS)
RenderFrame* render_frame)
: RenderFrameObserver(render_frame)
#if defined(ENABLE_PEPPER_CDMS)
, create_pepper_cdm_cb_(create_pepper_cdm_cb)
#elif defined(ENABLE_BROWSER_CDMS)
, manager_(manager)
#endif // defined(ENABLE_PEPPER_CDMS)
{
}
RenderCdmFactory::~RenderCdmFactory() {
DCHECK(thread_checker_.CalledOnValidThread());
}
void RenderCdmFactory::Create(
const std::string& key_system,
bool allow_distinctive_identifier,
bool allow_persistent_state,
const GURL& security_origin,
const media::SessionMessageCB& session_message_cb,
const media::SessionClosedCB& session_closed_cb,
const media::LegacySessionErrorCB& legacy_session_error_cb,
const media::SessionKeysChangeCB& session_keys_change_cb,
const media::SessionExpirationUpdateCB& session_expiration_update_cb,
const media::CdmCreatedCB& cdm_created_cb) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!security_origin.is_valid()) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(cdm_created_cb, nullptr, "Invalid origin."));
return;
}
if (media::CanUseAesDecryptor(key_system)) {
// TODO(sandersd): Currently the prefixed API always allows distinctive
// identifiers and persistent state. Once that changes we can sanity check
// here that neither is allowed for AesDecryptor, since it does not support
// them and should never be configured that way. http://crbug.com/455271
scoped_ptr<media::MediaKeys> cdm(
new media::AesDecryptor(security_origin, session_message_cb,
session_closed_cb, session_keys_change_cb));
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(cdm_created_cb, base::Passed(&cdm), ""));
return;
}
#if defined(ENABLE_PEPPER_CDMS)
PpapiDecryptor::Create(
key_system, allow_distinctive_identifier, allow_persistent_state,
security_origin, create_pepper_cdm_cb_, session_message_cb,
session_closed_cb, legacy_session_error_cb, session_keys_change_cb,
session_expiration_update_cb, cdm_created_cb);
#elif defined(ENABLE_BROWSER_CDMS)
DCHECK(allow_distinctive_identifier);
DCHECK(allow_persistent_state);
ProxyMediaKeys::Create(key_system, security_origin, manager_,
session_message_cb, session_closed_cb,
legacy_session_error_cb, session_keys_change_cb,
session_expiration_update_cb, cdm_created_cb);
#else
// No possible CDM to create, so fail the request.
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(cdm_created_cb, nullptr, "Key system not supported."));
#endif // defined(ENABLE_PEPPER_CDMS)
}
} // namespace content
|