Skip to content

Commit 4a0beb7

Browse files
authored
Update SharedBuffer.md
1 parent 6c036a3 commit 4a0beb7

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

specs/SharedBuffer.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Then both the native application code and the script will be able to access the
2525
# Conceptual pages (How To)
2626

2727
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.
2929

3030
When the application code calls `PostSharedBufferToScript`, the script side will
3131
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
3737
collection to release the memory along with the owning objects, the application
3838
should try to release the buffer as soon as it doesn't need access to it.
3939
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.
4141

4242
As the memory could contain sensitive information and corrupted memory could crash
4343
the application, the application should only share buffer with trusted sites.
4444

4545
The application can use other messaging channel like `PostWebMessageAsJson` and
4646
`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).
4848

4949
# Examples
5050

@@ -59,30 +59,26 @@ The script code will look like this:
5959
}
6060
6161
function SharedBufferReceived(e) {
62-
if (e.data && e.data.read_only) {
62+
if (e.data && e.data.readOnly) {
6363
// This is the one time read only buffer
64-
let one_time_shared_buffer = e.sharedBuffer;
64+
let oneTimeSharedBuffer = e.sharedBuffer;
6565
// Consume the data from the buffer
66-
DisplaySharedBufferData(one_time_shared_buffer);
66+
DisplaySharedBufferData(oneTimeSharedBuffer);
6767
// Release the buffer after consuming the data.
68-
chrome.webview.releaseSharedBuffer(one_time_shared_buffer);
68+
chrome.webview.releaseBuffer(oneTimeSharedBuffer);
6969
}
7070
}
7171
```
7272
## Win32 C++
7373
```cpp
7474

75-
wil::com_ptr<ICoreWebView2Environment11> environment;
76-
CHECK_FAILURE(
77-
m_appWindow->GetWebViewEnvironment()->QueryInterface(IID_PPV_ARGS(&environment)));
78-
7975
wil::com_ptr<ICoreWebView2SharedBuffer> sharedBuffer;
80-
CHECK_FAILURE(environment->CreateSharedBuffer(bufferSize, &sharedBuffer));
76+
CHECK_FAILURE(webviewEnvironment->CreateSharedBuffer(bufferSize, &sharedBuffer));
8177
// Fill data into the shared memory via IStream.
8278
wil::com_ptr<IStream> stream;
8379
CHECK_FAILURE(sharedBuffer->GetStream(&stream));
8480
CHECK_FAILURE(stream->Write(data, dataSize, nullptr));
85-
PCWSTR additionalDataAsJson = L"{\"read_only\":true}";
81+
PCWSTR additionalDataAsJson = L"{\"readOnly\":true}";
8682
if (forFrame)
8783
{
8884
m_webviewFrame->PostSharedBufferToScript(
@@ -106,10 +102,10 @@ The script code will look like this:
106102
{
107103
using (StreamWriter writer = new StreamWriter(stream))
108104
{
109-
writer.Write(bufferData);
105+
writer.Write(data);
110106
}
111107
}
112-
string additionalDataAsJson = "{\"read_only\":true}";
108+
string additionalDataAsJson = "{\"readOnly\":true}";
113109
if (forFrame)
114110
{
115111
m_webviewFrame.PostSharedBufferToScript(sharedBuffer, /*isReadOnlyToScript*/true, additionalDataAsJson);
@@ -164,17 +160,17 @@ interface ICoreWebView2SharedBuffer : IUnknown {
164160
/// objects returned from `GetStream` will fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
165161
/// `PostSharedBufferToScript` will also fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
166162
///
167-
/// The script code should call `chrome.webview.releaseSharedBuffer` with
163+
/// The script code should call `chrome.webview.releaseBuffer` with
168164
/// the shared buffer as the parameter to release underlying resources as soon
169165
/// 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`,
171167
/// JavaScript `TypeError` exception will be raised complaining about accessing a
172168
/// detached ArrayBuffer, the same exception when trying to access a transferred ArrayBuffer.
173169
///
174170
/// Closing the buffer object on native side doesn't impact access from Script and releasing
175171
/// the buffer from script doesn't impact access to the buffer from native side.
176172
/// The underlying shared memory will be released by the OS when both native and script side
177-
/// releases the buffer.
173+
/// release the buffer.
178174
HRESULT Close();
179175
}
180176
@@ -193,7 +189,7 @@ interface ICoreWebView2_14 : IUnknown {
193189
/// violation in WebView renderer process and crash the renderer process.
194190
/// If the shared buffer is already closed, the API will fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
195191
///
196-
/// The script code should call `chrome.webview.releaseSharedBuffer` with
192+
/// The script code should call `chrome.webview.releaseBuffer` with
197193
/// the shared buffer as the parameter to release underlying resources as soon
198194
/// as it does not need access to the shared buffer any more.
199195
///
@@ -222,7 +218,7 @@ interface ICoreWebView2Frame4 : IUnknown {
222218
/// violation in WebView renderer process and crash the renderer process.
223219
/// If the shared buffer is already closed, the API will fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
224220
///
225-
/// The script code should call `chrome.webview.releaseSharedBuffer` with
221+
/// The script code should call `chrome.webview.releaseBuffer` with
226222
/// the shared buffer as the parameter to release underlying resources as soon
227223
/// as it does not need access to the shared buffer any more.
228224
///

0 commit comments

Comments
 (0)