michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const tabs = require('sdk/tabs'); michael@0: const widgets = require('sdk/widget'); michael@0: const data = require('sdk/self').data; michael@0: const pageMod = require('sdk/page-mod'); michael@0: const panel = require('sdk/panel'); michael@0: michael@0: const ICON_WIDTH = 16; michael@0: michael@0: function updateWidgetView(tab) { michael@0: let widgetView = widget.getView(tab.window); michael@0: if (!tab.libraries) { michael@0: tab.libraries = []; michael@0: } michael@0: widgetView.port.emit("update", tab.libraries); michael@0: widgetView.width = tab.libraries.length * ICON_WIDTH; michael@0: } michael@0: michael@0: var widget = widgets.Widget({ michael@0: id: "library-detector", michael@0: label: "Library Detector", michael@0: contentURL: data.url("widget.html"), michael@0: panel: panel.Panel({ michael@0: width: 240, michael@0: height: 60, michael@0: contentURL: data.url("panel.html") michael@0: }) michael@0: }); michael@0: michael@0: widget.port.on('setLibraryInfo', function(libraryInfo) { michael@0: widget.panel.postMessage(libraryInfo); michael@0: }); michael@0: michael@0: pageMod.PageMod({ michael@0: include: "*", michael@0: contentScriptWhen: 'end', michael@0: contentScriptFile: (data.url('library-detector.js')), michael@0: onAttach: function(worker) { michael@0: worker.on('message', function(libraryList) { michael@0: if (!worker.tab.libraries) { michael@0: worker.tab.libraries = []; michael@0: } michael@0: libraryList.forEach(function(library) { michael@0: if (worker.tab.libraries.indexOf(library) == -1) { michael@0: worker.tab.libraries.push(library); michael@0: } michael@0: }); michael@0: if (worker.tab == tabs.activeTab) { michael@0: updateWidgetView(worker.tab); michael@0: } michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: tabs.on('activate', function(tab) { michael@0: updateWidgetView(tab); michael@0: }); michael@0: michael@0: /* michael@0: For change of location michael@0: */ michael@0: tabs.on('ready', function(tab) { michael@0: tab.libraries = []; michael@0: });