"use strict";

const {before} = require("sdk/test/utils");
const {PlacesProvider} = require("addon/PlacesProvider");
const {PlacesTestUtils} = require("./lib/PlacesTestUtils");
const {Ci, Cu} = require("chrome");
const systemEvents = require("sdk/system/events");
const {TOP_SITES_DEFAULT_LENGTH} = require("common/constants");

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.importGlobalProperties(["btoa"]);

XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                  "resource://gre/modules/PlacesUtils.jsm");

XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
                                  "resource://gre/modules/NetUtil.jsm");

XPCOMUtils.defineLazyModuleGetter(this, "Bookmarks",
                                  "resource://gre/modules/Bookmarks.jsm");

// use time at the start of the tests, chnaging it inside timeDaysAgo()
// may cause tiny time differences, which break expected sql ordering
const TIME_NOW = (new Date()).getTime();

// utility function to compute past timestamp in microseconds
function timeDaysAgo(numDays) {
  return (TIME_NOW - (numDays * 24 * 60 * 60 * 1000)) * 1000;
}

// tests that timestamp falls within 10 days of now
Example #2
0
/* 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";

var {Cu, Cc, Ci} = require("chrome");

Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/osfile.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/UserCustomizations.jsm");
Cu.importGlobalProperties(["FileReader"]);

var promise = require("promise");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { ActorPool } = require("devtools/server/actors/common");
var { DebuggerServer } = require("devtools/server/main");
var Services = require("Services");

// Comma separated list of permissions that a sideloaded app can't ask for
const UNSAFE_PERMISSIONS = Services.prefs.getCharPref("devtools.apps.forbidden-permissions");

var FramesMock = null;

exports.setFramesMock = function (mock) {
  FramesMock = mock;
};

DevToolsUtils.defineLazyGetter(this, "Frames", () => {
Example #3
0
const chrome = require('chrome');
chrome.Cu.importGlobalProperties(['fetch']);

const contextMenu = require('sdk/context-menu');
const notifications = require('sdk/notifications');
const panels = require('sdk/panel');
const passwords = require('sdk/passwords');
const prefs = require('sdk/simple-prefs');

contextMenu.Item({
	contentScript: 'self.on("click", function(node) { self.postMessage(node.href); });',
	context: contextMenu.URLContext('*'),
	label: 'Send to LFTP',
	onMessage: onMenuItemClick
});

function onMenuItemClick(path) {
	return getSavedCredentials(path).then(credentials => onSendLink(path, credentials.username, credentials.password));
}

function onSendLink(path, username, password) {
	return sendLink(path, username, password)
		.then(response => onResponse(path, response))
		.catch(onError);
}

function onResponse(path, response) {
	if (response.status === 401) {
		return new Promise((resolve, reject) => {
			const panel = panels.Panel({
				contentURL: './password.html',
/* globals Services, XPCOMUtils */

const {Ci, Cu} = require("chrome");
const simplePrefs = require("sdk/simple-prefs");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.importGlobalProperties(["fetch"]);

const ENDPOINT_PREF = "telemetry.ping.endpoint";
const TELEMETRY_PREF = "telemetry";
const ACTION_NOTIF = "user-action-event";
const PERFORMANCE_NOTIF = "performance-event";
const COMPLETE_NOTIF = "tab-session-complete";
const LOGGING_PREF = "performance.log";

function TelemetrySender() {
  this.enabled = simplePrefs.prefs[TELEMETRY_PREF];
  this._pingEndpoint = simplePrefs.prefs[ENDPOINT_PREF];
  this.logging = simplePrefs.prefs[LOGGING_PREF];
  this._onPrefChange = this._onPrefChange.bind(this);
  simplePrefs.on(ENDPOINT_PREF, this._onPrefChange);
  simplePrefs.on(TELEMETRY_PREF, this._onPrefChange);
  simplePrefs.on(LOGGING_PREF, this._onPrefChange);
  if (this.enabled) {
    Services.obs.addObserver(this, COMPLETE_NOTIF, true);
    Services.obs.addObserver(this, ACTION_NOTIF, true);
    Services.obs.addObserver(this, PERFORMANCE_NOTIF, true);
  }
}

