Explorar el Código

fix: remove the unused context param

tophf hace 3 años
padre
commit
0d9e94ddc1

+ 2 - 2
src/injected/util/index.js

@@ -40,10 +40,10 @@ export const bindEvents = (srcId, destId, bridge) => {
       incomingNodeEvent = null;
     }
   }, true);
-  bridge.post = (cmd, data, { dataKey } = bridge, node) => {
+  bridge.post = (cmd, data, realm, node) => {
     // Constructing the event now so we don't send anything if it throws on invalid `node`
     const evtNode = node && new SafeMouseEvent(destId, { __proto__: null, relatedTarget: node });
-    fireBridgeEvent(destId, { cmd, data, dataKey, node: !!evtNode });
+    fireBridgeEvent(destId, { cmd, data, node: !!evtNode });
     if (evtNode) window::fire(evtNode);
   };
 };

+ 4 - 4
src/injected/web/bridge.js

@@ -19,7 +19,7 @@ const bridge = {
     const fn = handlers[cmd];
     if (fn) node::fn(data);
   },
-  send(cmd, data, context, node) {
+  send(cmd, data, node) {
     let cb;
     let res;
     try {
@@ -29,7 +29,7 @@ const bridge = {
     } catch (e) {
       // Unavoidable since vault's Promise can't be used after the iframe is removed
     }
-    postWithCallback(cmd, data, context, node, cb);
+    postWithCallback(cmd, data, node, cb);
     return res;
   },
   call: postWithCallback,
@@ -37,7 +37,7 @@ const bridge = {
 
 let callbackResult;
 
-function postWithCallback(cmd, data, context, node, cb, customCallbackId) {
+function postWithCallback(cmd, data, node, cb, customCallbackId) {
   const id = safeGetUniqId();
   callbacks[id] = cb || defaultCallback;
   if (customCallbackId) {
@@ -45,7 +45,7 @@ function postWithCallback(cmd, data, context, node, cb, customCallbackId) {
   } else {
     data = { [CALLBACK_ID]: id, data };
   }
-  bridge.post(cmd, data, context, node);
+  bridge.post(cmd, data, node);
   if (!cb) return callbackResult;
 }
 

+ 2 - 3
src/injected/web/gm-api-wrapper.js

@@ -41,7 +41,6 @@ export function makeGmApiWrapper(script) {
     id,
     script,
     resources,
-    dataKey: script.dataKey,
     resCache: createNullObj(),
   };
   const gmInfo = makeGmInfo(script.gmInfo, meta, resources);
@@ -59,10 +58,10 @@ export function makeGmApiWrapper(script) {
   }
   assign(gm, componentUtils);
   if (grant::indexOf(WINDOW_CLOSE) >= 0) {
-    gm.close = vmOwnFunc(() => bridge.post('TabClose', 0, context));
+    gm.close = vmOwnFunc(() => bridge.post('TabClose'));
   }
   if (grant::indexOf(WINDOW_FOCUS) >= 0) {
-    gm.focus = vmOwnFunc(() => bridge.post('TabFocus', 0, context));
+    gm.focus = vmOwnFunc(() => bridge.post('TabFocus'));
   }
   if (!gmApi && numGrants) gmApi = makeGmApi();
   grant::forEach((name) => {

+ 12 - 12
src/injected/web/gm-api.js

@@ -88,14 +88,14 @@ export function makeGmApi() {
       const { id } = this;
       const key = `${id}:${cap}`;
       store.commands[key] = func;
-      bridge.post('RegisterMenu', { id, cap }, this);
+      bridge.post('RegisterMenu', { id, cap });
       return cap;
     },
     GM_unregisterMenuCommand(cap) {
       const { id } = this;
       const key = `${id}:${cap}`;
       delete store.commands[key];
-      bridge.post('UnregisterMenu', { id, cap }, this);
+      bridge.post('UnregisterMenu', { id, cap });
     },
     GM_download(arg1, name) {
       // not using ... as it calls Babel's polyfill that calls unsafe Object.xxx
@@ -141,8 +141,8 @@ export function makeGmApi() {
      */
     GM_addElement(parent, tag, attributes) {
       return isString(parent)
-        ? webAddElement(null, parent, tag, this)
-        : webAddElement(parent, tag, attributes, this);
+        ? webAddElement(null, parent, tag)
+        : webAddElement(parent, tag, attributes);
     },
     /**
      * Bypasses site's CSP for inline `style`.
@@ -150,12 +150,12 @@ export function makeGmApi() {
      * @returns {HTMLElement} it also has .then() so it should be compatible with TM and old VM
      */
     GM_addStyle(css) {
-      return webAddElement(null, 'style', { textContent: css, id: safeGetUniqId('VMst') }, this);
+      return webAddElement(null, 'style', { textContent: css, id: safeGetUniqId('VMst') });
     },
     GM_openInTab(url, options) {
       options = createNullObj(isObject(options) ? options : { active: !options });
       options.url = url;
-      return onTabCreate(options, this);
+      return onTabCreate(options);
     },
     GM_notification(text, title, image, onclick) {
       const options = isObject(text) ? text : {
@@ -168,23 +168,23 @@ export function makeGmApi() {
       if (!options.text) {
         throw new SafeError('GM_notification: `text` is required!');
       }
-      const id = onNotificationCreate(options, this);
+      const id = onNotificationCreate(options);
       return {
-        remove: vmOwnFunc(() => bridge.send('RemoveNotification', id, this)),
+        remove: vmOwnFunc(() => bridge.send('RemoveNotification', id)),
       };
     },
     GM_setClipboard(data, type) {
-      bridge.post('SetClipboard', { data, type }, this);
+      bridge.post('SetClipboard', { data, type });
     },
     // using the native console.log so the output has a clickable link to the caller's source
     GM_log: logging.log,
   };
 }
 
-function webAddElement(parent, tag, attrs, context) {
+function webAddElement(parent, tag, attrs) {
   let el;
   let errorInfo;
-  bridge.call('AddElement', { tag, attrs }, context, parent, function _(res) {
+  bridge.call('AddElement', { tag, attrs }, parent, function _(res) {
     el = this;
     errorInfo = res;
   }, 'cbId');
@@ -222,7 +222,7 @@ function getResource(context, name, isBlob, isBlobAuto) {
     const bucketKey = isBlob == null ? 0 : 1 + (isBlob = isBlobAuto ? !isData : isBlob);
     res = isData && isBlob === false || ensureNestedProp(resCache, bucketKey, key, false);
     if (!res) {
-      res = bridge.call('GetResource', { id, isBlob, key, raw: isData && key }, context);
+      res = bridge.call('GetResource', { id, isBlob, key, raw: isData && key });
       if (res !== true && isBlob) {
         // Creating Blob URL in page context to make it accessible for page userscripts
         res = createObjectURL(res);

+ 3 - 4
src/injected/web/index.js

@@ -27,11 +27,10 @@ export default function initialize(
     }, { __proto__: null, once: true, capture: true });
     window::fire(new SafeCustomEvent(PAGE_MODE_HANDSHAKE));
   }
-  bridge.dataKey = contentId;
   if (invokeHost) {
     bridge.mode = INJECT_CONTENT;
-    bridge.post = (cmd, data, context, node) => {
-      invokeHost({ cmd, data, node, dataKey: (context || bridge).dataKey }, INJECT_CONTENT);
+    bridge.post = (cmd, data, node) => {
+      invokeHost({ cmd, data, node }, INJECT_CONTENT);
     };
     invokeGuest = (cmd, data, realm, node) => {
       if (process.env.DEBUG) console.info('[bridge.guest.content] received', { cmd, data, node });
@@ -117,7 +116,7 @@ async function onCodeSet(item, fn) {
     log('info', [bridge.mode], item.displayName);
   }
   const run = () => {
-    bridge.post('Run', item.props.id, item);
+    bridge.post('Run', item.props.id);
     const { gm, wrapper } = makeGmApiWrapper(item);
     (wrapper || global)::fn(gm, logging.error);
   };

+ 2 - 2
src/injected/web/notifications.js

@@ -18,7 +18,7 @@ bridge.addHandlers({
   },
 });
 
-export function onNotificationCreate(options, context) {
+export function onNotificationCreate(options) {
   lastId += 1;
   notifications[lastId] = options;
   bridge.post('Notification', {
@@ -26,6 +26,6 @@ export function onNotificationCreate(options, context) {
     text: options.text,
     title: options.title,
     image: options.image,
-  }, context);
+  });
   return lastId;
 }

+ 2 - 2
src/injected/web/requests.js

@@ -46,7 +46,7 @@ export function onRequestCreate(opts, context, fileName) {
   start(req, context, fileName);
   return {
     abort() {
-      bridge.post('AbortRequest', id, context);
+      bridge.post('AbortRequest', id);
     },
   };
 }
@@ -171,7 +171,7 @@ function start(req, context, fileName) {
     'timeout',
     'url',
     'user',
-  ]), context);
+  ]));
 }
 
 /** Chrome/FF can't directly transfer FormData to isolated world so we explode it,

+ 3 - 3
src/injected/web/tabs.js

@@ -15,17 +15,17 @@ bridge.addHandlers({
   },
 });
 
-export function onTabCreate(data, context) {
+export function onTabCreate(data) {
   lastId += 1;
   const key = lastId;
   const item = {
     onclose: null,
     closed: false,
     close() {
-      bridge.post('TabClose', key, context);
+      bridge.post('TabClose', key);
     },
   };
   tabs[key] = item;
-  bridge.post('TabOpen', { key, data }, context);
+  bridge.post('TabOpen', { key, data });
   return item;
 }

+ 1 - 1
src/types.d.ts

@@ -103,7 +103,7 @@ declare namespace GMReq {
 declare type VMBridgePostFunc = (
   cmd: string,
   data: PlainJSONValue,
-  context?: { dataKey: string },
+  realm?: string,
   node?: Node,
 ) => void;
 //#endregion Generic