Skip to content

Commit

Permalink
work-in-progress-dont-merge :^)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Dec 10, 2019
1 parent 3c9e72d commit 60eab90
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 50 deletions.
22 changes: 11 additions & 11 deletions add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
"message": "Active Tab",
"description": "A menu item in Browser Action pop-up (panel_activeTabSiteRedirectEnable)"
},
"panel_activeTabSiteRedirectToggle": {
"message": "Redirect on $1",
"description": "A menu item in Browser Action pop-up (panel_activeTabSiteRedirectToggle)"
"panel_activeTabSiteIntegrationsToggle": {
"message": "Enable integrations on $1",
"description": "A menu item in Browser Action pop-up (panel_activeTabSiteIntegrationsToggle)"
},
"panel_activeTabSiteRedirectToggleTooltip": {
"message": "Click to toggle gateway redirects on $1",
"description": "A menu item tooltip in Browser Action pop-up (panel_activeTabSiteRedirectToggleTooltip)"
"panel_activeTabSiteIntegrationsToggleTooltip": {
"message": "Click to toggle all IPFS integrations on $1",
"description": "A menu item tooltip in Browser Action pop-up (panel_activeTabSiteIntegrationsToggleTooltip)"
},
"panel_pinCurrentIpfsAddress": {
"message": "Pin IPFS Resource",
Expand Down Expand Up @@ -291,12 +291,12 @@
"message": "Redirecting to a path-based gateway breaks Origin-based security isolation of DNSLink website! Please leave this disabled unless you are aware of (and ok with) related risks.",
"description": "A warning on the Preferences screen, displayed when URL does not belong to Secure Context (option_customGatewayUrl_warning)"
},
"option_noRedirectHostnames_title": {
"message": "Redirect Opt-Outs",
"description": "An option title on the Preferences screen (option_noRedirectHostnames_title)"
"option_noIntegrationsHostnames_title": {
"message": "IPFS Integrations Opt-Outs",
"description": "An option title on the Preferences screen (option_noIntegrationsHostnames_title)"
},
"option_noRedirectHostnames_description": {
"message": "List of websites that should not be redirected to the Custom Gateway (includes subresources from other domains). One hostname per line.",
"option_noIntegrationsHostnames_description": {
"message": "List of websites that should not have any IPFS integrations enabled. One hostname per line.",
"description": "An option description on the Preferences screen (option_noRedirectHostnames_description)"
},
"option_publicGatewayUrl_title": {
Expand Down
6 changes: 3 additions & 3 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ module.exports = async function init () {
openViaWebUI: state.openViaWebUI,
apiURLString: dropSlash(state.apiURLString),
redirect: state.redirect,
noRedirectHostnames: state.noRedirectHostnames,
noIntegrationsHostnames: state.noIntegrationsHostnames,
currentTab: await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0])
}
try {
Expand All @@ -257,7 +257,7 @@ module.exports = async function init () {
info.isIpfsContext = ipfsPathValidator.isIpfsPageActionsContext(url)
info.currentDnslinkFqdn = dnslinkResolver.findDNSLinkHostname(url)
info.currentFqdn = info.currentDnslinkFqdn || new URL(url).hostname
info.currentTabRedirectOptOut = info.noRedirectHostnames && info.noRedirectHostnames.includes(info.currentFqdn)
info.currentTabIntegrationsOptOut = info.noIntegrationsHostnames && info.noIntegrationsHostnames.includes(info.currentFqdn)
info.isRedirectContext = info.currentFqdn && ipfsPathValidator.isRedirectPageActionsContext(url)
}
// Still here?
Expand Down Expand Up @@ -679,7 +679,7 @@ module.exports = async function init () {
case 'detectIpfsPathHeader':
case 'preloadAtPublicGateway':
case 'openViaWebUI':
case 'noRedirectHostnames':
case 'noIntegrationsHostnames':
case 'dnslinkRedirect':
state[key] = change.newValue
break
Expand Down
2 changes: 1 addition & 1 deletion add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
const parentUrl = request.originUrl || request.initiator // FF: originUrl (Referer-like Origin URL), Chrome: initiator (just Origin)
const fqdn = new URL(request.url).hostname
const parentFqdn = parentUrl && parentUrl !== 'null' && request.url !== parentUrl ? new URL(parentUrl).hostname : null
if (state.noRedirectHostnames.some(optout =>
if (state.noIntegrationsHostnames.some(optout =>
fqdn !== 'gateway.ipfs.io' && (fqdn.endsWith(optout) || (parentFqdn && parentFqdn.endsWith(optout))
))) {
ignore(request.requestId)
Expand Down
2 changes: 1 addition & 1 deletion add-on/src/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.optionDefaults = Object.freeze({
publicGatewayUrl: 'https://ipfs.io',
publicSubdomainGatewayUrl: 'https://dweb.link',
useCustomGateway: true,
noRedirectHostnames: [],
noIntegrationsHostnames: [],
automaticMode: true,
linkify: false,
dnslinkPolicy: 'best-effort',
Expand Down
16 changes: 8 additions & 8 deletions add-on/src/options/forms/gateways-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function gatewaysForm ({
ipfsNodeType,
customGatewayUrl,
useCustomGateway,
noRedirectHostnames,
noIntegrationsHostnames,
publicGatewayUrl,
publicSubdomainGatewayUrl,
onOptionChange
Expand All @@ -23,7 +23,7 @@ function gatewaysForm ({
const onUseCustomGatewayChange = onOptionChange('useCustomGateway')
const onPublicGatewayUrlChange = onOptionChange('publicGatewayUrl', normalizeGatewayURL)
const onPublicSubdomainGatewayUrlChange = onOptionChange('publicSubdomainGatewayUrl', normalizeGatewayURL)
const onNoRedirectHostnamesChange = onOptionChange('noRedirectHostnames', hostTextToArray)
const onNoIntegrationsHostnamesChange = onOptionChange('noIntegrationsHostnames', hostTextToArray)
const mixedContentWarning = !secureContextUrl.test(customGatewayUrl)
const supportRedirectToCustomGateway = ipfsNodeType !== 'embedded'
const allowChangeOfCustomGateway = ipfsNodeType !== 'embedded:chromesockets'
Expand Down Expand Up @@ -110,18 +110,18 @@ function gatewaysForm ({
` : null}
${supportRedirectToCustomGateway ? html`
<div>
<label for="noRedirectHostnames">
<label for="noIntegrationsHostnames">
<dl>
<dt>${browser.i18n.getMessage('option_noRedirectHostnames_title')}</dt>
<dd>${browser.i18n.getMessage('option_noRedirectHostnames_description')}</dd>
<dt>${browser.i18n.getMessage('option_noIntegrationsHostnames_title')}</dt>
<dd>${browser.i18n.getMessage('option_noIntegrationsHostnames_description')}</dd>
</dl>
</label>
<textarea
id="noRedirectHostnames"
id="noIntegrationsHostnames"
spellcheck="false"
onchange=${onNoRedirectHostnamesChange}
onchange=${onNoIntegrationsHostnamesChange}
rows="4"
>${hostArrayToText(noRedirectHostnames)}</textarea>
>${hostArrayToText(noIntegrationsHostnames)}</textarea>
</div>
` : null}
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion add-on/src/options/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = function optionsPage (state, emit) {
useCustomGateway: state.options.useCustomGateway,
publicGatewayUrl: state.options.publicGatewayUrl,
publicSubdomainGatewayUrl: state.options.publicSubdomainGatewayUrl,
noRedirectHostnames: state.options.noRedirectHostnames,
noIntegrationsHostnames: state.options.noIntegrationsHostnames,
onOptionChange
})}
${fileImportForm({
Expand Down
20 changes: 9 additions & 11 deletions add-on/src/popup/browser-action/context-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ function contextActions ({
currentTab,
currentFqdn,
currentDnslinkFqdn,
currentTabRedirectOptOut,
currentTabIntegrationsOptOut,
ipfsNodeType,
isIpfsContext,
isPinning,
isUnPinning,
isPinned,
isIpfsOnline,
isApiAvailable,
onToggleSiteRedirect,
onToggleSiteIntegrations,
onViewOnGateway,
onCopy,
onPin,
Expand Down Expand Up @@ -69,25 +69,23 @@ function contextActions ({
</div>
`
}
/* TODO: change "redirect on {fqdn}" to "disable on {fqdn}" and disable all integrations
// removed per site toggle for now: ${renderSiteRedirectToggle()}
const renderSiteRedirectToggle = () => {
const renderSiteIntegrationsToggle = () => {
if (!isRedirectContext) return
return html`
${navItem({
text: browser.i18n.getMessage('panel_activeTabSiteRedirectToggle', currentFqdn),
title: browser.i18n.getMessage('panel_activeTabSiteRedirectToggleTooltip', currentFqdn),
text: browser.i18n.getMessage('panel_activeTabSiteIntegrationsToggle', currentFqdn),
title: browser.i18n.getMessage('panel_activeTabSiteIntegrationsToggleTooltip', currentFqdn),
style: 'truncate',
disabled: !(active && redirect),
switchValue: active && redirect && !currentTabRedirectOptOut,
onClick: onToggleSiteRedirect
disabled: !(active),
switchValue: active && !currentTabIntegrationsOptOut,
onClick: onToggleSiteIntegrations
})}
`
}
*/
return html`
<div class='fade-in pv1'>
${renderIpfsContextItems()}
${renderSiteIntegrationsToggle()}
</div>
`
}
Expand Down
4 changes: 2 additions & 2 deletions add-on/src/popup/browser-action/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ module.exports = function browserActionPage (state, emit) {
const onOpenWebUi = () => emit('openWebUi')
const onOpenPrefs = () => emit('openPrefs')
const onToggleGlobalRedirect = () => emit('toggleGlobalRedirect')
const onToggleSiteRedirect = () => emit('toggleSiteRedirect')
const onToggleSiteIntegrations = () => emit('toggleSiteIntegrations')
const onToggleActive = () => emit('toggleActive')

const headerProps = Object.assign({ onToggleActive, onOpenPrefs }, state)
const activeTabActionsProps = Object.assign({ onViewOnGateway, onToggleSiteRedirect, onCopy, onPin, onUnPin }, state)
const activeTabActionsProps = Object.assign({ onViewOnGateway, onToggleSiteIntegrations, onCopy, onPin, onUnPin }, state)
const opsProps = Object.assign({ onQuickUpload, onOpenWebUi, onToggleGlobalRedirect }, state)

return html`
Expand Down
21 changes: 11 additions & 10 deletions add-on/src/popup/browser-action/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = (state, emitter) => {
currentTab: null,
currentFqdn: null,
currentDnslinkFqdn: null,
noRedirectHostnames: []
noIntegrationsHostnames: []
})

let port
Expand Down Expand Up @@ -166,22 +166,23 @@ module.exports = (state, emitter) => {
}
})

emitter.on('toggleSiteRedirect', async () => {
state.currentTabRedirectOptOut = !state.currentTabRedirectOptOut
emitter.on('toggleSiteIntegrations', async () => {
state.currentTabIntegrationsOptOut = !state.currentTabIntegrationsOptOut
emitter.emit('render')

try {
let noRedirectHostnames = state.noRedirectHostnames
let noIntegrationsHostnames = state.noIntegrationsHostnames
// if we are on /ipns/fqdn.tld/ then use hostname from DNSLink
const fqdn = state.currentDnslinkFqdn || state.currentFqdn
if (noRedirectHostnames.includes(fqdn)) {
noRedirectHostnames = noRedirectHostnames.filter(host => !host.endsWith(fqdn))
if (noIntegrationsHostnames.includes(fqdn)) {
noIntegrationsHostnames = noIntegrationsHostnames.filter(host => !host.endsWith(fqdn))
} else {
noRedirectHostnames.push(fqdn)
noIntegrationsHostnames.push(fqdn)
}
// console.dir('toggleSiteRedirect', state)
await browser.storage.local.set({ noRedirectHostnames })
// console.dir('toggleSiteIntegrations', state)
await browser.storage.local.set({ noIntegrationsHostnames })

// TODO: remove below? does it still make sense in "integrations toggle" context?
// Reload the current tab to apply updated redirect preference
if (!state.currentDnslinkFqdn || !IsIpfs.ipnsUrl(state.currentTab.url)) {
// No DNSLink, reload URL as-is
Expand All @@ -198,7 +199,7 @@ module.exports = (state, emitter) => {
})
}
} catch (error) {
console.error(`Unable to update redirect state due to ${error}`)
console.error(`Unable to update integrations state due to ${error}`)
emitter.emit('render')
}
})
Expand Down
4 changes: 2 additions & 2 deletions add-on/src/popup/page-action/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module.exports = function pageActionPage (state, emit) {
const onCopy = (copyAction) => emit('copy', copyAction)
const onPin = () => emit('pin')
const onUnPin = () => emit('unPin')
const onToggleSiteRedirect = () => emit('toggleSiteRedirect')
const onToggleSiteIntegrations = () => emit('toggleSiteIntegrations')

const contextActionsProps = Object.assign({ onViewOnGateway, onCopy, onPin, onUnPin, onToggleSiteRedirect }, state)
const contextActionsProps = Object.assign({ onViewOnGateway, onCopy, onPin, onUnPin, onToggleSiteIntegrations }, state)

// Instant init: page-action is shown only in ipfsContext
contextActionsProps.isIpfsContext = true
Expand Down

0 comments on commit 60eab90

Please sign in to comment.