TelemetrySender.prototype = {
Example #5
0
module.metadata = {
  'stability': 'experimental'
};

/*
 * Encodings supported by TextEncoder/Decoder:
 * utf-8, utf-16le, utf-16be
 * http://encoding.spec.whatwg.org/#interface-textencoder
 *
 * Node however supports the following encodings:
 * ascii, utf-8, utf-16le, usc2, base64, hex
 */

const { Cu } = require('chrome');
lazyRequire(this, 'sdk/lang/type', "isNumber");
Cu.importGlobalProperties(["TextEncoder", "TextDecoder"]);

exports.TextEncoder = TextEncoder;
exports.TextDecoder = TextDecoder;

/**
 * Use WeakMaps to work around Bug 929146, which prevents us from adding
 * getters or values to typed arrays
 * https://bugzilla.mozilla.org/show_bug.cgi?id=929146
 */
const parents = new WeakMap();
const views = new WeakMap();

function Buffer(subject, encoding /*, bufferLength */) {

  // Allow invocation without `new` constructor
Example #6
0
"use strict";

const {Cu} = require("chrome");
Cu.importGlobalProperties(["URL"]);

/**
 * Convert a hex color string to the RGB form, e.g. #0A0102 => [10, 1, 2]
 */
function hexToRGB(hex) {
  if (!hex) {
    return hex;
  }
  let hexToConvert = hex;
  // if the hex is in shorthand form, expand it first
  if (/^#?([a-f\d])([a-f\d])([a-f\d])$/i.test(hexToConvert)) {
    const expandedHex = [...hex].slice(1, 4).map(item => `${item}${item}`).join("");
    hexToConvert = `#${expandedHex}`;
  }
  let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexToConvert);
  return result ? [
    parseInt(result[1], 16),
    parseInt(result[2], 16),
    parseInt(result[3], 16)
  ] : null;
}

/*
 * Consolidate favicons from tippytop, firefox, and our own metadata. Tippytop
 * is our number 1 choice, followed by the favicon returned by the metadata service,
 * and finally firefox's data URI as a last resort
 */
/**
 * This file is used on Linux to get the symbol table for a library.
 * We call out to the 'nm' command line utility which writes out symbol
 * information to stdout.
 */
const child_process = require('sdk/system/child_process');
const { Cu } = require('chrome');
Cu.importGlobalProperties(['TextEncoder']);

class NMParser {
  constructor() {
    this._addrToSymMap = new Map();
    this._currentLine = '';
    this._approximateSymLength = 0;
  }

  consume(data) {
    const currentLineLength = this._currentLine.length;
    let buffer = this._currentLine + data;
    let nextLineBreak = buffer.indexOf('\n', currentLineLength);
    while (nextLineBreak !== -1) {
      this._processLine(buffer.substr(0, nextLineBreak));
      buffer = buffer.substr(nextLineBreak + 1);
      nextLineBreak = buffer.indexOf('\n');
    }
    this._currentLine = buffer;
  }

  finish() {
    this._processLine(this._currentLine);
    return {
Example #8
0
/* 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/. */

// This file holds various CSS parsing and rewriting utilities.
// Some entry points of note are:
// parseDeclarations - parse a CSS rule into declarations
// RuleRewriter - rewrite CSS rule text
// parsePseudoClassesAndAttributes - parse selector and extract
//     pseudo-classes
// parseSingleValue - parse a single CSS property value

"use strict";

const {Cc, Ci, Cu} = require("chrome");
Cu.importGlobalProperties(["CSS"]);
const promise = require("promise");
Cu.import("resource://gre/modules/Task.jsm", this);
loader.lazyGetter(this, "DOMUtils", () => {
  return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
});

const SELECTOR_ATTRIBUTE = exports.SELECTOR_ATTRIBUTE = 1;
const SELECTOR_ELEMENT = exports.SELECTOR_ELEMENT = 2;
const SELECTOR_PSEUDO_CLASS = exports.SELECTOR_PSEUDO_CLASS = 3;

// Used to test whether a newline appears anywhere in some text.
const NEWLINE_RX = /[\r\n]/;
// Used to test whether a bit of text starts an empty comment, either
// an "ordinary" /* ... */ comment, or a "heuristic bypass" comment
// like /*! ... */.
Example #9
0
/* global XPCOMUtils, Task, Services, EventEmitter, FormHistory,
SearchSuggestionController, PrivateBrowsingUtils, exports, require */

"use strict";
const {Ci, Cu} = require("chrome");
const CURRENT_ENGINE = "browser-search-engine-modified";
const HIDDEN_ENGINES = "browser.search.hiddenOneOffs";
const ENGINE_ICON_SIZE = 16;
const MAX_LOCAL_SUGGESTIONS = 3;
const MAX_SUGGESTIONS = 6;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.importGlobalProperties(["URL", "Blob", "FileReader", "atob"]);

XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
                                  "resource://gre/modules/FormHistory.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
                                  "resource://gre/modules/PrivateBrowsingUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "SearchSuggestionController",
                                  "resource://gre/modules/SearchSuggestionController.jsm");

XPCOMUtils.defineLazyGetter(this, "EventEmitter", function() {
  const {EventEmitter} = Cu.import("resource://devtools/shared/event-emitter.js", {});
  return EventEmitter;
});

let NewTabSearchProvider = function NewTabSearchProvider() {
  EventEmitter.decorate(this);
};
Example #10
0
/* globals crypto, atob, btoa */
/*eslint no-unused-vars: 1*/

"use strict";

/******
 * Begin magic patching for Firefox Addons 
 ******/
// Pull in the global crypto property
var {Cu} = require('chrome');
Cu.importGlobalProperties(['crypto', 'atob', 'btoa']);

/******
 * End magic patching for Firefox Addons 
 ******/

// Error is automatically available in addon land
// Uint8Array is automatically available in addon land

// supporting Safari and its vendor prefix
if(!crypto.subtle) crypto.subtle = crypto.webkitSubtle;
/*-
 * Copyright 2014 Square Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
Example #11
0
			chrome: true,
			width: 200,
			height: 50,
			popup: true
		})
	});
	*/
};

var {Cc, Ci, Cr, Cu} = require("chrome");
var { viewFor } = require("sdk/view/core");
var windows = require("sdk/windows").browserWindows;

const fileIO = require("sdk/io/file");

Cu.importGlobalProperties( [ "File" ] );


function openFilePicker(callback, options)
{
	var domWin = viewFor(windows.activeWindow);
	//console.log('CHROME WIN', domWin, windows.activeWindow);
	var nsIFilePicker = Ci.nsIFilePicker;
	var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
	fp.init(domWin, /*"Select a File MMMMMMMMMM"*/null, nsIFilePicker.modeOpen);

	// filters
	var filters = options.filters || [];
	//console.log(filters);
	for (var i = 0, l = filters.length; i < l; ++i)
	{