| Index: third_party/WebKit/Source/devtools/front_end/resources/CookieItemsView.js
|
| diff --git a/third_party/WebKit/Source/devtools/front_end/resources/CookieItemsView.js b/third_party/WebKit/Source/devtools/front_end/resources/CookieItemsView.js
|
| index 3043976370aca7c2130e2fc0c44f5d240b9f9755..cfc808334389e854f79f578489a1ff53a0dc1b01 100644
|
| --- a/third_party/WebKit/Source/devtools/front_end/resources/CookieItemsView.js
|
| +++ b/third_party/WebKit/Source/devtools/front_end/resources/CookieItemsView.js
|
| @@ -27,84 +27,26 @@
|
| * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| */
|
|
|
| -/**
|
| - * @unrestricted
|
| - */
|
| -Resources.CookieItemsView = class extends UI.SimpleView {
|
| +Resources.CookieItemsView = class extends Resources.StorageItemsView {
|
| + /**
|
| + * @param {!Resources.CookieTreeElement} treeElement
|
| + * @param {!SDK.Target} target
|
| + * @param {string} cookieDomain
|
| + */
|
| constructor(treeElement, target, cookieDomain) {
|
| - super(Common.UIString('Cookies'));
|
| + super(Common.UIString('Cookies'), 'cookiesPanel');
|
|
|
| this.element.classList.add('storage-view');
|
|
|
| - this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete Selected'), 'largeicon-delete');
|
| - this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._deleteButtonClicked, this);
|
| -
|
| - this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'largeicon-clear');
|
| - this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clearButtonClicked, this);
|
| -
|
| - this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'largeicon-refresh');
|
| - this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._refreshButtonClicked, this);
|
| -
|
| - this._filterBar = new UI.FilterBar('cookiesPanel', true);
|
| - this._textFilterUI = new UI.TextFilterUI(true);
|
| - this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged, this);
|
| - this._filterBar.addFilter(this._textFilterUI);
|
| -
|
| - this._filterSeparator = new UI.ToolbarSeparator();
|
| - this._filterButton = this._filterBar.filterButton();
|
| -
|
| this._target = target;
|
| this._treeElement = treeElement;
|
| this._cookieDomain = cookieDomain;
|
|
|
| - this.element.addEventListener('contextmenu', this._contextMenu.bind(this), true);
|
| - }
|
| -
|
| - /**
|
| - * @override
|
| - * @return {!Array.<!UI.ToolbarItem>}
|
| - */
|
| - syncToolbarItems() {
|
| - return [this._refreshButton, this._clearButton, this._deleteButton, this._filterSeparator, this._filterButton];
|
| - }
|
| -
|
| - /**
|
| - * @override
|
| - */
|
| - wasShown() {
|
| - this._update();
|
| - }
|
| -
|
| - /**
|
| - * @override
|
| - */
|
| - willHide() {
|
| - this._deleteButton.setEnabled(false);
|
| - }
|
| -
|
| - /**
|
| - * @param {!Common.Event} event
|
| - */
|
| - _filterChanged(event) {
|
| - var text = this._textFilterUI.value();
|
| - this._filterRegex = text && new RegExp(text.escapeForRegExp(), 'i');
|
| - this._update();
|
| - }
|
| -
|
| - _update() {
|
| - var resourceURLs = [];
|
| - var cookieDomain = this._cookieDomain;
|
| - /**
|
| - * @param {!SDK.Resource} resource
|
| - */
|
| - function populateResourceURLs(resource) {
|
| - var url = resource.documentURL.asParsedURL();
|
| - if (url && url.securityOrigin() === cookieDomain)
|
| - resourceURLs.push(resource.url);
|
| - }
|
| -
|
| - SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResourceURLs);
|
| - SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCookies.bind(this));
|
| + /** @type {?Array<!SDK.Cookie>} */
|
| + this._cookies = null;
|
| + this._totalSize = 0;
|
| + /** @type {?CookieTable.CookiesTable} */
|
| + this._cookiesTable = null;
|
| }
|
|
|
| /**
|
| @@ -117,73 +59,55 @@ Resources.CookieItemsView = class extends UI.SimpleView {
|
| if (!this._cookiesTable) {
|
| const parsedURL = this._cookieDomain.asParsedURL();
|
| const domain = parsedURL ? parsedURL.host : '';
|
| - this._cookiesTable =
|
| - new CookieTable.CookiesTable(false, this._update.bind(this), this._enableDeleteButton.bind(this), domain);
|
| + this._cookiesTable = new CookieTable.CookiesTable(
|
| + false, this.refreshItems.bind(this), () => this.setCanDeleteSelected(true), domain);
|
| }
|
|
|
| - var shownCookies = this._filterCookies(this._cookies);
|
| + var shownCookies = this.filter(allCookies, cookie => `${cookie.name()} ${cookie.value()} ${cookie.domain()}`);
|
| this._cookiesTable.setCookies(shownCookies);
|
| - this._filterBar.show(this.element);
|
| this._cookiesTable.show(this.element);
|
| this._treeElement.subtitle =
|
| String.sprintf(Common.UIString('%d cookies (%s)'), this._cookies.length, Number.bytesToString(this._totalSize));
|
| - this._filterButton.setEnabled(true);
|
| - this._clearButton.setEnabled(true);
|
| - this._deleteButton.setEnabled(!!this._cookiesTable.selectedCookie());
|
| + this.setCanFilter(true);
|
| + this.setCanDeleteAll(true);
|
| + this.setCanDeleteSelected(!!this._cookiesTable.selectedCookie());
|
| }
|
|
|
| /**
|
| - * @param {!Array.<!SDK.Cookie>} cookies
|
| + * @override
|
| */
|
| - _filterCookies(cookies) {
|
| - if (!this._filterRegex)
|
| - return cookies;
|
| -
|
| - return cookies.filter(cookie => {
|
| - const candidate = `${cookie.name()} ${cookie.value()} ${cookie.domain()}`;
|
| - return this._filterRegex.test(candidate);
|
| - });
|
| - }
|
| -
|
| - clear() {
|
| + deleteAllItems() {
|
| this._cookiesTable.clear();
|
| - this._update();
|
| - }
|
| -
|
| - /**
|
| - * @param {!Common.Event} event
|
| - */
|
| - _clearButtonClicked(event) {
|
| - this.clear();
|
| - }
|
| -
|
| - _enableDeleteButton() {
|
| - this._deleteButton.setEnabled(true);
|
| + this.refreshItems();
|
| }
|
|
|
| /**
|
| - * @param {!Common.Event} event
|
| + * @override
|
| */
|
| - _deleteButtonClicked(event) {
|
| + deleteSelectedItem() {
|
| var selectedCookie = this._cookiesTable.selectedCookie();
|
| if (selectedCookie) {
|
| selectedCookie.remove();
|
| - this._update();
|
| + this.refreshItems();
|
| }
|
| }
|
|
|
| /**
|
| - * @param {!Common.Event} event
|
| + * @override
|
| */
|
| - _refreshButtonClicked(event) {
|
| - this._update();
|
| - }
|
| -
|
| - _contextMenu(event) {
|
| - if (!this._cookies.length) {
|
| - var contextMenu = new UI.ContextMenu(event);
|
| - contextMenu.appendItem(Common.UIString('Refresh'), this._update.bind(this));
|
| - contextMenu.show();
|
| + refreshItems() {
|
| + var resourceURLs = [];
|
| + var cookieDomain = this._cookieDomain;
|
| + /**
|
| + * @param {!SDK.Resource} resource
|
| + */
|
| + function populateResourceURLs(resource) {
|
| + var url = resource.documentURL.asParsedURL();
|
| + if (url && url.securityOrigin() === cookieDomain)
|
| + resourceURLs.push(resource.url);
|
| }
|
| +
|
| + SDK.ResourceTreeModel.fromTarget(this._target).forAllResources(populateResourceURLs);
|
| + SDK.Cookies.getCookiesAsync(this._target, resourceURLs, this._updateWithCookies.bind(this));
|
| }
|
| };
|
|
|