Chromium Code Reviews| 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. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 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 /** |
| 31 * @unrestricted | 31 * @unrestricted |
| 32 */ | 32 */ |
| 33 Resources.CookieItemsView = class extends UI.SimpleView { | 33 Resources.CookieItemsView = class extends Resources.ItemsView { |
| 34 constructor(treeElement, target, cookieDomain) { | 34 constructor(treeElement, target, cookieDomain) { |
| 35 super(Common.UIString('Cookies')); | 35 super(Common.UIString('Cookies'), 'cookiesPanel'); |
| 36 | 36 |
| 37 this.element.classList.add('storage-view'); | 37 this.element.classList.add('storage-view'); |
| 38 | 38 |
| 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; | 39 this._target = target; |
| 57 this._treeElement = treeElement; | 40 this._treeElement = treeElement; |
| 58 this._cookieDomain = cookieDomain; | 41 this._cookieDomain = cookieDomain; |
| 59 | 42 |
| 60 this._emptyWidget = new UI.EmptyWidget( | 43 this._emptyWidget = new UI.EmptyWidget( |
| 61 cookieDomain ? | 44 cookieDomain ? |
| 62 Common.UIString('This site has no cookies.') : | 45 Common.UIString('This site has no cookies.') : |
| 63 Common.UIString( | 46 Common.UIString( |
| 64 'By default cookies are disabled for local files.\nYou could ove rride this by starting the browser with --enable-file-cookies command line flag. ')); | 47 'By default cookies are disabled for local files.\nYou could ove rride this by starting the browser with --enable-file-cookies command line flag. ')); |
| 65 this._emptyWidget.show(this.element); | 48 this._emptyWidget.show(this.element); |
| 66 | 49 |
| 67 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t rue); | 50 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t rue); |
| 68 } | 51 } |
| 69 | 52 |
| 70 /** | 53 /** |
| 71 * @override | 54 * @override |
| 72 * @return {!Array.<!UI.ToolbarItem>} | |
| 73 */ | |
| 74 syncToolbarItems() { | |
| 75 return [this._refreshButton, this._clearButton, this._deleteButton, this._fi lterSeparator, this._filterButton]; | |
| 76 } | |
| 77 | |
| 78 /** | |
| 79 * @override | |
| 80 */ | 55 */ |
| 81 wasShown() { | 56 wasShown() { |
| 82 this._update(); | 57 this._update(); |
| 83 } | 58 } |
| 84 | 59 |
| 85 /** | 60 /** |
| 86 * @override | 61 * @override |
| 87 */ | 62 */ |
| 88 willHide() { | 63 willHide() { |
| 89 this._deleteButton.setEnabled(false); | 64 this.deleteButton.setEnabled(false); |
| 90 } | |
| 91 | |
| 92 /** | |
| 93 * @param {!Common.Event} event | |
| 94 */ | |
| 95 _filterChanged(event) { | |
| 96 var text = this._textFilterUI.value(); | |
| 97 this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i'); | |
| 98 this._update(); | |
| 99 } | 65 } |
| 100 | 66 |
| 101 _update() { | 67 _update() { |
|
dgozman
2017/01/26 22:21:09
Merge this with refresh?
eostroukhov
2017/01/26 23:35:45
Done.
| |
| 102 var resourceURLs = []; | 68 var resourceURLs = []; |
| 103 var cookieDomain = this._cookieDomain; | 69 var cookieDomain = this._cookieDomain; |
| 104 /** | 70 /** |
| 105 * @param {!SDK.Resource} resource | 71 * @param {!SDK.Resource} resource |
| 106 */ | 72 */ |
| 107 function populateResourceURLs(resource) { | 73 function populateResourceURLs(resource) { |
| 108 var url = resource.documentURL.asParsedURL(); | 74 var url = resource.documentURL.asParsedURL(); |
| 109 if (url && url.securityOrigin() === cookieDomain) | 75 if (url && url.securityOrigin() === cookieDomain) |
| 110 resourceURLs.push(resource.url); | 76 resourceURLs.push(resource.url); |
| 111 } | 77 } |
| 112 | 78 |
| 113 SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResou rceURLs); | 79 SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResou rceURLs); |
| 114 SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCook ies.bind(this)); | 80 SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCook ies.bind(this)); |
| 115 } | 81 } |
| 116 | 82 |
| 117 /** | 83 /** |
| 118 * @param {!Array.<!SDK.Cookie>} allCookies | 84 * @param {!Array.<!SDK.Cookie>} allCookies |
| 119 */ | 85 */ |
| 120 _updateWithCookies(allCookies) { | 86 _updateWithCookies(allCookies) { |
| 121 this._cookies = allCookies; | 87 this._cookies = allCookies; |
| 122 this._totalSize = allCookies.reduce((size, cookie) => size + cookie.size(), 0); | 88 this._totalSize = allCookies.reduce((size, cookie) => size + cookie.size(), 0); |
| 123 | 89 |
| 124 if (!this._cookies.length) { | 90 if (!this._cookies.length) { |
| 125 // Nothing to show. | 91 // Nothing to show. |
| 126 this._emptyWidget.show(this.element); | 92 this._emptyWidget.show(this.element); |
| 127 this._filterButton.setEnabled(false); | 93 |
| 128 this._clearButton.setEnabled(false); | 94 this.filterButton.setEnabled(false); |
| 129 this._deleteButton.setEnabled(false); | 95 this.clearAllButton.setEnabled(false); |
| 96 this.deleteButton.setEnabled(false); | |
| 97 | |
| 130 if (this._cookiesTable) | 98 if (this._cookiesTable) |
| 131 this._cookiesTable.detach(); | 99 this._cookiesTable.detach(); |
| 132 return; | 100 return; |
| 133 } | 101 } |
| 134 | 102 |
| 135 if (!this._cookiesTable) { | 103 if (!this._cookiesTable) { |
| 136 this._cookiesTable = | 104 this._cookiesTable = |
| 137 new CookieTable.CookiesTable(false, this._update.bind(this), this._ena bleDeleteButton.bind(this)); | 105 new CookieTable.CookiesTable(false, this._update.bind(this), () => thi s.deleteButton.setEnabled(true)); |
| 138 } | 106 } |
| 139 | 107 |
| 140 var shownCookies = this._filterCookies(this._cookies); | 108 var shownCookies = this.filter(allCookies, cookie => `${cookie.name()} ${coo kie.value()} ${cookie.domain()}`); |
| 141 this._cookiesTable.setCookies(shownCookies); | 109 this._cookiesTable.setCookies(shownCookies); |
| 142 this._emptyWidget.detach(); | 110 this._emptyWidget.detach(); |
| 143 this._filterBar.show(this.element); | 111 this.showFilterBar(); |
| 144 this._cookiesTable.show(this.element); | 112 this._cookiesTable.show(this.element); |
| 145 this._treeElement.subtitle = | 113 this._treeElement.subtitle = |
| 146 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length, Number.bytesToString(this._totalSize)); | 114 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length, Number.bytesToString(this._totalSize)); |
| 147 this._filterButton.setEnabled(true); | 115 this.filterButton.setEnabled(true); |
| 148 this._clearButton.setEnabled(true); | 116 this.clearAllButton.setEnabled(true); |
| 149 this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie()); | 117 this.deleteButton.setEnabled(!!this._cookiesTable.selectedCookie()); |
| 150 } | |
| 151 | |
| 152 /** | |
| 153 * @param {!Array.<!SDK.Cookie>} cookies | |
| 154 */ | |
| 155 _filterCookies(cookies) { | |
| 156 if (!this._filterRegex) | |
| 157 return cookies; | |
| 158 | |
| 159 return cookies.filter(cookie => { | |
| 160 const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`; | |
| 161 return this._filterRegex.test(candidate); | |
| 162 }); | |
| 163 } | 118 } |
| 164 | 119 |
| 165 clear() { | 120 clear() { |
| 166 this._cookiesTable.clear(); | 121 this._cookiesTable.clear(); |
| 167 this._update(); | 122 this._update(); |
| 168 } | 123 } |
| 169 | 124 |
| 170 /** | 125 /** |
| 171 * @param {!Common.Event} event | 126 * @override |
| 172 */ | 127 */ |
| 173 _clearButtonClicked(event) { | 128 onClearAll() { |
| 174 this.clear(); | 129 this.clear(); |
| 175 } | 130 } |
| 176 | 131 |
| 177 _enableDeleteButton() { | |
| 178 this._deleteButton.setEnabled(true); | |
| 179 } | |
| 180 | |
| 181 /** | 132 /** |
| 182 * @param {!Common.Event} event | 133 * @override |
| 183 */ | 134 */ |
| 184 _deleteButtonClicked(event) { | 135 onDelete() { |
| 185 var selectedCookie = this._cookiesTable.selectedCookie(); | 136 var selectedCookie = this._cookiesTable.selectedCookie(); |
| 186 if (selectedCookie) { | 137 if (selectedCookie) { |
| 187 selectedCookie.remove(); | 138 selectedCookie.remove(); |
| 188 this._update(); | 139 this._update(); |
| 189 } | 140 } |
| 190 } | 141 } |
| 191 | 142 |
| 192 /** | 143 /** |
| 193 * @param {!Common.Event} event | 144 * @override |
| 194 */ | 145 */ |
| 195 _refreshButtonClicked(event) { | 146 onRefresh() { |
| 196 this._update(); | 147 this._update(); |
| 197 } | 148 } |
| 198 | 149 |
| 199 _contextMenu(event) { | 150 _contextMenu(event) { |
| 200 if (!this._cookies.length) { | 151 if (!this._cookies.length) { |
| 201 var contextMenu = new UI.ContextMenu(event); | 152 var contextMenu = new UI.ContextMenu(event); |
| 202 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this) ); | 153 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this) ); |
| 203 contextMenu.show(); | 154 contextMenu.show(); |
| 204 } | 155 } |
| 205 } | 156 } |
| 206 }; | 157 }; |
| OLD | NEW |