Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('options', function() { | |
| 6 /** @const */ var OptionsPage = options.OptionsPage; | |
| 7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | |
| 8 | |
| 9 ///////////////////////////////////////////////////////////////////////////// | |
| 10 // WebsiteSettingsManager class: | |
| 11 | |
| 12 /** | |
| 13 * Encapsulated handling of the website settings page. | |
| 14 * @constructor | |
| 15 */ | |
| 16 function WebsiteSettingsManager() { | |
| 17 OptionsPage.call(this, 'websiteSettings', | |
| 18 loadTimeData.getString('websitesOptionsPageTabTitle'), | |
| 19 'website-settings-page'); | |
| 20 } | |
| 21 | |
| 22 cr.addSingletonGetter(WebsiteSettingsManager); | |
| 23 | |
| 24 WebsiteSettingsManager.prototype = { | |
| 25 __proto__: OptionsPage.prototype, | |
| 26 | |
| 27 /** | |
| 28 * The saved origins list. | |
| 29 * @type {OriginList} | |
| 30 * @private | |
| 31 */ | |
| 32 originList_: null, | |
| 33 | |
| 34 /** @override */ | |
| 35 initializePage: function() { | |
| 36 OptionsPage.prototype.initializePage.call(this); | |
| 37 | |
| 38 $('website-settings-overlay-confirm').onclick = | |
| 39 OptionsPage.closeOverlay.bind(OptionsPage); | |
| 40 | |
| 41 $('resourceType').onchange = function() { | |
| 42 var target = event.target; | |
|
Vitaly Pavlenko
2014/09/07 05:14:33
I don't understand why |event| is defined at this
| |
| 43 assert(target.tagName == 'SELECT'); | |
| 44 chrome.send('updateOrigins', [target.value]); | |
| 45 }; | |
| 46 | |
| 47 var searchBox = $('website-settings-search-box'); | |
| 48 searchBox.addEventListener('search', | |
| 49 this.handleSearchQueryChange_.bind(this)); | |
| 50 | |
| 51 searchBox.onkeydown = function(e) { | |
| 52 if (e.keyIdentifier == 'Enter') | |
| 53 e.preventDefault(); | |
| 54 }; | |
| 55 | |
| 56 this.createOriginsList_(); | |
| 57 chrome.send('updateOrigins', ['geolocation']); | |
| 58 }, | |
| 59 | |
| 60 /** | |
| 61 * Creates, decorates and initializes the origin list. | |
| 62 * @private | |
| 63 */ | |
| 64 createOriginsList_: function() { | |
| 65 this.originList_ = this.pageDiv.querySelector('.origin-list'); | |
| 66 options.OriginList.decorate(this.originList_); | |
| 67 this.originList_.autoExpands = true; | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * Populate the origin list with all of the origins with a given permission | |
| 72 * or that are using a given resource. | |
| 73 * @private | |
| 74 */ | |
| 75 populateOrigins_: function(originDict) { | |
| 76 // TODO(dhnishi): Include the last usage time instead of just pushing the | |
| 77 // keys. | |
| 78 this.originList_.dataModel = new ArrayDataModel(Object.keys(originDict)); | |
| 79 }, | |
| 80 | |
| 81 /** | |
| 82 * Update the table with the origins filtered by the value in the search | |
| 83 * box. | |
| 84 * @private | |
| 85 */ | |
| 86 searchOrigins: function() { | |
| 87 var filter = | |
| 88 $('website-settings-search-box').value; | |
| 89 chrome.send('updateOriginsSearchResults', [filter]); | |
| 90 }, | |
| 91 | |
| 92 /** | |
| 93 * Handle and delay search query changes. | |
| 94 * @param {!Event} e The event object. | |
| 95 * @private | |
| 96 */ | |
| 97 handleSearchQueryChange_: function() { | |
| 98 if (this.queryDelayTimerId_) | |
| 99 window.clearTimeout(this.queryDelayTimerId_); | |
| 100 | |
| 101 this.queryDelayTimerId_ = window.setTimeout(this.searchOrigins.bind(this), | |
| 102 160); | |
| 103 }, | |
| 104 }; | |
| 105 | |
| 106 WebsiteSettingsManager.populateOrigins = function(originDict) { | |
| 107 WebsiteSettingsManager.getInstance().populateOrigins_(originDict); | |
| 108 }; | |
| 109 | |
| 110 // Export | |
| 111 return { | |
| 112 WebsiteSettingsManager: WebsiteSettingsManager | |
| 113 }; | |
| 114 }); | |
| OLD | NEW |