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

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

Issue 2623063003: DevTools: Fix getCookies to report for all resources (Closed)
Patch Set: audit and line length fixes Created 3 years, 11 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.
(...skipping 13 matching lines...) Expand all
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 /**
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, target, 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 Selected') , 'largeicon-delete'); 39 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete Selected') , 'largeicon-delete');
40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del eteButtonClicked, this); 40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del eteButtonClicked, this);
41 41
42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg eicon-clear'); 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); 43 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clea rButtonClicked, this);
44 44
45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg eicon-refresh'); 45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg eicon-refresh');
46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re freshButtonClicked, this); 46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re freshButtonClicked, this);
47 47
48 this._filterBar = new UI.FilterBar('cookiesPanel', true); 48 this._filterBar = new UI.FilterBar('cookiesPanel', true);
49 this._textFilterUI = new UI.TextFilterUI(true); 49 this._textFilterUI = new UI.TextFilterUI(true);
50 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._ filterChanged, this); 50 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._ filterChanged, this);
51 this._filterBar.addFilter(this._textFilterUI); 51 this._filterBar.addFilter(this._textFilterUI);
52 52
53 this._filterSeparator = new UI.ToolbarSeparator(); 53 this._filterSeparator = new UI.ToolbarSeparator();
54 this._filterButton = this._filterBar.filterButton(); 54 this._filterButton = this._filterBar.filterButton();
55 55
56 this._target = target;
56 this._treeElement = treeElement; 57 this._treeElement = treeElement;
57 this._cookieDomain = cookieDomain; 58 this._cookieDomain = cookieDomain;
58 59
59 this._emptyWidget = new UI.EmptyWidget( 60 this._emptyWidget = new UI.EmptyWidget(
60 cookieDomain ? 61 cookieDomain ?
61 Common.UIString('This site has no cookies.') : 62 Common.UIString('This site has no cookies.') :
62 Common.UIString( 63 Common.UIString(
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. ')); 64 'By default cookies are disabled for local files.\nYou could ove rride this by starting the browser with --enable-file-cookies command line flag. '));
64 this._emptyWidget.show(this.element); 65 this._emptyWidget.show(this.element);
65 66
(...skipping 25 matching lines...) Expand all
91 /** 92 /**
92 * @param {!Common.Event} event 93 * @param {!Common.Event} event
93 */ 94 */
94 _filterChanged(event) { 95 _filterChanged(event) {
95 var text = this._textFilterUI.value(); 96 var text = this._textFilterUI.value();
96 this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i'); 97 this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i');
97 this._update(); 98 this._update();
98 } 99 }
99 100
100 _update() { 101 _update() {
101 SDK.Cookies.getCookiesAsync(this._updateWithCookies.bind(this)); 102 var resourceURLs = [];
103 var cookieDomain = this._cookieDomain;
104 function populateResourceURLs(resource) {
pfeldman 2017/01/13 02:17:34 You should annotate all function parameters for co
phulce 2017/01/18 00:52:34 Done.
105 var url = resource.documentURL.asParsedURL();
106 if (url && url.securityOrigin() === cookieDomain)
107 resourceURLs.push(resource.url);
108 }
109
110 SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResou rceURLs);
111 SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCook ies.bind(this));
102 } 112 }
103 113
104 /** 114 /**
105 * @param {!Array.<!SDK.Cookie>} allCookies 115 * @param {!Array.<!SDK.Cookie>} allCookies
106 */ 116 */
107 _updateWithCookies(allCookies) { 117 _updateWithCookies(allCookies) {
108 this._cookies = this._filterCookiesForDomain(allCookies); 118 this._cookies = allCookies;
119 this._totalSize = allCookies.reduce((size, cookie) => size + cookie.size(), 0);
pfeldman 2017/01/13 02:17:34 Not sure why total size would matter :)
phulce 2017/01/18 00:52:34 it's pre-existing, used for display
109 120
110 if (!this._cookies.length) { 121 if (!this._cookies.length) {
111 // Nothing to show. 122 // Nothing to show.
112 this._emptyWidget.show(this.element); 123 this._emptyWidget.show(this.element);
113 this._filterButton.setEnabled(false); 124 this._filterButton.setEnabled(false);
114 this._clearButton.setEnabled(false); 125 this._clearButton.setEnabled(false);
115 this._deleteButton.setEnabled(false); 126 this._deleteButton.setEnabled(false);
116 if (this._cookiesTable) 127 if (this._cookiesTable)
117 this._cookiesTable.detach(); 128 this._cookiesTable.detach();
118 return; 129 return;
119 } 130 }
120 131
121 if (!this._cookiesTable) { 132 if (!this._cookiesTable) {
122 this._cookiesTable = 133 this._cookiesTable =
123 new CookieTable.CookiesTable(false, this._update.bind(this), this._ena bleDeleteButton.bind(this)); 134 new CookieTable.CookiesTable(false, this._update.bind(this), this._ena bleDeleteButton.bind(this));
124 } 135 }
125 136
126 var shownCookies = this._filterCookiesForFilters(this._cookies); 137 var shownCookies = this._filterCookies(this._cookies);
127 this._cookiesTable.setCookies(shownCookies); 138 this._cookiesTable.setCookies(shownCookies);
128 this._emptyWidget.detach(); 139 this._emptyWidget.detach();
129 this._cookiesTable.show(this.element); 140 this._cookiesTable.show(this.element);
130 this._filterBar.show(this.element); 141 this._filterBar.show(this.element);
131 this._treeElement.subtitle = 142 this._treeElement.subtitle =
132 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length, Number.bytesToString(this._totalSize)); 143 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length, Number.bytesToString(this._totalSize));
133 this._filterButton.setEnabled(true); 144 this._filterButton.setEnabled(true);
134 this._clearButton.setEnabled(true); 145 this._clearButton.setEnabled(true);
135 this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie()); 146 this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie());
136 } 147 }
137 148
138 /** 149 /**
139 * @param {!Array.<!SDK.Cookie>} cookies 150 * @param {!Array.<!SDK.Cookie>} cookies
140 */ 151 */
141 _filterCookiesForFilters(cookies) { 152 _filterCookies(cookies) {
142 if (!this._filterRegex) 153 if (!this._filterRegex)
143 return cookies; 154 return cookies;
144 155
145 return cookies.filter(cookie => { 156 return cookies.filter(cookie => {
146 const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`; 157 const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`;
147 return this._filterRegex.test(candidate); 158 return this._filterRegex.test(candidate);
148 }); 159 });
149 } 160 }
150 161
151 /**
152 * @param {!Array.<!SDK.Cookie>} allCookies
153 */
154 _filterCookiesForDomain(allCookies) {
155 var cookies = [];
156 var resourceURLsForDocumentURL = [];
157 this._totalSize = 0;
158
159 /**
160 * @this {Resources.CookieItemsView}
161 */
162 function populateResourcesForDocuments(resource) {
163 var url = resource.documentURL.asParsedURL();
164 if (url && url.securityOrigin() === this._cookieDomain)
165 resourceURLsForDocumentURL.push(resource.url);
166 }
167 Bindings.forAllResources(populateResourcesForDocuments.bind(this));
168
169 for (var i = 0; i < allCookies.length; ++i) {
170 var pushed = false;
171 var size = allCookies[i].size();
172 for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) {
173 var resourceURL = resourceURLsForDocumentURL[j];
174 if (SDK.Cookies.cookieMatchesResourceURL(allCookies[i], resourceURL)) {
175 this._totalSize += size;
176 if (!pushed) {
177 pushed = true;
178 cookies.push(allCookies[i]);
179 }
180 }
181 }
182 }
183 return cookies;
184 }
185
186 clear() { 162 clear() {
187 this._cookiesTable.clear(); 163 this._cookiesTable.clear();
188 this._update(); 164 this._update();
189 } 165 }
190 166
191 /** 167 /**
192 * @param {!Common.Event} event 168 * @param {!Common.Event} event
193 */ 169 */
194 _clearButtonClicked(event) { 170 _clearButtonClicked(event) {
195 this.clear(); 171 this.clear();
(...skipping 22 matching lines...) Expand all
218 } 194 }
219 195
220 _contextMenu(event) { 196 _contextMenu(event) {
221 if (!this._cookies.length) { 197 if (!this._cookies.length) {
222 var contextMenu = new UI.ContextMenu(event); 198 var contextMenu = new UI.ContextMenu(event);
223 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this) ); 199 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this) );
224 contextMenu.show(); 200 contextMenu.show();
225 } 201 }
226 } 202 }
227 }; 203 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698