Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/resources/settings/site_settings/all_sites.js

Issue 2846723002: [MD settings] separate all-sites from site-list (Closed)
Patch Set: review changes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'all-sites' is the polymer element for showing the list of all sites under 7 * 'all-sites' is the polymer element for showing the list of all sites under
8 * Site Settings. 8 * Site Settings.
9 */ 9 */
10 Polymer({ 10 Polymer({
11 is: 'all-sites', 11 is: 'all-sites',
12 12
13 behaviors: [SiteSettingsBehavior], 13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior],
14
15 properties: {
16 /**
17 * Array of sites to display in the widget.
18 * @type {!Array<!SiteException>}
19 */
20 sites: {
21 type: Array,
22 value: function() {
23 return [];
24 },
25 },
26 },
27
28 /** @override */
29 ready: function() {
30 this.browserProxy_ =
31 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance();
32 this.addWebUIListener(
33 'contentSettingSitePermissionChanged', this.populateList_.bind(this));
34 this.populateList_();
35 },
36
37 /**
38 * Retrieves a list of all known sites with site details.
39 * @return {!Promise<!Array<!RawSiteException>>}
40 * @private
41 */
42 getAllSitesList_: function() {
43 /** @type {!Array<!RawSiteException>} */
44 var promiseList = [];
45
46 var types = Object.values(settings.ContentSettingsTypes);
47 for (var i = 0; i < types.length; i++) {
48 var type = types[i];
49 if (type == settings.ContentSettingsTypes.PROTOCOL_HANDLERS ||
50 type == settings.ContentSettingsTypes.USB_DEVICES ||
51 type == settings.ContentSettingsTypes.ZOOM_LEVELS) {
52 // Some categories store their data in a custom way.
53 continue;
54 }
55
56 promiseList.push(this.browserProxy_.getExceptionList(type));
57 }
58
59 return Promise.all(promiseList);
60 },
61
62 /**
63 * A handler for selecting a site (by clicking on the origin).
64 * @param {!{model: !{item: !SiteException}}} event
65 * @private
66 */
67 onOriginTap_: function(event) {
68 settings.navigateTo(
69 settings.Route.SITE_SETTINGS_SITE_DETAILS,
70 new URLSearchParams('site=' + event.model.item.origin));
71 },
72
73 /** @private */
74 populateList_: function() {
75 this.getAllSitesList_().then(this.processExceptions_.bind(this));
76 },
77
78 /**
79 * Process the exception list returned from the native layer.
80 * @param {!Array<!RawSiteException>} data List of sites (exceptions)
81 * to process.
82 * @private
83 */
84 processExceptions_: function(data) {
85 var sites = /** @type {!Array<!RawSiteException>} */ ([]);
86 for (var i = 0; i < data.length; ++i) {
87 var exceptionList = data[i];
88 for (var k = 0; k < exceptionList.length; ++k) {
89 sites.push(exceptionList[k]);
90 }
91 }
92 this.sites = this.toSiteArray_(sites);
93 },
94
95 /**
96 * TODO(dschuyler): Move this processing to C++ handler.
97 * Converts a list of exceptions received from the C++ handler to
98 * full SiteException objects. The list is sorted by site name, then protocol
99 * and port and de-duped (by origin).
100 * @param {!Array<!RawSiteException>} sites A list of sites to convert.
101 * @return {!Array<!SiteException>} A list of full SiteExceptions. Sorted and
102 * deduped.
103 * @private
104 */
105 toSiteArray_: function(sites) {
106 var self = this;
107 sites.sort(function(a, b) {
108 var url1 = self.toUrl(a.origin);
109 var url2 = self.toUrl(b.origin);
110 var comparison = url1.host.localeCompare(url2.host);
111 if (comparison == 0) {
112 comparison = url1.protocol.localeCompare(url2.protocol);
113 if (comparison == 0) {
114 comparison = url1.port.localeCompare(url2.port);
115 if (comparison == 0) {
116 // Compare hosts for the embedding origins.
117 var host1 = self.toUrl(a.embeddingOrigin);
118 var host2 = self.toUrl(b.embeddingOrigin);
119 host1 = (host1 == null) ? '' : host1.host;
120 host2 = (host2 == null) ? '' : host2.host;
121 return host1.localeCompare(host2);
122 }
123 }
124 }
125 return comparison;
126 });
127 var results = /** @type {!Array<!SiteException>} */ ([]);
128 var lastOrigin = '';
129 var lastEmbeddingOrigin = '';
130 for (var i = 0; i < sites.length; ++i) {
131 // Remove duplicates.
132 if (sites[i].origin == lastOrigin &&
133 sites[i].embeddingOrigin == lastEmbeddingOrigin) {
134 continue;
135 }
136 /** @type {!SiteException} */
137 var siteException = this.expandSiteException(sites[i]);
138 results.push(siteException);
139 lastOrigin = siteException.origin;
140 lastEmbeddingOrigin = siteException.embeddingOrigin;
141 }
142 return results;
143 },
14 }); 144 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698