1// Copyright (c) 2011 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 5function closeDialog() { 6 chrome.send('DialogClose', ['']); 7} 8 9function setInfobarLabel(text) { 10 $('info-banner').textContent = text; 11 $('info-banner').hidden = !text.length; 12} 13 14function updateControlState() { 15 var allowedCookies = $('allowed-cookies'); 16 $('block-button').disabled = !allowedCookies.children.length || 17 !allowedCookies.selectedItem || 18 allowedCookies.selectedItem.data.type != 'origin'; 19 20 var blockedCookies = $('blocked-cookies'); 21 $('allow-button').disabled = 22 $('allow-this-session-button').disabled = !blockedCookies.children.length || 23 !blockedCookies.selectedItem || 24 blockedCookies.selectedItem.data.type != 'origin'; 25} 26 27function handleCookiesTreeChange(e) { 28 updateControlState(); 29} 30 31function handleBlockButtonClick(e) { 32 var selected = $('allowed-cookies').selectedItem; 33 if (!selected) 34 return; 35 36 chrome.send('Block', [selected.pathId]); 37} 38 39function handleAllowButtonClick(e) { 40 var selected = $('blocked-cookies').selectedItem; 41 if (selected) 42 chrome.send('Allow', [selected.pathId]); 43} 44 45function handleAllowThisSessionButtonClick(e) { 46 var selected = $('blocked-cookies').selectedItem; 47 if (selected) 48 chrome.send('AllowThisSession', [selected.pathId]); 49} 50 51function load() { 52 ui.CookiesTree.decorate($('allowed-cookies')); 53 ui.CookiesTree.decorate($('blocked-cookies')); 54 55 chrome.send('BindCookiesTreeModel', []); 56 57 $('allowed-cookies').addEventListener('change', handleCookiesTreeChange); 58 $('blocked-cookies').addEventListener('change', handleCookiesTreeChange); 59 60 $('block-button').addEventListener('click', handleBlockButtonClick); 61 $('allow-button').addEventListener('click', handleAllowButtonClick); 62 $('allow-this-session-button').addEventListener('click', 63 handleAllowThisSessionButtonClick); 64 65 $('close-button').addEventListener('click', closeDialog); 66 67 document.oncontextmenu = function(e) { 68 e.preventDefault(); 69 } 70 71 document.onkeydown = function(e) { 72 if (e.keyCode == 27) // Esc 73 closeDialog(); 74 } 75 76 updateControlState(); 77} 78 79document.addEventListener('DOMContentLoaded', load); 80