OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 /** |
| 32 * @constructor |
| 33 * @extends {WebInspector.View} |
| 34 * @param {string} securityOrigin |
| 35 */ |
| 36 WebInspector.QuotaView = function(securityOrigin) |
| 37 { |
| 38 WebInspector.View.call(this); |
| 39 this.securityOrigin = securityOrigin; |
| 40 |
| 41 this.element.addStyleClass("storage-view"); |
| 42 this.element.addStyleClass("table"); |
| 43 |
| 44 this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString(
"Refresh"), "refresh-storage-status-bar-item"); |
| 45 this.refreshButton.addEventListener("click", this._refreshButtonClicked, thi
s); |
| 46 } |
| 47 |
| 48 WebInspector.QuotaView.prototype = { |
| 49 get statusBarItems() |
| 50 { |
| 51 return [this.refreshButton.element]; |
| 52 }, |
| 53 |
| 54 wasShown: function() |
| 55 { |
| 56 this._update(); |
| 57 }, |
| 58 |
| 59 /* |
| 60 * @param {?Protocol.Error} error |
| 61 * @param {QuotaAgent.Quota} quota |
| 62 * @param {QuotaAgent.Usage} usage |
| 63 */ |
| 64 _showUsageAndQuota: function(error, quota, usage) |
| 65 { |
| 66 if (error) |
| 67 return; |
| 68 |
| 69 var columns = [ |
| 70 {id: "key", title: WebInspector.UIString("Key"), editable: true, wei
ght: 50}, |
| 71 {id: "value", title: WebInspector.UIString("Value"), editable: true,
weight: 50} |
| 72 ]; |
| 73 |
| 74 function getUsageItem(type, client) |
| 75 { |
| 76 if (!usage[type]) |
| 77 return null; |
| 78 var items = usage[type]; |
| 79 for (var i = 0; i != items.length; i++) { |
| 80 if (items[i].id == client) |
| 81 return Number.bytesToString(items[i].value); |
| 82 } |
| 83 return null; |
| 84 } |
| 85 |
| 86 var StorageType = { |
| 87 Temporary: "temporary", |
| 88 Persistent: "persistent", |
| 89 Syncable: "syncable" |
| 90 }; |
| 91 |
| 92 var ClientID = { |
| 93 Filesystem: "filesystem", |
| 94 Database: "database", |
| 95 Appcache: "appcache", |
| 96 IndexedDatabase: "indexeddatabase" |
| 97 }; |
| 98 |
| 99 var items = [ |
| 100 { name: WebInspector.UIString("Temporary global quota"), value: Numb
er.bytesToString(quota.temporary) }, |
| 101 { name: WebInspector.UIString("Persistent host quota"), value: Numbe
r.bytesToString(quota.persistent) }, |
| 102 { name: WebInspector.UIString("Temporary file system usage"), value:
getUsageItem(StorageType.Temporary, ClientID.Filesystem) }, |
| 103 { name: WebInspector.UIString("Persistent file system usage"), value
: getUsageItem(StorageType.Persistent, ClientID.Filesystem) }, |
| 104 { name: WebInspector.UIString("Syncable file system usage"), value:
getUsageItem(StorageType.Syncable, ClientID.Filesystem) }, |
| 105 { name: WebInspector.UIString("Web SQL usage"), value: getUsageItem(
StorageType.Temporary, ClientID.Database) }, |
| 106 { name: WebInspector.UIString("Application Cache usage"), value: get
UsageItem(StorageType.Temporary, ClientID.Appcache) }, |
| 107 { name: WebInspector.UIString("IndexedDB usage"), value: getUsageIte
m(StorageType.Temporary, ClientID.IndexedDatabase) } |
| 108 ].filter(function(item) {return item.value !== null}); |
| 109 |
| 110 var dataGrid = new WebInspector.DataGrid(columns); |
| 111 dataGrid.setName("QuotaItemsView"); |
| 112 |
| 113 for (var i = 0; i < items.length; i++) |
| 114 dataGrid.rootNode().appendChild(new WebInspector.DataGridNode({key:
items[i].name, value: items[i].value}, false)); |
| 115 |
| 116 dataGrid.show(this.element); |
| 117 }, |
| 118 |
| 119 _refreshButtonClicked: function(event) |
| 120 { |
| 121 this._update(); |
| 122 }, |
| 123 |
| 124 _update: function() |
| 125 { |
| 126 this.detachChildViews(); |
| 127 PageAgent.queryUsageAndQuota(this.securityOrigin, this._showUsageAndQuot
a.bind(this)); |
| 128 }, |
| 129 |
| 130 __proto__: WebInspector.View.prototype |
| 131 } |
| 132 |
OLD | NEW |