summaryrefslogtreecommitdiffstats
path: root/devtools/client/jsonview/main.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/jsonview/main.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/jsonview/main.js')
-rw-r--r--devtools/client/jsonview/main.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/devtools/client/jsonview/main.js b/devtools/client/jsonview/main.js
new file mode 100644
index 000000000..a438e2e34
--- /dev/null
+++ b/devtools/client/jsonview/main.js
@@ -0,0 +1,62 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+/* globals JsonViewUtils*/
+
+"use strict";
+
+const { Cu } = require("chrome");
+const Services = require("Services");
+
+const { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
+
+XPCOMUtils.defineLazyGetter(this, "JsonViewUtils", function () {
+ return require("devtools/client/jsonview/utils");
+});
+
+/**
+ * Singleton object that represents the JSON View in-content tool.
+ * It has the same lifetime as the browser. Initialization done by
+ * DevTools() object from devtools/client/framework/devtools.js
+ */
+var JsonView = {
+ initialize: function () {
+ // Load JSON converter module. This converter is responsible
+ // for handling 'application/json' documents and converting
+ // them into a simple web-app that allows easy inspection
+ // of the JSON data.
+ Services.ppmm.loadProcessScript(
+ "resource://devtools/client/jsonview/converter-observer.js",
+ true);
+
+ this.onSaveListener = this.onSave.bind(this);
+
+ // Register for messages coming from the child process.
+ Services.ppmm.addMessageListener(
+ "devtools:jsonview:save", this.onSaveListener);
+ },
+
+ destroy: function () {
+ Services.ppmm.removeMessageListener(
+ "devtools:jsonview:save", this.onSaveListener);
+ },
+
+ // Message handlers for events from child processes
+
+ /**
+ * Save JSON to a file needs to be implemented here
+ * in the parent process.
+ */
+ onSave: function (message) {
+ let value = message.data;
+ let file = JsonViewUtils.getTargetFile();
+ if (file) {
+ JsonViewUtils.saveToFile(file, value);
+ }
+ }
+};
+
+// Exports from this module
+module.exports.JsonView = JsonView;