Update V8 to version 4.6.61.
[chromium-blink-merge.git] / content / public / browser / media_device_id.cc
blobc8e5f235999f560ba3ac86a593961eee1a91dc3f
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 #include "content/public/browser/media_device_id.h"
6 #include "base/logging.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h"
9 #include "content/browser/browser_main_loop.h"
10 #include "content/browser/renderer_host/media/media_stream_manager.h"
11 #include "crypto/hmac.h"
13 namespace content {
15 std::string GetHMACForMediaDeviceID(const ResourceContext::SaltCallback& sc,
16 const GURL& security_origin,
17 const std::string& raw_unique_id) {
18 DCHECK(security_origin.is_valid());
19 DCHECK(!raw_unique_id.empty());
20 crypto::HMAC hmac(crypto::HMAC::SHA256);
21 const size_t digest_length = hmac.DigestLength();
22 std::vector<uint8> digest(digest_length);
23 std::string salt = sc.Run();
24 bool result = hmac.Init(security_origin.spec()) &&
25 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size());
26 DCHECK(result);
27 return base::StringToLowerASCII(base::HexEncode(&digest[0], digest.size()));
30 bool DoesMediaDeviceIDMatchHMAC(const ResourceContext::SaltCallback& sc,
31 const GURL& security_origin,
32 const std::string& device_guid,
33 const std::string& raw_unique_id) {
34 DCHECK(security_origin.is_valid());
35 DCHECK(!raw_unique_id.empty());
36 std::string guid_from_raw_device_id =
37 GetHMACForMediaDeviceID(sc, security_origin, raw_unique_id);
38 return guid_from_raw_device_id == device_guid;
41 bool GetMediaDeviceIDForHMAC(MediaStreamType stream_type,
42 const ResourceContext::SaltCallback& rc,
43 const GURL& security_origin,
44 const std::string& source_id,
45 std::string* device_id) {
46 content::MediaStreamManager* manager =
47 content::BrowserMainLoop::GetInstance()->media_stream_manager();
49 return manager->TranslateSourceIdToDeviceId(
50 content::MEDIA_DEVICE_VIDEO_CAPTURE,
51 rc,
52 security_origin,
53 source_id,
54 device_id);
57 } // namespace content