diff --git a/add-on/_locales/en/messages.json b/add-on/_locales/en/messages.json index 863117a48..e762d3bb2 100644 --- a/add-on/_locales/en/messages.json +++ b/add-on/_locales/en/messages.json @@ -91,6 +91,10 @@ "message": "Copy Public Gateway URL", "description": "A menu item in Browser Action pop-up and right-click context menu (panel_copyCurrentPublicGwUrl)" }, + "panel_contextMenuViewOnGateway": { + "message": "View on Gateway", + "description": "A menu item in Browser Action pop-up and right-click context menu (panel_contextMenuViewOnGateway)" + }, "pageAction_titleIpfsAtPublicGateway": { "message": "IPFS resource loaded via Public Gateway", "description": "A tooltip displayed over Page Action in location bar (pageAction_titleIpfsAtPublicGateway)" @@ -276,7 +280,7 @@ "description": "An option description on the Preferences screen (option_useCustomGateway_description)" }, "option_dnslinkRedirect_title": { - "message": "Force load from Custom Gateway", + "message": "Force page load from custom gateway", "description": "An option title on the Preferences screen (option_dnslinkRedirect_title)" }, "option_dnslinkRedirect_description": { diff --git a/add-on/src/lib/context-menus.js b/add-on/src/lib/context-menus.js index bf78c4bd4..f8f4d9e7c 100644 --- a/add-on/src/lib/context-menus.js +++ b/add-on/src/lib/context-menus.js @@ -58,9 +58,11 @@ const contextMenuImportToIpfsSelection = 'contextMenu_importToIpfsSelection' const contextMenuCopyCanonicalAddress = 'panelCopy_currentIpfsAddress' const contextMenuCopyRawCid = 'panelCopy_copyRawCid' const contextMenuCopyAddressAtPublicGw = 'panel_copyCurrentPublicGwUrl' +const contextMenuViewOnGateway = 'panel_contextMenuViewOnGateway' module.exports.contextMenuCopyCanonicalAddress = contextMenuCopyCanonicalAddress module.exports.contextMenuCopyRawCid = contextMenuCopyRawCid module.exports.contextMenuCopyAddressAtPublicGw = contextMenuCopyAddressAtPublicGw +module.exports.contextMenuViewOnGateway = contextMenuViewOnGateway // menu items that are enabled only when API is online const apiMenuItems = new Set() diff --git a/add-on/src/lib/inspector.js b/add-on/src/lib/inspector.js new file mode 100644 index 000000000..3226c1e36 --- /dev/null +++ b/add-on/src/lib/inspector.js @@ -0,0 +1,21 @@ +'use strict' + +const browser = require('webextension-polyfill') +const { findValueForContext } = require('./context-menus') +const { pathAtHttpGateway } = require('./ipfs-path') + +function createInspector (notify, ipfsPathValidator, getState) { + return { + async viewOnGateway (context, contextType) { + const url = await findValueForContext(context, contextType) + const ipfsPath = ipfsPathValidator.resolveToIpfsPath(url) + const gateway = getState().pubGwURLString + const gatewayUrl = pathAtHttpGateway(ipfsPath, gateway) + await browser.tabs.create({ url: gatewayUrl }) + } + // TODO: view in WebUI's Files + // TODO: view in WebUI's IPLD Explorer + } +} + +module.exports = createInspector diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index da17bd7d4..9f21bbb68 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -18,8 +18,9 @@ const { createIpfsUrlProtocolHandler } = require('./ipfs-protocol') const createIpfsImportHandler = require('./ipfs-import') const createNotifier = require('./notifier') const createCopier = require('./copier') +const createInspector = require('./inspector') const { createRuntimeChecks } = require('./runtime-checks') -const { createContextMenus, findValueForContext, contextMenuCopyAddressAtPublicGw, contextMenuCopyRawCid, contextMenuCopyCanonicalAddress } = require('./context-menus') +const { createContextMenus, findValueForContext, contextMenuCopyAddressAtPublicGw, contextMenuCopyRawCid, contextMenuCopyCanonicalAddress, contextMenuViewOnGateway } = require('./context-menus') const createIpfsProxy = require('./ipfs-proxy') const { showPendingLandingPages } = require('./on-installed') @@ -34,6 +35,7 @@ module.exports = async function init () { var modifyRequest var notify var copier + var inspector var runtime var contextMenus var apiStatusUpdateInterval @@ -69,6 +71,7 @@ module.exports = async function init () { ipfsPathValidator = createIpfsPathValidator(getState, getIpfs, dnslinkResolver) ipfsImportHandler = createIpfsImportHandler(getState, getIpfs, ipfsPathValidator, runtime) copier = createCopier(notify, ipfsPathValidator) + inspector = createInspector(notify, ipfsPathValidator, getState) contextMenus = createContextMenus(getState, runtime, ipfsPathValidator, { onAddFromContext, onCopyCanonicalAddress: copier.copyCanonicalAddress, @@ -212,6 +215,7 @@ module.exports = async function init () { const BrowserActionMessageHandlers = { notification: (message) => notify(message.title, message.message), + [contextMenuViewOnGateway]: inspector.viewOnGateway, [contextMenuCopyCanonicalAddress]: copier.copyCanonicalAddress, [contextMenuCopyRawCid]: copier.copyRawCid, [contextMenuCopyAddressAtPublicGw]: copier.copyAddressAtPublicGw diff --git a/add-on/src/popup/browser-action/context-actions.js b/add-on/src/popup/browser-action/context-actions.js index 199e9d75b..afdded37d 100644 --- a/add-on/src/popup/browser-action/context-actions.js +++ b/add-on/src/popup/browser-action/context-actions.js @@ -5,14 +5,23 @@ const browser = require('webextension-polyfill') const html = require('choo/html') const navItem = require('./nav-item') const navHeader = require('./nav-header') -const { contextMenuCopyAddressAtPublicGw, contextMenuCopyRawCid, contextMenuCopyCanonicalAddress } = require('../../lib/context-menus') +const { + contextMenuViewOnGateway, + contextMenuCopyAddressAtPublicGw, + contextMenuCopyRawCid, + contextMenuCopyCanonicalAddress +} = require('../../lib/context-menus') // Context Actions are displayed in Browser Action and Page Action (FF only) function contextActions ({ active, redirect, isRedirectContext, + pubGwURLString, + gwURLString, + currentTab, currentFqdn, + currentDnslinkFqdn, currentTabRedirectOptOut, ipfsNodeType, isIpfsContext, @@ -22,16 +31,21 @@ function contextActions ({ isIpfsOnline, isApiAvailable, onToggleSiteRedirect, + onViewOnGateway, onCopy, onPin, onUnPin }) { const activeCidResolver = active && isIpfsOnline && isApiAvailable const activePinControls = active && isIpfsOnline && isApiAvailable - + const activeViewOnGateway = currentTab && !(currentTab.url.startsWith(pubGwURLString) || currentTab.url.startsWith(gwURLString)) const renderIpfsContextItems = () => { if (!isIpfsContext) return return html`