OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 /** | 30 /** |
31 * @unrestricted | 31 * @unrestricted |
32 */ | 32 */ |
33 Resources.CookieItemsView = class extends UI.SimpleView { | 33 Resources.CookieItemsView = class extends UI.SimpleView { |
34 constructor(treeElement, cookieDomain) { | 34 constructor(treeElement, cookieDomain) { |
35 super(Common.UIString('Cookies')); | 35 super(Common.UIString('Cookies')); |
36 | 36 |
37 this.element.classList.add('storage-view'); | 37 this.element.classList.add('storage-view'); |
38 | 38 |
39 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largei
con-delete'); | 39 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete Selected')
, 'largeicon-delete'); |
40 this._deleteButton.setVisible(false); | |
41 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del
eteButtonClicked, this); | 40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del
eteButtonClicked, this); |
42 | 41 |
43 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear'), 'largeico
n-clear'); | 42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg
eicon-clear'); |
44 this._clearButton.setVisible(false); | |
45 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clea
rButtonClicked, this); | 43 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clea
rButtonClicked, this); |
46 | 44 |
47 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); | 45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); |
48 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re
freshButtonClicked, this); | 46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re
freshButtonClicked, this); |
49 | 47 |
| 48 this._filterBar = new UI.FilterBar('cookiesPanel', true); |
| 49 this._textFilterUI = new UI.TextFilterUI(true); |
| 50 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._
filterChanged, this); |
| 51 this._filterBar.addFilter(this._textFilterUI); |
| 52 |
| 53 this._filterSeparator = new UI.ToolbarSeparator(); |
| 54 this._filterButton = this._filterBar.filterButton(); |
| 55 |
50 this._treeElement = treeElement; | 56 this._treeElement = treeElement; |
51 this._cookieDomain = cookieDomain; | 57 this._cookieDomain = cookieDomain; |
52 | 58 |
53 this._emptyWidget = new UI.EmptyWidget( | 59 this._emptyWidget = new UI.EmptyWidget( |
54 cookieDomain ? | 60 cookieDomain ? |
55 Common.UIString('This site has no cookies.') : | 61 Common.UIString('This site has no cookies.') : |
56 Common.UIString( | 62 Common.UIString( |
57 'By default cookies are disabled for local files.\nYou could ove
rride this by starting the browser with --enable-file-cookies command line flag.
')); | 63 'By default cookies are disabled for local files.\nYou could ove
rride this by starting the browser with --enable-file-cookies command line flag.
')); |
58 this._emptyWidget.show(this.element); | 64 this._emptyWidget.show(this.element); |
59 | 65 |
60 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t
rue); | 66 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t
rue); |
61 } | 67 } |
62 | 68 |
63 /** | 69 /** |
64 * @override | 70 * @override |
65 * @return {!Array.<!UI.ToolbarItem>} | 71 * @return {!Array.<!UI.ToolbarItem>} |
66 */ | 72 */ |
67 syncToolbarItems() { | 73 syncToolbarItems() { |
68 return [this._refreshButton, this._clearButton, this._deleteButton]; | 74 return [ |
| 75 this._refreshButton, this._clearButton, this._deleteButton, |
| 76 this._filterSeparator, this._filterButton |
| 77 ]; |
69 } | 78 } |
70 | 79 |
71 /** | 80 /** |
72 * @override | 81 * @override |
73 */ | 82 */ |
74 wasShown() { | 83 wasShown() { |
75 this._update(); | 84 this._update(); |
76 } | 85 } |
77 | 86 |
78 /** | 87 /** |
79 * @override | 88 * @override |
80 */ | 89 */ |
81 willHide() { | 90 willHide() { |
82 this._deleteButton.setVisible(false); | 91 this._deleteButton.setEnabled(false); |
| 92 } |
| 93 |
| 94 /** |
| 95 * @param {!Common.Event} event |
| 96 */ |
| 97 _filterChanged(event) { |
| 98 var text = this._textFilterUI.value(); |
| 99 this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i'); |
| 100 this._update(); |
83 } | 101 } |
84 | 102 |
85 _update() { | 103 _update() { |
86 SDK.Cookies.getCookiesAsync(this._updateWithCookies.bind(this)); | 104 SDK.Cookies.getCookiesAsync(this._updateWithCookies.bind(this)); |
87 } | 105 } |
88 | 106 |
89 /** | 107 /** |
90 * @param {!Array.<!SDK.Cookie>} allCookies | 108 * @param {!Array.<!SDK.Cookie>} allCookies |
91 */ | 109 */ |
92 _updateWithCookies(allCookies) { | 110 _updateWithCookies(allCookies) { |
93 this._cookies = this._filterCookiesForDomain(allCookies); | 111 this._cookies = this._filterCookiesForDomain(allCookies); |
94 | 112 |
95 if (!this._cookies.length) { | 113 if (!this._cookies.length) { |
96 // Nothing to show. | 114 // Nothing to show. |
97 this._emptyWidget.show(this.element); | 115 this._emptyWidget.show(this.element); |
98 this._clearButton.setVisible(false); | 116 this._filterButton.setEnabled(false); |
99 this._deleteButton.setVisible(false); | 117 this._clearButton.setEnabled(false); |
| 118 this._deleteButton.setEnabled(false); |
100 if (this._cookiesTable) | 119 if (this._cookiesTable) |
101 this._cookiesTable.detach(); | 120 this._cookiesTable.detach(); |
102 return; | 121 return; |
103 } | 122 } |
104 | 123 |
105 if (!this._cookiesTable) { | 124 if (!this._cookiesTable) { |
106 this._cookiesTable = | 125 this._cookiesTable = |
107 new Components.CookiesTable(false, this._update.bind(this), this._show
DeleteButton.bind(this)); | 126 new Components.CookiesTable(false, this._update.bind(this), this._enab
leDeleteButton.bind(this)); |
108 } | 127 } |
109 | 128 |
110 this._cookiesTable.setCookies(this._cookies); | 129 var shownCookies = this._filterCookiesForFilters(this._cookies); |
| 130 this._cookiesTable.setCookies(shownCookies); |
111 this._emptyWidget.detach(); | 131 this._emptyWidget.detach(); |
112 this._cookiesTable.show(this.element); | 132 this._cookiesTable.show(this.element); |
| 133 this._filterBar.show(this.element); |
113 this._treeElement.subtitle = | 134 this._treeElement.subtitle = |
114 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length,
Number.bytesToString(this._totalSize)); | 135 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length,
Number.bytesToString(this._totalSize)); |
115 this._clearButton.setVisible(true); | 136 this._filterButton.setEnabled(true); |
116 this._deleteButton.setVisible(!!this._cookiesTable.selectedCookie()); | 137 this._clearButton.setEnabled(true); |
| 138 this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie()); |
117 } | 139 } |
118 | 140 |
119 /** | 141 /** |
| 142 * @param {!Array.<!SDK.Cookie>} cookies |
| 143 */ |
| 144 _filterCookiesForFilters(cookies) { |
| 145 if (!this._filterRegex) |
| 146 return cookies; |
| 147 |
| 148 return cookies.filter(cookie => { |
| 149 const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`; |
| 150 return this._filterRegex.test(candidate); |
| 151 }); |
| 152 } |
| 153 |
| 154 /** |
120 * @param {!Array.<!SDK.Cookie>} allCookies | 155 * @param {!Array.<!SDK.Cookie>} allCookies |
121 */ | 156 */ |
122 _filterCookiesForDomain(allCookies) { | 157 _filterCookiesForDomain(allCookies) { |
123 var cookies = []; | 158 var cookies = []; |
124 var resourceURLsForDocumentURL = []; | 159 var resourceURLsForDocumentURL = []; |
125 this._totalSize = 0; | 160 this._totalSize = 0; |
126 | 161 |
127 /** | 162 /** |
128 * @this {Resources.CookieItemsView} | 163 * @this {Resources.CookieItemsView} |
129 */ | 164 */ |
(...skipping 26 matching lines...) Expand all Loading... |
156 this._update(); | 191 this._update(); |
157 } | 192 } |
158 | 193 |
159 /** | 194 /** |
160 * @param {!Common.Event} event | 195 * @param {!Common.Event} event |
161 */ | 196 */ |
162 _clearButtonClicked(event) { | 197 _clearButtonClicked(event) { |
163 this.clear(); | 198 this.clear(); |
164 } | 199 } |
165 | 200 |
166 _showDeleteButton() { | 201 _enableDeleteButton() { |
167 this._deleteButton.setVisible(true); | 202 this._deleteButton.setEnabled(true); |
168 } | 203 } |
169 | 204 |
170 /** | 205 /** |
171 * @param {!Common.Event} event | 206 * @param {!Common.Event} event |
172 */ | 207 */ |
173 _deleteButtonClicked(event) { | 208 _deleteButtonClicked(event) { |
174 var selectedCookie = this._cookiesTable.selectedCookie(); | 209 var selectedCookie = this._cookiesTable.selectedCookie(); |
175 if (selectedCookie) { | 210 if (selectedCookie) { |
176 selectedCookie.remove(); | 211 selectedCookie.remove(); |
177 this._update(); | 212 this._update(); |
178 } | 213 } |
179 } | 214 } |
180 | 215 |
181 /** | 216 /** |
182 * @param {!Common.Event} event | 217 * @param {!Common.Event} event |
183 */ | 218 */ |
184 _refreshButtonClicked(event) { | 219 _refreshButtonClicked(event) { |
185 this._update(); | 220 this._update(); |
186 } | 221 } |
187 | 222 |
188 _contextMenu(event) { | 223 _contextMenu(event) { |
189 if (!this._cookies.length) { | 224 if (!this._cookies.length) { |
190 var contextMenu = new UI.ContextMenu(event); | 225 var contextMenu = new UI.ContextMenu(event); |
191 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this)
); | 226 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this)
); |
192 contextMenu.show(); | 227 contextMenu.show(); |
193 } | 228 } |
194 } | 229 } |
195 }; | 230 }; |
OLD | NEW |