@@ -25,7 +25,7 @@ Then both the native application code and the script will be able to access the
25
25
# Conceptual pages (How To)
26
26
27
27
Besides using the memory address directly, the shared buffer object can be accessed
28
- from native side via an IStream* object that you can get from the shared object.
28
+ from native side via an IStream* object that you can get from the shared buffer object.
29
29
30
30
When the application code calls ` PostSharedBufferToScript ` , the script side will
31
31
receive a ` SharedBufferReceived ` event containing the buffer as an ` ArrayBuffer ` object.
@@ -37,14 +37,14 @@ As shared buffer normally represent a large memory, instead of waiting for garba
37
37
collection to release the memory along with the owning objects, the application
38
38
should try to release the buffer as soon as it doesn't need access to it.
39
39
This can be done by calling Close() method on the shared buffer object, or
40
- ` chrome.webview.releaseSharedBuffer ` from script.
40
+ ` chrome.webview.releaseBuffer ` from script.
41
41
42
42
As the memory could contain sensitive information and corrupted memory could crash
43
43
the application, the application should only share buffer with trusted sites.
44
44
45
45
The application can use other messaging channel like ` PostWebMessageAsJson ` and
46
46
` chrome.webview.postMessage ` to inform the other side the desire to have a shared
47
- buffer and the status of the buffer (data is produced or consumed).
47
+ buffer and the status of the buffer (like data is produced or consumed).
48
48
49
49
# Examples
50
50
@@ -59,30 +59,26 @@ The script code will look like this:
59
59
}
60
60
61
61
function SharedBufferReceived(e) {
62
- if (e.data && e.data.read_only ) {
62
+ if (e.data && e.data.readOnly ) {
63
63
// This is the one time read only buffer
64
- let one_time_shared_buffer = e.sharedBuffer;
64
+ let oneTimeSharedBuffer = e.sharedBuffer;
65
65
// Consume the data from the buffer
66
- DisplaySharedBufferData(one_time_shared_buffer );
66
+ DisplaySharedBufferData(oneTimeSharedBuffer );
67
67
// Release the buffer after consuming the data.
68
- chrome.webview.releaseSharedBuffer(one_time_shared_buffer );
68
+ chrome.webview.releaseBuffer(oneTimeSharedBuffer );
69
69
}
70
70
}
71
71
```
72
72
## Win32 C++
73
73
``` cpp
74
74
75
- wil::com_ptr<ICoreWebView2Environment11> environment;
76
- CHECK_FAILURE (
77
- m_appWindow->GetWebViewEnvironment()->QueryInterface(IID_PPV_ARGS(&environment)));
78
-
79
75
wil::com_ptr<ICoreWebView2SharedBuffer> sharedBuffer;
80
- CHECK_FAILURE(environment ->CreateSharedBuffer(bufferSize, &sharedBuffer));
76
+ CHECK_FAILURE (webviewEnvironment ->CreateSharedBuffer(bufferSize, &sharedBuffer));
81
77
// Fill data into the shared memory via IStream.
82
78
wil::com_ptr<IStream > stream;
83
79
CHECK_FAILURE(sharedBuffer->GetStream(&stream));
84
80
CHECK_FAILURE(stream->Write(data, dataSize, nullptr));
85
- PCWSTR additionalDataAsJson = L"{\"read_only \":true}";
81
+ PCWSTR additionalDataAsJson = L"{\" readOnly \" : true }";
86
82
if (forFrame)
87
83
{
88
84
m_webviewFrame->PostSharedBufferToScript(
@@ -106,10 +102,10 @@ The script code will look like this:
106
102
{
107
103
using (StreamWriter writer = new StreamWriter(stream))
108
104
{
109
- writer.Write(bufferData );
105
+ writer.Write(data );
110
106
}
111
107
}
112
- string additionalDataAsJson = "{\"read_only \":true}";
108
+ string additionalDataAsJson = "{\"readOnly \":true}";
113
109
if (forFrame)
114
110
{
115
111
m_webviewFrame.PostSharedBufferToScript(sharedBuffer, /*isReadOnlyToScript*/true, additionalDataAsJson);
@@ -164,17 +160,17 @@ interface ICoreWebView2SharedBuffer : IUnknown {
164
160
/// objects returned from `GetStream` will fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
165
161
/// `PostSharedBufferToScript` will also fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
166
162
///
167
- /// The script code should call `chrome.webview.releaseSharedBuffer ` with
163
+ /// The script code should call `chrome.webview.releaseBuffer ` with
168
164
/// the shared buffer as the parameter to release underlying resources as soon
169
165
/// as it does not need access the shared buffer any more.
170
- /// When script tries to access the buffer after calling `chrome.webview.releaseSharedBuffer `,
166
+ /// When script tries to access the buffer after calling `chrome.webview.releaseBuffer `,
171
167
/// JavaScript `TypeError` exception will be raised complaining about accessing a
172
168
/// detached ArrayBuffer, the same exception when trying to access a transferred ArrayBuffer.
173
169
///
174
170
/// Closing the buffer object on native side doesn't impact access from Script and releasing
175
171
/// the buffer from script doesn't impact access to the buffer from native side.
176
172
/// The underlying shared memory will be released by the OS when both native and script side
177
- /// releases the buffer.
173
+ /// release the buffer.
178
174
HRESULT Close();
179
175
}
180
176
@@ -193,7 +189,7 @@ interface ICoreWebView2_14 : IUnknown {
193
189
/// violation in WebView renderer process and crash the renderer process.
194
190
/// If the shared buffer is already closed, the API will fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
195
191
///
196
- /// The script code should call `chrome.webview.releaseSharedBuffer ` with
192
+ /// The script code should call `chrome.webview.releaseBuffer ` with
197
193
/// the shared buffer as the parameter to release underlying resources as soon
198
194
/// as it does not need access to the shared buffer any more.
199
195
///
@@ -222,7 +218,7 @@ interface ICoreWebView2Frame4 : IUnknown {
222
218
/// violation in WebView renderer process and crash the renderer process.
223
219
/// If the shared buffer is already closed, the API will fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
224
220
///
225
- /// The script code should call `chrome.webview.releaseSharedBuffer ` with
221
+ /// The script code should call `chrome.webview.releaseBuffer ` with
226
222
/// the shared buffer as the parameter to release underlying resources as soon
227
223
/// as it does not need access to the shared buffer any more.
228
224
///
0 commit comments