• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  view() {
25    if (this.showCookieConsent) {
26      this.showCookieConsent = localStorage.getItem(COOKIE_ACK_KEY) === null;
27    }
28    if (!this.showCookieConsent) return;
29    return m(
30        '.cookie-consent',
31        m('.cookie-text',
32          `This site uses cookies from Google to deliver its services and to
33          analyze traffic.`),
34        m('.buttons',
35          m('button',
36            m('a',
37              {
38                href: 'https://policies.google.com/technologies/cookies',
39                target: '_blank'
40              },
41              'More details')),
42          m('button',
43            {
44              onclick: () => {
45                this.showCookieConsent = false;
46                localStorage.setItem(COOKIE_ACK_KEY, 'true');
47                globals.rafScheduler.scheduleFullRedraw();
48              }
49            },
50            'OK')),
51    );
52  }
53}
54