Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / resources / ServiceWorkerCacheViews.js
blob0828d9acfa3c325874dc53ffe611c7b87dd77008
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @constructor
7 * @extends {WebInspector.VBox}
8 * @param {!WebInspector.ServiceWorkerCacheModel} model
9 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
11 WebInspector.ServiceWorkerCacheView = function(model, cache)
13 WebInspector.VBox.call(this);
14 this.registerRequiredCSS("resources/serviceWorkerCacheViews.css");
16 this._model = model;
18 this.element.classList.add("service-worker-cache-data-view");
19 this.element.classList.add("storage-view");
21 this._createEditorToolbar();
23 this._refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString("Refresh"), "refresh-toolbar-item");
24 this._refreshButton.addEventListener("click", this._refreshButtonClicked, this);
26 this._pageSize = 50;
27 this._skipCount = 0;
29 this.update(cache);
30 this._entries = [];
33 WebInspector.ServiceWorkerCacheView.prototype = {
34 /**
35 * @return {!WebInspector.DataGrid}
37 _createDataGrid: function()
39 var columns = [];
40 columns.push({id: "number", title: WebInspector.UIString("#"), width: "50px"});
41 columns.push({id: "request", title: WebInspector.UIString("Request")});
42 columns.push({id: "response", title: WebInspector.UIString("Response")});
44 var dataGrid = new WebInspector.DataGrid(columns, undefined, this._deleteButtonClicked.bind(this), this._updateData.bind(this, true));
45 return dataGrid;
48 _createEditorToolbar: function()
50 var editorToolbar = new WebInspector.Toolbar(this.element);
51 editorToolbar.element.classList.add("data-view-toolbar");
53 this._pageBackButton = new WebInspector.ToolbarButton(WebInspector.UIString("Show previous page"), "play-backwards-toolbar-item");
54 this._pageBackButton.addEventListener("click", this._pageBackButtonClicked, this);
55 editorToolbar.appendToolbarItem(this._pageBackButton);
57 this._pageForwardButton = new WebInspector.ToolbarButton(WebInspector.UIString("Show next page"), "play-toolbar-item");
58 this._pageForwardButton.setEnabled(false);
59 this._pageForwardButton.addEventListener("click", this._pageForwardButtonClicked, this);
60 editorToolbar.appendToolbarItem(this._pageForwardButton);
63 _pageBackButtonClicked: function()
65 this._skipCount = Math.max(0, this._skipCount - this._pageSize);
66 this._updateData(false);
69 _pageForwardButtonClicked: function()
71 this._skipCount = this._skipCount + this._pageSize;
72 this._updateData(false);
75 /**
76 * @param {!WebInspector.DataGridNode} node
78 _deleteButtonClicked: function(node)
80 this._model.deleteCacheEntry(this._cache, node.data["request"], node.remove.bind(node));
83 /**
84 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
86 update: function(cache)
88 this._cache = cache;
90 if (this._dataGrid)
91 this._dataGrid.detach();
92 this._dataGrid = this._createDataGrid();
93 this._dataGrid.show(this.element);
95 this._skipCount = 0;
96 this._updateData(true);
99 /**
100 * @param {number} skipCount
101 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>} entries
102 * @param {boolean} hasMore
103 * @this {WebInspector.ServiceWorkerCacheView}
105 _updateDataCallback(skipCount, entries, hasMore)
107 this._refreshButton.setEnabled(true);
108 this.clear();
109 this._entries = entries;
110 for (var i = 0; i < entries.length; ++i) {
111 var data = {};
112 data["number"] = i + skipCount;
113 data["request"] = entries[i].request;
114 data["response"] = entries[i].response;
115 var node = new WebInspector.DataGridNode(data);
116 node.selectable = true;
117 this._dataGrid.rootNode().appendChild(node);
119 this._pageBackButton.setEnabled(!!skipCount);
120 this._pageForwardButton.setEnabled(hasMore);
124 * @param {boolean} force
126 _updateData: function(force)
128 var pageSize = this._pageSize;
129 var skipCount = this._skipCount;
130 this._refreshButton.setEnabled(false);
132 if (!force && this._lastPageSize === pageSize && this._lastSkipCount === skipCount)
133 return;
135 if (this._lastPageSize !== pageSize) {
136 skipCount = 0;
137 this._skipCount = 0;
139 this._lastPageSize = pageSize;
140 this._lastSkipCount = skipCount;
141 this._model.loadCacheData(this._cache, skipCount, pageSize, this._updateDataCallback.bind(this, skipCount));
144 _refreshButtonClicked: function(event)
146 this._updateData(true);
150 * @return {!Array.<!WebInspector.ToolbarItem>}
152 toolbarItems: function()
154 return [this._refreshButton];
157 clear: function()
159 this._dataGrid.rootNode().removeChildren();
160 this._entries = [];
163 __proto__: WebInspector.VBox.prototype