• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2011 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
5cr.define('options', function() {
6
7  var OptionsPage = options.OptionsPage;
8
9  /////////////////////////////////////////////////////////////////////////////
10  // CookiesView class:
11
12  /**
13   * Encapsulated handling of the cookies and other site data page.
14   * @constructor
15   */
16  function CookiesView(model) {
17    OptionsPage.call(this, 'cookies',
18                     templateData.cookiesViewPageTabTitle,
19                     'cookiesViewPage');
20  }
21
22  cr.addSingletonGetter(CookiesView);
23
24  CookiesView.prototype = {
25    __proto__: OptionsPage.prototype,
26
27    initializePage: function() {
28      OptionsPage.prototype.initializePage.call(this);
29
30      $('cookies-search-box').addEventListener('search',
31          this.handleSearchQueryChange_.bind(this));
32
33      $('remove-all-cookies-button').onclick = function(e) {
34        chrome.send('removeAllCookies', []);
35      };
36
37      var cookiesList = $('cookies-list');
38      options.CookiesList.decorate(cookiesList);
39
40      this.addEventListener('visibleChange', this.handleVisibleChange_);
41    },
42
43    lastQuery_ : null,
44
45    /**
46     * Search cookie using text in cookiesSearchBox.
47     */
48    searchCookie: function() {
49      this.queryDelayTimerId_ = 0;
50      var filter = $('cookies-search-box').value;
51      if (this.lastQuery_ != filter) {
52        this.lastQuery_ = filter;
53        chrome.send('updateCookieSearchResults', [filter]);
54      }
55    },
56
57    queryDelayTimerId_: 0,
58
59    /**
60     * Handles search query changes.
61     * @private
62     * @param {!Event} e The event object.
63     */
64    handleSearchQueryChange_: function(e) {
65      if (this.queryDelayTimerId_)
66        window.clearTimeout(this.queryDelayTimerId_);
67
68      this.queryDelayTimerId_ = window.setTimeout(
69          this.searchCookie.bind(this), 500);
70    },
71
72    initialized_: false,
73
74    /**
75     * Handler for OptionsPage's visible property change event.
76     * @private
77     * @param {Event} e Property change event.
78     */
79    handleVisibleChange_: function(e) {
80      if (!this.visible)
81        return;
82      if (!this.initialized_) {
83        this.initialized_ = true;
84        this.searchCookie();
85      } else {
86        $('cookies-list').redraw();
87      }
88    },
89  };
90
91  // CookiesViewHandler callbacks.
92  CookiesView.onTreeItemAdded = function(args) {
93    $('cookies-list').addByParentId(args[0], args[1], args[2]);
94  };
95
96  CookiesView.onTreeItemRemoved = function(args) {
97    $('cookies-list').removeByParentId(args[0], args[1], args[2]);
98  };
99
100  CookiesView.loadChildren = function(args) {
101    $('cookies-list').loadChildren(args[0], args[1]);
102  };
103
104  // Export
105  return {
106    CookiesView: CookiesView
107  };
108
109});
110