Bug 1610641 - Remove unused MediaPlayerApp, Notifications, RuntimePermissions. r=esawin

Differential Revision: https://phabricator.services.mozilla.com/D60584

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2020-01-22 14:52:51 +00:00
Родитель 162b378a2a
Коммит d5c021dcff
4 изменённых файлов: 0 добавлений и 498 удалений

Просмотреть файл

@ -1,159 +0,0 @@
// -*- Mode: js2; 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";
var EXPORTED_SYMBOLS = ["MediaPlayerApp"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { EventDispatcher } = ChromeUtils.import(
"resource://gre/modules/Messaging.jsm"
);
// Helper function for sending commands to Java.
function send(type, data, callback) {
let msg = {
type: type,
};
for (let i in data) {
msg[i] = data[i];
}
EventDispatcher.instance
.sendRequestForResult(msg)
.then(result => callback(result, null), error => callback(null, error));
}
/* These apps represent players supported natively by the platform. This class will proxy commands
* to native controls */
function MediaPlayerApp(service) {
this.service = service;
this.location = service.location;
this.id = service.uuid;
}
MediaPlayerApp.prototype = {
start: function start(callback) {
send("MediaPlayer:Start", { id: this.id }, (result, err) => {
if (callback) {
callback(err == null);
}
});
},
stop: function stop(callback) {
send("MediaPlayer:Stop", { id: this.id }, (result, err) => {
if (callback) {
callback(err == null);
}
});
},
remoteMedia: function remoteMedia(callback, listener) {
if (callback) {
callback(new RemoteMedia(this.id, listener));
}
},
};
/* RemoteMedia provides a proxy to a native media player session.
*/
function RemoteMedia(id, listener) {
this._id = id;
this._listener = listener;
if ("onRemoteMediaStart" in this._listener) {
Services.tm.dispatchToMainThread(() => {
this._listener.onRemoteMediaStart(this);
});
}
}
RemoteMedia.prototype = {
shutdown: function shutdown() {
EventDispatcher.instance.unregisterListener(this, [
"MediaPlayer:Playing",
"MediaPlayer:Paused",
]);
this._send("MediaPlayer:End", {}, (result, err) => {
this._status = "shutdown";
if ("onRemoteMediaStop" in this._listener) {
this._listener.onRemoteMediaStop(this);
}
});
},
play: function play() {
this._send("MediaPlayer:Play", {}, (result, err) => {
if (err) {
Cu.reportError("Can't play " + err);
this.shutdown();
return;
}
this._status = "started";
});
},
pause: function pause() {
this._send("MediaPlayer:Pause", {}, (result, err) => {
if (err) {
Cu.reportError("Can't pause " + err);
this.shutdown();
return;
}
this._status = "paused";
});
},
load: function load(aData) {
this._send("MediaPlayer:Load", aData, (result, err) => {
if (err) {
Cu.reportError("Can't load " + err);
this.shutdown();
return;
}
EventDispatcher.instance.registerListener(this, [
"MediaPlayer:Playing",
"MediaPlayer:Paused",
]);
this._status = "started";
});
},
get status() {
return this._status;
},
onEvent: function(event, message, callback) {
switch (event) {
case "MediaPlayer:Playing":
if (this._status !== "started") {
this._status = "started";
if ("onRemoteMediaStatus" in this._listener) {
this._listener.onRemoteMediaStatus(this);
}
}
break;
case "MediaPlayer:Paused":
if (this._status !== "paused") {
this._status = "paused";
if ("onRemoteMediaStatus" in this._listener) {
this._listener.onRemoteMediaStatus(this);
}
}
break;
}
},
_send: function(msg, data, callback) {
data.id = this._id;
send(msg, data, callback);
},
};

Просмотреть файл

@ -1,270 +0,0 @@
/* 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 { EventDispatcher } = ChromeUtils.import(
"resource://gre/modules/Messaging.jsm"
);
var EXPORTED_SYMBOLS = ["Notifications"];
var _notificationsMap = {};
var _handlersMap = {};
function Notification(aId, aOptions) {
this._id = aId;
this._when = new Date().getTime();
this.fillWithOptions(aOptions);
}
Notification.prototype = {
fillWithOptions: function(aOptions) {
if ("icon" in aOptions && aOptions.icon != null) {
this._icon = aOptions.icon;
} else {
throw new Error("Notification icon is mandatory");
}
if ("title" in aOptions && aOptions.title != null) {
this._title = aOptions.title;
} else {
throw new Error("Notification title is mandatory");
}
if ("message" in aOptions && aOptions.message != null) {
this._message = aOptions.message;
} else {
this._message = null;
}
if ("priority" in aOptions && aOptions.priority != null) {
this._priority = aOptions.priority;
}
if ("buttons" in aOptions && aOptions.buttons != null) {
if (aOptions.buttons.length > 3) {
throw new Error("Too many buttons provided. The max number is 3");
}
this._buttons = {};
for (let i = 0; i < aOptions.buttons.length; i++) {
let button_id = aOptions.buttons[i].buttonId;
this._buttons[button_id] = aOptions.buttons[i];
}
} else {
this._buttons = null;
}
if ("ongoing" in aOptions && aOptions.ongoing != null) {
this._ongoing = aOptions.ongoing;
} else {
this._ongoing = false;
}
if ("progress" in aOptions && aOptions.progress != null) {
this._progress = aOptions.progress;
} else {
this._progress = null;
}
if ("onCancel" in aOptions && aOptions.onCancel != null) {
this._onCancel = aOptions.onCancel;
} else {
this._onCancel = null;
}
if ("onClick" in aOptions && aOptions.onClick != null) {
this._onClick = aOptions.onClick;
} else {
this._onClick = null;
}
if ("cookie" in aOptions && aOptions.cookie != null) {
this._cookie = aOptions.cookie;
} else {
this._cookie = null;
}
if ("handlerKey" in aOptions && aOptions.handlerKey != null) {
this._handlerKey = aOptions.handlerKey;
}
if ("persistent" in aOptions && aOptions.persistent != null) {
this._persistent = aOptions.persistent;
} else {
this._persistent = false;
}
},
show: function() {
let msg = {
id: this._id,
title: this._title,
smallIcon: this._icon,
ongoing: this._ongoing,
when: this._when,
persistent: this._persistent,
};
if (this._message) {
msg.text = this._message;
}
if (this._progress) {
msg.progress_value = this._progress;
msg.progress_max = 100;
msg.progress_indeterminate = false;
} else if (Number.isNaN(this._progress)) {
msg.progress_value = 0;
msg.progress_max = 0;
msg.progress_indeterminate = true;
}
if (this._cookie) {
msg.cookie = JSON.stringify(this._cookie);
}
if (this._priority) {
msg.priority = this._priority;
}
if (this._buttons) {
msg.actions = [];
let buttonName;
for (buttonName in this._buttons) {
let button = this._buttons[buttonName];
let obj = {
buttonId: button.buttonId,
title: button.title,
icon: button.icon,
};
msg.actions.push(obj);
}
}
if (this._light) {
msg.light = this._light;
}
if (this._handlerKey) {
msg.handlerKey = this._handlerKey;
}
EventDispatcher.instance.dispatch("Notification:Show", msg);
return this;
},
cancel: function() {
let msg = {
id: this._id,
handlerKey: this._handlerKey,
cookie: JSON.stringify(this._cookie),
};
EventDispatcher.instance.dispatch("Notification:Hide", msg);
},
};
var Notifications = {
get idService() {
delete this.idService;
return (this.idService = Cc["@mozilla.org/uuid-generator;1"].getService(
Ci.nsIUUIDGenerator
));
},
registerHandler: function(key, handler) {
if (!_handlersMap[key]) {
_handlersMap[key] = [];
}
_handlersMap[key].push(handler);
},
unregisterHandler: function(key, handler) {
let h = _handlersMap[key];
if (!h) {
return;
}
let i = h.indexOf(handler);
if (i > -1) {
h.splice(i, 1);
}
},
create: function notif_notify(aOptions) {
let id = this.idService.generateUUID().toString();
let notification = new Notification(id, aOptions);
_notificationsMap[id] = notification;
notification.show();
return id;
},
update: function notif_update(aId, aOptions) {
let notification = _notificationsMap[aId];
if (!notification) {
throw new Error("Unknown notification id");
}
notification.fillWithOptions(aOptions);
notification.show();
},
cancel: function notif_cancel(aId) {
let notification = _notificationsMap[aId];
if (notification) {
notification.cancel();
}
},
onEvent: function notif_onEvent(event, data, callback) {
let id = data.id;
let handlerKey = data.handlerKey;
let cookie = data.cookie ? JSON.parse(data.cookie) : undefined;
let notification = _notificationsMap[id];
switch (data.eventType) {
case "notification-clicked":
if (notification && notification._onClick) {
notification._onClick(id, notification._cookie);
}
if (handlerKey) {
_handlersMap[handlerKey].forEach(function(handler) {
handler.onClick(cookie);
});
}
break;
case "notification-button-clicked":
if (handlerKey) {
_handlersMap[handlerKey].forEach(function(handler) {
handler.onButtonClick(data.buttonId, cookie);
});
}
break;
case "notification-cleared":
case "notification-closed":
if (handlerKey) {
_handlersMap[handlerKey].forEach(function(handler) {
handler.onCancel(cookie);
});
}
if (notification && notification._onCancel) {
notification._onCancel(id, notification._cookie);
}
delete _notificationsMap[id]; // since the notification was dismissed, we no longer need to hold a reference.
break;
}
},
QueryInterface: ChromeUtils.generateQI([
"nsIObserver",
"nsISupportsWeakReference",
]),
};
EventDispatcher.instance.registerListener(Notifications, "Notification:Event");

Просмотреть файл

@ -1,66 +0,0 @@
/* 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";
var EXPORTED_SYMBOLS = ["RuntimePermissions"];
ChromeUtils.defineModuleGetter(
this,
"EventDispatcher",
"resource://gre/modules/Messaging.jsm"
);
// See: http://developer.android.com/reference/android/Manifest.permission.html
const ACCESS_COARSE_LOCATION = "android.permission.ACCESS_COARSE_LOCATION";
const ACCESS_FINE_LOCATION = "android.permission.ACCESS_FINE_LOCATION";
const CAMERA = "android.permission.CAMERA";
const RECORD_AUDIO = "android.permission.RECORD_AUDIO";
const WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE";
const READ_EXTERNAL_STORAGE = "android.permission.READ_EXTERNAL_STORAGE";
var RuntimePermissions = {
ACCESS_COARSE_LOCATION: ACCESS_COARSE_LOCATION,
ACCESS_FINE_LOCATION: ACCESS_FINE_LOCATION,
CAMERA: CAMERA,
RECORD_AUDIO: RECORD_AUDIO,
WRITE_EXTERNAL_STORAGE: WRITE_EXTERNAL_STORAGE,
READ_EXTERNAL_STORAGE: READ_EXTERNAL_STORAGE,
/**
* Check whether the permissions have been granted or not. If needed prompt the user to accept the permissions.
*
* @returns A promise resolving to true if all the permissions have been granted or false if any of the
* permissions have been denied.
*/
waitForPermissions: function(permission) {
let permissions = [].concat(permission);
let msg = {
type: "RuntimePermissions:Check",
permissions: permissions,
shouldPrompt: true,
};
return EventDispatcher.instance.sendRequestForResult(msg);
},
/**
* Check whether the specified permissions have already been granted or not.
*
* @returns A promise resolving to true if all the permissions are already granted or false if any of the
* permissions are not granted.
*/
checkPermissions: function(permission) {
let permissions = [].concat(permission);
let msg = {
type: "RuntimePermissions:Check",
permissions: permissions,
shouldPrompt: false,
};
return EventDispatcher.instance.sendRequestForResult(msg);
},
};

Просмотреть файл

@ -21,9 +21,6 @@ EXTRA_JS_MODULES += [
'Home.jsm', 'Home.jsm',
'HomeProvider.jsm', 'HomeProvider.jsm',
'LightweightThemeConsumer.jsm', 'LightweightThemeConsumer.jsm',
'MediaPlayerApp.jsm',
'Notifications.jsm',
'RuntimePermissions.jsm',
'SharedPreferences.jsm', 'SharedPreferences.jsm',
'Snackbars.jsm', 'Snackbars.jsm',
'WebsiteMetadata.jsm' 'WebsiteMetadata.jsm'