morgan pushed to branch tor-browser-128.9.0esr-14.5-1 at The Tor Project / Applications / Tor Browser

Commits:

1 changed file:

Changes:

  • browser/components/abouttor/content/aboutTor.js
    ... ... @@ -182,6 +182,21 @@ const SurveyArea = {
    182 182
        */
    
    183 183
       _version: 1,
    
    184 184
     
    
    185
    +  /**
    
    186
    +   * The latest version of the survey the user has dismissed.
    
    187
    +   * If higher or equal than _version, the survey will not be displayed.
    
    188
    +   *
    
    189
    +   * @type {integer}
    
    190
    +   */
    
    191
    +  _dismissVersion: 0,
    
    192
    +
    
    193
    +  /**
    
    194
    +   * The surveys will be shown only in the stable channel of Tor Browser.
    
    195
    +   *
    
    196
    +   * @type {boolean}
    
    197
    +   */
    
    198
    +  _isStable: false,
    
    199
    +
    
    185 200
       /**
    
    186 201
        * The date to start showing the survey.
    
    187 202
        *
    
    ... ... @@ -293,6 +308,13 @@ const SurveyArea = {
    293 308
         },
    
    294 309
       ],
    
    295 310
     
    
    311
    +  /**
    
    312
    +   * The observer to update the localized content whenever the language changes.
    
    313
    +   *
    
    314
    +   * @type {MutationObserver}
    
    315
    +   */
    
    316
    +  _langObserver: null,
    
    317
    +
    
    296 318
       /**
    
    297 319
        * Initialize the survey area.
    
    298 320
        */
    
    ... ... @@ -311,6 +333,17 @@ const SurveyArea = {
    311 333
         document.getElementById("survey-dismiss").addEventListener("click", () => {
    
    312 334
           this._hide();
    
    313 335
         });
    
    336
    +    this._langObserver = new MutationObserver(mutationList => {
    
    337
    +      for (const mutation of mutationList) {
    
    338
    +        if (
    
    339
    +          mutation.type === "attributes" &&
    
    340
    +          mutation.attributeName === "lang"
    
    341
    +        ) {
    
    342
    +          this.potentiallyShow();
    
    343
    +        }
    
    344
    +      }
    
    345
    +    });
    
    346
    +    this._langObserver.observe(document.documentElement, { attributes: true });
    
    314 347
       },
    
    315 348
     
    
    316 349
       /**
    
    ... ... @@ -333,23 +366,33 @@ const SurveyArea = {
    333 366
       },
    
    334 367
     
    
    335 368
       /**
    
    336
    -   * Decide whether to show the survey.
    
    369
    +   * Set the data for the survey.
    
    337 370
        *
    
    338 371
        * @param {integer} dismissVersion - The latest version of survey that the
    
    339 372
        *   user has already dismissed.
    
    340 373
        * @param {boolean} isStable - Whether this is the stable release of Tor
    
    341 374
        *   Browser.
    
    342 375
        */
    
    343
    -  potentiallyShow(dismissVersion, isStable) {
    
    376
    +  setData(dismissVersion, isStable) {
    
    377
    +    this._isStable = isStable;
    
    378
    +    this._dismissVersion = dismissVersion;
    
    379
    +    this.potentiallyShow();
    
    380
    +  },
    
    381
    +
    
    382
    +  /**
    
    383
    +   * Decide whether to show or update the survey.
    
    384
    +   */
    
    385
    +  potentiallyShow() {
    
    344 386
         const now = Date.now();
    
    345 387
         if (
    
    346 388
           now < this._startDate ||
    
    347 389
           now >= this._endDate ||
    
    348 390
           // The user has already dismissed this version of the survey before:
    
    349
    -      dismissVersion >= this._version ||
    
    350
    -      !isStable
    
    391
    +      this._dismissVersion >= this._version ||
    
    392
    +      !this._isStable
    
    351 393
         ) {
    
    352 394
           // Don't show the survey.
    
    395
    +      document.body.classList.remove("show-survey");
    
    353 396
           return;
    
    354 397
         }
    
    355 398
     
    
    ... ... @@ -358,6 +401,7 @@ const SurveyArea = {
    358 401
         // Instead we only translate the banner into a limited set of locales that
    
    359 402
         // match the languages that the survey itself supports. This should match
    
    360 403
         // the language of the survey when it is opened by the user.
    
    404
    +    this._localeData = this._localeDataSet[0];
    
    361 405
         const pageLocale = document.documentElement.getAttribute("lang");
    
    362 406
         for (const localeData of this._localeDataSet) {
    
    363 407
           if (localeData.browserLocales.includes(pageLocale)) {
    
    ... ... @@ -365,10 +409,6 @@ const SurveyArea = {
    365 409
             break;
    
    366 410
           }
    
    367 411
         }
    
    368
    -    if (!this._localeData) {
    
    369
    -      // Show the default en-US banner.
    
    370
    -      this._localeData = this._localeDataSet[0];
    
    371
    -    }
    
    372 412
     
    
    373 413
         // Make sure the survey's lang and dir attributes match the chosen locale.
    
    374 414
         const surveyEl = document.getElementById("survey");
    
    ... ... @@ -403,5 +443,5 @@ window.addEventListener("InitialData", event => {
    403 443
       } = event.detail;
    
    404 444
       SearchWidget.setOnionizeState(!!searchOnionize);
    
    405 445
       MessageArea.setMessageData(messageData, !!isStable, !!torConnectEnabled);
    
    406
    -  SurveyArea.potentiallyShow(surveyDismissVersion, isStable);
    
    446
    +  SurveyArea.setData(surveyDismissVersion, isStable);
    
    407 447
     });