You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: specs/HostResourceMapping.md
+97-26Lines changed: 97 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,34 +3,55 @@ We have received feedbacks that there is a need to access local files in WebView
3
3
4
4
5
5
# Description
6
-
To access local files in WebView2, define a virutal host name to local folder mapping using the `AddVirtualHostNameToFolderMapping` API,
6
+
To access local files in WebView2, define a virtual host name to local folder mapping using the `SetVirtualHostNameToFolderMapping` API,
7
7
and then refer to local files under the folder with a normal http/https url with the virtual host name.
8
8
9
9
# Examples
10
-
Suppose the app has index.html file next to its exe file. The following code snippet demonstrates how to define a mapping
11
-
for `app-file.invalid` host name so that it can be accessed from pages using normal http/https url like https://app-file.invalid/index.html.
10
+
Suppose the app has index.html file in `asset` sub folder in the folder where its exe file is. The following code snippet demonstrates how to define a mapping
11
+
for `appassets.webview2.microsoft.com` host name so that it can be accessed using normal http/https url like https://appassets.webview2.microsoft.com/index.html.
webView.Source = new Uri("https://appassets.webview2.microsoft.com/index.html");
25
26
```
26
27
28
+
## WinRT
29
+
Suppose the app has index.html file in a `book1` sub folder of the app's LocalFolder folder. The following code snippet demonstrates how to define a mapping
30
+
for `book1.appassets.webview2.microsoft.com` host name so that it can be accessed using normal http/https url like https://book1.appassets.webview2.microsoft.com/index.html.
Choose a virtual host name that will not be used by real sites.
29
43
If you own a domain (like example.com), an option is to use a sub domain reserved for the app (like my-app.example.com).
30
-
If you don't own a domain, [RFC 6761](https://tools.ietf.org/html/rfc6761) has reserved several special-use domain names that would
31
-
not be used by real sites, like .example, .test, and .invalid.
44
+
We have also reserved a special domain appassets.webview2.microsoft.com for this usage.
45
+
46
+
The host name used in the APIs is canonicalized using Chromium's host name parsing logic
47
+
before being used internally.
48
+
All host names that are canonicalized to the same string are considered identical.
49
+
For example, `EXAMPLE.COM` and `example.com` are considered the same host name.
50
+
An international host name and its puny coded host name are considered the same host name.
51
+
There is no DSN resolution for host name and trailing '.' is not normalized as part of canonicalization.
52
+
Therefore `example.com` and `example.com.` are treated as different host names. So are `virtual-host-name` and `virtual-host-name.example.com` when the DNS suffix of the machine is `example.com`.
32
53
33
-
Give only minimal cross orign access neccessary to run the app. If there is no need to access local resources
54
+
Give only minimal cross origin access necessary to run the app. If there is no need to access local resources
34
55
from other origins, use COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY.
35
56
36
57
# API Notes
@@ -39,15 +60,22 @@ See [API Details](#api-details) section below for API reference.
39
60
# API Details
40
61
41
62
## Win32 C++
42
-
The follow table illustrates the host resource cross origin access according to access context and `COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND`.
63
+
The following table illustrates the host resource cross origin access according to
64
+
access context and `COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND`.
0 commit comments