-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(windows): add sharedbuffer implement and example #1115
Conversation
b8c73f7
to
5c99ea1
Compare
Hey @defims thanks for contributing! Though we have enforced commit signing so I'll need you to sign your commit before we can merge it. |
9f95014
to
4b63d82
Compare
Same as #1109 this PR is only exposing APIs that can be accessed through webview.controller and I don't see any value in adding it here tbh. |
@amrbashir Thank you for your review.
However, as you are concerned, it is a high-cost method with few applicable scenarios. It is currently only available on Windows. For these reasons, I have not wrapped related methods too much. Instead, I only expose basic APIs on WKWebView and WebKitGTK currently do not have similar APIs. The cost of simulating them with existing interfaces is too high, so they have not been added yet. If the relevant API documentation is provided, I will be happy to add them and encapsulate them into a unified interface. |
I meant that these newly exposed APIs can just be accessed by doing the following without adding it explicitly in wry: let controller = webview.controller();
let webview2 = controller.CoreWebview2().unwrap().cast::<ICoreWebView2_19>().unwrap();
let environment = webview2.Environment().unwrap().cast::<ICoreWebView2Environment12>().unwrap();
// use webview2 & environment to create and post the shared buffer Same goes for #1109 |
Wow! That's great. I didn't notice this method before. This method can get the I tried it, and it worked. 🎉 Here is the test code: use windows::ComInterface;
let controller = webview.controller();
let webview2 = unsafe { controller.CoreWebView2() }.unwrap().cast::<ICoreWebView2_19>().unwrap();
let environment = unsafe { webview2.Environment() }.unwrap().cast::<ICoreWebView2Environment12>().unwrap();
let _ = unsafe { webview2.AddHostObjectToScript(w!("i32"), &mut i32_variant.0) };
let shared_buffer = unsafe { webview.create_shared_buffer(1024) }.unwrap());
let _ = unsafe { environment.PostSharedBufferToScript(sharedbuffer, access, additionaldataasjson) }; |
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
Checklist
PostSharedBufferToScript
for making streaming possible #1110 feat: synchronous communication between webview and rust #454Other information
Two methods,
webview.create_shared_buffer()
andwebview.post_shared_buffer_to_script()
, were added to theWebViewExtWindows
trait, Since these are two Windows-specific methods.Because manual memory management is risky, the new methods do not provide any additional helper functions to manage memory. Users are responsible for managing memory themselves.