| 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 | 29 |
| 30 /** | 30 Resources.CookieItemsView = class extends Resources.StorageItemsView { |
| 31 * @unrestricted | 31 /** |
| 32 */ | 32 * @param {!Resources.CookieTreeElement} treeElement |
| 33 Resources.CookieItemsView = class extends UI.SimpleView { | 33 * @param {!SDK.Target} target |
| 34 * @param {string} cookieDomain |
| 35 */ |
| 34 constructor(treeElement, target, cookieDomain) { | 36 constructor(treeElement, target, cookieDomain) { |
| 35 super(Common.UIString('Cookies')); | 37 super(Common.UIString('Cookies'), 'cookiesPanel'); |
| 36 | 38 |
| 37 this.element.classList.add('storage-view'); | 39 this.element.classList.add('storage-view'); |
| 38 | 40 |
| 39 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete Selected')
, 'largeicon-delete'); | |
| 40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del
eteButtonClicked, this); | |
| 41 | |
| 42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg
eicon-clear'); | |
| 43 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clea
rButtonClicked, this); | |
| 44 | |
| 45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); | |
| 46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re
freshButtonClicked, this); | |
| 47 | |
| 48 this._filterBar = new UI.FilterBar('cookiesPanel', true); | |
| 49 this._textFilterUI = new UI.TextFilterUI(true); | |
| 50 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._
filterChanged, this); | |
| 51 this._filterBar.addFilter(this._textFilterUI); | |
| 52 | |
| 53 this._filterSeparator = new UI.ToolbarSeparator(); | |
| 54 this._filterButton = this._filterBar.filterButton(); | |
| 55 | |
| 56 this._target = target; | 41 this._target = target; |
| 57 this._treeElement = treeElement; | 42 this._treeElement = treeElement; |
| 58 this._cookieDomain = cookieDomain; | 43 this._cookieDomain = cookieDomain; |
| 59 | 44 |
| 60 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t
rue); | 45 /** @type {?Array<!SDK.Cookie>} */ |
| 46 this._cookies = null; |
| 47 this._totalSize = 0; |
| 48 /** @type {?CookieTable.CookiesTable} */ |
| 49 this._cookiesTable = null; |
| 61 } | 50 } |
| 62 | 51 |
| 63 /** | 52 /** |
| 64 * @override | |
| 65 * @return {!Array.<!UI.ToolbarItem>} | |
| 66 */ | |
| 67 syncToolbarItems() { | |
| 68 return [this._refreshButton, this._clearButton, this._deleteButton, this._fi
lterSeparator, this._filterButton]; | |
| 69 } | |
| 70 | |
| 71 /** | |
| 72 * @override | |
| 73 */ | |
| 74 wasShown() { | |
| 75 this._update(); | |
| 76 } | |
| 77 | |
| 78 /** | |
| 79 * @override | |
| 80 */ | |
| 81 willHide() { | |
| 82 this._deleteButton.setEnabled(false); | |
| 83 } | |
| 84 | |
| 85 /** | |
| 86 * @param {!Common.Event} event | |
| 87 */ | |
| 88 _filterChanged(event) { | |
| 89 var text = this._textFilterUI.value(); | |
| 90 this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i'); | |
| 91 this._update(); | |
| 92 } | |
| 93 | |
| 94 _update() { | |
| 95 var resourceURLs = []; | |
| 96 var cookieDomain = this._cookieDomain; | |
| 97 /** | |
| 98 * @param {!SDK.Resource} resource | |
| 99 */ | |
| 100 function populateResourceURLs(resource) { | |
| 101 var url = resource.documentURL.asParsedURL(); | |
| 102 if (url && url.securityOrigin() === cookieDomain) | |
| 103 resourceURLs.push(resource.url); | |
| 104 } | |
| 105 | |
| 106 SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResou
rceURLs); | |
| 107 SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCook
ies.bind(this)); | |
| 108 } | |
| 109 | |
| 110 /** | |
| 111 * @param {!Array.<!SDK.Cookie>} allCookies | 53 * @param {!Array.<!SDK.Cookie>} allCookies |
| 112 */ | 54 */ |
| 113 _updateWithCookies(allCookies) { | 55 _updateWithCookies(allCookies) { |
| 114 this._cookies = allCookies; | 56 this._cookies = allCookies; |
| 115 this._totalSize = allCookies.reduce((size, cookie) => size + cookie.size(),
0); | 57 this._totalSize = allCookies.reduce((size, cookie) => size + cookie.size(),
0); |
| 116 | 58 |
| 117 if (!this._cookiesTable) { | 59 if (!this._cookiesTable) { |
| 118 const parsedURL = this._cookieDomain.asParsedURL(); | 60 const parsedURL = this._cookieDomain.asParsedURL(); |
| 119 const domain = parsedURL ? parsedURL.host : ''; | 61 const domain = parsedURL ? parsedURL.host : ''; |
| 120 this._cookiesTable = | 62 this._cookiesTable = new CookieTable.CookiesTable( |
| 121 new CookieTable.CookiesTable(false, this._update.bind(this), this._ena
bleDeleteButton.bind(this), domain); | 63 false, this.refreshItems.bind(this), () => this.setCanDeleteSelected(t
rue), domain); |
| 122 } | 64 } |
| 123 | 65 |
| 124 var shownCookies = this._filterCookies(this._cookies); | 66 var shownCookies = this.filter(allCookies, cookie => `${cookie.name()} ${coo
kie.value()} ${cookie.domain()}`); |
| 125 this._cookiesTable.setCookies(shownCookies); | 67 this._cookiesTable.setCookies(shownCookies); |
| 126 this._filterBar.show(this.element); | |
| 127 this._cookiesTable.show(this.element); | 68 this._cookiesTable.show(this.element); |
| 128 this._treeElement.subtitle = | 69 this._treeElement.subtitle = |
| 129 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length,
Number.bytesToString(this._totalSize)); | 70 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length,
Number.bytesToString(this._totalSize)); |
| 130 this._filterButton.setEnabled(true); | 71 this.setCanFilter(true); |
| 131 this._clearButton.setEnabled(true); | 72 this.setCanDeleteAll(true); |
| 132 this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie()); | 73 this.setCanDeleteSelected(!!this._cookiesTable.selectedCookie()); |
| 133 } | 74 } |
| 134 | 75 |
| 135 /** | 76 /** |
| 136 * @param {!Array.<!SDK.Cookie>} cookies | 77 * @override |
| 137 */ | 78 */ |
| 138 _filterCookies(cookies) { | 79 deleteAllItems() { |
| 139 if (!this._filterRegex) | |
| 140 return cookies; | |
| 141 | |
| 142 return cookies.filter(cookie => { | |
| 143 const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`; | |
| 144 return this._filterRegex.test(candidate); | |
| 145 }); | |
| 146 } | |
| 147 | |
| 148 clear() { | |
| 149 this._cookiesTable.clear(); | 80 this._cookiesTable.clear(); |
| 150 this._update(); | 81 this.refreshItems(); |
| 151 } | 82 } |
| 152 | 83 |
| 153 /** | 84 /** |
| 154 * @param {!Common.Event} event | 85 * @override |
| 155 */ | 86 */ |
| 156 _clearButtonClicked(event) { | 87 deleteSelectedItem() { |
| 157 this.clear(); | |
| 158 } | |
| 159 | |
| 160 _enableDeleteButton() { | |
| 161 this._deleteButton.setEnabled(true); | |
| 162 } | |
| 163 | |
| 164 /** | |
| 165 * @param {!Common.Event} event | |
| 166 */ | |
| 167 _deleteButtonClicked(event) { | |
| 168 var selectedCookie = this._cookiesTable.selectedCookie(); | 88 var selectedCookie = this._cookiesTable.selectedCookie(); |
| 169 if (selectedCookie) { | 89 if (selectedCookie) { |
| 170 selectedCookie.remove(); | 90 selectedCookie.remove(); |
| 171 this._update(); | 91 this.refreshItems(); |
| 172 } | 92 } |
| 173 } | 93 } |
| 174 | 94 |
| 175 /** | 95 /** |
| 176 * @param {!Common.Event} event | 96 * @override |
| 177 */ | 97 */ |
| 178 _refreshButtonClicked(event) { | 98 refreshItems() { |
| 179 this._update(); | 99 var resourceURLs = []; |
| 180 } | 100 var cookieDomain = this._cookieDomain; |
| 101 /** |
| 102 * @param {!SDK.Resource} resource |
| 103 */ |
| 104 function populateResourceURLs(resource) { |
| 105 var url = resource.documentURL.asParsedURL(); |
| 106 if (url && url.securityOrigin() === cookieDomain) |
| 107 resourceURLs.push(resource.url); |
| 108 } |
| 181 | 109 |
| 182 _contextMenu(event) { | 110 SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResou
rceURLs); |
| 183 if (!this._cookies.length) { | 111 SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCook
ies.bind(this)); |
| 184 var contextMenu = new UI.ContextMenu(event); | |
| 185 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this)
); | |
| 186 contextMenu.show(); | |
| 187 } | |
| 188 } | 112 } |
| 189 }; | 113 }; |
| OLD | NEW |