Backed out changeset bbbe3c47bd0b (bug 1297361) for eslint failure
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Mon, 05 Dec 2016 16:17:20 +0100
changeset 325291 1e7ee9c3b11432576e6bff68aa9a96650c3130a0
parent 325290 2d08aeb18ac99e1078a762cf0146a6a124a76018
child 325292 b997bb5bccb4da93ce1f5d3453ca562324ab1d5f
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
bugs1297361
milestone53.0a1
backs outbbbe3c47bd0b88bd6f1b6ca39a1f8d68bd89f4e7
Backed out changeset bbbe3c47bd0b (bug 1297361) for eslint failure
devtools/client/jsonview/converter-child.js
devtools/client/jsonview/json-viewer.js
--- a/devtools/client/jsonview/converter-child.js
+++ b/devtools/client/jsonview/converter-child.js
@@ -1,17 +1,17 @@
 /* -*- 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/. */
 
 "use strict";
 
-const {Cc, Ci, components} = require("chrome");
+const {Cu, Cc, Ci, components} = require("chrome");
 const Services = require("Services");
 const {Class} = require("sdk/core/heritage");
 const {Unknown} = require("sdk/platform/xpcom");
 const xpcom = require("sdk/platform/xpcom");
 const Events = require("sdk/dom/events");
 const Clipboard = require("sdk/clipboard");
 
 loader.lazyRequireGetter(this, "NetworkHelper",
@@ -135,18 +135,19 @@ let Converter = Class({
           return undefined;
         }
       }
     };
 
     JsonViewUtils.exportIntoContentScope(win, Locale, "Locale");
 
     Events.once(win, "DOMContentLoaded", event => {
-      win.addEventListener("contentMessage",
-        this.onContentMessage.bind(this), false, true);
+      Cu.exportFunction(this.postChromeMessage.bind(this), win, {
+        defineAs: "postChromeMessage"
+      });
     });
 
     // The request doesn't have to be always nsIHttpChannel
     // (e.g. in case of data: URLs)
     if (request instanceof Ci.nsIHttpChannel) {
       request.visitResponseHeaders({
         visitHeader: function (name, value) {
           headers.response.push({name: name, value: value});
@@ -257,25 +258,20 @@ let Converter = Class({
       "<base href=\"" + this.htmlEncode(this.data.url()) + "\">" +
       "</head><body>" +
       output +
       "</body></html>";
   },
 
   // Chrome <-> Content communication
 
-  onContentMessage: function (e) {
-    // Do not handle events from different documents.
-    let win = NetworkHelper.getWindowForRequest(this.channel);
-    if (win != e.target) {
-      return;
-    }
+  postChromeMessage: function (type, args, objects) {
+    let value = args;
 
-    let value = e.detail.value;
-    switch (e.detail.type) {
+    switch (type) {
       case "copy":
         Clipboard.set(value, "text");
         break;
 
       case "copy-headers":
         this.copyHeaders(value);
         break;
 
--- a/devtools/client/jsonview/json-viewer.js
+++ b/devtools/client/jsonview/json-viewer.js
@@ -37,25 +37,27 @@ define(function (require, exports, modul
   headers.remove();
 
   /**
    * Application actions/commands. This list implements all commands
    * available for the JSON viewer.
    */
   input.actions = {
     onCopyJson: function () {
-      dispatchEvent("copy", input.prettified ? input.jsonPretty : input.jsonText);
+      let value = input.prettified ? input.jsonPretty : input.jsonText;
+      postChromeMessage("copy", value);
     },
 
     onSaveJson: function () {
-      dispatchEvent("save", input.prettified ? input.jsonPretty : input.jsonText);
+      let value = input.prettified ? input.jsonPretty : input.jsonText;
+      postChromeMessage("save", value);
     },
 
     onCopyHeaders: function () {
-      dispatchEvent("copy-headers", input.headers);
+      postChromeMessage("copy-headers", input.headers);
     },
 
     onSearch: function (value) {
       theApp.setState({searchFilter: value});
     },
 
     onPrettify: function (data) {
       if (input.prettified) {
@@ -67,34 +69,16 @@ define(function (require, exports, modul
         theApp.setState({jsonText: input.jsonPretty});
       }
 
       input.prettified = !input.prettified;
     },
   };
 
   /**
-   * Helper for dispatching an event. It's handled in chrome scope.
-   *
-   * @param {String} type Event detail type
-   * @param {Object} value Event detail value
-   */
-  function dispatchEvent (type, value) {
-    let data = {
-      detail: {
-        type,
-        value,
-      }
-    };
-
-    let contentMessageEvent = new CustomEvent("contentMessage", data);
-    window.dispatchEvent(contentMessageEvent);
-  }
-
-  /**
    * Render the main application component. It's the main tab bar displayed
    * at the top of the window. This component also represents ReacJS root.
    */
   let content = document.getElementById("content");
   let theApp = render(MainTabbedArea(input), content);
 
   let onResize = event => {
     window.document.body.style.height = window.innerHeight + "px";