mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-02 21:37:32 +09:00
Merge remote-tracking branch 'origin/master' into custom
This commit is contained in:
commit
c9f0b81b06
259 changed files with 14813 additions and 39387 deletions
|
|
@ -8,7 +8,6 @@ const {utils: Cu} = Components;
|
|||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeImageOptimizer",
|
||||
"resource://gre/modules/addons/LightweightThemeImageOptimizer.jsm");
|
||||
|
|
@ -148,12 +147,13 @@ LightweightThemeConsumer.prototype = {
|
|||
footer.removeAttribute("lwthemefooter");
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
// On OS X, we extend the lightweight theme into the titlebar, which means setting
|
||||
// the chromemargin attribute. Some XUL applications already draw in the titlebar,
|
||||
// so we need to save the chromemargin value before we overwrite it with the value
|
||||
// that lets us draw in the titlebar. We stash this value on the root attribute so
|
||||
// that XUL applications have the ability to invalidate the saved value.
|
||||
if (AppConstants.platform == "macosx" && stateChanging) {
|
||||
if (stateChanging) {
|
||||
if (!root.hasAttribute("chromemargin-nonlwtheme")) {
|
||||
root.setAttribute("chromemargin-nonlwtheme", root.getAttribute("chromemargin"));
|
||||
}
|
||||
|
|
@ -169,6 +169,7 @@ LightweightThemeConsumer.prototype = {
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Services.obs.notifyObservers(this._win, "lightweight-theme-window-updated",
|
||||
JSON.stringify(aData));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,21 @@ this.EXPORTED_SYMBOLS = ["ResetProfile"];
|
|||
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
// For Basilisk and Pale Moon
|
||||
// Hard-code MOZ_APP_NAME to firefox because of hard-coded type in migrator.
|
||||
const MOZ_APP_NAME = (((AppConstants.MOZ_APP_NAME == "basilisk")
|
||||
|| (AppConstants.MOZ_APP_NAME == "palemoon"))
|
||||
? "firefox" : AppConstants.MOZ_APP_NAME);
|
||||
const MOZ_BUILD_APP = AppConstants.MOZ_BUILD_APP;
|
||||
// We need to tell the migrator that many different applications are Mozilla applications
|
||||
#ifdef MOZ_PHOENIX
|
||||
const MOZ_APP_NAME = "firefox";
|
||||
const MOZ_BUILD_APP = "browser";
|
||||
#elifdef MOZ_THUNDERBIRD
|
||||
const MOZ_APP_NAME = "thunderbird";
|
||||
const MOZ_BUILD_APP = "mail";
|
||||
#elif defined(MOZ_SUITE) && !defined(BINOC_BOREALIS)
|
||||
const MOZ_APP_NAME = "seamonkey";
|
||||
const MOZ_BUILD_APP = "suite";
|
||||
#else
|
||||
#expand const MOZ_APP_NAME = "__MOZ_APP_NAME__";
|
||||
#expand const MOZ_BUILD_APP = "__MOZ_BUILD_APP__".match(/([^\/]*)\/*$/)[1];
|
||||
#endif
|
||||
|
||||
this.ResetProfile = {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ const Ci = Components.interfaces;
|
|||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
|
||||
Components.utils.import("resource://gre/modules/AppConstants.jsm");
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
this.Services = {};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ this.EXPORTED_SYMBOLS = ["UpdateUtils"];
|
|||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
|
@ -33,9 +32,8 @@ this.UpdateUtils = {
|
|||
* Whether or not to include the partner bits. Default: true.
|
||||
*/
|
||||
getUpdateChannel(aIncludePartners = true) {
|
||||
let channel = defaults.getCharPref("app.update.channel",
|
||||
AppConstants.MOZ_UPDATE_CHANNEL);
|
||||
let defaults = Services.prefs.getDefaultBranch(null);
|
||||
#expand let channel = defaults.getCharPref("app.update.channel", "__MOZ_UPDATE_CHANNEL__");
|
||||
|
||||
if (aIncludePartners) {
|
||||
try {
|
||||
|
|
@ -132,49 +130,48 @@ XPCOMUtils.defineLazyGetter(UpdateUtils, "Locale", function() {
|
|||
* Provides adhoc system capability information for application update.
|
||||
*/
|
||||
XPCOMUtils.defineLazyGetter(this, "gSystemCapabilities", function aus_gSC() {
|
||||
if (AppConstants.platform == "win") {
|
||||
const PF_MMX_INSTRUCTIONS_AVAILABLE = 3; // MMX
|
||||
const PF_XMMI_INSTRUCTIONS_AVAILABLE = 6; // SSE
|
||||
const PF_XMMI64_INSTRUCTIONS_AVAILABLE = 10; // SSE2
|
||||
const PF_SSE3_INSTRUCTIONS_AVAILABLE = 13; // SSE3
|
||||
#ifdef XP_WIN
|
||||
const PF_MMX_INSTRUCTIONS_AVAILABLE = 3; // MMX
|
||||
const PF_XMMI_INSTRUCTIONS_AVAILABLE = 6; // SSE
|
||||
const PF_XMMI64_INSTRUCTIONS_AVAILABLE = 10; // SSE2
|
||||
const PF_SSE3_INSTRUCTIONS_AVAILABLE = 13; // SSE3
|
||||
|
||||
let lib = ctypes.open("kernel32.dll");
|
||||
let IsProcessorFeaturePresent = lib.declare("IsProcessorFeaturePresent",
|
||||
ctypes.winapi_abi,
|
||||
ctypes.int32_t, /* success */
|
||||
ctypes.uint32_t); /* DWORD */
|
||||
let instructionSet = "unknown";
|
||||
try {
|
||||
if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) {
|
||||
instructionSet = "SSE3";
|
||||
} else if (IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE)) {
|
||||
instructionSet = "SSE2";
|
||||
} else if (IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE)) {
|
||||
instructionSet = "SSE";
|
||||
} else if (IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE)) {
|
||||
instructionSet = "MMX";
|
||||
}
|
||||
} catch (e) {
|
||||
instructionSet = "error";
|
||||
Cu.reportError("Error getting processor instruction set. " +
|
||||
"Exception: " + e);
|
||||
}
|
||||
|
||||
lib.close();
|
||||
return instructionSet;
|
||||
}
|
||||
|
||||
if (AppConstants == "linux") {
|
||||
let instructionSet = "unknown";
|
||||
if (navigator.cpuHasSSE2) {
|
||||
let lib = ctypes.open("kernel32.dll");
|
||||
let IsProcessorFeaturePresent = lib.declare("IsProcessorFeaturePresent",
|
||||
ctypes.winapi_abi,
|
||||
ctypes.int32_t, /* success */
|
||||
ctypes.uint32_t); /* DWORD */
|
||||
let instructionSet = "unknown";
|
||||
try {
|
||||
if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) {
|
||||
instructionSet = "SSE3";
|
||||
} else if (IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE)) {
|
||||
instructionSet = "SSE2";
|
||||
} else if (IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE)) {
|
||||
instructionSet = "SSE";
|
||||
} else if (IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE)) {
|
||||
instructionSet = "MMX";
|
||||
}
|
||||
return instructionSet;
|
||||
} catch (e) {
|
||||
instructionSet = "error";
|
||||
Cu.reportError("Error getting processor instruction set. " +
|
||||
"Exception: " + e);
|
||||
}
|
||||
|
||||
lib.close();
|
||||
return instructionSet;
|
||||
#elifdef XP_LINUX
|
||||
let instructionSet = "unknown";
|
||||
if (navigator.cpuHasSSE2) {
|
||||
instructionSet = "SSE2";
|
||||
}
|
||||
return instructionSet;
|
||||
#else
|
||||
return "NA"
|
||||
#endif
|
||||
});
|
||||
|
||||
#ifdef XP_WIN
|
||||
/* Windows only getter that returns the processor architecture. */
|
||||
XPCOMUtils.defineLazyGetter(this, "gWinCPUArch", function aus_gWinCPUArch() {
|
||||
// Get processor architecture
|
||||
|
|
@ -239,6 +236,7 @@ XPCOMUtils.defineLazyGetter(this, "gWinCPUArch", function aus_gWinCPUArch() {
|
|||
|
||||
return arch;
|
||||
});
|
||||
#endif
|
||||
|
||||
XPCOMUtils.defineLazyGetter(UpdateUtils, "ABI", function() {
|
||||
let abi = null;
|
||||
|
|
@ -249,19 +247,20 @@ XPCOMUtils.defineLazyGetter(UpdateUtils, "ABI", function() {
|
|||
Cu.reportError("XPCOM ABI unknown");
|
||||
}
|
||||
|
||||
if (AppConstants.platform == "macosx") {
|
||||
// Mac universal build should report a different ABI than either macppc
|
||||
// or mactel.
|
||||
let macutils = Cc["@mozilla.org/xpcom/mac-utils;1"].
|
||||
getService(Ci.nsIMacUtils);
|
||||
#ifdef XP_MACOSX
|
||||
// Mac universal build should report a different ABI than either macppc
|
||||
// or mactel.
|
||||
let macutils = Cc["@mozilla.org/xpcom/mac-utils;1"].
|
||||
getService(Ci.nsIMacUtils);
|
||||
|
||||
if (macutils.isUniversalBinary) {
|
||||
abi += "-u-" + macutils.architecturesInBinary;
|
||||
}
|
||||
} else if (AppConstants.platform == "win") {
|
||||
// Windows build should report the CPU architecture that it's running on.
|
||||
abi += "-" + gWinCPUArch;
|
||||
if (macutils.isUniversalBinary) {
|
||||
abi += "-u-" + macutils.architecturesInBinary;
|
||||
}
|
||||
#elifdef XP_WIN
|
||||
// Windows build should report the CPU architecture that it's running on.
|
||||
abi += "-" + gWinCPUArch;
|
||||
#endif
|
||||
|
||||
return abi;
|
||||
});
|
||||
|
||||
|
|
@ -275,95 +274,96 @@ XPCOMUtils.defineLazyGetter(UpdateUtils, "OSVersion", function() {
|
|||
Cu.reportError("OS Version unknown.");
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
if (osVersion) {
|
||||
if (AppConstants.platform == "win") {
|
||||
const BYTE = ctypes.uint8_t;
|
||||
const WORD = ctypes.uint16_t;
|
||||
const DWORD = ctypes.uint32_t;
|
||||
const WCHAR = ctypes.char16_t;
|
||||
const BOOL = ctypes.int;
|
||||
const BYTE = ctypes.uint8_t;
|
||||
const WORD = ctypes.uint16_t;
|
||||
const DWORD = ctypes.uint32_t;
|
||||
const WCHAR = ctypes.char16_t;
|
||||
const BOOL = ctypes.int;
|
||||
|
||||
// This structure is described at:
|
||||
// http://msdn.microsoft.com/en-us/library/ms724833%28v=vs.85%29.aspx
|
||||
const SZCSDVERSIONLENGTH = 128;
|
||||
const OSVERSIONINFOEXW = new ctypes.StructType('OSVERSIONINFOEXW',
|
||||
[
|
||||
{dwOSVersionInfoSize: DWORD},
|
||||
{dwMajorVersion: DWORD},
|
||||
{dwMinorVersion: DWORD},
|
||||
{dwBuildNumber: DWORD},
|
||||
{dwPlatformId: DWORD},
|
||||
{szCSDVersion: ctypes.ArrayType(WCHAR, SZCSDVERSIONLENGTH)},
|
||||
{wServicePackMajor: WORD},
|
||||
{wServicePackMinor: WORD},
|
||||
{wSuiteMask: WORD},
|
||||
{wProductType: BYTE},
|
||||
{wReserved: BYTE}
|
||||
]);
|
||||
// This structure is described at:
|
||||
// http://msdn.microsoft.com/en-us/library/ms724833%28v=vs.85%29.aspx
|
||||
const SZCSDVERSIONLENGTH = 128;
|
||||
const OSVERSIONINFOEXW = new ctypes.StructType('OSVERSIONINFOEXW',
|
||||
[
|
||||
{dwOSVersionInfoSize: DWORD},
|
||||
{dwMajorVersion: DWORD},
|
||||
{dwMinorVersion: DWORD},
|
||||
{dwBuildNumber: DWORD},
|
||||
{dwPlatformId: DWORD},
|
||||
{szCSDVersion: ctypes.ArrayType(WCHAR, SZCSDVERSIONLENGTH)},
|
||||
{wServicePackMajor: WORD},
|
||||
{wServicePackMinor: WORD},
|
||||
{wSuiteMask: WORD},
|
||||
{wProductType: BYTE},
|
||||
{wReserved: BYTE}
|
||||
]);
|
||||
|
||||
// This structure is described at:
|
||||
// http://msdn.microsoft.com/en-us/library/ms724958%28v=vs.85%29.aspx
|
||||
const SYSTEM_INFO = new ctypes.StructType('SYSTEM_INFO',
|
||||
[
|
||||
{wProcessorArchitecture: WORD},
|
||||
{wReserved: WORD},
|
||||
{dwPageSize: DWORD},
|
||||
{lpMinimumApplicationAddress: ctypes.voidptr_t},
|
||||
{lpMaximumApplicationAddress: ctypes.voidptr_t},
|
||||
{dwActiveProcessorMask: DWORD.ptr},
|
||||
{dwNumberOfProcessors: DWORD},
|
||||
{dwProcessorType: DWORD},
|
||||
{dwAllocationGranularity: DWORD},
|
||||
{wProcessorLevel: WORD},
|
||||
{wProcessorRevision: WORD}
|
||||
]);
|
||||
// This structure is described at:
|
||||
// http://msdn.microsoft.com/en-us/library/ms724958%28v=vs.85%29.aspx
|
||||
const SYSTEM_INFO = new ctypes.StructType('SYSTEM_INFO',
|
||||
[
|
||||
{wProcessorArchitecture: WORD},
|
||||
{wReserved: WORD},
|
||||
{dwPageSize: DWORD},
|
||||
{lpMinimumApplicationAddress: ctypes.voidptr_t},
|
||||
{lpMaximumApplicationAddress: ctypes.voidptr_t},
|
||||
{dwActiveProcessorMask: DWORD.ptr},
|
||||
{dwNumberOfProcessors: DWORD},
|
||||
{dwProcessorType: DWORD},
|
||||
{dwAllocationGranularity: DWORD},
|
||||
{wProcessorLevel: WORD},
|
||||
{wProcessorRevision: WORD}
|
||||
]);
|
||||
|
||||
let kernel32 = false;
|
||||
let kernel32 = false;
|
||||
try {
|
||||
kernel32 = ctypes.open("Kernel32");
|
||||
} catch (e) {
|
||||
Cu.reportError("Unable to open kernel32! " + e);
|
||||
osVersion += ".unknown (unknown)";
|
||||
}
|
||||
|
||||
if (kernel32) {
|
||||
try {
|
||||
kernel32 = ctypes.open("Kernel32");
|
||||
} catch (e) {
|
||||
Cu.reportError("Unable to open kernel32! " + e);
|
||||
osVersion += ".unknown (unknown)";
|
||||
}
|
||||
|
||||
if (kernel32) {
|
||||
// Get Service pack info
|
||||
try {
|
||||
// Get Service pack info
|
||||
try {
|
||||
let GetVersionEx = kernel32.declare("GetVersionExW",
|
||||
ctypes.default_abi,
|
||||
BOOL,
|
||||
OSVERSIONINFOEXW.ptr);
|
||||
let winVer = OSVERSIONINFOEXW();
|
||||
winVer.dwOSVersionInfoSize = OSVERSIONINFOEXW.size;
|
||||
let GetVersionEx = kernel32.declare("GetVersionExW",
|
||||
ctypes.default_abi,
|
||||
BOOL,
|
||||
OSVERSIONINFOEXW.ptr);
|
||||
let winVer = OSVERSIONINFOEXW();
|
||||
winVer.dwOSVersionInfoSize = OSVERSIONINFOEXW.size;
|
||||
|
||||
if (0 !== GetVersionEx(winVer.address())) {
|
||||
osVersion += "." + winVer.wServicePackMajor +
|
||||
"." + winVer.wServicePackMinor;
|
||||
} else {
|
||||
Cu.reportError("Unknown failure in GetVersionEX (returned 0)");
|
||||
osVersion += ".unknown";
|
||||
}
|
||||
} catch (e) {
|
||||
Cu.reportError("Error getting service pack information. Exception: " + e);
|
||||
if (0 !== GetVersionEx(winVer.address())) {
|
||||
osVersion += "." + winVer.wServicePackMajor +
|
||||
"." + winVer.wServicePackMinor;
|
||||
} else {
|
||||
Cu.reportError("Unknown failure in GetVersionEX (returned 0)");
|
||||
osVersion += ".unknown";
|
||||
}
|
||||
} finally {
|
||||
kernel32.close();
|
||||
} catch (e) {
|
||||
Cu.reportError("Error getting service pack information. Exception: " + e);
|
||||
osVersion += ".unknown";
|
||||
}
|
||||
|
||||
// Add processor architecture
|
||||
osVersion += " (" + gWinCPUArch + ")";
|
||||
} finally {
|
||||
kernel32.close();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
osVersion += " (" + Services.sysinfo.getProperty("secondaryLibrary") + ")";
|
||||
// Add processor architecture
|
||||
osVersion += " (" + gWinCPUArch + ")";
|
||||
}
|
||||
catch (e) {
|
||||
// Not all platforms have a secondary widget library, so an error is nothing to worry about.
|
||||
}
|
||||
osVersion = encodeURIComponent(osVersion);
|
||||
}
|
||||
|
||||
try {
|
||||
osVersion += " (" + Services.sysinfo.getProperty("secondaryLibrary") + ")";
|
||||
}
|
||||
catch (e) {
|
||||
// Not all platforms have a secondary widget library, so an error is nothing to worry about.
|
||||
}
|
||||
osVersion = encodeURIComponent(osVersion);
|
||||
#endif
|
||||
|
||||
return osVersion;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
* 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/. */
|
||||
|
||||
Components.utils.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
const HAVE_CSS_WINDOW_DRAG_SUPPORT = ["win", "macosx"].includes(AppConstants.platform);
|
||||
#if defined(XP_WIN) || defined(XP_MACOSX)
|
||||
const HAVE_CSS_WINDOW_DRAG_SUPPORT = true;
|
||||
#else
|
||||
const HAVE_CSS_WINDOW_DRAG_SUPPORT = false;
|
||||
#endif
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ "WindowDraggingElement" ];
|
||||
|
||||
|
|
@ -62,12 +64,13 @@ WindowDraggingElement.prototype = {
|
|||
if (!this.shouldDrag(aEvent))
|
||||
return;
|
||||
|
||||
if (/^gtk/i.test(AppConstants.MOZ_WIDGET_TOOLKIT)) {
|
||||
// On GTK, there is a toolkit-level function which handles
|
||||
// window dragging, which must be used.
|
||||
this._window.beginWindowMove(aEvent, isPanel ? this._elem : null);
|
||||
break;
|
||||
}
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
// On GTK, there is a toolkit-level function which handles
|
||||
// window dragging, which must be used.
|
||||
this._window.beginWindowMove(aEvent, isPanel ? this._elem : null);
|
||||
break;
|
||||
#endif
|
||||
|
||||
if (isPanel) {
|
||||
let screenRect = this._elem.getOuterScreenRect();
|
||||
this._deltaX = aEvent.screenX - screenRect.left;
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ Cu.import("resource://gre/modules/Services.jsm");
|
|||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
|
||||
"resource://gre/modules/AppConstants.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
|
||||
"resource://gre/modules/BrowserUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ExtensionUtils",
|
||||
|
|
@ -846,9 +844,9 @@ var onBeforeRequest = {
|
|||
get allowedOptions() {
|
||||
delete this.allowedOptions;
|
||||
this.allowedOptions = ["blocking"];
|
||||
if (!AppConstants.RELEASE_OR_BETA) {
|
||||
this.allowedOptions.push("requestBody");
|
||||
}
|
||||
#ifndef RELEASE_OR_BETA
|
||||
this.allowedOptions.push("requestBody");
|
||||
#endif
|
||||
return this.allowedOptions;
|
||||
},
|
||||
addListener(callback, filter = null, opt_extraInfoSpec = null) {
|
||||
|
|
|
|||
|
|
@ -74,11 +74,7 @@ EXTRA_JS_MODULES += [
|
|||
'RemotePageManager.jsm',
|
||||
'RemoteSecurityUI.jsm',
|
||||
'RemoteWebProgress.jsm',
|
||||
'ResetProfile.jsm',
|
||||
'ResponsivenessMonitor.jsm',
|
||||
'secondscreen/PresentationApp.jsm',
|
||||
'secondscreen/RokuApp.jsm',
|
||||
'secondscreen/SimpleServiceDiscovery.jsm',
|
||||
'SelectContentHelper.jsm',
|
||||
'SelectParentHelper.jsm',
|
||||
'ServiceRequest.jsm',
|
||||
|
|
@ -93,7 +89,6 @@ EXTRA_JS_MODULES += [
|
|||
'Task.jsm',
|
||||
'Timer.jsm',
|
||||
'WebChannel.jsm',
|
||||
'WindowDraggingUtils.jsm',
|
||||
'ZipUtils.jsm',
|
||||
]
|
||||
EXTRA_JS_MODULES.third_party.jsesc += ['third_party/jsesc/jsesc.js']
|
||||
|
|
@ -101,8 +96,10 @@ EXTRA_JS_MODULES.sessionstore += ['sessionstore/Utils.jsm']
|
|||
|
||||
EXTRA_PP_JS_MODULES += [
|
||||
'NewTabUtils.jsm',
|
||||
'ResetProfile.jsm',
|
||||
'Troubleshoot.jsm',
|
||||
'UpdateUtils.jsm',
|
||||
'WindowDraggingUtils.jsm',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'cocoa'):
|
||||
|
|
@ -120,7 +117,7 @@ EXTRA_PP_JS_MODULES += [
|
|||
]
|
||||
|
||||
if 'Android' != CONFIG['OS_TARGET']:
|
||||
EXTRA_JS_MODULES += [
|
||||
EXTRA_PP_JS_MODULES += [
|
||||
'LightweightThemeConsumer.jsm',
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,190 +0,0 @@
|
|||
// -*- 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";
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["PresentationApp"];
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "sysInfo", () => {
|
||||
return Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
|
||||
});
|
||||
|
||||
const DEBUG = false;
|
||||
|
||||
const STATE_UNINIT = "uninitialized" // RemoteMedia status
|
||||
const STATE_STARTED = "started"; // RemoteMedia status
|
||||
const STATE_PAUSED = "paused"; // RemoteMedia status
|
||||
const STATE_SHUTDOWN = "shutdown"; // RemoteMedia status
|
||||
|
||||
function debug(msg) {
|
||||
Services.console.logStringMessage("PresentationApp: " + msg);
|
||||
}
|
||||
|
||||
// PresentationApp is a wrapper for interacting with a Presentation Receiver Device.
|
||||
function PresentationApp(service, request) {
|
||||
this.service = service;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
PresentationApp.prototype = {
|
||||
start: function start(callback) {
|
||||
this.request.startWithDevice(this.service.uuid)
|
||||
.then((session) => {
|
||||
this._session = session;
|
||||
if (callback) {
|
||||
session.addEventListener('connect', () => {
|
||||
callback(true);
|
||||
});
|
||||
}
|
||||
}, () => {
|
||||
if (callback) {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
stop: function stop(callback) {
|
||||
if (this._session && this._session.state === "connected") {
|
||||
this._session.terminate();
|
||||
}
|
||||
|
||||
delete this._session;
|
||||
|
||||
if (callback) {
|
||||
callback(true);
|
||||
}
|
||||
},
|
||||
|
||||
remoteMedia: function remoteMedia(callback, listener) {
|
||||
if (callback) {
|
||||
if (!this._session) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
callback(new RemoteMedia(this._session, listener));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* RemoteMedia provides a wrapper for using Presentation API to control Firefox TV app.
|
||||
* The server implementation must be built into the Firefox TV receiver app.
|
||||
* see https://github.com/mozilla-b2g/gaia/tree/master/tv_apps/fling-player
|
||||
*/
|
||||
function RemoteMedia(session, listener) {
|
||||
this._session = session ;
|
||||
this._listener = listener;
|
||||
this._status = STATE_UNINIT;
|
||||
|
||||
this._session.addEventListener("message", this);
|
||||
this._session.addEventListener("terminate", this);
|
||||
|
||||
if (this._listener && "onRemoteMediaStart" in this._listener) {
|
||||
Services.tm.mainThread.dispatch((function() {
|
||||
this._listener.onRemoteMediaStart(this);
|
||||
}).bind(this), Ci.nsIThread.DISPATCH_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
RemoteMedia.prototype = {
|
||||
_seq: 0,
|
||||
|
||||
handleEvent: function(e) {
|
||||
switch (e.type) {
|
||||
case "message":
|
||||
this._onmessage(e);
|
||||
break;
|
||||
case "terminate":
|
||||
this._onterminate(e);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
_onmessage: function(e) {
|
||||
DEBUG && debug("onmessage: " + e.data);
|
||||
if (this.status === STATE_SHUTDOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.data.indexOf("stopped") > -1) {
|
||||
if (this.status !== STATE_PAUSED) {
|
||||
this._status = STATE_PAUSED;
|
||||
if (this._listener && "onRemoteMediaStatus" in this._listener) {
|
||||
this._listener.onRemoteMediaStatus(this);
|
||||
}
|
||||
}
|
||||
} else if (e.data.indexOf("playing") > -1) {
|
||||
if (this.status !== STATE_STARTED) {
|
||||
this._status = STATE_STARTED;
|
||||
if (this._listener && "onRemoteMediaStatus" in this._listener) {
|
||||
this._listener.onRemoteMediaStatus(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_onterminate: function(e) {
|
||||
DEBUG && debug("onterminate: " + this._session.state);
|
||||
this._status = STATE_SHUTDOWN;
|
||||
if (this._listener && "onRemoteMediaStop" in this._listener) {
|
||||
this._listener.onRemoteMediaStop(this);
|
||||
}
|
||||
},
|
||||
|
||||
_sendCommand: function(command, data) {
|
||||
let msg = {
|
||||
'type': command,
|
||||
'seq': ++this._seq
|
||||
};
|
||||
|
||||
if (data) {
|
||||
for (var k in data) {
|
||||
msg[k] = data[k];
|
||||
}
|
||||
}
|
||||
|
||||
let raw = JSON.stringify(msg);
|
||||
DEBUG && debug("send command: " + raw);
|
||||
|
||||
this._session.send(raw);
|
||||
},
|
||||
|
||||
shutdown: function shutdown() {
|
||||
DEBUG && debug("RemoteMedia - shutdown");
|
||||
this._sendCommand("close");
|
||||
},
|
||||
|
||||
play: function play() {
|
||||
DEBUG && debug("RemoteMedia - play");
|
||||
this._sendCommand("play");
|
||||
},
|
||||
|
||||
pause: function pause() {
|
||||
DEBUG && debug("RemoteMedia - pause");
|
||||
this._sendCommand("pause");
|
||||
},
|
||||
|
||||
load: function load(data) {
|
||||
DEBUG && debug("RemoteMedia - load: " + data);
|
||||
this._sendCommand("load", { "url": data.source });
|
||||
|
||||
let deviceName;
|
||||
if (Services.appinfo.widgetToolkit == "android") {
|
||||
deviceName = sysInfo.get("device");
|
||||
} else {
|
||||
deviceName = sysInfo.get("host");
|
||||
}
|
||||
this._sendCommand("device-info", { "displayName": deviceName });
|
||||
},
|
||||
|
||||
get status() {
|
||||
return this._status;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,230 +0,0 @@
|
|||
// -*- 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";
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["RokuApp"];
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
function log(msg) {
|
||||
// Services.console.logStringMessage(msg);
|
||||
}
|
||||
|
||||
const PROTOCOL_VERSION = 1;
|
||||
|
||||
/* RokuApp is a wrapper for interacting with a Roku channel.
|
||||
* The basic interactions all use a REST API.
|
||||
* spec: http://sdkdocs.roku.com/display/sdkdoc/External+Control+Guide
|
||||
*/
|
||||
function RokuApp(service) {
|
||||
this.service = service;
|
||||
this.resourceURL = this.service.location;
|
||||
this.app = AppConstants.RELEASE_OR_BETA ? "Firefox" : "Firefox Nightly";
|
||||
this.mediaAppID = -1;
|
||||
}
|
||||
|
||||
RokuApp.prototype = {
|
||||
status: function status(callback) {
|
||||
// We have no way to know if the app is running, so just return "unknown"
|
||||
// but we use this call to fetch the mediaAppID for the given app name
|
||||
let url = this.resourceURL + "query/apps";
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.open("GET", url, true);
|
||||
xhr.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
|
||||
xhr.overrideMimeType("text/xml");
|
||||
|
||||
xhr.addEventListener("load", (function() {
|
||||
if (xhr.status == 200) {
|
||||
let doc = xhr.responseXML;
|
||||
let apps = doc.querySelectorAll("app");
|
||||
for (let app of apps) {
|
||||
if (app.textContent == this.app) {
|
||||
this.mediaAppID = app.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Since ECP has no way of telling us if an app is running, we always return "unknown"
|
||||
if (callback) {
|
||||
callback({ state: "unknown" });
|
||||
}
|
||||
}).bind(this), false);
|
||||
|
||||
xhr.addEventListener("error", (function() {
|
||||
if (callback) {
|
||||
callback({ state: "unknown" });
|
||||
}
|
||||
}).bind(this), false);
|
||||
|
||||
xhr.send(null);
|
||||
},
|
||||
|
||||
start: function start(callback) {
|
||||
// We need to make sure we have cached the mediaAppID
|
||||
if (this.mediaAppID == -1) {
|
||||
this.status(function() {
|
||||
// If we found the mediaAppID, use it to make a new start call
|
||||
if (this.mediaAppID != -1) {
|
||||
this.start(callback);
|
||||
} else {
|
||||
// We failed to start the app, so let the caller know
|
||||
callback(false);
|
||||
}
|
||||
}.bind(this));
|
||||
return;
|
||||
}
|
||||
|
||||
// Start a given app with any extra query data. Each app uses it's own data scheme.
|
||||
// NOTE: Roku will also pass "source=external-control" as a param
|
||||
let url = this.resourceURL + "launch/" + this.mediaAppID + "?version=" + parseInt(PROTOCOL_VERSION);
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.open("POST", url, true);
|
||||
xhr.overrideMimeType("text/plain");
|
||||
|
||||
xhr.addEventListener("load", (function() {
|
||||
if (callback) {
|
||||
callback(xhr.status === 200);
|
||||
}
|
||||
}).bind(this), false);
|
||||
|
||||
xhr.addEventListener("error", (function() {
|
||||
if (callback) {
|
||||
callback(false);
|
||||
}
|
||||
}).bind(this), false);
|
||||
|
||||
xhr.send(null);
|
||||
},
|
||||
|
||||
stop: function stop(callback) {
|
||||
// Roku doesn't seem to support stopping an app, so let's just go back to
|
||||
// the Home screen
|
||||
let url = this.resourceURL + "keypress/Home";
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.open("POST", url, true);
|
||||
xhr.overrideMimeType("text/plain");
|
||||
|
||||
xhr.addEventListener("load", (function() {
|
||||
if (callback) {
|
||||
callback(xhr.status === 200);
|
||||
}
|
||||
}).bind(this), false);
|
||||
|
||||
xhr.addEventListener("error", (function() {
|
||||
if (callback) {
|
||||
callback(false);
|
||||
}
|
||||
}).bind(this), false);
|
||||
|
||||
xhr.send(null);
|
||||
},
|
||||
|
||||
remoteMedia: function remoteMedia(callback, listener) {
|
||||
if (this.mediaAppID != -1) {
|
||||
if (callback) {
|
||||
callback(new RemoteMedia(this.resourceURL, listener));
|
||||
}
|
||||
} else if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* RemoteMedia provides a wrapper for using TCP socket to control Roku apps.
|
||||
* The server implementation must be built into the Roku receiver app.
|
||||
*/
|
||||
function RemoteMedia(url, listener) {
|
||||
this._url = url;
|
||||
this._listener = listener;
|
||||
this._status = "uninitialized";
|
||||
|
||||
let serverURI = Services.io.newURI(this._url, null, null);
|
||||
this._socket = Cc["@mozilla.org/network/socket-transport-service;1"].getService(Ci.nsISocketTransportService).createTransport(null, 0, serverURI.host, 9191, null);
|
||||
this._outputStream = this._socket.openOutputStream(0, 0, 0);
|
||||
|
||||
this._scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
|
||||
|
||||
this._inputStream = this._socket.openInputStream(0, 0, 0);
|
||||
this._pump = Cc["@mozilla.org/network/input-stream-pump;1"].createInstance(Ci.nsIInputStreamPump);
|
||||
this._pump.init(this._inputStream, -1, -1, 0, 0, true);
|
||||
this._pump.asyncRead(this, null);
|
||||
}
|
||||
|
||||
RemoteMedia.prototype = {
|
||||
onStartRequest: function(request, context) {
|
||||
},
|
||||
|
||||
onDataAvailable: function(request, context, stream, offset, count) {
|
||||
this._scriptableStream.init(stream);
|
||||
let data = this._scriptableStream.read(count);
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
let msg = JSON.parse(data);
|
||||
if (this._status === msg._s) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._status = msg._s;
|
||||
|
||||
if (this._listener) {
|
||||
// Check to see if we are getting the initial "connected" message
|
||||
if (this._status == "connected" && "onRemoteMediaStart" in this._listener) {
|
||||
this._listener.onRemoteMediaStart(this);
|
||||
}
|
||||
|
||||
if ("onRemoteMediaStatus" in this._listener) {
|
||||
this._listener.onRemoteMediaStatus(this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, result) {
|
||||
if (this._listener && "onRemoteMediaStop" in this._listener)
|
||||
this._listener.onRemoteMediaStop(this);
|
||||
},
|
||||
|
||||
_sendMsg: function _sendMsg(data) {
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
// Add the protocol version
|
||||
data["_v"] = PROTOCOL_VERSION;
|
||||
|
||||
let raw = JSON.stringify(data);
|
||||
this._outputStream.write(raw, raw.length);
|
||||
},
|
||||
|
||||
shutdown: function shutdown() {
|
||||
this._outputStream.close();
|
||||
this._inputStream.close();
|
||||
},
|
||||
|
||||
get active() {
|
||||
return (this._socket && this._socket.isAlive());
|
||||
},
|
||||
|
||||
play: function play() {
|
||||
// TODO: add position support
|
||||
this._sendMsg({ type: "PLAY" });
|
||||
},
|
||||
|
||||
pause: function pause() {
|
||||
this._sendMsg({ type: "STOP" });
|
||||
},
|
||||
|
||||
load: function load(data) {
|
||||
this._sendMsg({ type: "LOAD", title: data.title, source: data.source, poster: data.poster });
|
||||
},
|
||||
|
||||
get status() {
|
||||
return this._status;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,432 +0,0 @@
|
|||
// -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
||||
/* 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";
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["SimpleServiceDiscovery"];
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Timer.jsm");
|
||||
|
||||
var log = Cu.reportError;
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "converter", function () {
|
||||
let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
conv.charset = "utf8";
|
||||
return conv;
|
||||
});
|
||||
|
||||
// Spec information:
|
||||
// https://tools.ietf.org/html/draft-cai-ssdp-v1-03
|
||||
// http://www.dial-multiscreen.org/dial-protocol-specification
|
||||
const SSDP_PORT = 1900;
|
||||
const SSDP_ADDRESS = "239.255.255.250";
|
||||
|
||||
const SSDP_DISCOVER_PACKET =
|
||||
"M-SEARCH * HTTP/1.1\r\n" +
|
||||
"HOST: " + SSDP_ADDRESS + ":" + SSDP_PORT + "\r\n" +
|
||||
"MAN: \"ssdp:discover\"\r\n" +
|
||||
"MX: 2\r\n" +
|
||||
"ST: %SEARCH_TARGET%\r\n\r\n";
|
||||
|
||||
const SSDP_DISCOVER_ATTEMPTS = 3;
|
||||
const SSDP_DISCOVER_DELAY = 500;
|
||||
const SSDP_DISCOVER_TIMEOUT_MULTIPLIER = 2;
|
||||
const SSDP_TRANSMISSION_INTERVAL = 1000;
|
||||
|
||||
const EVENT_SERVICE_FOUND = "ssdp-service-found";
|
||||
const EVENT_SERVICE_LOST = "ssdp-service-lost";
|
||||
|
||||
/*
|
||||
* SimpleServiceDiscovery manages any discovered SSDP services. It uses a UDP
|
||||
* broadcast to locate available services on the local network.
|
||||
*/
|
||||
var SimpleServiceDiscovery = {
|
||||
get EVENT_SERVICE_FOUND() { return EVENT_SERVICE_FOUND; },
|
||||
get EVENT_SERVICE_LOST() { return EVENT_SERVICE_LOST; },
|
||||
|
||||
_devices: new Map(),
|
||||
_services: new Map(),
|
||||
_searchSocket: null,
|
||||
_searchInterval: 0,
|
||||
_searchTimestamp: 0,
|
||||
_searchTimeout: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
|
||||
_searchRepeat: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
|
||||
_discoveryMethods: [],
|
||||
|
||||
_forceTrailingSlash: function(aURL) {
|
||||
// Cleanup the URL to make it consistent across devices
|
||||
try {
|
||||
aURL = Services.io.newURI(aURL, null, null).spec;
|
||||
} catch (e) {}
|
||||
return aURL;
|
||||
},
|
||||
|
||||
// nsIUDPSocketListener implementation
|
||||
onPacketReceived: function(aSocket, aMessage) {
|
||||
// Listen for responses from specific devices. There could be more than one
|
||||
// available.
|
||||
let response = aMessage.data.split("\n");
|
||||
let service = {};
|
||||
response.forEach(function(row) {
|
||||
let name = row.toUpperCase();
|
||||
if (name.startsWith("LOCATION")) {
|
||||
service.location = row.substr(10).trim();
|
||||
} else if (name.startsWith("ST")) {
|
||||
service.target = row.substr(4).trim();
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
if (service.location && service.target) {
|
||||
service.location = this._forceTrailingSlash(service.location);
|
||||
|
||||
// When we find a valid response, package up the service information
|
||||
// and pass it on.
|
||||
try {
|
||||
this._processService(service);
|
||||
} catch (e) {}
|
||||
}
|
||||
},
|
||||
|
||||
onStopListening: function(aSocket, aStatus) {
|
||||
// This is fired when the socket is closed expectedly or unexpectedly.
|
||||
// nsITimer.cancel() is a no-op if the timer is not active.
|
||||
this._searchTimeout.cancel();
|
||||
this._searchSocket = null;
|
||||
},
|
||||
|
||||
// Start a search. Make it continuous by passing an interval (in milliseconds).
|
||||
// This will stop a current search loop because the timer resets itself.
|
||||
// Returns the existing search interval.
|
||||
search: function search(aInterval) {
|
||||
let existingSearchInterval = this._searchInterval;
|
||||
if (aInterval > 0) {
|
||||
this._searchInterval = aInterval || 0;
|
||||
this._searchRepeat.initWithCallback(this._search.bind(this), this._searchInterval, Ci.nsITimer.TYPE_REPEATING_SLACK);
|
||||
}
|
||||
this._search();
|
||||
return existingSearchInterval;
|
||||
},
|
||||
|
||||
// Stop the current continuous search
|
||||
stopSearch: function stopSearch() {
|
||||
this._searchRepeat.cancel();
|
||||
},
|
||||
|
||||
_usingLAN: function() {
|
||||
let network = Cc["@mozilla.org/network/network-link-service;1"].getService(Ci.nsINetworkLinkService);
|
||||
return (network.linkType == Ci.nsINetworkLinkService.LINK_TYPE_WIFI ||
|
||||
network.linkType == Ci.nsINetworkLinkService.LINK_TYPE_ETHERNET ||
|
||||
network.linkType == Ci.nsINetworkLinkService.LINK_TYPE_UNKNOWN);
|
||||
},
|
||||
|
||||
_search: function _search() {
|
||||
// If a search is already active, shut it down.
|
||||
this._searchShutdown();
|
||||
|
||||
// We only search if on local network
|
||||
if (!this._usingLAN()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the timestamp so we can use it to clean out stale services the
|
||||
// next time we search.
|
||||
this._searchTimestamp = Date.now();
|
||||
|
||||
// Look for any fixed IP devices. Some routers might be configured to block
|
||||
// UDP broadcasts, so this is a way to skip discovery.
|
||||
this._searchFixedDevices();
|
||||
|
||||
// Look for any devices via registered external discovery mechanism.
|
||||
this._startExternalDiscovery();
|
||||
|
||||
// Perform a UDP broadcast to search for SSDP devices
|
||||
let socket = Cc["@mozilla.org/network/udp-socket;1"].createInstance(Ci.nsIUDPSocket);
|
||||
try {
|
||||
socket.init(SSDP_PORT, false, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
socket.joinMulticast(SSDP_ADDRESS);
|
||||
socket.asyncListen(this);
|
||||
} catch (e) {
|
||||
// We were unable to create the broadcast socket. Just return, but don't
|
||||
// kill the interval timer. This might work next time.
|
||||
log("failed to start socket: " + e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make the timeout SSDP_DISCOVER_TIMEOUT_MULTIPLIER times as long as the time needed to send out the discovery packets.
|
||||
const SSDP_DISCOVER_TIMEOUT = this._devices.size * SSDP_DISCOVER_ATTEMPTS * SSDP_TRANSMISSION_INTERVAL * SSDP_DISCOVER_TIMEOUT_MULTIPLIER;
|
||||
this._searchSocket = socket;
|
||||
this._searchTimeout.initWithCallback(this._searchShutdown.bind(this), SSDP_DISCOVER_TIMEOUT, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
|
||||
let data = SSDP_DISCOVER_PACKET;
|
||||
|
||||
// Send discovery packets out at 1 per SSDP_TRANSMISSION_INTERVAL and send each SSDP_DISCOVER_ATTEMPTS times
|
||||
// to allow for packet loss on noisy networks.
|
||||
let timeout = SSDP_DISCOVER_DELAY;
|
||||
for (let attempts = 0; attempts < SSDP_DISCOVER_ATTEMPTS; attempts++) {
|
||||
for (let [key, device] of this._devices) {
|
||||
let target = device.target;
|
||||
setTimeout(function() {
|
||||
let msgData = data.replace("%SEARCH_TARGET%", target);
|
||||
try {
|
||||
let msgRaw = converter.convertToByteArray(msgData);
|
||||
socket.send(SSDP_ADDRESS, SSDP_PORT, msgRaw, msgRaw.length);
|
||||
} catch (e) {
|
||||
log("failed to convert to byte array: " + e);
|
||||
}
|
||||
}, timeout);
|
||||
timeout += SSDP_TRANSMISSION_INTERVAL;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_searchFixedDevices: function _searchFixedDevices() {
|
||||
let fixedDevices = Services.prefs.getCharPref("browser.casting.fixedDevices", "");
|
||||
|
||||
if (!fixedDevices) {
|
||||
return;
|
||||
}
|
||||
|
||||
fixedDevices = JSON.parse(fixedDevices);
|
||||
for (let fixedDevice of fixedDevices) {
|
||||
// Verify we have the right data
|
||||
if (!("location" in fixedDevice) || !("target" in fixedDevice)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fixedDevice.location = this._forceTrailingSlash(fixedDevice.location);
|
||||
|
||||
let service = {
|
||||
location: fixedDevice.location,
|
||||
target: fixedDevice.target
|
||||
};
|
||||
|
||||
// We don't assume the fixed target is ready. We still need to ping it.
|
||||
try {
|
||||
this._processService(service);
|
||||
} catch (e) {}
|
||||
}
|
||||
},
|
||||
|
||||
// Called when the search timeout is hit. We use it to cleanup the socket and
|
||||
// perform some post-processing on the services list.
|
||||
_searchShutdown: function _searchShutdown() {
|
||||
if (this._searchSocket) {
|
||||
// This will call onStopListening.
|
||||
this._searchSocket.close();
|
||||
|
||||
// Clean out any stale services
|
||||
for (let [key, service] of this._services) {
|
||||
if (service.lastPing != this._searchTimestamp) {
|
||||
this.removeService(service.uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._stopExternalDiscovery();
|
||||
},
|
||||
|
||||
getSupportedExtensions: function() {
|
||||
let extensions = [];
|
||||
this.services.forEach(function(service) {
|
||||
extensions = extensions.concat(service.extensions);
|
||||
}, this);
|
||||
return extensions.filter(function(extension, pos) {
|
||||
return extensions.indexOf(extension) == pos;
|
||||
});
|
||||
},
|
||||
|
||||
getSupportedMimeTypes: function() {
|
||||
let types = [];
|
||||
this.services.forEach(function(service) {
|
||||
types = types.concat(service.types);
|
||||
}, this);
|
||||
return types.filter(function(type, pos) {
|
||||
return types.indexOf(type) == pos;
|
||||
});
|
||||
},
|
||||
|
||||
registerDevice: function registerDevice(aDevice) {
|
||||
// We must have "id", "target" and "factory" defined
|
||||
if (!("id" in aDevice) || !("target" in aDevice) || !("factory" in aDevice)) {
|
||||
// Fatal for registration
|
||||
throw "Registration requires an id, a target and a location";
|
||||
}
|
||||
|
||||
// Only add if we don't already know about this device
|
||||
if (!this._devices.has(aDevice.id)) {
|
||||
this._devices.set(aDevice.id, aDevice);
|
||||
} else {
|
||||
log("device was already registered: " + aDevice.id);
|
||||
}
|
||||
},
|
||||
|
||||
unregisterDevice: function unregisterDevice(aDevice) {
|
||||
// We must have "id", "target" and "factory" defined
|
||||
if (!("id" in aDevice) || !("target" in aDevice) || !("factory" in aDevice)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only remove if we know about this device
|
||||
if (this._devices.has(aDevice.id)) {
|
||||
this._devices.delete(aDevice.id);
|
||||
} else {
|
||||
log("device was not registered: " + aDevice.id);
|
||||
}
|
||||
},
|
||||
|
||||
findAppForService: function findAppForService(aService) {
|
||||
if (!aService || !aService.deviceID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Find the registration for the device
|
||||
if (this._devices.has(aService.deviceID)) {
|
||||
return this._devices.get(aService.deviceID).factory(aService);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
findServiceForID: function findServiceForID(aUUID) {
|
||||
if (this._services.has(aUUID)) {
|
||||
return this._services.get(aUUID);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// Returns an array copy of the active services
|
||||
get services() {
|
||||
let array = [];
|
||||
for (let [key, service] of this._services) {
|
||||
let target = this._devices.get(service.deviceID);
|
||||
service.extensions = target.extensions;
|
||||
service.types = target.types;
|
||||
array.push(service);
|
||||
}
|
||||
return array;
|
||||
},
|
||||
|
||||
// Returns false if the service does not match the device's filters
|
||||
_filterService: function _filterService(aService) {
|
||||
// Loop over all the devices, looking for one that matches the service
|
||||
for (let [key, device] of this._devices) {
|
||||
// First level of match is on the target itself
|
||||
if (device.target != aService.target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we have no filter, everything passes
|
||||
if (!("filters" in device)) {
|
||||
aService.deviceID = device.id;
|
||||
return true;
|
||||
}
|
||||
|
||||
// If all the filters pass, we have a match
|
||||
let failed = false;
|
||||
let filters = device.filters;
|
||||
for (let filter in filters) {
|
||||
if (filter in aService && aService[filter] != filters[filter]) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// We found a match, so link the service to the device
|
||||
if (!failed) {
|
||||
aService.deviceID = device.id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// We didn't find any matches
|
||||
return false;
|
||||
},
|
||||
|
||||
_processService: function _processService(aService) {
|
||||
// Use the REST api to request more information about this service
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.open("GET", aService.location, true);
|
||||
xhr.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
|
||||
xhr.overrideMimeType("text/xml");
|
||||
|
||||
xhr.addEventListener("load", (function() {
|
||||
if (xhr.status == 200) {
|
||||
let doc = xhr.responseXML;
|
||||
aService.appsURL = xhr.getResponseHeader("Application-URL");
|
||||
if (aService.appsURL && !aService.appsURL.endsWith("/"))
|
||||
aService.appsURL += "/";
|
||||
aService.friendlyName = doc.querySelector("friendlyName").textContent;
|
||||
aService.uuid = doc.querySelector("UDN").textContent;
|
||||
aService.manufacturer = doc.querySelector("manufacturer").textContent;
|
||||
aService.modelName = doc.querySelector("modelName").textContent;
|
||||
|
||||
this.addService(aService);
|
||||
}
|
||||
}).bind(this), false);
|
||||
|
||||
xhr.send(null);
|
||||
},
|
||||
|
||||
// Add a service to the WeakMap, even if one already exists with this id.
|
||||
// Returns true if this succeeded or false if it failed
|
||||
_addService: function(service) {
|
||||
// Filter out services that do not match the device filter
|
||||
if (!this._filterService(service)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let device = this._devices.get(service.target);
|
||||
if (device && device.mirror) {
|
||||
service.mirror = true;
|
||||
}
|
||||
this._services.set(service.uuid, service);
|
||||
return true;
|
||||
},
|
||||
|
||||
addService: function(service) {
|
||||
// Only add and notify if we don't already know about this service
|
||||
if (!this._services.has(service.uuid)) {
|
||||
if (!this._addService(service)) {
|
||||
return;
|
||||
}
|
||||
Services.obs.notifyObservers(null, EVENT_SERVICE_FOUND, service.uuid);
|
||||
}
|
||||
|
||||
// Make sure we remember this service is not stale
|
||||
this._services.get(service.uuid).lastPing = this._searchTimestamp;
|
||||
},
|
||||
|
||||
removeService: function(uuid) {
|
||||
Services.obs.notifyObservers(null, EVENT_SERVICE_LOST, uuid);
|
||||
this._services.delete(uuid);
|
||||
},
|
||||
|
||||
updateService: function(service) {
|
||||
if (!this._addService(service)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we remember this service is not stale
|
||||
this._services.get(service.uuid).lastPing = this._searchTimestamp;
|
||||
},
|
||||
|
||||
addExternalDiscovery: function(discovery) {
|
||||
this._discoveryMethods.push(discovery);
|
||||
},
|
||||
|
||||
_startExternalDiscovery: function() {
|
||||
for (let discovery of this._discoveryMethods) {
|
||||
discovery.startDiscovery();
|
||||
}
|
||||
},
|
||||
|
||||
_stopExternalDiscovery: function() {
|
||||
for (let discovery of this._discoveryMethods) {
|
||||
discovery.stopDiscovery();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
@ -18,17 +18,16 @@ let EXPORTED_SYMBOLS = ["Subprocess"];
|
|||
|
||||
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/subprocess/subprocess_common.jsm");
|
||||
|
||||
if (AppConstants.platform == "win") {
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SubprocessImpl",
|
||||
"resource://gre/modules/subprocess/subprocess_win.jsm");
|
||||
} else {
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SubprocessImpl",
|
||||
"resource://gre/modules/subprocess/subprocess_unix.jsm");
|
||||
}
|
||||
#ifdef XP_WIN
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SubprocessImpl",
|
||||
"resource://gre/modules/subprocess/subprocess_win.jsm");
|
||||
#else
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SubprocessImpl",
|
||||
"resource://gre/modules/subprocess/subprocess_unix.jsm");
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Allows for creation of and communication with OS-level sub-processes.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
# 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/.
|
||||
|
||||
EXTRA_JS_MODULES += [
|
||||
EXTRA_PP_JS_MODULES += [
|
||||
'Subprocess.jsm',
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|||
|
||||
var EXPORTED_SYMBOLS = ["SubprocessImpl"];
|
||||
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
Cu.import("resource://gre/modules/ctypes.jsm");
|
||||
Cu.import("resource://gre/modules/osfile.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
|
@ -35,7 +34,7 @@ class WinPromiseWorker extends PromiseWorker {
|
|||
this.signalEvent = libc.CreateSemaphoreW(null, 0, 32, null);
|
||||
|
||||
this.call("init", [{
|
||||
breakAwayFromJob: !AppConstants.isPlatformAndVersionAtLeast("win", "6.2"),
|
||||
breakAwayFromJob: Services.vc.compare(Services.sysinfo.getProperty("version"), "6.2") <= 0,
|
||||
comspec: env.get("COMSPEC"),
|
||||
signalEvent: String(ctypes.cast(this.signalEvent, ctypes.uintptr_t).value),
|
||||
}]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue