2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
32 * @extends {WebInspector.VBox}
34 WebInspector.CookieItemsView = function(treeElement, cookieDomain)
36 WebInspector.VBox.call(this);
38 this.element.classList.add("storage-view");
40 this._deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("Delete"), "delete-storage-status-bar-item");
41 this._deleteButton.visible = false;
42 this._deleteButton.addEventListener("click", this._deleteButtonClicked, this);
44 this._clearButton = new WebInspector.StatusBarButton(WebInspector.UIString("Clear"), "clear-storage-status-bar-item");
45 this._clearButton.visible = false;
46 this._clearButton.addEventListener("click", this._clearButtonClicked, this);
48 this._refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item");
49 this._refreshButton.addEventListener("click", this._refreshButtonClicked, this);
51 this._treeElement = treeElement;
52 this._cookieDomain = cookieDomain;
54 this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("This site has no cookies."));
55 this._emptyView.show(this.element);
57 this.element.addEventListener("contextmenu", this._contextMenu.bind(this), true);
60 WebInspector.CookieItemsView.prototype = {
63 return [this._refreshButton.element, this._clearButton.element, this._deleteButton.element];
73 this._deleteButton.visible = false;
78 WebInspector.Cookies.getCookiesAsync(this._updateWithCookies.bind(this));
82 * @param {!Array.<!WebInspector.Cookie>} allCookies
84 _updateWithCookies: function(allCookies)
86 this._cookies = this._filterCookiesForDomain(allCookies);
88 if (!this._cookies.length) {
90 this._emptyView.show(this.element);
91 this._clearButton.visible = false;
92 this._deleteButton.visible = false;
93 if (this._cookiesTable)
94 this._cookiesTable.detach();
98 if (!this._cookiesTable)
99 this._cookiesTable = new WebInspector.CookiesTable(false, this._update.bind(this), this._showDeleteButton.bind(this));
101 this._cookiesTable.setCookies(this._cookies);
102 this._emptyView.detach();
103 this._cookiesTable.show(this.element);
104 this._treeElement.subtitle = String.sprintf(WebInspector.UIString("%d cookies (%s)"), this._cookies.length,
105 Number.bytesToString(this._totalSize));
106 this._clearButton.visible = true;
107 this._deleteButton.visible = !!this._cookiesTable.selectedCookie();
111 * @param {!Array.<!WebInspector.Cookie>} allCookies
113 _filterCookiesForDomain: function(allCookies)
116 var resourceURLsForDocumentURL = [];
120 * @this {WebInspector.CookieItemsView}
122 function populateResourcesForDocuments(resource)
124 var url = resource.documentURL.asParsedURL();
125 if (url && url.host == this._cookieDomain)
126 resourceURLsForDocumentURL.push(resource.url);
128 WebInspector.forAllResources(populateResourcesForDocuments.bind(this));
130 for (var i = 0; i < allCookies.length; ++i) {
132 var size = allCookies[i].size();
133 for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) {
134 var resourceURL = resourceURLsForDocumentURL[j];
135 if (WebInspector.Cookies.cookieMatchesResourceURL(allCookies[i], resourceURL)) {
136 this._totalSize += size;
139 cookies.push(allCookies[i]);
149 this._cookiesTable.clear();
153 _clearButtonClicked: function()
158 _showDeleteButton: function()
160 this._deleteButton.visible = true;
163 _deleteButtonClicked: function()
165 var selectedCookie = this._cookiesTable.selectedCookie();
166 if (selectedCookie) {
167 selectedCookie.remove();
172 _refreshButtonClicked: function(event)
177 _contextMenu: function(event)
179 if (!this._cookies.length) {
180 var contextMenu = new WebInspector.ContextMenu(event);
181 contextMenu.appendItem(WebInspector.UIString("Refresh"), this._update.bind(this));
186 __proto__: WebInspector.VBox.prototype