Bug 1369159 - Do not reuse the chrome window when saving in JSON Viewer. r=Honza
authorOriol <oriol-bugzilla@hotmail.com>
Thu, 01 Jun 2017 07:04:00 -0400
changeset 412506 5f83e3e0c2edbd5909a1549705c987a3b1462a3b
parent 412505 da6426dca3796cfaece3af92e5f8f0a77768d6f4
child 412507 73a2ddbb89bc2011fff7867582d182c015730bfa
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1369159
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1369159 - Do not reuse the chrome window when saving in JSON Viewer. r=Honza
devtools/client/jsonview/main.js
--- a/devtools/client/jsonview/main.js
+++ b/devtools/client/jsonview/main.js
@@ -1,30 +1,24 @@
 /* -*- 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, Cc, Ci } = require("chrome");
 const Services = require("Services");
 
 const { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
 
-XPCOMUtils.defineLazyGetter(this, "chrome", function () {
+XPCOMUtils.defineLazyGetter(this, "WindowMediator", function () {
   return Cc["@mozilla.org/appshell/window-mediator;1"]
-    .getService(Ci.nsIWindowMediator)
-    .getMostRecentWindow("navigator:browser");
-});
-
-XPCOMUtils.defineLazyGetter(this, "JsonViewUtils", function () {
-  return require("devtools/client/jsonview/utils");
+    .getService(Ci.nsIWindowMediator);
 });
 
 /**
  * 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 = {
@@ -32,35 +26,34 @@ var JsonView = {
     // 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);
+      "devtools:jsonview:save", this.onSave);
   },
 
   destroy: function () {
     Services.ppmm.removeMessageListener(
-      "devtools:jsonview:save", this.onSaveListener);
+      "devtools:jsonview:save", this.onSave);
   },
 
   // 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 chrome = WindowMediator.getMostRecentWindow("navigator:browser");
     let browser = chrome.gBrowser.selectedBrowser;
     if (message.data.url === null) {
       // Save original contents
       chrome.saveBrowser(browser, false, message.data.windowID);
     } else {
       // The following code emulates saveBrowser, but:
       // - Uses the given blob URL containing the custom contents to save.
       // - Obtains the file name from the URL of the document, not the blob.