1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 var EXPORTED_SYMBOLS = ["JSONHandler"];
9 const { HTTP_404, HTTP_505 } = ChromeUtils.import(
10 "chrome://remote/content/server/HTTPD.jsm"
12 const { Log } = ChromeUtils.import("chrome://remote/content/Log.jsm");
13 const { Protocol } = ChromeUtils.import("chrome://remote/content/Protocol.jsm");
14 const { RemoteAgentError } = ChromeUtils.import(
15 "chrome://remote/content/Error.jsm"
22 "/json/version": this.getVersion.bind(this),
23 "/json/protocol": this.getProtocol.bind(this),
24 "/json/list": this.getTargetList.bind(this),
29 const mainProcessTarget = this.agent.targets.getMainProcessTarget();
32 "Protocol-Version": "1.0",
33 "User-Agent": "Mozilla",
35 "WebKit-Version": "1.0",
36 webSocketDebuggerUrl: mainProcessTarget.toJSON().webSocketDebuggerUrl,
41 return Protocol.Description;
45 return [...this.agent.targets];
48 // nsIHttpRequestHandler
50 handle(request, response) {
51 if (request.method != "GET") {
55 if (!(request.path in this.routes)) {
60 const body = this.routes[request.path]();
61 const payload = JSON.stringify(body, null, Log.verbose ? "\t" : null);
63 response.setStatusLine(request.httpVersion, 200, "OK");
64 response.setHeader("Content-Type", "application/json");
65 response.write(payload);
67 new RemoteAgentError(e).notify();
74 get QueryInterface() {
75 return ChromeUtils.generateQI(["nsIHttpRequestHandler"]);