summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/settings/site_settings/site_data.js
blob: c5df0d69c512672b5fb55d271b8efc7cc30b31ef (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// 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.

/**
 * @fileoverview
 * 'site-data' handles showing the local storage summary list for all sites.
 */

Polymer({
  is: 'site-data',

  behaviors: [CookieTreeBehavior],

  properties: {
    /**
     * The current filter applied to the cookie data list.
     * @private
     */
    filterString_: {
      type: String,
      value: '',
    },

    /** @private */
    confirmationDeleteMsg_: String,

    /** @private */
    idToDelete_: String,
  },

  /** @override */
  ready: function() {
    this.loadCookies();
  },

  /**
   * A filter function for the list.
   * @param {!CookieDataSummaryItem} item The item to possibly filter out.
   * @return {boolean} Whether to show the item.
   * @private
   */
  showItem_: function(item) {
    if (this.filterString_.length == 0)
      return true;
    return item.site.indexOf(this.filterString_) > -1;
  },

  /** @private */
  onSearchChanged_: function(e) {
    this.filterString_ = e.detail;
    this.$.list.render();
  },

  /** @private */
  isRemoveButtonVisible_: function(sites, renderedItemCount) {
    return renderedItemCount != 0;
  },

  /**
   * Returns the string to use for the Remove label.
   * @return {string} filterString The current filter string.
   * @private
   */
  computeRemoveLabel_: function(filterString) {
    if (filterString.length == 0)
      return loadTimeData.getString('siteSettingsCookieRemoveAll');
    return loadTimeData.getString('siteSettingsCookieRemoveAllShown');
  },

  /** @private */
  onCloseDialog_: function() {
    this.$.confirmDeleteDialog.close();
  },

  /**
   * Shows a dialog to confirm the deletion of multiple sites.
   * @private
   */
  onConfirmDeleteMultipleSites_: function() {
    this.idToDelete_ = '';  // Delete all.
    this.confirmationDeleteMsg_ = loadTimeData.getString(
        'siteSettingsCookieRemoveMultipleConfirmation');
    this.$.confirmDeleteDialog.showModal();
  },

  /**
   * Called when deletion for a single/multiple sites has been confirmed.
   * @private
   */
  onConfirmDelete_: function() {
    if (this.idToDelete_ != '')
      this.onDeleteSite_();
    else
      this.onDeleteMultipleSites_();
    this.$.confirmDeleteDialog.close();
  },

  /**
   * Deletes all site data for a given site.
   * @private
   */
  onDeleteSite_: function() {
    this.browserProxy.removeCookie(this.idToDelete_);
  },

  /**
   * Deletes site data for multiple sites.
   * @private
   */
  onDeleteMultipleSites_: function() {
    if (this.filterString_.length == 0) {
      this.removeAllCookies();
    } else {
      var items = this.$.list.items;
      for (var i = 0; i < items.length; ++i) {
        if (this.showItem_(items[i]))
          this.browserProxy.removeCookie(items[i].id);
      }
      // We just deleted all items found by the filter, let's reset the filter.
      /** @type {SettingsSubpageSearchElement} */(this.$.filter).setValue('');
    }
  },

  /**
   * @param {!{model: !{item: CookieDataSummaryItem}}} event
   * @private
   */
  onSiteTap_: function(event) {
    settings.navigateTo(settings.Route.SITE_SETTINGS_DATA_DETAILS,
        new URLSearchParams('site=' + event.model.item.site));
  },
});