mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
This reverts commit 8d2803c179
.
This commit is contained in:
parent
68e1958005
commit
ba4f56fbf7
@ -32,7 +32,6 @@ import {
|
|||||||
import { checkForLastErrorAndLog } from '../../shared/modules/browser-runtime.utils';
|
import { checkForLastErrorAndLog } from '../../shared/modules/browser-runtime.utils';
|
||||||
import { isManifestV3 } from '../../shared/modules/mv3.utils';
|
import { isManifestV3 } from '../../shared/modules/mv3.utils';
|
||||||
import { maskObject } from '../../shared/modules/object.utils';
|
import { maskObject } from '../../shared/modules/object.utils';
|
||||||
import { getEnvironmentType, deferredPromise, getPlatform } from './lib/util';
|
|
||||||
import migrations from './migrations';
|
import migrations from './migrations';
|
||||||
import Migrator from './lib/migrator';
|
import Migrator from './lib/migrator';
|
||||||
import ExtensionPlatform from './platforms/extension';
|
import ExtensionPlatform from './platforms/extension';
|
||||||
@ -51,6 +50,7 @@ import rawFirstTimeState from './first-time-state';
|
|||||||
import getFirstPreferredLangCode from './lib/get-first-preferred-lang-code';
|
import getFirstPreferredLangCode from './lib/get-first-preferred-lang-code';
|
||||||
import getObjStructure from './lib/getObjStructure';
|
import getObjStructure from './lib/getObjStructure';
|
||||||
import setupEnsIpfsResolver from './lib/ens-ipfs/setup';
|
import setupEnsIpfsResolver from './lib/ens-ipfs/setup';
|
||||||
|
import { deferredPromise, getPlatform } from './lib/util';
|
||||||
|
|
||||||
/* eslint-enable import/first */
|
/* eslint-enable import/first */
|
||||||
|
|
||||||
@ -84,7 +84,6 @@ let popupIsOpen = false;
|
|||||||
let notificationIsOpen = false;
|
let notificationIsOpen = false;
|
||||||
let uiIsTriggering = false;
|
let uiIsTriggering = false;
|
||||||
const openMetamaskTabsIDs = {};
|
const openMetamaskTabsIDs = {};
|
||||||
const openMetamaskConnections = new Map();
|
|
||||||
const requestAccountTabIds = {};
|
const requestAccountTabIds = {};
|
||||||
let controller;
|
let controller;
|
||||||
|
|
||||||
@ -185,28 +184,10 @@ let connectExternal;
|
|||||||
browser.runtime.onConnect.addListener(async (...args) => {
|
browser.runtime.onConnect.addListener(async (...args) => {
|
||||||
// Queue up connection attempts here, waiting until after initialization
|
// Queue up connection attempts here, waiting until after initialization
|
||||||
await isInitialized;
|
await isInitialized;
|
||||||
const remotePort = args[0];
|
|
||||||
const { sender } = remotePort;
|
|
||||||
|
|
||||||
const url = sender?.url;
|
|
||||||
const detectedProcessName = url ? getEnvironmentType(url) : '';
|
|
||||||
|
|
||||||
const connectionId = generateConnectionId(remotePort, detectedProcessName);
|
|
||||||
const openConnections = openMetamaskConnections.get(connectionId) || 0;
|
|
||||||
|
|
||||||
if (
|
|
||||||
openConnections === 0 ||
|
|
||||||
(detectedProcessName === 'background' && openConnections < 2)
|
|
||||||
// 2 background connections are allowed, one for phishing warning page and one for the ledger bridge keyring
|
|
||||||
) {
|
|
||||||
// This is set in `setupController`, which is called as part of initialization
|
// This is set in `setupController`, which is called as part of initialization
|
||||||
connectRemote(...args);
|
connectRemote(...args);
|
||||||
openMetamaskConnections.set(connectionId, openConnections + 1);
|
|
||||||
} else {
|
|
||||||
throw new Error('CONNECTION_ALREADY_EXISTS');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.runtime.onConnectExternal.addListener(async (...args) => {
|
browser.runtime.onConnectExternal.addListener(async (...args) => {
|
||||||
// Queue up connection attempts here, waiting until after initialization
|
// Queue up connection attempts here, waiting until after initialization
|
||||||
await isInitialized;
|
await isInitialized;
|
||||||
@ -435,21 +416,6 @@ export async function loadStateFromPersistence() {
|
|||||||
return versionedData.data;
|
return versionedData.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateConnectionId(remotePort, detectedProcessName) {
|
|
||||||
const { sender } = remotePort;
|
|
||||||
const id = sender?.tab ? sender.tab.id : sender?.id;
|
|
||||||
if (!id || !detectedProcessName) {
|
|
||||||
console.error(
|
|
||||||
'Must provide id and detectedProcessName to generate connection id.',
|
|
||||||
id,
|
|
||||||
detectedProcessName,
|
|
||||||
); // eslint-disable-line no-console
|
|
||||||
throw new Error(
|
|
||||||
'Must provide id and detectedProcessName to generate connection id.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return `${id}-${detectedProcessName}`;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Initializes the MetaMask Controller with any initial state and default language.
|
* Initializes the MetaMask Controller with any initial state and default language.
|
||||||
* Configures platform-specific error reporting strategy.
|
* Configures platform-specific error reporting strategy.
|
||||||
@ -604,6 +570,7 @@ export function setupController(
|
|||||||
// communication with popup
|
// communication with popup
|
||||||
controller.isClientOpen = true;
|
controller.isClientOpen = true;
|
||||||
controller.setupTrustedCommunication(portStream, remotePort.sender);
|
controller.setupTrustedCommunication(portStream, remotePort.sender);
|
||||||
|
|
||||||
if (isManifestV3) {
|
if (isManifestV3) {
|
||||||
// If we get a WORKER_KEEP_ALIVE message, we respond with an ACK
|
// If we get a WORKER_KEEP_ALIVE message, we respond with an ACK
|
||||||
remotePort.onMessage.addListener((message) => {
|
remotePort.onMessage.addListener((message) => {
|
||||||
@ -618,11 +585,9 @@ export function setupController(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectionId = generateConnectionId(remotePort, processName);
|
|
||||||
if (processName === ENVIRONMENT_TYPE_POPUP) {
|
if (processName === ENVIRONMENT_TYPE_POPUP) {
|
||||||
popupIsOpen = true;
|
popupIsOpen = true;
|
||||||
endOfStream(portStream, () => {
|
endOfStream(portStream, () => {
|
||||||
openMetamaskConnections.set(connectionId, 0);
|
|
||||||
popupIsOpen = false;
|
popupIsOpen = false;
|
||||||
const isClientOpen = isClientOpenStatus();
|
const isClientOpen = isClientOpenStatus();
|
||||||
controller.isClientOpen = isClientOpen;
|
controller.isClientOpen = isClientOpen;
|
||||||
@ -632,8 +597,8 @@ export function setupController(
|
|||||||
|
|
||||||
if (processName === ENVIRONMENT_TYPE_NOTIFICATION) {
|
if (processName === ENVIRONMENT_TYPE_NOTIFICATION) {
|
||||||
notificationIsOpen = true;
|
notificationIsOpen = true;
|
||||||
|
|
||||||
endOfStream(portStream, () => {
|
endOfStream(portStream, () => {
|
||||||
openMetamaskConnections.set(connectionId, 0);
|
|
||||||
notificationIsOpen = false;
|
notificationIsOpen = false;
|
||||||
const isClientOpen = isClientOpenStatus();
|
const isClientOpen = isClientOpenStatus();
|
||||||
controller.isClientOpen = isClientOpen;
|
controller.isClientOpen = isClientOpen;
|
||||||
@ -649,7 +614,6 @@ export function setupController(
|
|||||||
openMetamaskTabsIDs[tabId] = true;
|
openMetamaskTabsIDs[tabId] = true;
|
||||||
|
|
||||||
endOfStream(portStream, () => {
|
endOfStream(portStream, () => {
|
||||||
openMetamaskConnections.set(connectionId, 0);
|
|
||||||
delete openMetamaskTabsIDs[tabId];
|
delete openMetamaskTabsIDs[tabId];
|
||||||
const isClientOpen = isClientOpenStatus();
|
const isClientOpen = isClientOpenStatus();
|
||||||
controller.isClientOpen = isClientOpen;
|
controller.isClientOpen = isClientOpen;
|
||||||
|
Loading…
Reference in New Issue
Block a user