tor-browser

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

tab-component-data.js (1270B)


      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 "use strict";
      6 
      7 const {
      8  DEBUG_TARGETS,
      9  REQUEST_TABS_SUCCESS,
     10 } = require("resource://devtools/client/aboutdebugging/src/constants.js");
     11 
     12 /**
     13 * This middleware converts tabs object that get from DevToolsClient.listTabs() to data
     14 * which is used in DebugTargetItem.
     15 */
     16 const tabComponentDataMiddleware = () => next => action => {
     17  switch (action.type) {
     18    case REQUEST_TABS_SUCCESS: {
     19      action.tabs = toComponentData(action.tabs);
     20      break;
     21    }
     22  }
     23 
     24  return next(action);
     25 };
     26 
     27 function toComponentData(tabs) {
     28  return tabs.map(tab => {
     29    const type = DEBUG_TARGETS.TAB;
     30    const id = tab.browserId;
     31    const icon = tab.favicon
     32      ? `data:image/png;base64,${btoa(
     33          String.fromCharCode.apply(String, tab.favicon)
     34        )}`
     35      : "chrome://devtools/skin/images/globe.svg";
     36    const name = tab.title || tab.url;
     37    const { url, isZombieTab } = tab;
     38    return {
     39      name,
     40      icon,
     41      id,
     42      type,
     43      details: {
     44        isZombieTab,
     45        url,
     46      },
     47    };
     48  });
     49 }
     50 
     51 module.exports = tabComponentDataMiddleware;