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 m from 'mithril'; 16 17import {raf} from '../core/raf_scheduler'; 18 19import {globals} from './globals'; 20 21const COOKIE_ACK_KEY = 'cookieAck'; 22 23export class CookieConsent implements m.ClassComponent { 24 private showCookieConsent = true; 25 26 oninit() { 27 this.showCookieConsent = true; 28 if ( 29 !globals.logging.isEnabled() || 30 localStorage.getItem(COOKIE_ACK_KEY) === 'true' 31 ) { 32 this.showCookieConsent = false; 33 } 34 } 35 36 view() { 37 if (!this.showCookieConsent) return; 38 return m( 39 '.cookie-consent', 40 m( 41 '.cookie-text', 42 `This site uses cookies from Google to deliver its services and to 43 analyze traffic.`, 44 ), 45 m( 46 '.buttons', 47 m( 48 'button', 49 m( 50 'a', 51 { 52 href: 'https://policies.google.com/technologies/cookies', 53 target: '_blank', 54 }, 55 'More details', 56 ), 57 ), 58 m( 59 'button', 60 { 61 onclick: () => { 62 this.showCookieConsent = false; 63 localStorage.setItem(COOKIE_ACK_KEY, 'true'); 64 raf.scheduleFullRedraw(); 65 }, 66 }, 67 'OK', 68 ), 69 ), 70 ); 71 } 72} 73