blob: 5e7ba34e43528c60e0c9d6e5390990c6360a0a48 [file] [log] [blame]
timothy@apple.com27b08c92013-06-11 19:16:26 +00001/*
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +00002 * Copyright (C) 2010, 2013-2015 Apple Inc. All rights reserved.
timothy@apple.com27b08c92013-06-11 19:16:26 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
drousso@apple.com0b21e4c2017-08-02 03:09:57 +000026WI.ApplicationCacheFrameContentView = class ApplicationCacheFrameContentView extends WI.ContentView
timothy@apple.com27b08c92013-06-11 19:16:26 +000027{
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000028 constructor(representedObject)
29 {
drousso@apple.com0b21e4c2017-08-02 03:09:57 +000030 console.assert(representedObject instanceof WI.ApplicationCacheFrame);
timothy@apple.com27b08c92013-06-11 19:16:26 +000031
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000032 super(representedObject);
timothy@apple.com27b08c92013-06-11 19:16:26 +000033
commit-queue@webkit.org03e20682016-03-08 23:02:55 +000034 this.element.classList.add("application-cache-frame");
timothy@apple.com27b08c92013-06-11 19:16:26 +000035
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000036 this._frame = representedObject.frame;
timothy@apple.com27b08c92013-06-11 19:16:26 +000037
drousso@apple.com0b21e4c2017-08-02 03:09:57 +000038 this._emptyView = WI.createMessageTextView(WI.UIString("No Application Cache information available"), false);
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000039 this._emptyView.classList.add("hidden");
40 this.element.appendChild(this._emptyView);
timothy@apple.com27b08c92013-06-11 19:16:26 +000041
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000042 this._markDirty();
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +000043
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000044 var status = representedObject.status;
45 this.updateStatus(status);
timothy@apple.com27b08c92013-06-11 19:16:26 +000046
drousso@apple.com0b21e4c2017-08-02 03:09:57 +000047 WI.applicationCacheManager.addEventListener(WI.ApplicationCacheManager.Event.FrameManifestStatusChanged, this._updateStatus, this);
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000048 }
timothy@apple.com27b08c92013-06-11 19:16:26 +000049
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000050 shown()
timothy@apple.com27b08c92013-06-11 19:16:26 +000051 {
commit-queue@webkit.org46dbc442016-10-29 01:17:43 +000052 super.shown();
53
timothy@apple.com27b08c92013-06-11 19:16:26 +000054 this._maybeUpdate();
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000055 }
timothy@apple.com27b08c92013-06-11 19:16:26 +000056
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000057 closed()
timothy@apple.com27b08c92013-06-11 19:16:26 +000058 {
drousso@apple.com0b21e4c2017-08-02 03:09:57 +000059 WI.applicationCacheManager.removeEventListener(null, null, this);
commit-queue@webkit.org46dbc442016-10-29 01:17:43 +000060
61 super.closed();
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000062 }
timothy@apple.com27b08c92013-06-11 19:16:26 +000063
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000064 saveToCookie(cookie)
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +000065 {
drousso@apple.com0b21e4c2017-08-02 03:09:57 +000066 cookie.type = WI.ContentViewCookieType.ApplicationCache;
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +000067 cookie.frame = this.representedObject.frame.url;
68 cookie.manifest = this.representedObject.manifest.manifestURL;
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000069 }
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +000070
timothy@apple.com27b08c92013-06-11 19:16:26 +000071 get scrollableElements()
72 {
73 if (!this._dataGrid)
74 return [];
75 return [this._dataGrid.scrollContainer];
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000076 }
timothy@apple.com27b08c92013-06-11 19:16:26 +000077
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000078 _maybeUpdate()
timothy@apple.com27b08c92013-06-11 19:16:26 +000079 {
80 if (!this.visible || !this._viewDirty)
81 return;
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +000082
timothy@apple.com27b08c92013-06-11 19:16:26 +000083 this._update();
84 this._viewDirty = false;
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000085 }
timothy@apple.com27b08c92013-06-11 19:16:26 +000086
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000087 _markDirty()
timothy@apple.com27b08c92013-06-11 19:16:26 +000088 {
89 this._viewDirty = true;
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000090 }
timothy@apple.com27b08c92013-06-11 19:16:26 +000091
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +000092 _updateStatus(event)
timothy@apple.com27b08c92013-06-11 19:16:26 +000093 {
94 var frameManifest = event.data.frameManifest;
95 if (frameManifest !== this.representedObject)
96 return;
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +000097
drousso@apple.com0b21e4c2017-08-02 03:09:57 +000098 console.assert(frameManifest instanceof WI.ApplicationCacheFrame);
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +000099
timothy@apple.com27b08c92013-06-11 19:16:26 +0000100 this.updateStatus(frameManifest.status);
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000101 }
timothy@apple.com27b08c92013-06-11 19:16:26 +0000102
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000103 updateStatus(status)
timothy@apple.com27b08c92013-06-11 19:16:26 +0000104 {
105 var oldStatus = this._status;
106 this._status = status;
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +0000107
drousso@apple.com0b21e4c2017-08-02 03:09:57 +0000108 if (this.visible && this._status === WI.ApplicationCacheManager.Status.Idle && (oldStatus === WI.ApplicationCacheManager.Status.UpdateReady || !this._resources))
timothy@apple.com27b08c92013-06-11 19:16:26 +0000109 this._markDirty();
110
111 this._maybeUpdate();
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000112 }
timothy@apple.com27b08c92013-06-11 19:16:26 +0000113
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000114 _update()
timothy@apple.com27b08c92013-06-11 19:16:26 +0000115 {
drousso@apple.com0b21e4c2017-08-02 03:09:57 +0000116 WI.applicationCacheManager.requestApplicationCache(this._frame, this._updateCallback.bind(this));
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000117 }
timothy@apple.com27b08c92013-06-11 19:16:26 +0000118
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000119 _updateCallback(applicationCache)
timothy@apple.com27b08c92013-06-11 19:16:26 +0000120 {
121 if (!applicationCache || !applicationCache.manifestURL) {
122 delete this._manifest;
123 delete this._creationTime;
124 delete this._updateTime;
125 delete this._size;
126 delete this._resources;
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +0000127
timothy@apple.com27b08c92013-06-11 19:16:26 +0000128 this._emptyView.classList.remove("hidden");
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +0000129
timothy@apple.com27b08c92013-06-11 19:16:26 +0000130 if (this._dataGrid)
131 this._dataGrid.element.classList.add("hidden");
132 return;
133 }
134
135 // FIXME: are these variables needed anywhere else?
136 this._manifest = applicationCache.manifestURL;
137 this._creationTime = applicationCache.creationTime;
138 this._updateTime = applicationCache.updateTime;
139 this._size = applicationCache.size;
140 this._resources = applicationCache.resources;
141
142 if (!this._dataGrid)
143 this._createDataGrid();
144
145 this._populateDataGrid();
146 this._dataGrid.autoSizeColumns(20, 80);
147 this._dataGrid.element.classList.remove("hidden");
commit-queue@webkit.org10c778d2013-10-10 23:20:56 +0000148
timothy@apple.com27b08c92013-06-11 19:16:26 +0000149 this._emptyView.classList.add("hidden");
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000150 }
timothy@apple.com27b08c92013-06-11 19:16:26 +0000151
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000152 _createDataGrid()
timothy@apple.com27b08c92013-06-11 19:16:26 +0000153 {
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000154 var columns = {url: {}, type: {}, size: {}};
155
drousso@apple.com0b21e4c2017-08-02 03:09:57 +0000156 columns.url.title = WI.UIString("Resource");
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000157 columns.url.sortable = true;
158
drousso@apple.com0b21e4c2017-08-02 03:09:57 +0000159 columns.type.title = WI.UIString("Type");
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000160 columns.type.sortable = true;
161
drousso@apple.com0b21e4c2017-08-02 03:09:57 +0000162 columns.size.title = WI.UIString("Size");
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000163 columns.size.aligned = "right";
164 columns.size.sortable = true;
165
drousso@apple.com0b21e4c2017-08-02 03:09:57 +0000166 this._dataGrid = new WI.DataGrid(columns);
167 this._dataGrid.addEventListener(WI.DataGrid.Event.SortChanged, this._sortDataGrid, this);
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000168
mattbaker@apple.com503ed072016-06-16 19:39:10 +0000169 this._dataGrid.sortColumnIdentifier = "url";
drousso@apple.com0b21e4c2017-08-02 03:09:57 +0000170 this._dataGrid.sortOrder = WI.DataGrid.SortOrder.Ascending;
mattbaker@apple.com503ed072016-06-16 19:39:10 +0000171 this._dataGrid.createSettings("application-cache-frame-content-view");
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000172
mattbaker@apple.com45467e62015-11-06 00:03:59 +0000173 this.addSubview(this._dataGrid);
timothy@apple.com27b08c92013-06-11 19:16:26 +0000174 this._dataGrid.updateLayout();
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000175 }
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000176
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000177 _sortDataGrid()
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000178 {
179 function numberCompare(columnIdentifier, nodeA, nodeB)
180 {
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000181 return nodeA.data[columnIdentifier] - nodeB.data[columnIdentifier];
182 }
183 function localeCompare(columnIdentifier, nodeA, nodeB)
184 {
drousso@apple.com27198182017-06-30 21:47:05 +0000185 return (nodeA.data[columnIdentifier] + "").extendedLocaleCompare(nodeB.data[columnIdentifier] + "");
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000186 }
187
188 var comparator;
189 switch (this._dataGrid.sortColumnIdentifier) {
190 case "type": comparator = localeCompare.bind(this, "type"); break;
commit-queue@webkit.org5cd8e262017-09-13 23:46:44 +0000191 case "size": comparator = numberCompare.bind(this, "sizeNumber"); break;
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000192 case "url":
joepeck@webkit.org15c73992016-09-05 05:02:38 +0000193 default: comparator = localeCompare.bind(this, "url"); break;
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000194 }
195
196 this._dataGrid.sortNodes(comparator);
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000197 }
timothy@apple.com27b08c92013-06-11 19:16:26 +0000198
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000199 _populateDataGrid()
timothy@apple.com27b08c92013-06-11 19:16:26 +0000200 {
timothy@apple.com27b08c92013-06-11 19:16:26 +0000201 this._dataGrid.removeChildren();
202
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000203 for (var resource of this._resources) {
204 var data = {
205 url: resource.url,
206 type: resource.type,
commit-queue@webkit.org5cd8e262017-09-13 23:46:44 +0000207 size: Number.bytesToString(resource.size),
208 sizeNumber: resource.size,
bburg@apple.com9d5954b2014-03-12 18:18:29 +0000209 };
drousso@apple.com0b21e4c2017-08-02 03:09:57 +0000210 var node = new WI.DataGridNode(data);
timothy@apple.com27b08c92013-06-11 19:16:26 +0000211 this._dataGrid.appendChild(node);
timothy@apple.com27b08c92013-06-11 19:16:26 +0000212 }
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000213 }
timothy@apple.com27b08c92013-06-11 19:16:26 +0000214
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000215 _deleteButtonClicked(event)
timothy@apple.com27b08c92013-06-11 19:16:26 +0000216 {
217 if (!this._dataGrid || !this._dataGrid.selectedNode)
218 return;
219
220 // FIXME: Delete Button semantics are not yet defined. (Delete a single, or all?)
221 this._deleteCallback(this._dataGrid.selectedNode);
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000222 }
timothy@apple.com27b08c92013-06-11 19:16:26 +0000223
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000224 _deleteCallback(node)
timothy@apple.com27b08c92013-06-11 19:16:26 +0000225 {
226 // FIXME: Should we delete a single (selected) resource or all resources?
227 // InspectorBackend.deleteCachedResource(...)
228 // this._update();
229 }
burg@cs.washington.edu53f4d962015-08-05 18:12:35 +0000230};