tor-browser

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

fetchScopes.js (1757B)


      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 import {
      6  getGeneratedFrameScope,
      7  getOriginalFrameScope,
      8  getSelectedFrame,
      9 } from "../../selectors/index";
     10 import { mapScopes } from "./mapScopes";
     11 import { generateInlinePreview } from "./inlinePreview";
     12 const {
     13  PROMISE,
     14 } = require("resource://devtools/client/shared/redux/middleware/promise.js");
     15 import { validateSelectedFrame } from "../../utils/context";
     16 
     17 /**
     18 * Retrieve the scopes and map them for the currently selected frame.
     19 * Once this is done, update the inline previews.
     20 */
     21 export function fetchScopes() {
     22  return async function ({ dispatch, getState, client }) {
     23    const selectedFrame = getSelectedFrame(getState());
     24    // See if we already fetched the scopes.
     25    // We may have pause on multiple thread and re-select a paused thread
     26    // for which we already fetched the scopes.
     27    // Ignore pending scopes as the previous action may have been cancelled
     28    // by context assertions.
     29    let scopes = getGeneratedFrameScope(getState(), selectedFrame);
     30    if (!scopes?.scope) {
     31      scopes = dispatch({
     32        type: "ADD_SCOPES",
     33        selectedFrame,
     34        [PROMISE]: client.getFrameScopes(selectedFrame),
     35      });
     36 
     37      scopes.then(() => {
     38        // Avoid generating previews, if we resumed or switched to another frame while retrieving scopes
     39        validateSelectedFrame(getState(), selectedFrame);
     40 
     41        dispatch(generateInlinePreview(selectedFrame));
     42      });
     43    }
     44 
     45    if (!getOriginalFrameScope(getState(), selectedFrame)) {
     46      await dispatch(mapScopes(selectedFrame, scopes));
     47    }
     48  };
     49 }