Web Inspector: DOMDebugger: move breakpoint storage to use `WI.ObjectStore`
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 19:17:14 +0000 (19:17 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 19:17:14 +0000 (19:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196231
<rdar://problem/49236864>

Reviewed by Joseph Pecoraro.

* UserInterface/Controllers/DOMDebuggerManager.js:
(WI.DOMDebuggerManager):
(WI.DOMDebuggerManager.prototype.addDOMBreakpoint):
(WI.DOMDebuggerManager.prototype.removeDOMBreakpoint):
(WI.DOMDebuggerManager.prototype.removeDOMBreakpointsForNode):
(WI.DOMDebuggerManager.prototype.addEventBreakpoint):
(WI.DOMDebuggerManager.prototype.removeEventBreakpoint):
(WI.DOMDebuggerManager.prototype.addURLBreakpoint):
(WI.DOMDebuggerManager.prototype.removeURLBreakpoint):
(WI.DOMDebuggerManager.prototype._handleDOMBreakpointDisabledStateChanged):
(WI.DOMDebuggerManager.prototype._handleEventBreakpointDisabledStateChanged):
(WI.DOMDebuggerManager.prototype._handleURLBreakpointDisabledStateChanged):
(WI.DOMDebuggerManager.prototype._saveDOMBreakpoints): Deleted.
(WI.DOMDebuggerManager.prototype._saveEventBreakpoints): Deleted.
(WI.DOMDebuggerManager.prototype._saveURLBreakpoints): Deleted.

* UserInterface/Models/DOMBreakpoint.js:
(WI.DOMBreakpoint.prototype.saveIdentityToCookie):
(WI.DOMBreakpoint.prototype.toJSON): Added.
(WI.DOMBreakpoint.prototype.get serializableInfo): Deleted.
* UserInterface/Models/EventBreakpoint.js:
(WI.EventBreakpoint.prototype.saveIdentityToCookie):
(WI.EventBreakpoint.prototype.toJSON): Added.
(WI.EventBreakpoint.prototype.get serializableInfo): Deleted.
* UserInterface/Models/URLBreakpoint.js:
(WI.URLBreakpoint.prototype.saveIdentityToCookie):
(WI.URLBreakpoint.prototype.toJSON): Added.
(WI.URLBreakpoint.prototype.get serializableInfo): Deleted.
Replace `get serializableInfo` with `toJSON` as required by `WI.ObjectStore`.

* UserInterface/Base/ObjectStore.js:
(WI.ObjectStore._open):
Increment version.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/ObjectStore.js
Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js
Source/WebInspectorUI/UserInterface/Models/DOMBreakpoint.js
Source/WebInspectorUI/UserInterface/Models/EventBreakpoint.js
Source/WebInspectorUI/UserInterface/Models/URLBreakpoint.js

index f18f4ec..b8ac3b9 100644 (file)
@@ -1,5 +1,47 @@
 2019-04-15  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: DOMDebugger: move breakpoint storage to use `WI.ObjectStore`
+        https://bugs.webkit.org/show_bug.cgi?id=196231
+        <rdar://problem/49236864>
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Controllers/DOMDebuggerManager.js:
+        (WI.DOMDebuggerManager):
+        (WI.DOMDebuggerManager.prototype.addDOMBreakpoint):
+        (WI.DOMDebuggerManager.prototype.removeDOMBreakpoint):
+        (WI.DOMDebuggerManager.prototype.removeDOMBreakpointsForNode):
+        (WI.DOMDebuggerManager.prototype.addEventBreakpoint):
+        (WI.DOMDebuggerManager.prototype.removeEventBreakpoint):
+        (WI.DOMDebuggerManager.prototype.addURLBreakpoint):
+        (WI.DOMDebuggerManager.prototype.removeURLBreakpoint):
+        (WI.DOMDebuggerManager.prototype._handleDOMBreakpointDisabledStateChanged):
+        (WI.DOMDebuggerManager.prototype._handleEventBreakpointDisabledStateChanged):
+        (WI.DOMDebuggerManager.prototype._handleURLBreakpointDisabledStateChanged):
+        (WI.DOMDebuggerManager.prototype._saveDOMBreakpoints): Deleted.
+        (WI.DOMDebuggerManager.prototype._saveEventBreakpoints): Deleted.
+        (WI.DOMDebuggerManager.prototype._saveURLBreakpoints): Deleted.
+
+        * UserInterface/Models/DOMBreakpoint.js:
+        (WI.DOMBreakpoint.prototype.saveIdentityToCookie):
+        (WI.DOMBreakpoint.prototype.toJSON): Added.
+        (WI.DOMBreakpoint.prototype.get serializableInfo): Deleted.
+        * UserInterface/Models/EventBreakpoint.js:
+        (WI.EventBreakpoint.prototype.saveIdentityToCookie):
+        (WI.EventBreakpoint.prototype.toJSON): Added.
+        (WI.EventBreakpoint.prototype.get serializableInfo): Deleted.
+        * UserInterface/Models/URLBreakpoint.js:
+        (WI.URLBreakpoint.prototype.saveIdentityToCookie):
+        (WI.URLBreakpoint.prototype.toJSON): Added.
+        (WI.URLBreakpoint.prototype.get serializableInfo): Deleted.
+        Replace `get serializableInfo` with `toJSON` as required by `WI.ObjectStore`.
+
+        * UserInterface/Base/ObjectStore.js:
+        (WI.ObjectStore._open):
+        Increment version.
+
+2019-04-15  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: drag/drop over the sidebar should load an imported file in Canvas/Audit tab
         https://bugs.webkit.org/show_bug.cgi?id=196873
         <rdar://problem/49858190>
index cee44bb..3f4e944 100644 (file)
@@ -67,7 +67,7 @@ WI.ObjectStore = class ObjectStore
 
         WI.ObjectStore._databaseCallbacks = [callback];
 
-        const version = 2; // Increment this for every edit to `WI.objectStores`.
+        const version = 3; // Increment this for every edit to `WI.objectStores`.
 
         let databaseRequest = window.indexedDB.open(WI.ObjectStore._databaseName, version);
         databaseRequest.addEventListener("upgradeneeded", (event) => {
@@ -242,4 +242,7 @@ WI.ObjectStore.toJSONSymbol = Symbol("ObjectStore-toJSON");
 WI.objectStores = {
     audits: new WI.ObjectStore("audit-manager-tests", {keyPath: "__id", autoIncrement: true}),
     breakpoints: new WI.ObjectStore("debugger-breakpoints", {keyPath: "__id"}),
+    domBreakpoints: new WI.ObjectStore("dom-debugger-dom-breakpoints", {keyPath: "__id"}),
+    eventBreakpoints: new WI.ObjectStore("dom-debugger-event-breakpoints", {keyPath: "__id"}),
+    urlBreakpoints: new WI.ObjectStore("dom-debugger-url-breakpoints", {keyPath: "__id"}),
 };
index c5e0548..12fbeb9 100644 (file)
@@ -29,14 +29,11 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
     {
         super();
 
-        this._domBreakpointsSetting = new WI.Setting("dom-breakpoints", []);
         this._domBreakpointURLMap = new Multimap;
         this._domBreakpointFrameIdentifierMap = new Map;
 
-        this._eventBreakpointSetting = new WI.Setting("event-breakpoints", []);
         this._eventBreakpoints = [];
 
-        this._urlBreakpointsSetting = new WI.Setting("url-breakpoints", WI.Setting.migrateValue("xhr-breakpoints") || []);
         this._urlBreakpoints = [];
         this._allRequestsBreakpointEnabledSetting = new WI.Setting("break-on-all-requests", false);
 
@@ -56,19 +53,41 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
         WI.Frame.addEventListener(WI.Frame.Event.ChildFrameWasRemoved, this._childFrameWasRemoved, this);
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
 
-        if (this.supported) {
-            this._restoringBreakpoints = true;
+        let loadBreakpoints = async (constructor, objectStore, oldSettings, callback) => {
+            for (let key of oldSettings) {
+                let existingSerializedBreakpoints = WI.Setting.migrateValue(key);
+                if (existingSerializedBreakpoints) {
+                    for (let existingSerializedBreakpoint of existingSerializedBreakpoints)
+                        await objectStore.putObject(constructor.deserialize(existingSerializedBreakpoint));
+                }
+            }
 
-            for (let serializedInfo of this._domBreakpointsSetting.value)
-                this.addDOMBreakpoint(WI.DOMBreakpoint.deserialize(serializedInfo));
+            let serializedBreakpoints = await objectStore.getAll();
 
-            for (let serializedInfo of this._eventBreakpointSetting.value)
-                this.addEventBreakpoint(WI.EventBreakpoint.deserialize(serializedInfo));
+            this._restoringBreakpoints = true;
+            for (let serializedBreakpoint of serializedBreakpoints) {
+                let breakpoint = constructor.deserialize(serializedBreakpoint);
 
-            for (let serializedInfo of this._urlBreakpointsSetting.value)
-                this.addURLBreakpoint(WI.URLBreakpoint.deserialize(serializedInfo));
+                const key = null;
+                objectStore.associateObject(breakpoint, key, serializedBreakpoint);
 
+                callback(breakpoint);
+            }
             this._restoringBreakpoints = false;
+        };
+
+        if (this.supported) {
+            loadBreakpoints(WI.DOMBreakpoint, WI.objectStores.domBreakpoints, ["dom-breakpoints"], (breakpoint) => {
+                this.addDOMBreakpoint(breakpoint);
+            });
+
+            loadBreakpoints(WI.EventBreakpoint, WI.objectStores.eventBreakpoints, ["event-breakpoints"], (breakpoint) => {
+                this.addEventBreakpoint(breakpoint);
+            });
+
+            loadBreakpoints(WI.URLBreakpoint, WI.objectStores.urlBreakpoints, ["xhr-breakpoints", "url-breakpoints"], (breakpoint) => {
+                this.addURLBreakpoint(breakpoint);
+            });
         }
     }
 
@@ -180,7 +199,8 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
 
         this.dispatchEventToListeners(WI.DOMDebuggerManager.Event.DOMBreakpointAdded, {breakpoint});
 
-        this._saveDOMBreakpoints();
+        if (!this._restoringBreakpoints)
+            WI.objectStores.domBreakpoints.putObject(breakpoint);
     }
 
     removeDOMBreakpoint(breakpoint)
@@ -214,17 +234,13 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
 
         breakpoint.domNodeIdentifier = null;
 
-        this._saveDOMBreakpoints();
+        if (!this._restoringBreakpoints)
+            WI.objectStores.domBreakpoints.deleteObject(breakpoint);
     }
 
     removeDOMBreakpointsForNode(node)
     {
-        this._restoringBreakpoints = true;
-
         this.domBreakpointsForNode(node).forEach(this.removeDOMBreakpoint, this);
-
-        this._restoringBreakpoints = false;
-        this._saveDOMBreakpoints();
     }
 
     eventBreakpointForTypeAndEventName(type, eventName)
@@ -257,7 +273,8 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
             }
         }
 
-        this._saveEventBreakpoints();
+        if (!this._restoringBreakpoints)
+            WI.objectStores.eventBreakpoints.putObject(breakpoint);
     }
 
     removeEventBreakpoint(breakpoint)
