зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1359855 - Inline jsonview main module to keep it working before user action. r=Honza,jdescottes
MozReview-Commit-ID: 3COOvQtYn0E --HG-- extra : rebase_source : 600e747ef6f902faee6c966e49d8cbbb304be873
This commit is contained in:
Родитель
113a2f9b50
Коммит
80498fc6b9
|
@ -193,6 +193,7 @@ DevToolsStartup.prototype = {
|
|||
// that command only once
|
||||
devtoolsFlag = false;
|
||||
}
|
||||
JsonView.initialize();
|
||||
};
|
||||
Services.obs.addObserver(onWindowReady, "browser-delayed-startup-finished");
|
||||
},
|
||||
|
@ -527,5 +528,67 @@ DevToolsStartup.prototype = {
|
|||
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
|
||||
};
|
||||
|
||||
/**
|
||||
* Singleton object that represents the JSON View in-content tool.
|
||||
* It has the same lifetime as the browser.
|
||||
*/
|
||||
const JsonView = {
|
||||
initialized: false,
|
||||
|
||||
initialize: function () {
|
||||
// Prevent loading the frame script multiple times if we call this more than once.
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
this.initialized = true;
|
||||
|
||||
// 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);
|
||||
|
||||
// Register for messages coming from the child process.
|
||||
// This is never removed as there is no particular need to unregister
|
||||
// it during shutdown.
|
||||
Services.ppmm.addMessageListener(
|
||||
"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 = Services.wm.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.
|
||||
let persistable = browser.QueryInterface(Ci.nsIFrameLoaderOwner)
|
||||
.frameLoader.QueryInterface(Ci.nsIWebBrowserPersistable);
|
||||
persistable.startPersistence(message.data.windowID, {
|
||||
onDocumentReady(doc) {
|
||||
let uri = chrome.makeURI(doc.documentURI, doc.characterSet);
|
||||
let filename = chrome.getDefaultFileName(undefined, uri, doc, null);
|
||||
chrome.internalSave(message.data.url, doc, filename, null, doc.contentType,
|
||||
false, null, null, null, doc, false, null, undefined);
|
||||
},
|
||||
onError(status) {
|
||||
throw new Error("JSON Viewer's onSave failed in startPersistence");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(
|
||||
[DevToolsStartup]);
|
||||
|
|
|
@ -24,7 +24,6 @@ loader.lazyImporter(this, "BrowserToolboxProcess", "resource://devtools/client/f
|
|||
const {defaultTools: DefaultTools, defaultThemes: DefaultThemes} =
|
||||
require("devtools/client/definitions");
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
const {JsonView} = require("devtools/client/jsonview/main");
|
||||
const AboutDevTools = require("devtools/client/framework/about-devtools-toolbox");
|
||||
const {Task} = require("devtools/shared/task");
|
||||
const {getTheme, setTheme, addThemeObserver, removeThemeObserver} =
|
||||
|
@ -44,9 +43,6 @@ function DevTools() {
|
|||
// List of toolboxes that are still in process of creation
|
||||
this._creatingToolboxes = new Map(); // Map<target, toolbox Promise>
|
||||
|
||||
// JSON Viewer for 'application/json' documents.
|
||||
JsonView.initialize();
|
||||
|
||||
AboutDevTools.register();
|
||||
|
||||
EventEmitter.decorate(this);
|
||||
|
@ -644,8 +640,6 @@ DevTools.prototype = {
|
|||
this.unregisterTool(key, true);
|
||||
}
|
||||
|
||||
JsonView.destroy();
|
||||
|
||||
gDevTools.unregisterDefaults();
|
||||
|
||||
removeThemeObserver(this._onThemeChanged);
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
/* -*- 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 { Ci } = require("chrome");
|
||||
const Services = require("Services");
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
// Register for messages coming from the child process.
|
||||
Services.ppmm.addMessageListener(
|
||||
"devtools:jsonview:save", this.onSave);
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
Services.ppmm.removeMessageListener(
|
||||
"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 = Services.wm.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.
|
||||
let persistable = browser.QueryInterface(Ci.nsIFrameLoaderOwner)
|
||||
.frameLoader.QueryInterface(Ci.nsIWebBrowserPersistable);
|
||||
persistable.startPersistence(message.data.windowID, {
|
||||
onDocumentReady(doc) {
|
||||
let uri = chrome.makeURI(doc.documentURI, doc.characterSet);
|
||||
let filename = chrome.getDefaultFileName(undefined, uri, doc, null);
|
||||
chrome.internalSave(message.data.url, doc, filename, null, doc.contentType,
|
||||
false, null, null, null, doc, false, null, undefined);
|
||||
},
|
||||
onError(status) {
|
||||
throw new Error("JSON Viewer's onSave failed in startPersistence");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Exports from this module
|
||||
module.exports.JsonView = JsonView;
|
|
@ -14,7 +14,6 @@ DevToolsModules(
|
|||
'converter-child.js',
|
||||
'converter-observer.js',
|
||||
'json-viewer.js',
|
||||
'main.js',
|
||||
'viewer-config.js'
|
||||
)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче