summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/settings/site_settings/cookie_info.js
blob: 91289e40b9e453e500f6f7952afc6b22cf8d72d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @typedef {{hasChildren: boolean,
 *            id: string,
 *            idPath: string,
 *            title: string,
 *            totalUsage: string,
 *            type: string}}
 */
let CookieDetails;

/**
 * @typedef {{content: string,
 *            label: string}}
 */
let CookieDataForDisplay;

// This structure maps the various cookie type names from C++ (hence the
// underscores) to arrays of the different types of data each has, along with
// the i18n name for the description of that data type.
// This structure serves three purposes:
// 1) to list what subset of the cookie data we want to show in the UI.
// 2) What order to show it in.
// 3) What user friendly label to prefix the data with.
const cookieInfo = {
  'cookie': [
    ['name', 'cookieName'], ['content', 'cookieContent'],
    ['domain', 'cookieDomain'], ['path', 'cookiePath'],
    ['sendfor', 'cookieSendFor'],
    ['accessibleToScript', 'cookieAccessibleToScript'],
    ['created', 'cookieCreated'], ['expires', 'cookieExpires']
  ],
  'app_cache': [
    ['origin', 'appCacheOrigin'], ['size', 'localStorageSize'],
    ['modified', 'localStorageLastModified']
  ],
  'database': [
    ['origin', 'databaseOrigin'], ['size', 'localStorageSize'],
    ['modified', 'localStorageLastModified']
  ],
  'local_storage': [
    ['origin', 'localStorageOrigin'], ['size', 'localStorageSize'],
    ['modified', 'localStorageLastModified']
  ],
  'indexed_db': [
    ['origin', 'indexedDbOrigin'], ['size', 'indexedDbSize'],
    ['modified', 'indexedDbLastModified']
  ],
  'file_system': [
    ['origin', 'fileSystemOrigin'], ['persistent', 'fileSystemPersistentUsage'],
    ['temporary', 'fileSystemTemporaryUsage']
  ],
  'service_worker':
      [['origin', 'serviceWorkerOrigin'], ['size', 'serviceWorkerSize']],
  'shared_worker':
      [['worker', 'sharedWorkerWorker'], ['name', 'sharedWorkerName']],
  'cache_storage': [
    ['origin', 'cacheStorageOrigin'], ['size', 'cacheStorageSize'],
    ['modified', 'cacheStorageLastModified']
  ],
  'flash_lso': [['domain', 'cookieDomain']],
  'media_license': [
    ['origin', 'mediaLicenseOrigin'], ['size', 'mediaLicenseSize'],
    ['modified', 'mediaLicenseLastModified']
  ],
};

/**
 * Get cookie data for a given HTML node.
 * @param {CookieDetails} data The contents of the cookie.
 * @return {!Array<CookieDataForDisplay>}
 */
const getCookieData = function(data) {
  /** @type {!Array<CookieDataForDisplay>} */
  const out = [];
  const fields = cookieInfo[data.type];
  for (let i = 0; i < fields.length; i++) {
    const field = fields[i];
    // Iterate through the keys found in |cookieInfo| for the given |type|
    // and see if those keys are present in the data. If so, display them
    // (in the order determined by |cookieInfo|).
    const key = field[0];
    if (data[key].length > 0) {
      const entry = /** @type {CookieDataForDisplay} */ ({
        label: loadTimeData.getString(field[1]),
        content: data[key],
      });
      out.push(entry);
    }
  }
  return out;
};