зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1592286 - Add a WebCompat experimental API for mapping MatchPatterns to Picture-in-Picture toggle position policies. r=denschub
Differential Revision: https://phabricator.services.mozilla.com/D57375 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8416f879eb
Коммит
8bdfa0e67a
|
@ -0,0 +1,25 @@
|
|||
/* 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";
|
||||
|
||||
/* globals browser */
|
||||
|
||||
let AVAILABLE_PIP_OVERRIDES;
|
||||
|
||||
{
|
||||
// See PictureInPictureTogglePolicy.jsm for these values.
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const TOGGLE_POLICIES = browser.pictureInPictureChild.getPolicies();
|
||||
|
||||
AVAILABLE_PIP_OVERRIDES = {
|
||||
// The keys of this object are match patterns for URLs, as documented in
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// "https://*.youtube.com/*": TOGGLE_POLICIES.THREE_QUARTERS,
|
||||
// "https://*.twitch.tv/mikeconley_dot_ca/*": TOGGLE_POLICIES.TOP,
|
||||
};
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/* 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";
|
||||
|
||||
/* global ChromeUtils, ExtensionAPI, Services */
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"Services",
|
||||
"resource://gre/modules/Services.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"TOGGLE_POLICIES",
|
||||
"resource://gre/modules/PictureInPictureTogglePolicy.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"AppConstants",
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
|
||||
const TOGGLE_ENABLED_PREF =
|
||||
"media.videocontrols.picture-in-picture.video-toggle.enabled";
|
||||
|
||||
/**
|
||||
* This API is expected to be running in the parent process.
|
||||
*/
|
||||
this.pictureInPictureParent = class extends ExtensionAPI {
|
||||
getAPI(context) {
|
||||
return {
|
||||
pictureInPictureParent: {
|
||||
setOverrides(overrides) {
|
||||
// The Picture-in-Picture toggle is only implemented for Desktop, so make
|
||||
// this a no-op for non-Desktop builds.
|
||||
if (AppConstants.platform == "android") {
|
||||
return;
|
||||
}
|
||||
|
||||
Services.ppmm.sharedData.set(
|
||||
"PictureInPicture:ToggleOverrides",
|
||||
overrides
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This API is expected to be running in a content process - specifically,
|
||||
* the WebExtension content process that the background scripts run in. We
|
||||
* split these out so that they can return values synchronously to the
|
||||
* background scripts.
|
||||
*/
|
||||
this.pictureInPictureChild = class extends ExtensionAPI {
|
||||
getAPI(context) {
|
||||
return {
|
||||
pictureInPictureChild: {
|
||||
getPolicies() {
|
||||
// The Picture-in-Picture toggle is only implemented for Desktop, so make
|
||||
// this return nothing for non-Desktop builds.
|
||||
if (AppConstants.platform == "android") {
|
||||
return {};
|
||||
}
|
||||
|
||||
return Cu.cloneInto(TOGGLE_POLICIES, context.cloneScope);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
|
@ -0,0 +1,39 @@
|
|||
[
|
||||
{
|
||||
"namespace": "pictureInPictureParent",
|
||||
"description": "Parent process methods for controlling the Picture-in-Picture feature.",
|
||||
"functions": [
|
||||
{
|
||||
"name": "setOverrides",
|
||||
"type": "function",
|
||||
"description": "Set Picture-in-Picture toggle position overrides",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "overrides",
|
||||
"type": "object",
|
||||
"additionalProperties": { "type": "any" },
|
||||
"description": "The Picture-in-Picture toggle position overrides to set"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"namespace": "pictureInPictureChild",
|
||||
"description": "WebExtension process methods for querying the Picture-in-Picture feature.",
|
||||
"functions": [
|
||||
{
|
||||
"name": "getPolicies",
|
||||
"type": "function",
|
||||
"description": "Get the Picture-in-Picture toggle position override constants",
|
||||
"parameters": [],
|
||||
"returns": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"additionalProperties": { "type": "any" },
|
||||
"description": "The Picture-in-Picture toggle position override constants"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
/* 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";
|
||||
|
||||
/* globals browser, module */
|
||||
|
||||
class PictureInPictureOverrides {
|
||||
constructor(availableOverrides) {
|
||||
this._availableOverrides = availableOverrides;
|
||||
}
|
||||
|
||||
bootup() {
|
||||
browser.pictureInPictureParent.setOverrides(this._availableOverrides);
|
||||
}
|
||||
}
|
|
@ -36,6 +36,22 @@
|
|||
"paths": [["experiments"]]
|
||||
}
|
||||
},
|
||||
"pictureInPictureChild": {
|
||||
"schema": "experiment-apis/pictureInPicture.json",
|
||||
"child": {
|
||||
"scopes": ["addon_child"],
|
||||
"script": "experiment-apis/pictureInPicture.js",
|
||||
"paths": [["pictureInPictureChild"]]
|
||||
}
|
||||
},
|
||||
"pictureInPictureParent": {
|
||||
"schema": "experiment-apis/pictureInPicture.json",
|
||||
"parent": {
|
||||
"scopes": ["addon_parent"],
|
||||
"script": "experiment-apis/pictureInPicture.js",
|
||||
"paths": [["pictureInPictureParent"]]
|
||||
}
|
||||
},
|
||||
"sharedPreferences": {
|
||||
"schema": "experiment-apis/sharedPreferences.json",
|
||||
"parent": {
|
||||
|
@ -59,10 +75,12 @@
|
|||
"lib/module_shim.js",
|
||||
"lib/google.js",
|
||||
"data/injections.js",
|
||||
"data/picture_in_picture_overrides.js",
|
||||
"data/ua_overrides.js",
|
||||
"lib/about_compat_broker.js",
|
||||
"lib/custom_functions.js",
|
||||
"lib/injections.js",
|
||||
"lib/picture_in_picture_overrides.js",
|
||||
"lib/ua_overrides.js",
|
||||
"run.js"
|
||||
]
|
||||
|
|
|
@ -24,6 +24,7 @@ FINAL_TARGET_FILES.features['webcompat@mozilla.org']['about-compat'] += [
|
|||
|
||||
FINAL_TARGET_FILES.features['webcompat@mozilla.org']['data'] += [
|
||||
'data/injections.js',
|
||||
'data/picture_in_picture_overrides.js',
|
||||
'data/ua_overrides.js',
|
||||
]
|
||||
|
||||
|
@ -32,6 +33,8 @@ FINAL_TARGET_FILES.features['webcompat@mozilla.org']['experiment-apis'] += [
|
|||
'experiment-apis/aboutConfigPrefs.json',
|
||||
'experiment-apis/experiments.js',
|
||||
'experiment-apis/experiments.json',
|
||||
'experiment-apis/pictureInPicture.js',
|
||||
'experiment-apis/pictureInPicture.json',
|
||||
'experiment-apis/sharedPreferences.js',
|
||||
'experiment-apis/sharedPreferences.json',
|
||||
]
|
||||
|
@ -74,6 +77,7 @@ FINAL_TARGET_FILES.features['webcompat@mozilla.org']['lib'] += [
|
|||
'lib/google.js',
|
||||
'lib/injections.js',
|
||||
'lib/module_shim.js',
|
||||
'lib/picture_in_picture_overrides.js',
|
||||
'lib/ua_overrides.js',
|
||||
]
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
"use strict";
|
||||
|
||||
/* globals AVAILABLE_INJECTIONS, AVAILABLE_UA_OVERRIDES, AboutCompatBroker,
|
||||
Injections, UAOverrides, CUSTOM_FUNCTIONS */
|
||||
Injections, UAOverrides, CUSTOM_FUNCTIONS, AVAILABLE_PIP_OVERRIDES,
|
||||
PictureInPictureOverrides */
|
||||
|
||||
const injections = new Injections(AVAILABLE_INJECTIONS, CUSTOM_FUNCTIONS);
|
||||
const uaOverrides = new UAOverrides(AVAILABLE_UA_OVERRIDES);
|
||||
const pipOverrides = new PictureInPictureOverrides(AVAILABLE_PIP_OVERRIDES);
|
||||
|
||||
const aboutCompatBroker = new AboutCompatBroker({
|
||||
injections,
|
||||
|
@ -18,3 +20,4 @@ const aboutCompatBroker = new AboutCompatBroker({
|
|||
aboutCompatBroker.bootup();
|
||||
injections.bootup();
|
||||
uaOverrides.bootup();
|
||||
pipOverrides.bootup();
|
||||
|
|
Загрузка…
Ссылка в новой задаче