@@ -8,7 +8,6 @@ import * as os from 'os'
8
8
import * as path from 'path'
9
9
import * as vscode from 'vscode'
10
10
import * as nls from 'vscode-nls'
11
- import { ScriptResource } from '../lambda/models/scriptResource'
12
11
import { ext } from '../shared/extensionGlobals'
13
12
import { mostRecentVersionKey , pluginVersion } from './constants'
14
13
import { readFileAsString } from './filesystemUtilities'
@@ -17,41 +16,29 @@ import { getLogger } from './logger'
17
16
const localize = nls . loadMessageBundle ( )
18
17
19
18
export class ExtensionUtilities {
20
- public static getLibrariesForHtml ( names : string [ ] ) : ScriptResource [ ] {
19
+ public static getLibrariesForHtml ( names : string [ ] , webview : vscode . Webview ) : vscode . Uri [ ] {
21
20
const basePath = path . join ( ext . context . extensionPath , 'media' , 'libs' )
22
21
23
- return this . resolveResourceURIs ( basePath , names )
22
+ return this . resolveResourceURIs ( basePath , names , webview )
24
23
}
25
24
26
- public static getScriptsForHtml ( names : string [ ] ) : ScriptResource [ ] {
25
+ public static getScriptsForHtml ( names : string [ ] , webview : vscode . Webview ) : vscode . Uri [ ] {
27
26
const basePath = path . join ( ext . context . extensionPath , 'media' , 'js' )
28
27
29
- return this . resolveResourceURIs ( basePath , names )
28
+ return this . resolveResourceURIs ( basePath , names , webview )
30
29
}
31
30
32
- public static getCssForHtml ( names : string [ ] ) : ScriptResource [ ] {
31
+ public static getCssForHtml ( names : string [ ] , webview : vscode . Webview ) : vscode . Uri [ ] {
33
32
const basePath = path . join ( ext . context . extensionPath , 'media' , 'css' )
34
33
35
- return this . resolveResourceURIs ( basePath , names )
34
+ return this . resolveResourceURIs ( basePath , names , webview )
36
35
}
37
36
38
- public static getNonce ( ) : string {
39
- let text = ''
40
- const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
41
- for ( let i = 0 ; i < 32 ; i ++ ) {
42
- text += possible . charAt ( Math . floor ( Math . random ( ) * possible . length ) )
43
- }
44
-
45
- return text
46
- }
47
-
48
- private static resolveResourceURIs ( basePath : string , names : string [ ] ) : ScriptResource [ ] {
49
- const scripts : ScriptResource [ ] = [ ]
37
+ private static resolveResourceURIs ( basePath : string , names : string [ ] , webview : vscode . Webview ) : vscode . Uri [ ] {
38
+ const scripts : vscode . Uri [ ] = [ ]
50
39
_ . forEach ( names , scriptName => {
51
40
const scriptPathOnDisk = vscode . Uri . file ( path . join ( basePath , scriptName ) )
52
- const scriptUri = scriptPathOnDisk . with ( { scheme : 'vscode-resource' } )
53
- const nonce = ExtensionUtilities . getNonce ( )
54
- scripts . push ( { nonce : nonce , uri : scriptUri } )
41
+ scripts . push ( webview . asWebviewUri ( scriptPathOnDisk ) )
55
42
} )
56
43
57
44
return scripts
@@ -110,17 +97,17 @@ export async function createQuickStartWebview(
110
97
context : vscode . ExtensionContext ,
111
98
page : string = 'quickStart.html'
112
99
) : Promise < vscode . WebviewPanel > {
113
- const html = convertExtensionRootTokensToPath (
114
- await readFileAsString ( path . join ( context . extensionPath , page ) ) ,
115
- context . extensionPath
116
- )
117
100
// create hidden webview, leave it up to the caller to show
118
101
const view = vscode . window . createWebviewPanel (
119
102
'html' ,
120
103
localize ( 'AWS.command.quickStart.title' , 'AWS Toolkit - Quick Start' ) ,
121
104
{ viewColumn : vscode . ViewColumn . Active , preserveFocus : true }
122
105
)
123
- view . webview . html = html
106
+ view . webview . html = convertExtensionRootTokensToPath (
107
+ await readFileAsString ( path . join ( context . extensionPath , page ) ) ,
108
+ context . extensionPath ,
109
+ view . webview
110
+ )
124
111
125
112
return view
126
113
}
@@ -132,8 +119,10 @@ export async function createQuickStartWebview(
132
119
* @param text Text to scan
133
120
* @param basePath Extension path (from extension context)
134
121
*/
135
- function convertExtensionRootTokensToPath ( text : string , basePath : string ) : string {
136
- return text . replace ( / ! ! E X T E N S I O N R O O T ! ! / g, `vscode-resource:${ basePath } ` )
122
+ function convertExtensionRootTokensToPath ( text : string , basePath : string , webview : vscode . Webview ) : string {
123
+ return text . replace ( / ! ! E X T E N S I O N R O O T ! ! (?< restOfUrl > [ - a - z A - Z 0 - 9 @ : % _ \+ . ~ # ? & / / = ] * ) / g, ( matchedString , restOfUrl ) => {
124
+ return webview . asWebviewUri ( vscode . Uri . file ( `${ basePath } ${ restOfUrl } ` ) ) . toString ( )
125
+ } )
137
126
}
138
127
139
128
/**
0 commit comments