1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * @implements {WebInspector.Linkifier.LinkHandler}
9 WebInspector
.FrontendWebSocketAPI = function()
11 InspectorFrontendHost
.events
.addEventListener(InspectorFrontendHostAPI
.Events
.DispatchFrontendAPIMessage
, this._onFrontendAPIMessage
, this);
12 InspectorFrontendHost
.events
.addEventListener(InspectorFrontendHostAPI
.Events
.FrontendAPIAttached
, this._onAttach
, this);
13 InspectorFrontendHost
.events
.addEventListener(InspectorFrontendHostAPI
.Events
.FrontendAPIDetached
, this._onDetach
, this);
16 WebInspector
.FrontendWebSocketAPI
.prototype = {
19 WebInspector
.workspace
.addEventListener(WebInspector
.Workspace
.Events
.UISourceCodeContentCommitted
, this._workingCopyCommitted
, this);
20 WebInspector
.workspace
.addEventListener(WebInspector
.Workspace
.Events
.UISourceCodeWorkingCopyChanged
, this._workingCopyChanged
, this);
21 WebInspector
.Linkifier
.setLinkHandler(this);
26 WebInspector
.workspace
.removeEventListener(WebInspector
.Workspace
.Events
.UISourceCodeContentCommitted
, this._workingCopyCommitted
, this);
27 WebInspector
.workspace
.removeEventListener(WebInspector
.Workspace
.Events
.UISourceCodeWorkingCopyChanged
, this._workingCopyChanged
, this);
28 WebInspector
.Linkifier
.setLinkHandler(null);
34 * @param {number=} lineNumber
37 handleLink: function(url
, lineNumber
)
39 var uiSourceCode
= WebInspector
.networkMapping
.uiSourceCodeForURLForAnyTarget(url
);
41 url
= uiSourceCode
.originURL();
42 if (url
.startsWith("file://")) {
43 var file
= url
.substring(7);
44 this._issueFrontendAPINotification("Frontend.revealLocation", { file
: file
, line
: lineNumber
});
51 * @param {!WebInspector.Event} event
53 _onFrontendAPIMessage: function(event
)
55 var message
= JSON
.parse(/** @type {string} */ (event
.data
));
56 this._dispatchFrontendAPIMessage(message
["id"], message
["method"], message
["params"] || null);
61 * @param {string} method
62 * @param {?Object} params
64 _dispatchFrontendAPIMessage: function(id
, method
, params
)
66 this._dispatchingFrontendMessage
= true;
68 case "Frontend.updateBuffer":
69 var file
= params
["file"];
70 var buffer
= params
["buffer"];
71 var saved
= params
["saved"];
72 var uiSourceCode
= WebInspector
.workspace
.filesystemUISourceCode("file://" + file
);
74 if (buffer
!== uiSourceCode
.workingCopy())
75 uiSourceCode
.setWorkingCopy(buffer
);
77 uiSourceCode
.checkContentUpdated();
79 this._issueResponse(id
);
82 WebInspector
.console
.log("Unhandled API message: " + method
);
84 this._dispatchingFrontendMessage
= false;
88 * @param {!WebInspector.Event} event
89 * @param {boolean=} saved
91 _workingCopyChanged: function(event
, saved
)
93 if (this._dispatchingFrontendMessage
)
95 var uiSourceCode
= /** @type {!WebInspector.UISourceCode} */ (event
.data
["uiSourceCode"]);
96 var url
= uiSourceCode
.originURL();
97 if (url
.startsWith("file://"))
98 url
= url
.substring(7);
99 var params
= { file
: url
, buffer
: uiSourceCode
.workingCopy() };
102 this._issueFrontendAPINotification("Frontend.bufferUpdated", params
);
106 * @param {!WebInspector.Event} event
108 _workingCopyCommitted: function(event
)
110 this._workingCopyChanged(event
, true);
115 * @param {!Object=} params
117 _issueResponse: function(id
, params
)
119 var object
= {id
: id
};
121 object
.params
= params
;
122 InspectorFrontendHost
.sendFrontendAPINotification(JSON
.stringify(object
));
126 * @param {string} method
127 * @param {?Object} params
129 _issueFrontendAPINotification: function(method
, params
)
131 InspectorFrontendHost
.sendFrontendAPINotification(JSON
.stringify({ method
: method
, params
: params
}));