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

Side by Side Diff: chrome/tools/test/reference_build/chrome_linux/resources/inspector/CookieItemsView.js

Issue 177049: On Linux, move the passing of filedescriptors to a dedicated socketpair(). (Closed)
Patch Set: Removed *.d files from reference build Created 11 years, 3 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
(Empty)
1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
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
16 * from this software without specific prior written permission.
17 *
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
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
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 WebInspector.CookieItemsView = function()
31 {
32 WebInspector.View.call(this);
33
34 this.element.addStyleClass("storage-view");
35 this.element.addStyleClass("table");
36
37 this.deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString(" Delete"), "delete-storage-status-bar-item");
38 this.deleteButton.visible = false;
39 this.deleteButton.addEventListener("click", this._deleteButtonClicked.bind(t his), false);
40
41 this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString( "Refresh"), "refresh-storage-status-bar-item");
42 this.refreshButton.addEventListener("click", this._refreshButtonClicked.bind (this), false);
43 }
44
45 WebInspector.CookieItemsView.prototype = {
46 get statusBarItems()
47 {
48 return [this.refreshButton.element, this.deleteButton.element];
49 },
50
51 show: function(parentElement)
52 {
53 WebInspector.View.prototype.show.call(this, parentElement);
54 this.update();
55 },
56
57 hide: function()
58 {
59 WebInspector.View.prototype.hide.call(this);
60 this.deleteButton.visible = false;
61 },
62
63 update: function()
64 {
65 this.element.removeChildren();
66
67 var self = this;
68 function callback(cookies, isAdvanced) {
69 var dataGrid = (isAdvanced ? self.dataGridForCookies(cookies) : self .simpleDataGridForCookies(cookies));
70 if (dataGrid) {
71 self._dataGrid = dataGrid;
72 self.element.appendChild(dataGrid.element);
73 if (isAdvanced)
74 self.deleteButton.visible = true;
75 } else {
76 var emptyMsgElement = document.createElement("div");
77 emptyMsgElement.className = "storage-table-empty";
78 emptyMsgElement.textContent = WebInspector.UIString("This site h as no cookies.");
79 self.element.appendChild(emptyMsgElement);
80 self._dataGrid = null;
81 self.deleteButton.visible = false;
82 }
83 }
84
85 WebInspector.Cookies.getCookiesAsync(callback);
86 },
87
88 dataGridForCookies: function(cookies)
89 {
90 if (!cookies.length)
91 return null;
92
93 for (var i = 0; i < cookies.length; ++i)
94 cookies[i].expires = new Date(cookies[i].expires);
95
96 var columns = { 0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {} } ;
97 columns[0].title = WebInspector.UIString("Name");
98 columns[0].width = columns[0].title.length;
99 columns[1].title = WebInspector.UIString("Value");
100 columns[1].width = columns[1].title.length;
101 columns[2].title = WebInspector.UIString("Domain");
102 columns[2].width = columns[2].title.length;
103 columns[3].title = WebInspector.UIString("Path");
104 columns[3].width = columns[3].title.length;
105 columns[4].title = WebInspector.UIString("Expires");
106 columns[4].width = columns[4].title.length;
107 columns[5].title = WebInspector.UIString("Size");
108 columns[5].width = columns[5].title.length;
109 columns[5].aligned = "right";
110 columns[6].title = WebInspector.UIString("HTTP");
111 columns[6].width = columns[6].title.length;
112 columns[6].aligned = "centered";
113 columns[7].title = WebInspector.UIString("Secure");
114 columns[7].width = columns[7].title.length;
115 columns[7].aligned = "centered";
116
117 function updateDataAndColumn(index, value) {
118 data[index] = value;
119 if (value.length > columns[index].width)
120 columns[index].width = value.length;
121 }
122
123 var data;
124 var nodes = [];
125 for (var i = 0; i < cookies.length; ++i) {
126 var cookie = cookies[i];
127 data = {};
128
129 updateDataAndColumn(0, cookie.name);
130 updateDataAndColumn(1, cookie.value);
131 updateDataAndColumn(2, cookie.domain);
132 updateDataAndColumn(3, cookie.path);
133 updateDataAndColumn(4, (cookie.session ? WebInspector.UIString("Sess ion") : cookie.expires.toGMTString()));
134 updateDataAndColumn(5, Number.bytesToString(cookie.size, WebInspecto r.UIString));
135 updateDataAndColumn(6, (cookie.httpOnly ? "\u2713" : "")); // Checkm ark
136 updateDataAndColumn(7, (cookie.secure ? "\u2713" : "")); // Checkmar k
137
138 var node = new WebInspector.DataGridNode(data, false);
139 node.cookie = cookie;
140 node.selectable = true;
141 nodes.push(node);
142 }
143
144 var totalColumnWidths = 0;
145 for (var columnIdentifier in columns)
146 totalColumnWidths += columns[columnIdentifier].width;
147
148 // Enforce the Value column (the 2nd column) to be a max of 33%
149 // tweaking the raw total width because may massively outshadow the othe rs
150 var valueColumnWidth = columns[1].width;
151 if (valueColumnWidth / totalColumnWidths > 0.33) {
152 totalColumnWidths -= valueColumnWidth;
153 totalColumnWidths *= 1.33;
154 columns[1].width = totalColumnWidths * 0.33;
155 }
156
157 // Calculate the percentage width for the columns.
158 const minimumPrecent = 6;
159 var recoupPercent = 0;
160 for (var columnIdentifier in columns) {
161 var width = columns[columnIdentifier].width;
162 width = Math.round((width / totalColumnWidths) * 100);
163 if (width < minimumPrecent) {
164 recoupPercent += (minimumPrecent - width);
165 width = minimumPrecent;
166 }
167 columns[columnIdentifier].width = width;
168 }
169
170 // Enforce the minimum percentage width. (need to narrow total percentag e due to earlier additions)
171 while (recoupPercent > 0) {
172 for (var columnIdentifier in columns) {
173 if (columns[columnIdentifier].width > minimumPrecent) {
174 --columns[columnIdentifier].width;
175 --recoupPercent;
176 if (!recoupPercent)
177 break;
178 }
179 }
180 }
181
182 for (var columnIdentifier in columns)
183 columns[columnIdentifier].width += "%";
184
185 var dataGrid = new WebInspector.DataGrid(columns);
186 var length = nodes.length;
187 for (var i = 0; i < length; ++i)
188 dataGrid.appendChild(nodes[i]);
189 if (length > 0)
190 nodes[0].selected = true;
191
192 return dataGrid;
193 },
194
195 simpleDataGridForCookies: function(cookies)
196 {
197 if (!cookies.length)
198 return null;
199
200 var columns = {};
201 columns[0] = {};
202 columns[1] = {};
203 columns[0].title = WebInspector.UIString("Name");
204 columns[0].width = columns[0].title.length;
205 columns[1].title = WebInspector.UIString("Value");
206 columns[1].width = columns[1].title.length;
207
208 var nodes = [];
209 for (var i = 0; i < cookies.length; ++i) {
210 var cookie = cookies[i];
211 var data = {};
212
213 var name = cookie.name;
214 data[0] = name;
215 if (name.length > columns[0].width)
216 columns[0].width = name.length;
217
218 var value = cookie.value;
219 data[1] = value;
220 if (value.length > columns[1].width)
221 columns[1].width = value.length;
222
223 var node = new WebInspector.DataGridNode(data, false);
224 node.selectable = true;
225 nodes.push(node);
226 }
227
228 var totalColumnWidths = columns[0].width + columns[1].width;
229 var width = Math.round((columns[0].width * 100) / totalColumnWidths);
230 const minimumPrecent = 20;
231 if (width < minimumPrecent)
232 width = minimumPrecent;
233 if (width > 100 - minimumPrecent)
234 width = 100 - minimumPrecent;
235 columns[0].width = width;
236 columns[1].width = 100 - width;
237 columns[0].width += "%";
238 columns[1].width += "%";
239
240 var dataGrid = new WebInspector.DataGrid(columns);
241 var length = nodes.length;
242 for (var i = 0; i < length; ++i)
243 dataGrid.appendChild(nodes[i]);
244 if (length > 0)
245 nodes[0].selected = true;
246
247 return dataGrid;
248 },
249
250 _deleteButtonClicked: function(event)
251 {
252 if (!this._dataGrid)
253 return;
254
255 var cookie = this._dataGrid.selectedNode.cookie;
256 InspectorController.deleteCookie(cookie.name);
257 this.update();
258 },
259
260 _refreshButtonClicked: function(event)
261 {
262 this.update();
263 }
264 }
265
266 WebInspector.CookieItemsView.prototype.__proto__ = WebInspector.View.prototype;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698