tor-browser

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

ui.js (5779B)


      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 const {
      7  ACTIVITY_TYPE,
      8  OPEN_NETWORK_DETAILS,
      9  RESIZE_NETWORK_DETAILS,
     10  ENABLE_PERSISTENT_LOGS,
     11  DISABLE_BROWSER_CACHE,
     12  OPEN_STATISTICS,
     13  RESET_COLUMNS,
     14  SELECT_DETAILS_PANEL_TAB,
     15  SELECT_ACTION_BAR_TAB,
     16  TOGGLE_COLUMN,
     17  WATERFALL_RESIZE,
     18  SET_COLUMNS_WIDTH,
     19  SET_HEADERS_URL_PREVIEW_EXPANDED,
     20  SET_DEFAULT_RAW_RESPONSE,
     21  OPEN_ACTION_BAR,
     22 } = require("resource://devtools/client/netmonitor/src/constants.js");
     23 
     24 const {
     25  getDisplayedRequests,
     26 } = require("resource://devtools/client/netmonitor/src/selectors/index.js");
     27 
     28 const DEVTOOLS_DISABLE_CACHE_PREF = "devtools.cache.disabled";
     29 
     30 /**
     31 * Change network details panel.
     32 *
     33 * @param {boolean} open - expected network details panel open state
     34 */
     35 function openNetworkDetails(open) {
     36  return ({ dispatch, getState }) => {
     37    const visibleRequestItems = getDisplayedRequests(getState());
     38    const defaultSelectedId = visibleRequestItems.length
     39      ? visibleRequestItems[0].id
     40      : null;
     41 
     42    return dispatch({
     43      type: OPEN_NETWORK_DETAILS,
     44      open,
     45      defaultSelectedId,
     46    });
     47  };
     48 }
     49 
     50 /**
     51 * Change network action bar open state.
     52 *
     53 * @param {boolean} open - expected network action bar open state
     54 */
     55 function openNetworkActionBar(open) {
     56  return {
     57    type: OPEN_ACTION_BAR,
     58    open,
     59  };
     60 }
     61 
     62 /**
     63 * Change network details panel size.
     64 *
     65 * @param {integer} width
     66 * @param {integer} height
     67 */
     68 function resizeNetworkDetails(width, height) {
     69  return {
     70    type: RESIZE_NETWORK_DETAILS,
     71    width,
     72    height,
     73  };
     74 }
     75 
     76 /**
     77 * Change persistent logs state.
     78 *
     79 * @param {boolean} enabled - expected persistent logs enabled state
     80 */
     81 function enablePersistentLogs(enabled, skipTelemetry = false) {
     82  return {
     83    type: ENABLE_PERSISTENT_LOGS,
     84    enabled,
     85    skipTelemetry,
     86  };
     87 }
     88 
     89 /**
     90 * Change browser cache state.
     91 *
     92 * @param {boolean} disabled - expected browser cache in disable state
     93 */
     94 function disableBrowserCache(disabled) {
     95  return {
     96    type: DISABLE_BROWSER_CACHE,
     97    disabled,
     98  };
     99 }
    100 
    101 /**
    102 * Change performance statistics panel open state.
    103 *
    104 * @param {object} connector - connector object to the backend
    105 * @param {boolean} visible - expected performance statistics panel open state
    106 */
    107 function openStatistics(connector, open) {
    108  if (open) {
    109    connector.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED);
    110  } else if (Services.prefs.getBoolPref(DEVTOOLS_DISABLE_CACHE_PREF)) {
    111    // Opening the Statistics panel reconfigures the page and enables
    112    // the browser cache (using ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED).
    113    // So, make sure to disable the cache again when the user returns back
    114    // from the Statistics panel (if DEVTOOLS_DISABLE_CACHE_PREF == true).
    115    // See also bug 1430359.
    116    connector.triggerActivity(ACTIVITY_TYPE.DISABLE_CACHE);
    117  }
    118  return {
    119    type: OPEN_STATISTICS,
    120    open,
    121  };
    122 }
    123 
    124 /**
    125 * Resets all columns to their default state.
    126 *
    127 */
    128 function resetColumns() {
    129  return {
    130    type: RESET_COLUMNS,
    131  };
    132 }
    133 
    134 /**
    135 * Waterfall width has changed (likely on window resize). Update the UI.
    136 */
    137 function resizeWaterfall(width) {
    138  return {
    139    type: WATERFALL_RESIZE,
    140    width,
    141  };
    142 }
    143 
    144 /**
    145 * Change the selected tab for network details panel.
    146 *
    147 * @param {string} id - tab id to be selected
    148 */
    149 function selectDetailsPanelTab(id) {
    150  return {
    151    type: SELECT_DETAILS_PANEL_TAB,
    152    id,
    153  };
    154 }
    155 
    156 /**
    157 * Change the selected tab for network action bar.
    158 *
    159 * @param {string} id - tab id to be selected
    160 */
    161 function selectActionBarTab(id) {
    162  return {
    163    type: SELECT_ACTION_BAR_TAB,
    164    id,
    165  };
    166 }
    167 
    168 /**
    169 * Toggles a column
    170 *
    171 * @param {string} column - The column that is going to be toggled
    172 */
    173 function toggleColumn(column) {
    174  return {
    175    type: TOGGLE_COLUMN,
    176    column,
    177  };
    178 }
    179 
    180 /**
    181 * Set width of multiple columns
    182 *
    183 * @param {Array} widths - array of pairs {name, width}
    184 */
    185 function setColumnsWidth(widths) {
    186  return {
    187    type: SET_COLUMNS_WIDTH,
    188    widths,
    189  };
    190 }
    191 
    192 /**
    193 * Toggle network details panel.
    194 */
    195 function toggleNetworkDetails() {
    196  return ({ dispatch, getState }) =>
    197    dispatch(openNetworkDetails(!getState().ui.networkDetailsOpen));
    198 }
    199 
    200 /**
    201 * Toggle network action panel.
    202 */
    203 function toggleNetworkActionBar() {
    204  return ({ dispatch, getState }) =>
    205    dispatch(openNetworkActionBar(!getState().ui.networkActionOpen));
    206 }
    207 
    208 /**
    209 * Toggle persistent logs status.
    210 */
    211 function togglePersistentLogs() {
    212  return ({ dispatch, getState }) =>
    213    dispatch(enablePersistentLogs(!getState().ui.persistentLogsEnabled));
    214 }
    215 
    216 /**
    217 * Toggle browser cache status.
    218 */
    219 function toggleBrowserCache() {
    220  return ({ dispatch, getState }) =>
    221    dispatch(disableBrowserCache(!getState().ui.browserCacheDisabled));
    222 }
    223 
    224 /**
    225 * Toggle performance statistics panel.
    226 */
    227 function toggleStatistics(connector) {
    228  return ({ dispatch, getState }) =>
    229    dispatch(openStatistics(connector, !getState().ui.statisticsOpen));
    230 }
    231 
    232 function setHeadersUrlPreviewExpanded(expanded) {
    233  return {
    234    type: SET_HEADERS_URL_PREVIEW_EXPANDED,
    235    expanded,
    236  };
    237 }
    238 
    239 function setDefaultRawResponse(enabled) {
    240  return {
    241    type: SET_DEFAULT_RAW_RESPONSE,
    242    enabled,
    243  };
    244 }
    245 
    246 module.exports = {
    247  openNetworkDetails,
    248  openNetworkActionBar,
    249  resizeNetworkDetails,
    250  enablePersistentLogs,
    251  disableBrowserCache,
    252  openStatistics,
    253  resetColumns,
    254  resizeWaterfall,
    255  selectDetailsPanelTab,
    256  selectActionBarTab,
    257  toggleColumn,
    258  setColumnsWidth,
    259  toggleNetworkDetails,
    260  toggleNetworkActionBar,
    261  togglePersistentLogs,
    262  toggleBrowserCache,
    263  toggleStatistics,
    264  setHeadersUrlPreviewExpanded,
    265  setDefaultRawResponse,
    266 };