Chromium Code Reviews| Index: chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js |
| diff --git a/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js b/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js |
| index 5c8d55722aeff98d7b8e3bde1df11083fb4a7bb0..dd27683c97e8429cc4f75b2744e93cda23f73e08 100644 |
| --- a/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js |
| +++ b/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js |
| @@ -28,8 +28,9 @@ Polymer({ |
| */ |
| counters_: { |
| type: Object, |
| - value: { |
| - // Will be filled as results are reported. |
| + // Will be filled as results are reported. |
| + value: function() { |
| + return {}; |
| } |
| }, |
| @@ -60,6 +61,21 @@ Polymer({ |
| type: Boolean, |
| value: false, |
| }, |
| + |
| + /** @private {!Array<ImportantSite>} */ |
| + importantSites_: { |
| + type: Array, |
| + value: function() { |
| + return []; |
| + } |
| + }, |
| + |
| + /** @private */ |
| + importantSitesFlagEnabled_: { |
| + type: Boolean, |
| + value: false, |
| + }, |
| + |
|
Dan Beam
2017/05/09 19:23:18
remove extra \n
dullweber
2017/05/11 13:13:47
Done.
|
| }, |
| /** @private {settings.ClearBrowsingDataBrowserProxy} */ |
| @@ -80,9 +96,21 @@ Polymer({ |
| attached: function() { |
| this.browserProxy_ = |
| settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); |
| - this.browserProxy_.initialize().then(function() { |
| - this.$.dialog.showModal(); |
| - }.bind(this)); |
| + this.browserProxy_.initialize() |
| + .then(function() { |
| + this.$.clearBrowsingDataDialog.showModal(); |
| + return this.browserProxy_.fetchImportantSites(); |
| + }.bind(this)) |
| + .then(this.receiveImportantSites_.bind(this)); |
| + }, |
| + |
| + /** |
| + * @param {!ImportantSitesResponse} result |
| + * @private |
| + */ |
| + receiveImportantSites_: function(result) { |
| + this.importantSitesFlagEnabled_ = result.flagEnabled; |
| + this.set('importantSites_', result.importantSites); |
| }, |
| /** |
| @@ -96,7 +124,7 @@ Polymer({ |
| updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { |
| this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; |
| this.$.syncedDataSentence.hidden = !syncing; |
| - this.$.dialog.classList.add('fully-rendered'); |
| + this.$.clearBrowsingDataDialog.classList.add('fully-rendered'); |
| }, |
| /** |
| @@ -113,30 +141,98 @@ Polymer({ |
| this.set('counters_.' + assert(matches[1]), text); |
| }, |
| + /** |
| + * @return {boolean} Whether the ImportantSites dialog should be shown. |
| + * @private |
| + */ |
| + shouldShowImportantSites_: function() { |
| + if (!this.importantSitesFlagEnabled_) |
| + return false; |
| + if (!this.$.cookiesCheckbox.checked && !this.$.cacheCheckbox.checked) |
| + return false; |
| + |
| + var haveImportantSites = this.importantSites_.length > 0; |
| + chrome.send( |
| + 'metricsHandler:recordBooleanHistogram', |
| + ['History.ClearBrowsingData.ImportantDialogShown', haveImportantSites]); |
| + return haveImportantSites; |
| + }, |
| + |
| /** |
| * Handles the tap on the Clear Data button. |
| * @private |
| */ |
| onClearBrowsingDataTap_: function() { |
| + if (this.shouldShowImportantSites_()) { |
| + this.$.importantSitesDialog.showModal(); |
| + this.$.clearBrowsingDataDialog.close(); |
| + } else { |
| + this.clearBrowsingData_() |
| + } |
| + }, |
| + |
| + /** |
| + * Handles closing of the clear browsing data dialog. Stops the close |
| + * event from propagating if another dialog is shown to prevent the |
| + * privacy-page from closing this dialog. |
| + * @private |
| + */ |
| + onClearBrowsingDataDialogClose_: function(event) { |
| + if (this.$.importantSitesDialog.open) |
| + event.stopPropagation() |
| + }, |
| + |
| + /** |
| + * Clears browsing data and maybe shows a history notice. |
| + * @private |
| + */ |
| + clearBrowsingData_: function() { |
| this.clearingInProgress_ = true; |
| - this.browserProxy_.clearBrowsingData().then( |
| - /** |
| - * @param {boolean} shouldShowNotice Whether we should show the notice |
| - * about other forms of browsing history before closing the dialog. |
| - */ |
| - function(shouldShowNotice) { |
| - this.clearingInProgress_ = false; |
| - this.showHistoryDeletionDialog_ = shouldShowNotice; |
| - |
| - if (!shouldShowNotice) |
| - this.$.dialog.close(); |
| - }.bind(this)); |
| + this.browserProxy_.clearBrowsingData(this.importantSites_) |
| + .then( |
| + /** |
| + * @param {boolean} shouldShowNotice Whether we should show the |
| + * notice about other forms of browsing history before closing the |
| + * dialog. |
| + */ |
| + function(shouldShowNotice) { |
| + this.clearingInProgress_ = false; |
| + this.showHistoryDeletionDialog_ = shouldShowNotice; |
| + |
| + if (!shouldShowNotice) { |
| + closeDialogs_(); |
|
Dan Beam
2017/05/09 19:23:18
fairly sure this should be this.closeDialogs_() an
dullweber
2017/05/11 13:13:47
Done.
|
| + } |
| + }.bind(this)); |
| + }, |
| + |
| + /** |
| + * Closes the clear browsing data or important site dialog if they are open. |
| + * @private |
| + */ |
| + closeDialogs_() { |
|
Dan Beam
2017/05/09 19:23:18
this is an ES6 feature (object literal extensions)
dullweber
2017/05/11 13:13:45
sorry, I compiled without vulcanize and I also jus
|
| + if (this.$.clearBrowsingDataDialog.open) |
| + this.$.clearBrowsingDataDialog.close(); |
| + if (this.$.importantSitesDialog.open) |
| + this.$.importantSitesDialog.close(); |
| }, |
| /** @private */ |
| onCancelTap_: function() { |
| - this.$.dialog.cancel(); |
| + this.$.clearBrowsingDataDialog.cancel(); |
| + }, |
| + |
| + /** |
| + * Handles the tap confirm button in important sites. |
| + * @private |
| + */ |
| + onImportantSitesConfirmTap_: function() { |
| + this.clearBrowsingData_(); |
| + }, |
| + |
| + /** @private */ |
| + onImportantSitesCancelTap_: function() { |
| + this.$.importantSitesDialog.cancel(); |
| }, |
| /** |
| @@ -145,6 +241,6 @@ Polymer({ |
| */ |
| onHistoryDeletionDialogClose_: function() { |
| this.showHistoryDeletionDialog_ = false; |
| - this.$.dialog.close(); |
| - } |
| + closeDialogs_(); |
|
Dan Beam
2017/05/09 19:23:18
same (should be this.closeDialogs_())
dullweber
2017/05/11 13:13:46
Done.
|
| + }, |
| }); |