Commit aadd69a8 authored by Liang-Heng Chen's avatar Liang-Heng Chen Committed by Matthew Finkel
Browse files

Bug 1330467 - part 12. FPI isolation of translation permissions; r=johannh

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

--HG--
extra : moz-landing-system : lando
parent 4b907aa7
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ var Translation = {

    trUI.showURLBarIcon();

    if (trUI.shouldShowInfoBar(aBrowser.currentURI)) {
    if (trUI.shouldShowInfoBar(aBrowser.contentPrincipal)) {
      trUI.showTranslationInfoBar();
    }
  },
@@ -308,7 +308,7 @@ TranslationUI.prototype = {
    return notif;
  },

  shouldShowInfoBar(aURI) {
  shouldShowInfoBar(aPrincipal) {
    // Never show the infobar automatically while the translation
    // service is temporarily unavailable.
    if (Translation.serviceUnavailable) {
@@ -326,7 +326,7 @@ TranslationUI.prototype = {

    // or if we should never show the infobar for this domain.
    let perms = Services.perms;
    if (perms.testExactPermission(aURI, "translate") == perms.DENY_ACTION) {
    if (perms.testExactPermissionFromPrincipal(aPrincipal, "translate") == perms.DENY_ACTION) {
      TranslationTelemetry.recordAutoRejectedTranslationOffer();
      return false;
    }
+4 −4
Original line number Diff line number Diff line
@@ -352,11 +352,11 @@ class MozTranslationNotification extends MozElements.Notification {
    item.disabled = neverForLangs.split(",").includes(lang);

    // Check if translation is disabled for the domain:
    let uri = this.translation.browser.currentURI;
    let principal = this.translation.browser.contentPrincipal;
    let perms = Services.perms;
    item = this._getAnonElt("neverForSite");
    item.disabled =
      perms.testExactPermission(uri, "translate") == perms.DENY_ACTION;
      perms.testExactPermissionFromPrincipal(principal, "translate") == perms.DENY_ACTION;
  }

  neverForLanguage() {
@@ -374,9 +374,9 @@ class MozTranslationNotification extends MozElements.Notification {
  }

  neverForSite() {
    let uri = this.translation.browser.currentURI;
    let principal = this.translation.browser.contentPrincipal;
    let perms = Services.perms;
    perms.add(uri, "translate", perms.DENY_ACTION);
    perms.addFromPrincipal(principal, "translate", perms.DENY_ACTION);

    this.closeCommand();
  }
+6 −6
Original line number Diff line number Diff line
@@ -131,9 +131,9 @@ var gTests = [
      let notif = await getInfoBar();
      ok(notif, "the infobar is visible");
      let ui = gBrowser.selectedBrowser.translationUI;
      let uri = gBrowser.selectedBrowser.currentURI;
      let principal = gBrowser.selectedBrowser.contentPrincipal;
      ok(
        ui.shouldShowInfoBar(uri, "fr"),
        ui.shouldShowInfoBar(principal, "fr"),
        "check shouldShowInfoBar initially returns true"
      );

@@ -160,7 +160,7 @@ var gTests = [
      is(langs.length, 1, "one language in the exception list");
      is(langs[0], "fr", "correct language in the exception list");
      ok(
        !ui.shouldShowInfoBar(uri, "fr"),
        !ui.shouldShowInfoBar(principal, "fr"),
        "the infobar wouldn't be shown anymore"
      );

@@ -192,9 +192,9 @@ var gTests = [
      let notif = await getInfoBar();
      ok(notif, "the infobar is visible");
      let ui = gBrowser.selectedBrowser.translationUI;
      let uri = gBrowser.selectedBrowser.currentURI;
      let principal = gBrowser.selectedBrowser.contentPrincipal;
      ok(
        ui.shouldShowInfoBar(uri, "fr"),
        ui.shouldShowInfoBar(principal, "fr"),
        "check shouldShowInfoBar initially returns true"
      );

@@ -225,7 +225,7 @@ var gTests = [
        "correct site in the exception list"
      );
      ok(
        !ui.shouldShowInfoBar(uri, "fr"),
        !ui.shouldShowInfoBar(principal, "fr"),
        "the infobar wouldn't be shown anymore"
      );