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.
17 function CookiesView(model) {
18 Page.call(this, 'cookies',
19 loadTimeData.getString('cookiesViewPageTabTitle'),
23 cr.addSingletonGetter(CookiesView);
25 CookiesView.prototype = {
26 __proto__: Page.prototype,
29 * The timer id of the timer set on search query change events.
33 queryDelayTimerId_: 0,
36 * The most recent search query, empty string if the query is empty.
43 initializePage: function() {
44 Page.prototype.initializePage.call(this);
46 var searchBox = this.pageDiv.querySelector('.cookies-search-box');
47 searchBox.addEventListener(
48 'search', this.handleSearchQueryChange_.bind(this));
49 searchBox.onkeydown = function(e) {
50 // Prevent the overlay from handling this event.
51 if (e.keyIdentifier == 'Enter')
55 this.pageDiv.querySelector('.remove-all-cookies-button').onclick =
57 chrome.send('removeAllCookies');
60 var cookiesList = this.pageDiv.querySelector('.cookies-list');
61 options.CookiesList.decorate(cookiesList);
63 this.addEventListener('visibleChange', this.handleVisibleChange_);
65 this.pageDiv.querySelector('.cookies-view-overlay-confirm').onclick =
66 PageManager.closeOverlay.bind(PageManager);
70 didShowPage: function() {
71 this.pageDiv.querySelector('.cookies-search-box').value = '';
76 * Search cookie using text in |cookies-search-box|.
78 searchCookie: function() {
79 this.queryDelayTimerId_ = 0;
80 var filter = this.pageDiv.querySelector('.cookies-search-box').value;
81 if (this.lastQuery_ != filter) {
82 this.lastQuery_ = filter;
83 chrome.send('updateCookieSearchResults', [filter]);
88 * Handles search query changes.
89 * @param {!Event} e The event object.
92 handleSearchQueryChange_: function(e) {
93 var stringId = document.querySelector('.cookies-search-box').value ?
94 'remove_all_shown_cookie' : 'remove_all_cookie';
95 document.querySelector('.remove-all-cookies-button').innerHTML =
96 loadTimeData.getString(stringId);
97 if (this.queryDelayTimerId_)
98 window.clearTimeout(this.queryDelayTimerId_);
100 this.queryDelayTimerId_ = window.setTimeout(
101 this.searchCookie.bind(this), 500);
107 * Handler for Page's visible property change event.
108 * @param {Event} e Property change event.
111 handleVisibleChange_: function(e) {
115 chrome.send('reloadCookies');
117 if (!this.initialized_) {
118 this.initialized_ = true;
121 this.pageDiv.querySelector('.cookies-list').redraw();
124 this.pageDiv.querySelector('.cookies-search-box').focus();
128 // CookiesViewHandler callbacks.
129 CookiesView.onTreeItemAdded = function(args) {
130 $('cookies-list').addByParentId(args[0], args[1], args[2]);
133 CookiesView.onTreeItemRemoved = function(args) {
134 $('cookies-list').removeByParentId(args[0], args[1], args[2]);
137 CookiesView.loadChildren = function(args) {
138 $('cookies-list').loadChildren(args[0], args[1]);
143 CookiesView: CookiesView