Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js

Issue 2354973003: [DevTools] Move subtargets functionality from ServiceWorker to Target domain. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js b/third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js
index 23c70c3813809b7afa6be65b27771bc45780de63..5e3c5ca7abd234ab90642a26b9ced4f3a1517ca9 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerManager.js
@@ -32,15 +32,16 @@
* @constructor
* @extends {WebInspector.SDKObject}
* @param {!WebInspector.Target} target
+ * @param {!WebInspector.SubTargetsManager} subTargetsManager
*/
-WebInspector.ServiceWorkerManager = function(target)
+WebInspector.ServiceWorkerManager = function(target, subTargetsManager)
{
WebInspector.SDKObject.call(this, target);
target.registerServiceWorkerDispatcher(new WebInspector.ServiceWorkerDispatcher(this));
this._lastAnonymousTargetId = 0;
+ this._subTargetsManager = subTargetsManager;
+ this._subTargetsManager.addEventListener(WebInspector.SubTargetsManager.Events.SubTargetsUpdated, this._updateAllContextLabels, this);
this._agent = target.serviceWorkerAgent();
- /** @type {!Map.<string, !WebInspector.ServiceWorker>} */
- this._workers = new Map();
/** @type {!Map.<string, !WebInspector.ServiceWorkerRegistration>} */
this._registrations = new Map();
this.enable();
@@ -53,21 +54,20 @@ WebInspector.ServiceWorkerManager = function(target)
/** @enum {symbol} */
WebInspector.ServiceWorkerManager.Events = {
- WorkersUpdated: Symbol("WorkersUpdated"),
RegistrationUpdated: Symbol("RegistrationUpdated"),
RegistrationErrorAdded: Symbol("RegistrationErrorAdded"),
RegistrationDeleted: Symbol("RegistrationDeleted")
}
+WebInspector.ServiceWorkerManager._VersionIdSymbol = Symbol("VersionId");
+
WebInspector.ServiceWorkerManager.prototype = {
enable: function()
{
if (this._enabled)
return;
this._enabled = true;
-
this._agent.enable();
- WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Events.MainFrameNavigated, this._mainFrameNavigated, this);
},
disable: function()
@@ -75,21 +75,8 @@ WebInspector.ServiceWorkerManager.prototype = {
if (!this._enabled)
return;
this._enabled = false;
-
- for (var worker of this._workers.values())
- worker._connection.close();
- this._workers.clear();
this._registrations.clear();
this._agent.disable();
- WebInspector.targetManager.removeEventListener(WebInspector.TargetManager.Events.MainFrameNavigated, this._mainFrameNavigated, this);
- },
-
- /**
- * @return {!Iterable.<!WebInspector.ServiceWorker>}
- */
- workers: function()
- {
- return this._workers.values();
},
/**
@@ -98,19 +85,19 @@ WebInspector.ServiceWorkerManager.prototype = {
*/
targetForVersionId: function(versionId)
{
- for (var pair of this._workers) {
- if (pair[1]._versionId === versionId)
- return pair[1]._target;
- }
- return null;
+ var version = this.findVersion(versionId);
+ if (!version || !version.targetId)
+ return null;
+ return this._subTargetsManager.targetForId(version.targetId);
},
/**
- * @return {boolean}
+ * @param {!WebInspector.Target} target
+ * @return {?string}
*/
- hasWorkers: function()
+ _versionIdForTarget: function(target)
{
- return !!this._workers.size;
+ return target[WebInspector.ServiceWorkerManager._VersionIdSymbol] || null;
},
/**
@@ -193,14 +180,6 @@ WebInspector.ServiceWorkerManager.prototype = {
},
/**
- * @param {!ServiceWorkerAgent.TargetID} targetId
- */
- activateTarget: function(targetId)
- {
- this._agent.activateTarget(targetId);
- },
-
- /**
* @param {string} scope
*/
_unregister: function(scope)
@@ -241,68 +220,6 @@ WebInspector.ServiceWorkerManager.prototype = {
},
/**
- * @param {!ServiceWorkerAgent.TargetID} targetId
- * @param {function(?WebInspector.TargetInfo)=} callback
- */
- getTargetInfo: function(targetId, callback)
- {
- /**
- * @param {?Protocol.Error} error
- * @param {?ServiceWorkerAgent.TargetInfo} targetInfo
- */
- function innerCallback(error, targetInfo)
- {
- if (error) {
- console.error(error);
- callback(null);
- return;
- }
- if (targetInfo)
- callback(new WebInspector.TargetInfo(targetInfo));
- else
- callback(null)
- }
- this._agent.getTargetInfo(targetId, innerCallback);
- },
-
- /**
- * @param {string} workerId
- * @param {string} url
- * @param {string} versionId
- */
- _workerCreated: function(workerId, url, versionId)
- {
- new WebInspector.ServiceWorker(this, workerId, url, versionId);
- this._updateWorkerStatuses();
- },
-
- /**
- * @param {string} workerId
- */
- _workerTerminated: function(workerId)
- {
- var worker = this._workers.get(workerId);
- if (!worker)
- return;
-
- worker._closeConnection();
- this._workers.delete(workerId);
-
- this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.WorkersUpdated);
- },
-
- /**
- * @param {string} workerId
- * @param {string} message
- */
- _dispatchMessage: function(workerId, message)
- {
- var worker = this._workers.get(workerId);
- if (worker)
- worker._connection.dispatch(message);
- },
-
- /**
* @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrations
*/
_workerRegistrationUpdated: function(registrations)
@@ -337,7 +254,10 @@ WebInspector.ServiceWorkerManager.prototype = {
var registration = this._registrations.get(payload.registrationId);
if (!registration)
continue;
- registration._updateVersion(payload);
+ var version = registration._updateVersion(payload);
+ var target = version.targetId ? this._subTargetsManager.targetForId(version.targetId) : null;
+ if (target)
+ target[WebInspector.ServiceWorkerManager._VersionIdSymbol] = version.id;
registrations.add(registration);
}
for (var registration of registrations) {
@@ -348,22 +268,7 @@ WebInspector.ServiceWorkerManager.prototype = {
this.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.RegistrationUpdated, registration);
}
}
- this._updateWorkerStatuses();
- },
-
- _updateWorkerStatuses: function()
- {
- /** @type {!Map<string, string>} */
- var versionById = new Map();
- for (var registration of this._registrations.valuesArray()) {
- for (var version of registration.versions.valuesArray())
- versionById.set(version.id, version.status);
- }
- for (var worker of this._workers.valuesArray()) {
- var status = versionById.get(worker.versionId());
- if (status)
- worker.setStatus(status);
- }
+ this._updateAllContextLabels();
},
/**
@@ -379,14 +284,6 @@ WebInspector.ServiceWorkerManager.prototype = {
},
/**
- * @param {!WebInspector.Event} event
- */
- _mainFrameNavigated: function(event)
- {
- // Attach to the new worker set.
- },
-
- /**
* @return {!WebInspector.Setting}
*/
forceUpdateOnReloadSetting: function()
@@ -399,127 +296,71 @@ WebInspector.ServiceWorkerManager.prototype = {
this._agent.setForceUpdateOnPageLoad(this._forceUpdateSetting.get());
},
- /**
- * @param {!WebInspector.Event} event
- */
- _executionContextCreated: function(event)
- {
- var executionContext = /** @type {!WebInspector.ExecutionContext} */ (event.data);
- var target = executionContext.target();
- if (!target.parentTarget())
- return;
- var worker = target.parentTarget()[WebInspector.ServiceWorker.Symbol];
- if (worker)
- worker._setContextLabelFor(executionContext);
- },
-
- __proto__: WebInspector.SDKObject.prototype
-}
-
-/**
- * @constructor
- * @param {!WebInspector.ServiceWorkerManager} manager
- * @param {string} workerId
- * @param {string} url
- * @param {string} versionId
- */
-WebInspector.ServiceWorker = function(manager, workerId, url, versionId)
-{
- this._manager = manager;
- this._agent = manager.target().serviceWorkerAgent();
- this._workerId = workerId;
- this._connection = new WebInspector.ServiceWorkerConnection(this._agent, workerId);
- this._url = url;
- this._versionId = versionId;
- var parsedURL = url.asParsedURL();
- this._name = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++WebInspector.ServiceWorker._lastAnonymousTargetId);
- this._scope = parsedURL ? parsedURL.host + parsedURL.folderPathComponents : "";
-
- this._manager._workers.set(workerId, this);
- var capabilities =
- WebInspector.Target.Capability.Log | WebInspector.Target.Capability.Network |
- WebInspector.Target.Capability.Worker;
- this._target = WebInspector.targetManager.createTarget(this._name, capabilities, this._connection, manager.target());
- this._target[WebInspector.ServiceWorker.Symbol] = this;
- this._manager.dispatchEventToListeners(WebInspector.ServiceWorkerManager.Events.WorkersUpdated);
- this._target.runtimeAgent().runIfWaitingForDebugger();
-}
-
-WebInspector.ServiceWorker.Symbol = Symbol("serviceWorker");
-
-WebInspector.ServiceWorker._lastAnonymousTargetId = 0;
-
-WebInspector.ServiceWorker.prototype = {
- /**
- * @return {string}
- */
- name: function()
+ _updateAllContextLabels: function()
{
- return this._name;
- },
+ /** @type {!Map<string, string>} */
+ var statusByVersionId = new Map();
+ for (var registration of this._registrations.valuesArray()) {
+ for (var version of registration.versions.valuesArray()) {
+ var target = version.targetId ? this._subTargetsManager.targetForId(version.targetId) : null;
+ if (target)
+ target[WebInspector.ServiceWorkerManager._VersionIdSymbol] = version.id;
+ statusByVersionId.set(version.id, version.status);
+ }
+ }
- /**
- * @return {string}
- */
- url: function()
- {
- return this._url;
+ for (var target of WebInspector.targetManager.targets()) {
+ var versionId = this._versionForWorkerOfServiceWorkerTarget(target);
+ if (!versionId)
+ return;
+ var status = statusByVersionId.get(versionId) || "";
+ for (var context of target.runtimeModel.executionContexts())
+ this._updateContextLabel(context, versionId, status);
+ }
},
/**
- * @return {string}
+ * @param {!WebInspector.Target} target
+ * @return {?string}
*/
- versionId: function()
+ _versionForWorkerOfServiceWorkerTarget: function(target)
{
- return this._versionId;
+ var parent = target.parentTarget();
+ if (!parent || parent.parentTarget() !== this.target())
+ return null;
+ if (this._subTargetsManager.targetType(parent) !== TargetAgent.TargetType.Service_worker)
+ return null;
+ return this._versionIdForTarget(parent);
},
/**
- * @return {string}
+ * @param {!WebInspector.Event} event
*/
- scope: function()
- {
- return this._scope;
- },
-
- stop: function()
- {
- this._agent.stop(this._workerId);
- },
-
- /** @param {string} status */
- setStatus: function(status)
+ _executionContextCreated: function(event)
{
- if (this._status === status)
+ var executionContext = /** @type {!WebInspector.ExecutionContext} */ (event.data);
+ var versionId = this._versionForWorkerOfServiceWorkerTarget(executionContext.target());
+ if (!versionId)
return;
- this._status = status;
-
- for (var target of WebInspector.targetManager.targets()) {
- if (target.parentTarget() !== this._target)
- continue;
- for (var context of target.runtimeModel.executionContexts())
- this._setContextLabelFor(context);
- }
+ this._updateContextLabel(executionContext, versionId, this.findVersion(versionId).status);
},
/**
* @param {!WebInspector.ExecutionContext} context
+ * @param {string} versionId
+ * @param {string} status
*/
- _setContextLabelFor: function(context)
+ _updateContextLabel: function(context, versionId, status)
{
var parsedUrl = context.origin.asParsedURL();
var label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : context.name;
- if (this._status)
- context.setLabel(label + " #" + this._versionId + " (" + this._status + ")");
+ if (status)
+ context.setLabel(label + " #" + versionId + " (" + status + ")");
else
context.setLabel(label);
},
- _closeConnection: function()
- {
- this._connection._close();
- delete this._connection;
- }
+ __proto__: WebInspector.SDKObject.prototype
}
/**
@@ -535,36 +376,6 @@ WebInspector.ServiceWorkerDispatcher = function(manager)
WebInspector.ServiceWorkerDispatcher.prototype = {
/**
* @override
- * @param {string} workerId
- * @param {string} url
- * @param {string} versionId
- */
- workerCreated: function(workerId, url, versionId)
- {
- this._manager._workerCreated(workerId, url, versionId);
- },
-
- /**
- * @override
- * @param {string} workerId
- */
- workerTerminated: function(workerId)
- {
- this._manager._workerTerminated(workerId);
- },
-
- /**
- * @override
- * @param {string} workerId
- * @param {string} message
- */
- dispatchMessage: function(workerId, message)
- {
- this._manager._dispatchMessage(workerId, message);
- },
-
- /**
- * @override
* @param {!Array.<!ServiceWorkerAgent.ServiceWorkerRegistration>} registrations
*/
workerRegistrationUpdated: function(registrations)
@@ -593,68 +404,6 @@ WebInspector.ServiceWorkerDispatcher.prototype = {
/**
* @constructor
- * @extends {InspectorBackendClass.Connection}
- * @param {!Protocol.ServiceWorkerAgent} agent
- * @param {string} workerId
- */
-WebInspector.ServiceWorkerConnection = function(agent, workerId)
-{
- InspectorBackendClass.Connection.call(this);
- // FIXME: remove resourceTreeModel and others from worker targets
- this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage", "Database", "Network", "IndexedDB"]);
- this._agent = agent;
- this._workerId = workerId;
-}
-
-WebInspector.ServiceWorkerConnection.prototype = {
- /**
- * @override
- * @param {!Object} messageObject
- */
- sendMessage: function(messageObject)
- {
- this._agent.sendMessage(this._workerId, JSON.stringify(messageObject));
- },
-
- _close: function()
- {
- this.connectionClosed("worker_terminated");
- },
-
- __proto__: InspectorBackendClass.Connection.prototype
-}
-
-/**
- * @constructor
- * @param {!ServiceWorkerAgent.TargetInfo} payload
- */
-WebInspector.TargetInfo = function(payload)
-{
- this.id = payload.id;
- this.type = payload.type;
- this.title = payload.title;
- this.url = payload.url;
-}
-
-WebInspector.TargetInfo.prototype = {
- /**
- * @return {boolean}
- */
- isWebContents: function()
- {
- return this.type === "page";
- },
- /**
- * @return {boolean}
- */
- isFrame: function()
- {
- return this.type === "frame";
- },
-}
-
-/**
- * @constructor
* @param {!WebInspector.ServiceWorkerRegistration} registration
* @param {!ServiceWorkerAgent.ServiceWorkerVersion} payload
*/
@@ -691,6 +440,7 @@ WebInspector.ServiceWorkerVersion.prototype = {
this.controlledClients = [];
for (var i = 0; i < payload.controlledClients.length; ++i)
this.controlledClients.push(payload.controlledClients[i]);
+ this.targetId = payload.targetId || null;
},
/**

Powered by Google App Engine
This is Rietveld 408576698