Index: Source/devtools/front_end/QuotaView.js |
diff --git a/Source/devtools/front_end/QuotaView.js b/Source/devtools/front_end/QuotaView.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..22fb741bb7e217618ec5afa7077e78c2da9a1c9e |
--- /dev/null |
+++ b/Source/devtools/front_end/QuotaView.js |
@@ -0,0 +1,132 @@ |
+/* |
+ * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+/** |
+ * @constructor |
+ * @extends {WebInspector.View} |
+ * @param {string} securityOrigin |
+ */ |
+WebInspector.QuotaView = function(securityOrigin) |
+{ |
+ WebInspector.View.call(this); |
+ this.securityOrigin = securityOrigin; |
+ |
+ this.element.addStyleClass("storage-view"); |
+ this.element.addStyleClass("table"); |
+ |
+ this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item"); |
+ this.refreshButton.addEventListener("click", this._refreshButtonClicked, this); |
+} |
+ |
+WebInspector.QuotaView.prototype = { |
+ get statusBarItems() |
+ { |
+ return [this.refreshButton.element]; |
+ }, |
+ |
+ wasShown: function() |
+ { |
+ this._update(); |
+ }, |
+ |
+ /* |
+ * @param {?Protocol.Error} error |
+ * @param {QuotaAgent.Quota} quota |
+ * @param {QuotaAgent.Usage} usage |
+ */ |
+ _showUsageAndQuota: function(error, quota, usage) |
+ { |
+ if (error) |
+ return; |
+ |
+ var columns = [ |
+ {id: "key", title: WebInspector.UIString("Key"), editable: true, weight: 50}, |
+ {id: "value", title: WebInspector.UIString("Value"), editable: true, weight: 50} |
+ ]; |
+ |
+ function getUsageItem(type, client) |
+ { |
+ if (!usage[type]) |
+ return null; |
+ var items = usage[type]; |
+ for (var i = 0; i != items.length; i++) { |
+ if (items[i].id == client) |
+ return Number.bytesToString(items[i].value); |
+ } |
+ return null; |
+ } |
+ |
+ var StorageType = { |
+ Temporary: "temporary", |
+ Persistent: "persistent", |
+ Syncable: "syncable" |
+ }; |
+ |
+ var ClientID = { |
+ Filesystem: "filesystem", |
+ Database: "database", |
+ Appcache: "appcache", |
+ IndexedDatabase: "indexeddatabase" |
+ }; |
+ |
+ var items = [ |
+ { name: WebInspector.UIString("Temporary global quota"), value: Number.bytesToString(quota.temporary) }, |
+ { name: WebInspector.UIString("Persistent host quota"), value: Number.bytesToString(quota.persistent) }, |
+ { name: WebInspector.UIString("Temporary file system usage"), value: getUsageItem(StorageType.Temporary, ClientID.Filesystem) }, |
+ { name: WebInspector.UIString("Persistent file system usage"), value: getUsageItem(StorageType.Persistent, ClientID.Filesystem) }, |
+ { name: WebInspector.UIString("Syncable file system usage"), value: getUsageItem(StorageType.Syncable, ClientID.Filesystem) }, |
+ { name: WebInspector.UIString("Web SQL usage"), value: getUsageItem(StorageType.Temporary, ClientID.Database) }, |
+ { name: WebInspector.UIString("Application Cache usage"), value: getUsageItem(StorageType.Temporary, ClientID.Appcache) }, |
+ { name: WebInspector.UIString("IndexedDB usage"), value: getUsageItem(StorageType.Temporary, ClientID.IndexedDatabase) } |
+ ].filter(function(item) {return item.value !== null}); |
+ |
+ var dataGrid = new WebInspector.DataGrid(columns); |
+ dataGrid.setName("QuotaItemsView"); |
+ |
+ for (var i = 0; i < items.length; i++) |
+ dataGrid.rootNode().appendChild(new WebInspector.DataGridNode({key: items[i].name, value: items[i].value}, false)); |
+ |
+ dataGrid.show(this.element); |
+ }, |
+ |
+ _refreshButtonClicked: function(event) |
+ { |
+ this._update(); |
+ }, |
+ |
+ _update: function() |
+ { |
+ this.detachChildViews(); |
+ PageAgent.queryUsageAndQuota(this.securityOrigin, this._showUsageAndQuota.bind(this)); |
+ }, |
+ |
+ __proto__: WebInspector.View.prototype |
+} |
+ |