summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/settings/multidevice_page/multidevice_feature_item.js
blob: 1b8b003a81c204ac0b31e1892731bdc3ad52631e (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
// Copyright 2018 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
 * Item for an individual multidevice feature. These features appear in the
 * multidevice subpage to allow the user to individually toggle them as long as
 * the phone is enabled as a multidevice host. The feature items contain basic
 * information relevant to the individual feature, such as a route to the
 * feature's autonomous page if there is one.
 */
cr.exportPath('settings');

Polymer({
  is: 'settings-multidevice-feature-item',

  behaviors: [MultiDeviceFeatureBehavior],

  properties: {
    /** @type {!settings.MultiDeviceFeature} */
    feature: Number,

    /**
     * If it is truthy, the item should be actionable and clicking on it should
     * navigate to the provided route. Otherwise, the item is simply not
     * actionable.
     * @type {settings.Route|undefined}
     */
    subpageRoute: Object,

    /**
     * URLSearchParams for subpage route. No param is provided if it is
     * undefined.
     * @type {URLSearchParams|undefined}
     */
    subpageRouteUrlSearchParams: Object,
  },

  /**
   * @return {boolean}
   * @private
   */
  hasSubpageClickHandler_: function() {
    return !!this.subpageRoute && this.isFeatureAllowedByPolicy(this.feature);
  },

  /** @private */
  handleItemClick_: function(event) {
    if (!this.hasSubpageClickHandler_()) {
      return;
    }

    // We do not navigate away if the click was on a link.
    if (event.path[0].tagName === 'A') {
      event.stopPropagation();
      return;
    }

    // Remove the search term when navigating to avoid potentially having any
    // visible search term reappear at a later time. See
    // https://crbug.com/989119.
    settings.navigateTo(
        this.subpageRoute, this.subpageRouteUrlSearchParams,
        true /* opt_removeSearch */);
  },
});