| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.SDKObject} | 33 * @extends {WebInspector.SDKObject} |
| 34 * @param {!WebInspector.Target} target | 34 * @param {!WebInspector.Target} target |
| 35 */ | 35 */ |
| 36 WebInspector.ServiceWorkerManager = function(target) | 36 WebInspector.ServiceWorkerManager = function(target) |
| 37 { | 37 { |
| 38 WebInspector.SDKObject.call(this, target); | 38 WebInspector.SDKObject.call(this, target); |
| 39 target.registerServiceWorkerDispatcher(new WebInspector.ServiceWorkerDispatc
her(this)); | 39 target.registerServiceWorkerDispatcher(new WebInspector.ServiceWorkerDispatc
her(this)); |
| 40 this._lastAnonymousTargetId = 0; | 40 this._lastAnonymousTargetId = 0; |
| 41 this._agent = target.serviceWorkerAgent(); |
| 41 /** @type {!Map.<string, !WebInspector.ServiceWorker>} */ | 42 /** @type {!Map.<string, !WebInspector.ServiceWorker>} */ |
| 42 this._workers = new Map(); | 43 this._workers = new Map(); |
| 43 /** @type {!Map.<string, !ServiceWorkerAgent.ServiceWorkerRegistration>} */ | 44 /** @type {!Map.<string, !ServiceWorkerAgent.ServiceWorkerRegistration>} */ |
| 44 this._registrations = new Map(); | 45 this._registrations = new Map(); |
| 45 /** @type {!Map.<string, !Map.<string, !ServiceWorkerAgent.ServiceWorkerVers
ion>>} */ | 46 /** @type {!Map.<string, !Map.<string, !ServiceWorkerAgent.ServiceWorkerVers
ion>>} */ |
| 46 this._versions = new Map(); | 47 this._versions = new Map(); |
| 47 this.enable(); | 48 this.enable(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 WebInspector.ServiceWorkerManager.Events = { | 51 WebInspector.ServiceWorkerManager.Events = { |
| 51 WorkersUpdated: "WorkersUpdated", | 52 WorkersUpdated: "WorkersUpdated", |
| 52 RegistrationUpdated: "RegistrationUpdated", | 53 RegistrationUpdated: "RegistrationUpdated", |
| 53 RegistrationDeleted: "RegistrationDeleted", | 54 RegistrationDeleted: "RegistrationDeleted", |
| 54 VersionUpdated: "VersionUpdated", | 55 VersionUpdated: "VersionUpdated", |
| 55 VersionDeleted: "VersionDeleted" | 56 VersionDeleted: "VersionDeleted" |
| 56 } | 57 } |
| 57 | 58 |
| 58 WebInspector.ServiceWorkerManager.prototype = { | 59 WebInspector.ServiceWorkerManager.prototype = { |
| 59 enable: function() | 60 enable: function() |
| 60 { | 61 { |
| 61 if (this._enabled) | 62 if (this._enabled) |
| 62 return; | 63 return; |
| 63 this._enabled = true; | 64 this._enabled = true; |
| 64 | 65 |
| 65 this.target().serviceWorkerAgent().enable(); | 66 this._agent.enable(); |
| 66 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E
vents.MainFrameNavigated, this._mainFrameNavigated, this); | 67 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E
vents.MainFrameNavigated, this._mainFrameNavigated, this); |
| 67 }, | 68 }, |
| 68 | 69 |
| 69 disable: function() | 70 disable: function() |
| 70 { | 71 { |
| 71 if (!this._enabled) | 72 if (!this._enabled) |
| 72 return; | 73 return; |
| 73 this._enabled = false; | 74 this._enabled = false; |
| 74 | 75 |
| 75 for (var worker of this._workers.values()) | 76 for (var worker of this._workers.values()) |
| 76 worker._connection.close(); | 77 worker._connection.close(); |
| 77 this._workers.clear(); | 78 this._workers.clear(); |
| 78 this._registrations.clear(); | 79 this._registrations.clear(); |
| 79 this._versions.clear(); | 80 this._versions.clear(); |
| 80 this.target().serviceWorkerAgent().disable(); | 81 this._agent.disable(); |
| 81 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage
r.Events.MainFrameNavigated, this._mainFrameNavigated, this); | 82 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage
r.Events.MainFrameNavigated, this._mainFrameNavigated, this); |
| 82 }, | 83 }, |
| 83 | 84 |
| 84 /** | 85 /** |
| 85 * @return {!Iterable.<!WebInspector.ServiceWorker>} | 86 * @return {!Iterable.<!WebInspector.ServiceWorker>} |
| 86 */ | 87 */ |
| 87 workers: function() | 88 workers: function() |
| 88 { | 89 { |
| 89 return this._workers.values(); | 90 return this._workers.values(); |
| 90 }, | 91 }, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 107 | 108 |
| 108 /** | 109 /** |
| 109 * @return {!Map.<string, !Map.<string, !ServiceWorkerAgent.ServiceWorkerVer
sion>>} | 110 * @return {!Map.<string, !Map.<string, !ServiceWorkerAgent.ServiceWorkerVer
sion>>} |
| 110 */ | 111 */ |
| 111 versions: function() | 112 versions: function() |
| 112 { | 113 { |
| 113 return this._versions; | 114 return this._versions; |
| 114 }, | 115 }, |
| 115 | 116 |
| 116 /** | 117 /** |
| 118 * @param {string} scope |
| 119 */ |
| 120 unregister: function(scope) |
| 121 { |
| 122 this._agent.unregister(scope); |
| 123 }, |
| 124 |
| 125 /** |
| 126 * @param {string} scope |
| 127 */ |
| 128 startWorker: function(scope) |
| 129 { |
| 130 this._agent.startWorker(scope); |
| 131 }, |
| 132 |
| 133 /** |
| 134 * @param {string} versionId |
| 135 */ |
| 136 stopWorker: function(versionId) |
| 137 { |
| 138 this._agent.stopWorker(versionId); |
| 139 }, |
| 140 |
| 141 /** |
| 142 * @param {string} versionId |
| 143 */ |
| 144 inspectWorker: function(versionId) |
| 145 { |
| 146 this._agent.inspectWorker(versionId); |
| 147 }, |
| 148 |
| 149 /** |
| 117 * @param {string} workerId | 150 * @param {string} workerId |
| 118 * @param {string} url | 151 * @param {string} url |
| 119 */ | 152 */ |
| 120 _workerCreated: function(workerId, url) | 153 _workerCreated: function(workerId, url) |
| 121 { | 154 { |
| 122 new WebInspector.ServiceWorker(this, workerId, url); | 155 new WebInspector.ServiceWorker(this, workerId, url); |
| 123 }, | 156 }, |
| 124 | 157 |
| 125 /** | 158 /** |
| 126 * @param {string} workerId | 159 * @param {string} workerId |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 this._agent.sendMessage(this._workerId, JSON.stringify(messageObject)); | 397 this._agent.sendMessage(this._workerId, JSON.stringify(messageObject)); |
| 365 }, | 398 }, |
| 366 | 399 |
| 367 _close: function() | 400 _close: function() |
| 368 { | 401 { |
| 369 this.connectionClosed("worker_terminated"); | 402 this.connectionClosed("worker_terminated"); |
| 370 }, | 403 }, |
| 371 | 404 |
| 372 __proto__: InspectorBackendClass.Connection.prototype | 405 __proto__: InspectorBackendClass.Connection.prototype |
| 373 } | 406 } |
| OLD | NEW |