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 function sendCommand(cmd) { 6 window.domAutomationController.setAutomationId(1); 7 window.domAutomationController.send(cmd); 8 } 9 10 function makeImageSet(url1x, url2x) { 11 return '-webkit-image-set(url(' + url1x + ') 1x, url(' + url2x + ') 2x)'; 12 } 13 14 function initialize() { 15 if (loadTimeData.getBoolean('allowAccessRequests')) { 16 $('request-access-button').onclick = function(event) { 17 updateAfterRequestSent(); 18 sendCommand('request'); 19 }; 20 } else { 21 $('request-access-button').hidden = true; 22 } 23 var avatarURL1x = loadTimeData.getString('avatarURL1x'); 24 var avatarURL2x = loadTimeData.getString('avatarURL2x'); 25 if (avatarURL1x) { 26 $('avatar-img').style.content = makeImageSet(avatarURL1x, avatarURL2x); 27 $('avatar-img').hidden = false; 28 $('error-img').hidden = true; 29 var secondAvatarURL1x = loadTimeData.getString('secondAvatarURL1x'); 30 var secondAvatarURL2x = loadTimeData.getString('secondAvatarURL2x'); 31 if (secondAvatarURL1x) { 32 $('second-avatar-img').style.content = 33 makeImageSet(secondAvatarURL1x, secondAvatarURL2x); 34 $('second-avatar-img').hidden = false; 35 // The avatar images should overlap a bit. 36 $('avatar-img').style.left = '10px'; 37 $('avatar-img').style.zIndex = '1'; 38 $('second-avatar-img').style.left = '-10px'; 39 } 40 } 41 $('back-button').onclick = function(event) { 42 sendCommand('back'); 43 }; 44 } 45 46 /** 47 * Updates the interstitial to show that the request was sent. 48 */ 49 function updateAfterRequestSent() { 50 $('error-img').hidden = true; 51 $('request-access-button').hidden = true; 52 $('block-page-message').hidden = true; 53 $('request-sent-message').hidden = false; 54 if ($('avatar-img').hidden) { 55 $('request-sent-message').style.marginTop = '40px'; 56 } 57 } 58 59 document.addEventListener('DOMContentLoaded', initialize); 60