github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/declarativecontent/bindings/ffi_bindings.ts (about)

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/declarativecontent", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "constof_PageStateMatcherInstanceType": (ref: heap.Ref<string>): number => {
     8        const idx = ["declarativeContent.PageStateMatcher"].indexOf(A.H.get(ref));
     9        return idx < 0 ? 0 : idx + 1;
    10      },
    11  
    12      "store_PageStateMatcher": (ptr: Pointer, ref: heap.Ref<any>) => {
    13        const x = A.H.get<any>(ref);
    14  
    15        if (typeof x === "undefined") {
    16          A.store.Bool(ptr + 94, false);
    17          A.store.Ref(ptr + 0, undefined);
    18          A.store.Enum(ptr + 4, -1);
    19          A.store.Bool(ptr + 93, false);
    20          A.store.Bool(ptr + 8, false);
    21  
    22          A.store.Bool(ptr + 12 + 0, false);
    23          A.store.Ref(ptr + 12 + 0, undefined);
    24          A.store.Ref(ptr + 12 + 0, undefined);
    25          A.store.Ref(ptr + 12 + 0, undefined);
    26          A.store.Ref(ptr + 12 + 0, undefined);
    27          A.store.Ref(ptr + 12 + 0, undefined);
    28          A.store.Ref(ptr + 12 + 0, undefined);
    29          A.store.Ref(ptr + 12 + 0, undefined);
    30          A.store.Ref(ptr + 12 + 0, undefined);
    31          A.store.Ref(ptr + 12 + 0, undefined);
    32          A.store.Ref(ptr + 12 + 0, undefined);
    33          A.store.Ref(ptr + 12 + 0, undefined);
    34          A.store.Ref(ptr + 12 + 0, undefined);
    35          A.store.Ref(ptr + 12 + 0, undefined);
    36          A.store.Ref(ptr + 12 + 0, undefined);
    37          A.store.Ref(ptr + 12 + 0, undefined);
    38          A.store.Ref(ptr + 12 + 0, undefined);
    39          A.store.Ref(ptr + 12 + 0, undefined);
    40          A.store.Ref(ptr + 12 + 0, undefined);
    41          A.store.Ref(ptr + 12 + 0, undefined);
    42          A.store.Ref(ptr + 12 + 0, undefined);
    43        } else {
    44          A.store.Bool(ptr + 94, true);
    45          A.store.Ref(ptr + 0, x["css"]);
    46          A.store.Enum(ptr + 4, ["declarativeContent.PageStateMatcher"].indexOf(x["instanceType"] as string));
    47          A.store.Bool(ptr + 93, "isBookmarked" in x ? true : false);
    48          A.store.Bool(ptr + 8, x["isBookmarked"] ? true : false);
    49  
    50          if (typeof x["pageUrl"] === "undefined") {
    51            A.store.Bool(ptr + 12 + 0, false);
    52            A.store.Ref(ptr + 12 + 0, undefined);
    53            A.store.Ref(ptr + 12 + 0, undefined);
    54            A.store.Ref(ptr + 12 + 0, undefined);
    55            A.store.Ref(ptr + 12 + 0, undefined);
    56            A.store.Ref(ptr + 12 + 0, undefined);
    57            A.store.Ref(ptr + 12 + 0, undefined);
    58            A.store.Ref(ptr + 12 + 0, undefined);
    59            A.store.Ref(ptr + 12 + 0, undefined);
    60            A.store.Ref(ptr + 12 + 0, undefined);
    61            A.store.Ref(ptr + 12 + 0, undefined);
    62            A.store.Ref(ptr + 12 + 0, undefined);
    63            A.store.Ref(ptr + 12 + 0, undefined);
    64            A.store.Ref(ptr + 12 + 0, undefined);
    65            A.store.Ref(ptr + 12 + 0, undefined);
    66            A.store.Ref(ptr + 12 + 0, undefined);
    67            A.store.Ref(ptr + 12 + 0, undefined);
    68            A.store.Ref(ptr + 12 + 0, undefined);
    69            A.store.Ref(ptr + 12 + 0, undefined);
    70            A.store.Ref(ptr + 12 + 0, undefined);
    71            A.store.Ref(ptr + 12 + 0, undefined);
    72          } else {
    73            A.store.Bool(ptr + 12 + 0, true);
    74            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["hostContains"]);
    75            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["hostEquals"]);
    76            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["hostPrefix"]);
    77            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["hostSuffix"]);
    78            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["originAndPathMatches"]);
    79            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["pathContains"]);
    80            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["pathEquals"]);
    81            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["pathPrefix"]);
    82            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["pathSuffix"]);
    83            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["ports"]);
    84            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["queryContains"]);
    85            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["queryEquals"]);
    86            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["queryPrefix"]);
    87            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["querySuffix"]);
    88            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["schemes"]);
    89            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["urlContains"]);
    90            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["urlEquals"]);
    91            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["urlMatches"]);
    92            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["urlPrefix"]);
    93            A.store.Ref(ptr + 12 + 0, x["pageUrl"]["urlSuffix"]);
    94          }
    95        }
    96      },
    97      "load_PageStateMatcher": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    98        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    99  
   100        x["css"] = A.load.Ref(ptr + 0, undefined);
   101        x["instanceType"] = A.load.Enum(ptr + 4, ["declarativeContent.PageStateMatcher"]);
   102        if (A.load.Bool(ptr + 93)) {
   103          x["isBookmarked"] = A.load.Bool(ptr + 8);
   104        } else {
   105          delete x["isBookmarked"];
   106        }
   107        if (A.load.Bool(ptr + 12 + 0)) {
   108          x["pageUrl"] = {};
   109          x["pageUrl"]["hostContains"] = A.load.Ref(ptr + 12 + 0, undefined);
   110          x["pageUrl"]["hostEquals"] = A.load.Ref(ptr + 12 + 0, undefined);
   111          x["pageUrl"]["hostPrefix"] = A.load.Ref(ptr + 12 + 0, undefined);
   112          x["pageUrl"]["hostSuffix"] = A.load.Ref(ptr + 12 + 0, undefined);
   113          x["pageUrl"]["originAndPathMatches"] = A.load.Ref(ptr + 12 + 0, undefined);
   114          x["pageUrl"]["pathContains"] = A.load.Ref(ptr + 12 + 0, undefined);
   115          x["pageUrl"]["pathEquals"] = A.load.Ref(ptr + 12 + 0, undefined);
   116          x["pageUrl"]["pathPrefix"] = A.load.Ref(ptr + 12 + 0, undefined);
   117          x["pageUrl"]["pathSuffix"] = A.load.Ref(ptr + 12 + 0, undefined);
   118          x["pageUrl"]["ports"] = A.load.Ref(ptr + 12 + 0, undefined);
   119          x["pageUrl"]["queryContains"] = A.load.Ref(ptr + 12 + 0, undefined);
   120          x["pageUrl"]["queryEquals"] = A.load.Ref(ptr + 12 + 0, undefined);
   121          x["pageUrl"]["queryPrefix"] = A.load.Ref(ptr + 12 + 0, undefined);
   122          x["pageUrl"]["querySuffix"] = A.load.Ref(ptr + 12 + 0, undefined);
   123          x["pageUrl"]["schemes"] = A.load.Ref(ptr + 12 + 0, undefined);
   124          x["pageUrl"]["urlContains"] = A.load.Ref(ptr + 12 + 0, undefined);
   125          x["pageUrl"]["urlEquals"] = A.load.Ref(ptr + 12 + 0, undefined);
   126          x["pageUrl"]["urlMatches"] = A.load.Ref(ptr + 12 + 0, undefined);
   127          x["pageUrl"]["urlPrefix"] = A.load.Ref(ptr + 12 + 0, undefined);
   128          x["pageUrl"]["urlSuffix"] = A.load.Ref(ptr + 12 + 0, undefined);
   129        } else {
   130          delete x["pageUrl"];
   131        }
   132        return create === A.H.TRUE ? A.H.push(x) : ref;
   133      },
   134      "constof_RequestContentScriptInstanceType": (ref: heap.Ref<string>): number => {
   135        const idx = ["declarativeContent.RequestContentScript"].indexOf(A.H.get(ref));
   136        return idx < 0 ? 0 : idx + 1;
   137      },
   138  
   139      "store_RequestContentScript": (ptr: Pointer, ref: heap.Ref<any>) => {
   140        const x = A.H.get<any>(ref);
   141  
   142        if (typeof x === "undefined") {
   143          A.store.Bool(ptr + 19, false);
   144          A.store.Bool(ptr + 17, false);
   145          A.store.Bool(ptr + 0, false);
   146          A.store.Ref(ptr + 4, undefined);
   147          A.store.Enum(ptr + 8, -1);
   148          A.store.Ref(ptr + 12, undefined);
   149          A.store.Bool(ptr + 18, false);
   150          A.store.Bool(ptr + 16, false);
   151        } else {
   152          A.store.Bool(ptr + 19, true);
   153          A.store.Bool(ptr + 17, "allFrames" in x ? true : false);
   154          A.store.Bool(ptr + 0, x["allFrames"] ? true : false);
   155          A.store.Ref(ptr + 4, x["css"]);
   156          A.store.Enum(ptr + 8, ["declarativeContent.RequestContentScript"].indexOf(x["instanceType"] as string));
   157          A.store.Ref(ptr + 12, x["js"]);
   158          A.store.Bool(ptr + 18, "matchAboutBlank" in x ? true : false);
   159          A.store.Bool(ptr + 16, x["matchAboutBlank"] ? true : false);
   160        }
   161      },
   162      "load_RequestContentScript": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
   163        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
   164  
   165        if (A.load.Bool(ptr + 17)) {
   166          x["allFrames"] = A.load.Bool(ptr + 0);
   167        } else {
   168          delete x["allFrames"];
   169        }
   170        x["css"] = A.load.Ref(ptr + 4, undefined);
   171        x["instanceType"] = A.load.Enum(ptr + 8, ["declarativeContent.RequestContentScript"]);
   172        x["js"] = A.load.Ref(ptr + 12, undefined);
   173        if (A.load.Bool(ptr + 18)) {
   174          x["matchAboutBlank"] = A.load.Bool(ptr + 16);
   175        } else {
   176          delete x["matchAboutBlank"];
   177        }
   178        return create === A.H.TRUE ? A.H.push(x) : ref;
   179      },
   180      "constof_SetIconInstanceType": (ref: heap.Ref<string>): number => {
   181        const idx = ["declarativeContent.SetIcon"].indexOf(A.H.get(ref));
   182        return idx < 0 ? 0 : idx + 1;
   183      },
   184  
   185      "store_SetIcon": (ptr: Pointer, ref: heap.Ref<any>) => {
   186        const x = A.H.get<any>(ref);
   187  
   188        if (typeof x === "undefined") {
   189          A.store.Bool(ptr + 8, false);
   190          A.store.Ref(ptr + 0, undefined);
   191          A.store.Enum(ptr + 4, -1);
   192        } else {
   193          A.store.Bool(ptr + 8, true);
   194          A.store.Ref(ptr + 0, x["imageData"]);
   195          A.store.Enum(ptr + 4, ["declarativeContent.SetIcon"].indexOf(x["instanceType"] as string));
   196        }
   197      },
   198      "load_SetIcon": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
   199        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
   200  
   201        x["imageData"] = A.load.Ref(ptr + 0, undefined);
   202        x["instanceType"] = A.load.Enum(ptr + 4, ["declarativeContent.SetIcon"]);
   203        return create === A.H.TRUE ? A.H.push(x) : ref;
   204      },
   205      "constof_ShowActionInstanceType": (ref: heap.Ref<string>): number => {
   206        const idx = ["declarativeContent.ShowAction"].indexOf(A.H.get(ref));
   207        return idx < 0 ? 0 : idx + 1;
   208      },
   209  
   210      "store_ShowAction": (ptr: Pointer, ref: heap.Ref<any>) => {
   211        const x = A.H.get<any>(ref);
   212  
   213        if (typeof x === "undefined") {
   214          A.store.Bool(ptr + 4, false);
   215          A.store.Enum(ptr + 0, -1);
   216        } else {
   217          A.store.Bool(ptr + 4, true);
   218          A.store.Enum(ptr + 0, ["declarativeContent.ShowAction"].indexOf(x["instanceType"] as string));
   219        }
   220      },
   221      "load_ShowAction": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
   222        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
   223  
   224        x["instanceType"] = A.load.Enum(ptr + 0, ["declarativeContent.ShowAction"]);
   225        return create === A.H.TRUE ? A.H.push(x) : ref;
   226      },
   227      "constof_ShowPageActionInstanceType": (ref: heap.Ref<string>): number => {
   228        const idx = ["declarativeContent.ShowPageAction"].indexOf(A.H.get(ref));
   229        return idx < 0 ? 0 : idx + 1;
   230      },
   231  
   232      "store_ShowPageAction": (ptr: Pointer, ref: heap.Ref<any>) => {
   233        const x = A.H.get<any>(ref);
   234  
   235        if (typeof x === "undefined") {
   236          A.store.Bool(ptr + 4, false);
   237          A.store.Enum(ptr + 0, -1);
   238        } else {
   239          A.store.Bool(ptr + 4, true);
   240          A.store.Enum(ptr + 0, ["declarativeContent.ShowPageAction"].indexOf(x["instanceType"] as string));
   241        }
   242      },
   243      "load_ShowPageAction": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
   244        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
   245  
   246        x["instanceType"] = A.load.Enum(ptr + 0, ["declarativeContent.ShowPageAction"]);
   247        return create === A.H.TRUE ? A.H.push(x) : ref;
   248      },
   249      "has_OnPageChanged": (): heap.Ref<boolean> => {
   250        if (WEBEXT?.declarativeContent?.onPageChanged && "addListener" in WEBEXT?.declarativeContent?.onPageChanged) {
   251          return A.H.TRUE;
   252        }
   253        return A.H.FALSE;
   254      },
   255      "func_OnPageChanged": (fn: Pointer): void => {
   256        A.store.Ref(fn, WEBEXT.declarativeContent.onPageChanged.addListener);
   257      },
   258      "call_OnPageChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   259        const _ret = WEBEXT.declarativeContent.onPageChanged.addListener(A.H.get<object>(callback));
   260      },
   261      "try_OnPageChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   262        try {
   263          const _ret = WEBEXT.declarativeContent.onPageChanged.addListener(A.H.get<object>(callback));
   264          return A.H.TRUE;
   265        } catch (err: any) {
   266          A.store.Ref(errPtr, err);
   267          return A.H.FALSE;
   268        }
   269      },
   270      "has_OffPageChanged": (): heap.Ref<boolean> => {
   271        if (WEBEXT?.declarativeContent?.onPageChanged && "removeListener" in WEBEXT?.declarativeContent?.onPageChanged) {
   272          return A.H.TRUE;
   273        }
   274        return A.H.FALSE;
   275      },
   276      "func_OffPageChanged": (fn: Pointer): void => {
   277        A.store.Ref(fn, WEBEXT.declarativeContent.onPageChanged.removeListener);
   278      },
   279      "call_OffPageChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   280        const _ret = WEBEXT.declarativeContent.onPageChanged.removeListener(A.H.get<object>(callback));
   281      },
   282      "try_OffPageChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   283        try {
   284          const _ret = WEBEXT.declarativeContent.onPageChanged.removeListener(A.H.get<object>(callback));
   285          return A.H.TRUE;
   286        } catch (err: any) {
   287          A.store.Ref(errPtr, err);
   288          return A.H.FALSE;
   289        }
   290      },
   291      "has_HasOnPageChanged": (): heap.Ref<boolean> => {
   292        if (WEBEXT?.declarativeContent?.onPageChanged && "hasListener" in WEBEXT?.declarativeContent?.onPageChanged) {
   293          return A.H.TRUE;
   294        }
   295        return A.H.FALSE;
   296      },
   297      "func_HasOnPageChanged": (fn: Pointer): void => {
   298        A.store.Ref(fn, WEBEXT.declarativeContent.onPageChanged.hasListener);
   299      },
   300      "call_HasOnPageChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   301        const _ret = WEBEXT.declarativeContent.onPageChanged.hasListener(A.H.get<object>(callback));
   302        A.store.Bool(retPtr, _ret);
   303      },
   304      "try_HasOnPageChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   305        try {
   306          const _ret = WEBEXT.declarativeContent.onPageChanged.hasListener(A.H.get<object>(callback));
   307          A.store.Bool(retPtr, _ret);
   308          return A.H.TRUE;
   309        } catch (err: any) {
   310          A.store.Ref(errPtr, err);
   311          return A.H.FALSE;
   312        }
   313      },
   314    };
   315  });