/* You may find the license in the LICENSE file */

/*
 * This is a compat layer, that will likely change or will be completely removed!
 * Please use api.jsm directly
 */

const EXPORTED_SYMBOLS = ['inject'];

function inject(window) {
	window.__defineGetter__('DTA', function(){
		delete this.DTA;
		let DTA = {
			showPreferences: function(pane) this.Mediator.showPreferences(window, pane)
		};
		Components.utils.import("resource://dta/api.jsm", DTA);
		DTA.Mediator.open = function DTA_Mediator_open(url, ref) {
			this.openUrl(window, url, ref);
		}
		return (window.DTA = DTA);
	});
	
	/* Compat; mostly FlashGot, maybe others */
	// Obsolete; will be removed in 2.++ timeframe
	window.__defineGetter__('DTA_AddingFunctions', function() {
	 	let rv = {
			get ios() {
				return DTA.IOService
			},
			composeURL: function() DTA.composeURL.apply(this, arguments),
			applyWithWindow: function(func, args) {
				DTA.Debug.logString("Obsolete function called: " + func.name);
				args.unshift(window);
				return func.apply(DTA, args);
			},
			saveSingleLink: function() this.applyWithWindow(DTA.saveSingleLink, Array.map(arguments, function(e) e)),
			saveLinkArray: function() {
				let args = Array.map(arguments, function(e) e);
				let turbo = args.shift();
				if (turbo) {
					this.applyWithWindow(DTA.turboSaveLinkArray, args);
				}
				else {
					this.applyWithWindow(DTA.saveLinkArray, args);
				}
			},
			turboSaveLinkArray: function() this.applyWithWindow(DTA.turboSaveLinkArray, Array.map(arguments, function(e) e)),
			sendToDown: function() this.applyWithWindow(DTA.sendToDown, Array.map(arguments, function(e) e)),
			turboSendToDown: function() this.applyWithWindow(DTA.turboSendToDown, Array.map(arguments, function(e) e))
		};
	 	delete window.DTA_AddingFunctions;
	 	return (window.DTA_AddingFunctions = rv);
	});
	window.__defineGetter__('DTA_getLinkPrintMetalink', function() DTA.getLinkPrintMetalink);
	window.__defineGetter__('DTA_URL', function() DTA.URL);
};