Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/CookieItemsView.js

Issue 2649923006: [DevTools] Add filtering to DOM storages (Closed)
Patch Set: [DevTools] Add filtering to DOM storages Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived 15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission. 16 * from this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30 /** 30 Resources.CookieItemsView = class extends Resources.ItemsView {
31 * @unrestricted 31 /**
32 */ 32 * @param {!Resources.CookieTreeElement} treeElement
33 Resources.CookieItemsView = class extends UI.SimpleView { 33 * @param {!SDK.Target} target
34 * @param {string} cookieDomain
35 */
34 constructor(treeElement, target, cookieDomain) { 36 constructor(treeElement, target, cookieDomain) {
35 super(Common.UIString('Cookies')); 37 super(Common.UIString('Cookies'), 'cookiesPanel');
36 38
37 this.element.classList.add('storage-view'); 39 this.element.classList.add('storage-view');
38 40
39 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete Selected') , 'largeicon-delete');
40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del eteButtonClicked, this);
41
42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg eicon-clear');
43 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clea rButtonClicked, this);
44
45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg eicon-refresh');
46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re freshButtonClicked, this);
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
56 this._target = target; 41 this._target = target;
57 this._treeElement = treeElement; 42 this._treeElement = treeElement;
58 this._cookieDomain = cookieDomain; 43 this._cookieDomain = cookieDomain;
59 44
60 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t rue); 45 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t rue);
46
47 /** @type {?Array<!SDK.Cookie>} */
48 this._cookies = null;
49 this._totalSize = 0;
50 /** @type {?CookieTable.CookiesTable} */
51 this._cookiesTable = null;
61 } 52 }
62 53
63 /** 54 /**
64 * @override
65 * @return {!Array.<!UI.ToolbarItem>}
66 */
67 syncToolbarItems() {
68 return [this._refreshButton, this._clearButton, this._deleteButton, this._fi lterSeparator, this._filterButton];
69 }
70
71 /**
72 * @override
73 */
74 wasShown() {
75 this._update();
76 }
77
78 /**
79 * @override
80 */
81 willHide() {
82 this._deleteButton.setEnabled(false);
83 }
84
85 /**
86 * @param {!Common.Event} event
87 */
88 _filterChanged(event) {
89 var text = this._textFilterUI.value();
90 this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i');
91 this._update();
92 }
93
94 _update() {
95 var resourceURLs = [];
96 var cookieDomain = this._cookieDomain;
97 /**
98 * @param {!SDK.Resource} resource
99 */
100 function populateResourceURLs(resource) {
101 var url = resource.documentURL.asParsedURL();
102 if (url && url.securityOrigin() === cookieDomain)
103 resourceURLs.push(resource.url);
104 }
105
106 SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResou rceURLs);
107 SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCook ies.bind(this));
108 }
109
110 /**
111 * @param {!Array.<!SDK.Cookie>} allCookies 55 * @param {!Array.<!SDK.Cookie>} allCookies
112 */ 56 */
113 _updateWithCookies(allCookies) { 57 _updateWithCookies(allCookies) {
114 this._cookies = allCookies; 58 this._cookies = allCookies;
115 this._totalSize = allCookies.reduce((size, cookie) => size + cookie.size(), 0); 59 this._totalSize = allCookies.reduce((size, cookie) => size + cookie.size(), 0);
116 60
117 if (!this._cookiesTable) { 61 if (!this._cookiesTable) {
118 const parsedURL = this._cookieDomain.asParsedURL(); 62 const parsedURL = this._cookieDomain.asParsedURL();
119 const domain = parsedURL ? parsedURL.host : ''; 63 const domain = parsedURL ? parsedURL.host : '';
120 this._cookiesTable = 64 this._cookiesTable = new CookieTable.CookiesTable(
121 new CookieTable.CookiesTable(false, this._update.bind(this), this._ena bleDeleteButton.bind(this), domain); 65 false, this.refreshItems.bind(this), () => this.setCanDeleteSelected(t rue), domain);
122 } 66 }
123 67
124 var shownCookies = this._filterCookies(this._cookies); 68 var shownCookies = this.filter(allCookies, cookie => `${cookie.name()} ${coo kie.value()} ${cookie.domain()}`);
125 this._cookiesTable.setCookies(shownCookies); 69 this._cookiesTable.setCookies(shownCookies);
126 this._filterBar.show(this.element);
127 this._cookiesTable.show(this.element); 70 this._cookiesTable.show(this.element);
128 this._treeElement.subtitle = 71 this._treeElement.subtitle =
129 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length, Number.bytesToString(this._totalSize)); 72 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length, Number.bytesToString(this._totalSize));
130 this._filterButton.setEnabled(true); 73 this.setCanFilter(true);
131 this._clearButton.setEnabled(true); 74 this.setCanDeleteAll(true);
132 this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie()); 75 this.setCanDeleteSelected(!!this._cookiesTable.selectedCookie());
133 } 76 }
134 77
135 /** 78 /**
136 * @param {!Array.<!SDK.Cookie>} cookies 79 * @override
137 */ 80 */
138 _filterCookies(cookies) { 81 deleteAllItems() {
139 if (!this._filterRegex)
140 return cookies;
141
142 return cookies.filter(cookie => {
143 const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`;
144 return this._filterRegex.test(candidate);
145 });
146 }
147
148 clear() {
149 this._cookiesTable.clear(); 82 this._cookiesTable.clear();
150 this._update(); 83 this.refreshItems();
151 } 84 }
152 85
153 /** 86 /**
154 * @param {!Common.Event} event 87 * @override
155 */ 88 */
156 _clearButtonClicked(event) { 89 deleteSelectedItem() {
157 this.clear();
158 }
159
160 _enableDeleteButton() {
161 this._deleteButton.setEnabled(true);
162 }
163
164 /**
165 * @param {!Common.Event} event
166 */
167 _deleteButtonClicked(event) {
168 var selectedCookie = this._cookiesTable.selectedCookie(); 90 var selectedCookie = this._cookiesTable.selectedCookie();
169 if (selectedCookie) { 91 if (selectedCookie) {
170 selectedCookie.remove(); 92 selectedCookie.remove();
171 this._update(); 93 this.refreshItems();
172 } 94 }
173 } 95 }
174 96
175 /** 97 /**
176 * @param {!Common.Event} event 98 * @override
177 */ 99 */
178 _refreshButtonClicked(event) { 100 refreshItems() {
179 this._update(); 101 var resourceURLs = [];
102 var cookieDomain = this._cookieDomain;
103 /**
104 * @param {!SDK.Resource} resource
105 */
106 function populateResourceURLs(resource) {
107 var url = resource.documentURL.asParsedURL();
108 if (url && url.securityOrigin() === cookieDomain)
109 resourceURLs.push(resource.url);
110 }
111
112 SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResou rceURLs);
113 SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCook ies.bind(this));
180 } 114 }
181 115
182 _contextMenu(event) { 116 _contextMenu(event) {
183 if (!this._cookies.length) { 117 if (!this._cookies.length) {
184 var contextMenu = new UI.ContextMenu(event); 118 var contextMenu = new UI.ContextMenu(event);
185 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this) ); 119 contextMenu.appendItem(Common.UIString('Refresh'), this.refreshItems.bind( this));
dgozman 2017/01/30 21:53:48 I'm curious whether this should go to base class.
eostroukhov 2017/01/31 01:17:34 Done. I changed the menu item to show even when t
186 contextMenu.show(); 120 contextMenu.show();
187 } 121 }
188 } 122 }
189 }; 123 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698