Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
saveToFile: function(file, jsonString, compress) {
let openFlags = OPEN_FLAGS.WRONLY | OPEN_FLAGS.CREATE_FILE |
OPEN_FLAGS.TRUNCATE;
try {
let foStream = Cc("@mozilla.org/network/file-output-stream;1")
.createInstance(Ci.nsIFileOutputStream);
let permFlags = parseInt("0666", 8);
foStream.init(file, openFlags, permFlags, 0);
let convertor = Cc("@mozilla.org/intl/converter-output-stream;1")
.createInstance(Ci.nsIConverterOutputStream);
convertor.init(foStream, "UTF-8", 0, 0);
// The entire jsonString can be huge so, write the data in chunks.
let chunkLength = 1024 * 1024;
for (let i=0; i<=jsonString.length; i++) {
let data = jsonString.substr(i, chunkLength+1);
if (data) {
convertor.writeString(data);
}
i = i + chunkLength;
}
// this closes foStream
convertor.close();
// asynchronously.
// Both ends of the pipe must be blocking.
let sink = Cc("@mozilla.org/pipe;1").createInstance(Ci.nsIPipe);
// The streams need to be blocking because this is required by the
// stream tee.
sink.init(false, false, this.responsePipeSegmentSize, PR_UINT32_MAX, null);
// Add listener for the response body.
let newListener = new NetworkResponseListener(this, aHttpActivity);
// Remember the input stream, so it isn't released by GC.
newListener.inputStream = sink.inputStream;
newListener.sink = sink;
let tee = Cc("@mozilla.org/network/stream-listener-tee;1").
createInstance(Ci.nsIStreamListenerTee);
let originalListener = channel.setNewListener(tee);
tee.init(originalListener, sink.outputStream, newListener);
},
"use strict";
const { Ci, Cc } = require("devtools/sham/chrome");
const { Services } = require("devtools/sham/services");
const { DOMHelpers } = require("devtools/client/shared/DOMHelpers");
const { Task } = require("devtools/sham/task");
const { Promise } = require("devtools/sham/promise");
const { getMostRecentBrowserWindow } = require("sdk/window/utils");
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const DEV_EDITION_PROMO_URL = "/devtools/client/framework/dev-edition-promo/dev-edition-promo.xul";
const DEV_EDITION_PROMO_ENABLED_PREF = "devtools.devedition.promo.enabled";
const DEV_EDITION_PROMO_SHOWN_PREF = "devtools.devedition.promo.shown";
const DEV_EDITION_PROMO_URL_PREF = "devtools.devedition.promo.url";
const LOCALE = Cc("@mozilla.org/chrome/chrome-registry;1")
.getService(Ci.nsIXULChromeRegistry)
.getSelectedLocale("global");
/**
* Only show Dev Edition promo if it's enabled (beta channel),
* if it has not been shown before, and it's a locale build
* for `en-US`
*/
function shouldDevEditionPromoShow () {
return Services.prefs.getBoolPref(DEV_EDITION_PROMO_ENABLED_PREF) &&
!Services.prefs.getBoolPref(DEV_EDITION_PROMO_SHOWN_PREF) &&
LOCALE === "en-US";
}
var TYPES = {
// The Developer Edition promo doorhanger, called by
DevToolsUtils.defineLazyGetter(this, "localCertService", () => {
// Ensure PSM is initialized to support TLS sockets
Cc("@mozilla.org/psm;1").getService(Ci.nsISupports);
return Cc("@mozilla.org/security/local-cert-service;1")
.getService(Ci.nsILocalCertService);
});
/* -*- 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, Cu} = require("devtools/sham/chrome");
//const {setTimeout, clearTimeout} = require("devtools/sham/timer");
const {parseDeclarations} =
require("devtools/client/shared/css-parsing-utils");
const promise = require("devtools/sham/promise");
const HTML_NS = "http://www.w3.org/1999/xhtml";
const domUtils = Cc("@mozilla.org/inspector/dom-utils;1")
.getService(Ci.inIDOMUtils);
/**
* Create a child element with a set of attributes.
*
* @param {Element} parent
* The parent node.
* @param {string} tagName
* The tag name.
* @param {object} attributes
* A set of attributes to set on the node.
*/
function createChild(parent, tagName, attributes={}) {
let elt = parent.ownerDocument.createElementNS(HTML_NS, tagName);
for (let attr in attributes) {
if (attributes.hasOwnProperty(attr)) {
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set 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, Cu} = require("devtools/sham/chrome");
const {PREF_ORIG_SOURCES} = require("devtools/client/styleeditor/utils");
const overlays = require("devtools/client/styleinspector/style-inspector-overlays");
const { Services } = require("devtools/sham/services");
const {Task} = require("devtools/sham/task");
const clipboardHelper = Cc("@mozilla.org/widget/clipboardhelper;1").getService(Ci.nsIClipboardHelper);
const _strings = Services.strings.createBundle(require("l10n/styleinspector.properties"));
// XXX: Need to use different popups
const XUL_NS = "http://www.w3.org/1999/xhtml";
const PREF_ENABLE_MDN_DOCS_TOOLTIP =
"devtools.inspector.mdnDocsTooltip.enabled";
/**
* Style inspector context menu
*
* @param {RuleView|ComputedView} view
* RuleView or ComputedView instance controlling this menu
* @param {Object} options
* Option menu configuration
*/
function StyleInspectorMenu(view, options) {
saveFileAs: function SP_saveFileAs(aCallback)
{
let fp = Cc("@mozilla.org/filepicker;1").createInstance(Ci.nsIFilePicker);
let fpCallback = aResult => {
if (aResult != Ci.nsIFilePicker.returnCancel) {
this.setFilename(fp.file.path);
this.exportToFile(fp.file, true, false, aStatus => {
if (Components.isSuccessCode(aStatus)) {
this.dirty = false;
this.setRecentFile(fp.file);
}
if (aCallback) {
aCallback(aStatus);
}
});
}
};
fp.init(window, this.strings.GetStringFromName("saveFileAs"),
loader.lazyGetter(this, "oscpu", () => {
return Cc("@mozilla.org/network/protocol;1?name=http")
.getService(Ci.nsIHttpProtocolHandler).oscpu;
});
getLocalDirectory: function(path) {
let dir;
if (!path) {
dir = dirService.get("ProfD", Ci.nsILocalFile);
dir.append("har");
dir.append("logs");
} else {
dir = Cc("@mozilla.org/file/local;1").createInstance(Ci.nsILocalFile);
dir.initWithPath(path);
}
return dir;
},
}
saveFile: function SP_saveFile(aCallback)
{
if (!this.filename) {
return this.saveFileAs(aCallback);
}
let file = Cc("@mozilla.org/file/local;1").createInstance(Ci.nsILocalFile);
file.initWithPath(this.filename);
this.exportToFile(file, true, false, aStatus => {
if (Components.isSuccessCode(aStatus)) {
this.dirty = false;
document.getElementById("sp-cmd-revert").setAttribute("disabled", true);
this.setRecentFile(file);
}
if (aCallback) {
aCallback(aStatus);
}
});
},