| 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 WebInspector.CookieItemsView = class extends WebInspector.SimpleView { | 33 Resources.CookieItemsView = class extends UI.SimpleView { |
| 34 constructor(treeElement, cookieDomain) { | 34 constructor(treeElement, cookieDomain) { |
| 35 super(WebInspector.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 WebInspector.ToolbarButton(WebInspector.UIString('D
elete'), 'largeicon-delete'); | 39 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largei
con-delete'); |
| 40 this._deleteButton.setVisible(false); | 40 this._deleteButton.setVisible(false); |
| 41 this._deleteButton.addEventListener('click', this._deleteButtonClicked, this
); | 41 this._deleteButton.addEventListener('click', this._deleteButtonClicked, this
); |
| 42 | 42 |
| 43 this._clearButton = new WebInspector.ToolbarButton(WebInspector.UIString('Cl
ear'), 'largeicon-clear'); | 43 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear'), 'largeico
n-clear'); |
| 44 this._clearButton.setVisible(false); | 44 this._clearButton.setVisible(false); |
| 45 this._clearButton.addEventListener('click', this._clearButtonClicked, this); | 45 this._clearButton.addEventListener('click', this._clearButtonClicked, this); |
| 46 | 46 |
| 47 this._refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString('
Refresh'), 'largeicon-refresh'); | 47 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); |
| 48 this._refreshButton.addEventListener('click', this._refreshButtonClicked, th
is); | 48 this._refreshButton.addEventListener('click', this._refreshButtonClicked, th
is); |
| 49 | 49 |
| 50 this._treeElement = treeElement; | 50 this._treeElement = treeElement; |
| 51 this._cookieDomain = cookieDomain; | 51 this._cookieDomain = cookieDomain; |
| 52 | 52 |
| 53 this._emptyWidget = new WebInspector.EmptyWidget( | 53 this._emptyWidget = new UI.EmptyWidget( |
| 54 cookieDomain ? | 54 cookieDomain ? |
| 55 WebInspector.UIString('This site has no cookies.') : | 55 Common.UIString('This site has no cookies.') : |
| 56 WebInspector.UIString( | 56 Common.UIString( |
| 57 'By default cookies are disabled for local files.\nYou could ove
rride this by starting the browser with --enable-file-cookies command line flag.
')); | 57 'By default cookies are disabled for local files.\nYou could ove
rride this by starting the browser with --enable-file-cookies command line flag.
')); |
| 58 this._emptyWidget.show(this.element); | 58 this._emptyWidget.show(this.element); |
| 59 | 59 |
| 60 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t
rue); | 60 this.element.addEventListener('contextmenu', this._contextMenu.bind(this), t
rue); |
| 61 } | 61 } |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * @override | 64 * @override |
| 65 * @return {!Array.<!WebInspector.ToolbarItem>} | 65 * @return {!Array.<!UI.ToolbarItem>} |
| 66 */ | 66 */ |
| 67 syncToolbarItems() { | 67 syncToolbarItems() { |
| 68 return [this._refreshButton, this._clearButton, this._deleteButton]; | 68 return [this._refreshButton, this._clearButton, this._deleteButton]; |
| 69 } | 69 } |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * @override | 72 * @override |
| 73 */ | 73 */ |
| 74 wasShown() { | 74 wasShown() { |
| 75 this._update(); | 75 this._update(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * @override | 79 * @override |
| 80 */ | 80 */ |
| 81 willHide() { | 81 willHide() { |
| 82 this._deleteButton.setVisible(false); | 82 this._deleteButton.setVisible(false); |
| 83 } | 83 } |
| 84 | 84 |
| 85 _update() { | 85 _update() { |
| 86 WebInspector.Cookies.getCookiesAsync(this._updateWithCookies.bind(this)); | 86 SDK.Cookies.getCookiesAsync(this._updateWithCookies.bind(this)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * @param {!Array.<!WebInspector.Cookie>} allCookies | 90 * @param {!Array.<!SDK.Cookie>} allCookies |
| 91 */ | 91 */ |
| 92 _updateWithCookies(allCookies) { | 92 _updateWithCookies(allCookies) { |
| 93 this._cookies = this._filterCookiesForDomain(allCookies); | 93 this._cookies = this._filterCookiesForDomain(allCookies); |
| 94 | 94 |
| 95 if (!this._cookies.length) { | 95 if (!this._cookies.length) { |
| 96 // Nothing to show. | 96 // Nothing to show. |
| 97 this._emptyWidget.show(this.element); | 97 this._emptyWidget.show(this.element); |
| 98 this._clearButton.setVisible(false); | 98 this._clearButton.setVisible(false); |
| 99 this._deleteButton.setVisible(false); | 99 this._deleteButton.setVisible(false); |
| 100 if (this._cookiesTable) | 100 if (this._cookiesTable) |
| 101 this._cookiesTable.detach(); | 101 this._cookiesTable.detach(); |
| 102 return; | 102 return; |
| 103 } | 103 } |
| 104 | 104 |
| 105 if (!this._cookiesTable) | 105 if (!this._cookiesTable) |
| 106 this._cookiesTable = | 106 this._cookiesTable = |
| 107 new WebInspector.CookiesTable(false, this._update.bind(this), this._sh
owDeleteButton.bind(this)); | 107 new Components.CookiesTable(false, this._update.bind(this), this._show
DeleteButton.bind(this)); |
| 108 | 108 |
| 109 this._cookiesTable.setCookies(this._cookies); | 109 this._cookiesTable.setCookies(this._cookies); |
| 110 this._emptyWidget.detach(); | 110 this._emptyWidget.detach(); |
| 111 this._cookiesTable.show(this.element); | 111 this._cookiesTable.show(this.element); |
| 112 this._treeElement.subtitle = String.sprintf( | 112 this._treeElement.subtitle = String.sprintf( |
| 113 WebInspector.UIString('%d cookies (%s)'), this._cookies.length, Number.b
ytesToString(this._totalSize)); | 113 Common.UIString('%d cookies (%s)'), this._cookies.length, Number.bytesTo
String(this._totalSize)); |
| 114 this._clearButton.setVisible(true); | 114 this._clearButton.setVisible(true); |
| 115 this._deleteButton.setVisible(!!this._cookiesTable.selectedCookie()); | 115 this._deleteButton.setVisible(!!this._cookiesTable.selectedCookie()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * @param {!Array.<!WebInspector.Cookie>} allCookies | 119 * @param {!Array.<!SDK.Cookie>} allCookies |
| 120 */ | 120 */ |
| 121 _filterCookiesForDomain(allCookies) { | 121 _filterCookiesForDomain(allCookies) { |
| 122 var cookies = []; | 122 var cookies = []; |
| 123 var resourceURLsForDocumentURL = []; | 123 var resourceURLsForDocumentURL = []; |
| 124 this._totalSize = 0; | 124 this._totalSize = 0; |
| 125 | 125 |
| 126 /** | 126 /** |
| 127 * @this {WebInspector.CookieItemsView} | 127 * @this {Resources.CookieItemsView} |
| 128 */ | 128 */ |
| 129 function populateResourcesForDocuments(resource) { | 129 function populateResourcesForDocuments(resource) { |
| 130 var url = resource.documentURL.asParsedURL(); | 130 var url = resource.documentURL.asParsedURL(); |
| 131 if (url && url.securityOrigin() === this._cookieDomain) | 131 if (url && url.securityOrigin() === this._cookieDomain) |
| 132 resourceURLsForDocumentURL.push(resource.url); | 132 resourceURLsForDocumentURL.push(resource.url); |
| 133 } | 133 } |
| 134 WebInspector.forAllResources(populateResourcesForDocuments.bind(this)); | 134 Bindings.forAllResources(populateResourcesForDocuments.bind(this)); |
| 135 | 135 |
| 136 for (var i = 0; i < allCookies.length; ++i) { | 136 for (var i = 0; i < allCookies.length; ++i) { |
| 137 var pushed = false; | 137 var pushed = false; |
| 138 var size = allCookies[i].size(); | 138 var size = allCookies[i].size(); |
| 139 for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) { | 139 for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) { |
| 140 var resourceURL = resourceURLsForDocumentURL[j]; | 140 var resourceURL = resourceURLsForDocumentURL[j]; |
| 141 if (WebInspector.Cookies.cookieMatchesResourceURL(allCookies[i], resourc
eURL)) { | 141 if (SDK.Cookies.cookieMatchesResourceURL(allCookies[i], resourceURL)) { |
| 142 this._totalSize += size; | 142 this._totalSize += size; |
| 143 if (!pushed) { | 143 if (!pushed) { |
| 144 pushed = true; | 144 pushed = true; |
| 145 cookies.push(allCookies[i]); | 145 cookies.push(allCookies[i]); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 return cookies; | 150 return cookies; |
| 151 } | 151 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 170 this._update(); | 170 this._update(); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 _refreshButtonClicked(event) { | 174 _refreshButtonClicked(event) { |
| 175 this._update(); | 175 this._update(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 _contextMenu(event) { | 178 _contextMenu(event) { |
| 179 if (!this._cookies.length) { | 179 if (!this._cookies.length) { |
| 180 var contextMenu = new WebInspector.ContextMenu(event); | 180 var contextMenu = new UI.ContextMenu(event); |
| 181 contextMenu.appendItem(WebInspector.UIString('Refresh'), this._update.bind
(this)); | 181 contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this)
); |
| 182 contextMenu.show(); | 182 contextMenu.show(); |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 }; | 185 }; |
| OLD | NEW |