summaryrefslogtreecommitdiffstats
path: root/mobile/android/components/TabSource.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /mobile/android/components/TabSource.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/components/TabSource.js')
-rw-r--r--mobile/android/components/TabSource.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/mobile/android/components/TabSource.js b/mobile/android/components/TabSource.js
new file mode 100644
index 000000000..c35a54438
--- /dev/null
+++ b/mobile/android/components/TabSource.js
@@ -0,0 +1,91 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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"
+
+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");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Prompt",
+ "resource://gre/modules/Prompt.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Messaging",
+ "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) {
+ let label;
+ if (tab.browser.contentTitle)
+ label = tab.browser.contentTitle;
+ else if (tab.browser.contentURI)
+ label = tab.browser.contentURI.spec;
+ else
+ label = tab.originalURI.spec;
+ return { label: label,
+ icon: "thumbnail:" + tab.id }
+ }));
+
+ 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) {
+ Messaging.sendRequest({ type: "Tab:StreamStart", tabID: tabs[i].id });
+ }
+ }
+ },
+
+ 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) {
+ Messaging.sendRequest({ type: "Tab:StreamStop", tabID: tabs[i].id });
+ }
+ }
+ }
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TabSource]);