@@ -277,7 +294,9 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
 
         this._eventBreakpoints.remove(breakpoint);
 
-        this._saveEventBreakpoints();
+        if (!this._restoringBreakpoints)
+            WI.objectStores.eventBreakpoints.deleteObject(breakpoint);
+
         this.dispatchEventToListeners(WI.DOMDebuggerManager.Event.EventBreakpointRemoved, {breakpoint});
 
         if (breakpoint.disabled)
@@ -331,7 +350,8 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
             }
         }
 
-        this._saveURLBreakpoints();
+        if (!this._restoringBreakpoints)
+            WI.objectStores.urlBreakpoints.putObject(breakpoint);
     }
 
     removeURLBreakpoint(breakpoint)
@@ -351,7 +371,9 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
 
         this._urlBreakpoints.remove(breakpoint, true);
 
-        this._saveURLBreakpoints();
+        if (!this._restoringBreakpoints)
+            WI.objectStores.urlBreakpoints.deleteObject(breakpoint);
+
         this.dispatchEventToListeners(WI.DOMDebuggerManager.Event.URLBreakpointRemoved, {breakpoint});
 
         if (breakpoint.disabled)
@@ -517,30 +539,6 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
         }
     }
 
-    _saveDOMBreakpoints()
-    {
-        if (this._restoringBreakpoints)
-            return;
-
-        this._domBreakpointsSetting.value = Array.from(this._domBreakpointURLMap.values()).map((breakpoint) => breakpoint.serializableInfo);
-    }
-
-    _saveEventBreakpoints()
-    {
-        if (this._restoringBreakpoints)
-            return;
-
-        this._eventBreakpointSetting.value = this._eventBreakpoints.map((breakpoint) => breakpoint.serializableInfo);
-    }
-
-    _saveURLBreakpoints()
-    {
-        if (this._restoringBreakpoints)
-            return;
-
-        this._urlBreakpointsSetting.value = this._urlBreakpoints.map((breakpoint) => breakpoint.serializableInfo);
-    }
-
     _handleDOMBreakpointDisabledStateChanged(event)
     {
         let breakpoint = event.target;
@@ -548,7 +546,8 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
         if (target && target.DOMDebuggerAgent)
             this._updateDOMBreakpoint(breakpoint, target);
 
-        this._saveDOMBreakpoints();
+        if (!this._restoringBreakpoints)
+            WI.objectStores.domBreakpoints.putObject(breakpoint);
     }
 
     _handleEventBreakpointDisabledStateChanged(event)
