1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('options', function() {
var OptionsPage = options.OptionsPage;
/////////////////////////////////////////////////////////////////////////////
// CookiesView class:
/**
* Encapsulated handling of the cookies and other site data page.
* @constructor
*/
function CookiesView(model) {
OptionsPage.call(this, 'cookies',
templateData.cookiesViewPageTabTitle,
'cookiesViewPage');
}
cr.addSingletonGetter(CookiesView);
CookiesView.prototype = {
__proto__: OptionsPage.prototype,
/**
* The timer id of the timer set on search query change events.
* @type {number}
* @private
*/
queryDelayTimerId_: 0,
/**
* The most recent search query, or null if the query is empty.
* @type {?string}
* @private
*/
lastQuery_ : null,
initializePage: function() {
OptionsPage.prototype.initializePage.call(this);
$('cookies-search-box').addEventListener('search',
this.handleSearchQueryChange_.bind(this));
$('remove-all-cookies-button').onclick = function(e) {
chrome.send('removeAllCookies', []);
};
var cookiesList = $('cookies-list');
options.CookiesList.decorate(cookiesList);
window.addEventListener('resize', this.handleResize_.bind(this));
this.addEventListener('visibleChange', this.handleVisibleChange_);
},
/**
* Search cookie using text in |cookies-search-box|.
*/
searchCookie: function() {
this.queryDelayTimerId_ = 0;
var filter = $('cookies-search-box').value;
if (this.lastQuery_ != filter) {
this.lastQuery_ = filter;
chrome.send('updateCookieSearchResults', [filter]);
}
},
/**
* Handles search query changes.
* @param {!Event} e The event object.
* @private
*/
handleSearchQueryChange_: function(e) {
if (this.queryDelayTimerId_)
window.clearTimeout(this.queryDelayTimerId_);
this.queryDelayTimerId_ = window.setTimeout(
this.searchCookie.bind(this), 500);
},
initialized_: false,
/**
* Handler for OptionsPage's visible property change event.
* @param {Event} e Property change event.
* @private
*/
handleVisibleChange_: function(e) {
if (!this.visible)
return;
// Resize the cookies list whenever the options page becomes visible.
this.handleResize_(null);
if (!this.initialized_) {
this.initialized_ = true;
this.searchCookie();
} else {
$('cookies-list').redraw();
}
$('cookies-search-box').focus();
},
/**
* Handler for when the window changes size. Resizes the cookies list to
* match the window height.
* @param {?Event} e Window resize event, or null if called directly.
* @private
*/
handleResize_: function(e) {
if (!this.visible)
return;
var cookiesList = $('cookies-list');
// 25 pixels from the window bottom seems like a visually pleasing amount.
var height = window.innerHeight - cookiesList.offsetTop - 25;
cookiesList.style.height = height + 'px';
},
};
// CookiesViewHandler callbacks.
CookiesView.onTreeItemAdded = function(args) {
$('cookies-list').addByParentId(args[0], args[1], args[2]);
};
CookiesView.onTreeItemRemoved = function(args) {
$('cookies-list').removeByParentId(args[0], args[1], args[2]);
};
CookiesView.loadChildren = function(args) {
$('cookies-list').loadChildren(args[0], args[1]);
};
// Export
return {
CookiesView: CookiesView
};
});
|