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

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

Issue 2450973002: [DevTools] Inherit WI.Target from Protocol.Target. (Closed)
Patch Set: Created 4 years, 2 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/InspectorBackend.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/InspectorBackend.js b/third_party/WebKit/Source/devtools/front_end/sdk/InspectorBackend.js
index 41558bc2530e393691b3b41ea3de7dbf899ba561..9009fd49b348b38b7d35a8f83414047be0e74ed3 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/InspectorBackend.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/InspectorBackend.js
@@ -36,7 +36,6 @@ function InspectorBackendClass()
this._agentPrototypes = {};
this._dispatcherPrototypes = {};
this._initialized = false;
- this._initProtocolAgentsConstructor();
}
InspectorBackendClass._DevToolsErrorCode = -32000;
@@ -60,23 +59,10 @@ InspectorBackendClass.prototype = {
return this._initialized;
},
- _initProtocolAgentsConstructor: function()
- {
- window.Protocol = {};
-
- /**
- * @constructor
- * @param {!Object.<string, !Object>} agentsMap
- */
- window.Protocol.Agents = function(agentsMap) {
- this._agentsMap = agentsMap;
- };
- },
-
/**
* @param {string} domain
*/
- _addAgentGetterMethodToProtocolAgentsPrototype: function(domain)
+ _addAgentGetterMethodToProtocolTargetPrototype: function(domain)
{
var upperCaseLength = 0;
while (upperCaseLength < domain.length && domain[upperCaseLength].toLowerCase() !== domain[upperCaseLength])
@@ -85,35 +71,35 @@ InspectorBackendClass.prototype = {
var methodName = domain.substr(0, upperCaseLength).toLowerCase() + domain.slice(upperCaseLength) + "Agent";
/**
- * @this {Protocol.Agents}
+ * @this {Protocol.Target}
*/
function agentGetter()
{
- return this._agentsMap[domain];
+ return this._agents[domain];
}
- window.Protocol.Agents.prototype[methodName] = agentGetter;
+ Protocol.Target.prototype[methodName] = agentGetter;
/**
- * @this {Protocol.Agents}
+ * @this {Protocol.Target}
*/
function registerDispatcher(dispatcher)
{
this.registerDispatcher(domain, dispatcher);
}
- window.Protocol.Agents.prototype["register" + domain + "Dispatcher"] = registerDispatcher;
+ Protocol.Target.prototype["register" + domain + "Dispatcher"] = registerDispatcher;
},
/**
* @param {string} domain
- * @return {!InspectorBackendClass.AgentPrototype}
+ * @return {!InspectorBackendClass._AgentPrototype}
*/
_agentPrototype: function(domain)
{
if (!this._agentPrototypes[domain]) {
- this._agentPrototypes[domain] = new InspectorBackendClass.AgentPrototype(domain);
- this._addAgentGetterMethodToProtocolAgentsPrototype(domain);
+ this._agentPrototypes[domain] = new InspectorBackendClass._AgentPrototype(domain);
+ this._addAgentGetterMethodToProtocolTargetPrototype(domain);
}
return this._agentPrototypes[domain];
@@ -121,12 +107,12 @@ InspectorBackendClass.prototype = {
/**
* @param {string} domain
- * @return {!InspectorBackendClass.DispatcherPrototype}
+ * @return {!InspectorBackendClass._DispatcherPrototype}
*/
_dispatcherPrototype: function(domain)
{
if (!this._dispatcherPrototypes[domain])
- this._dispatcherPrototypes[domain] = new InspectorBackendClass.DispatcherPrototype();
+ this._dispatcherPrototypes[domain] = new InspectorBackendClass._DispatcherPrototype();
return this._dispatcherPrototypes[domain];
},
@@ -200,6 +186,8 @@ InspectorBackendClass.prototype = {
}
};
+var InspectorBackend = new InspectorBackendClass();
+
/**
* @interface
*/
@@ -232,15 +220,18 @@ InspectorBackendClass.Connection.Params;
*/
InspectorBackendClass.Connection.Factory;
+var Protocol = {};
+
+/** @typedef {string} */
+Protocol.Error;
+
/**
* @constructor
* @param {!InspectorBackendClass.Connection.Factory} connectionFactory
- * @param {function(string)} disconnectedCallback
*/
-InspectorBackendClass.TargetPrototype = function(connectionFactory, disconnectedCallback)
+Protocol.Target = function(connectionFactory)
{
- this._connection = connectionFactory({onMessage: this.dispatch.bind(this), onDisconnect: this._disconnected.bind(this)});
- this._disconnectedCallback = disconnectedCallback;
+ this._connection = connectionFactory({onMessage: this._onMessage.bind(this), onDisconnect: this._onDisconnect.bind(this)});
this._lastMessageId = 1;
this._pendingResponsesCount = 0;
this._agents = {};
@@ -253,16 +244,16 @@ InspectorBackendClass.TargetPrototype = function(connectionFactory, disconnected
InspectorBackendClass.sendRawMessageForTesting = this._sendRawMessageForTesting.bind(this);
};
-InspectorBackendClass.TargetPrototype.prototype = {
+Protocol.Target.prototype = {
/**
- * @param {!Object.<string, !InspectorBackendClass.AgentPrototype>} agentPrototypes
- * @param {!Object.<string, !InspectorBackendClass.DispatcherPrototype>} dispatcherPrototypes
+ * @param {!Object.<string, !InspectorBackendClass._AgentPrototype>} agentPrototypes
+ * @param {!Object.<string, !InspectorBackendClass._DispatcherPrototype>} dispatcherPrototypes
*/
_initialize: function(agentPrototypes, dispatcherPrototypes)
{
for (var domain in agentPrototypes) {
this._agents[domain] = Object.create(agentPrototypes[domain]);
- this._agents[domain].setConnection(this);
+ this._agents[domain].setTarget(this);
}
for (var domain in dispatcherPrototypes)
@@ -272,29 +263,21 @@ InspectorBackendClass.TargetPrototype.prototype = {
/**
* @return {number}
*/
- nextMessageId: function()
+ _nextMessageId: function()
{
return this._lastMessageId++;
},
/**
* @param {string} domain
- * @return {!InspectorBackendClass.AgentPrototype}
+ * @return {!InspectorBackendClass._AgentPrototype}
*/
- agent: function(domain)
+ _agent: function(domain)
{
return this._agents[domain];
},
/**
- * @return {!Object.<string, !Object>}
- */
- agentsMap: function()
- {
- return this._agents;
- },
-
- /**
* @param {string} domain
* @param {string} method
* @param {?Object} params
@@ -309,7 +292,7 @@ InspectorBackendClass.TargetPrototype.prototype = {
}
var messageObject = {};
- var messageId = this.nextMessageId();
+ var messageId = this._nextMessageId();
messageObject.id = messageId;
messageObject.method = method;
if (params)
@@ -359,7 +342,7 @@ InspectorBackendClass.TargetPrototype.prototype = {
/**
* @param {!Object|string} message
*/
- dispatch: function(message)
+ _onMessage: function(message)
{
if (InspectorBackendClass.Options.dumpInspectorProtocolMessages)
this._dumpProtocolMessage("backend: " + ((typeof message === "string") ? message : JSON.stringify(message)));
@@ -377,7 +360,7 @@ InspectorBackendClass.TargetPrototype.prototype = {
if (InspectorBackendClass.Options.dumpInspectorTimeStats)
processingStartTime = Date.now();
- this.agent(callback.domain).dispatchResponse(messageObject, callback.methodName, callback);
+ this._agent(callback.domain).dispatchResponse(messageObject, callback.methodName, callback);
--this._pendingResponsesCount;
delete this._callbacks[messageObject.id];
@@ -456,12 +439,26 @@ InspectorBackendClass.TargetPrototype.prototype = {
/**
* @param {string} reason
*/
- _disconnected: function(reason)
+ _onDisconnect: function(reason)
{
this._connection = null;
this._runPendingCallbacks();
- this._disconnectedCallback(reason);
- this._disconnectedCallback = null;
+ this.dispose();
+ },
+
+ /**
+ * @protected
+ */
+ dispose: function()
+ {
+ },
+
+ /**
+ * @return {boolean}
+ */
+ isDisposed: function()
+ {
+ return !this._connection;
},
_runPendingCallbacks: function()
@@ -483,7 +480,7 @@ InspectorBackendClass.TargetPrototype.prototype = {
{
var error = { message: "Connection is closed, can't dispatch pending " + methodName, code: InspectorBackendClass._DevToolsErrorCode, data: null};
var messageObject = {error: error};
- setTimeout(InspectorBackendClass.AgentPrototype.prototype.dispatchResponse.bind(this.agent(domain), messageObject, methodName, callback), 0);
+ setTimeout(InspectorBackendClass._AgentPrototype.prototype.dispatchResponse.bind(this._agent(domain), messageObject, methodName, callback), 0);
},
};
@@ -491,21 +488,20 @@ InspectorBackendClass.TargetPrototype.prototype = {
* @constructor
* @param {string} domain
*/
-InspectorBackendClass.AgentPrototype = function(domain)
+InspectorBackendClass._AgentPrototype = function(domain)
{
this._replyArgs = {};
this._hasErrorData = {};
this._domain = domain;
- this._suppressErrorLogging = false;
};
-InspectorBackendClass.AgentPrototype.prototype = {
+InspectorBackendClass._AgentPrototype.prototype = {
/**
- * @param {!InspectorBackendClass.Connection} connection
+ * @param {!Protocol.Target} target
*/
- setConnection: function(connection)
+ setTarget: function(target)
{
- this._connection = connection;
+ this._target = target;
},
/**
@@ -520,25 +516,25 @@ InspectorBackendClass.AgentPrototype.prototype = {
/**
* @param {...*} vararg
- * @this {InspectorBackendClass.AgentPrototype}
+ * @this {InspectorBackendClass._AgentPrototype}
* @return {!Promise.<*>}
*/
function sendMessagePromise(vararg)
{
var params = Array.prototype.slice.call(arguments);
- return InspectorBackendClass.AgentPrototype.prototype._sendMessageToBackendPromise.call(this, domainAndMethod, signature, params);
+ return InspectorBackendClass._AgentPrototype.prototype._sendMessageToBackendPromise.call(this, domainAndMethod, signature, params);
}
this[methodName] = sendMessagePromise;
/**
* @param {...*} vararg
- * @this {InspectorBackendClass.AgentPrototype}
+ * @this {InspectorBackendClass._AgentPrototype}
*/
function invoke(vararg)
{
var params = [domainAndMethod].concat(Array.prototype.slice.call(arguments));
- InspectorBackendClass.AgentPrototype.prototype._invoke.apply(this, params);
+ InspectorBackendClass._AgentPrototype.prototype._invoke.apply(this, params);
}
this["invoke_" + methodName] = invoke;
@@ -624,7 +620,7 @@ InspectorBackendClass.AgentPrototype.prototype = {
/**
* @param {function(?)} resolve
* @param {function(!Error)} reject
- * @this {InspectorBackendClass.AgentPrototype}
+ * @this {InspectorBackendClass._AgentPrototype}
*/
function promiseAction(resolve, reject)
{
@@ -636,7 +632,7 @@ InspectorBackendClass.AgentPrototype.prototype = {
var result = userCallback ? userCallback.apply(null, arguments) : undefined;
resolve(result);
}
- this._connection._wrapCallbackAndSendMessageObject(this._domain, method, params, callback);
+ this._target._wrapCallbackAndSendMessageObject(this._domain, method, params, callback);
}
},
@@ -647,7 +643,7 @@ InspectorBackendClass.AgentPrototype.prototype = {
*/
_invoke: function(method, args, callback)
{
- this._connection._wrapCallbackAndSendMessageObject(this._domain, method, args, callback);
+ this._target._wrapCallbackAndSendMessageObject(this._domain, method, args, callback);
},
/**
@@ -657,7 +653,7 @@ InspectorBackendClass.AgentPrototype.prototype = {
*/
dispatchResponse: function(messageObject, methodName, callback)
{
- if (messageObject.error && messageObject.error.code !== InspectorBackendClass._DevToolsErrorCode && messageObject.error.code !== InspectorBackendClass.DevToolsStubErrorCode && !InspectorBackendClass.Options.suppressRequestErrors && !this._suppressErrorLogging) {
+ if (messageObject.error && messageObject.error.code !== InspectorBackendClass._DevToolsErrorCode && messageObject.error.code !== InspectorBackendClass.DevToolsStubErrorCode && !InspectorBackendClass.Options.suppressRequestErrors) {
var id = InspectorBackendClass.Options.dumpInspectorProtocolMessages ? " with id = " + messageObject.id : "";
console.error("Request " + methodName + id + " failed. " + JSON.stringify(messageObject.error));
}
@@ -676,23 +672,18 @@ InspectorBackendClass.AgentPrototype.prototype = {
callback.apply(null, argumentsArray);
},
-
- suppressErrorLogging: function()
- {
- this._suppressErrorLogging = true;
- }
};
/**
* @constructor
*/
-InspectorBackendClass.DispatcherPrototype = function()
+InspectorBackendClass._DispatcherPrototype = function()
{
this._eventArgs = {};
this._dispatcher = null;
};
-InspectorBackendClass.DispatcherPrototype.prototype = {
+InspectorBackendClass._DispatcherPrototype.prototype = {
/**
* @param {string} eventName
@@ -753,5 +744,3 @@ InspectorBackendClass.Options = {
dumpInspectorProtocolMessages: false,
suppressRequestErrors: false
};
-
-InspectorBackend = new InspectorBackendClass();

Powered by Google App Engine
This is Rietveld 408576698