2014-04-01 01:59:41 +00:00
|
|
|
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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"
|
|
|
|
|
2014-03-18 19:05:46 +00:00
|
|
|
const { classes: Cc, interfaces: Ci, manager: Cm, utils: Cu, results: Cr } = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Prompt.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "sendMessageToJava",
|
|
|
|
"resource://gre/modules/Messaging.jsm");
|
|
|
|
|
|
|
|
function TabSource() {
|
|
|
|
}
|
|
|
|
|
|
|
|
TabSource.prototype = {
|
|
|
|
classID: Components.ID("{5850c76e-b916-4218-b99a-31f004e0a7e7}"),
|
|
|
|
classDescription: "Fennec Tab Source",
|
|
|
|
contractID: "@mozilla.org/tab-source-service;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsITabSource]),
|
|
|
|
|
|
|
|
getTabToStream: function() {
|
|
|
|
let app = Services.wm.getMostRecentWindow("navigator:browser").BrowserApp;
|
|
|
|
let tabs = app.tabs;
|
|
|
|
if (tabs == null || tabs.length == 0) {
|
|
|
|
Services.console.logStringMessage("ERROR: No tabs");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
let title = bundle.GetStringFromName("tabshare.title")
|
|
|
|
|
|
|
|
let prompt = new Prompt({
|
|
|
|
title: title,
|
|
|
|
window: null
|
|
|
|
}).setSingleChoiceItems(tabs.map(function(tab) {
|
2014-04-02 18:32:30 +00:00
|
|
|
let label;
|
|
|
|
if (tab.browser.contentTitle)
|
|
|
|
label = tab.browser.contentTitle;
|
|
|
|
else if (tab.browser.contentURI && tab.browser.contentURI.spec)
|
|
|
|
label = tab.browser.contentURI.spec;
|
|
|
|
else
|
|
|
|
label = tab.originalURI;
|
2014-04-01 01:59:41 +00:00
|
|
|
return { label: label,
|
|
|
|
icon: "thumbnail:" + tab.id }
|
2014-03-18 19:05:46 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
let result = null;
|
|
|
|
prompt.show(function(data) {
|
|
|
|
result = data.button;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Spin this thread while we wait for a result.
|
|
|
|
let thread = Services.tm.currentThread;
|
|
|
|
while (result == null) {
|
|
|
|
thread.processNextEvent(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == -1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return tabs[result].browser.contentWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
notifyStreamStart: function(window) {
|
|
|
|
let app = Services.wm.getMostRecentWindow("navigator:browser").BrowserApp;
|
|
|
|
let tabs = app.tabs;
|
|
|
|
for (var i in tabs) {
|
|
|
|
if (tabs[i].browser.contentWindow == window) {
|
2014-04-02 18:32:30 +00:00
|
|
|
sendMessageToJava({ type: "Tab:StreamStart", tabID: tabs[i].id });
|
2014-03-18 19:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
notifyStreamStop: function(window) {
|
|
|
|
let app = Services.wm.getMostRecentWindow("navigator:browser").BrowserApp;
|
|
|
|
let tabs = app.tabs;
|
|
|
|
for (let i in tabs) {
|
|
|
|
if (tabs[i].browser.contentWindow == window) {
|
2014-04-02 18:32:30 +00:00
|
|
|
sendMessageToJava({ type: "Tab:StreamStop", tabID: tabs[i].id });
|
2014-03-18 19:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TabSource]);
|