tor-browser

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

DragParentContextBase.sys.mjs (1736B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /* global content */
      7 
      8 // Common base of DragSourceParentContext and DragTargetParentContext
      9 export class DragParentContextBase {
     10  // The name of the subtype of this object.
     11  subtypeName = "";
     12 
     13  // Browsing context that the related element is in
     14  browsingContext = null;
     15 
     16  constructor(aSubtypeName, aBrowsingContext, aParams, aSpecialPowers) {
     17    Object.assign(this, aParams);
     18    this.params = aParams;
     19    this.subtypeName = aSubtypeName;
     20    this.browsingContext = aBrowsingContext;
     21    this.specialPowers = aSpecialPowers;
     22  }
     23 
     24  getElementPositions() {
     25    return this.runRemote("getElementPositions");
     26  }
     27 
     28  expect(aMsgType) {
     29    return this.runRemote("expect", aMsgType);
     30  }
     31 
     32  checkExpected() {
     33    return this.runRemote("checkExpected");
     34  }
     35 
     36  checkHasDrag(aShouldHaveDrag) {
     37    return this.runRemote("checkHasDrag", aShouldHaveDrag);
     38  }
     39 
     40  checkSessionHasAction() {
     41    return this.runRemote("checkSessionHasAction");
     42  }
     43 
     44  synchronize() {
     45    return this.runRemoteFn(() => {});
     46  }
     47 
     48  cleanup() {
     49    return this.runRemote("cleanup");
     50  }
     51 
     52  runRemote(aFnName, aParams = []) {
     53    let args = [this.subtypeName, aFnName].concat(aParams);
     54    return this.specialPowers.spawn(
     55      this.browsingContext,
     56      args,
     57      (subtypeName, fnName, ...params) => {
     58        return content.window[subtypeName][fnName](...params);
     59      }
     60    );
     61  }
     62 
     63  runRemoteFn(fn, params = []) {
     64    return this.specialPowers.spawn(this.browsingContext, params, fn);
     65  }
     66 }