Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 ready: function() { | |
|
dpapad
2017/04/28 23:54:05
@override missing.
dschuyler
2017/05/18 23:16:11
Done.
| |
| 29 this.browserProxy_ = | |
| 30 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | |
| 31 this.addWebUIListener( | |
| 32 'contentSettingSitePermissionChanged', this.populateList_.bind(this)); | |
| 33 this.populateList_(); | |
| 34 }, | |
| 35 | |
| 36 /** | |
| 37 * Retrieves a list of all known sites with site details. | |
| 38 * @return {!Promise} | |
|
dpapad
2017/04/28 23:54:05
What is the type of |promiseList|? Can we make the
dschuyler
2017/05/18 23:16:11
Done.
| |
| 39 * @private | |
| 40 */ | |
| 41 getAllSitesList_: function() { | |
| 42 var promiseList = []; | |
| 43 for (var type in settings.ContentSettingsTypes) { | |
|
dpapad
2017/04/28 23:54:05
Do we need to iterate on the keys of ContentSettin
dschuyler
2017/05/18 23:16:11
done.
| |
| 44 if (settings.ContentSettingsTypes[type] == | |
| 45 settings.ContentSettingsTypes.PROTOCOL_HANDLERS || | |
| 46 settings.ContentSettingsTypes[type] == | |
| 47 settings.ContentSettingsTypes.USB_DEVICES || | |
| 48 settings.ContentSettingsTypes[type] == | |
| 49 settings.ContentSettingsTypes.ZOOM_LEVELS) { | |
| 50 // Some categories store their data in a custom way. | |
| 51 continue; | |
| 52 } | |
| 53 | |
| 54 promiseList.push(this.browserProxy_.getExceptionList( | |
| 55 settings.ContentSettingsTypes[type])); | |
| 56 } | |
| 57 | |
| 58 return Promise.all(promiseList); | |
| 59 }, | |
| 60 | |
| 61 /** | |
| 62 * A handler for selecting a site (by clicking on the origin). | |
| 63 * @param {!{model: !{item: !SiteException}}} event | |
| 64 * @private | |
| 65 */ | |
| 66 onOriginTap_: function(event) { | |
| 67 settings.navigateTo( | |
| 68 settings.Route.SITE_SETTINGS_SITE_DETAILS, | |
| 69 new URLSearchParams('site=' + event.model.item.origin)); | |
| 70 }, | |
| 71 | |
| 72 /** @private */ | |
| 73 populateList_: function() { | |
| 74 this.getAllSitesList_().then(function(lists) { | |
|
dpapad
2017/04/28 23:54:05
this.getAllSitesList_().then(this.processException
dschuyler
2017/05/18 23:16:11
Done.
| |
| 75 this.processExceptions_(lists); | |
| 76 }.bind(this)); | |
| 77 }, | |
| 78 | |
| 79 /** | |
| 80 * Process the exception list returned from the native layer. | |
| 81 * @param {!Array<!Array<RawSiteException>>} data List of sites (exceptions) | |
| 82 * to process. | |
| 83 * @private | |
| 84 */ | |
| 85 processExceptions_: function(data) { | |
| 86 var sites = /** @type {!Array<RawSiteException>} */ ([]); | |
| 87 for (var i = 0; i < data.length; ++i) { | |
| 88 var exceptionList = data[i]; | |
| 89 for (var k = 0; k < exceptionList.length; ++k) { | |
| 90 sites.push(exceptionList[k]); | |
| 91 } | |
| 92 } | |
| 93 this.sites = this.toSiteArray_(sites); | |
| 94 }, | |
| 95 | |
| 96 /** | |
| 97 * TODO(dschuyler): Move this processing to C++ handler. | |
| 98 * Converts a list of exceptions received from the C++ handler to | |
| 99 * full SiteException objects. The list is sorted by site name, then protocol | |
| 100 * and port and de-duped (by origin). | |
| 101 * @param {!Array<RawSiteException>} sites A list of sites to convert. | |
|
dpapad
2017/04/28 23:54:05
Should this be !Array<!RawSiteException>? Similar
dschuyler
2017/05/18 23:16:11
Done.
| |
| 102 * @return {!Array<SiteException>} A list of full SiteExceptions. Sorted and | |
| 103 * deduped. | |
| 104 * @private | |
| 105 */ | |
| 106 toSiteArray_: function(sites) { | |
| 107 var self = this; | |
| 108 sites.sort(function(a, b) { | |
| 109 var url1 = self.toUrl(a.origin); | |
| 110 var url2 = self.toUrl(b.origin); | |
| 111 var comparison = url1.host.localeCompare(url2.host); | |
| 112 if (comparison == 0) { | |
| 113 comparison = url1.protocol.localeCompare(url2.protocol); | |
| 114 if (comparison == 0) { | |
| 115 comparison = url1.port.localeCompare(url2.port); | |
| 116 if (comparison == 0) { | |
|
dpapad
2017/04/28 23:54:05
Do those three if (comparison == 0) checks need to
dschuyler
2017/05/18 23:16:11
I agree that would work. Is it more readable, or f
dpapad
2017/05/18 23:37:08
Treat this suggestion as optional. FWIW, there is
dschuyler
2017/05/18 23:44:22
I'll think on it more and/or ask for another opini
| |
| 117 // Compare hosts for the embedding origins. | |
| 118 var host1 = self.toUrl(a.embeddingOrigin); | |
| 119 var host2 = self.toUrl(b.embeddingOrigin); | |
| 120 host1 = (host1 == null) ? '' : host1.host; | |
| 121 host2 = (host2 == null) ? '' : host2.host; | |
| 122 return host1.localeCompare(host2); | |
| 123 } | |
| 124 } | |
| 125 } | |
| 126 return comparison; | |
| 127 }); | |
| 128 var results = /** @type {!Array<SiteException>} */ ([]); | |
| 129 var lastOrigin = ''; | |
| 130 var lastEmbeddingOrigin = ''; | |
| 131 for (var i = 0; i < sites.length; ++i) { | |
| 132 /** @type {!SiteException} */ | |
| 133 var siteException = this.expandSiteException(sites[i]); | |
| 134 | |
| 135 // Remove duplicates. | |
| 136 if (siteException.origin == lastOrigin && | |
|
dpapad
2017/04/28 23:54:05
|origin| and |embeddingOrigin| already exist on |s
dschuyler
2017/05/18 23:16:11
Sure, but I don't want to change this code too muc
dpapad
2017/05/18 23:37:08
Can you add a TODO so that we don't completely for
dschuyler
2017/05/18 23:44:22
Sorry, my response above wasn't clear - I see that
dpapad
2017/05/19 19:25:31
Ah ok. Yes it was not clear that it was addressed.
| |
| 137 siteException.embeddingOrigin == lastEmbeddingOrigin) { | |
| 138 continue; | |
| 139 } | |
| 140 | |
| 141 results.push(siteException); | |
| 142 lastOrigin = siteException.origin; | |
| 143 lastEmbeddingOrigin = siteException.embeddingOrigin; | |
| 144 } | |
| 145 return results; | |
| 146 }, | |
| 14 }); | 147 }); |
| OLD | NEW |