Skip to content

Commit

Permalink
fix(mv3): ♻️ opposite functionality supportsBlock -> `supportsDecla…
Browse files Browse the repository at this point in the history
…rativeNetRequest`

Signed-off-by: Nishant Arora <[email protected]>
  • Loading branch information
whizzzkid committed Sep 15, 2023
1 parent 68b3da2 commit ec2da96
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { recoveryPagePath } from './constants.js'
import { braveNodeType } from './ipfs-client/brave.js'
import { dropSlash, ipfsUri, pathAtHttpGateway, sameGateway } from './ipfs-path.js'
import { safeURL } from './options.js'
import { addRuleToDynamicRuleSetGenerator, isLocalHost, supportsBlock } from './redirect-handler/blockOrObserve.js'
import { addRuleToDynamicRuleSetGenerator, isLocalHost, supportsDeclarativeNetRequest } from './redirect-handler/blockOrObserve.js'
import { RequestTracker } from './trackers/requestTracker.js'

const log = debug('ipfs-companion:request')
Expand Down Expand Up @@ -488,7 +488,7 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida
async function handleRedirection ({ originUrl, redirectUrl, request }) {
if (redirectUrl !== '' && originUrl !== '' && redirectUrl !== originUrl) {
resolvedRequestTracker.track(request)
if (supportsBlock()) {
if (!supportsDeclarativeNetRequest()) {
return { redirectUrl }
}

Expand Down
8 changes: 4 additions & 4 deletions add-on/src/lib/redirect-handler/blockOrObserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const defaultNSRegexStr = `(${[...DEFAULT_NAMESPACES].join('|')})`
// the way sinon ends up stubbing it, it's not directly available in the global scope on import
// rather it gets replaced dynamically when the module is imported. Which means, we can't
// just check for the existence of the property, we need to call the browser instance at that point.
export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES > 0)
export const supportsDeclarativeNetRequest = (): boolean => browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES > 0

/**
* Sends message to self to notify about change.
Expand All @@ -55,7 +55,7 @@ export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX
*/
async function sendMessageToSelf (msg: messageToSelfType, value?: any): Promise<void> {
// this check ensures we don't send messages to ourselves if blocking mode is enabled.
if (!supportsBlock()) {
if (supportsDeclarativeNetRequest()) {
const message: messageToSelf = { type: msg, value }
// on FF, this call waits for the response from the listener.
// on Chrome, this needs a callback.
Expand Down Expand Up @@ -156,7 +156,7 @@ function constructRegexFilter ({ originUrl, redirectUrl }: IRegexFilter): IFilte

// If the browser supports the declarativeNetRequest API, we can block the request.
export function getExtraInfoSpec<T> (additionalParams: T[] = []): T[] {
if (supportsBlock()) {
if (!supportsDeclarativeNetRequest()) {
return ['blocking' as T, ...additionalParams]
}
return additionalParams
Expand All @@ -182,7 +182,7 @@ function validateIfRuleChanged (rule: browser.DeclarativeNetRequest.Rule): boole
* Clean up all the rules, when extension is disabled.
*/
export async function cleanupRules (resetInMemory: boolean = false): Promise<void> {
if (supportsBlock()) {
if (!supportsDeclarativeNetRequest()) {
return
}
const existingRules = await browser.declarativeNetRequest.getDynamicRules()
Expand Down
18 changes: 9 additions & 9 deletions add-on/src/options/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
/* eslint-env browser, webextensions */

import html from 'choo/html/index.js'
import globalToggleForm from './forms/global-toggle-form.js'
import ipfsNodeForm from './forms/ipfs-node-form.js'
import fileImportForm from './forms/file-import-form.js'
import dnslinkForm from './forms/dnslink-form.js'
import gatewaysForm from './forms/gateways-form.js'
import { supportsDeclarativeNetRequest } from '../lib/redirect-handler/blockOrObserve.js'
import apiForm from './forms/api-form.js'
import dnslinkForm from './forms/dnslink-form.js'
import experimentsForm from './forms/experiments-form.js'
import telemetryForm from './forms/telemetry-form.js'
import resetForm from './forms/reset-form.js'
import fileImportForm from './forms/file-import-form.js'
import gatewaysForm from './forms/gateways-form.js'
import globalToggleForm from './forms/global-toggle-form.js'
import ipfsNodeForm from './forms/ipfs-node-form.js'
import redirectRuleForm from './forms/redirect-rule-form.js'
import { supportsBlock } from '../lib/redirect-handler/blockOrObserve.js'
import resetForm from './forms/reset-form.js'
import telemetryForm from './forms/telemetry-form.js'

// Render the options page:
// Passed current app `state` from the store and `emit`, a function to create
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function optionsPage (state, emit) {
${resetForm({
onOptionsReset
})}
${supportsBlock()
${!supportsDeclarativeNetRequest()
? ''
: redirectRuleForm({
redirectRules: state.redirectRules,
Expand Down

0 comments on commit ec2da96

Please sign in to comment.