tor-browser

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

TabListComponent.sys.mjs (3936B)


      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 let log = ChromeUtils.importESModule(
      6  "resource://gre/modules/Log.sys.mjs"
      7 ).Log.repository.getLogger("Sync.RemoteTabs");
      8 
      9 const lazy = {};
     10 
     11 ChromeUtils.defineESModuleGetters(lazy, {
     12  OpenInTabsUtils:
     13    "moz-src:///browser/components/tabbrowser/OpenInTabsUtils.sys.mjs",
     14 });
     15 
     16 /**
     17 * TabListComponent
     18 *
     19 * The purpose of this component is to compose the view, state, and actions.
     20 * It defines high level actions that act on the state and passes them to the
     21 * view for it to trigger during user interaction. It also subscribes the view
     22 * to state changes so it can rerender.
     23 */
     24 
     25 export function TabListComponent({
     26  window,
     27  store,
     28  View,
     29  SyncedTabs,
     30  clipboardHelper,
     31  getChromeWindow,
     32 }) {
     33  this._window = window;
     34  this._store = store;
     35  this._View = View;
     36  this._clipboardHelper = clipboardHelper;
     37  this._getChromeWindow = getChromeWindow;
     38  // used to trigger Sync from context menu
     39  this._SyncedTabs = SyncedTabs;
     40 }
     41 
     42 TabListComponent.prototype = {
     43  get container() {
     44    return this._view.container;
     45  },
     46 
     47  init() {
     48    log.debug("Initializing TabListComponent");
     49 
     50    this._view = new this._View(this._window, {
     51      onSelectRow: (...args) => this.onSelectRow(...args),
     52      onOpenTab: (...args) => this.onOpenTab(...args),
     53      onOpenTabs: (...args) => this.onOpenTabs(...args),
     54      onMoveSelectionDown: (...args) => this.onMoveSelectionDown(...args),
     55      onMoveSelectionUp: (...args) => this.onMoveSelectionUp(...args),
     56      onToggleBranch: (...args) => this.onToggleBranch(...args),
     57      onBookmarkTab: (...args) => this.onBookmarkTab(...args),
     58      onCopyTabLocation: (...args) => this.onCopyTabLocation(...args),
     59      onSyncRefresh: (...args) => this.onSyncRefresh(...args),
     60      onFilter: (...args) => this.onFilter(...args),
     61      onClearFilter: (...args) => this.onClearFilter(...args),
     62      onFilterFocus: (...args) => this.onFilterFocus(...args),
     63      onFilterBlur: (...args) => this.onFilterBlur(...args),
     64    });
     65 
     66    this._store.on("change", state => this._view.render(state));
     67    this._view.render({ clients: [] });
     68    // get what's already available...
     69    this._store.getData();
     70    this._store.focusInput();
     71  },
     72 
     73  uninit() {
     74    this._view.destroy();
     75  },
     76 
     77  onFilter(query) {
     78    this._store.getData(query);
     79  },
     80 
     81  onClearFilter() {
     82    this._store.clearFilter();
     83  },
     84 
     85  onFilterFocus() {
     86    this._store.focusInput();
     87  },
     88 
     89  onFilterBlur() {
     90    this._store.blurInput();
     91  },
     92 
     93  onSelectRow(position) {
     94    this._store.selectRow(position[0], position[1]);
     95  },
     96 
     97  onMoveSelectionDown() {
     98    this._store.moveSelectionDown();
     99  },
    100 
    101  onMoveSelectionUp() {
    102    this._store.moveSelectionUp();
    103  },
    104 
    105  onToggleBranch(id) {
    106    this._store.toggleBranch(id);
    107  },
    108 
    109  onBookmarkTab(uri, title) {
    110    this._window.top.PlacesCommandHook.bookmarkLink(uri, title).catch(
    111      console.error
    112    );
    113  },
    114 
    115  onOpenTab(url, where, params) {
    116    this._window.openTrustedLinkIn(url, where, params);
    117  },
    118 
    119  onOpenTabs(urls, where) {
    120    if (!lazy.OpenInTabsUtils.confirmOpenInTabs(urls.length, this._window)) {
    121      return;
    122    }
    123    if (where == "window") {
    124      this._window.openDialog(
    125        this._window.AppConstants.BROWSER_CHROME_URL,
    126        "_blank",
    127        "chrome,dialog=no,all",
    128        urls.join("|")
    129      );
    130    } else {
    131      let loadInBackground = where == "tabshifted";
    132      this._getChromeWindow(this._window).gBrowser.loadTabs(urls, {
    133        inBackground: loadInBackground,
    134        replace: false,
    135        triggeringPrincipal:
    136          Services.scriptSecurityManager.getSystemPrincipal(),
    137      });
    138    }
    139  },
    140 
    141  onCopyTabLocation(url) {
    142    this._clipboardHelper.copyString(url);
    143  },
    144 
    145  onSyncRefresh() {
    146    this._SyncedTabs.syncTabs(true);
    147  },
    148 };