Web Inspector: [Resources] Prefactorings in DataGrid and CookieTable
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Feb 2013 10:11:46 +0000 (10:11 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Feb 2013 10:11:46 +0000 (10:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109141

Patch by Eugene Klyuchnikov <eustas@chromium.org> on 2013-02-11
Reviewed by Vsevolod Vlasov.

1) Make deleteCookie method static and move to WebInspector.Cookie
2) Replace resfreshCallback getter/setter in DataGrid with
constructor parameter

* inspector/front-end/CookieItemsView.js: Adopt changes.
* inspector/front-end/CookieParser.js:
(WebInspector.Cookie.prototype.remove): Moved from CookiesTable.
* inspector/front-end/CookiesTable.js: Adopt changes.
* inspector/front-end/DataGrid.js:
Replace setter with constructor parameter.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142441 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/CookieItemsView.js
Source/WebCore/inspector/front-end/CookieParser.js
Source/WebCore/inspector/front-end/CookiesTable.js
Source/WebCore/inspector/front-end/DataGrid.js

index e78937fc1079ac51327ab5af525e0313765f5f00..e160aa221c5d44cb3e2aab36470d8ba11efbae02 100644 (file)
@@ -1,3 +1,21 @@
+2013-02-11  Eugene Klyuchnikov  <eustas@chromium.org>
+
+        Web Inspector: [Resources] Prefactorings in DataGrid and CookieTable
+        https://bugs.webkit.org/show_bug.cgi?id=109141
+
+        Reviewed by Vsevolod Vlasov.
+
+        1) Make deleteCookie method static and move to WebInspector.Cookie
+        2) Replace resfreshCallback getter/setter in DataGrid with
+        constructor parameter
+
+        * inspector/front-end/CookieItemsView.js: Adopt changes.
+        * inspector/front-end/CookieParser.js:
+        (WebInspector.Cookie.prototype.remove): Moved from CookiesTable.
+        * inspector/front-end/CookiesTable.js: Adopt changes.
+        * inspector/front-end/DataGrid.js:
+        Replace setter with constructor parameter.
+
 2013-02-11  John J. Barton  <johnjbarton@chromium.org>
 
         Web Inspector: Don't throw exceptions in WebInspector.Color
index 00492d5fbf4fa15b587cc1a72a3975b194c404d5..d981a7f7a5a15033c0129f6cafdff68bd6fbe8d2 100644 (file)
@@ -92,7 +92,7 @@ WebInspector.CookieItemsView.prototype = {
         }
 
         if (!this._cookiesTable)
-            this._cookiesTable = isAdvanced ? new WebInspector.CookiesTable(false, this._deleteCookie.bind(this), this._update.bind(this)) : new WebInspector.SimpleCookiesTable();
+            this._cookiesTable = isAdvanced ? new WebInspector.CookiesTable(false, this._update.bind(this)) : new WebInspector.SimpleCookiesTable();
 
         this._cookiesTable.setCookies(this._cookies);
         this._emptyView.detach();
@@ -138,20 +138,13 @@ WebInspector.CookieItemsView.prototype = {
         return cookies;
     },
 
-    /**
-     * @param {!WebInspector.Cookie} cookie
-     */
-    _deleteCookie: function(cookie)
-    {
-        PageAgent.deleteCookie(cookie.name(), (cookie.secure() ? "https://" : "http://") + cookie.domain() + cookie.path());
-        this._update();
-    },
-
     _deleteButtonClicked: function()
     {
         var selectedCookie = this._cookiesTable.selectedCookie();
-        if (selectedCookie)
-            this._deleteCookie(selectedCookie);
+        if (selectedCookie) {
+            selectedCookie.remove();
+            this._update();
+        }
     },
 
     _refreshButtonClicked: function(event)
index 0cd67066d163c87a067556e581450f97149e677a..80f4cd6679c4a62b18c8332b9e084ee2a2301379 100644 (file)
@@ -349,6 +349,14 @@ WebInspector.Cookie.prototype = {
     addAttribute: function(key, value)
     {
         this._attributes[key.toLowerCase()] = value;
+    },
+
+    /**
+     * @param {function(?Protocol.Error)=} callback
+     */
+    remove: function(callback)
+    {
+        PageAgent.deleteCookie(this.name(), (this.secure() ? "https://" : "http://") + this.domain() + this.path(), callback);
     }
 }
 
