| 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 13 matching lines...) Expand all Loading... |
| 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 UI.SimpleView { |
| 34 constructor(treeElement, cookieDomain) { | 34 constructor(treeElement, target, cookieDomain) { |
| 35 super(Common.UIString('Cookies')); | 35 super(Common.UIString('Cookies')); |
| 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'); | 39 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete Selected')
, 'largeicon-delete'); |
| 40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del
eteButtonClicked, this); | 40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del
eteButtonClicked, this); |
| 41 | 41 |
| 42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg
eicon-clear'); | 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); | 43 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clea
rButtonClicked, this); |
| 44 | 44 |
| 45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); | 45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); |
| 46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re
freshButtonClicked, this); | 46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re
freshButtonClicked, this); |
| 47 | 47 |
| 48 this._filterBar = new UI.FilterBar('cookiesPanel', true); | 48 this._filterBar = new UI.FilterBar('cookiesPanel', true); |
| 49 this._textFilterUI = new UI.TextFilterUI(true); | 49 this._textFilterUI = new UI.TextFilterUI(true); |
| 50 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._
filterChanged, this); | 50 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._
filterChanged, this); |
| 51 this._filterBar.addFilter(this._textFilterUI); | 51 this._filterBar.addFilter(this._textFilterUI); |
| 52 | 52 |
| 53 this._filterSeparator = new UI.ToolbarSeparator(); | 53 this._filterSeparator = new UI.ToolbarSeparator(); |
| 54 this._filterButton = this._filterBar.filterButton(); | 54 this._filterButton = this._filterBar.filterButton(); |
| 55 | 55 |
| 56 this._target = target; |
| 56 this._treeElement = treeElement; | 57 this._treeElement = treeElement; |
| 57 this._cookieDomain = cookieDomain; | 58 this._cookieDomain = cookieDomain; |
| 58 | 59 |
| 59 this._emptyWidget = new UI.EmptyWidget( | 60 this._emptyWidget = new UI.EmptyWidget( |
| 60 cookieDomain ? | 61 cookieDomain ? |
| 61 Common.UIString('This site has no cookies.') : | 62 Common.UIString('This site has no cookies.') : |
| 62 Common.UIString( | 63 Common.UIString( |
| 63 'By default cookies are disabled for local files.\nYou could ove
rride this by starting the browser with --enable-file-cookies command line flag.
')); | 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.
')); |
| 64 this._emptyWidget.show(this.element); | 65 this._emptyWidget.show(this.element); |
| 65 | 66 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 91 /** | 92 /** |
| 92 * @param {!Common.Event} event | 93 * @param {!Common.Event} event |
| 93 */ | 94 */ |
| 94 _filterChanged(event) { | 95 _filterChanged(event) { |
| 95 var text = this._textFilterUI.value(); | 96 var text = this._textFilterUI.value(); |
| 96 this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i'); | 97 this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i'); |
| 97 this._update(); | 98 this._update(); |
| 98 } | 99 } |
| 99 | 100 |
| 100 _update() { | 101 _update() { |
| 101 SDK.Cookies.getCookiesAsync(this._updateWithCookies.bind(this)); | 102 var resourceURLs = []; |
| 103 var cookieDomain = this._cookieDomain; |
| 104 /** |
| 105 * @param {!SDK.Resource} resource |
| 106 */ |
| 107 function populateResourceURLs(resource) { |
| 108 var url = resource.documentURL.asParsedURL(); |
| 109 if (url && url.securityOrigin() === cookieDomain) |
| 110 resourceURLs.push(resource.url); |
| 111 } |
| 112 |
| 113 SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResou
rceURLs); |
| 114 SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCook
ies.bind(this)); |
| 102 } | 115 } |
| 103 | 116 |
| 104 /** | 117 /** |
| 105 * @param {!Array.<!SDK.Cookie>} allCookies | 118 * @param {!Array.<!SDK.Cookie>} allCookies |
| 106 */ | 119 */ |
| 107 _updateWithCookies(allCookies) { | 120 _updateWithCookies(allCookies) { |
| 108 this._cookies = this._filterCookiesForDomain(allCookies); | 121 this._cookies = allCookies; |
| 122 this._totalSize = allCookies.reduce((size, cookie) => size + cookie.size(),
0); |
| 109 | 123 |
| 110 if (!this._cookies.length) { | 124 if (!this._cookies.length) { |
| 111 // Nothing to show. | 125 // Nothing to show. |
| 112 this._emptyWidget.show(this.element); | 126 this._emptyWidget.show(this.element); |
| 113 this._filterButton.setEnabled(false); | 127 this._filterButton.setEnabled(false); |
| 114 this._clearButton.setEnabled(false); | 128 this._clearButton.setEnabled(false); |
| 115 this._deleteButton.setEnabled(false); | 129 this._deleteButton.setEnabled(false); |
| 116 if (this._cookiesTable) | 130 if (this._cookiesTable) |
| 117 this._cookiesTable.detach(); | 131 this._cookiesTable.detach(); |
| 118 return; | 132 return; |
| 119 } | 133 } |
| 120 | 134 |
| 121 if (!this._cookiesTable) { | 135 if (!this._cookiesTable) { |
| 122 this._cookiesTable = | 136 this._cookiesTable = |
| 123 new CookieTable.CookiesTable(false, this._update.bind(this), this._ena
bleDeleteButton.bind(this)); | 137 new CookieTable.CookiesTable(false, this._update.bind(this), this._ena
bleDeleteButton.bind(this)); |
| 124 } | 138 } |
| 125 | 139 |
| 126 var shownCookies = this._filterCookiesForFilters(this._cookies); | 140 var shownCookies = this._filterCookies(this._cookies); |
| 127 this._cookiesTable.setCookies(shownCookies); | 141 this._cookiesTable.setCookies(shownCookies); |
| 128 this._emptyWidget.detach(); | 142 this._emptyWidget.detach(); |
| 129 this._filterBar.show(this.element); | 143 this._filterBar.show(this.element); |
| 130 this._cookiesTable.show(this.element); | 144 this._cookiesTable.show(this.element); |
| 131 this._treeElement.subtitle = | 145 this._treeElement.subtitle = |
| 132 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length,
Number.bytesToString(this._totalSize)); | 146 String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length,
Number.bytesToString(this._totalSize)); |
| 133 this._filterButton.setEnabled(true); | 147 this._filterButton.setEnabled(true); |
| 134 this._clearButton.setEnabled(true); | 148 this._clearButton.setEnabled(true); |
| 135 this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie()); | 149 this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie()); |
| 136 } | 150 } |
| 137 | 151 |
| 138 /** | 152 /** |
| 139 * @param {!Array.<!SDK.Cookie>} cookies | 153 * @param {!Array.<!SDK.Cookie>} cookies |
| 140 */ | 154 */ |
| 141 _filterCookiesForFilters(cookies) { | 155 _filterCookies(cookies) { |
| 142 if (!this._filterRegex) | 156 if (!this._filterRegex) |
| 143 return cookies; | 157 return cookies; |
| 144 | 158 |
| 145 return cookies.filter(cookie => { | 159 return cookies.filter(cookie => { |
| 146 const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`; | 160 const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`; |
| 147 return this._filterRegex.test(candidate); | 161 return this._filterRegex.test(candidate); |
| 148 }); | 162 }); |
| 149 } | 163 } |
| 150 | 164 |
| 151 /** | |
| 152 * @param {!Array.<!SDK.Cookie>} allCookies | |
| 153 */ | |
| 154 _filterCookiesForDomain(allCookies) { | |
| 155 var cookies = []; | |
| 156 var resourceURLsForDocumentURL = []; | |
| 157 this._totalSize = 0; | |
| 158 | |
| 159 /** | |
| 160 * @this {Resources.CookieItemsView} | |
| 161 */ | |
| 162 function populateResourcesForDocuments(resource) { | |
| 163 var url = resource.documentURL.asParsedURL(); | |
| 164 if (url && url.securityOrigin() === this._cookieDomain) | |
| 165 resourceURLsForDocumentURL.push(resource.url); | |
| 166 } | |
| 167 Bindings.forAllResources(populateResourcesForDocuments.bind(this)); | |
| 168 | |
| 169 for (var i = 0; i < allCookies.length; ++i) { | |
| 170 var pushed = false; | |
| 171 var size = allCookies[i].size(); | |
| 172 for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) { | |
| 173 var resourceURL = resourceURLsForDocumentURL[j]; | |
| 174 if (SDK.Cookies.cookieMatchesResourceURL(allCookies[i], resourceURL)) { | |
| 175 this._totalSize += size; | |
| 176 if (!pushed) { | |
| 177 pushed = true; | |
| 178 cookies.push(allCookies[i]); | |
| 179 } | |
| 180 } | |
| 181 } | |
| 182 } | |
| 183 return cookies; | |
| 184 } | |
| 185 | |
| 186 clear() { | 165 clear() { |
| 187 this._cookiesTable.clear(); | 166 this._cookiesTable.clear(); |
| 188 this._update(); | 167 this._update(); |
| 189 } | 168 } |
| 190 | 169 |
| 191 /** | 170 /** |
| 192 * @param {!Common.Event} event | 171 * @param {!Common.Event} event |
| 193 */ | 172 */ |
| 194 _clearButtonClicked(event) { | 173 _clearButtonClicked(event) { |
| 195 this.clear(); | 174 this.clear(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 218 } | 197 } |
| 219 | 198 |
| 220 _contextMenu(event) { | 199 _contextMenu(event) { |
| 221 if (!this._cookies.length) { | 200 if (!this._cookies.length) { |
| 222 var contextMenu = new UI.ContextMenu(event); | 201 var contextMenu = new UI.ContextMenu(event); |
| 223 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this)
); | 202 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this)
); |
| 224 contextMenu.show(); | 203 contextMenu.show(); |
| 225 } | 204 } |
| 226 } | 205 } |
| 227 }; | 206 }; |
| OLD | NEW |