Chromium Code Reviews| 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 * Example: | 10 * Example: |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 observer: 'onOriginChanged_', | 36 observer: 'onOriginChanged_', |
| 37 }, | 37 }, |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * The amount of data stored for the origin. | 40 * The amount of data stored for the origin. |
| 41 */ | 41 */ |
| 42 storedData_: { | 42 storedData_: { |
| 43 type: String, | 43 type: String, |
| 44 value: '', | 44 value: '', |
| 45 }, | 45 }, |
| 46 | |
| 47 /** | |
| 48 * The type of storage for the origin. | |
| 49 */ | |
| 50 storageType_: Number, | |
| 51 | |
| 52 /** | |
| 53 * The category the user selected to get to this page. | |
| 54 */ | |
| 55 categorySelected: String, | |
| 56 | |
| 57 /** | |
| 58 * The current active route. | |
| 59 */ | |
| 60 currentRoute: { | |
| 61 type: Object, | |
| 62 notify: true, | |
| 63 }, | |
| 46 }, | 64 }, |
| 47 | 65 |
| 48 ready: function() { | 66 ready: function() { |
| 49 this.$.cookies.category = settings.ContentSettingsTypes.COOKIES; | 67 this.$.cookies.category = settings.ContentSettingsTypes.COOKIES; |
| 50 this.$.javascript.category = settings.ContentSettingsTypes.JAVASCRIPT; | 68 this.$.javascript.category = settings.ContentSettingsTypes.JAVASCRIPT; |
| 51 this.$.popups.category = settings.ContentSettingsTypes.POPUPS; | 69 this.$.popups.category = settings.ContentSettingsTypes.POPUPS; |
| 52 this.$.geolocation.category = settings.ContentSettingsTypes.GEOLOCATION; | 70 this.$.geolocation.category = settings.ContentSettingsTypes.GEOLOCATION; |
| 53 this.$.notification.category = settings.ContentSettingsTypes.NOTIFICATIONS; | 71 this.$.notification.category = settings.ContentSettingsTypes.NOTIFICATIONS; |
| 54 this.$.fullscreen.category = settings.ContentSettingsTypes.FULLSCREEN; | 72 this.$.fullscreen.category = settings.ContentSettingsTypes.FULLSCREEN; |
| 55 this.$.camera.category = settings.ContentSettingsTypes.CAMERA; | 73 this.$.camera.category = settings.ContentSettingsTypes.CAMERA; |
| 56 this.$.mic.category = settings.ContentSettingsTypes.MIC; | 74 this.$.mic.category = settings.ContentSettingsTypes.MIC; |
| 57 }, | 75 }, |
| 58 | 76 |
| 59 /** | 77 /** |
| 60 * Handler for when the origin changes. | 78 * Handler for when the origin changes. |
| 61 */ | 79 */ |
| 62 onOriginChanged_: function() { | 80 onOriginChanged_: function() { |
| 63 var url = /** @type {{hostname: string}} */(new URL(this.origin)); | 81 var url = /** @type {{hostname: string}} */(new URL(this.origin)); |
| 64 this.$.usageApi.fetchUsageTotal(url.hostname); | 82 this.$.usageApi.fetchUsageTotal(url.hostname); |
| 65 }, | 83 }, |
| 66 | 84 |
| 67 /** | 85 /** |
| 68 * Clears all data stored for the current origin. | 86 * Clears all data stored for the current origin. |
| 69 */ | 87 */ |
| 70 onClearStorage_: function() { | 88 onClearStorage_: function() { |
| 71 // TODO(finnur): Implement. | 89 this.$.usageApi.clearUsage(this.origin, this.storageType_); |
| 90 this.storedData_ = ''; | |
|
michaelpg
2016/02/03 18:39:13
Typically we would wait for a callback from C++ to
Finnur
2016/02/04 14:56:58
Done.
| |
| 91 this.navigateBackIfNoData_(); | |
| 72 }, | 92 }, |
| 73 | 93 |
| 74 /** | 94 /** |
| 75 * Resets all permissions and clears all data stored for the current origin. | 95 * Resets all permissions and clears all data stored for the current origin. |
| 76 */ | 96 */ |
| 77 onClearAndReset_: function() { | 97 onClearAndReset_: function() { |
| 78 Array.prototype.forEach.call( | 98 Array.prototype.forEach.call( |
| 79 this.root.querySelectorAll('site-details-permission'), | 99 this.root.querySelectorAll('site-details-permission'), |
| 80 function(element) { element.resetPermission(); }); | 100 function(element) { element.resetPermission(); }); |
| 81 | 101 |
| 82 this.onClearStorage_(); | 102 if (this.storedData_ != '') |
| 103 this.onClearStorage_(); | |
| 104 else | |
| 105 this.navigateBackIfNoData_(); | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * Navigate back if the UI is empty (everything been cleared). | |
| 110 */ | |
| 111 navigateBackIfNoData_: function() { | |
| 112 if (this.storedData_ == '' && !this.permissionShowing_()) { | |
| 113 this.currentRoute = { | |
|
michaelpg
2016/02/03 18:39:13
Is this the same as this.fire('subpage-back')? Tha
Finnur
2016/02/04 14:56:58
That was actually the first thing I tried, but rea
michaelpg
2016/02/04 19:18:01
Awesome!!
| |
| 114 page: this.currentRoute.page, | |
| 115 section: 'privacy', | |
| 116 subpage: ['site-settings', 'site-settings-category-' + | |
| 117 this.categorySelected], | |
| 118 }; | |
| 119 } | |
| 120 }, | |
| 121 | |
| 122 /** | |
| 123 * Returns true if one or more permission is showing. | |
| 124 */ | |
| 125 permissionShowing_: function() { | |
| 126 var height = 0; | |
| 127 Array.prototype.forEach.call( | |
|
michaelpg
2016/02/03 18:39:13
see Array.prototype.some
Finnur
2016/02/04 14:56:58
Hey, neat!
| |
| 128 this.root.querySelectorAll('site-details-permission'), | |
| 129 function(element) { height += element.offsetHeight; }); | |
|
michaelpg
2016/02/03 18:39:13
with some:
function(element) { return element.
Finnur
2016/02/04 14:56:58
Hmmm... is there a benefit to the latter syntax? I
michaelpg
2016/02/04 19:18:01
It's called an arrow function. Relatively new, no
michaelpg
2016/02/05 01:32:22
btw, arrow functions will break the presubmit lint
| |
| 130 return height > 0; | |
| 83 }, | 131 }, |
| 84 }); | 132 }); |
| OLD | NEW |