1 // Copyright (c) 2012 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() {
7 var Page
= cr
.ui
.pageManager
.Page
;
8 var PageManager
= cr
.ui
.pageManager
.PageManager
;
10 /////////////////////////////////////////////////////////////////////////////
14 * Encapsulated handling of the cookies and other site data page.
16 * @extends {cr.ui.pageManager.Page}
18 function CookiesView(model
) {
19 Page
.call(this, 'cookies',
20 loadTimeData
.getString('cookiesViewPageTabTitle'),
24 cr
.addSingletonGetter(CookiesView
);
26 CookiesView
.prototype = {
27 __proto__
: Page
.prototype,
30 * The timer id of the timer set on search query change events.
34 queryDelayTimerId_
: 0,
37 * The most recent search query, empty string if the query is empty.
44 initializePage: function() {
45 Page
.prototype.initializePage
.call(this);
47 var searchBox
= this.pageDiv
.querySelector('.cookies-search-box');
48 searchBox
.addEventListener(
49 'search', this.handleSearchQueryChange_
.bind(this));
50 searchBox
.onkeydown = function(e
) {
51 // Prevent the overlay from handling this event.
52 if (e
.keyIdentifier
== 'Enter')
56 this.pageDiv
.querySelector('.remove-all-cookies-button').onclick
=
58 chrome
.send('removeAllCookies');
61 var cookiesList
= this.pageDiv
.querySelector('.cookies-list');
62 options
.CookiesList
.decorate(cookiesList
);
64 this.addEventListener('visibleChange', this.handleVisibleChange_
);
66 this.pageDiv
.querySelector('.cookies-view-overlay-confirm').onclick
=
67 PageManager
.closeOverlay
.bind(PageManager
);
71 didShowPage: function() {
72 this.pageDiv
.querySelector('.cookies-search-box').value
= '';
77 * Search cookie using text in |cookies-search-box|.
79 searchCookie: function() {
80 this.queryDelayTimerId_
= 0;
81 var filter
= this.pageDiv
.querySelector('.cookies-search-box').value
;
82 if (this.lastQuery_
!= filter
) {
83 this.lastQuery_
= filter
;
84 chrome
.send('updateCookieSearchResults', [filter
]);
89 * Handles search query changes.
90 * @param {!Event} e The event object.
93 handleSearchQueryChange_: function(e
) {
94 var stringId
= document
.querySelector('.cookies-search-box').value
?
95 'remove_all_shown_cookie' : 'remove_all_cookie';
96 document
.querySelector('.remove-all-cookies-button').innerHTML
=
97 loadTimeData
.getString(stringId
);
98 if (this.queryDelayTimerId_
)
99 window
.clearTimeout(this.queryDelayTimerId_
);
101 this.queryDelayTimerId_
= window
.setTimeout(
102 this.searchCookie
.bind(this), 500);
108 * Handler for Page's visible property change event.
109 * @param {Event} e Property change event.
112 handleVisibleChange_: function(e
) {
116 chrome
.send('reloadCookies');
118 if (!this.initialized_
) {
119 this.initialized_
= true;
122 this.pageDiv
.querySelector('.cookies-list').redraw();
125 this.pageDiv
.querySelector('.cookies-search-box').focus();
129 // CookiesViewHandler callbacks.
130 CookiesView
.onTreeItemAdded = function(args
) {
131 $('cookies-list').addByParentId(args
[0], args
[1], args
[2]);
134 CookiesView
.onTreeItemRemoved = function(args
) {
135 $('cookies-list').removeByParentId(args
[0], args
[1], args
[2]);
138 CookiesView
.loadChildren = function(args
) {
139 $('cookies-list').loadChildren(args
[0], args
[1]);
144 CookiesView
: CookiesView