@@ -563,7 +562,9 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
             if (target.DOMDebuggerAgent)
                 this._updateEventBreakpoint(breakpoint, target);
         }
-        this._saveEventBreakpoints();
+
+        if (!this._restoringBreakpoints)
+            WI.objectStores.eventBreakpoints.putObject(breakpoint);
     }
 
     _handleURLBreakpointDisabledStateChanged(event)
@@ -577,7 +578,9 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
             if (target.DOMDebuggerAgent)
                 this._updateURLBreakpoint(breakpoint, target);
         }
-        this._saveURLBreakpoints();
+
+        if (!this._restoringBreakpoints)
+            WI.objectStores.urlBreakpoints.putObject(breakpoint);
     }
 
     _childFrameWasRemoved(event)
index de24192..799459b 100644 (file)
@@ -96,27 +96,28 @@ WI.DOMBreakpoint = class DOMBreakpoint extends WI.Object
         this.dispatchEventToListeners(WI.DOMBreakpoint.Event.DOMNodeChanged, data);
     }
 
-    get serializableInfo()
+    saveIdentityToCookie(cookie)
     {
-        let info = {url: this._url, path: this._path, type: this._type};
-        if (this._disabled)
-            info.disabled = true;
-
-        return info;
+        cookie["dom-breakpoint-url"] = this._url;
+        cookie["dom-breakpoint-path"] = this._path;
+        cookie["dom-breakpoint-type"] = this._type;
     }
 