index 8798eb14e50403f0852eade8d4110663f23afc39..5cc6c3b0eeaaa5e75f0864b5ac8c088d67fe8e5c 100644 (file)
  * @constructor
  * @extends {WebInspector.View}
  * @param {boolean} expandable
- * @param {function(!WebInspector.Cookie)=} deleteCallback
  * @param {function()=} refreshCallback
  */
-WebInspector.CookiesTable = function(expandable, deleteCallback, refreshCallback)
+WebInspector.CookiesTable = function(expandable, refreshCallback)
 {
     WebInspector.View.call(this);
     this.element.className = "fill";
 
+    var readOnly = expandable;
+    this._refreshCallback = refreshCallback;
+
     var columns = {name: {}, value: {}, domain: {}, path: {}, expires: {}, size: {}, httpOnly: {}, secure: {}};
     columns.name.title = WebInspector.UIString("Name");
     columns.name.sortable = true;
@@ -71,9 +73,8 @@ WebInspector.CookiesTable = function(expandable, deleteCallback, refreshCallback
     columns.secure.sortable = true;
     columns.secure.width = "7%";
 
-    this._dataGrid = new WebInspector.DataGrid(columns, undefined, deleteCallback ? this._onDeleteFromGrid.bind(this, deleteCallback) : undefined);
+    this._dataGrid = new WebInspector.DataGrid(columns, null, readOnly ? null : this._onDeleteCookie.bind(this), refreshCallback);
     this._dataGrid.addEventListener("sorting changed", this._rebuildTable, this);
-    this._dataGrid.refreshCallback = refreshCallback;
 
     this._nextSelectedCookie = /** @type {?WebInspector.Cookie} */ (null);
 
@@ -241,13 +242,15 @@ WebInspector.CookiesTable.prototype = {
         return node;
     },
 
-    _onDeleteFromGrid: function(deleteCallback, node)
+    _onDeleteCookie: function(node)
     {
         var cookie = node.cookie;
         var neighbour = node.traverseNextNode() || node.traversePreviousNode();
         if (neighbour)
             this._nextSelectedCookie = neighbour.cookie;
-        deleteCallback(cookie);
+        cookie.remove();
+        if (this._refreshCallback)
+            this._refreshCallback();
     },
 
     __proto__: WebInspector.View.prototype
index c0ed262a0c37413a4bf469bde59f64e191a99b9d..f1fdfd501fd131c74c37ecc0acac5e123cfd9bb7 100644 (file)
 /**
  * @constructor
  * @extends {WebInspector.View}
- * @param {function(WebInspector.DataGridNode, string, string, string)=} editCallback
- * @param {function(WebInspector.DataGridNode)=} deleteCallback
+ * @param {?function(WebInspector.DataGridNode, string, string, string)=} editCallback
+ * @param {?function(WebInspector.DataGridNode)=} deleteCallback
+ * @param {?function()=} refreshCallback
  */
-WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
+WebInspector.DataGrid = function(columns, editCallback, deleteCallback, refreshCallback)
 {
     WebInspector.View.call(this);
     this.registerRequiredCSS("dataGrid.css");
@@ -52,12 +53,11 @@ WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
 
     // FIXME: Add a createCallback which is different from editCallback and has different
     // behavior when creating a new node.
-    if (editCallback) {
+    if (editCallback)
         this._dataTable.addEventListener("dblclick", this._ondblclick.bind(this), false);
-        this._editCallback = editCallback;
-    }
-    if (deleteCallback)
-        this._deleteCallback = deleteCallback;
+    this._editCallback = editCallback;
+    this._deleteCallback = deleteCallback;
+    this._refreshCallback = refreshCallback;
 
     this.aligned = {};
 
@@ -260,16 +260,6 @@ WebInspector.DataGrid.prototype = {
         return this._rootNode;
     },
 
-    get refreshCallback()
-    {
-        return this._refreshCallback;
-    },
-
-    set refreshCallback(refreshCallback)
-    {
-        this._refreshCallback = refreshCallback;
-    },
-
     _ondblclick: function(event)
     {
         if (this._editing || this._editingNode)