| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
| 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | 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 | 15 * its contributors may be used to endorse or promote products derived |
| 16 * from this software without specific prior written permission. | 16 * from this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 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 | 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 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 | 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 /** |
| 30 * @unrestricted |
| 31 */ |
| 32 WebInspector.CookieItemsView = class extends WebInspector.SimpleView { |
| 33 constructor(treeElement, cookieDomain) { |
| 34 super(WebInspector.UIString('Cookies')); |
| 29 | 35 |
| 30 /** | 36 this.element.classList.add('storage-view'); |
| 31 * @constructor | |
| 32 * @extends {WebInspector.SimpleView} | |
| 33 */ | |
| 34 WebInspector.CookieItemsView = function(treeElement, cookieDomain) | |
| 35 { | |
| 36 WebInspector.SimpleView.call(this, WebInspector.UIString("Cookies")); | |
| 37 | 37 |
| 38 this.element.classList.add("storage-view"); | 38 this._deleteButton = new WebInspector.ToolbarButton(WebInspector.UIString('D
elete'), 'delete-toolbar-item'); |
| 39 this._deleteButton.setVisible(false); |
| 40 this._deleteButton.addEventListener('click', this._deleteButtonClicked, this
); |
| 39 | 41 |
| 40 this._deleteButton = new WebInspector.ToolbarButton(WebInspector.UIString("D
elete"), "delete-toolbar-item"); | 42 this._clearButton = new WebInspector.ToolbarButton(WebInspector.UIString('Cl
ear'), 'clear-toolbar-item'); |
| 41 this._deleteButton.setVisible(false); | 43 this._clearButton.setVisible(false); |
| 42 this._deleteButton.addEventListener("click", this._deleteButtonClicked, this
); | 44 this._clearButton.addEventListener('click', this._clearButtonClicked, this); |
| 43 | 45 |
| 44 this._clearButton = new WebInspector.ToolbarButton(WebInspector.UIString("Cl
ear"), "clear-toolbar-item"); | 46 this._refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString('
Refresh'), 'refresh-toolbar-item'); |
| 45 this._clearButton.setVisible(false); | 47 this._refreshButton.addEventListener('click', this._refreshButtonClicked, th
is); |
| 46 this._clearButton.addEventListener("click", this._clearButtonClicked, this); | |
| 47 | |
| 48 this._refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString("
Refresh"), "refresh-toolbar-item"); | |
| 49 this._refreshButton.addEventListener("click", this._refreshButtonClicked, th
is); | |
| 50 | 48 |
| 51 this._treeElement = treeElement; | 49 this._treeElement = treeElement; |
| 52 this._cookieDomain = cookieDomain; | 50 this._cookieDomain = cookieDomain; |
| 53 | 51 |
| 54 this._emptyWidget = new WebInspector.EmptyWidget(cookieDomain ? WebInspector
.UIString("This site has no cookies.") : WebInspector.UIString("By default cooki
es are disabled for local files.\nYou could override this by starting the browse
r with --enable-file-cookies command line flag.")); | 52 this._emptyWidget = new WebInspector.EmptyWidget( |
| 53 cookieDomain ? |
| 54 WebInspector.UIString('This site has no cookies.') : |
| 55 WebInspector.UIString( |
| 56 'By default cookies are disabled for local files.\nYou could ove
rride this by starting the browser with --enable-file-cookies command line flag.
')); |
| 55 this._emptyWidget.show(this.element); | 57 this._emptyWidget.show(this.element); |
| 56 | 58 |
| 57 this.element.addEventListener("contextmenu", this._contextMenu.bind(this), t
rue); | 59 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t
rue); |
| 58 }; | 60 } |
| 59 | 61 |
| 60 WebInspector.CookieItemsView.prototype = { | 62 /** |
| 61 /** | 63 * @override |
| 62 * @override | 64 * @return {!Array.<!WebInspector.ToolbarItem>} |
| 63 * @return {!Array.<!WebInspector.ToolbarItem>} | 65 */ |
| 64 */ | 66 syncToolbarItems() { |
| 65 syncToolbarItems: function() | 67 return [this._refreshButton, this._clearButton, this._deleteButton]; |
| 66 { | 68 } |
| 67 return [this._refreshButton, this._clearButton, this._deleteButton]; | |
| 68 }, | |
| 69 | 69 |
| 70 wasShown: function() | 70 /** |
| 71 { | 71 * @override |
| 72 this._update(); | 72 */ |
| 73 }, | 73 wasShown() { |
| 74 this._update(); |
| 75 } |
| 74 | 76 |
| 75 willHide: function() | 77 /** |
| 76 { | 78 * @override |
| 77 this._deleteButton.setVisible(false); | 79 */ |
| 78 }, | 80 willHide() { |
| 81 this._deleteButton.setVisible(false); |
| 82 } |
| 79 | 83 |
| 80 _update: function() | 84 _update() { |
| 81 { | 85 WebInspector.Cookies.getCookiesAsync(this._updateWithCookies.bind(this)); |
| 82 WebInspector.Cookies.getCookiesAsync(this._updateWithCookies.bind(this))
; | 86 } |
| 83 }, | 87 |
| 88 /** |
| 89 * @param {!Array.<!WebInspector.Cookie>} allCookies |
| 90 */ |
| 91 _updateWithCookies(allCookies) { |
| 92 this._cookies = this._filterCookiesForDomain(allCookies); |
| 93 |
| 94 if (!this._cookies.length) { |
| 95 // Nothing to show. |
| 96 this._emptyWidget.show(this.element); |
| 97 this._clearButton.setVisible(false); |
| 98 this._deleteButton.setVisible(false); |
| 99 if (this._cookiesTable) |
| 100 this._cookiesTable.detach(); |
| 101 return; |
| 102 } |
| 103 |
| 104 if (!this._cookiesTable) |
| 105 this._cookiesTable = |
| 106 new WebInspector.CookiesTable(false, this._update.bind(this), this._sh
owDeleteButton.bind(this)); |
| 107 |
| 108 this._cookiesTable.setCookies(this._cookies); |
| 109 this._emptyWidget.detach(); |
| 110 this._cookiesTable.show(this.element); |
| 111 this._treeElement.subtitle = String.sprintf( |
| 112 WebInspector.UIString('%d cookies (%s)'), this._cookies.length, Number.b
ytesToString(this._totalSize)); |
| 113 this._clearButton.setVisible(true); |
| 114 this._deleteButton.setVisible(!!this._cookiesTable.selectedCookie()); |
| 115 } |
| 116 |
| 117 /** |
| 118 * @param {!Array.<!WebInspector.Cookie>} allCookies |
| 119 */ |
| 120 _filterCookiesForDomain(allCookies) { |
| 121 var cookies = []; |
| 122 var resourceURLsForDocumentURL = []; |
| 123 this._totalSize = 0; |
| 84 | 124 |
| 85 /** | 125 /** |
| 86 * @param {!Array.<!WebInspector.Cookie>} allCookies | 126 * @this {WebInspector.CookieItemsView} |
| 87 */ | 127 */ |
| 88 _updateWithCookies: function(allCookies) | 128 function populateResourcesForDocuments(resource) { |
| 89 { | 129 var url = resource.documentURL.asParsedURL(); |
| 90 this._cookies = this._filterCookiesForDomain(allCookies); | 130 if (url && url.securityOrigin() === this._cookieDomain) |
| 131 resourceURLsForDocumentURL.push(resource.url); |
| 132 } |
| 133 WebInspector.forAllResources(populateResourcesForDocuments.bind(this)); |
| 91 | 134 |
| 92 if (!this._cookies.length) { | 135 for (var i = 0; i < allCookies.length; ++i) { |
| 93 // Nothing to show. | 136 var pushed = false; |
| 94 this._emptyWidget.show(this.element); | 137 var size = allCookies[i].size(); |
| 95 this._clearButton.setVisible(false); | 138 for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) { |
| 96 this._deleteButton.setVisible(false); | 139 var resourceURL = resourceURLsForDocumentURL[j]; |
| 97 if (this._cookiesTable) | 140 if (WebInspector.Cookies.cookieMatchesResourceURL(allCookies[i], resourc
eURL)) { |
| 98 this._cookiesTable.detach(); | 141 this._totalSize += size; |
| 99 return; | 142 if (!pushed) { |
| 143 pushed = true; |
| 144 cookies.push(allCookies[i]); |
| 145 } |
| 100 } | 146 } |
| 147 } |
| 148 } |
| 149 return cookies; |
| 150 } |
| 101 | 151 |
| 102 if (!this._cookiesTable) | 152 clear() { |
| 103 this._cookiesTable = new WebInspector.CookiesTable(false, this._upda
te.bind(this), this._showDeleteButton.bind(this)); | 153 this._cookiesTable.clear(); |
| 154 this._update(); |
| 155 } |
| 104 | 156 |
| 105 this._cookiesTable.setCookies(this._cookies); | 157 _clearButtonClicked() { |
| 106 this._emptyWidget.detach(); | 158 this.clear(); |
| 107 this._cookiesTable.show(this.element); | 159 } |
| 108 this._treeElement.subtitle = String.sprintf(WebInspector.UIString("%d co
okies (%s)"), this._cookies.length, | |
| 109 Number.bytesToString(this._totalSize)); | |
| 110 this._clearButton.setVisible(true); | |
| 111 this._deleteButton.setVisible(!!this._cookiesTable.selectedCookie()); | |
| 112 }, | |
| 113 | 160 |
| 114 /** | 161 _showDeleteButton() { |
| 115 * @param {!Array.<!WebInspector.Cookie>} allCookies | 162 this._deleteButton.setVisible(true); |
| 116 */ | 163 } |
| 117 _filterCookiesForDomain: function(allCookies) | |
| 118 { | |
| 119 var cookies = []; | |
| 120 var resourceURLsForDocumentURL = []; | |
| 121 this._totalSize = 0; | |
| 122 | 164 |
| 123 /** | 165 _deleteButtonClicked() { |
| 124 * @this {WebInspector.CookieItemsView} | 166 var selectedCookie = this._cookiesTable.selectedCookie(); |
| 125 */ | 167 if (selectedCookie) { |
| 126 function populateResourcesForDocuments(resource) | 168 selectedCookie.remove(); |
| 127 { | 169 this._update(); |
| 128 var url = resource.documentURL.asParsedURL(); | 170 } |
| 129 if (url && url.securityOrigin() === this._cookieDomain) | 171 } |
| 130 resourceURLsForDocumentURL.push(resource.url); | |
| 131 } | |
| 132 WebInspector.forAllResources(populateResourcesForDocuments.bind(this)); | |
| 133 | 172 |
| 134 for (var i = 0; i < allCookies.length; ++i) { | 173 _refreshButtonClicked(event) { |
| 135 var pushed = false; | 174 this._update(); |
| 136 var size = allCookies[i].size(); | 175 } |
| 137 for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) { | |
| 138 var resourceURL = resourceURLsForDocumentURL[j]; | |
| 139 if (WebInspector.Cookies.cookieMatchesResourceURL(allCookies[i],
resourceURL)) { | |
| 140 this._totalSize += size; | |
| 141 if (!pushed) { | |
| 142 pushed = true; | |
| 143 cookies.push(allCookies[i]); | |
| 144 } | |
| 145 } | |
| 146 } | |
| 147 } | |
| 148 return cookies; | |
| 149 }, | |
| 150 | 176 |
| 151 clear: function() | 177 _contextMenu(event) { |
| 152 { | 178 if (!this._cookies.length) { |
| 153 this._cookiesTable.clear(); | 179 var contextMenu = new WebInspector.ContextMenu(event); |
| 154 this._update(); | 180 contextMenu.appendItem(WebInspector.UIString('Refresh'), this._update.bind
(this)); |
| 155 }, | 181 contextMenu.show(); |
| 156 | 182 } |
| 157 _clearButtonClicked: function() | 183 } |
| 158 { | |
| 159 this.clear(); | |
| 160 }, | |
| 161 | |
| 162 _showDeleteButton: function() | |
| 163 { | |
| 164 this._deleteButton.setVisible(true); | |
| 165 }, | |
| 166 | |
| 167 _deleteButtonClicked: function() | |
| 168 { | |
| 169 var selectedCookie = this._cookiesTable.selectedCookie(); | |
| 170 if (selectedCookie) { | |
| 171 selectedCookie.remove(); | |
| 172 this._update(); | |
| 173 } | |
| 174 }, | |
| 175 | |
| 176 _refreshButtonClicked: function(event) | |
| 177 { | |
| 178 this._update(); | |
| 179 }, | |
| 180 | |
| 181 _contextMenu: function(event) | |
| 182 { | |
| 183 if (!this._cookies.length) { | |
| 184 var contextMenu = new WebInspector.ContextMenu(event); | |
| 185 contextMenu.appendItem(WebInspector.UIString("Refresh"), this._updat
e.bind(this)); | |
| 186 contextMenu.show(); | |
| 187 } | |
| 188 }, | |
| 189 | |
| 190 __proto__: WebInspector.SimpleView.prototype | |
| 191 }; | 184 }; |
| OLD | NEW |