-    saveIdentityToCookie(cookie)
+    toJSON(key)
     {
-        cookie[WI.DOMBreakpoint.DocumentURLCookieKey] = this.url;
-        cookie[WI.DOMBreakpoint.NodePathCookieKey] = this.path;
-        cookie[WI.DOMBreakpoint.TypeCookieKey] = this.type;
+        let json = {
+            url: this._url,
+            path: this._path,
+            type: this._type,
+        };
+        if (this._disabled)
+            json.disabled = true;
+        if (key === WI.ObjectStore.toJSONSymbol)
+            json[WI.objectStores.domBreakpoints.keyPath] = this._url + ":" + this._path + ":" + this._type;
+        return json;
     }
 };
 
-WI.DOMBreakpoint.DocumentURLCookieKey = "dom-breakpoint-document-url";
-WI.DOMBreakpoint.NodePathCookieKey = "dom-breakpoint-node-path";
-WI.DOMBreakpoint.TypeCookieKey = "dom-breakpoint-type";
-
 WI.DOMBreakpoint.Type = {
     SubtreeModified: "subtree-modified",
     AttributeModified: "attribute-modified",
index 08bb915..3090de9 100644 (file)
@@ -68,22 +68,23 @@ WI.EventBreakpoint = class EventBreakpoint extends WI.Object
         this.dispatchEventToListeners(WI.EventBreakpoint.Event.DisabledStateChanged);
     }
 
-    get serializableInfo()
+    saveIdentityToCookie(cookie)
     {
-        let info = {
+        cookie["event-breakpoint-type"] = this._type;
+        cookie["event-breakpoint-event-name"] = this._eventName;
+    }
+
+    toJSON(key)
+    {
+        let json = {
             type: this._type,
             eventName: this._eventName,
         };
         if (this._disabled)
-            info.disabled = true;
-
-        return info;
-    }
-
-    saveIdentityToCookie(cookie)
-    {
-        cookie[WI.EventBreakpoint.TypeCookieKey] = this._type;
-        cookie[WI.EventBreakpoint.EventNameCookieKey] = this._eventName;
+            json.disabled = true;
+        if (key === WI.ObjectStore.toJSONSymbol)
+            json[WI.objectStores.eventBreakpoints.keyPath] = this._type + ":" + this._eventName;
+        return json;
     }
 };
 
@@ -93,9 +94,6 @@ WI.EventBreakpoint.Type = {
     Timer: "timer",
 };
 
-WI.EventBreakpoint.TypeCookieKey = "event-breakpoint-type";
-WI.EventBreakpoint.EventNameCookieKey = "event-breakpoint-event-name";
-
 WI.EventBreakpoint.Event = {
     DisabledStateChanged: "event-breakpoint-disabled-state-changed",
 };
index e5e0be6..47eef64 100644 (file)
@@ -66,18 +66,23 @@ WI.URLBreakpoint = class URLBreakpoint extends WI.Object
         this.dispatchEventToListeners(WI.URLBreakpoint.Event.DisabledStateChanged);
     }
 
-    get serializableInfo()
+    saveIdentityToCookie(cookie)
     {
-        let info = {type: this._type, url: this._url};
-        if (this._disabled)
-            info.disabled = true;
-
-        return info;
+        cookie["url-breakpoint-type"] = this._type;
+        cookie["url-breakpoint-url"] = this._url;
     }
 
-    saveIdentityToCookie(cookie)
+    toJSON(key)
     {
-        cookie["url-breakpoint-url"] = this._url;
+        let json = {
+            type: this._type,
+            url: this._url,
+        };
+        if (this._disabled)
+            json.disabled = true;
+        if (key === WI.ObjectStore.toJSONSymbol)
+            json[WI.objectStores.urlBreakpoints.keyPath] = this._type + ":" + this._url;
+        return json;
     }
 };