Skip to content

Commit

Permalink
Merge m-c to m-i
Browse files Browse the repository at this point in the history
  • Loading branch information
philor committed Feb 8, 2016
2 parents 0b7d2ac + a67988c commit 23a0125
Show file tree
Hide file tree
Showing 27 changed files with 1,723 additions and 77 deletions.
1 change: 1 addition & 0 deletions devtools/client/storage/test/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ support-files =
[browser_storage_dynamic_updates.js]
[browser_storage_overflow.js]
[browser_storage_sidebar.js]
skip-if = (os == 'win' && os_version == '6.1' && e10s && !debug) # bug 1229272
[browser_storage_values.js]
7 changes: 7 additions & 0 deletions mobile/android/app/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pref("network.predictor.enabled", true);
pref("network.predictor.max-db-size", 2097152); // bytes
pref("network.predictor.preserve", 50); // percentage of predictor data to keep when cleaning up

// Use JS mDNS as a fallback
pref("network.mdns.use_js_fallback", true);

/* history max results display */
pref("browser.display.history.maxresults", 100);

Expand Down Expand Up @@ -976,3 +979,7 @@ pref("identity.fxaccounts.remote.oauth.uri", "https://oauth.accounts.firefox.com

// Token server used by Firefox Account-authenticated Sync.
pref("identity.sync.tokenserver.uri", "https://token.services.mozilla.com/1.0/sync/1.5");

// Enable Presentation API
pref("dom.presentation.enabled", true);
pref("dom.presentation.discovery.enabled", true);
62 changes: 62 additions & 0 deletions mobile/android/chrome/content/CastingApps.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,64 @@ var mediaPlayerDevice = {
}
};

var fxOSTVDevice = {
id: "app://fling-player.gaiamobile.org",
target: "app://fling-player.gaiamobile.org/index.html",
factory: function(aService) {
Cu.import("resource://gre/modules/PresentationApp.jsm");
let request = new window.PresentationRequest(this.target);
return new PresentationApp(aService, request);
},
init: function() {
Services.obs.addObserver(this, "presentation-device-change", false);
SimpleServiceDiscovery.addExternalDiscovery(this);
},
observe: function(subject, topic, data) {
let device = subject.QueryInterface(Ci.nsIPresentationDevice);
let service = this.toService(device);
switch (data) {
case "add":
SimpleServiceDiscovery.addService(service);
break;
case "update":
SimpleServiceDiscovery.updateService(service);
break;
case "remove":
if(SimpleServiceDiscovery.findServiceForID(device.id)) {
SimpleServiceDiscovery.removeService(device.id);
}
break;
}
},
toService: function(device) {
return {
location: device.id,
target: fxOSTVDevice.target,
friendlyName: device.name,
uuid: device.id,
manufacturer: "Firefox OS TV",
modelName: "Firefox OS TV",
};
},
startDiscovery: function() {
window.navigator.mozPresentationDeviceInfo.forceDiscovery();

// need to update the lastPing time for known device.
window.navigator.mozPresentationDeviceInfo.getAll()
.then(function(devices) {
for (let device of devices) {
let service = fxOSTVDevice.toService(device);
SimpleServiceDiscovery.addService(service);
}
});
},
stopDiscovery: function() {
// do nothing
},
types: ["video/mp4", "video/webm"],
extensions: ["mp4", "webm"],
};

var CastingApps = {
_castMenuId: -1,
mirrorStartMenuId: -1,
Expand All @@ -79,6 +137,10 @@ var CastingApps = {
mediaPlayerDevice.init();
SimpleServiceDiscovery.registerDevice(mediaPlayerDevice);

// Presentation Device will notify us any time the available device list changes.
fxOSTVDevice.init();
SimpleServiceDiscovery.registerDevice(fxOSTVDevice);

// Search for devices continuously
SimpleServiceDiscovery.search(this._interval);

Expand Down
1 change: 1 addition & 0 deletions mobile/android/chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ var BrowserApp = {

InitLater(() => Cu.import("resource://gre/modules/NotificationDB.jsm"));
InitLater(() => Cu.import("resource://gre/modules/Payment.jsm"));
InitLater(() => Cu.import("resource://gre/modules/PresentationDeviceInfoManager.jsm"));

InitLater(() => Services.obs.notifyObservers(window, "browser-delayed-startup-finished", ""));
InitLater(() => Messaging.sendRequest({ type: "Gecko:DelayedStartup" }));
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/passwordmgr/content/passwordManager.xul
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
src="chrome://passwordmgr/locale/passwordmgr.properties"/>

<keyset>
<key keycode="VK_ESCAPE" oncommand="window.close();"/>
<key keycode="VK_ESCAPE" oncommand="escapeKeyHandler();"/>
<key key="&windowClose.key;" modifiers="accel" oncommand="escapeKeyHandler();"/>
<key key="&focusSearch1.key;" modifiers="accel" oncommand="FocusFilterBox();"/>
<key key="&focusSearch2.key;" modifiers="accel" oncommand="FocusFilterBox();"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { ContentTaskUtils } = Cu.import("resource://testing-common/ContentTaskUtils.jsm", {});
const TIME_INTERVAL = 500;
const PWMGR_DLG = "chrome://passwordmgr/content/passwordManager.xul";

var doc;
Expand Down Expand Up @@ -55,7 +54,7 @@ function* editUsernamePromises(site, oldUsername, newUsername) {
is(Services.logins.findLogins({}, site, "", "").length, 1, "Correct login replaced");
login = Services.logins.findLogins({}, site, "", "")[0];
is(login.username, newUsername, "Correct username updated");
is(getUsername(0), newUsername, "Correct username shown");
is(getUsername(0), newUsername, "Correct username shown after the update");
}

function* editPasswordPromises(site, oldPassword, newPassword) {
Expand All @@ -77,7 +76,7 @@ function* editPasswordPromises(site, oldPassword, newPassword) {
is(Services.logins.findLogins({}, site, "", "").length, 1, "Correct login replaced");
login = Services.logins.findLogins({}, site, "", "")[0];
is(login.password, newPassword, "Correct password updated");
is(getPassword(0), newPassword, "Correct password shown");
is(getPassword(0), newPassword, "Correct password shown after the update");
}

add_task(function* test_setup() {
Expand Down
1 change: 1 addition & 0 deletions toolkit/modules/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ EXTRA_JS_MODULES += [
'RemoteSecurityUI.jsm',
'RemoteWebProgress.jsm',
'ResetProfile.jsm',
'secondscreen/PresentationApp.jsm',
'secondscreen/RokuApp.jsm',
'secondscreen/SimpleServiceDiscovery.jsm',
'SelectContentHelper.jsm',
Expand Down
190 changes: 190 additions & 0 deletions toolkit/modules/secondscreen/PresentationApp.jsm
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// -*- 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) {
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("statechange", 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 "statechange":
this._onstatechange(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);
}
}
}
},

_onstatechange: function(e) {
DEBUG && debug("onstatechange: " + this._session.state);
if (this._session.state !== "connected") {
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;
}
}
24 changes: 23 additions & 1 deletion toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var SimpleServiceDiscovery = {
_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
Expand Down Expand Up @@ -141,6 +142,9 @@ var SimpleServiceDiscovery = {
// 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 {
Expand Down Expand Up @@ -226,6 +230,8 @@ var SimpleServiceDiscovery = {
}
}
}

this._stopExternalDiscovery();
},

getSupportedExtensions: function() {
Expand Down Expand Up @@ -409,5 +415,21 @@ var SimpleServiceDiscovery = {

// 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();
}
},
}
Loading

0 comments on commit 23a0125

Please sign in to comment.