Bug 1894999 - Expose chat prefs via experiments featuregate r=tarek,fluent-reviewers,settings-reviewers,desktop-theme-reviewers,flod,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D209639
This commit is contained in:
Ed Lee 2024-06-07 04:28:22 +00:00
parent 4c3610fd24
commit 9c113718ee
9 changed files with 115 additions and 0 deletions

View file

@ -92,4 +92,24 @@ export const GenAI = {
);
win.openWebLinkIn(url + "", "tab", { relatedToCurrent: true });
},
/**
* Build preferences for chat such as handling providers.
*
* @param {Window} window for about:preferences
*/
buildPreferences({ document, Preferences }) {
const providerEl = document.getElementById("genai-chat-provider");
if (!providerEl) {
return;
}
const enabled = Preferences.get("browser.ml.chat.enabled");
const onEnabledChange = () => (providerEl.disabled = !enabled.value);
onEnabledChange();
enabled.on("change", onEnabledChange);
// TODO bug 1895433 populate providers
Preferences.add({ id: "browser.ml.chat.provider", type: "string" });
},
};

View file

@ -36,3 +36,19 @@
<description class="text-deemphasized featureGateDescription"/>
</html:div>
</html:template>
<html:template id="template-genai-chat">
<description class="featureGateDescription"
data-l10n-id="genai-settings-chat-choose"/>
<menulist class="indent"
id="genai-chat-provider"
preference="browser.ml.chat.provider">
<menupopup>
<menuitem data-l10n-id="genai-settings-chat-choose-one-menuitem"
value=""/>
</menupopup>
</menulist>
<description class="featureGateDescription tip-caption"
data-l10n-id="genai-settings-chat-links"
id="genai-chat-links"/>
</html:template>

View file

@ -4,6 +4,10 @@
/* import-globals-from preferences.js */
ChromeUtils.defineESModuleGetters(this, {
GenAI: "resource:///modules/GenAI.sys.mjs",
});
var gExperimentalPane = {
inited: false,
_template: null,
@ -149,6 +153,12 @@ var gExperimentalPane = {
checkbox.id = feature.id;
checkbox.setAttribute("aria-describedby", description.id);
document.l10n.setAttributes(checkbox, feature.title);
let extraTemplate = document.getElementById(`template-${feature.id}`);
if (extraTemplate) {
template
.querySelector(".featureGate")
.appendChild(extraTemplate.content.cloneNode(true));
}
frag.appendChild(template);
let preference = Preferences.add({
id: feature.preference,
@ -159,5 +169,8 @@ var gExperimentalPane = {
preference.setElementValue(checkbox);
}
this._featureGatesContainer.appendChild(frag);
// Bug 1895494 to allow more generic logic
GenAI.buildPreferences(window);
},
};

View file

@ -67,6 +67,7 @@
<link rel="localization" href="browser/sanitize.ftl"/>
<link rel="localization" href="browser/translations.ftl"/>
<link rel="localization" href="preview/translations.ftl"/>
<link rel="localization" href="preview/genai.ftl"/>
<link rel="localization" href="preview/enUS-searchFeatures.ftl"/>
<link rel="localization" href="preview/backupSettings.ftl"/>
<link rel="localization" href="security/certificates/certManager.ftl"/>

View file

@ -72,3 +72,37 @@ add_task(async function testSearchFindsExperiments() {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
add_task(async function testExtraTemplate() {
await SpecialPowers.pushPrefEnv({
set: [["browser.preferences.experimental", true]],
});
// Pretend a feature has id of "featureGate" to reuse that template
const server = new DefinitionServer();
server.addDefinition({
id: "featureGate",
isPublicJexl: "true",
preference: "test.feature",
});
await BrowserTestUtils.openNewForegroundTab(
gBrowser,
`about:preferences?definitionsUrl=${encodeURIComponent(
server.definitionsUrl
)}#paneExperimental`
);
const doc = gBrowser.contentDocument;
const checkbox = await TestUtils.waitForCondition(
() => doc.getElementById("featureGate"),
"wait for feature to get added to the DOM"
);
is(
checkbox.parentNode.querySelectorAll("checkbox").length,
2,
"extra template added another checkbox"
);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});

View file

@ -0,0 +1,16 @@
# 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/.
## Generative AI (GenAI) Settings section
genai-settings-chat-title =
.label = A.I.: Chatbot integration
genai-settings-chat-description =
Select text on a webpage and right-click to see relevant prompts like summarize, simplify, and more. { -brand-short-name } sends the selected text and the prompt to the chatbot of your choice. If you try this feature, <a data-l10n-name="connect">share your thoughts on Connect</a>.
We plan to add more chatbots as we continue to experiment.
genai-settings-chat-choose = Choose a chatbot
genai-settings-chat-choose-one-menuitem =
.label = Choose one
genai-settings-chat-links = When you choose a chatbot, you agree to the providers terms and privacy.

View file

@ -15,6 +15,7 @@
preview/shopping.ftl (../components/shopping/content/shopping.ftl)
preview/sidebar.ftl (../components/sidebar/sidebar.ftl)
preview/onboarding.ftl (../components/aboutwelcome/content/onboarding.ftl)
preview/genai.ftl (../locales-preview/genai.ftl)
preview/translations.ftl (../locales-preview/translations.ftl)
browser (%browser/**/*.ftl)
preview/profiles.ftl (../components/profiles/content/profiles.ftl)

View file

@ -1245,7 +1245,9 @@ richlistitem .text-link:hover {
}
.featureGateDescription {
margin-block: var(--space-small);
margin-inline-start: calc(var(--checkbox-size) + var(--checkbox-margin-inline));
white-space: pre-wrap;
}
.checkbox-row {

View file

@ -61,6 +61,18 @@ bug-numbers = [1651607]
is-public-jexl = "true"
default-value-jexl = "false"
[genai-chat]
title = "genai-settings-chat-title"
description = "genai-settings-chat-description"
# Bug 1895497 to add actual link
description-links = {connect= "https://connect.mozilla.org"}
restart-required = false
preference = "browser.ml.chat.enabled"
type = "boolean"
bug-numbers = [1894999]
is-public-jexl = "false"
default-value-jexl = "false"
[webrtc-global-mute-toggles]
title = "experimental-features-webrtc-global-mute-toggles"
description = "experimental-features-webrtc-global-mute-toggles-description"