tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

microsoftAccountIcon.js (1655B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Third-party origin we need to request storage access for.
      6 const STORAGE_ACCESS_ORIGIN = "https://storage.live.com";
      7 
      8 console.warn(
      9  `Firefox calls the Storage Access API on behalf of the site. See https://bugzilla.mozilla.org/show_bug.cgi?id=1728111 for details.`
     10 );
     11 
     12 document.documentElement.addEventListener(
     13  "click",
     14  e => {
     15    const { target, isTrusted } = e;
     16    if (!isTrusted) {
     17      return;
     18    }
     19 
     20    // If the user clicks the login button, we need to get access for storage.
     21    const signInButton = target.closest(
     22      `button[data-bi-id="signedout.hero.signIn"]`
     23    );
     24 
     25    // Also, fall back to calling it when the user clicks the photo in case there are weird login flows we didn't account for.
     26    const initialsButton = target.closest(`#O365_MainLink_MePhoto`);
     27 
     28    // Also handle clicks to the sign in dialog on Bing
     29    const bingSignInButton = target.closest(".id_accountItem");
     30 
     31    // Also handle clicks to the sign in ui on Office.com
     32    const officeSignInUI = target.closest("#mectrl_main_trigger");
     33 
     34    if (
     35      !signInButton &&
     36      !initialsButton &&
     37      !bingSignInButton &&
     38      !officeSignInUI
     39    ) {
     40      return;
     41    }
     42 
     43    console.warn(
     44      "Calling the Storage Access API on behalf of " + STORAGE_ACCESS_ORIGIN
     45    );
     46 
     47    e.stopPropagation();
     48    e.preventDefault();
     49    document.requestStorageAccessForOrigin(STORAGE_ACCESS_ORIGIN).then(() => {
     50      target.click();
     51    });
     52  },
     53  true
     54 );