1// Copyright (C) 2020 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import * as m from 'mithril'; 16 17import {globals} from './globals'; 18 19const COOKIE_ACK_KEY = 'cookieAck'; 20 21export class CookieConsent implements m.ClassComponent { 22 private showCookieConsent = true; 23 24 oninit() { 25 this.showCookieConsent = true; 26 if (!globals.logging.isEnabled() || 27 localStorage.getItem(COOKIE_ACK_KEY) === 'true') { 28 this.showCookieConsent = false; 29 } 30 } 31 32 view() { 33 if (!this.showCookieConsent) return; 34 return m( 35 '.cookie-consent', 36 m('.cookie-text', 37 `This site uses cookies from Google to deliver its services and to 38 analyze traffic.`), 39 m('.buttons', 40 m('button', 41 m('a', 42 { 43 href: 'https://policies.google.com/technologies/cookies', 44 target: '_blank' 45 }, 46 'More details')), 47 m('button', 48 { 49 onclick: () => { 50 this.showCookieConsent = false; 51 localStorage.setItem(COOKIE_ACK_KEY, 'true'); 52 globals.rafScheduler.scheduleFullRedraw(); 53 } 54 }, 55 'OK')), 56 ); 57 } 58} 59