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.
5 cr.define('options', function() {
6 /** @const */ var Page = cr.ui.pageManager.Page;
7 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
10 /////////////////////////////////////////////////////////////////////////////
11 // WebsiteSettingsManager class:
14 * Encapsulated handling of the website settings page.
17 function WebsiteSettingsManager() {
18 Page.call(this, 'websiteSettings',
19 loadTimeData.getString('websitesOptionsPageTabTitle'),
20 'website-settings-page');
23 cr.addSingletonGetter(WebsiteSettingsManager);
25 WebsiteSettingsManager.prototype = {
26 __proto__: Page.prototype,
29 * The saved origins list.
36 initializePage: function() {
37 Page.prototype.initializePage.call(this);
39 $('website-settings-overlay-confirm').onclick =
40 PageManager.closeOverlay.bind(PageManager);
42 $('resourceType').onchange = function() {
43 var target = event.target;
44 assert(target.tagName == 'SELECT');
45 if (target.value == 'storage')
46 chrome.send('updateLocalStorage');
48 chrome.send('updateOrigins', [target.value]);
51 var searchBox = $('website-settings-search-box');
52 searchBox.addEventListener('search',
53 this.handleSearchQueryChange_.bind(this));
55 searchBox.onkeydown = function(e) {
56 if (e.keyIdentifier == 'Enter')
60 this.createOriginsList_();
61 chrome.send('updateOrigins', ['geolocation']);
65 * Creates, decorates and initializes the origin list.
68 createOriginsList_: function() {
69 this.originList_ = this.pageDiv.querySelector('.origin-list');
70 options.OriginList.decorate(this.originList_);
71 this.originList_.autoExpands = true;
75 * Populate the origin list with all of the origins with a given permission
76 * or that are using a given resource.
77 * @param {!Object} originDict A dictionary of origins to their usage, which
78 will be used to sort the origins.
81 populateOrigins_: function(originDict) {
82 var origins = Object.keys(originDict).map(function(origin) {
83 // |usage| means the time of last usage in seconds since epoch
84 // (Jan 1, 1970) for permissions and means the amount of local storage
85 // in bytes used for local storage.
88 usage: originDict[origin].usage,
89 usageString: originDict[origin].usageString
92 origins.sort(function(first, second) {
93 return second.usage - first.usage;
95 this.originList_.dataModel = new ArrayDataModel(origins);
99 * Update the table with the origins filtered by the value in the search
103 searchOrigins: function() {
104 var filter = $('website-settings-search-box').value;
105 chrome.send('updateOriginsSearchResults', [filter]);
109 * Handle and delay search query changes.
110 * @param {!Event} e The event object.
113 handleSearchQueryChange_: function() {
114 if (this.queryDelayTimerId_)
115 window.clearTimeout(this.queryDelayTimerId_);
117 this.queryDelayTimerId_ = window.setTimeout(this.searchOrigins.bind(this),
122 WebsiteSettingsManager.populateOrigins = function(originDict) {
123 WebsiteSettingsManager.getInstance().populateOrigins_(originDict);
128 WebsiteSettingsManager: WebsiteSettingsManager