aboutsummaryrefslogtreecommitdiff
path: root/tools/addon-sdk-1.5/packages/api-utils/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tools/addon-sdk-1.5/packages/api-utils/lib/utils')
-rw-r--r--tools/addon-sdk-1.5/packages/api-utils/lib/utils/data.js71
-rw-r--r--tools/addon-sdk-1.5/packages/api-utils/lib/utils/function.js50
-rw-r--r--tools/addon-sdk-1.5/packages/api-utils/lib/utils/object.js46
-rw-r--r--tools/addon-sdk-1.5/packages/api-utils/lib/utils/registry.js57
-rw-r--r--tools/addon-sdk-1.5/packages/api-utils/lib/utils/thumbnail.js43
5 files changed, 0 insertions, 267 deletions
diff --git a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/data.js b/tools/addon-sdk-1.5/packages/api-utils/lib/utils/data.js
deleted file mode 100644
index 33356cd..0000000
--- a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/data.js
+++ /dev/null
@@ -1,71 +0,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";
-
-const { Cc, Ci, Cu } = require("chrome");
-const IOService = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService);
-const AppShellService = Cc["@mozilla.org/appshell/appShellService;1"].
- getService(Ci.nsIAppShellService);
-
-const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm");
-const FaviconService = Cc["@mozilla.org/browser/favicon-service;1"].
- getService(Ci.nsIFaviconService);
-
-const PNG_B64 = "data:image/png;base64,";
-const DEF_FAVICON_URI = "chrome://mozapps/skin/places/defaultFavicon.png";
-let DEF_FAVICON = null;
-
-/**
- * Takes URI of the page and returns associated favicon URI.
- * If page under passed uri has no favicon then base64 encoded data URI of
- * default faveicon is returned.
- * @param {String} uri
- * @returns {String}
- */
-exports.getFaviconURIForLocation = function getFaviconURIForLocation(uri) {
- let pageURI = NetUtil.newURI(uri);
- try {
- return FaviconService.getFaviconDataAsDataURL(
- FaviconService.getFaviconForPage(pageURI));
- }
- catch(e) {
- if (!DEF_FAVICON) {
- DEF_FAVICON = PNG_B64 +
- base64Encode(getChromeURIContent(DEF_FAVICON_URI));
- }
- return DEF_FAVICON;
- }
-}
-
-/**
- * Takes chrome URI and returns content under that URI.
- * @param {String} chromeURI
- * @returns {String}
- */
-function getChromeURIContent(chromeURI) {
- let channel = IOService.newChannel(chromeURI, null, null);
- let input = channel.open();
- let stream = Cc["@mozilla.org/binaryinputstream;1"].
- createInstance(Ci.nsIBinaryInputStream);
- stream.setInputStream(input);
- let content = stream.readBytes(input.available());
- stream.close();
- input.close();
- return content;
-}
-exports.getChromeURIContent = getChromeURIContent;
-
-/**
- * Creates a base-64 encoded ASCII string from a string of binary data.
- */
-function base64Encode(data) AppShellService.hiddenDOMWindow.btoa(String(data));
-exports.base64Encode = base64Encode;
-
-/**
- * Decodes a string of data which has been encoded using base-64 encoding.
- */
-function base64Decode(data) AppShellService.hiddenDOMWindow.atob(String(data));
-exports.base64Decode = base64Decode;
diff --git a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/function.js b/tools/addon-sdk-1.5/packages/api-utils/lib/utils/function.js
deleted file mode 100644
index d943c65..0000000
--- a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/function.js
+++ /dev/null
@@ -1,50 +0,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 { setTimeout } = require("../timer");
-
-/**
- * Takes a function and returns a wrapped one instead, calling which will call
- * original function in the next turn of event loop. This is basically utility
- * to do `setTimeout(function() { ... }, 0)`, with a difference that returned
- * function is reused, instead of creating a new one each time. This also allows
- * to use this functions as event listeners.
- */
-function Enqueued(callee) {
- return function enqueued()
- setTimeout(invoke, 0, callee, arguments, this);
-}
-exports.Enqueued = Enqueued;
-
-/**
- * Invokes `callee` by passing `params` as an arguments and `self` as `this`
- * pseudo-variable. Returns value that is returned by a callee.
- * @param {Function} callee
- * Function to invoke.
- * @param {Array} params
- * Arguments to invoke function with.
- * @param {Object} self
- * Object to be passed as a `this` pseudo variable.
- */
-function invoke(callee, params, self) callee.apply(self, params);
-exports.invoke = invoke;
-
-/**
- * Curries a function with the arguments given.
- *
- * @param {Function} fn
- * The function to curry
- *
- * @returns The function curried
- */
-function curry(fn) {
- if (typeof fn !== "function")
- throw new TypeError(String(fn) + " is not a function");
-
- let args = Array.slice(arguments, 1);
-
- return function() fn.apply(this, args.concat(Array.slice(arguments)));
-}
-exports.curry = curry;
diff --git a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/object.js b/tools/addon-sdk-1.5/packages/api-utils/lib/utils/object.js
deleted file mode 100644
index 165aa0b..0000000
--- a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/object.js
+++ /dev/null
@@ -1,46 +0,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";
-
-/**
- * Merges all the properties of all arguments into first argument. If two or
- * more argument objects have own properties with the same name, the property
- * is overridden, with precedence from right to left, implying, that properties
- * of the object on the left are overridden by a same named property of the
- * object on the right.
- * @examples
- * var a = { bar: 0, a: 'a' }
- * var b = merge(a, { foo: 'foo', bar: 1 }, { foo: 'bar', name: 'b' });
- * b === a // true
- * b.a // 'a'
- * b.foo // 'bar'
- * b.bar // 1
- * b.name // 'b'
- */
-function merge(source) {
- let descriptor = {};
- Array.slice(arguments, 1).forEach(function onEach(properties) {
- Object.getOwnPropertyNames(properties).forEach(function(name) {
- descriptor[name] = Object.getOwnPropertyDescriptor(properties, name);
- });
- });
- return Object.defineProperties(source, descriptor);
-}
-exports.merge = merge;
-
-/**
- * Returns an object that inherits from the first argument and contains all the
- * properties from all following arguments.
- * `extend(source1, source2, source3)` is equivalent of
- * `merge(Object.create(source1), source2, source3)`.
- */
-function extend(source) {
- let rest = Array.slice(arguments, 1);
- rest.unshift(Object.create(source));
- return merge.apply(null, rest);
-}
-exports.extend = extend;
-
-
diff --git a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/registry.js b/tools/addon-sdk-1.5/packages/api-utils/lib/utils/registry.js
deleted file mode 100644
index 2ce6a6e..0000000
--- a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/registry.js
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et: */
-/* 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 { EventEmitter } = require('../events');
-const unload = require('../unload');
-
-const Registry = EventEmitter.compose({
- _registry: null,
- _constructor: null,
- constructor: function Registry(constructor) {
- this._registry = [];
- this._constructor = constructor;
- this.on('error', this._onError = this._onError.bind(this));
- unload.ensure(this, "_destructor");
- },
- _destructor: function _destructor() {
- let _registry = this._registry.slice(0);
- for each (let instance in _registry)
- this._emit('remove', instance);
- this._registry.splice(0);
- },
- _onError: function _onError(e) {
- if (!this._listeners('error').length)
- console.error(e);
- },
- has: function has(instance) {
- let _registry = this._registry;
- return (
- (0 <= _registry.indexOf(instance)) ||
- (instance && instance._public && 0 <= _registry.indexOf(instance._public))
- );
- },
- add: function add(instance) {
- let { _constructor, _registry } = this;
- if (!(instance instanceof _constructor))
- instance = new _constructor(instance);
- if (0 > _registry.indexOf(instance)) {
- _registry.push(instance);
- this._emit('add', instance);
- }
- return instance;
- },
- remove: function remove(instance) {
- let _registry = this._registry;
- let index = _registry.indexOf(instance)
- if (0 <= index) {
- this._emit('remove', instance);
- _registry.splice(index, 1);
- }
- }
-});
-exports.Registry = Registry;
-
diff --git a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/thumbnail.js b/tools/addon-sdk-1.5/packages/api-utils/lib/utils/thumbnail.js
deleted file mode 100644
index dfd03dd..0000000
--- a/tools/addon-sdk-1.5/packages/api-utils/lib/utils/thumbnail.js
+++ /dev/null
@@ -1,43 +0,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";
-
-const { Cc, Ci, Cu } = require("chrome");
-const AppShellService = Cc["@mozilla.org/appshell/appShellService;1"].
- getService(Ci.nsIAppShellService);
-
-const NS = "http://www.w3.org/1999/xhtml";
-const COLOR = "rgb(255,255,255)";
-
-/**
- * Creates canvas element with a thumbnail of the passed window.
- * @param {Window} window
- * @returns {Element}
- */
-function getThumbnailCanvasForWindow(window) {
- let aspectRatio = 0.5625; // 16:9
- let thumbnail = AppShellService.hiddenDOMWindow.document
- .createElementNS(NS, "canvas");
- thumbnail.mozOpaque = true;
- thumbnail.width = Math.ceil(window.screen.availWidth / 5.75);
- thumbnail.height = Math.round(thumbnail.width * aspectRatio);
- let ctx = thumbnail.getContext("2d");
- let snippetWidth = window.innerWidth * .6;
- let scale = thumbnail.width / snippetWidth;
- ctx.scale(scale, scale);
- ctx.drawWindow(window, window.scrollX, window.scrollY, snippetWidth,
- snippetWidth * aspectRatio, COLOR);
- return thumbnail;
-}
-exports.getThumbnailCanvasForWindow = getThumbnailCanvasForWindow;
-
-/**
- * Creates Base64 encoded data URI of the thumbnail for the passed window.
- * @param {Window} window
- * @returns {String}
- */
-exports.getThumbnailURIForWindow = function getThumbnailURIForWindow(window) {
- return getThumbnailCanvasForWindow(window).toDataURL()
-};