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

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/contentscripts", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "constof_RunAt": (ref: heap.Ref<string>): number => {
     8        const idx = ["document_idle", "document_start", "document_end"].indexOf(A.H.get(ref));
     9        return idx < 0 ? 0 : idx + 1;
    10      },
    11  
    12      "store_ContentScript": (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 + 39, false);
    17          A.store.Ref(ptr + 0, undefined);
    18          A.store.Ref(ptr + 4, undefined);
    19          A.store.Ref(ptr + 8, undefined);
    20          A.store.Ref(ptr + 12, undefined);
    21          A.store.Bool(ptr + 36, false);
    22          A.store.Bool(ptr + 16, false);
    23          A.store.Bool(ptr + 37, false);
    24          A.store.Bool(ptr + 17, false);
    25          A.store.Bool(ptr + 38, false);
    26          A.store.Bool(ptr + 18, false);
    27          A.store.Ref(ptr + 20, undefined);
    28          A.store.Ref(ptr + 24, undefined);
    29          A.store.Enum(ptr + 28, -1);
    30          A.store.Enum(ptr + 32, -1);
    31        } else {
    32          A.store.Bool(ptr + 39, true);
    33          A.store.Ref(ptr + 0, x["matches"]);
    34          A.store.Ref(ptr + 4, x["exclude_matches"]);
    35          A.store.Ref(ptr + 8, x["css"]);
    36          A.store.Ref(ptr + 12, x["js"]);
    37          A.store.Bool(ptr + 36, "all_frames" in x ? true : false);
    38          A.store.Bool(ptr + 16, x["all_frames"] ? true : false);
    39          A.store.Bool(ptr + 37, "match_origin_as_fallback" in x ? true : false);
    40          A.store.Bool(ptr + 17, x["match_origin_as_fallback"] ? true : false);
    41          A.store.Bool(ptr + 38, "match_about_blank" in x ? true : false);
    42          A.store.Bool(ptr + 18, x["match_about_blank"] ? true : false);
    43          A.store.Ref(ptr + 20, x["include_globs"]);
    44          A.store.Ref(ptr + 24, x["exclude_globs"]);
    45          A.store.Enum(ptr + 28, ["document_idle", "document_start", "document_end"].indexOf(x["run_at"] as string));
    46          A.store.Enum(ptr + 32, ["ISOLATED", "MAIN"].indexOf(x["world"] as string));
    47        }
    48      },
    49      "load_ContentScript": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    50        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    51  
    52        x["matches"] = A.load.Ref(ptr + 0, undefined);
    53        x["exclude_matches"] = A.load.Ref(ptr + 4, undefined);
    54        x["css"] = A.load.Ref(ptr + 8, undefined);
    55        x["js"] = A.load.Ref(ptr + 12, undefined);
    56        if (A.load.Bool(ptr + 36)) {
    57          x["all_frames"] = A.load.Bool(ptr + 16);
    58        } else {
    59          delete x["all_frames"];
    60        }
    61        if (A.load.Bool(ptr + 37)) {
    62          x["match_origin_as_fallback"] = A.load.Bool(ptr + 17);
    63        } else {
    64          delete x["match_origin_as_fallback"];
    65        }
    66        if (A.load.Bool(ptr + 38)) {
    67          x["match_about_blank"] = A.load.Bool(ptr + 18);
    68        } else {
    69          delete x["match_about_blank"];
    70        }
    71        x["include_globs"] = A.load.Ref(ptr + 20, undefined);
    72        x["exclude_globs"] = A.load.Ref(ptr + 24, undefined);
    73        x["run_at"] = A.load.Enum(ptr + 28, ["document_idle", "document_start", "document_end"]);
    74        x["world"] = A.load.Enum(ptr + 32, ["ISOLATED", "MAIN"]);
    75        return create === A.H.TRUE ? A.H.push(x) : ref;
    76      },
    77  
    78      "store_ManifestKeys": (ptr: Pointer, ref: heap.Ref<any>) => {
    79        const x = A.H.get<any>(ref);
    80  
    81        if (typeof x === "undefined") {
    82          A.store.Bool(ptr + 4, false);
    83          A.store.Ref(ptr + 0, undefined);
    84        } else {
    85          A.store.Bool(ptr + 4, true);
    86          A.store.Ref(ptr + 0, x["content_scripts"]);
    87        }
    88      },
    89      "load_ManifestKeys": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    90        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    91  
    92        x["content_scripts"] = A.load.Ref(ptr + 0, undefined);
    93        return create === A.H.TRUE ? A.H.push(x) : ref;
    94      },
    95    };
    96  });