| 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 site that this widget is showing details for. |
| 18 * @type {SiteException} | 18 * @type {SiteException} |
| 19 */ | 19 */ |
| 20 site: { | 20 site: { |
| 21 type: Object, | 21 type: Object, |
| 22 observer: 'onSiteChanged_', | 22 observer: 'onSiteChanged_', |
| 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 */ | 28 */ |
| 28 storedData_: { | 29 storedData_: { |
| 29 type: String, | 30 type: String, |
| 30 value: '', | 31 value: '', |
| 31 }, | 32 }, |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * The type of storage for the origin. | 35 * The type of storage for the origin. |
| 36 * @private |
| 35 */ | 37 */ |
| 36 storageType_: Number, | 38 storageType_: Number, |
| 39 |
| 40 /** @private */ |
| 41 confirmationDeleteMsg_: String, |
| 37 }, | 42 }, |
| 38 | 43 |
| 39 listeners: { | 44 listeners: { |
| 40 'usage-deleted': 'onUsageDeleted', | 45 'usage-deleted': 'onUsageDeleted_', |
| 41 }, | 46 }, |
| 42 | 47 |
| 48 /** @override */ |
| 43 ready: function() { | 49 ready: function() { |
| 44 this.ContentSettingsTypes = settings.ContentSettingsTypes; | 50 this.ContentSettingsTypes = settings.ContentSettingsTypes; |
| 45 }, | 51 }, |
| 46 | 52 |
| 47 /** | 53 /** |
| 48 * settings.RouteObserverBehavior | 54 * settings.RouteObserverBehavior |
| 49 * @param {!settings.Route} route | 55 * @param {!settings.Route} route |
| 50 * @protected | 56 * @protected |
| 51 */ | 57 */ |
| 52 currentRouteChanged: function(route) { | 58 currentRouteChanged: function(route) { |
| 53 var site = settings.getQueryParameters().get('site'); | 59 var site = settings.getQueryParameters().get('site'); |
| 54 if (!site) | 60 if (!site) |
| 55 return; | 61 return; |
| 56 this.browserProxy.getSiteDetails(site).then(function(siteInfo) { | 62 this.browserProxy.getSiteDetails(site).then(function(siteInfo) { |
| 57 this.site = this.expandSiteException(siteInfo); | 63 this.site = this.expandSiteException(siteInfo); |
| 58 }.bind(this)); | 64 }.bind(this)); |
| 59 }, | 65 }, |
| 60 | 66 |
| 61 /** | 67 /** |
| 62 * Handler for when the origin changes. | 68 * Handler for when the origin changes. |
| 69 * @private |
| 63 */ | 70 */ |
| 64 onSiteChanged_: function() { | 71 onSiteChanged_: function() { |
| 65 // originForDisplay may be initially undefined if the user follows a direct | 72 // originForDisplay may be initially undefined if the user follows a direct |
| 66 // link (URL) to this page. | 73 // link (URL) to this page. |
| 67 if (this.site.originForDisplay !== undefined) { | 74 if (this.site.originForDisplay !== undefined) { |
| 68 // Using originForDisplay avoids the [*.] prefix that some exceptions use. | 75 // Using originForDisplay avoids the [*.] prefix that some exceptions use. |
| 69 var url = new URL(this.ensureUrlHasScheme(this.site.originForDisplay)); | 76 var url = new URL(this.ensureUrlHasScheme(this.site.originForDisplay)); |
| 70 this.$.usageApi.fetchUsageTotal(url.hostname); | 77 this.$.usageApi.fetchUsageTotal(url.hostname); |
| 71 } | 78 } |
| 72 }, | 79 }, |
| 73 | 80 |
| 81 /** @private */ |
| 82 onCloseDialog_: function() { |
| 83 this.$.confirmDeleteDialog.close(); |
| 84 }, |
| 85 |
| 86 /** |
| 87 * Confirms the deletion of storage for a site. |
| 88 * @private |
| 89 */ |
| 90 onConfirmClearStorage_: function() { |
| 91 this.confirmationDeleteMsg_ = loadTimeData.getStringF( |
| 92 'siteSettingsSiteRemoveConfirmation', |
| 93 this.toUrl(this.site.origin).href); |
| 94 this.$.confirmDeleteDialog.showModal(); |
| 95 }, |
| 96 |
| 74 /** | 97 /** |
| 75 * Clears all data stored for the current origin. | 98 * Clears all data stored for the current origin. |
| 99 * @private |
| 76 */ | 100 */ |
| 77 onClearStorage_: function() { | 101 onClearStorage_: function() { |
| 78 this.$.usageApi.clearUsage( | 102 this.$.usageApi.clearUsage( |
| 79 this.toUrl(this.site.origin).href, this.storageType_); | 103 this.toUrl(this.site.origin).href, this.storageType_); |
| 80 }, | 104 }, |
| 81 | 105 |
| 82 /** | 106 /** |
| 83 * Called when usage has been deleted for an origin. | 107 * Called when usage has been deleted for an origin. |
| 108 * @param {!{detail: !{origin: string}}} event |
| 109 * @private |
| 84 */ | 110 */ |
| 85 onUsageDeleted: function(event) { | 111 onUsageDeleted_: function(event) { |
| 86 if (event.detail.origin == this.toUrl(this.site.origin).href) { | 112 if (event.detail.origin == this.toUrl(this.site.origin).href) { |
| 87 this.storedData_ = ''; | 113 this.storedData_ = ''; |
| 88 this.navigateBackIfNoData_(); | 114 this.navigateBackIfNoData_(); |
| 89 } | 115 } |
| 90 }, | 116 }, |
| 91 | 117 |
| 92 /** | 118 /** |
| 93 * Resets all permissions and clears all data stored for the current origin. | 119 * Resets all permissions and clears all data stored for the current origin. |
| 120 * @private |
| 94 */ | 121 */ |
| 95 onClearAndReset_: function() { | 122 onClearAndReset_: function() { |
| 96 Array.prototype.forEach.call( | 123 Array.prototype.forEach.call( |
| 97 this.root.querySelectorAll('site-details-permission'), | 124 this.root.querySelectorAll('site-details-permission'), |
| 98 function(element) { element.resetPermission(); }); | 125 function(element) { element.resetPermission(); }); |
| 99 | 126 |
| 100 if (this.storedData_ != '') | 127 if (this.storedData_ != '') |
| 101 this.onClearStorage_(); | 128 this.onClearStorage_(); |
| 102 else | 129 else |
| 103 this.navigateBackIfNoData_(); | 130 this.navigateBackIfNoData_(); |
| 104 }, | 131 }, |
| 105 | 132 |
| 106 /** | 133 /** |
| 107 * Navigate back if the UI is empty (everything been cleared). | 134 * Navigate back if the UI is empty (everything been cleared). |
| 135 * @private |
| 108 */ | 136 */ |
| 109 navigateBackIfNoData_: function() { | 137 navigateBackIfNoData_: function() { |
| 110 if (this.storedData_ == '' && !this.permissionShowing_()) | 138 if (this.storedData_ == '' && !this.permissionShowing_()) |
| 111 settings.navigateToPreviousRoute(); | 139 settings.navigateToPreviousRoute(); |
| 112 }, | 140 }, |
| 113 | 141 |
| 114 /** | 142 /** |
| 115 * Returns true if one or more permission is showing. | 143 * Returns true if one or more permission is showing. |
| 144 * @private |
| 116 */ | 145 */ |
| 117 permissionShowing_: function() { | 146 permissionShowing_: function() { |
| 118 return Array.prototype.some.call( | 147 return Array.prototype.some.call( |
| 119 this.root.querySelectorAll('site-details-permission'), | 148 this.root.querySelectorAll('site-details-permission'), |
| 120 function(element) { return element.offsetHeight > 0; }); | 149 function(element) { return element.offsetHeight > 0; }); |
| 121 }, | 150 }, |
| 122 }); | 151 }); |
| OLD | NEW |