| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * 'site-details' show the details (permissions and usage) for a given origin | 7 * 'site-details' show the details (permissions and usage) for a given origin |
| 8 * under Site Settings. | 8 * under Site Settings. |
| 9 */ | 9 */ |
| 10 Polymer({ | 10 Polymer({ |
| 11 is: 'site-details', | 11 is: 'site-details', |
| 12 | 12 |
| 13 behaviors: [SiteSettingsBehavior, settings.RouteObserverBehavior], | 13 behaviors: [SiteSettingsBehavior, settings.RouteObserverBehavior], |
| 14 | 14 |
| 15 properties: { | 15 properties: { |
| 16 /** | 16 /** |
| 17 * The site that this widget is showing details for. | 17 * The origin that this widget is showing details for. |
| 18 * @type {SiteException} | 18 * @private |
| 19 */ | 19 */ |
| 20 site: { | 20 origin: { |
| 21 type: Object, | 21 type: String, |
| 22 observer: 'onSiteChanged_', | 22 observer: 'onOriginChanged_', |
| 23 }, | 23 }, |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * The amount of data stored for the origin. | 26 * The amount of data stored for the origin. |
| 27 * @private | 27 * @private |
| 28 */ | 28 */ |
| 29 storedData_: { | 29 storedData_: { |
| 30 type: String, | 30 type: String, |
| 31 value: '', | 31 value: '', |
| 32 }, | 32 }, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * settings.RouteObserverBehavior | 54 * settings.RouteObserverBehavior |
| 55 * @param {!settings.Route} route | 55 * @param {!settings.Route} route |
| 56 * @protected | 56 * @protected |
| 57 */ | 57 */ |
| 58 currentRouteChanged: function(route) { | 58 currentRouteChanged: function(route) { |
| 59 var site = settings.getQueryParameters().get('site'); | 59 var site = settings.getQueryParameters().get('site'); |
| 60 if (!site) | 60 if (!site) |
| 61 return; | 61 return; |
| 62 this.browserProxy.getSiteDetails(site).then(function(siteInfo) { | 62 this.origin = site; |
| 63 this.site = this.expandSiteException(siteInfo); | |
| 64 }.bind(this)); | |
| 65 }, | 63 }, |
| 66 | 64 |
| 67 /** | 65 /** |
| 68 * Handler for when the origin changes. | 66 * Handler for when the origin changes. |
| 69 * @private | 67 * @private |
| 70 */ | 68 */ |
| 71 onSiteChanged_: function() { | 69 onOriginChanged_: function() { |
| 72 // origin may be initially undefined if the user follows a direct | 70 this.$.usageApi.fetchUsageTotal(this.toUrl(this.origin).hostname); |
| 73 // link (URL) to this page. | 71 |
| 74 var origin = this.site.origin; | 72 var siteDetailsPermissions = |
| 75 if (origin !== undefined) | 73 /** @type{!NodeList<!SiteDetailsPermissionElement>} */ |
| 76 this.$.usageApi.fetchUsageTotal(this.toUrl(origin).hostname); | 74 (this.root.querySelectorAll('site-details-permission')); |
| 75 var categoryList = |
| 76 /** @type{!Array<!string>} */ ( |
| 77 Array.prototype.map.call(siteDetailsPermissions, function(element) { |
| 78 return element.category; |
| 79 })); |
| 80 |
| 81 this.browserProxy.getOriginPermissions(this.origin, categoryList) |
| 82 .then(function(exceptionList) { |
| 83 exceptionList.forEach(function(exception, i) { |
| 84 // |exceptionList| should be in the same order as |categoryList|, |
| 85 // which is in the same order as |siteDetailsPermissions|. |
| 86 var element = /** @type{!SiteDetailsPermissionElement} */ ( |
| 87 siteDetailsPermissions[i]); |
| 88 element.site = /** @type{!SiteException} */ ( |
| 89 element.expandSiteException(exception)); |
| 90 }); |
| 91 }); |
| 77 }, | 92 }, |
| 78 | 93 |
| 79 /** @private */ | 94 /** @private */ |
| 80 onCloseDialog_: function() { | 95 onCloseDialog_: function() { |
| 81 this.$.confirmDeleteDialog.close(); | 96 this.$.confirmDeleteDialog.close(); |
| 82 }, | 97 }, |
| 83 | 98 |
| 84 /** | 99 /** |
| 85 * Confirms the deletion of storage for a site. | 100 * Confirms the deletion of storage for a site. |
| 86 * @param {!Event} e | 101 * @param {!Event} e |
| 87 * @private | 102 * @private |
| 88 */ | 103 */ |
| 89 onConfirmClearStorage_: function(e) { | 104 onConfirmClearStorage_: function(e) { |
| 90 e.preventDefault(); | 105 e.preventDefault(); |
| 91 this.confirmationDeleteMsg_ = loadTimeData.getStringF( | 106 this.confirmationDeleteMsg_ = loadTimeData.getStringF( |
| 92 'siteSettingsSiteRemoveConfirmation', | 107 'siteSettingsSiteRemoveConfirmation', this.toUrl(this.origin).href); |
| 93 this.toUrl(this.site.origin).href); | |
| 94 this.$.confirmDeleteDialog.showModal(); | 108 this.$.confirmDeleteDialog.showModal(); |
| 95 }, | 109 }, |
| 96 | 110 |
| 97 /** | 111 /** |
| 98 * Clears all data stored for the current origin. | 112 * Clears all data stored for the current origin. |
| 99 * @private | 113 * @private |
| 100 */ | 114 */ |
| 101 onClearStorage_: function() { | 115 onClearStorage_: function() { |
| 102 this.$.usageApi.clearUsage( | 116 this.$.usageApi.clearUsage(this.toUrl(this.origin).href, this.storageType_); |
| 103 this.toUrl(this.site.origin).href, this.storageType_); | |
| 104 }, | 117 }, |
| 105 | 118 |
| 106 /** | 119 /** |
| 107 * Called when usage has been deleted for an origin. | 120 * Called when usage has been deleted for an origin. |
| 108 * @param {!{detail: !{origin: string}}} event | 121 * @param {!{detail: !{origin: string}}} event |
| 109 * @private | 122 * @private |
| 110 */ | 123 */ |
| 111 onUsageDeleted_: function(event) { | 124 onUsageDeleted_: function(event) { |
| 112 if (event.detail.origin == this.toUrl(this.site.origin).href) { | 125 if (event.detail.origin == this.toUrl(this.origin).href) { |
| 113 this.storedData_ = ''; | 126 this.storedData_ = ''; |
| 114 this.navigateBackIfNoData_(); | 127 this.navigateBackIfNoData_(); |
| 115 } | 128 } |
| 116 }, | 129 }, |
| 117 | 130 |
| 118 /** | 131 /** |
| 119 * Resets all permissions and clears all data stored for the current origin. | 132 * Resets all permissions and clears all data stored for the current origin. |
| 120 * @private | 133 * @private |
| 121 */ | 134 */ |
| 122 onClearAndReset_: function() { | 135 onClearAndReset_: function() { |
| 123 Array.prototype.forEach.call( | 136 this.root.querySelectorAll('site-details-permission') |
| 124 this.root.querySelectorAll('site-details-permission'), | 137 .forEach(function(element) { |
| 125 function(element) { | |
| 126 element.resetPermission(); | 138 element.resetPermission(); |
| 127 }); | 139 }); |
| 128 | 140 |
| 129 if (this.storedData_ != '') | 141 if (this.storedData_ != '') |
| 130 this.onClearStorage_(); | 142 this.onClearStorage_(); |
| 131 else | 143 else |
| 132 this.navigateBackIfNoData_(); | 144 this.navigateBackIfNoData_(); |
| 133 }, | 145 }, |
| 134 | 146 |
| 135 /** | 147 /** |
| (...skipping 10 matching lines...) Expand all Loading... |
| 146 * @private | 158 * @private |
| 147 */ | 159 */ |
| 148 permissionShowing_: function() { | 160 permissionShowing_: function() { |
| 149 return Array.prototype.some.call( | 161 return Array.prototype.some.call( |
| 150 this.root.querySelectorAll('site-details-permission'), | 162 this.root.querySelectorAll('site-details-permission'), |
| 151 function(element) { | 163 function(element) { |
| 152 return element.offsetHeight > 0; | 164 return element.offsetHeight > 0; |
| 153 }); | 165 }); |
| 154 }, | 166 }, |
| 155 }); | 167 }); |
| OLD | NEW |