diff --git a/src/commands/serverActions.ts b/src/commands/serverActions.ts index 295ec47c..ffa73a07 100644 --- a/src/commands/serverActions.ts +++ b/src/commands/serverActions.ts @@ -19,7 +19,6 @@ import { } from "../utils"; import { mainCommandMenu, mainSourceControlMenu } from "./studio"; import { AtelierAPI } from "../api"; -import { getCSPToken } from "../utils/getCSPToken"; import { isfsConfig } from "../utils/FileProviderUtil"; type ServerAction = { detail: string; id: string; label: string; rawLink?: string }; @@ -224,11 +223,11 @@ export async function serverActions(): Promise { } switch (action.id) { case "openPortal": { - vscode.env.openExternal(vscode.Uri.parse(`${serverUrl}${portalPath}`)); + vscode.commands.executeCommand("workbench.action.browser.open", `${serverUrl}${portalPath}`); break; } case "openClassReference": { - vscode.env.openExternal(vscode.Uri.parse(`${serverUrl}${classRef}`)); + vscode.commands.executeCommand("workbench.action.browser.open", `${serverUrl}${classRef}`); break; } case "openStudioAddin": { @@ -248,15 +247,12 @@ export async function serverActions(): Promise { }); if (addin) { sendStudioAddinTelemetryEvent(addin.label); - const token = await getCSPToken(api, addin.id); let params = `Namespace=${nsEncoded}`; params += `&User=${encodeURIComponent(username)}`; - if (project !== "") { + if (project != "") { params += `&Project=${encodeURIComponent(project)}`; } - params += `&CSPCHD=${token}`; - params += "&CSPSHARE=1"; - vscode.env.openExternal(vscode.Uri.parse(`${serverUrl}${addin.id}?${params}`)); + vscode.commands.executeCommand("workbench.action.browser.open", `${serverUrl}${addin.id}?${params}`); } } break; @@ -278,16 +274,7 @@ export async function serverActions(): Promise { break; } default: { - let url = vscode.Uri.parse(action.detail); - if (action.rawLink?.startsWith("${serverUrl}")) { - const token = await getCSPToken(api, url.path); - if (token.length > 0) { - url = url.with({ - query: url.query.length ? `${url.query}&CSPCHD=${token}` : `CSPCHD=${token}`, - }); - } - } - vscode.env.openExternal(url); + vscode.commands.executeCommand("workbench.action.browser.open", action.detail); } } }); diff --git a/src/commands/studio.ts b/src/commands/studio.ts index 250b015e..49f2c8b9 100644 --- a/src/commands/studio.ts +++ b/src/commands/studio.ts @@ -130,10 +130,6 @@ export class StudioActions { .then((answer) => (answer === "Yes" ? "1" : answer === "No" ? "0" : "2")); case 2: { // Run a CSP page/Template. The Target is the full path of CSP page/template on the connected server - - // Do this ourself instead of using our new getCSPToken wrapper function, because that function reuses tokens which causes issues with - // webview when server is 2020.1.1 or greater, as session cookie scope is typically Strict, meaning that the webview - // cannot store the cookie. Consequence is web sessions may build up (they get a 900 second timeout) const cspchd = await this.api .actionQuery("select %Atelier_v1_Utils.General_GetCSPToken(?) token", [target]) .then((data) => data.result.content[0].token) @@ -160,10 +156,8 @@ export class StudioActions { if (message.result && message.result === "done") { answer = "1"; panel.dispose(); - } else if (typeof message.href == "string") { - const linkUri = vscode.Uri.parse(message.href); - // Only open http(s) links - if (/^https?$/.test(linkUri.scheme)) vscode.env.openExternal(linkUri); + } else if (typeof message.href == "string" && /^https?:\/\//.test(message.href)) { + vscode.commands.executeCommand("workbench.action.browser.open", message.href); } }); panel.onDidDispose(() => resolve(answer)); @@ -207,8 +201,11 @@ export class StudioActions { } case 3: { // Run an EXE on the client. - if (/^(ht|f)tps?:\/\//i.test(target)) { - // Allow target that is a URL to be opened in an external browser + if (/^https?:\/\//.test(target)) { + // Allow https URLs to be opened in the Integrated Browser + vscode.commands.executeCommand("workbench.action.browser.open", target); + } else if (/^ftps?:\/\//.test(target)) { + // ftp links aren't supported by the Integrated Browser vscode.env.openExternal(vscode.Uri.parse(target)); } else { // Anything else is not supported diff --git a/src/extension.ts b/src/extension.ts index 677022af..31dd9b76 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -644,8 +644,9 @@ function proposedApiPrompt(active: boolean, added?: readonly vscode.WorkspaceFol .then(async (action) => { switch (action) { case "Yes": - vscode.env.openExternal( - vscode.Uri.parse("https://github.com/intersystems-community/vscode-objectscript#enable-proposed-apis") + vscode.commands.executeCommand( + "workbench.action.browser.open", + "https://github.com/intersystems-community/vscode-objectscript#enable-proposed-apis" ); break; case "Never": @@ -1784,12 +1785,11 @@ export async function activate(context: vscode.ExtensionContext): Promise { .catch(() => { // Swallow errors })) ?? `/csp/${api.ns}`; - vscode.env.openExternal( - vscode.Uri.parse( - `${api.config.https ? "https" : "http"}://${api.config.host}:${api.config.port}${ - api.config.pathPrefix - }${app}${path}` - ) + vscode.commands.executeCommand( + "workbench.action.browser.open", + `${api.config.https ? "https" : "http"}://${api.config.host}:${api.config.port}${ + api.config.pathPrefix + }${app}${path}` ); } } diff --git a/src/utils/getCSPToken.ts b/src/utils/getCSPToken.ts deleted file mode 100644 index 2ba81ac8..00000000 --- a/src/utils/getCSPToken.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { AtelierAPI } from "../api"; - -const allTokens = new Map>(); - -// Get or extend CSP token that will give current connected user access to webapp at path -export async function getCSPToken(api: AtelierAPI, path: string): Promise { - // Ignore any queryparams, and null out any page name - const parts = path.split("?")[0].split("/"); - parts.pop(); - parts.push(""); - path = parts.join("/"); - - // The first key in map-of-maps where we record tokens represents the connection target - const { https, host, port, pathPrefix, username } = api.config; - const connKey = JSON.stringify({ https, host, port, pathPrefix, username }); - - const myTokens = allTokens.get(connKey) || new Map(); - const previousToken = myTokens.get(path) || ""; - let token = ""; - return api - .actionQuery("select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token", [path, previousToken]) - .then((tokenObj) => { - token = tokenObj.result.content[0].token; - myTokens.set(path, token); - allTokens.set(connKey, myTokens); - return token; - }); -}