1<html> 2<head> 3<title>DRM Test</title> 4<script language="JavaScript"> 5 6function setup() { 7 if (location.hostname == 'tests' || location.hostname == 'localhost') 8 return; 9 10 alert('This page can only be run from tests or localhost.'); 11 12 // Disable all elements. 13 var elements = document.getElementById("form").elements; 14 for (var i = 0, element; element = elements[i++]; ) { 15 element.disabled = true; 16 } 17 18 doTest(); 19} 20 21// Based on DRM detection code from https://github.com/google/shaka-player 22function probeSupport() { 23 var tests = []; 24 var testKeySystems = [ 25 'org.w3.clearkey', 26 'com.widevine.alpha', 27 ]; 28 29 var basicVideoCapabilities = [ 30 { contentType: 'video/mp4; codecs="avc1.42E01E"' }, 31 { contentType: 'video/webm; codecs="vp9"' } 32 ]; 33 34 var basicConfig = { 35 videoCapabilities: basicVideoCapabilities 36 }; 37 var offlineConfig = { 38 videoCapabilities: basicVideoCapabilities, 39 persistentState: 'required', 40 sessionTypes: ['persistent-license'] 41 }; 42 43 // Try the offline config first, then fall back to the basic config. 44 var configs = [offlineConfig, basicConfig]; 45 46 var support = {}; 47 testKeySystems.forEach(function(keySystem) { 48 var p = navigator.requestMediaKeySystemAccess(keySystem, configs) 49 .then(function(access) { 50 // We can't (yet) trust every browser to report the session types they 51 // support in access.getConfiguration(). Therefore, we create a 52 // MediaKeys object and try to create an offline session. 53 // https://goo.gl/gtYT3z, https://goo.gl/rvnB1g, https://goo.gl/z0URJ0 54 var mediaKeys = access.createMediaKeys(); 55 var persistentState = false; 56 try { 57 // This will throw if persistent licenses are not supported. 58 mediaKeys.createSession('persistent-license'); 59 persistentState = true; 60 } catch (e) {} 61 62 support[keySystem] = {persistentState: persistentState}; 63 }, function() { 64 support[keySystem] = null; 65 }); 66 tests.push(p); 67 }); 68 69 return Promise.all(tests).then(function() { 70 return support; 71 }); 72} 73 74function getWidevineCdmInfo() { 75 if (!('Widevine Content Decryption Module' in navigator.plugins)) { 76 return "Widevine CDM plugin not loaded."; 77 } 78 79 var plugin = navigator.plugins['Widevine Content Decryption Module']; 80 return "Widevine CDM plugin:\n" + JSON.stringify({ 81 "name": plugin.name, 82 "filename": plugin.filename, 83 "description": plugin.description, 84 }, null, ' ') 85} 86 87function printSupport(support) { 88 var output = document.getElementById('output'); 89 output.textContent = getWidevineCdmInfo() + "\n\nDRM Support:\n" + support; 90} 91 92function doTest() { 93 probeSupport().then(function(support) { 94 printSupport(JSON.stringify(support, null, ' ')); 95 }); 96} 97 98// Send a message to the browser process. 99function sendMessage() { 100 // Create the request object. 101 var request = {}; 102 request.widevine_cdm_path = 103 document.getElementById("widevine_cdm_path").value; 104 105 // Results in a call to the OnQuery method in drm_test.cc 106 window.cefQuery({ 107 request: JSON.stringify(request), 108 onSuccess: function(response) { 109 alert('Widevine CDM plugin loaded successfully!'); 110 // Registration succeeded so test again. 111 doTest(); 112 }, 113 onFailure: function(error_code, error_message) { 114 alert(error_message + ' (' + error_code + ')'); 115 } 116 }); 117} 118 119</script> 120 121</head> 122<body bgcolor="white" onload="setup()"> 123Important notes: 124<ul> 125<li>Clearkey support is built in and should always be enabled.</li> 126<li>Widevine support requires CDM binaries that must be downloaded from Google. Contact Google <a href="https://www.widevine.com/contact.html">here</a> for details.</li> 127<li>Widevine support is enabled by calling the CefRegisterWidevineCdm() function. See comments in cef_web_plugin.h for usage.</li> 128<li>The CefRegisterWidevineCdm() function can be called during runtime on Windows and OS X to register Widevine binaries. Use the below form to test this capability.</li> 129<li>Calling CefRegisterWidevineCdm() before CefInitialize() is required on Linux.</li> 130<li>Cefclient will call CefRegisterWidevineCdm() before CefInitialize() if "--widevine-cdm-path=<path>" is specified on the command-line.</li> 131<li>View extended media support information <a href="https://shaka-player-demo.appspot.com/support.html">here</a>.</li> 132<li>Test DRM video playback <a href="https://shaka-player-demo.appspot.com/demo/">here</a>. Select an "asset" that includes Clearkey or Widevine in the name.</li> 133</ul> 134 135<form id="form"> 136Widevine CDM Path: <input type="text" id="widevine_cdm_path" value="" size="40"> 137<input type="button" onclick="sendMessage();" value="Load CDM"> 138</form> 139<pre id="output"></pre> 140</body> 141</html> 142