webview2_sys/lib.rs
1//! Low Level Bindings for WebView2 SDK.
2#![cfg(windows)]
3#![allow(
4 clippy::missing_safety_doc,
5 non_snake_case,
6 clippy::upper_case_acronyms
7)]
8
9// Generated by idl2rs.
10
11use com::{
12 com_interface,
13 interfaces::{iunknown::IUnknownVTable, IUnknown},
14};
15use std::ffi::c_void;
16use winapi::shared::minwindef::{ULONG, *};
17use winapi::shared::ntdef::*;
18use winapi::shared::windef::*;
19use winapi::um::oaidl::VARIANT;
20use winapi::um::objidlbase::STATSTG;
21
22/// Represents a reference to a delegate that receives change notifications.
23#[repr(C)]
24#[derive(Debug, Eq, PartialEq, Copy, Clone)]
25pub struct EventRegistrationToken {
26 value: i64,
27}
28
29#[com_interface("0c733a30-2a1c-11ce-ade5-00aa0044773d")]
30pub trait ISequentialStream: IUnknown {
31 unsafe fn read(&self, pv: *mut c_void, cb: ULONG, pcbRead: *mut ULONG) -> HRESULT;
32 unsafe fn write(&self, pv: *const c_void, cb: ULONG, pcbWritten: *mut ULONG) -> HRESULT;
33}
34
35#[com_interface("0000000c-0000-0000-C000-000000000046")]
36pub trait IStream: ISequentialStream {
37 unsafe fn seek(
38 &self,
39 dlibMove: LARGE_INTEGER,
40 dwOrigin: DWORD,
41 plibNewPosition: *mut ULARGE_INTEGER,
42 ) -> HRESULT;
43 unsafe fn set_size(&self, libNewSize: ULARGE_INTEGER) -> HRESULT;
44 unsafe fn copy_to(
45 &self,
46 pstm: *mut *mut IStreamVTable,
47 cb: ULARGE_INTEGER,
48 pcbRead: *mut ULARGE_INTEGER,
49 pcbWritten: *mut ULARGE_INTEGER,
50 ) -> HRESULT;
51 unsafe fn commit(&self, grfCommitFlags: DWORD) -> HRESULT;
52 unsafe fn revert(&self) -> HRESULT;
53 unsafe fn lock_region(
54 &self,
55 libOffset: ULARGE_INTEGER,
56 cb: ULARGE_INTEGER,
57 dwLockType: DWORD,
58 ) -> HRESULT;
59 unsafe fn unlock_region(
60 &self,
61 libOffset: ULARGE_INTEGER,
62 cb: ULARGE_INTEGER,
63 dwLockType: DWORD,
64 ) -> HRESULT;
65 unsafe fn stat(&self, pstatstg: *mut STATSTG, grfStatFlag: DWORD) -> HRESULT;
66 unsafe fn clone(&self, ppstm: *mut *mut *mut IStreamVTable) -> HRESULT;
67}
68
69/// DLL export to create a WebView2 environment with a custom version of Edge,
70/// user data directory and/or additional options.
71///
72/// browserExecutableFolder is the relative path to the folder that
73/// contains the embedded Edge. The embedded Edge can be obtained by
74/// copying the version named folder of an installed Edge, like
75/// 73.0.52.0 sub folder of an installed 73.0.52.0 Edge. The folder
76/// should have msedge.exe, msedge.dll, and so on.
77/// Use null or empty string for browserExecutableFolder to create
78/// WebView using Edge installed on the machine, in which case the
79/// API will try to find a compatible version of Edge installed on the
80/// machine according to the channel preference trying to find first
81/// per user install and then per machine install.
82///
83/// The default channel search order is stable, beta, dev, and canary.
84/// When there is an override WEBVIEW2_RELEASE_CHANNEL_PREFERENCE environment
85/// variable or applicable releaseChannelPreference registry value
86/// with the value of 1, the channel search order is reversed.
87///
88/// userDataFolder can be
89/// specified to change the default user data folder location for
90/// WebView2. The path can be an absolute file path or a relative file path
91/// that is interpreted as relative to the current process's executable.
92/// Otherwise, for UWP apps, the default user data folder will be
93/// the app data folder for the package; for non-UWP apps,
94/// the default user data folder `{Executable File Name}.WebView2`
95/// will be created in the same directory next to the app executable.
96/// WebView2 creation can fail if the executable is running in a directory
97/// that the process doesn't have permission to create a new folder in.
98/// The app is responsible to clean up its user data folder
99/// when it is done.
100///
101/// Note that as a browser process might be shared among WebViews,
102/// WebView creation will fail with HRESULT_FROM_WIN32(ERROR_INVALID_STATE) if
103/// the specified options does not match the options of the WebViews that are
104/// currently running in the shared browser process.
105///
106/// environment_created_handler is the handler result to the async operation
107/// which will contain the WebView2Environment that got created.
108///
109/// The browserExecutableFolder, userDataFolder and additionalBrowserArguments
110/// of the environmentOptions may be overridden by
111/// values either specified in environment variables or in the registry.
112///
113/// When creating a WebView2Environment the following environment variables
114/// are checked:
115///
116/// ```
117/// WEBVIEW2_BROWSER_EXECUTABLE_FOLDER
118/// WEBVIEW2_USER_DATA_FOLDER
119/// WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS
120/// WEBVIEW2_RELEASE_CHANNEL_PREFERENCE
121/// ```
122///
123/// If an override environment variable is found then we use the
124/// browserExecutableFolder, userDataFolder and additionalBrowserArguments
125/// values as replacements for the corresponding values in
126/// CreateCoreWebView2EnvironmentWithOptions parameters.
127///
128/// While not strictly overrides, there exists additional environment variables
129/// that can be set:
130///
131/// ```
132/// WEBVIEW2_WAIT_FOR_SCRIPT_DEBUGGER
133/// ```
134///
135/// When found with a non-empty value, this indicates that the WebView is being
136/// launched under a script debugger. In this case, the WebView will issue a
137/// `Page.waitForDebugger` CDP command that will cause script execution inside the
138/// WebView to pause on launch, until a debugger issues a corresponding
139/// `Runtime.runIfWaitingForDebugger` CDP command to resume execution.
140/// Note: There is no registry key equivalent of this environment variable.
141///
142/// ```
143/// WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER
144/// ```
145///
146/// When found with a non-empty value, this indicates that the WebView is being
147/// launched under a script debugger that also supports host applications that
148/// use multiple WebViews. The value is used as the identifier for a named pipe
149/// that will be opened and written to when a new WebView is created by the host
150/// application. The payload will match that of the remote-debugging-port JSON
151/// target and can be used by the external debugger to attach to a specific
152/// WebView instance.
153/// The format of the pipe created by the debugger should be:
154/// `\\.\pipe\WebView2\Debugger\{app_name}\{pipe_name}`
155/// where:
156///
157/// - `{app_name}` is the host application exe filename, e.g. WebView2Example.exe
158/// - `{pipe_name}` is the value set for WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER.
159///
160/// To enable debugging of the targets identified by the JSON you will also need
161/// to set the WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environment variable to
162/// send `--remote-debugging-port={port_num}`
163/// where:
164///
165/// - `{port_num}` is the port on which the CDP server will bind.
166///
167/// Be aware that setting both the WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER and
168/// WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environment variables will cause the
169/// WebViews hosted in your application and their contents to be exposed to
170/// 3rd party applications such as debuggers.
171///
172/// Note: There is no registry key equivalent of this environment variable.
173///
174/// If none of those environment variables exist, then the registry is examined next.
175/// The following registry keys are checked:
176///
177/// ```
178/// [{Root}\Software\Policies\Microsoft\EmbeddedBrowserWebView\LoaderOverride\{AppId}]
179/// "releaseChannelPreference"=dword:00000000
180/// "browserExecutableFolder"=""
181/// "userDataFolder"=""
182/// "additionalBrowserArguments"=""
183/// ```
184///
185/// In the unlikely scenario where some instances of WebView are open during
186/// a browser update we could end up blocking the deletion of old Edge browsers.
187/// To avoid running out of disk space a new WebView creation will fail
188/// with the next error if it detects that there are many old versions present.
189///
190/// ```
191/// ERROR_DISK_FULL
192/// ```
193///
194/// The default maximum number of Edge versions allowed is 20.
195///
196/// The maximum number of old Edge versions allowed can be overwritten with the value
197/// of the following environment variable.
198///
199/// ```
200/// WEBVIEW2_MAX_INSTANCES
201/// ```
202///
203/// If the Webview depends on an installed Edge and it is uninstalled
204/// any subsequent creation will fail with the next error
205///
206/// ```
207/// ERROR_PRODUCT_UNINSTALLED
208/// ```
209///
210/// First we check with Root as HKLM and then HKCU.
211/// AppId is first set to the Application User Model ID of the caller's process,
212/// then if there's no corresponding registry key the AppId is
213/// set to the executable name of the caller's process, or if that
214/// isn't a registry key then '*'. If an override registry key is found then we
215/// use the browserExecutableFolder, userDataFolder and additionalBrowserArguments
216/// registry values as replacements for the corresponding values in
217/// CreateCoreWebView2EnvironmentWithOptions parameters.
218extern "stdcall" {
219 pub fn CreateCoreWebView2EnvironmentWithOptions(
220 browserExecutableFolder: PCWSTR,
221 userDataFolder: PCWSTR,
222 environment_options: *mut *mut ICoreWebView2EnvironmentOptionsVTable,
223 environment_created_handler: *mut *mut ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerVTable,
224 ) -> HRESULT;
225}
226
227/// Get the browser version info including channel name if it is not the stable channel
228/// or the Embedded Edge.
229/// Channel names are beta, dev, and canary.
230/// If an override exists for the browserExecutableFolder or the channel preference,
231/// the override will be used.
232/// If there isn't an override, then the parameter passed to
233/// GetAvailableCoreWebView2BrowserVersionString is used.
234extern "stdcall" {
235 pub fn GetAvailableCoreWebView2BrowserVersionString(
236 browser_executable_folder: PCWSTR,
237 version_info: *mut LPWSTR,
238 ) -> HRESULT;
239}
240
241/// This method is for anyone want to compare version correctly to determine
242/// which version is newer, older or same. It can be used to determine whether
243/// to use webview2 or certain feature base on version.
244/// Sets the value of result to -1, 0 or 1 if version1 is less than, equal or
245/// greater than version2 respectively.
246/// Returns E_INVALIDARG if it fails to parse any of the version strings or any
247/// input parameter is null.
248/// Input can directly use the versionInfo obtained from
249/// GetAvailableCoreWebView2BrowserVersionString, channel info will be ignored.
250extern "stdcall" {
251 pub fn CompareBrowserVersions(version1: PCWSTR, version2: PCWSTR, result: *mut i32) -> HRESULT;
252}
253/// Contains the information packed into the `LPARAM` sent to a Win32 key
254/// event. For more information about `WM_KEYDOWN`, navigate to
255/// \[WM_KEYDOWN message\]\[WindowsWin32InputdevWmKeydown\].
256///
257/// \[WindowsWin32InputdevWmKeydown\]: /windows/win32/inputdev/wm-keydown "WM_KEYDOWN message | Microsoft Docs"
258#[repr(C)]
259#[derive(Debug, Copy, Clone, Eq, PartialEq)]
260pub struct PhysicalKeyStatus {
261 /// Specifies the repeat count for the current message.
262 pub repeat_count: u32,
263 /// Specifies the scan code.
264 pub scan_code: u32,
265 /// Indicates that the key is an extended key.
266 pub is_extended_key: BOOL,
267 /// Indicates that a menu key is held down (context code).
268 pub is_menu_key_down: BOOL,
269 /// Indicates that the key was held down.
270 pub was_key_down: BOOL,
271 /// Indicates that the key was released.
272 pub is_key_released: BOOL,
273}
274
275/// A value representing RGBA color (Red, Green, Blue, Alpha) for WebView2.
276/// Each component takes a value from 0 to 255, with 0 being no intensity
277/// and 255 being the highest intensity.
278#[repr(C)]
279#[derive(Debug, Copy, Clone, Eq, PartialEq)]
280pub struct Color {
281 /// Specifies the intensity of the Alpha ie. opacity value. 0 is transparent,
282 /// 255 is opaque.
283 pub a: BYTE,
284 /// Specifies the intensity of the Red color.
285 pub r: BYTE,
286 /// Specifies the intensity of the Green color.
287 pub g: BYTE,
288 /// Specifies the intensity of the Blue color.
289 pub b: BYTE,
290}
291
292/// Specifies the image format for the `ICoreWebView2::CapturePreview` method.
293#[repr(u32)]
294#[derive(Debug, Copy, Clone, Eq, PartialEq)]
295pub enum CapturePreviewImageFormat {
296 /// Indicates that the PNG image format is used.
297 PNG,
298 /// Indicates the JPEG image format is used.
299 JPEG,
300}
301
302/// Kind of cookie SameSite status used in the ICoreWebView2Cookie interface.
303/// These fields match those as specified in https://developer.mozilla.org/docs/Web/HTTP/Cookies#.
304/// Learn more about SameSite cookies here: https://tools.ietf.org/html/draft-west-first-party-cookies-07
305#[repr(u32)]
306#[derive(Debug, Copy, Clone, Eq, PartialEq)]
307pub enum CookieSameSiteKind {
308 /// None SameSite type. No restrictions on cross-site requests.
309 None,
310 /// Lax SameSite type. The cookie will be sent with "same-site" requests, and with "cross-site" top level navigation.
311 Lax,
312 /// Strict SameSite type. The cookie will only be sent along with "same-site" requests.
313 Strict,
314}
315
316/// Kind of cross origin resource access allowed for host resources during download.
317/// Note that other normal access checks like same origin DOM access check and [Content
318/// Security Policy](https://developer.mozilla.org/docs/Web/HTTP/CSP) still apply.
319/// The following table illustrates the host resource cross origin access according to
320/// access context and `COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND`.
321///
322/// Cross Origin Access Context | DENY | ALLOW | DENY_CORS
323/// --- | --- | --- | ---
324/// From DOM like src of img, script or iframe element| Deny | Allow | Allow
325/// From Script like Fetch or XMLHttpRequest| Deny | Allow | Deny
326#[repr(u32)]
327#[derive(Debug, Copy, Clone, Eq, PartialEq)]
328pub enum HostResourceAccessKind {
329 /// All cross origin resource access is denied, including normal sub resource access
330 /// as src of a script or image element.
331 Deny,
332 /// All cross origin resource access is allowed, including accesses that are
333 /// subject to Cross-Origin Resource Sharing(CORS) check. The behavior is similar to
334 /// a web site sends back http header Access-Control-Allow-Origin: *.
335 Allow,
336 /// Cross origin resource access is allowed for normal sub resource access like
337 /// as src of a script or image element, while any access that subjects to CORS check
338 /// will be denied.
339 /// See [Cross-Origin Resource Sharing](https://developer.mozilla.org/docs/Web/HTTP/CORS)
340 /// for more information.
341 DenyCors,
342}
343
344/// Specifies the JavaScript dialog type used in the
345/// `ICoreWebView2ScriptDialogOpeningEventHandler` interface.
346#[repr(u32)]
347#[derive(Debug, Copy, Clone, Eq, PartialEq)]
348pub enum ScriptDialogKind {
349 /// Indicates that the dialog uses the `window.alert` JavaScript function.
350 Alert,
351 /// Indicates that the dialog uses the `window.confirm` JavaScript function.
352 Confirm,
353 /// Indicates that the dialog uses the `window.prompt` JavaScript function.
354 Prompt,
355 /// Indicates that the dialog uses the `beforeunload` JavaScript event.
356 Beforeunload,
357}
358
359/// Specifies the process failure type used in the
360/// `ICoreWebView2ProcessFailedEventHandler` interface. The values in this enum
361/// make reference to the process kinds in the Chromium architecture. For more
362/// information about what these processes are and what they do, see
363/// [Browser Architecture - Inside look at modern web browser](https://developers.google.com/web/updates/2018/09/inside-browser-part1).
364#[repr(u32)]
365#[derive(Debug, Copy, Clone, Eq, PartialEq)]
366pub enum ProcessFailedKind {
367 /// Indicates that the browser process ended unexpectedly. The WebView
368 /// automatically moves to the Closed state. The app has to recreate a new
369 /// WebView to recover from this failure.
370 BrowserProcessExited,
371 /// Indicates that the main frame's render process ended unexpectedly. A new
372 /// render process is created automatically and navigated to an error page.
373 /// You can use the `Reload` method to try to reload the page that failed.
374 RenderProcessExited,
375 /// Indicates that the main frame's render process is unresponsive.
376 RenderProcessUnresponsive,
377 /// Indicates that a frame-only render process ended unexpectedly. The process
378 /// exit does not affect the top-level document, only a subset of the
379 /// subframes within it. The content in these frames is replaced with an error
380 /// page in the frame.
381 FrameRenderProcessExited,
382 /// Indicates that a utility process ended unexpectedly.
383 UtilityProcessExited,
384 /// Indicates that a sandbox helper process ended unexpectedly.
385 SandboxHelperProcessExited,
386 /// Indicates that the GPU process ended unexpectedly.
387 GpuProcessExited,
388 /// Indicates that a PPAPI plugin process ended unexpectedly.
389 PpapiPluginProcessExited,
390 /// Indicates that a PPAPI plugin broker process ended unexpectedly.
391 PpapiBrokerProcessExited,
392 /// Indicates that a process of unspecified kind ended unexpectedly.
393 UnknownProcessExited,
394}
395
396/// Specifies the process failure reason used in the
397/// `ICoreWebView2ProcessFailedEventHandler` interface.
398#[repr(u32)]
399#[derive(Debug, Copy, Clone, Eq, PartialEq)]
400pub enum ProcessFailedReason {
401 /// An unexpected process failure occurred.
402 Unexpected,
403 /// The process became unresponsive.
404 /// This only applies to the main frame's render process.
405 Unresponsive,
406 /// The process was terminated. For example, from Task Manager.
407 Terminated,
408 /// The process crashed.
409 Crashed,
410 /// The process failed to launch.
411 LaunchFailed,
412 /// The process died due to running out of memory.
413 OutOfMemory,
414}
415
416/// Indicates the type of a permission request.
417#[repr(u32)]
418#[derive(Debug, Copy, Clone, Eq, PartialEq)]
419pub enum PermissionKind {
420 /// Indicates an unknown permission.
421 UnknownPermission,
422 /// Indicates permission to capture audio.
423 Microphone,
424 /// Indicates permission to capture video.
425 Camera,
426 /// Indicates permission to access geolocation.
427 Geolocation,
428 /// Indicates permission to send web notifications. This permission request
429 /// is currently auto-rejected and no event is run for it.
430 Notifications,
431 /// Indicates permission to access generic sensor. Generic Sensor covering
432 /// ambient-light-sensor, accelerometer, gyroscope, and magnetometer.
433 OtherSensors,
434 /// Indicates permission to read the system clipboard without a user gesture.
435 ClipboardRead,
436}
437
438/// Specifies the response to a permission request.
439#[repr(u32)]
440#[derive(Debug, Copy, Clone, Eq, PartialEq)]
441pub enum PermissionState {
442 /// Specifies that the default browser behavior is used, which normally
443 /// prompt users for decision.
444 Default,
445 /// Specifies that the permission request is granted.
446 Allow,
447 /// Specifies that the permission request is denied.
448 Deny,
449}
450
451/// Indicates the error status values for web navigations.
452#[repr(u32)]
453#[derive(Debug, Copy, Clone, Eq, PartialEq)]
454pub enum WebErrorStatus {
455 /// Indicates that an unknown error occurred.
456 Unknown,
457 /// Indicates that the SSL certificate common name does not match the web
458 /// address.
459 CertificateCommonNameIsIncorrect,
460 /// Indicates that the SSL certificate has expired.
461 CertificateExpired,
462 /// Indicates that the SSL client certificate contains errors.
463 ClientCertificateContainsErrors,
464 /// Indicates that the SSL certificate has been revoked.
465 CertificateRevoked,
466 /// Indicates that the SSL certificate is not valid. The certificate may not
467 /// match the public key pins for the host name, the certificate is signed
468 /// by an untrusted authority or using a weak sign algorithm, the certificate
469 /// claimed DNS names violate name constraints, the certificate contains a
470 /// weak key, the validity period of the certificate is too long, lack of
471 /// revocation information or revocation mechanism, non-unique host name,
472 /// lack of certificate transparency information, or the certificate is
473 /// chained to a
474 /// \[legacy Symantec root\]\[GoogleblogSecurity201803DistrustSymantecPkiImmediateHtml\].
475 ///
476 /// \[GoogleblogSecurity201803DistrustSymantecPkiImmediateHtml\]: https://security.googleblog.com/2018/03/distrust-of-symantec-pki-immediate.html "Distrust of the Symantec PKI: Immediate action needed by site operators | Google Security Blog"
477 CertificateIsInvalid,
478 /// Indicates that the host is unreachable.
479 ServerUnreachable,
480 /// Indicates that the connection has timed out.
481 Timeout,
482 /// Indicates that the server returned an invalid or unrecognized response.
483 ErrorHttpInvalidServerResponse,
484 /// Indicates that the connection was stopped.
485 ConnectionAborted,
486 /// Indicates that the connection was reset.
487 ConnectionReset,
488 /// Indicates that the Internet connection has been lost.
489 Disconnected,
490 /// Indicates that a connection to the destination was not established.
491 CannotConnect,
492 /// Indicates that the provided host name was not able to be resolved.
493 HostNameNotResolved,
494 /// Indicates that the operation was canceled.
495 OperationCanceled,
496 /// Indicates that the request redirect failed.
497 RedirectFailed,
498 /// Indicates that an unexpected error occurred.
499 UnexpectedError,
500}
501
502/// Specifies the web resource request contexts.
503#[repr(u32)]
504#[derive(Debug, Copy, Clone, Eq, PartialEq)]
505pub enum WebResourceContext {
506 /// Specifies all resources.
507 All,
508 /// Specifies a document resource.
509 Document,
510 /// Specifies a CSS resource.
511 Stylesheet,
512 /// Specifies an image resource.
513 Image,
514 /// Specifies another media resource such as a video.
515 Media,
516 /// Specifies a font resource.
517 Font,
518 /// Specifies a script resource.
519 Script,
520 /// Specifies an XML HTTP request.
521 XmlHttpRequest,
522 /// Specifies a Fetch API communication.
523 Fetch,
524 /// Specifies a TextTrack resource.
525 TextTrack,
526 /// Specifies an EventSource API communication.
527 EventSource,
528 /// Specifies a WebSocket API communication.
529 Websocket,
530 /// Specifies a Web App Manifest.
531 Manifest,
532 /// Specifies a Signed HTTP Exchange.
533 SignedExchange,
534 /// Specifies a Ping request.
535 Ping,
536 /// Specifies a CSP Violation Report.
537 CspViolationReport,
538 /// Specifies an other resource.
539 Other,
540}
541
542/// Specifies the reason for moving focus.
543#[repr(u32)]
544#[derive(Debug, Copy, Clone, Eq, PartialEq)]
545pub enum MoveFocusReason {
546 /// Specifies that the code is setting focus into WebView.
547 Programmatic,
548 /// Specifies that the focus is moving due to Tab traversal forward.
549 Next,
550 /// Specifies that the focus is moving due to Tab traversal backward.
551 Previous,
552}
553
554/// Specifies the key event type that triggered an `AcceleratorKeyPressed`
555/// event.
556#[repr(u32)]
557#[derive(Debug, Copy, Clone, Eq, PartialEq)]
558pub enum KeyEventKind {
559 /// Specifies that the key event type corresponds to window message
560 /// `WM_KEYDOWN`.
561 KeyDown,
562 /// Specifies that the key event type corresponds to window message
563 /// `WM_KEYUP`.
564 KeyUp,
565 /// Specifies that the key event type corresponds to window message
566 /// `WM_SYSKEYDOWN`.
567 SystemKeyDown,
568 /// Specifies that the key event type corresponds to window message
569 /// `WM_SYSKEYUP`.
570 SystemKeyUp,
571}
572
573/// Mouse event type used by SendMouseInput to convey the type of mouse event
574/// being sent to WebView. The values of this enum align with the matching
575/// WM_* window messages.
576#[repr(u32)]
577#[derive(Debug, Copy, Clone, Eq, PartialEq)]
578pub enum MouseEventKind {
579 /// Mouse horizontal wheel scroll event, WM_MOUSEHWHEEL.
580 HorizontalWheel = 0x020E,
581 /// Left button double click mouse event, WM_LBUTTONDBLCLK.
582 LeftButtonDoubleClick = 0x0203,
583 /// Left button down mouse event, WM_LBUTTONDOWN.
584 LeftButtonDown = 0x0201,
585 /// Left button up mouse event, WM_LBUTTONUP.
586 LeftButtonUp = 0x0202,
587 /// Mouse leave event, WM_MOUSELEAVE.
588 Leave = 0x02A3,
589 /// Middle button double click mouse event, WM_MBUTTONDBLCLK.
590 MiddleButtonDoubleClick = 0x0209,
591 /// Middle button down mouse event, WM_MBUTTONDOWN.
592 MiddleButtonDown = 0x0207,
593 /// Middle button up mouse event, WM_MBUTTONUP.
594 MiddleButtonUp = 0x0208,
595 /// Mouse move event, WM_MOUSEMOVE.
596 Move = 0x0200,
597 /// Right button double click mouse event, WM_RBUTTONDBLCLK.
598 RightButtonDoubleClick = 0x0206,
599 /// Right button down mouse event, WM_RBUTTONDOWN.
600 RightButtonDown = 0x0204,
601 /// Right button up mouse event, WM_RBUTTONUP.
602 RightButtonUp = 0x0205,
603 /// Mouse wheel scroll event, WM_MOUSEWHEEL.
604 Wheel = 0x020A,
605 /// First or second X button double click mouse event, WM_XBUTTONDBLCLK.
606 XButtonDoubleClick = 0x020D,
607 /// First or second X button down mouse event, WM_XBUTTONDOWN.
608 XButtonDown = 0x020B,
609 /// First or second X button up mouse event, WM_XBUTTONUP.
610 XButtonUp = 0x020C,
611}
612
613/// Mouse event virtual keys associated with a COREWEBVIEW2_MOUSE_EVENT_KIND for
614/// SendMouseInput. These values can be combined into a bit flag if more than
615/// one virtual key is pressed for the event. The values of this enum align
616/// with the matching MK_* mouse keys.
617#[repr(u32)]
618#[derive(Debug, Copy, Clone, Eq, PartialEq)]
619pub enum MouseEventVirtualKeys {
620 /// No additional keys pressed.
621 None = 0x0,
622 /// Left mouse button is down, MK_LBUTTON.
623 LeftButton = 0x0001,
624 /// Right mouse button is down, MK_RBUTTON.
625 RightButton = 0x0002,
626 /// SHIFT key is down, MK_SHIFT.
627 Shift = 0x0004,
628 /// CTRL key is down, MK_CONTROL.
629 Control = 0x0008,
630 /// Middle mouse button is down, MK_MBUTTON.
631 MiddleButton = 0x0010,
632 /// First X button is down, MK_XBUTTON1
633 XButton1 = 0x0020,
634 /// Second X button is down, MK_XBUTTON2
635 XButton2 = 0x0040,
636}
637
638/// Pointer event type used by SendPointerInput to convey the type of pointer
639/// event being sent to WebView. The values of this enum align with the
640/// matching WM_POINTER* window messages.
641#[repr(u32)]
642#[derive(Debug, Copy, Clone, Eq, PartialEq)]
643pub enum PointerEventKind {
644 /// Corresponds to WM_POINTERACTIVATE.
645 Activate = 0x024B,
646 /// Corresponds to WM_POINTERDOWN.
647 Down = 0x0246,
648 /// Corresponds to WM_POINTERENTER.
649 Enter = 0x0249,
650 /// Corresponds to WM_POINTERLEAVE.
651 Leave = 0x024A,
652 /// Corresponds to WM_POINTERUP.
653 Up = 0x0247,
654 /// Corresponds to WM_POINTERUPDATE.
655 Update = 0x0245,
656}
657
658/// Mode for how the Bounds property is interpreted in relation to the RasterizationScale property.
659#[repr(u32)]
660#[derive(Debug, Copy, Clone, Eq, PartialEq)]
661pub enum BoundsMode {
662 /// Bounds property represents raw pixels. Physical size of Webview is not impacted by RasterizationScale.
663 UseRawPixels,
664 /// Bounds property represents logicl pixels and the RasterizationScale property is used to get the physical size of the WebView.
665 UseRasterizationScale,
666}
667
668#[repr(u32)]
669#[derive(Debug, Copy, Clone, Eq, PartialEq)]
670pub enum ClientCertificateKind {
671 /// Specifies smart card certificate.
672 SmartCard,
673 /// Specifies PIN certificate.
674 Pin,
675 /// Specifies other certificate.
676 Other,
677}
678
679/// State of the download operation.
680#[repr(u32)]
681#[derive(Debug, Copy, Clone, Eq, PartialEq)]
682pub enum DownloadState {
683 /// The download is in progress.
684 InProgress,
685 /// The connection with the file host was broken. The `InterruptReason` property
686 /// can be accessed from `ICoreWebView2DownloadOperation`. See
687 /// `COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON` for descriptions of kinds of
688 /// interrupt reasons. Host can check whether an interrupted download can be
689 /// resumed with the `CanResume` property on the `ICoreWebView2DownloadOperation`.
690 /// Once resumed, a download is in the `COREWEBVIEW2_DOWNLOAD_STATE_IN_PROGRESS` state.
691 Interrupted,
692 /// The download completed successfully.
693 Completed,
694}
695
696/// Reason why a download was interrupted.
697#[repr(u32)]
698#[derive(Debug, Copy, Clone, Eq, PartialEq)]
699pub enum DownloadInterruptReason {
700 None,
701 /// Generic file error.
702 FileFailed,
703 /// Access denied due to security restrictions.
704 FileAccessDenied,
705 /// Disk full. User should free some space or choose a different location to
706 /// store the file.
707 FileNoSpace,
708 /// Result file path with file name is too long.
709 FileNameTooLong,
710 /// File is too large for file system.
711 FileTooLarge,
712 /// Microsoft Defender Smartscreen detected a virus in the file.
713 FileMalicious,
714 /// File was in use, too many files opened, or out of memory.
715 FileTransientError,
716 /// File blocked by local policy.
717 FileBlockedByPolicy,
718 /// Security check failed unexpectedly. Microsoft Defender SmartScreen could
719 /// not scan this file.
720 FileSecurityCheckFailed,
721 /// Seeking past the end of a file in opening a file, as part of resuming an
722 /// interrupted download. The file did not exist or was not as large as
723 /// expected. Partially downloaded file was truncated or deleted, and download
724 /// will be restarted automatically.
725 FileTooShort,
726 /// Partial file did not match the expected hash and was deleted. Download
727 /// will be restarted automatically.
728 FileHashMismatch,
729 /// Generic network error. User can retry the download manually.
730 NetworkFailed,
731 /// Network operation timed out.
732 NetworkTimeout,
733 /// Network connection lost. User can retry the download manually.
734 NetworkDisconnected,
735 /// Server has gone down. User can retry the download manually.
736 NetworkServerDown,
737 /// Network request invalid because original or redirected URI is invalid, has
738 /// an unsupported scheme, or is disallowed by network policy.
739 NetworkInvalidRequest,
740 /// Generic server error. User can retry the download manually.
741 ServerFailed,
742 /// Server does not support range requests.
743 ServerNoRange,
744 /// Server does not have the requested data.
745 ServerBadContent,
746 /// Server did not authorize access to resource.
747 ServerUnauthorized,
748 /// Server certificate problem.
749 ServerCertificateProblem,
750 /// Server access forbidden.
751 ServerForbidden,
752 /// Unexpected server response. Responding server may not be intended server.
753 /// User can retry the download manually.
754 ServerUnexpectedResponse,
755 /// Server sent fewer bytes than the Content-Length header. Content-length
756 /// header may be invalid or connection may have closed. Download is treated
757 /// as complete unless there are
758 /// [strong validators](https://tools.ietf.org/html/rfc7232#section-2) present
759 /// to interrupt the download.
760 ServerContentLengthMismatch,
761 /// Unexpected cross-origin redirect.
762 ServerCrossOriginRedirect,
763 /// User canceled the download.
764 UserCanceled,
765 /// User shut down the WebView. Resuming downloads that were interrupted
766 /// during shutdown is not yet supported.
767 UserShutdown,
768 /// User paused the download.
769 UserPaused,
770 /// WebView crashed.
771 DownloadProcessCrashed,
772}
773
774/// WebView2 enables you to host web content using the latest Microsoft Edge
775/// browser and web technology.
776#[com_interface("76eceacb-0462-4d94-ac83-423a6793775e")]
777pub trait ICoreWebView2: IUnknown {
778 /// The `ICoreWebView2Settings` object contains various modifiable settings
779 /// for the running WebView.
780 unsafe fn get_settings(
781 &self,
782 /* out, retval */ settings: *mut *mut *mut ICoreWebView2SettingsVTable,
783 ) -> HRESULT;
784
785 /// The URI of the current top level document. This value potentially
786 /// changes as a part of the `SourceChanged` event that runs for some cases
787 /// such as navigating to a different site or fragment navigations. It
788 /// remains the same for other types of navigations such as page refreshes
789 /// or `history.pushState` with the same URL as the current page.
790 ///
791 /// \snippet ControlComponent.cpp SourceChanged
792 unsafe fn get_source(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;
793
794 /// Cause a navigation of the top-level document to run to the specified URI.
795 /// For more information, navigate to \[Navigation events\]\[MicrosoftEdgeWebview2ConceptsNavigationevents\].
796 ///
797 /// \[MicrosoftEdgeWebview2ConceptsNavigationevents\]: /microsoft-edge/webview2/concepts/navigation-events "Navigation events | Microsoft Docs"
798 ///
799 /// \> [!NOTE]\n\> This operation starts a navigation and the corresponding
800 /// `NavigationStarting` event triggers sometime after `Navigate` runs.
801 ///
802 /// \snippet ControlComponent.cpp Navigate
803 unsafe fn navigate(&self, /* in */ uri: LPCWSTR) -> HRESULT;
804
805 /// Initiates a navigation to htmlContent as source HTML of a new document.
806 /// The `htmlContent` parameter may not be larger than 2 MB (2 * 1024 * 1024 bytes) in total size.
807 /// The origin of the new page is `about:blank`.
808 ///
809 /// \snippet SettingsComponent.cpp NavigateToString
810 unsafe fn navigate_to_string(&self, /* in */ html_content: LPCWSTR) -> HRESULT;
811
812 /// Add an event handler for the `NavigationStarting` event.
813 /// `NavigationStarting` runs when the WebView main frame is requesting
814 /// permission to navigate to a different URI. Redirects trigger this
815 /// operation as well, and the navigation id is the same as the original
816 /// one.
817 ///
818 /// You may block corresponding navigations until the event handler returns.
819 ///
820 /// \snippet SettingsComponent.cpp NavigationStarting
821 unsafe fn add_navigation_starting(
822 &self,
823 /* in */ event_handler: *mut *mut ICoreWebView2NavigationStartingEventHandlerVTable,
824 /* out */ token: *mut EventRegistrationToken,
825 ) -> HRESULT;
826
827 /// Remove an event handler previously added with `add_NavigationStarting`.
828 unsafe fn remove_navigation_starting(
829 &self,
830 /* in */ token: EventRegistrationToken,
831 ) -> HRESULT;
832
833 /// Add an event handler for the `ContentLoading` event. `ContentLoading`
834 /// triggers before any content is loaded, including scripts added with
835 /// `AddScriptToExecuteOnDocumentCreated`. `ContentLoading` does not trigger
836 /// if a same page navigation occurs (such as through `fragment`
837 /// navigations or `history.pushState` navigations). This operation
838 /// follows the `NavigationStarting` and `SourceChanged` events and precedes
839 /// the `HistoryChanged` and `NavigationCompleted` events.
840 unsafe fn add_content_loading(
841 &self,
842 /* in */ event_handler: *mut *mut ICoreWebView2ContentLoadingEventHandlerVTable,
843 /* out */ token: *mut EventRegistrationToken,
844 ) -> HRESULT;
845
846 /// Remove an event handler previously added with `add_ContentLoading`.
847 unsafe fn remove_content_loading(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
848
849 /// Add an event handler for the `SourceChanged` event. `SourceChanged`
850 /// triggers when the `Source` property changes. `SourceChanged` runs when
851 /// navigating to a different site or fragment navigations. It does not
852 /// trigger for other types of navigations such as page refreshes or
853 /// `history.pushState` with the same URL as the current page.
854 /// `SourceChanged` runs before `ContentLoading` for navigation to a new
855 /// document.
856 ///
857 /// \snippet ControlComponent.cpp SourceChanged
858 unsafe fn add_source_changed(
859 &self,
860 /* in */ event_handler: *mut *mut ICoreWebView2SourceChangedEventHandlerVTable,
861 /* out */ token: *mut EventRegistrationToken,
862 ) -> HRESULT;
863
864 /// Remove an event handler previously added with `add_SourceChanged`.
865 unsafe fn remove_source_changed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
866
867 /// Add an event handler for the `HistoryChanged` event. `HistoryChanged`
868 /// listens to the change of navigation history for the top level document.
869 /// Use `HistoryChanged` to verify that the `CanGoBack` or `CanGoForward`
870 /// value has changed. `HistoryChanged` also runs for using `GoBack`or
871 /// `GoForward`. `HistoryChanged` runs after `SourceChanged` and
872 /// `ContentLoading`.
873 ///
874 /// \snippet ControlComponent.cpp HistoryChanged
875 unsafe fn add_history_changed(
876 &self,
877 /* in */ event_handler: *mut *mut ICoreWebView2HistoryChangedEventHandlerVTable,
878 /* out */ token: *mut EventRegistrationToken,
879 ) -> HRESULT;
880
881 /// Remove an event handler previously added with `add_HistoryChanged`.
882 unsafe fn remove_history_changed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
883
884 /// Add an event handler for the `NavigationCompleted` event.
885 /// `NavigationCompleted` runs when the WebView has completely loaded
886 /// (`body.onload` runs) or loading stopped with error.
887 ///
888 /// \snippet ControlComponent.cpp NavigationCompleted
889 unsafe fn add_navigation_completed(
890 &self,
891 /* in */ event_handler: *mut *mut ICoreWebView2NavigationCompletedEventHandlerVTable,
892 /* out */ token: *mut EventRegistrationToken,
893 ) -> HRESULT;
894
895 /// Remove an event handler previously added with `add_NavigationCompleted`.
896 unsafe fn remove_navigation_completed(
897 &self,
898 /* in */ token: EventRegistrationToken,
899 ) -> HRESULT;
900
901 /// Add an event handler for the `FrameNavigationStarting` event.
902 /// `FrameNavigationStarting` triggers when a child frame in the WebView
903 /// requests permission to navigate to a different URI. Redirects trigger
904 /// this operation as well, and the navigation id is the same as the original
905 /// one.
906 ///
907 /// You may block corresponding navigations until the event handler returns.
908 ///
909 /// \snippet SettingsComponent.cpp FrameNavigationStarting
910 unsafe fn add_frame_navigation_starting(
911 &self,
912 /* in */ event_handler: *mut *mut ICoreWebView2NavigationStartingEventHandlerVTable,
913 /* out */ token: *mut EventRegistrationToken,
914 ) -> HRESULT;
915
916 /// Remove an event handler previously added with
917 /// `add_FrameNavigationStarting`.
918 unsafe fn remove_frame_navigation_starting(
919 &self,
920 /* in */ token: EventRegistrationToken,
921 ) -> HRESULT;
922
923 /// Add an event handler for the `FrameNavigationCompleted` event.
924 /// `FrameNavigationCompleted` triggers when a child frame has completely
925 /// loaded (`body.onload` has triggered) or loading stopped with error.
926 ///
927 /// \snippet ControlComponent.cpp FrameNavigationCompleted
928 unsafe fn add_frame_navigation_completed(
929 &self,
930 /* in */ event_handler: *mut *mut ICoreWebView2NavigationCompletedEventHandlerVTable,
931 /* out */ token: *mut EventRegistrationToken,
932 ) -> HRESULT;
933
934 /// Remove an event handler previously added with
935 /// `add_FrameNavigationCompleted`.
936 unsafe fn remove_frame_navigation_completed(
937 &self,
938 /* in */ token: EventRegistrationToken,
939 ) -> HRESULT;
940
941 /// Add an event handler for the `ScriptDialogOpening` event.
942 /// `ScriptDialogOpening` runs when a JavaScript dialog (`alert`, `confirm`,
943 /// `prompt`, or `beforeunload`) displays for the webview. This event only
944 /// triggers if the `ICoreWebView2Settings::AreDefaultScriptDialogsEnabled`
945 /// property is set to `FALSE`. The `ScriptDialogOpening` event suppresses
946 /// dialogs or replaces default dialogs with custom dialogs.
947 ///
948 /// If a deferral is not taken on the event args, the subsequent scripts are
949 /// blocked until the event handler returns. If a deferral is taken, the
950 /// scripts are blocked until the deferral is completed.
951 ///
952 /// \snippet SettingsComponent.cpp ScriptDialogOpening
953 unsafe fn add_script_dialog_opening(
954 &self,
955 /* in */ event_handler: *mut *mut ICoreWebView2ScriptDialogOpeningEventHandlerVTable,
956 /* out */ token: *mut EventRegistrationToken,
957 ) -> HRESULT;
958
959 /// Remove an event handler previously added with `add_ScriptDialogOpening`.
960 unsafe fn remove_script_dialog_opening(
961 &self,
962 /* in */ token: EventRegistrationToken,
963 ) -> HRESULT;
964
965 /// Add an event handler for the `PermissionRequested` event.
966 /// `PermissionRequested` runs when content in a WebView requests permission
967 /// to access some privileged resources.
968 ///
969 /// If a deferral is not taken on the event args, the subsequent scripts are
970 /// blocked until the event handler returns. If a deferral is taken, the
971 /// scripts are blocked until the deferral is completed.
972 ///
973 /// \snippet SettingsComponent.cpp PermissionRequested
974 unsafe fn add_permission_requested(
975 &self,
976 /* in */ event_handler: *mut *mut ICoreWebView2PermissionRequestedEventHandlerVTable,
977 /* out */ token: *mut EventRegistrationToken,
978 ) -> HRESULT;
979
980 /// Remove an event handler previously added with `add_PermissionRequested`.
981 unsafe fn remove_permission_requested(
982 &self,
983 /* in */ token: EventRegistrationToken,
984 ) -> HRESULT;
985
986 /// Add an event handler for the `ProcessFailed` event. `ProcessFailed` runs
987 /// when a WebView process ends unexpectedly or becomes unresponsive.
988 ///
989 /// \snippet ProcessComponent.cpp ProcessFailed
990 unsafe fn add_process_failed(
991 &self,
992 /* in */ event_handler: *mut *mut ICoreWebView2ProcessFailedEventHandlerVTable,
993 /* out */ token: *mut EventRegistrationToken,
994 ) -> HRESULT;
995
996 /// Remove an event handler previously added with add_ProcessFailed.
997 unsafe fn remove_process_failed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
998
999 /// Add the provided JavaScript to a list of scripts that should be run after
1000 /// the global object has been created, but before the HTML document has
1001 /// been parsed and before any other script included by the HTML document is
1002 /// run. This method injects a script that runs on all top-level document
1003 /// and child frame page navigations. This method runs asynchronously, and
1004 /// you must wait for the completion handler to finish before the injected
1005 /// script is ready to run. When this method completes, the `Invoke` method
1006 /// of the handler is run with the `id` of the injected script. `id` is a
1007 /// string. To remove the injected script, use
1008 /// `RemoveScriptToExecuteOnDocumentCreated`.
1009 ///
1010 /// If the method is run in add_NewWindowRequested handler it should be called
1011 /// after the new window is set. For more details see `ICoreWebView2NewWindowRequestedEventArgs::put_NewWindow`.
1012 ///
1013 /// \> [!NOTE]\n\> If an HTML document is running in a sandbox of some kind using
1014 /// \[sandbox\]\[MdnDocsWebHtmlElementIframeAttrSandbox\]
1015 /// properties or the
1016 /// \[Content-Security-Policy\]\[MdnDocsWebHttpHeadersContentSecurityPolicy\]
1017 /// HTTP header affects the script that runs. For example, if the
1018 /// `allow-modals` keyword is not set then requests to run the `alert`
1019 /// function are ignored.
1020 ///
1021 /// \snippet ScriptComponent.cpp AddScriptToExecuteOnDocumentCreated
1022 ///
1023 /// \[MdnDocsWebHtmlElementIframeAttrSandbox\]: https://developer.mozilla.org/docs/Web/HTML/Element/iframe#attr-sandbox "sandbox - \<iframe\>: The Inline Frame element | MDN"
1024 ///
1025 /// \[MdnDocsWebHttpHeadersContentSecurityPolicy\]: https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy "Content-Security-Policy | MDN"
1026 unsafe fn add_script_to_execute_on_document_created(
1027 &self,
1028 /* in */ java_script: LPCWSTR,
1029 /* in */
1030 handler: *mut *mut ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandlerVTable,
1031 ) -> HRESULT;
1032
1033 /// Remove the corresponding JavaScript added using
1034 /// `AddScriptToExecuteOnDocumentCreated` with the specified script ID.
1035 unsafe fn remove_script_to_execute_on_document_created(
1036 &self,
1037 /* in */ id: LPCWSTR,
1038 ) -> HRESULT;
1039
1040 /// Run JavaScript code from the javascript parameter in the current
1041 /// top-level document rendered in the WebView. The result of evaluating
1042 /// the provided JavaScript is used in this parameter. The result value is
1043 /// a JSON encoded string. If the result is undefined, contains a reference
1044 /// cycle, or otherwise is not able to be encoded into JSON, the JSON `null`
1045 /// value is returned as the `null` string.
1046 ///
1047 /// \> [!NOTE]\n\> A function that has no explicit return value returns undefined. If the
1048 /// script that was run throws an unhandled exception, then the result is
1049 /// also `null`. This method is applied asynchronously. If the method is
1050 /// run after the `NavigationStarting` event during a navigation, the script
1051 /// runs in the new document when loading it, around the time
1052 /// `ContentLoading` is run. This operation works even if
1053 /// `ICoreWebView2Settings::IsScriptEnabled` is set to `FALSE`.
1054 ///
1055 /// \snippet ScriptComponent.cpp ExecuteScript
1056 unsafe fn execute_script(
1057 &self,
1058 /* in */ java_script: LPCWSTR,
1059 /* in */ handler: *mut *mut ICoreWebView2ExecuteScriptCompletedHandlerVTable,
1060 ) -> HRESULT;
1061
1062 /// Capture an image of what WebView is displaying. Specify the format of
1063 /// the image with the `imageFormat` parameter. The resulting image binary
1064 /// data is written to the provided `imageStream` parameter. When
1065 /// `CapturePreview` finishes writing to the stream, the `Invoke` method on
1066 /// the provided `handler` parameter is run. This method fails if called
1067 /// before the first ContentLoading event. For example if this is called in
1068 /// the NavigationStarting event for the first navigation it will fail.
1069 /// For subsequent navigations, the method may not fail, but will not capture
1070 /// an image of a given webpage until the ContentLoading event has been fired
1071 /// for it. Any call to this method prior to that will result in a capture of
1072 /// the page being navigated away from.
1073 ///
1074 /// \snippet FileComponent.cpp CapturePreview
1075 unsafe fn capture_preview(
1076 &self,
1077 /* in */ image_format: CapturePreviewImageFormat,
1078 /* in */ image_stream: *mut *mut IStreamVTable,
1079 /* in */ handler: *mut *mut ICoreWebView2CapturePreviewCompletedHandlerVTable,
1080 ) -> HRESULT;
1081
1082 /// Reload the current page. This is similar to navigating to the URI of
1083 /// current top level document including all navigation events firing and
1084 /// respecting any entries in the HTTP cache. But, the back or forward
1085 /// history are not modified.
1086 unsafe fn reload(&self) -> HRESULT;
1087
1088 /// Post the specified webMessage to the top level document in this WebView.
1089 /// Runs the message event of the `window.chrome.webview` of the top-level
1090 /// document. JavaScript in that document may subscribe and unsubscribe to
1091 /// the event using the following code.
1092 ///
1093 /// ```cpp
1094 /// window.chrome.webview.addEventListener('message', handler)
1095 /// window.chrome.webview.removeEventListener('message', handler)
1096 /// ```
1097 ///
1098 /// The event args is an instance of `MessageEvent`. The
1099 /// `ICoreWebView2Settings::IsWebMessageEnabled` setting must be `TRUE` or
1100 /// this method fails with `E_INVALIDARG`. The `data` property of the event
1101 /// arg is the `webMessage` string parameter parsed as a JSON string into a
1102 /// JavaScript object. The `source` property of the event arg is a reference
1103 /// to the `window.chrome.webview` object. For information about sending
1104 /// messages from the HTML document in the WebView to the host, navigate to
1105 /// \[add_WebMessageReceived]. The message is sent asynchronously. If a
1106 /// navigation occurs before the message is posted to the page, the message
1107 /// is not sent.
1108 ///
1109 /// \snippet ScenarioWebMessage.cpp WebMessageReceived
1110 unsafe fn post_web_message_as_json(
1111 &self,
1112 /* in */ web_message_as_json: LPCWSTR,
1113 ) -> HRESULT;
1114
1115 /// Posts a message that is a simple string rather than a JSON string
1116 /// representation of a JavaScript object. This behaves in exactly the same
1117 /// manner as `PostWebMessageAsJson`, but the `data` property of the event
1118 /// arg of the `window.chrome.webview` message is a string with the same
1119 /// value as `webMessageAsString`. Use this instead of
1120 /// `PostWebMessageAsJson` if you want to communicate using simple strings
1121 /// rather than JSON objects.
1122 unsafe fn post_web_message_as_string(
1123 &self,
1124 /* in */ web_message_as_string: LPCWSTR,
1125 ) -> HRESULT;
1126
1127 /// Add an event handler for the `WebMessageReceived` event.
1128 /// `WebMessageReceived` runs when the
1129 /// `ICoreWebView2Settings::IsWebMessageEnabled` setting is set and the
1130 /// top-level document of the WebView runs
1131 /// `window.chrome.webview.postMessage`. The `postMessage` function is
1132 /// `void postMessage(object)` where object is any object supported by JSON
1133 /// conversion.
1134 ///
1135 /// \snippet assets\ScenarioWebMessage.html chromeWebView
1136 ///
1137 /// When `postMessage` is run, the `Invoke` method of the `handler` is run
1138 /// with the `object` parameter of the `postMessage` converted to a JSON
1139 /// string.
1140 ///
1141 /// \snippet ScenarioWebMessage.cpp WebMessageReceived
1142 unsafe fn add_web_message_received(
1143 &self,
1144 /* in */ handler: *mut *mut ICoreWebView2WebMessageReceivedEventHandlerVTable,
1145 /* out */ token: *mut EventRegistrationToken,
1146 ) -> HRESULT;
1147
1148 /// Remove an event handler previously added with `add_WebMessageReceived`.
1149 unsafe fn remove_web_message_received(
1150 &self,
1151 /* in */ token: EventRegistrationToken,
1152 ) -> HRESULT;
1153
1154 /// Runs an asynchronous `DevToolsProtocol` method. For more information
1155 /// about available methods, navigate to
1156 /// \[DevTools Protocol Viewer\]\[GithubChromedevtoolsDevtoolsProtocolTot\]
1157 /// . The `methodName` parameter is the full name of the method in the
1158 /// `{domain}.{method}` format. The `parametersAsJson` parameter is a JSON
1159 /// formatted string containing the parameters for the corresponding method.
1160 /// The `Invoke` method of the `handler` is run when the method
1161 /// asynchronously completes. `Invoke` is run with the return object of the
1162 /// method as a JSON string.
1163 ///
1164 /// \snippet ScriptComponent.cpp CallDevToolsProtocolMethod
1165 ///
1166 /// \[GithubChromedevtoolsDevtoolsProtocolTot\]: https://chromedevtools.github.io/devtools-protocol/tot "latest (tip-of-tree) protocol - Chrome DevTools Protocol | GitHub"
1167 unsafe fn call_dev_tools_protocol_method(
1168 &self,
1169 /* in */ method_name: LPCWSTR,
1170 /* in */ parameters_as_json: LPCWSTR,
1171 /* in */
1172 handler: *mut *mut ICoreWebView2CallDevToolsProtocolMethodCompletedHandlerVTable,
1173 ) -> HRESULT;
1174
1175 /// The process ID of the browser process that hosts the WebView.
1176 unsafe fn get_browser_process_id(&self, /* out, retval */ value: *mut u32) -> HRESULT;
1177
1178 /// `TRUE` if the WebView is able to navigate to a previous page in the
1179 /// navigation history. If `CanGoBack` changes value, the `HistoryChanged`
1180 /// event runs.
1181 unsafe fn get_can_go_back(&self, /* out, retval */ can_go_back: *mut BOOL) -> HRESULT;
1182
1183 /// `TRUE` if the WebView is able to navigate to a next page in the
1184 /// navigation history. If `CanGoForward` changes value, the
1185 /// `HistoryChanged` event runs.
1186 unsafe fn get_can_go_forward(
1187 &self,
1188 /* out, retval */ can_go_forward: *mut BOOL,
1189 ) -> HRESULT;
1190
1191 /// Navigates the WebView to the previous page in the navigation history.
1192 unsafe fn go_back(&self) -> HRESULT;
1193
1194 /// Navigates the WebView to the next page in the navigation history.
1195 unsafe fn go_forward(&self) -> HRESULT;
1196
1197 /// Get a DevTools Protocol event receiver that allows you to subscribe to a
1198 /// DevTools Protocol event. The `eventName` parameter is the full name of
1199 /// the event in the format `{domain}.{event}`. For more information about
1200 /// DevTools Protocol events description and event args, navigate to
1201 /// \[DevTools Protocol Viewer\]\[GithubChromedevtoolsDevtoolsProtocolTot\].
1202 ///
1203 /// \snippet ScriptComponent.cpp DevToolsProtocolEventReceived
1204 ///
1205 /// \[GithubChromedevtoolsDevtoolsProtocolTot\]: https://chromedevtools.github.io/devtools-protocol/tot "latest (tip-of-tree) protocol - Chrome DevTools Protocol | GitHub"
1206 unsafe fn get_dev_tools_protocol_event_receiver(
1207 &self,
1208 /* in */ event_name: LPCWSTR,
1209 /* out, retval */
1210 receiver: *mut *mut *mut ICoreWebView2DevToolsProtocolEventReceiverVTable,
1211 ) -> HRESULT;
1212
1213 /// Stop all navigations and pending resource fetches. Does not stop scripts.
1214 unsafe fn stop(&self) -> HRESULT;
1215
1216 /// Add an event handler for the `NewWindowRequested` event.
1217 /// `NewWindowRequested` runs when content inside the WebView requests to
1218 /// open a new window, such as through `window.open`. The app passes a
1219 /// target WebView that is considered the opened window.
1220 ///
1221 /// If a deferral is not taken on the event args, scripts that resulted in
1222 /// the new window that are requested are blocked until the event handler
1223 /// returns. If a deferral is taken, then scripts are blocked until the
1224 /// deferral is completed or new window is set.
1225 ///
1226 /// For more details and considerations on the target WebView to be supplied
1227 /// at the opened window, see `ICoreWebView2NewWindowRequestedEventArgs::put_NewWindow`.
1228 ///
1229 /// \snippet AppWindow.cpp NewWindowRequested
1230 unsafe fn add_new_window_requested(
1231 &self,
1232 /* in */ event_handler: *mut *mut ICoreWebView2NewWindowRequestedEventHandlerVTable,
1233 /* out */ token: *mut EventRegistrationToken,
1234 ) -> HRESULT;
1235
1236 /// Remove an event handler previously added with `add_NewWindowRequested`.
1237 unsafe fn remove_new_window_requested(
1238 &self,
1239 /* in */ token: EventRegistrationToken,
1240 ) -> HRESULT;
1241
1242 /// Add an event handler for the `DocumentTitleChanged` event.
1243 /// `DocumentTitleChanged` runs when the `DocumentTitle` property of the
1244 /// WebView changes and may run before or after the `NavigationCompleted`
1245 /// event.
1246 ///
1247 /// \snippet FileComponent.cpp DocumentTitleChanged
1248 unsafe fn add_document_title_changed(
1249 &self,
1250 /* in */
1251 event_handler: *mut *mut ICoreWebView2DocumentTitleChangedEventHandlerVTable,
1252 /* out */ token: *mut EventRegistrationToken,
1253 ) -> HRESULT;
1254
1255 /// Remove an event handler previously added with `add_DocumentTitleChanged`.
1256 unsafe fn remove_document_title_changed(
1257 &self,
1258 /* in */ token: EventRegistrationToken,
1259 ) -> HRESULT;
1260
1261 /// The title for the current top-level document. If the document has no
1262 /// explicit title or is otherwise empty, a default that may or may not match
1263 /// the URI of the document is used.
1264 unsafe fn get_document_title(&self, /* out, retval */ title: *mut LPWSTR) -> HRESULT;
1265
1266 /// Add the provided host object to script running in the WebView with the
1267 /// specified name. Host objects are exposed as host object proxies using
1268 /// `window.chrome.webview.hostObjects.{name}`. Host object proxies are
1269 /// promises and resolves to an object representing the host object. The
1270 /// promise is rejected if the app has not added an object with the name.
1271 /// When JavaScript code access a property or method of the object, a promise
1272 /// is return, which resolves to the value returned from the host for the
1273 /// property or method, or rejected in case of error, for example, no
1274 /// property or method on the object or parameters are not valid.
1275 ///
1276 /// \> [!NOTE]\n\> While simple types, `IDispatch` and array are supported, generic
1277 /// `IUnknown`, `VT_DECIMAL`, or `VT_RECORD` variant is not supported.
1278 /// Remote JavaScript objects like callback functions are represented as an
1279 /// `VT_DISPATCH` `VARIANT` with the object implementing `IDispatch`. The
1280 /// JavaScript callback method may be invoked using `DISPID_VALUE` for the
1281 /// `DISPID`. Nested arrays are supported up to a depth of 3. Arrays of by
1282 /// reference types are not supported. `VT_EMPTY` and `VT_NULL` are mapped
1283 /// into JavaScript as `null`. In JavaScript, `null` and undefined are
1284 /// mapped to `VT_EMPTY`.
1285 ///
1286 /// Additionally, all host objects are exposed as
1287 /// `window.chrome.webview.hostObjects.sync.{name}`. Here the host objects
1288 /// are exposed as synchronous host object proxies. These are not promises
1289 /// and function runtimes or property access synchronously block running
1290 /// script waiting to communicate cross process for the host code to run.
1291 /// Accordingly the result may have reliability issues and it is recommended
1292 /// that you use the promise-based asynchronous
1293 /// `window.chrome.webview.hostObjects.{name}` API.
1294 ///
1295 /// Synchronous host object proxies and asynchronous host object proxies may
1296 /// both use a proxy to the same host object. Remote changes made by one
1297 /// proxy propagates to any other proxy of that same host object whether
1298 /// the other proxies and synchronous or asynchronous.
1299 ///
1300 /// While JavaScript is blocked on a synchronous run to native code, that
1301 /// native code is unable to run back to JavaScript. Attempts to do so fail
1302 /// with `HRESULT_FROM_WIN32(ERROR_POSSIBLE_DEADLOCK)`.
1303 ///
1304 /// Host object proxies are JavaScript Proxy objects that intercept all
1305 /// property get, property set, and method invocations. Properties or methods
1306 /// that are a part of the Function or Object prototype are run locally.
1307 /// Additionally any property or method in the
1308 /// `chrome.webview.hostObjects.options.forceLocalProperties`
1309 /// array are also run locally. This defaults to including optional methods
1310 /// that have meaning in JavaScript like `toJSON` and `Symbol.toPrimitive`.
1311 /// Add more to the array as required.
1312 ///
1313 /// The `chrome.webview.hostObjects.cleanupSome` method performs a best
1314 /// effort garbage collection on host object proxies.
1315 ///
1316 /// Host object proxies additionally have the following methods which run
1317 /// locally.
1318 ///
1319 /// Method name | Details
1320 /// ---|---
1321 ///`applyHostFunction`, `getHostProperty`, `setHostProperty` | Perform a method invocation, property get, or property set on the host object. Use the methods to explicitly force a method or property to run remotely if a conflicting local method or property exists. For instance, `proxy.toString()` runs the local `toString` method on the proxy object. But proxy.applyHostFunction('toString') runs `toString` on the host proxied object instead.
1322 ///`getLocalProperty`, `setLocalProperty` | Perform property get, or property set locally. Use the methods to force getting or setting a property on the host object proxy rather than on the host object it represents. For instance, `proxy.unknownProperty` gets the property named `unknownProperty` from the host proxied object. But proxy.getLocalProperty('unknownProperty') gets the value of the property `unknownProperty` on the proxy object.
1323 ///`sync` | Asynchronous host object proxies expose a sync method which returns a promise for a synchronous host object proxy for the same host object. For example, `chrome.webview.hostObjects.sample.methodCall()` returns an asynchronous host object proxy. Use the `sync` method to obtain a synchronous host object proxy instead: `const syncProxy = await chrome.webview.hostObjects.sample.methodCall().sync()`.
1324 ///`async` | Synchronous host object proxies expose an async method which blocks and returns an asynchronous host object proxy for the same host object. For example, `chrome.webview.hostObjects.sync.sample.methodCall()` returns a synchronous host object proxy. Running the `async` method on this blocks and then returns an asynchronous host object proxy for the same host object: `const asyncProxy = chrome.webview.hostObjects.sync.sample.methodCall().async()`.
1325 ///`then` | Asynchronous host object proxies have a `then` method. Allows proxies to be awaitable. `then` returns a promise that resolves with a representation of the host object. If the proxy represents a JavaScript literal, a copy of that is returned locally. If the proxy represents a function, a non-awaitable proxy is returned. If the proxy represents a JavaScript object with a mix of literal properties and function properties, the a copy of the object is returned with some properties as host object proxies.
1326 ///
1327 /// All other property and method invocations (other than the above Remote
1328 /// object proxy methods, `forceLocalProperties` list, and properties on
1329 /// Function and Object prototypes) are run remotely. Asynchronous host
1330 /// object proxies return a promise representing asynchronous completion of
1331 /// remotely invoking the method, or getting the property. The promise
1332 /// resolves after the remote operations complete and the promises resolve to
1333 /// the resulting value of the operation. Synchronous host object proxies
1334 /// work similarly, but block running JavaScript and wait for the remote
1335 /// operation to complete.
1336 ///
1337 /// Setting a property on an asynchronous host object proxy works slightly
1338 /// differently. The set returns immediately and the return value is the
1339 /// value that is set. This is a requirement of the JavaScript Proxy object.
1340 /// If you need to asynchronously wait for the property set to complete, use
1341 /// the `setHostProperty` method which returns a promise as described above.
1342 /// Synchronous object property set property synchronously blocks until the
1343 /// property is set.
1344 ///
1345 /// For example, suppose you have a COM object with the following interface.
1346 ///
1347 /// \snippet HostObjectSample.idl AddHostObjectInterface
1348 ///
1349 /// Add an instance of this interface into your JavaScript with
1350 /// `AddHostObjectToScript`. In this case, name it `sample`.
1351 ///
1352 /// \snippet ScenarioAddHostObject.cpp AddHostObjectToScript
1353 ///
1354 /// In the HTML document, use the COM object using
1355 /// `chrome.webview.hostObjects.sample`.
1356 ///
1357 /// \snippet assets\ScenarioAddHostObject.html HostObjectUsage
1358 ///
1359 /// Exposing host objects to script has security risk. For more information
1360 /// about best practices, navigate to
1361 /// \[Best practices for developing secure WebView2 applications\]\[MicrosoftEdgeWebview2ConceptsSecurity\].
1362 ///
1363 /// \[MicrosoftEdgeWebview2ConceptsSecurity\]: /microsoft-edge/webview2/concepts/security "Best practices for developing secure WebView2 applications | Microsoft Docs"
1364 unsafe fn add_host_object_to_script(
1365 &self,
1366 /* in */ name: LPCWSTR,
1367 /* in */ object: *mut VARIANT,
1368 ) -> HRESULT;
1369
1370 /// Remove the host object specified by the name so that it is no longer
1371 /// accessible from JavaScript code in the WebView. While new access
1372 /// attempts are denied, if the object is already obtained by JavaScript code
1373 /// in the WebView, the JavaScript code continues to have access to that
1374 /// object. Run this method for a name that is already removed or never
1375 /// added fails.
1376 unsafe fn remove_host_object_from_script(&self, /* in */ name: LPCWSTR) -> HRESULT;
1377
1378 /// Opens the DevTools window for the current document in the WebView. Does
1379 /// nothing if run when the DevTools window is already open.
1380 unsafe fn open_dev_tools_window(&self) -> HRESULT;
1381
1382 /// Add an event handler for the `ContainsFullScreenElementChanged` event.
1383 /// `ContainsFullScreenElementChanged` triggers when the
1384 /// `ContainsFullScreenElement` property changes. An HTML element inside the
1385 /// WebView may enter fullscreen to the size of the WebView or leave
1386 /// fullscreen. This event is useful when, for example, a video element
1387 /// requests to go fullscreen. The listener of
1388 /// `ContainsFullScreenElementChanged` may resize the WebView in response.
1389 ///
1390 /// \snippet AppWindow.cpp ContainsFullScreenElementChanged
1391 unsafe fn add_contains_full_screen_element_changed(
1392 &self,
1393 /* in */
1394 event_handler: *mut *mut ICoreWebView2ContainsFullScreenElementChangedEventHandlerVTable,
1395 /* out */ token: *mut EventRegistrationToken,
1396 ) -> HRESULT;
1397
1398 /// Remove an event handler previously added with
1399 /// `add_ContainsFullScreenElementChanged`.
1400 unsafe fn remove_contains_full_screen_element_changed(
1401 &self,
1402 /* in */ token: EventRegistrationToken,
1403 ) -> HRESULT;
1404
1405 /// Indicates if the WebView contains a fullscreen HTML element.
1406 unsafe fn get_contains_full_screen_element(
1407 &self,
1408 /* out, retval */ contains_full_screen_element: *mut BOOL,
1409 ) -> HRESULT;
1410
1411 /// Add an event handler for the `WebResourceRequested` event.
1412 /// `WebResourceRequested` runs when the WebView is performing a URL request
1413 /// to a matching URL and resource context filter that was added with
1414 /// `AddWebResourceRequestedFilter`. At least one filter must be added for
1415 /// the event to run.
1416 ///
1417 /// The web resource requested may be blocked until the event handler returns
1418 /// if a deferral is not taken on the event args. If a deferral is taken,
1419 /// then the web resource requested is blocked until the deferral is
1420 /// completed.
1421 ///
1422 /// If the method is run in add_NewWindowRequested handler it should be called
1423 /// after the new window is set. For more details see `ICoreWebView2NewWindowRequestedEventArgs::put_NewWindow`.
1424 ///
1425 /// Currently this only supports file, http, and https URI schemes.
1426 ///
1427 /// \snippet SettingsComponent.cpp WebResourceRequested0
1428 /// \snippet SettingsComponent.cpp WebResourceRequested1
1429 unsafe fn add_web_resource_requested(
1430 &self,
1431 /* in */
1432 event_handler: *mut *mut ICoreWebView2WebResourceRequestedEventHandlerVTable,
1433 /* out */ token: *mut EventRegistrationToken,
1434 ) -> HRESULT;
1435
1436 /// Remove an event handler previously added with `add_WebResourceRequested`.
1437 unsafe fn remove_web_resource_requested(
1438 &self,
1439 /* in */ token: EventRegistrationToken,
1440 ) -> HRESULT;
1441
1442 /// Adds a URI and resource context filter for the `WebResourceRequested`
1443 /// event. A web resource request with a resource context that matches this
1444 /// filter's resource context and a URI that matches this filter's URI
1445 /// wildcard string will be raised via the `WebResourceRequested` event.
1446 ///
1447 /// The `uri` parameter value is a wildcard string matched against the URI
1448 /// of the web resource request. This is a glob style
1449 /// wildcard string in which a `*` matches zero or more characters and a `?`
1450 /// matches exactly one character.
1451 /// These wildcard characters can be escaped using a backslash just before
1452 /// the wildcard character in order to represent the literal `*` or `?`.
1453 ///
1454 /// The matching occurs over the URI as a whole string and not limiting
1455 /// wildcard matches to particular parts of the URI.
1456 /// The wildcard filter is compared to the URI after the URI has been
1457 /// normalized, any URI fragment has been removed, and non-ASCII hostnames
1458 /// have been converted to punycode.
1459 ///
1460 /// Specifying a `nullptr` for the uri is equivalent to an empty string which
1461 /// matches no URIs.
1462 ///
1463 /// For more information about resource context filters, navigate to
1464 /// [COREWEBVIEW2_WEB_RESOURCE_CONTEXT].
1465 ///
1466 /// | URI Filter String | Request URI | Match | Notes |
1467 /// | ---- | ---- | ---- | ---- |
1468 /// | `*` | https://contoso.com/a/b/c | Yes | A single * will match all URIs |
1469 /// | `*://contoso.com/*` | https://contoso.com/a/b/c | Yes | Matches everything in contoso.com across all schemes |
1470 /// | `*://contoso.com/*` | https://example.com/?https://contoso.com/ | Yes | But also matches a URI with just the same text anywhere in the URI |
1471 /// | `example` | https://contoso.com/example | No | The filter does not perform partial matches |
1472 /// | `*example` | https://contoso.com/example | Yes | The filter matches across URI parts |
1473 /// | `*example` | https://contoso.com/path/?example | Yes | The fitler matches across URI parts |
1474 /// | `*example` | https://contoso.com/path/?query#example | No | The filter is matched against the URI with no fragment |
1475 /// | `*example` | https://example | No | The URI is normalzied before filter matching so the actual URI used for comparison is https://example.com/ |
1476 /// | `*example/` | https://example | Yes | Just like above, but this time the filter ends with a / just like the normalized URI |
1477 /// | https://xn--qei.example/ | https://❤.example/ | Yes | Non-ASCII hostnames are normalized to punycode before wildcard comparison |
1478 /// | https://❤.example/ | https://xn--qei.example/ | No | Non-ASCII hostnames are normalized to punycode before wildcard comparison |
1479 unsafe fn add_web_resource_requested_filter(
1480 &self,
1481 /* in */ uri: LPCWSTR,
1482 /* in */ resource_context: WebResourceContext,
1483 ) -> HRESULT;
1484
1485 /// Removes a matching WebResource filter that was previously added for the
1486 /// `WebResourceRequested` event. If the same filter was added multiple
1487 /// times, then it must be removed as many times as it was added for the
1488 /// removal to be effective. Returns `E_INVALIDARG` for a filter that was
1489 /// never added.
1490 unsafe fn remove_web_resource_requested_filter(
1491 &self,
1492 /* in */ uri: LPCWSTR,
1493 /* in */ resource_context: WebResourceContext,
1494 ) -> HRESULT;
1495
1496 /// Add an event handler for the `WindowCloseRequested` event.
1497 /// `WindowCloseRequested` triggers when content inside the WebView
1498 /// requested to close the window, such as after `window.close` is run. The
1499 /// app should close the WebView and related app window if that makes sense
1500 /// to the app.
1501 ///
1502 /// \snippet AppWindow.cpp WindowCloseRequested
1503 unsafe fn add_window_close_requested(
1504 &self,
1505 /* in */
1506 event_handler: *mut *mut ICoreWebView2WindowCloseRequestedEventHandlerVTable,
1507 /* out */ token: *mut EventRegistrationToken,
1508 ) -> HRESULT;
1509
1510 /// Remove an event handler previously added with `add_WindowCloseRequested`.
1511 unsafe fn remove_window_close_requested(
1512 &self,
1513 /* in */ token: EventRegistrationToken,
1514 ) -> HRESULT;
1515}
1516
1517/// A continuation of the ICoreWebView2 interface.
1518#[com_interface("9E8F0CF8-E670-4B5E-B2BC-73E061E3184C")]
1519pub trait ICoreWebView2_2: ICoreWebView2 {
1520 /// Add an event handler for the WebResourceResponseReceived event.
1521 /// WebResourceResponseReceived is raised when the WebView receives the
1522 /// response for a request for a web resource (any URI resolution performed by
1523 /// the WebView; such as HTTP/HTTPS, file and data requests from redirects,
1524 /// navigations, declarations in HTML, implicit favicon lookups, and fetch API
1525 /// usage in the document). The host app can use this event to view the actual
1526 /// request and response for a web resource. There is no guarantee about the
1527 /// order in which the WebView processes the response and the host app's
1528 /// handler runs. The app's handler will not block the WebView from processing
1529 /// the response.
1530 /// \snippet ScenarioAuthentication.cpp WebResourceResponseReceived
1531 unsafe fn add_web_resource_response_received(
1532 &self,
1533 /* in */
1534 event_handler: *mut *mut ICoreWebView2WebResourceResponseReceivedEventHandlerVTable,
1535 /* out */ token: *mut EventRegistrationToken,
1536 ) -> HRESULT;
1537
1538 /// Remove an event handler previously added with
1539 /// add_WebResourceResponseReceived.
1540 unsafe fn remove_web_resource_response_received(
1541 &self,
1542 /* in */ token: EventRegistrationToken,
1543 ) -> HRESULT;
1544
1545 /// Navigates using a constructed WebResourceRequest object. This lets you
1546 /// provide post data or additional request headers during navigation.
1547 /// The headers in the WebResourceRequest override headers
1548 /// added by WebView2 runtime except for Cookie headers.
1549 /// Method can only be either "GET" or "POST". Provided post data will only
1550 /// be sent only if the method is "POST" and the uri scheme is HTTP(S).
1551 /// \snippet ScenarioNavigateWithWebResourceRequest.cpp NavigateWithWebResourceRequest
1552 unsafe fn navigate_with_web_resource_request(
1553 &self,
1554 /* in */ request: *mut *mut ICoreWebView2WebResourceRequestVTable,
1555 ) -> HRESULT;
1556
1557 /// Add an event handler for the DOMContentLoaded event.
1558 /// DOMContentLoaded is raised when the initial html document has been parsed.
1559 /// This aligns with the the document's DOMContentLoaded event in html.
1560 ///
1561 /// \snippet ScenarioDOMContentLoaded.cpp DOMContentLoaded
1562 unsafe fn add_domcontent_loaded(
1563 &self,
1564 /* in */ event_handler: *mut *mut ICoreWebView2DOMContentLoadedEventHandlerVTable,
1565 /* out */ token: *mut EventRegistrationToken,
1566 ) -> HRESULT;
1567
1568 /// Remove an event handler previously added with add_DOMContentLoaded.
1569 unsafe fn remove_domcontent_loaded(
1570 &self,
1571 /* in */ token: EventRegistrationToken,
1572 ) -> HRESULT;
1573
1574 /// Gets the cookie manager object associated with this ICoreWebView2.
1575 /// See ICoreWebView2CookieManager.
1576 ///
1577 /// \snippet ScenarioCookieManagement.cpp CookieManager
1578 unsafe fn get_cookie_manager(
1579 &self,
1580 /* out, retval */ cookie_manager: *mut *mut *mut ICoreWebView2CookieManagerVTable,
1581 ) -> HRESULT;
1582
1583 /// Exposes the CoreWebView2Environment used to create this CoreWebView2.
1584 unsafe fn get_environment(
1585 &self,
1586 /* out, retval */ environment: *mut *mut *mut ICoreWebView2EnvironmentVTable,
1587 ) -> HRESULT;
1588}
1589
1590/// A continuation of the ICoreWebView2_2 interface.
1591#[com_interface("A0D6DF20-3B92-416D-AA0C-437A9C727857")]
1592pub trait ICoreWebView2_3: ICoreWebView2_2 {
1593 /// An app may call the `TrySuspend` API to have the WebView2 consume less memory.
1594 /// This is useful when a Win32 app becomes invisible, or when a Universal Windows
1595 /// Platform app is being suspended, during the suspended event handler before completing
1596 /// the suspended event.
1597 /// The CoreWebView2Controller's IsVisible property must be false when the API is called.
1598 /// Otherwise, the API fails with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
1599 /// Suspending is similar to putting a tab to sleep in the Edge browser. Suspending pauses
1600 /// WebView script timers and animations, minimizes CPU usage for the associated
1601 /// browser renderer process and allows the operating system to reuse the memory that was
1602 /// used by the renderer process for other processes.
1603 /// Note that Suspend is best effort and considered completed successfully once the request
1604 /// is sent to browser renderer process. If there is a running script, the script will continue
1605 /// to run and the renderer process will be suspended after that script is done.
1606 /// See [Sleeping Tabs FAQ](https://techcommunity.microsoft.com/t5/articles/sleeping-tabs-faq/m-p/1705434)
1607 /// for conditions that might prevent WebView from being suspended. In those situations,
1608 /// the completed handler will be invoked with isSuccessful as false and errorCode as S_OK.
1609 /// The WebView will be automatically resumed when it becomes visible. Therefore, the
1610 /// app normally does not have to call `Resume` explicitly.
1611 /// The app can call `Resume` and then `TrySuspend` periodically for an invisible WebView so that
1612 /// the invisible WebView can sync up with latest data and the page ready to show fresh content
1613 /// when it becomes visible.
1614 /// All WebView APIs can still be accessed when a WebView is suspended. Some APIs like Navigate
1615 /// will auto resume the WebView. To avoid unexpected auto resume, check `IsSuspended` property
1616 /// before calling APIs that might change WebView state.
1617 ///
1618 /// \snippet ViewComponent.cpp ToggleIsVisibleOnMinimize
1619 ///
1620 /// \snippet ViewComponent.cpp Suspend
1621 ///
1622 unsafe fn try_suspend(
1623 &self,
1624 /* in */ handler: *mut *mut ICoreWebView2TrySuspendCompletedHandlerVTable,
1625 ) -> HRESULT;
1626
1627 /// Resumes the WebView so that it resumes activities on the web page.
1628 /// This API can be called while the WebView2 controller is invisible.
1629 /// The app can interact with the WebView immediately after `Resume`.
1630 /// WebView will be automatically resumed when it becomes visible.
1631 ///
1632 /// \snippet ViewComponent.cpp ToggleIsVisibleOnMinimize
1633 ///
1634 /// \snippet ViewComponent.cpp Resume
1635 ///
1636 unsafe fn resume(&self) -> HRESULT;
1637
1638 /// Whether WebView is suspended.
1639 /// `TRUE` when WebView is suspended, from the time when TrySuspend has completed
1640 /// successfully until WebView is resumed.
1641 unsafe fn get_is_suspended(&self, /* out, retval */ is_suspended: *mut BOOL) -> HRESULT;
1642
1643 /// Sets a mapping between a virtual host name and a folder path to make available to web sites
1644 /// via that host name.
1645 ///
1646 /// After setting the mapping, documents loaded in the WebView can use HTTP or HTTPS URLs at
1647 /// the specified host name specified by hostName to access files in the local folder specified
1648 /// by folderPath.
1649 ///
1650 /// This mapping applies to both top-level document and iframe navigations as well as subresource
1651 /// references from a document. This also applies to web workers including dedicated/shared worker
1652 /// and service worker, for loading either worker scripts or subresources
1653 /// (importScripts(), fetch(), XHR, etc.) issued from within a worker.
1654 /// For virtual host mapping to work with service worker, please keep the virtual host name
1655 /// mappings consistent among all WebViews sharing the same browser instance. As service worker
1656 /// works independently of WebViews, we merge mappings from all WebViews when resolving virutal
1657 /// host name, inconsistent mappings between WebViews would lead unexpected bevavior.
1658 ///
1659 /// Due to a current implementation limitation, media files accessed using virtual host name can be
1660 /// very slow to load.
1661 /// As the resource loaders for the current page might have already been created and running,
1662 /// changes to the mapping might not be applied to the current page and a reload of the page is
1663 /// needed to apply the new mapping.
1664 ///
1665 /// Both absolute and relative paths are supported for folderPath. Relative paths are interpreted
1666 /// as relative to the folder where the exe of the app is in.
1667 ///
1668 /// accessKind specifies the level of access to resources under the virtual host from other sites.
1669 ///
1670 /// For example, after calling
1671 /// ```cpp
1672 /// SetVirtualHostNameToFolderMapping(
1673 /// L"appassets.example", L"assets",
1674 /// COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY);
1675 /// ```
1676 /// navigating to `https://appassets.example/my-local-file.html` will
1677 /// show content from my-local-file.html in the assets subfolder located on disk under the same
1678 /// path as the app's executable file.
1679 ///
1680 /// You should typically choose virtual host names that are never used by real sites.
1681 /// If you own a domain such as example.com, another option is to use a subdomain reserved for
1682 /// the app (like my-app.example.com).
1683 ///
1684 /// [RFC 6761](https://tools.ietf.org/html/rfc6761) has reserved several special-use domain
1685 /// names that are guaranteed to not be used by real sites (for example, .example, .test, and
1686 /// .invalid.)
1687 ///
1688 /// Apps should use distinct domain names when mapping folder from different sources that
1689 /// should be isolated from each other. For instance, the app might use app-file.example for
1690 /// files that ship as part of the app, and book1.example might be used for files containing
1691 /// books from a less trusted source that were previously downloaded and saved to the disk by
1692 /// the app.
1693 ///
1694 /// The host name used in the APIs is canonicalized using Chromium's host name parsing logic
1695 /// before being used internally.
1696 ///
1697 /// All host names that are canonicalized to the same string are considered identical.
1698 /// For example, `EXAMPLE.COM` and `example.com` are treated as the same host name.
1699 /// An international host name and its Punycode-encoded host name are considered the same host
1700 /// name. There is no DNS resolution for host name and the trailing '.' is not normalized as
1701 /// part of canonicalization.
1702 ///
1703 /// Therefore `example.com` and `example.com.` are treated as different host names. Similarly,
1704 /// `virtual-host-name` and `virtual-host-name.example.com` are treated as different host names
1705 /// even if the machine has a DNS suffix of `example.com`.
1706 ///
1707 /// Specify the minimal cross-origin access necessary to run the app. If there is not a need to
1708 /// access local resources from other origins, use COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY.
1709 ///
1710 /// \snippet AppWindow.cpp AddVirtualHostNameToFolderMapping
1711 ///
1712 /// \snippet AppWindow.cpp LocalUrlUsage
1713 unsafe fn set_virtual_host_name_to_folder_mapping(
1714 &self,
1715 /* in */ host_name: LPCWSTR,
1716 /* in */ folder_path: LPCWSTR,
1717 /* in */ access_kind: HostResourceAccessKind,
1718 ) -> HRESULT;
1719
1720 /// Clears a host name mapping for local folder that was added by `SetVirtualHostNameToFolderMapping`.
1721 unsafe fn clear_virtual_host_name_to_folder_mapping(
1722 &self,
1723 /* in */ host_name: LPCWSTR,
1724 ) -> HRESULT;
1725}
1726
1727/// A continuation of the ICoreWebView2_3 interface to support FrameCreated and
1728/// DownloadStarting events.
1729#[com_interface("20d02d59-6df2-42dc-bd06-f98a694b1302")]
1730pub trait ICoreWebView2_4: ICoreWebView2_3 {
1731 /// Raised when a new iframe is created. Use the
1732 /// CoreWebView2Frame.add_Destroyed to listen for when this iframe goes
1733 /// away.
1734 unsafe fn add_frame_created(
1735 &self,
1736 /* in */ event_handler: *mut *mut ICoreWebView2FrameCreatedEventHandlerVTable,
1737 /* out */ token: *mut EventRegistrationToken,
1738 ) -> HRESULT;
1739
1740 /// Remove an event handler previously added with add_FrameCreated.
1741 unsafe fn remove_frame_created(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
1742
1743 /// Add an event handler for the `DownloadStarting` event. This event is
1744 /// raised when a download has begun, blocking the default download dialog,
1745 /// but not blocking the progress of the download.
1746 ///
1747 /// The host can choose to cancel a download, change the result file path,
1748 /// and hide the default download dialog.
1749 /// If the host chooses to cancel the download, the download is not saved, no
1750 /// dialog is shown, and the state is changed to
1751 /// COREWEBVIEW2_DOWNLOAD_STATE_INTERRUPTED with interrupt reason
1752 /// COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_USER_CANCELED. Otherwise, the
1753 /// download is saved to the default path after the event completes,
1754 /// and default download dialog is shown if the host did not choose to hide it.
1755 /// The host can change the visibility of the download dialog using the
1756 /// `Handled` property. If the event is not handled, downloads complete
1757 /// normally with the default dialog shown.
1758 ///
1759 /// \snippet ScenarioCustomDownloadExperience.cpp DownloadStarting
1760 unsafe fn add_download_starting(
1761 &self,
1762 /* in */ event_handler: *mut *mut ICoreWebView2DownloadStartingEventHandlerVTable,
1763 /* out */ token: *mut EventRegistrationToken,
1764 ) -> HRESULT;
1765
1766 /// Remove an event handler previously added with `add_DownloadStarting`.
1767 unsafe fn remove_download_starting(
1768 &self,
1769 /* in */ token: EventRegistrationToken,
1770 ) -> HRESULT;
1771}
1772
1773/// A continuation of the ICoreWebView2_4 interface to support ClientCertificateRequested
1774/// event.
1775#[com_interface("bedb11b8-d63c-11eb-b8bc-0242ac130003")]
1776pub trait ICoreWebView2_5: ICoreWebView2_4 {
1777 /// Add an event handler for the ClientCertificateRequested event.
1778 /// The ClientCertificateRequested event is raised when the WebView2
1779 /// is making a request to an HTTP server that needs a client certificate
1780 /// for HTTP authentication.
1781 /// Read more about HTTP client certificates at
1782 /// [RFC 8446 The Transport Layer Security (TLS) Protocol Version 1.3](https://tools.ietf.org/html/rfc8446).
1783 ///
1784 /// With this event you have several options for responding to client certificate requests:
1785 ///
1786 /// Scenario | Handled | Cancel | SelectedCertificate
1787 /// ---------------------------------------------------------- | ------- | ------ | -------------------
1788 /// Respond to server with a certificate | True | False | MutuallyTrustedCertificate value
1789 /// Respond to server without certificate | True | False | null
1790 /// Display default client certificate selection dialog prompt | False | False | n/a
1791 /// Cancel the request | n/a | True | n/a
1792 ///
1793 /// If you don't handle the event, WebView2 will
1794 /// show the default client certificate selection dialog prompt to user.
1795 ///
1796 /// \snippet SettingsComponent.cpp ClientCertificateRequested1
1797 /// \snippet ScenarioClientCertificateRequested.cpp ClientCertificateRequested2
1798 unsafe fn add_client_certificate_requested(
1799 &self,
1800 /* in */
1801 event_handler: *mut *mut ICoreWebView2ClientCertificateRequestedEventHandlerVTable,
1802 /* out */ token: *mut EventRegistrationToken,
1803 ) -> HRESULT;
1804
1805 /// Remove an event handler previously added with add_ClientCertificateRequested.
1806 unsafe fn remove_client_certificate_requested(
1807 &self,
1808 /* in */ token: EventRegistrationToken,
1809 ) -> HRESULT;
1810}
1811
1812/// The caller implements this interface to receive the TrySuspend result.
1813#[com_interface("00F206A7-9D17-4605-91F6-4E8E4DE192E3")]
1814pub trait ICoreWebView2TrySuspendCompletedHandler: IUnknown {
1815 /// Provides the result of the TrySuspend operation.
1816 /// See [Sleeping Tabs FAQ](https://techcommunity.microsoft.com/t5/articles/sleeping-tabs-faq/m-p/1705434)
1817 /// for conditions that might prevent WebView from being suspended. In those situations,
1818 /// isSuccessful will be false and errorCode is S_OK.
1819 unsafe fn invoke(
1820 &self,
1821 /* in */ error_code: HRESULT,
1822 /* in */ is_successful: BOOL,
1823 ) -> HRESULT;
1824}
1825
1826/// The owner of the `CoreWebView2` object that provides support for resizing,
1827/// showing and hiding, focusing, and other functionality related to
1828/// windowing and composition. The `CoreWebView2Controller` owns the
1829/// `CoreWebView2`, and if all references to the `CoreWebView2Controller` go
1830/// away, the WebView is closed.
1831#[com_interface("4d00c0d1-9434-4eb6-8078-8697a560334f")]
1832pub trait ICoreWebView2Controller: IUnknown {
1833 /// The `IsVisible` property determines whether to show or hide the WebView2.
1834 /// If `IsVisible` is set to `FALSE`, the WebView2 is transparent and is
1835 /// not rendered. However, this does not affect the window containing the
1836 /// WebView2 (the `HWND` parameter that was passed to
1837 /// `CreateCoreWebView2Controller`). If you want that window to disappear
1838 /// too, run `ShowWindow` on it directly in addition to modifying the
1839 /// `IsVisible` property. WebView2 as a child window does not get window
1840 /// messages when the top window is minimized or restored. For performance
1841 /// reason, developer should set `IsVisible` property of the WebView to
1842 /// `FALSE` when the app window is minimized and back to `TRUE` when app
1843 /// window is restored. App window does this by handling
1844 /// `SC_MINIMIZE and SC_RESTORE` command upon receiving `WM_SYSCOMMAND`
1845 /// message.
1846 ///
1847 /// \snippet ViewComponent.cpp ToggleIsVisible
1848 unsafe fn get_is_visible(&self, /* out, retval */ is_visible: *mut BOOL) -> HRESULT;
1849
1850 /// Sets the `IsVisible` property.
1851 ///
1852 /// \snippet ViewComponent.cpp ToggleIsVisibleOnMinimize
1853 unsafe fn put_is_visible(&self, /* in */ is_visible: BOOL) -> HRESULT;
1854
1855 /// The WebView bounds. Bounds are relative to the parent `HWND`. The app
1856 /// has two ways to position a WebView.
1857 ///
1858 /// * Create a child `HWND` that is the WebView parent `HWND`. Position
1859 /// the window where the WebView should be. Use `(0, 0)` for the
1860 /// top-left corner (the offset) of the `Bounds` of the WebView.
1861 /// * Use the top-most window of the app as the WebView parent HWND. For
1862 /// example, to position WebView correctly in the app, set the top-left
1863 /// corner of the Bound of the WebView.
1864 ///
1865 /// The values of `Bounds` are limited by the coordinate space of the host.
1866 unsafe fn get_bounds(&self, /* out, retval */ bounds: *mut RECT) -> HRESULT;
1867
1868 /// Sets the `Bounds` property.
1869 ///
1870 /// \snippet ViewComponent.cpp ResizeWebView
1871 unsafe fn put_bounds(&self, /* in */ bounds: RECT) -> HRESULT;
1872
1873 /// The zoom factor for the WebView.
1874 ///
1875 /// \> [!NOTE]\n\> Changing zoom factor may cause `window.innerWidth`,
1876 /// `window.innerHeight`, both, and page layout to change. A zoom factor
1877 /// that is applied by the host by running `ZoomFactor` becomes the new
1878 /// default zoom for the WebView. The zoom factor applies across navigations
1879 /// and is the zoom factor WebView is returned to when the user chooses
1880 /// Ctrl+0. When the zoom factor is changed by the user (resulting in
1881 /// the app receiving `ZoomFactorChanged`), that zoom applies only for the
1882 /// current page. Any user applied zoom is only for the current page and is
1883 /// reset on a navigation. Specifying a `zoomFactor` less than or equal to
1884 /// `0` is not allowed. WebView also has an internal supported zoom factor
1885 /// range. When a specified zoom factor is out of that range, it is
1886 /// normalized to be within the range, and a `ZoomFactorChanged` event is
1887 /// triggered for the real applied zoom factor. When the range normalization
1888 /// happens, the `ZoomFactor` property reports the zoom factor specified
1889 /// during the previous modification of the `ZoomFactor` property until the
1890 /// `ZoomFactorChanged` event is received after WebView applies the
1891 /// normalized zoom factor.
1892 unsafe fn get_zoom_factor(&self, /* out, retval */ zoom_factor: *mut f64) -> HRESULT;
1893
1894 /// Sets the `ZoomFactor` property.
1895 unsafe fn put_zoom_factor(&self, /* in */ zoom_factor: f64) -> HRESULT;
1896
1897 /// Adds an event handler for the `ZoomFactorChanged` event.
1898 /// `ZoomFactorChanged` runs when the `ZoomFactor` property of the WebView
1899 /// changes. The event may run because the `ZoomFactor` property was
1900 /// modified, or due to the user manually modifying the zoom. When it is
1901 /// modified using the `ZoomFactor` property, the internal zoom factor is
1902 /// updated immediately and no `ZoomFactorChanged` event is triggered.
1903 /// WebView associates the last used zoom factor for each site. It is
1904 /// possible for the zoom factor to change when navigating to a different
1905 /// page. When the zoom factor changes due to a navigation change, the
1906 /// `ZoomFactorChanged` event runs right after the `ContentLoading` event.
1907 ///
1908 /// \snippet ViewComponent.cpp ZoomFactorChanged
1909 unsafe fn add_zoom_factor_changed(
1910 &self,
1911 /* in */ event_handler: *mut *mut ICoreWebView2ZoomFactorChangedEventHandlerVTable,
1912 /* out */ token: *mut EventRegistrationToken,
1913 ) -> HRESULT;
1914
1915 /// Remove an event handler previously added with `add_ZoomFactorChanged`.
1916 unsafe fn remove_zoom_factor_changed(
1917 &self,
1918 /* in */ token: EventRegistrationToken,
1919 ) -> HRESULT;
1920
1921 /// Updates `Bounds` and `ZoomFactor` properties at the same time. This
1922 /// operation is atomic from the perspective of the host. After returning
1923 /// from this function, the `Bounds` and `ZoomFactor` properties are both
1924 /// updated if the function is successful, or neither is updated if the
1925 /// function fails. If `Bounds` and `ZoomFactor` are both updated by the
1926 /// same scale (for example, `Bounds` and `ZoomFactor` are both doubled),
1927 /// then the page does not display a change in `window.innerWidth` or
1928 /// `window.innerHeight` and the WebView renders the content at the new size
1929 /// and zoom without intermediate renderings. This function also updates
1930 /// just one of `ZoomFactor` or `Bounds` by passing in the new value for one
1931 /// and the current value for the other.
1932 ///
1933 /// \snippet ViewComponent.cpp SetBoundsAndZoomFactor
1934 unsafe fn set_bounds_and_zoom_factor(
1935 &self,
1936 /* in */ bounds: RECT,
1937 /* in */ zoom_factor: f64,
1938 ) -> HRESULT;
1939
1940 /// Moves focus into WebView. WebView gets focus and focus is set to
1941 /// correspondent element in the page hosted in the WebView. For
1942 /// Programmatic reason, focus is set to previously focused element or the
1943 /// default element if no previously focused element exists. For `Next`
1944 /// reason, focus is set to the first element. For `Previous` reason, focus
1945 /// is set to the last element. WebView changes focus through user
1946 /// interaction including selecting into a WebView or Tab into it. For
1947 /// tabbing, the app runs MoveFocus with Next or Previous to align with Tab
1948 /// and Shift+Tab respectively when it decides the WebView is the next
1949 /// element that may exist in a tab. Or, the app runs `IsDialogMessage`
1950 /// as part of the associated message loop to allow the platform to auto
1951 /// handle tabbing. The platform rotates through all windows with
1952 /// `WS_TABSTOP`. When the WebView gets focus from `IsDialogMessage`, it is
1953 /// internally put the focus on the first or last element for tab and
1954 /// Shift+Tab respectively.
1955 ///
1956 /// \snippet App.cpp MoveFocus0
1957 ///
1958 /// \snippet ControlComponent.cpp MoveFocus1
1959 ///
1960 /// \snippet ControlComponent.cpp MoveFocus2
1961 unsafe fn move_focus(&self, /* in */ reason: MoveFocusReason) -> HRESULT;
1962
1963 /// Adds an event handler for the `MoveFocusRequested` event.
1964 /// `MoveFocusRequested` runs when user tries to tab out of the WebView. The
1965 /// focus of the WebView has not changed when this event is run.
1966 ///
1967 /// \snippet ControlComponent.cpp MoveFocusRequested
1968 unsafe fn add_move_focus_requested(
1969 &self,
1970 /* in */ event_handler: *mut *mut ICoreWebView2MoveFocusRequestedEventHandlerVTable,
1971 /* out */ token: *mut EventRegistrationToken,
1972 ) -> HRESULT;
1973
1974 /// Removes an event handler previously added with `add_MoveFocusRequested`.
1975 unsafe fn remove_move_focus_requested(
1976 &self,
1977 /* in */ token: EventRegistrationToken,
1978 ) -> HRESULT;
1979
1980 /// Adds an event handler for the `GotFocus` event. `GotFocus` runs when
1981 /// WebView has focus.
1982 unsafe fn add_got_focus(
1983 &self,
1984 /* in */ event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
1985 /* out */ token: *mut EventRegistrationToken,
1986 ) -> HRESULT;
1987
1988 /// Removes an event handler previously added with `add_GotFocus`.
1989 unsafe fn remove_got_focus(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
1990
1991 /// Adds an event handler for the `LostFocus` event. `LostFocus` runs when
1992 /// WebView loses focus. In the case where `MoveFocusRequested` event is
1993 /// run, the focus is still on WebView when `MoveFocusRequested` event runs.
1994 /// `LostFocus` only runs afterwards when code of the app or default action
1995 /// of `MoveFocusRequested` event set focus away from WebView.
1996 unsafe fn add_lost_focus(
1997 &self,
1998 /* in */ event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
1999 /* out */ token: *mut EventRegistrationToken,
2000 ) -> HRESULT;
2001
2002 /// Removes an event handler previously added with `add_LostFocus`.
2003 unsafe fn remove_lost_focus(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
2004
2005 /// Adds an event handler for the `AcceleratorKeyPressed` event.
2006 /// `AcceleratorKeyPressed` runs when an accelerator key or key combo is
2007 /// pressed or released while the WebView is focused. A key is considered an
2008 /// accelerator if either of the following conditions are true.
2009 ///
2010 /// * Ctrl or Alt is currently being held.
2011 /// * The pressed key does not map to a character.
2012 ///
2013 /// A few specific keys are never considered accelerators, such as Shift.
2014 /// The `Escape` key is always considered an accelerator.
2015 ///
2016 /// Auto-repeated key events caused by holding the key down also triggers
2017 /// this event. Filter out the auto-repeated key events by verifying the
2018 /// `KeyEventLParam` or `PhysicalKeyStatus` event args.
2019 ///
2020 /// In windowed mode, the event handler is run synchronously. Until you
2021 /// run `Handled()` on the event args or the event handler returns, the
2022 /// browser process is blocked and outgoing cross-process COM requests fail
2023 /// with `RPC_E_CANTCALLOUT_ININPUTSYNCCALL`. All `CoreWebView2` API methods
2024 /// work, however.
2025 ///
2026 /// In windowless mode, the event handler is run asynchronously. Further
2027 /// input do not reach the browser until the event handler returns or
2028 /// `Handled()` is run, but the browser process is not blocked, and outgoing
2029 /// COM requests work normally.
2030 ///
2031 /// It is recommended to run `Handled(TRUE)` as early as are able to know
2032 /// that you want to handle the accelerator key.
2033 ///
2034 /// \snippet ControlComponent.cpp AcceleratorKeyPressed
2035 unsafe fn add_accelerator_key_pressed(
2036 &self,
2037 /* in */
2038 event_handler: *mut *mut ICoreWebView2AcceleratorKeyPressedEventHandlerVTable,
2039 /* out */ token: *mut EventRegistrationToken,
2040 ) -> HRESULT;
2041
2042 /// Removes an event handler previously added with
2043 /// `add_AcceleratorKeyPressed`.
2044 unsafe fn remove_accelerator_key_pressed(
2045 &self,
2046 /* in */ token: EventRegistrationToken,
2047 ) -> HRESULT;
2048
2049 /// The parent window provided by the app that this WebView is using to
2050 /// render content. This API initially returns the window passed into
2051 /// `CreateCoreWebView2Controller`.
2052 unsafe fn get_parent_window(&self, /* out, retval */ parent_window: *mut HWND) -> HRESULT;
2053
2054 /// Sets the parent window for the WebView. This causes the WebView to
2055 /// re-parent the main WebView window to the newly provided window.
2056 unsafe fn put_parent_window(&self, /* in */ parent_window: HWND) -> HRESULT;
2057
2058 /// This is a notification separate from `Bounds` that tells WebView that the
2059 /// main WebView parent (or any ancestor) `HWND` moved. This is needed
2060 /// for accessibility and certain dialogs in WebView to work correctly.
2061 ///
2062 /// \snippet ViewComponent.cpp NotifyParentWindowPositionChanged
2063 unsafe fn notify_parent_window_position_changed(&self) -> HRESULT;
2064
2065 /// Closes the WebView and cleans up the underlying browser instance.
2066 /// Cleaning up the browser instance releases the resources powering the
2067 /// WebView. The browser instance is shut down if no other WebViews are
2068 /// using it.
2069 ///
2070 /// After running `Close`, most methods will fail and event handlers stop
2071 /// running. Specifically, the WebView releases the associated references to
2072 /// any associated event handlers when `Close` is run.
2073 ///
2074 /// `Close` is implicitly run when the `CoreWebView2Controller` loses the
2075 /// final reference and is destructed. But it is best practice to
2076 /// explicitly run `Close` to avoid any accidental cycle of references
2077 /// between the WebView and the app code. Specifically, if you capture a
2078 /// reference to the WebView in an event handler you create a reference cycle
2079 /// between the WebView and the event handler. Run `Close` to break the
2080 /// cycle by releasing all event handlers. But to avoid the situation, it is
2081 /// best to both explicitly run `Close` on the WebView and to not capture a
2082 /// reference to the WebView to ensure the WebView is cleaned up correctly.
2083 ///
2084 /// \snippet AppWindow.cpp Close
2085 unsafe fn close(&self) -> HRESULT;
2086
2087 /// Gets the `CoreWebView2` associated with this `CoreWebView2Controller`.
2088 unsafe fn get_core_web_view2(
2089 &self,
2090 /* out, retval */ core_web_view2: *mut *mut *mut ICoreWebView2VTable,
2091 ) -> HRESULT;
2092}
2093
2094/// A continuation of the ICoreWebView2Controller interface.
2095#[com_interface("c979903e-d4ca-4228-92eb-47ee3fa96eab")]
2096pub trait ICoreWebView2Controller2: ICoreWebView2Controller {
2097 /// The `DefaultBackgroundColor` property is the color WebView renders
2098 /// underneath all web content. This means WebView renders this color when
2099 /// there is no web content loaded such as before the initial navigation or
2100 /// between navigations. This also means web pages with undefined css
2101 /// background properties or background properties containing transparent
2102 /// pixels will render their contents over this color. Web pages with defined
2103 /// and opaque background properties that span the page will obscure the
2104 /// `DefaultBackgroundColor` and display normally. The default value for this
2105 /// property is white to resemble the native browser experience.
2106 ///
2107 /// The Color is specified by the COREWEBVIEW2_COLOR that represents an RGBA
2108 /// value. The `A` represents an Alpha value, meaning
2109 /// `DefaultBackgroundColor` can be transparent. In the case of a transparent
2110 /// `DefaultBackgroundColor` WebView will render hosting app content as the
2111 /// background. This Alpha value is not supported on Windows 7. Any `A` value
2112 /// other than 255 will result in E_INVALIDARG on Windows 7.
2113 /// It is supported on all other WebView compatible platforms.
2114 ///
2115 /// Semi-transparent colors are not currently supported by this API and
2116 /// setting `DefaultBackgroundColor` to a semi-transparent color will fail
2117 /// with E_INVALIDARG. The only supported alpha values are 0 and 255, all
2118 /// other values will result in E_INVALIDARG.
2119 /// `DefaultBackgroundColor` can only be an opaque color or transparent.
2120 ///
2121 /// \snippet ViewComponent.cpp DefaultBackgroundColor
2122 unsafe fn get_default_background_color(
2123 &self,
2124 /* out, retval */ background_color: *mut Color,
2125 ) -> HRESULT;
2126
2127 /// Sets the `DefaultBackgroundColor` property.
2128 unsafe fn put_default_background_color(&self, /* in */ background_color: Color) -> HRESULT;
2129}
2130
2131/// A continuation of the ICoreWebView2Controller2 interface.
2132#[com_interface("f9614724-5d2b-41dc-aef7-73d62b51543b")]
2133pub trait ICoreWebView2Controller3: ICoreWebView2Controller2 {
2134 /// The rasterization scale for the WebView. The rasterization scale is the
2135 /// combination of the monitor DPI scale and text scaling set by the user.
2136 /// This value should be updated when the DPI scale of the app's top level
2137 /// window changes (i.e. monitor DPI scale changes or window changes monitor)
2138 /// or when the text scale factor of the system changes.
2139 ///
2140 /// \snippet AppWindow.cpp DPIChanged
2141 ///
2142 /// \snippet AppWindow.cpp TextScaleChanged1
2143 ///
2144 /// \snippet AppWindow.cpp TextScaleChanged2
2145 ///
2146 /// Rasterization scale applies to the WebView content, as well as
2147 /// popups, context menus, scroll bars, and so on. Normal app scaling
2148 /// scenarios should use the ZoomFactor property or SetBoundsAndZoomFactor
2149 /// API which only scale the rendered HTML content and not popups, context
2150 /// menus, scroll bars, and so on.
2151 ///
2152 /// \snippet ViewComponent.cpp RasterizationScale
2153 unsafe fn get_rasterization_scale(&self, /* out, retval */ scale: *mut f64) -> HRESULT;
2154
2155 /// Set the rasterization scale property.
2156 unsafe fn put_rasterization_scale(&self, /* in */ scale: f64) -> HRESULT;
2157
2158 /// ShouldDetectMonitorScaleChanges property determines whether the WebView
2159 /// attempts to track monitor DPI scale changes. When true, the WebView will
2160 /// track monitor DPI scale changes, update the RasterizationScale property,
2161 /// and raises RasterizationScaleChanged event. When false, the WebView will
2162 /// not track monitor DPI scale changes, and the app must update the
2163 /// RasterizationScale property itself. RasterizationScaleChanged event will
2164 /// never raise when ShouldDetectMonitorScaleChanges is false.
2165 unsafe fn get_should_detect_monitor_scale_changes(
2166 &self,
2167 /* out, retval */ value: *mut BOOL,
2168 ) -> HRESULT;
2169
2170 /// Set the ShouldDetectMonitorScaleChanges property.
2171 unsafe fn put_should_detect_monitor_scale_changes(&self, /* in */ value: BOOL) -> HRESULT;
2172
2173 /// Add an event handler for the RasterizationScaleChanged event.
2174 /// The event is raised when the WebView detects that the monitor DPI scale
2175 /// has changed, ShouldDetectMonitorScaleChanges is true, and the WebView has
2176 /// changed the RasterizationScale property.
2177 ///
2178 /// \snippet ViewComponent.cpp RasterizationScaleChanged
2179 unsafe fn add_rasterization_scale_changed(
2180 &self,
2181 /* in */
2182 event_handler: *mut *mut ICoreWebView2RasterizationScaleChangedEventHandlerVTable,
2183 /* out */ token: *mut EventRegistrationToken,
2184 ) -> HRESULT;
2185
2186 /// Remove an event handler previously added with
2187 /// add_RasterizationScaleChanged.
2188 unsafe fn remove_rasterization_scale_changed(
2189 &self,
2190 /* in */ token: EventRegistrationToken,
2191 ) -> HRESULT;
2192
2193 /// BoundsMode affects how setting the Bounds and RasterizationScale
2194 /// properties work. Bounds mode can either be in COREWEBVIEW2_BOUNDS_MODE_USE_RAW_PIXELS
2195 /// mode or COREWEBVIEW2_BOUNDS_MODE_USE_RASTERIZATION_SCALE mode.
2196 ///
2197 /// When the mode is in COREWEBVIEW2_BOUNDS_MODE_USE_RAW_PIXELS, setting the bounds
2198 /// property will set the size of the WebView in raw screen pixels. Changing
2199 /// the rasterization scale in this mode won't change the raw pixel size of
2200 /// the WebView and will only change the rasterization scale.
2201 ///
2202 /// When the mode is in COREWEBVIEW2_BOUNDS_MODE_USE_RASTERIZATION_SCALE, setting the
2203 /// bounds property will change the logical size of the WebView which can be
2204 /// described by the following equation:
2205 /// ```text
2206 /// Logical size * rasterization scale = Raw Pixel size
2207 /// ```
2208 /// In this case, changing the rasterization scale will keep the logical size
2209 /// the same and change the raw pixel size.
2210 ///
2211 /// \snippet ViewComponent.cpp BoundsMode
2212 unsafe fn get_bounds_mode(
2213 &self,
2214 /* out, retval */ bounds_mode: *mut BoundsMode,
2215 ) -> HRESULT;
2216
2217 /// Set the BoundsMode property.
2218 unsafe fn put_bounds_mode(&self, /* in */ bounds_mode: BoundsMode) -> HRESULT;
2219}
2220
2221/// This interface is an extension of the ICoreWebView2Controller interface to
2222/// support visual hosting. An object implementing the
2223/// ICoreWebView2CompositionController interface will also implement
2224/// ICoreWebView2Controller. Callers are expected to use
2225/// ICoreWebView2Controller for resizing, visibility, focus, and so on, and
2226/// then use ICoreWebView2CompositionController to connect to a composition
2227/// tree and provide input meant for the WebView.
2228#[com_interface("3df9b733-b9ae-4a15-86b4-eb9ee9826469")]
2229pub trait ICoreWebView2CompositionController: IUnknown {
2230 /// The RootVisualTarget is a visual in the hosting app's visual tree. This
2231 /// visual is where the WebView will connect its visual tree. The app uses
2232 /// this visual to position the WebView within the app. The app still needs
2233 /// to use the Bounds property to size the WebView. The RootVisualTarget
2234 /// property can be an IDCompositionVisual or a
2235 /// Windows::UI::Composition::ContainerVisual. WebView will connect its visual
2236 /// tree to the provided visual before returning from the property setter. The
2237 /// app needs to commit on its device setting the RootVisualTarget property.
2238 /// The RootVisualTarget property supports being set to nullptr to disconnect
2239 /// the WebView from the app's visual tree.
2240 /// \snippet ViewComponent.cpp SetRootVisualTarget
2241 /// \snippet ViewComponent.cpp BuildDCompTree
2242 unsafe fn get_root_visual_target(
2243 &self,
2244 /* out, retval */ target: *mut *mut *mut IUnknownVTable,
2245 ) -> HRESULT;
2246
2247 /// Set the RootVisualTarget property.
2248 unsafe fn put_root_visual_target(
2249 &self,
2250 /* in */ target: *mut *mut IUnknownVTable,
2251 ) -> HRESULT;
2252
2253 /// If eventKind is COREWEBVIEW2_MOUSE_EVENT_KIND_HORIZONTAL_WHEEL or
2254 /// COREWEBVIEW2_MOUSE_EVENT_KIND_WHEEL, then mouseData specifies the amount of
2255 /// wheel movement. A positive value indicates that the wheel was rotated
2256 /// forward, away from the user; a negative value indicates that the wheel was
2257 /// rotated backward, toward the user. One wheel click is defined as
2258 /// WHEEL_DELTA, which is 120.
2259 /// If eventKind is COREWEBVIEW2_MOUSE_EVENT_KIND_X_BUTTON_DOUBLE_CLICK
2260 /// COREWEBVIEW2_MOUSE_EVENT_KIND_X_BUTTON_DOWN, or
2261 /// COREWEBVIEW2_MOUSE_EVENT_KIND_X_BUTTON_UP, then mouseData specifies which X
2262 /// buttons were pressed or released. This value should be 1 if the first X
2263 /// button is pressed/released and 2 if the second X button is
2264 /// pressed/released.
2265 /// If eventKind is COREWEBVIEW2_MOUSE_EVENT_KIND_LEAVE, then virtualKeys,
2266 /// mouseData, and point should all be zero.
2267 /// If eventKind is any other value, then mouseData should be zero.
2268 /// Point is expected to be in the client coordinate space of the WebView.
2269 /// To track mouse events that start in the WebView and can potentially move
2270 /// outside of the WebView and host application, calling SetCapture and
2271 /// ReleaseCapture is recommended.
2272 /// To dismiss hover popups, it is also recommended to send
2273 /// COREWEBVIEW2_MOUSE_EVENT_KIND_LEAVE messages.
2274 /// \snippet ViewComponent.cpp SendMouseInput
2275 unsafe fn send_mouse_input(
2276 &self,
2277 /* in */ event_kind: MouseEventKind,
2278 /* in */ virtual_keys: MouseEventVirtualKeys,
2279 /* in */ mouse_data: u32,
2280 /* in */ point: POINT,
2281 ) -> HRESULT;
2282
2283 /// SendPointerInput accepts touch or pen pointer input of types defined in
2284 /// COREWEBVIEW2_POINTER_EVENT_KIND. Any pointer input from the system must be
2285 /// converted into an ICoreWebView2PointerInfo first.
2286 unsafe fn send_pointer_input(
2287 &self,
2288 /* in */ event_kind: PointerEventKind,
2289 /* in */ pointer_info: *mut *mut ICoreWebView2PointerInfoVTable,
2290 ) -> HRESULT;
2291
2292 /// The current cursor that WebView thinks it should be. The cursor should be
2293 /// set in WM_SETCURSOR through \::SetCursor or set on the corresponding
2294 /// parent/ancestor HWND of the WebView through \::SetClassLongPtr. The HCURSOR
2295 /// can be freed so CopyCursor/DestroyCursor is recommended to keep your own
2296 /// copy if you are doing more than immediately setting the cursor.
2297 unsafe fn get_cursor(&self, /* out, retval */ cursor: *mut HCURSOR) -> HRESULT;
2298
2299 /// The current system cursor ID reported by the underlying rendering engine
2300 /// for WebView. For example, most of the time, when the cursor is over text,
2301 /// this will return the int value for IDC_IBEAM. The systemCursorId is only
2302 /// valid if the rendering engine reports a default Windows cursor resource
2303 /// value. Navigate to
2304 /// /[LoadCursorW/]/[WindowsWin32ApiWinuserNfwinuserloadcursorw/] for more
2305 /// details. Otherwise, if custom CSS cursors are being used, this will return
2306 /// 0. To actually use systemCursorId in LoadCursor or LoadImage,
2307 /// MAKEINTRESOURCE must be called on it first.
2308 ///
2309 /// [WindowsWin32ApiWinuserNfwinuserloadcursorw]: /windows/win32/api/winuser/nf-winuser-loadcursorw "LoadCursorW function (winuser.h) - Win32 apps | Microsoft Docs"
2310 ///
2311 /// \snippet ViewComponent.cpp SystemCursorId
2312 unsafe fn get_system_cursor_id(
2313 &self,
2314 /* out, retval */ system_cursor_id: *mut u32,
2315 ) -> HRESULT;
2316
2317 /// Add an event handler for the CursorChanged event.
2318 /// The event is raised when WebView thinks the cursor should be changed. For
2319 /// example, when the mouse cursor is currently the default cursor but is then
2320 /// moved over text, it may try to change to the IBeam cursor.
2321 ///
2322 /// It is expected for the developer to send
2323 /// COREWEBVIEW2_MOUSE_EVENT_KIND_LEAVE messages (in addition to
2324 /// COREWEBVIEW2_MOUSE_EVENT_KIND_MOVE messages) through the SendMouseInput
2325 /// API. This is to ensure that the mouse is actually within the WebView that
2326 /// sends out CursorChanged events.
2327 ///
2328 /// \snippet ViewComponent.cpp CursorChanged
2329 unsafe fn add_cursor_changed(
2330 &self,
2331 /* in */ event_handler: *mut *mut ICoreWebView2CursorChangedEventHandlerVTable,
2332 /* out */ token: *mut EventRegistrationToken,
2333 ) -> HRESULT;
2334
2335 /// Remove an event handler previously added with add_CursorChanged.
2336 unsafe fn remove_cursor_changed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
2337}
2338
2339/// A continuation of the ICoreWebView2CompositionController interface.
2340#[com_interface("0b6a3d24-49cb-4806-ba20-b5e0734a7b26")]
2341pub trait ICoreWebView2CompositionController2: ICoreWebView2CompositionController {
2342 /// Returns the UI Automation Provider for the WebView.
2343 unsafe fn get_uiaprovider(
2344 &self,
2345 /* out, retval */ provider: *mut *mut *mut IUnknownVTable,
2346 ) -> HRESULT;
2347}
2348
2349/// This interface is used to complete deferrals on event args that support
2350/// getting deferrals using the `GetDeferral` method.
2351#[com_interface("c10e7f7b-b585-46f0-a623-8befbf3e4ee0")]
2352pub trait ICoreWebView2Deferral: IUnknown {
2353 /// Completes the associated deferred event. Complete should only be run
2354 /// once for each deferral taken.
2355 unsafe fn complete(&self) -> HRESULT;
2356}
2357
2358/// Defines properties that enable, disable, or modify WebView features.
2359/// Setting changes made after `NavigationStarting` event does not apply
2360/// until the next top-level navigation.
2361#[com_interface("e562e4f0-d7fa-43ac-8d71-c05150499f00")]
2362pub trait ICoreWebView2Settings: IUnknown {
2363 /// Controls if running JavaScript is enabled in all future navigations in
2364 /// the WebView. This only affects scripts in the document. Scripts
2365 /// injected with `ExecuteScript` runs even if script is disabled.
2366 /// The default value is `TRUE`.
2367 ///
2368 /// \snippet SettingsComponent.cpp IsScriptEnabled
2369 unsafe fn get_is_script_enabled(
2370 &self,
2371 /* out, retval */ is_script_enabled: *mut BOOL,
2372 ) -> HRESULT;
2373
2374 /// Sets the `IsScriptEnabled` property.
2375 unsafe fn put_is_script_enabled(&self, /* in */ is_script_enabled: BOOL) -> HRESULT;
2376
2377 /// The `IsWebMessageEnabled` property is used when loading a new HTML
2378 /// document. If set to `TRUE`, communication from the host to the top-level
2379 /// HTML document of the WebView is allowed using `PostWebMessageAsJson`,
2380 /// `PostWebMessageAsString`, and message event of `window.chrome.webview`.
2381 /// For more information, navigate to [PostWebMessageAsJson]. Communication
2382 /// from the top-level HTML document of the WebView to the host is allowed
2383 /// using the postMessage function of `window.chrome.webview` and
2384 /// `add_WebMessageReceived` method. For more information, navigate to
2385 /// [add_WebMessageReceived]. If set to false, then communication is
2386 /// disallowed. `PostWebMessageAsJson` and `PostWebMessageAsString` fails
2387 /// with `E_ACCESSDENIED` and `window.chrome.webview.postMessage` fails by
2388 /// throwing an instance of an `Error` object.
2389 /// The default value is `TRUE`.
2390 ///
2391 /// \snippet ScenarioWebMessage.cpp IsWebMessageEnabled
2392 unsafe fn get_is_web_message_enabled(
2393 &self,
2394 /* out, retval */ is_web_message_enabled: *mut BOOL,
2395 ) -> HRESULT;
2396
2397 /// Sets the `IsWebMessageEnabled` property.
2398 unsafe fn put_is_web_message_enabled(
2399 &self,
2400 /* in */ is_web_message_enabled: BOOL,
2401 ) -> HRESULT;
2402
2403 /// `AreDefaultScriptDialogsEnabled` is used when loading a new HTML
2404 /// document. If set to `FALSE`, WebView2 does not render the default JavaScript
2405 /// dialog box (Specifically those displayed by the JavaScript alert,
2406 /// confirm, prompt functions and `beforeunload` event). Instead, if an
2407 /// event handler is set using `add_ScriptDialogOpening`, WebView sends an
2408 /// event that contains all of the information for the dialog and allow the
2409 /// host app to show a custom UI.
2410 /// The default value is `TRUE`.
2411 unsafe fn get_are_default_script_dialogs_enabled(
2412 &self,
2413 /* out, retval */ are_default_script_dialogs_enabled: *mut BOOL,
2414 ) -> HRESULT;
2415
2416 /// Sets the `AreDefaultScriptDialogsEnabled` property.
2417 unsafe fn put_are_default_script_dialogs_enabled(
2418 &self,
2419 /* in */ are_default_script_dialogs_enabled: BOOL,
2420 ) -> HRESULT;
2421
2422 /// `IsStatusBarEnabled` controls whether the status bar is displayed. The
2423 /// status bar is usually displayed in the lower left of the WebView and
2424 /// shows things such as the URI of a link when the user hovers over it and
2425 /// other information.
2426 /// The default value is `TRUE`.
2427 /// The status bar UI can be altered by web content and should not be considered secure.
2428 unsafe fn get_is_status_bar_enabled(
2429 &self,
2430 /* out, retval */ is_status_bar_enabled: *mut BOOL,
2431 ) -> HRESULT;
2432
2433 /// Sets the `IsStatusBarEnabled` property.
2434 unsafe fn put_is_status_bar_enabled(
2435 &self,
2436 /* in */ is_status_bar_enabled: BOOL,
2437 ) -> HRESULT;
2438
2439 /// `AreDevToolsEnabled` controls whether the user is able to use the context
2440 /// menu or keyboard shortcuts to open the DevTools window.
2441 /// The default value is `TRUE`.
2442 unsafe fn get_are_dev_tools_enabled(
2443 &self,
2444 /* out, retval */ are_dev_tools_enabled: *mut BOOL,
2445 ) -> HRESULT;
2446
2447 /// Sets the `AreDevToolsEnabled` property.
2448 unsafe fn put_are_dev_tools_enabled(
2449 &self,
2450 /* in */ are_dev_tools_enabled: BOOL,
2451 ) -> HRESULT;
2452
2453 /// The `AreDefaultContextMenusEnabled` property is used to prevent default
2454 /// context menus from being shown to user in WebView.
2455 /// The default value is `TRUE`.
2456 ///
2457 /// \snippet SettingsComponent.cpp DisableContextMenu
2458 unsafe fn get_are_default_context_menus_enabled(
2459 &self,
2460 /* out, retval */ enabled: *mut BOOL,
2461 ) -> HRESULT;
2462
2463 /// Sets the `AreDefaultContextMenusEnabled` property.
2464 unsafe fn put_are_default_context_menus_enabled(&self, /* in */ enabled: BOOL) -> HRESULT;
2465
2466 /// The `AreHostObjectsAllowed` property is used to control whether host
2467 /// objects are accessible from the page in WebView.
2468 /// The default value is `TRUE`.
2469 ///
2470 /// \snippet SettingsComponent.cpp HostObjectsAccess
2471 unsafe fn get_are_host_objects_allowed(
2472 &self,
2473 /* out, retval */ allowed: *mut BOOL,
2474 ) -> HRESULT;
2475
2476 /// Sets the `AreHostObjectsAllowed` property.
2477 unsafe fn put_are_host_objects_allowed(&self, /* in */ allowed: BOOL) -> HRESULT;
2478
2479 /// The `IsZoomControlEnabled` property is used to prevent the user from
2480 /// impacting the zoom of the WebView. When disabled, the user is not able
2481 /// to zoom using Ctrl++, Ctrl+-, or Ctrl+mouse wheel, but the zoom
2482 /// is set using `ZoomFactor` API. The default value is `TRUE`.
2483 ///
2484 /// \snippet SettingsComponent.cpp DisableZoomControl
2485 unsafe fn get_is_zoom_control_enabled(
2486 &self,
2487 /* out, retval */ enabled: *mut BOOL,
2488 ) -> HRESULT;
2489
2490 /// Sets the `IsZoomControlEnabled` property.
2491 unsafe fn put_is_zoom_control_enabled(&self, /* in */ enabled: BOOL) -> HRESULT;
2492
2493 /// The `IsBuiltInErrorPageEnabled` property is used to disable built in
2494 /// error page for navigation failure and render process failure. When
2495 /// disabled, a blank page is displayed when the related error happens.
2496 /// The default value is `TRUE`.
2497 ///
2498 /// \snippet SettingsComponent.cpp BuiltInErrorPageEnabled
2499 unsafe fn get_is_built_in_error_page_enabled(
2500 &self,
2501 /* out, retval */ enabled: *mut BOOL,
2502 ) -> HRESULT;
2503
2504 /// Sets the `IsBuiltInErrorPageEnabled` property.
2505 unsafe fn put_is_built_in_error_page_enabled(&self, /* in */ enabled: BOOL) -> HRESULT;
2506}
2507
2508/// A continuation of the ICoreWebView2Settings interface that manages the user agent.
2509#[com_interface("ee9a0f68-f46c-4e32-ac23-ef8cac224d2a")]
2510pub trait ICoreWebView2Settings2: ICoreWebView2Settings {
2511 /// Returns the User Agent. The default value is the default User Agent of the
2512 /// Microsoft Edge browser.
2513 ///
2514 /// \snippet SettingsComponent.cpp UserAgent
2515 unsafe fn get_user_agent(&self, /* out, retval */ user_agent: *mut LPWSTR) -> HRESULT;
2516
2517 /// Sets the `UserAgent` property. This property may be overridden if
2518 /// the User-Agent header is set in a request. If the parameter is empty
2519 /// the User Agent will not be updated and the current User Agent will remain.
2520 unsafe fn put_user_agent(&self, /* in */ user_agent: LPCWSTR) -> HRESULT;
2521}
2522
2523/// A continuation of the ICoreWebView2Settings interface that manages whether
2524/// browser accelerator keys are enabled.
2525#[com_interface("fdb5ab74-af33-4854-84f0-0a631deb5eba")]
2526pub trait ICoreWebView2Settings3: ICoreWebView2Settings2 {
2527 /// When this setting is set to FALSE, it disables all accelerator keys that
2528 /// access features specific to a web browser, including but not limited to:
2529 /// - Ctrl-F and F3 for Find on Page
2530 /// - Ctrl-P for Print
2531 /// - Ctrl-R and F5 for Reload
2532 /// - Ctrl-Plus and Ctrl-Minus for zooming
2533 /// - Ctrl-Shift-C and F12 for DevTools
2534 /// - Special keys for browser functions, such as Back, Forward, and Search
2535 ///
2536 /// It does not disable accelerator keys related to movement and text editing,
2537 /// such as:
2538 /// - Home, End, Page Up, and Page Down
2539 /// - Ctrl-X, Ctrl-C, Ctrl-V
2540 /// - Ctrl-A for Select All
2541 /// - Ctrl-Z for Undo
2542 ///
2543 /// Those accelerator keys will always be enabled unless they are handled in
2544 /// the `AcceleratorKeyPressed` event.
2545 ///
2546 /// This setting has no effect on the `AcceleratorKeyPressed` event. The event
2547 /// will be fired for all accelerator keys, whether they are enabled or not.
2548 ///
2549 /// The default value for `AreBrowserAcceleratorKeysEnabled` is TRUE.
2550 ///
2551 /// \snippet SettingsComponent.cpp AreBrowserAcceleratorKeysEnabled
2552 unsafe fn get_are_browser_accelerator_keys_enabled(
2553 &self,
2554 /* out, retval */ are_browser_accelerator_keys_enabled: *mut BOOL,
2555 ) -> HRESULT;
2556
2557 /// Sets the `AreBrowserAcceleratorKeysEnabled` property.
2558 unsafe fn put_are_browser_accelerator_keys_enabled(
2559 &self,
2560 /* in */ are_browser_accelerator_keys_enabled: BOOL,
2561 ) -> HRESULT;
2562}
2563
2564/// A continuation of the ICoreWebView2Settings interface to manage autofill.
2565#[com_interface("cb56846c-4168-4d53-b04f-03b6d6796ff2")]
2566pub trait ICoreWebView2Settings4: ICoreWebView2Settings3 {
2567 /// IsPasswordAutosaveEnabled controls whether autosave for password
2568 /// information is enabled. The IsPasswordAutosaveEnabled property behaves
2569 /// independently of the IsGeneralAutofillEnabled property. When IsPasswordAutosaveEnabled is
2570 /// false, no new password data is saved and no Save/Update Password prompts are displayed.
2571 /// However, if there was password data already saved before disabling this setting,
2572 /// then that password information is auto-populated, suggestions are shown and clicking on
2573 /// one will populate the fields.
2574 /// When IsPasswordAutosaveEnabled is true, password information is auto-populated,
2575 /// suggestions are shown and clicking on one will populate the fields, new data
2576 /// is saved, and a Save/Update Password prompt is displayed.
2577 /// The default value is `FALSE`.
2578 ///
2579 /// \snippet SettingsComponent.cpp PasswordAutosaveEnabled
2580 unsafe fn get_is_password_autosave_enabled(
2581 &self,
2582 /* out, retval */ value: *mut BOOL,
2583 ) -> HRESULT;
2584
2585 /// Set the IsPasswordAutosaveEnabled property.
2586 unsafe fn put_is_password_autosave_enabled(&self, /* in */ value: BOOL) -> HRESULT;
2587
2588 /// IsGeneralAutofillEnabled controls whether autofill for information
2589 /// like names, street and email addresses, phone numbers, and arbitrary input
2590 /// is enabled. This excludes password and credit card information. When
2591 /// IsGeneralAutofillEnabled is false, no suggestions appear, and no new information
2592 /// is saved. When IsGeneralAutofillEnabled is true, information is saved, suggestions
2593 /// appear and clicking on one will populate the form fields.
2594 /// The default value is `TRUE`.
2595 ///
2596 /// \snippet SettingsComponent.cpp GeneralAutofillEnabled
2597 unsafe fn get_is_general_autofill_enabled(
2598 &self,
2599 /* out, retval */ value: *mut BOOL,
2600 ) -> HRESULT;
2601
2602 /// Set the IsGeneralAutofillEnabled property.
2603 unsafe fn put_is_general_autofill_enabled(&self, /* in */ value: BOOL) -> HRESULT;
2604}
2605
2606/// A continuation of the ICoreWebView2Settings interface to manage pinch zoom.
2607#[com_interface("183e7052-1d03-43a0-ab99-98e043b66b39")]
2608pub trait ICoreWebView2Settings5: ICoreWebView2Settings4 {
2609 /// Pinch-zoom, referred to as "Page Scale" zoom, is performed as a post-rendering step,
2610 /// it changes the page scale factor property and scales the surface the web page is
2611 /// rendered onto when user performs a pinch zooming action. It does not change the layout
2612 /// but rather changes the viewport and clips the web content, the content outside of the
2613 /// viewport isn't visible onscreen and users can't reach this content using mouse.
2614 ///
2615 /// The `IsPinchZoomEnabled` property enables or disables the ability of
2616 /// the end user to use a pinching motion on touch input enabled devices
2617 /// to scale the web content in the WebView2. It defaults to `TRUE`.
2618 /// When set to `FALSE`, the end user cannot pinch zoom after the next navigation.
2619 /// Disabling/Enabling `IsPinchZoomEnabled` only affects the end user's ability to use
2620 /// pinch motions and does not change the page scale factor.
2621 /// This API only affects the Page Scale zoom and has no effect on the
2622 /// existing browser zoom properties (`IsZoomControlEnabled` and `ZoomFactor`)
2623 /// or other end user mechanisms for zooming.
2624 ///
2625 /// \snippet SettingsComponent.cpp TogglePinchZoomEnabled
2626 unsafe fn get_is_pinch_zoom_enabled(
2627 &self,
2628 /* out, retval */ enabled: *mut BOOL,
2629 ) -> HRESULT;
2630
2631 /// Set the `IsPinchZoomEnabled` property
2632 unsafe fn put_is_pinch_zoom_enabled(&self, /* in */ enabled: BOOL) -> HRESULT;
2633}
2634
2635/// Event args for the `ProcessFailed` event.
2636#[com_interface("8155a9a4-1474-4a86-8cae-151b0fa6b8ca")]
2637pub trait ICoreWebView2ProcessFailedEventArgs: IUnknown {
2638 /// The kind of process failure that has occurred. `processFailedKind` is
2639 /// `COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_EXITED` if the
2640 /// failed process is the main frame's renderer, even if there were subframes
2641 /// rendered by such process; all frames are gone when this happens.
2642 unsafe fn get_process_failed_kind(
2643 &self,
2644 /* out, retval */ process_failed_kind: *mut ProcessFailedKind,
2645 ) -> HRESULT;
2646}
2647
2648/// Receives `ProcessFailed` events.
2649#[com_interface("79e0aea4-990b-42d9-aa1d-0fcc2e5bc7f1")]
2650pub trait ICoreWebView2ProcessFailedEventHandler: IUnknown {
2651 /// Provides the event args for the corresponding event.
2652 unsafe fn invoke(
2653 &self,
2654 /* in */ sender: *mut *mut ICoreWebView2VTable,
2655 /* in */ args: *mut *mut ICoreWebView2ProcessFailedEventArgsVTable,
2656 ) -> HRESULT;
2657}
2658
2659/// Implements the interface to receive `ZoomFactorChanged` events. Use the
2660/// `ICoreWebView2Controller.ZoomFactor` property to get the modified zoom
2661/// factor.
2662#[com_interface("b52d71d6-c4df-4543-a90c-64a3e60f38cb")]
2663pub trait ICoreWebView2ZoomFactorChangedEventHandler: IUnknown {
2664 /// Provides the event args for the corresponding event. No event args exist
2665 /// and the `args` parameter is set to `null`.
2666 unsafe fn invoke(
2667 &self,
2668 /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
2669 /* in */ args: *mut *mut IUnknownVTable,
2670 ) -> HRESULT;
2671}
2672
2673/// Iterator for a collection of HTTP headers. For more information, navigate
2674/// to ICoreWebView2HttpRequestHeaders and ICoreWebView2HttpResponseHeaders.
2675///
2676/// \snippet ScenarioWebViewEventMonitor.cpp HttpRequestHeaderIterator
2677#[com_interface("0702fc30-f43b-47bb-ab52-a42cb552ad9f")]
2678pub trait ICoreWebView2HttpHeadersCollectionIterator: IUnknown {
2679 /// Get the name and value of the current HTTP header of the iterator. If
2680 /// the previous `MoveNext` operation set the `hasNext` parameter to `FALSE`,
2681 /// this method fails.
2682 unsafe fn get_current_header(
2683 &self,
2684 /* out */ name: *mut LPWSTR,
2685 /* out */ value: *mut LPWSTR,
2686 ) -> HRESULT;
2687
2688 /// `TRUE` when the iterator has not run out of headers. If the collection
2689 /// over which the iterator is iterating is empty or if the iterator has gone
2690 /// past the end of the collection then this is `FALSE`.
2691 unsafe fn get_has_current_header(
2692 &self,
2693 /* out, retval */ has_current: *mut BOOL,
2694 ) -> HRESULT;
2695
2696 /// Move the iterator to the next HTTP header in the collection.
2697 ///
2698 /// \> [!NOTE]\n \> If no more HTTP headers exist, the `hasNext` parameter is set to
2699 /// `FALSE`. After this occurs the `GetCurrentHeader` method fails.
2700 unsafe fn move_next(&self, /* out, retval */ has_next: *mut BOOL) -> HRESULT;
2701}
2702
2703/// HTTP request headers. Used to inspect the HTTP request on
2704/// `WebResourceRequested` event and `NavigationStarting` event.
2705///
2706/// \> [!NOTE]\n\> It is possible to modify the HTTP request from a `WebResourceRequested`
2707/// event, but not from a `NavigationStarting` event.
2708#[com_interface("e86cac0e-5523-465c-b536-8fb9fc8c8c60")]
2709pub trait ICoreWebView2HttpRequestHeaders: IUnknown {
2710 /// Gets the header value matching the name.
2711 unsafe fn get_header(
2712 &self,
2713 /* in */ name: LPCWSTR,
2714 /* out, retval */ value: *mut LPWSTR,
2715 ) -> HRESULT;
2716
2717 /// Gets the header value matching the name using an iterator.
2718 unsafe fn get_headers(
2719 &self,
2720 /* in */ name: LPCWSTR,
2721 /* out, retval */
2722 iterator: *mut *mut *mut ICoreWebView2HttpHeadersCollectionIteratorVTable,
2723 ) -> HRESULT;
2724
2725 /// Verifies that the headers contain an entry that matches the header name.
2726 unsafe fn contains(
2727 &self,
2728 /* in */ name: LPCWSTR,
2729 /* out, retval */ contains: *mut BOOL,
2730 ) -> HRESULT;
2731
2732 /// Adds or updates header that matches the name.
2733 unsafe fn set_header(
2734 &self,
2735 /* in */ name: LPCWSTR,
2736 /* in */ value: LPCWSTR,
2737 ) -> HRESULT;
2738
2739 /// Removes header that matches the name.
2740 unsafe fn remove_header(&self, /* in */ name: LPCWSTR) -> HRESULT;
2741
2742 /// Gets an iterator over the collection of request headers.
2743 unsafe fn get_iterator(
2744 &self,
2745 /* out, retval */
2746 iterator: *mut *mut *mut ICoreWebView2HttpHeadersCollectionIteratorVTable,
2747 ) -> HRESULT;
2748}
2749
2750/// HTTP response headers. Used to construct a `WebResourceResponse` for the
2751/// `WebResourceRequested` event.
2752#[com_interface("03c5ff5a-9b45-4a88-881c-89a9f328619c")]
2753pub trait ICoreWebView2HttpResponseHeaders: IUnknown {
2754 /// Appends header line with name and value.
2755 unsafe fn append_header(
2756 &self,
2757 /* in */ name: LPCWSTR,
2758 /* in */ value: LPCWSTR,
2759 ) -> HRESULT;
2760
2761 /// Verifies that the headers contain entries that match the header name.
2762 unsafe fn contains(
2763 &self,
2764 /* in */ name: LPCWSTR,
2765 /* out, retval */ contains: *mut BOOL,
2766 ) -> HRESULT;
2767
2768 /// Gets the first header value in the collection matching the name.
2769 unsafe fn get_header(
2770 &self,
2771 /* in */ name: LPCWSTR,
2772 /* out, retval */ value: *mut LPWSTR,
2773 ) -> HRESULT;
2774
2775 /// Gets the header values matching the name.
2776 unsafe fn get_headers(
2777 &self,
2778 /* in */ name: LPCWSTR,
2779 /* out, retval */
2780 iterator: *mut *mut *mut ICoreWebView2HttpHeadersCollectionIteratorVTable,
2781 ) -> HRESULT;
2782
2783 /// Gets an iterator over the collection of entire response headers.
2784 unsafe fn get_iterator(
2785 &self,
2786 /* out, retval */
2787 iterator: *mut *mut *mut ICoreWebView2HttpHeadersCollectionIteratorVTable,
2788 ) -> HRESULT;
2789}
2790
2791/// An HTTP request used with the `WebResourceRequested` event.
2792#[com_interface("97055cd4-512c-4264-8b5f-e3f446cea6a5")]
2793pub trait ICoreWebView2WebResourceRequest: IUnknown {
2794 /// The request URI.
2795 unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;
2796
2797 /// Sets the `Uri` property.
2798 unsafe fn put_uri(&self, /* in */ uri: LPCWSTR) -> HRESULT;
2799
2800 /// The HTTP request method.
2801 unsafe fn get_method(&self, /* out, retval */ method: *mut LPWSTR) -> HRESULT;
2802
2803 /// Sets the `Method` property.
2804 unsafe fn put_method(&self, /* in */ method: LPCWSTR) -> HRESULT;
2805
2806 /// The HTTP request message body as stream. POST data should be here. If a
2807 /// stream is set, which overrides the message body, the stream must have
2808 /// all the content data available by the time the `WebResourceRequested`
2809 /// event deferral of this response is completed. Stream should be agile or
2810 /// be created from a background STA to prevent performance impact to the UI
2811 /// thread. `Null` means no content data. `IStream` semantics apply
2812 /// (return `S_OK` to `Read` runs until all data is exhausted).
2813 unsafe fn get_content(
2814 &self,
2815 /* out, retval */ content: *mut *mut *mut IStreamVTable,
2816 ) -> HRESULT;
2817
2818 /// Sets the `Content` property.
2819 unsafe fn put_content(&self, /* in */ content: *mut *mut IStreamVTable) -> HRESULT;
2820
2821 /// The mutable HTTP request headers
2822 unsafe fn get_headers(
2823 &self,
2824 /* out, retval */ headers: *mut *mut *mut ICoreWebView2HttpRequestHeadersVTable,
2825 ) -> HRESULT;
2826}
2827
2828/// An HTTP response used with the `WebResourceRequested` event.
2829#[com_interface("aafcc94f-fa27-48fd-97df-830ef75aaec9")]
2830pub trait ICoreWebView2WebResourceResponse: IUnknown {
2831 /// HTTP response content as stream. Stream must have all the content data
2832 /// available by the time the `WebResourceRequested` event deferral of this
2833 /// response is completed. Stream should be agile or be created from a
2834 /// background thread to prevent performance impact to the UI thread. `Null`
2835 /// means no content data. `IStream` semantics apply (return `S_OK` to
2836 /// `Read` runs until all data is exhausted).
2837 unsafe fn get_content(
2838 &self,
2839 /* out, retval */ content: *mut *mut *mut IStreamVTable,
2840 ) -> HRESULT;
2841
2842 /// Sets the `Content` property.
2843 unsafe fn put_content(&self, /* in */ content: *mut *mut IStreamVTable) -> HRESULT;
2844
2845 /// Overridden HTTP response headers.
2846 unsafe fn get_headers(
2847 &self,
2848 /* out, retval */ headers: *mut *mut *mut ICoreWebView2HttpResponseHeadersVTable,
2849 ) -> HRESULT;
2850
2851 /// The HTTP response status code.
2852 unsafe fn get_status_code(&self, /* out, retval */ status_code: *mut i32) -> HRESULT;
2853
2854 /// Sets the `StatusCode` property.
2855 unsafe fn put_status_code(&self, /* in */ status_code: i32) -> HRESULT;
2856
2857 /// The HTTP response reason phrase.
2858 unsafe fn get_reason_phrase(
2859 &self,
2860 /* out, retval */ reason_phrase: *mut LPWSTR,
2861 ) -> HRESULT;
2862
2863 /// Sets the `ReasonPhrase` property.
2864 unsafe fn put_reason_phrase(&self, /* in */ reason_phrase: LPCWSTR) -> HRESULT;
2865}
2866
2867/// Event args for the `NavigationStarting` event.
2868#[com_interface("5b495469-e119-438a-9b18-7604f25f2e49")]
2869pub trait ICoreWebView2NavigationStartingEventArgs: IUnknown {
2870 /// The uri of the requested navigation.
2871 unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;
2872
2873 /// `TRUE` when the navigation was initiated through a user gesture as
2874 /// opposed to programmatic navigation by page script. Navigations initiated
2875 /// via WebView2 APIs are considered as user initiated.
2876 unsafe fn get_is_user_initiated(
2877 &self,
2878 /* out, retval */ is_user_initiated: *mut BOOL,
2879 ) -> HRESULT;
2880
2881 /// `TRUE` when the navigation is redirected.
2882 unsafe fn get_is_redirected(&self, /* out, retval */ is_redirected: *mut BOOL) -> HRESULT;
2883
2884 /// The HTTP request headers for the navigation.
2885 ///
2886 /// \> [!NOTE]\n\> You are not able to modify the HTTP request headers in a
2887 /// `NavigationStarting` event.
2888 unsafe fn get_request_headers(
2889 &self,
2890 /* out, retval */
2891 request_headers: *mut *mut *mut ICoreWebView2HttpRequestHeadersVTable,
2892 ) -> HRESULT;
2893
2894 /// The host may set this flag to cancel the navigation. If set, the
2895 /// navigation is not longer present and the content of the current page is
2896 /// intact. For performance reasons, `GET` HTTP requests may happen, while
2897 /// the host is responding. You may set cookies and use part of a request
2898 /// for the navigation. Cancellation for navigation to `about:blank` or
2899 /// frame navigation to `srcdoc` is not supported. Such attempts are
2900 /// ignored.
2901 unsafe fn get_cancel(&self, /* out, retval */ cancel: *mut BOOL) -> HRESULT;
2902
2903 /// Sets the `Cancel` property.
2904 unsafe fn put_cancel(&self, /* in */ cancel: BOOL) -> HRESULT;
2905
2906 /// The ID of the navigation.
2907 unsafe fn get_navigation_id(&self, /* out, retval */ navigation_id: *mut u64) -> HRESULT;
2908}
2909
2910/// Receives `NavigationStarting` events.
2911#[com_interface("9adbe429-f36d-432b-9ddc-f8881fbd76e3")]
2912pub trait ICoreWebView2NavigationStartingEventHandler: IUnknown {
2913 /// Provides the event args for the corresponding event.
2914 unsafe fn invoke(
2915 &self,
2916 /* in */ sender: *mut *mut ICoreWebView2VTable,
2917 /* in */ args: *mut *mut ICoreWebView2NavigationStartingEventArgsVTable,
2918 ) -> HRESULT;
2919}
2920
2921/// Event args for the `ContentLoading` event.
2922#[com_interface("0c8a1275-9b6b-4901-87ad-70df25bafa6e")]
2923pub trait ICoreWebView2ContentLoadingEventArgs: IUnknown {
2924 /// `TRUE` if the loaded content is an error page.
2925 unsafe fn get_is_error_page(&self, /* out, retval */ is_error_page: *mut BOOL) -> HRESULT;
2926
2927 /// The ID of the navigation.
2928 unsafe fn get_navigation_id(&self, /* out, retval */ navigation_id: *mut u64) -> HRESULT;
2929}
2930
2931/// Receives `ContentLoading` events.
2932#[com_interface("364471e7-f2be-4910-bdba-d72077d51c4b")]
2933pub trait ICoreWebView2ContentLoadingEventHandler: IUnknown {
2934 /// Provides the event args for the corresponding event.
2935 unsafe fn invoke(
2936 &self,
2937 /* in */ sender: *mut *mut ICoreWebView2VTable,
2938 /* in */ args: *mut *mut ICoreWebView2ContentLoadingEventArgsVTable,
2939 ) -> HRESULT;
2940}
2941
2942/// Event args for the `SourceChanged` event.
2943#[com_interface("31e0e545-1dba-4266-8914-f63848a1f7d7")]
2944pub trait ICoreWebView2SourceChangedEventArgs: IUnknown {
2945 /// `TRUE` if the page being navigated to is a new document.
2946 unsafe fn get_is_new_document(
2947 &self,
2948 /* out, retval */ is_new_document: *mut BOOL,
2949 ) -> HRESULT;
2950}
2951
2952/// Receives `SourceChanged` events.
2953#[com_interface("3c067f9f-5388-4772-8b48-79f7ef1ab37c")]
2954pub trait ICoreWebView2SourceChangedEventHandler: IUnknown {
2955 /// Provides the event args for the corresponding event.
2956 unsafe fn invoke(
2957 &self,
2958 /* in */ sender: *mut *mut ICoreWebView2VTable,
2959 /* in */ args: *mut *mut ICoreWebView2SourceChangedEventArgsVTable,
2960 ) -> HRESULT;
2961}
2962
2963/// Receives `HistoryChanged` events.
2964#[com_interface("c79a420c-efd9-4058-9295-3e8b4bcab645")]
2965pub trait ICoreWebView2HistoryChangedEventHandler: IUnknown {
2966 /// Provides the event args for the corresponding event. No event args exist
2967 /// and the `args` parameter is set to `null`.
2968 unsafe fn invoke(
2969 &self,
2970 /* in */ sender: *mut *mut ICoreWebView2VTable,
2971 /* in */ args: *mut *mut IUnknownVTable,
2972 ) -> HRESULT;
2973}
2974
2975/// Event args for the `ScriptDialogOpening` event.
2976#[com_interface("7390bb70-abe0-4843-9529-f143b31b03d6")]
2977pub trait ICoreWebView2ScriptDialogOpeningEventArgs: IUnknown {
2978 /// The URI of the page that requested the dialog box.
2979 unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;
2980
2981 /// The kind of JavaScript dialog box. `alert`, `confirm`, `prompt`, or
2982 /// `beforeunload`.
2983 unsafe fn get_kind(&self, /* out, retval */ kind: *mut ScriptDialogKind) -> HRESULT;
2984
2985 /// The message of the dialog box. From JavaScript this is the first
2986 /// parameter passed to `alert`, `confirm`, and `prompt` and is empty for
2987 /// `beforeunload`.
2988 unsafe fn get_message(&self, /* out, retval */ message: *mut LPWSTR) -> HRESULT;
2989
2990 /// The host may run this to respond with **OK** to `confirm`, `prompt`, and
2991 /// `beforeunload` dialogs. Do not run this method to indicate cancel.
2992 /// From JavaScript, this means that the `confirm` and `beforeunload` function
2993 /// returns `TRUE` if `Accept` is run. And for the prompt function it returns
2994 /// the value of `ResultText` if `Accept` is run and otherwise returns
2995 /// `FALSE`.
2996 unsafe fn accept(&self) -> HRESULT;
2997
2998 /// The second parameter passed to the JavaScript prompt dialog.
2999 /// The result of the prompt JavaScript function uses this value as the
3000 /// default value.
3001 unsafe fn get_default_text(&self, /* out, retval */ default_text: *mut LPWSTR) -> HRESULT;
3002
3003 /// The return value from the JavaScript prompt function if `Accept` is run.
3004 /// This value is ignored for dialog kinds other than prompt. If `Accept`
3005 /// is not run, this value is ignored and `FALSE` is returned from prompt.
3006 unsafe fn get_result_text(&self, /* out, retval */ result_text: *mut LPWSTR) -> HRESULT;
3007
3008 /// Sets the `ResultText` property.
3009 unsafe fn put_result_text(&self, /* in */ result_text: LPCWSTR) -> HRESULT;
3010
3011 /// Returns an `ICoreWebView2Deferral` object. Use this operation to
3012 /// complete the event at a later time.
3013 unsafe fn get_deferral(
3014 &self,
3015 /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
3016 ) -> HRESULT;
3017}
3018
3019/// Receives `ScriptDialogOpening` events.
3020#[com_interface("ef381bf9-afa8-4e37-91c4-8ac48524bdfb")]
3021pub trait ICoreWebView2ScriptDialogOpeningEventHandler: IUnknown {
3022 /// Provides the event args for the corresponding event.
3023 unsafe fn invoke(
3024 &self,
3025 /* in */ sender: *mut *mut ICoreWebView2VTable,
3026 /* in */ args: *mut *mut ICoreWebView2ScriptDialogOpeningEventArgsVTable,
3027 ) -> HRESULT;
3028}
3029
3030/// Event args for the `NavigationCompleted` event.
3031#[com_interface("30d68b7d-20d9-4752-a9ca-ec8448fbb5c1")]
3032pub trait ICoreWebView2NavigationCompletedEventArgs: IUnknown {
3033 /// `TRUE` when the navigation is successful. `FALSE` for a navigation that
3034 /// ended up in an error page (failures due to no network, DNS lookup
3035 /// failure, HTTP server responds with 4xx), but may also be `FALSE` for
3036 /// additional scenarios such as `window.stop()` run on navigated page.
3037 unsafe fn get_is_success(&self, /* out, retval */ is_success: *mut BOOL) -> HRESULT;
3038
3039 /// The error code if the navigation failed.
3040 unsafe fn get_web_error_status(
3041 &self,
3042 /* out, retval */ web_error_status: *mut WebErrorStatus,
3043 ) -> HRESULT;
3044
3045 /// The ID of the navigation.
3046 unsafe fn get_navigation_id(&self, /* out, retval */ navigation_id: *mut u64) -> HRESULT;
3047}
3048
3049/// Receives `NavigationCompleted` events.
3050#[com_interface("d33a35bf-1c49-4f98-93ab-006e0533fe1c")]
3051pub trait ICoreWebView2NavigationCompletedEventHandler: IUnknown {
3052 /// Provides the event args for the corresponding event.
3053 unsafe fn invoke(
3054 &self,
3055 /* in */ sender: *mut *mut ICoreWebView2VTable,
3056 /* in */ args: *mut *mut ICoreWebView2NavigationCompletedEventArgsVTable,
3057 ) -> HRESULT;
3058}
3059
3060/// Event args for the `PermissionRequested` event.
3061#[com_interface("973ae2ef-ff18-4894-8fb2-3c758f046810")]
3062pub trait ICoreWebView2PermissionRequestedEventArgs: IUnknown {
3063 /// The origin of the web content that requests the permission.
3064 unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;
3065
3066 /// The type of the permission that is requested.
3067 unsafe fn get_permission_kind(
3068 &self,
3069 /* out, retval */ permission_kind: *mut PermissionKind,
3070 ) -> HRESULT;
3071
3072 /// `TRUE` when the permission request was initiated through a user gesture.
3073 ///
3074 /// \> [!NOTE]\n\> Being initiated through a user gesture does not mean that user intended
3075 /// to access the associated resource.
3076 unsafe fn get_is_user_initiated(
3077 &self,
3078 /* out, retval */ is_user_initiated: *mut BOOL,
3079 ) -> HRESULT;
3080
3081 /// The status of a permission request, (for example is the request is granted).
3082 /// The default value is `COREWEBVIEW2_PERMISSION_STATE_DEFAULT`.
3083 unsafe fn get_state(&self, /* out, retval */ state: *mut PermissionState) -> HRESULT;
3084
3085 /// Sets the `State` property.
3086 unsafe fn put_state(&self, /* in */ state: PermissionState) -> HRESULT;
3087
3088 /// Gets an `ICoreWebView2Deferral` object. Use the deferral object to make
3089 /// the permission decision at a later time.
3090 unsafe fn get_deferral(
3091 &self,
3092 /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
3093 ) -> HRESULT;
3094}
3095
3096/// Receives `PermissionRequested` events.
3097#[com_interface("15e1c6a3-c72a-4df3-91d7-d097fbec6bfd")]
3098pub trait ICoreWebView2PermissionRequestedEventHandler: IUnknown {
3099 /// Provides the event args for the corresponding event.
3100 unsafe fn invoke(
3101 &self,
3102 /* in */ sender: *mut *mut ICoreWebView2VTable,
3103 /* in */ args: *mut *mut ICoreWebView2PermissionRequestedEventArgsVTable,
3104 ) -> HRESULT;
3105}
3106
3107/// Receives the result of the `AddScriptToExecuteOnDocumentCreated` method.
3108#[com_interface("b99369f3-9b11-47b5-bc6f-8e7895fcea17")]
3109pub trait ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler: IUnknown {
3110 /// Provide the completion status and result of the corresponding
3111 /// asynchronous method.
3112 unsafe fn invoke(
3113 &self,
3114 /* in */ error_code: HRESULT,
3115 /* in */ id: LPCWSTR,
3116 ) -> HRESULT;
3117}
3118
3119/// Receives the result of the `ExecuteScript` method.
3120#[com_interface("49511172-cc67-4bca-9923-137112f4c4cc")]
3121pub trait ICoreWebView2ExecuteScriptCompletedHandler: IUnknown {
3122 /// Provide the implementer with the completion status and result of the
3123 /// corresponding asynchronous method.
3124 unsafe fn invoke(
3125 &self,
3126 /* in */ error_code: HRESULT,
3127 /* in */ result_object_as_json: LPCWSTR,
3128 ) -> HRESULT;
3129}
3130
3131/// Event args for the `WebResourceRequested` event.
3132#[com_interface("453e667f-12c7-49d4-be6d-ddbe7956f57a")]
3133pub trait ICoreWebView2WebResourceRequestedEventArgs: IUnknown {
3134 /// The Web resource request. The request object may be missing some headers
3135 /// that are added by network stack at a later time.
3136 unsafe fn get_request(
3137 &self,
3138 /* out, retval */ request: *mut *mut *mut ICoreWebView2WebResourceRequestVTable,
3139 ) -> HRESULT;
3140
3141 /// A placeholder for the web resource response object. If this object is
3142 /// set, the web resource request is completed with the specified response.
3143 unsafe fn get_response(
3144 &self,
3145 /* out, retval */ response: *mut *mut *mut ICoreWebView2WebResourceResponseVTable,
3146 ) -> HRESULT;
3147
3148 /// Sets the `Response` property. Create an empty web resource response
3149 /// object with `CreateWebResourceResponse` and then modify it to construct
3150 /// the response.
3151 unsafe fn put_response(
3152 &self,
3153 /* in */ response: *mut *mut ICoreWebView2WebResourceResponseVTable,
3154 ) -> HRESULT;
3155
3156 /// Obtain an `ICoreWebView2Deferral` object and put the event into a
3157 /// deferred state. Use the `ICoreWebView2Deferral` object to complete the
3158 /// request at a later time.
3159 unsafe fn get_deferral(
3160 &self,
3161 /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
3162 ) -> HRESULT;
3163
3164 /// The web resource request context.
3165 unsafe fn get_resource_context(
3166 &self,
3167 /* out, retval */ context: *mut WebResourceContext,
3168 ) -> HRESULT;
3169}
3170
3171/// Runs when a URL request (through network, file, and so on) is made in
3172/// the webview for a Web resource matching resource context filter and URL
3173/// specified in `AddWebResourceRequestedFilter`. The host views and modifies
3174/// the request or provide a response in a similar pattern to HTTP, in which
3175/// case the request immediately completed. This may not contain any request
3176/// headers that are added by the network stack, such as an `Authorization`
3177/// header.
3178#[com_interface("ab00b74c-15f1-4646-80e8-e76341d25d71")]
3179pub trait ICoreWebView2WebResourceRequestedEventHandler: IUnknown {
3180 /// Provides the event args for the corresponding event.
3181 unsafe fn invoke(
3182 &self,
3183 /* in */ sender: *mut *mut ICoreWebView2VTable,
3184 /* in */ args: *mut *mut ICoreWebView2WebResourceRequestedEventArgsVTable,
3185 ) -> HRESULT;
3186}
3187
3188/// Receives the result of the `CapturePreview` method. The result is written
3189/// to the stream provided in the `CapturePreview` method.
3190#[com_interface("697e05e9-3d8f-45fa-96f4-8ffe1ededaf5")]
3191pub trait ICoreWebView2CapturePreviewCompletedHandler: IUnknown {
3192 /// Provides the completion status of the corresponding asynchronous method.
3193 unsafe fn invoke(&self, /* in */ error_code: HRESULT) -> HRESULT;
3194}
3195
3196/// Receives `GotFocus` and `LostFocus` events.
3197#[com_interface("05ea24bd-6452-4926-9014-4b82b498135d")]
3198pub trait ICoreWebView2FocusChangedEventHandler: IUnknown {
3199 /// Provides the event args for the corresponding event. No event args exist
3200 /// and the `args` parameter is set to `null`.
3201 unsafe fn invoke(
3202 &self,
3203 /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
3204 /* in */ args: *mut *mut IUnknownVTable,
3205 ) -> HRESULT;
3206}
3207
3208/// Event args for the `MoveFocusRequested` event.
3209#[com_interface("2d6aa13b-3839-4a15-92fc-d88b3c0d9c9d")]
3210pub trait ICoreWebView2MoveFocusRequestedEventArgs: IUnknown {
3211 /// The reason for WebView to run the `MoveFocusRequested` event.
3212 unsafe fn get_reason(&self, /* out, retval */ reason: *mut MoveFocusReason) -> HRESULT;
3213
3214 /// Indicates whether the event has been handled by the app. If the app has
3215 /// moved the focus to another desired location, it should set the `Handled`
3216 /// property to `TRUE`. When the `Handled` property is `FALSE` after the
3217 /// event handler returns, default action is taken. The default action is to
3218 /// try to find the next tab stop child window in the app and try to move
3219 /// focus to that window. If no other window exists to move focus, focus is
3220 /// cycled within the web content of the WebView.
3221 unsafe fn get_handled(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;
3222
3223 /// Sets the `Handled` property.
3224 unsafe fn put_handled(&self, /* in */ value: BOOL) -> HRESULT;
3225}
3226
3227/// Receives `MoveFocusRequested` events.
3228#[com_interface("69035451-6dc7-4cb8-9bce-b2bd70ad289f")]
3229pub trait ICoreWebView2MoveFocusRequestedEventHandler: IUnknown {
3230 /// Provides the event args for the corresponding event.
3231 unsafe fn invoke(
3232 &self,
3233 /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
3234 /* in */ args: *mut *mut ICoreWebView2MoveFocusRequestedEventArgsVTable,
3235 ) -> HRESULT;
3236}
3237
3238/// Event args for the `WebMessageReceived` event.
3239#[com_interface("0f99a40c-e962-4207-9e92-e3d542eff849")]
3240pub trait ICoreWebView2WebMessageReceivedEventArgs: IUnknown {
3241 /// The URI of the document that sent this web message.
3242 unsafe fn get_source(&self, /* out, retval */ source: *mut LPWSTR) -> HRESULT;
3243
3244 /// The message posted from the WebView content to the host converted to a
3245 /// JSON string. Run this operation to communicate using JavaScript objects.
3246 ///
3247 /// For example, the following `postMessage` runs result in the following
3248 /// `WebMessageAsJson` values.
3249 ///
3250 /// ```json
3251 /// postMessage({'a': 'b'}) L"{\"a\": \"b\"}"
3252 /// postMessage(1.2) L"1.2"
3253 /// postMessage('example') L"\"example\""
3254 /// ```
3255 unsafe fn get_web_message_as_json(
3256 &self,
3257 /* out, retval */ web_message_as_json: *mut LPWSTR,
3258 ) -> HRESULT;
3259
3260 /// If the message posted from the WebView content to the host is a string
3261 /// type, this method returns the value of that string. If the message
3262 /// posted is some other kind of JavaScript type this method fails with the
3263 /// following error.
3264 ///
3265 /// ```text
3266 /// E_INVALIDARG
3267 /// ```
3268 ///
3269 /// Run this operation to communicate using simple strings.
3270 ///
3271 /// For example, the following `postMessage` runs result in the following
3272 /// `WebMessageAsString` values.
3273 ///
3274 /// ```json
3275 /// postMessage({'a': 'b'}) E_INVALIDARG
3276 /// postMessage(1.2) E_INVALIDARG
3277 /// postMessage('example') L"example"
3278 /// ```
3279 unsafe fn try_get_web_message_as_string(
3280 &self,
3281 /* out, retval */ web_message_as_string: *mut LPWSTR,
3282 ) -> HRESULT;
3283}
3284
3285/// Receives `WebMessageReceived` events.
3286#[com_interface("57213f19-00e6-49fa-8e07-898ea01ecbd2")]
3287pub trait ICoreWebView2WebMessageReceivedEventHandler: IUnknown {
3288 /// Provides the event args for the corresponding event.
3289 unsafe fn invoke(
3290 &self,
3291 /* in */ sender: *mut *mut ICoreWebView2VTable,
3292 /* in */ args: *mut *mut ICoreWebView2WebMessageReceivedEventArgsVTable,
3293 ) -> HRESULT;
3294}
3295
3296/// Event args for the `DevToolsProtocolEventReceived` event.
3297#[com_interface("653c2959-bb3a-4377-8632-b58ada4e66c4")]
3298pub trait ICoreWebView2DevToolsProtocolEventReceivedEventArgs: IUnknown {
3299 /// The parameter object of the corresponding `DevToolsProtocol` event
3300 /// represented as a JSON string.
3301 unsafe fn get_parameter_object_as_json(
3302 &self,
3303 /* out, retval */ parameter_object_as_json: *mut LPWSTR,
3304 ) -> HRESULT;
3305}
3306
3307/// Receives `DevToolsProtocolEventReceived` events from the WebView.
3308#[com_interface("e2fda4be-5456-406c-a261-3d452138362c")]
3309pub trait ICoreWebView2DevToolsProtocolEventReceivedEventHandler: IUnknown {
3310 /// Provides the event args for the corresponding event.
3311 unsafe fn invoke(
3312 &self,
3313 /* in */ sender: *mut *mut ICoreWebView2VTable,
3314 /* in */ args: *mut *mut ICoreWebView2DevToolsProtocolEventReceivedEventArgsVTable,
3315 ) -> HRESULT;
3316}
3317
3318/// Receives `CallDevToolsProtocolMethod` completion results.
3319#[com_interface("5c4889f0-5ef6-4c5a-952c-d8f1b92d0574")]
3320pub trait ICoreWebView2CallDevToolsProtocolMethodCompletedHandler: IUnknown {
3321 /// Provides the completion status and result of the corresponding
3322 /// asynchronous method.
3323 unsafe fn invoke(
3324 &self,
3325 /* in */ error_code: HRESULT,
3326 /* in */ return_object_as_json: LPCWSTR,
3327 ) -> HRESULT;
3328}
3329
3330/// Receives the `CoreWebView2Controller` created using `CreateCoreWebView2Controller`.
3331#[com_interface("6c4819f3-c9b7-4260-8127-c9f5bde7f68c")]
3332pub trait ICoreWebView2CreateCoreWebView2ControllerCompletedHandler: IUnknown {
3333 /// Provides the completion status and result of the corresponding
3334 /// asynchronous method.
3335 unsafe fn invoke(
3336 &self,
3337 error_code: HRESULT,
3338 created_controller: *mut *mut ICoreWebView2ControllerVTable,
3339 ) -> HRESULT;
3340}
3341
3342/// The caller implements this interface to receive the CoreWebView2Controller
3343/// created via CreateCoreWebView2CompositionController.
3344#[com_interface("02fab84b-1428-4fb7-ad45-1b2e64736184")]
3345pub trait ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler: IUnknown {
3346 /// Called to provide the implementer with the completion status and result
3347 /// of the corresponding asynchronous method call.
3348 unsafe fn invoke(
3349 &self,
3350 error_code: HRESULT,
3351 web_view: *mut *mut ICoreWebView2CompositionControllerVTable,
3352 ) -> HRESULT;
3353}
3354
3355/// Event args for the `NewWindowRequested` event. The event is run when
3356/// content inside webview requested to a open a new window (through
3357/// `window.open()` and so on).
3358#[com_interface("34acb11c-fc37-4418-9132-f9c21d1eafb9")]
3359pub trait ICoreWebView2NewWindowRequestedEventArgs: IUnknown {
3360 /// The target uri of the new window requested.
3361 unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;
3362
3363 /// Sets a CoreWebView2 as a result of the NewWindowRequested event. If the
3364 /// `NewWindow` is set, the top-level window returns as the opened `WindowProxy`.
3365 /// The NewWindow property should be set to a CoreWebView2 that has not been
3366 /// navigated previously. Don't use methods that cause navigation or interact
3367 /// with the DOM on this CoreWebView2. Setting event handlers, changing
3368 /// Settings properties, or other methods are fine to call. Once the
3369 /// NewWindow is set the underlying web contents of this CoreWebView2 will be
3370 /// replaced and navigated as appropriate for the new window.
3371 /// After setting new window it cannot be changed and error will be return otherwise.
3372 ///
3373 /// The methods which should affect the new web contents like
3374 /// AddScriptToExecuteOnDocumentCreated and add_WebResourceRequested
3375 /// have to be called after setting NewWindow.
3376 unsafe fn put_new_window(
3377 &self,
3378 /* in */ new_window: *mut *mut ICoreWebView2VTable,
3379 ) -> HRESULT;
3380
3381 /// Gets the new window.
3382 unsafe fn get_new_window(
3383 &self,
3384 /* out, retval */ new_window: *mut *mut *mut ICoreWebView2VTable,
3385 ) -> HRESULT;
3386
3387 /// Sets whether the `NewWindowRequested` event is handled by host. If this
3388 /// is `FALSE` and no `NewWindow` is set, the WebView opens a popup window
3389 /// and it returns as opened `WindowProxy`. If set to `TRUE` and no
3390 /// `NewWindow` is set for `window.open`, the opened `WindowProxy` is for an
3391 /// testing window object and no window loads.
3392 /// The default value is `FALSE`.
3393 unsafe fn put_handled(&self, /* in */ handled: BOOL) -> HRESULT;
3394
3395 /// Gets whether the `NewWindowRequested` event is handled by host.
3396 unsafe fn get_handled(&self, /* out, retval */ handled: *mut BOOL) -> HRESULT;
3397
3398 /// `TRUE` when the new window request was initiated through a user gesture
3399 /// such as selecting an anchor tag with target. The Microsoft Edge popup
3400 /// blocker is disabled for WebView so the app is able to use this flag to
3401 /// block non-user initiated popups.
3402 unsafe fn get_is_user_initiated(
3403 &self,
3404 /* out, retval */ is_user_initiated: *mut BOOL,
3405 ) -> HRESULT;
3406
3407 /// Obtain an `ICoreWebView2Deferral` object and put the event into a
3408 /// deferred state. Use the `ICoreWebView2Deferral` object to complete the
3409 /// window open request at a later time. While this event is deferred the
3410 /// opener window returns a `WindowProxy` to an un-navigated window, which
3411 /// navigates when the deferral is complete.
3412 unsafe fn get_deferral(
3413 &self,
3414 /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
3415 ) -> HRESULT;
3416
3417 /// Window features specified by the `window.open`. The features should be
3418 /// considered for positioning and sizing of new webview windows.
3419 unsafe fn get_window_features(
3420 &self,
3421 /* out, retval */ value: *mut *mut *mut ICoreWebView2WindowFeaturesVTable,
3422 ) -> HRESULT;
3423}
3424
3425/// The window features for a WebView popup window. The fields match the
3426/// `windowFeatures` passed to `window.open` as specified in
3427/// \[Window features\]\[MdnDocsWebApiWindowOpenWindowFeatures\]
3428/// on MDN.
3429/// There is no requirement for you to respect the values. If your app does
3430/// not have corresponding UI features (for example, no toolbar) or if all
3431/// instance of WebView are opened in tabs and do not have distinct size or
3432/// positions, then your app does not respect the values. You may want to
3433/// respect values, but perhaps only some apply to the UI of you app.
3434/// Accordingly, you may respect all, some, or none of the properties as
3435/// appropriate for your app. For all numeric properties, if the value that is
3436/// passed to `window.open` is outside the range of an unsigned 32bit int, the
3437/// resulting value is the absolute value of the maximum for unsigned 32bit
3438/// integer. If you are not able to parse the value an integer, it is
3439/// considered `0`. If the value is a floating point value, it is rounded down
3440/// to an integer.
3441///
3442/// \[MdnDocsWebApiWindowOpenWindowFeatures\]: https://developer.mozilla.org/docs/Web/API/Window/open#Window_features "Window features - Window.open() | MDN"
3443#[com_interface("5eaf559f-b46e-4397-8860-e422f287ff1e")]
3444pub trait ICoreWebView2WindowFeatures: IUnknown {
3445 /// Specifies left and top values.
3446 unsafe fn get_has_position(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;
3447
3448 /// Specifiesheight and width values.
3449 unsafe fn get_has_size(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;
3450
3451 /// Specifies the left position of the window. If `HasPosition` is set to
3452 /// `FALSE`, this field is ignored.
3453 unsafe fn get_left(&self, /* out, retval */ value: *mut u32) -> HRESULT;
3454
3455 /// Specifies the top position of the window. If `HasPosition` is set to
3456 /// `FALSE`, this field is ignored.
3457 unsafe fn get_top(&self, /* out, retval */ value: *mut u32) -> HRESULT;
3458
3459 /// Specifies the height of the window. Minimum value is `100`. If
3460 /// `HasSize` is set to `FALSE`, this field is ignored.
3461 unsafe fn get_height(&self, /* out, retval */ value: *mut u32) -> HRESULT;
3462
3463 /// Specifies the width of the window. Minimum value is `100`. If `HasSize`
3464 /// is set to `FALSE`, this field is ignored.
3465 unsafe fn get_width(&self, /* out, retval */ value: *mut u32) -> HRESULT;
3466
3467 /// Indicates that the menu bar is displayed.
3468 unsafe fn get_should_display_menu_bar(
3469 &self,
3470 /* out, retval */ value: *mut BOOL,
3471 ) -> HRESULT;
3472
3473 /// Indicates that the status bar is displayed.
3474 unsafe fn get_should_display_status(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;
3475
3476 /// Indicates that the browser toolbar is displayed.
3477 unsafe fn get_should_display_toolbar(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;
3478
3479 /// Indicates that the scroll bars are displayed.
3480 unsafe fn get_should_display_scroll_bars(
3481 &self,
3482 /* out, retval */ value: *mut BOOL,
3483 ) -> HRESULT;
3484}
3485
3486/// Receives `NewWindowRequested` events.
3487#[com_interface("d4c185fe-c81c-4989-97af-2d3fa7ab5651")]
3488pub trait ICoreWebView2NewWindowRequestedEventHandler: IUnknown {
3489 /// Provides the event args for the corresponding event.
3490 unsafe fn invoke(
3491 &self,
3492 /* in */ sender: *mut *mut ICoreWebView2VTable,
3493 /* in */ args: *mut *mut ICoreWebView2NewWindowRequestedEventArgsVTable,
3494 ) -> HRESULT;
3495}
3496
3497/// Receives `DocumentTitleChanged` events. Use the `DocumentTitle` property
3498/// to get the modified title.
3499#[com_interface("f5f2b923-953e-4042-9f95-f3a118e1afd4")]
3500pub trait ICoreWebView2DocumentTitleChangedEventHandler: IUnknown {
3501 /// Provides the event args for the corresponding event. No event args exist
3502 /// and the `args` parameter is set to `null`.
3503 unsafe fn invoke(
3504 &self,
3505 /* in */ sender: *mut *mut ICoreWebView2VTable,
3506 /* in */ args: *mut *mut IUnknownVTable,
3507 ) -> HRESULT;
3508}
3509
3510/// Event args for the `AcceleratorKeyPressed` event.
3511#[com_interface("9f760f8a-fb79-42be-9990-7b56900fa9c7")]
3512pub trait ICoreWebView2AcceleratorKeyPressedEventArgs: IUnknown {
3513 /// The key event type that caused the event to run.
3514 unsafe fn get_key_event_kind(
3515 &self,
3516 /* out, retval */ key_event_kind: *mut KeyEventKind,
3517 ) -> HRESULT;
3518
3519 /// The Win32 virtual key code of the key that was pressed or released. It
3520 /// is one of the Win32 virtual key constants such as `VK_RETURN` or an
3521 /// (uppercase) ASCII value such as `A`. Verify whether Ctrl or Alt
3522 /// are pressed by running `GetKeyState(VK_CONTROL)` or
3523 /// `GetKeyState(VK_MENU)`.
3524 unsafe fn get_virtual_key(&self, /* out, retval */ virtual_key: *mut u32) -> HRESULT;
3525
3526 /// The `LPARAM` value that accompanied the window message. For more
3527 /// information, navigate to
3528 /// \[WM_KEYDOWN\]\[WindowsWin32InputdevWmKeydown\]
3529 /// and
3530 /// \[WM_KEYUP\]\[WindowsWin32InputdevWmKeyup\].
3531 ///
3532 /// \[WindowsWin32InputdevWmKeydown\]: /windows/win32/inputdev/wm-keydown "WM_KEYDOWN message | Microsoft Docs"
3533 ///
3534 /// \[WindowsWin32InputdevWmKeyup\]: /windows/win32/inputdev/wm-keyup "WM_KEYUP message | Microsoft Docs"
3535 unsafe fn get_key_event_lparam(&self, /* out, retval */ l_param: *mut i32) -> HRESULT;
3536
3537 /// A structure representing the information passed in the `LPARAM` of the
3538 /// window message.
3539 unsafe fn get_physical_key_status(
3540 &self,
3541 /* out, retval */ physical_key_status: *mut PhysicalKeyStatus,
3542 ) -> HRESULT;
3543
3544 /// During `AcceleratorKeyPressedEvent` handler invocation the WebView is
3545 /// blocked waiting for the decision of if the accelerator is handled by the
3546 /// host (or not). If the `Handled` property is set to `TRUE` then this
3547 /// prevents the WebView from performing the default action for this
3548 /// accelerator key. Otherwise the WebView performs the default action for
3549 /// the accelerator key.
3550 unsafe fn get_handled(&self, /* out, retval */ handled: *mut BOOL) -> HRESULT;
3551
3552 /// Sets the `Handled` property.
3553 unsafe fn put_handled(&self, /* in */ handled: BOOL) -> HRESULT;
3554}
3555
3556/// Receives `AcceleratorKeyPressed` events.
3557#[com_interface("b29c7e28-fa79-41a8-8e44-65811c76dcb2")]
3558pub trait ICoreWebView2AcceleratorKeyPressedEventHandler: IUnknown {
3559 /// Provides the event args for the corresponding event.
3560 unsafe fn invoke(
3561 &self,
3562 /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
3563 /* in */ args: *mut *mut ICoreWebView2AcceleratorKeyPressedEventArgsVTable,
3564 ) -> HRESULT;
3565}
3566
3567/// Receives `NewBrowserVersionAvailable` events.
3568#[com_interface("f9a2976e-d34e-44fc-adee-81b6b57ca914")]
3569pub trait ICoreWebView2NewBrowserVersionAvailableEventHandler: IUnknown {
3570 /// Provides the event args for the corresponding event.
3571 unsafe fn invoke(
3572 &self,
3573 /* in */ sender: *mut *mut ICoreWebView2EnvironmentVTable,
3574 /* in */ args: *mut *mut IUnknownVTable,
3575 ) -> HRESULT;
3576}
3577
3578/// Receives `ContainsFullScreenElementChanged` events.
3579#[com_interface("e45d98b1-afef-45be-8baf-6c7728867f73")]
3580pub trait ICoreWebView2ContainsFullScreenElementChangedEventHandler: IUnknown {
3581 /// Provides the event args for the corresponding event. No event args exist
3582 /// and the `args` parameter is set to `null`.
3583 unsafe fn invoke(
3584 &self,
3585 /* in */ sender: *mut *mut ICoreWebView2VTable,
3586 /* in */ args: *mut *mut IUnknownVTable,
3587 ) -> HRESULT;
3588}
3589
3590/// Receives `WindowCloseRequested` events.
3591#[com_interface("5c19e9e0-092f-486b-affa-ca8231913039")]
3592pub trait ICoreWebView2WindowCloseRequestedEventHandler: IUnknown {
3593 /// Provides the event args for the corresponding event. No event args exist
3594 /// and the `args` parameter is set to `null`.
3595 unsafe fn invoke(
3596 &self,
3597 /* in */ sender: *mut *mut ICoreWebView2VTable,
3598 /* in */ args: *mut *mut IUnknownVTable,
3599 ) -> HRESULT;
3600}
3601
3602/// Receives `WebResourceResponseReceived` events.
3603#[com_interface("7DE9898A-24F5-40C3-A2DE-D4F458E69828")]
3604pub trait ICoreWebView2WebResourceResponseReceivedEventHandler: IUnknown {
3605 /// Provides the event args for the corresponding event.
3606 unsafe fn invoke(
3607 &self,
3608 /* in */ sender: *mut *mut ICoreWebView2VTable,
3609 /* in */ args: *mut *mut ICoreWebView2WebResourceResponseReceivedEventArgsVTable,
3610 ) -> HRESULT;
3611}
3612
3613/// Event args for the WebResourceResponseReceived event.
3614#[com_interface("D1DB483D-6796-4B8B-80FC-13712BB716F4")]
3615pub trait ICoreWebView2WebResourceResponseReceivedEventArgs: IUnknown {
3616 /// The request object for the web resource, as committed. This includes
3617 /// headers added by the network stack that were not be included during the
3618 /// associated WebResourceRequested event, such as Authentication headers.
3619 /// Modifications to this object have no effect on how the request is
3620 /// processed as it has already been sent.
3621 unsafe fn get_request(
3622 &self,
3623 /* out, retval */ request: *mut *mut *mut ICoreWebView2WebResourceRequestVTable,
3624 ) -> HRESULT;
3625
3626 /// View of the response object received for the web resource.
3627 unsafe fn get_response(
3628 &self,
3629 /* out, retval */
3630 response: *mut *mut *mut ICoreWebView2WebResourceResponseViewVTable,
3631 ) -> HRESULT;
3632}
3633
3634/// View of the HTTP representation for a web resource response. The properties
3635/// of this object are not mutable. This response view is used with the
3636/// WebResourceResponseReceived event.
3637#[com_interface("79701053-7759-4162-8F7D-F1B3F084928D")]
3638pub trait ICoreWebView2WebResourceResponseView: IUnknown {
3639 /// The HTTP response headers as received.
3640 unsafe fn get_headers(
3641 &self,
3642 /* out, retval */ headers: *mut *mut *mut ICoreWebView2HttpResponseHeadersVTable,
3643 ) -> HRESULT;
3644
3645 /// The HTTP response status code.
3646 unsafe fn get_status_code(&self, /* out, retval */ status_code: *mut i32) -> HRESULT;
3647
3648 /// The HTTP response reason phrase.
3649 unsafe fn get_reason_phrase(
3650 &self,
3651 /* out, retval */ reason_phrase: *mut LPWSTR,
3652 ) -> HRESULT;
3653
3654 /// Get the response content asynchronously. The handler will receive the
3655 /// response content stream.
3656 /// If this method is being called again before a first call has completed,
3657 /// the handler will be invoked at the same time the handlers from prior calls
3658 /// are invoked.
3659 /// If this method is being called after a first call has completed, the
3660 /// handler will be invoked immediately.
3661 /// \snippet ScenarioWebViewEventMonitor.cpp GetContent
3662 unsafe fn get_content(
3663 &self,
3664 /* in */
3665 handler: *mut *mut ICoreWebView2WebResourceResponseViewGetContentCompletedHandlerVTable,
3666 ) -> HRESULT;
3667}
3668
3669/// Receives the result of the
3670/// `ICoreWebView2WebResourceResponseView::GetContent` method.
3671#[com_interface("875738E1-9FA2-40E3-8B74-2E8972DD6FE7")]
3672pub trait ICoreWebView2WebResourceResponseViewGetContentCompletedHandler: IUnknown {
3673 /// Provides the completion status and result of the corresponding
3674 /// asynchronous method call. A failure `errorCode` will be passed if the
3675 /// content failed to load. `E_ABORT` means the response loading was blocked
3676 /// (e.g., by CORS policy); `ERROR_CANCELLED` means the response loading was
3677 /// cancelled. `ERROR_NO_DATA` means the response has no content data,
3678 /// `content` is `null` in this case. Note content (if any) is ignored for
3679 /// redirects, 204 No Content, 205 Reset Content, and HEAD-request responses.
3680 unsafe fn invoke(
3681 &self,
3682 /* in */ error_code: HRESULT,
3683 /* in */ content: *mut *mut IStreamVTable,
3684 ) -> HRESULT;
3685}
3686
3687/// Event args for the DOMContentLoaded event.
3688#[com_interface("16B1E21A-C503-44F2-84C9-70ABA5031283")]
3689pub trait ICoreWebView2DOMContentLoadedEventArgs: IUnknown {
3690 /// The ID of the navigation which corresponds to other navigation ID properties on other navigation events.
3691 unsafe fn get_navigation_id(&self, /* out, retval */ navigation_id: *mut u64) -> HRESULT;
3692}
3693
3694/// Receives `DOMContentLoaded` events.
3695#[com_interface("4BAC7E9C-199E-49ED-87ED-249303ACF019")]
3696pub trait ICoreWebView2DOMContentLoadedEventHandler: IUnknown {
3697 /// Provides the event args for the corresponding event.
3698 unsafe fn invoke(
3699 &self,
3700 /* in */ sender: *mut *mut ICoreWebView2VTable,
3701 /* in */ args: *mut *mut ICoreWebView2DOMContentLoadedEventArgsVTable,
3702 ) -> HRESULT;
3703}
3704
3705/// Provides a set of properties that are used to manage an
3706/// ICoreWebView2Cookie.
3707///
3708/// \snippet ScenarioCookieManagement.cpp CookieObject
3709#[com_interface("AD26D6BE-1486-43E6-BF87-A2034006CA21")]
3710pub trait ICoreWebView2Cookie: IUnknown {
3711 /// Cookie name.
3712 unsafe fn get_name(&self, /* out, retval */ name: *mut LPWSTR) -> HRESULT;
3713
3714 /// Cookie value.
3715 unsafe fn get_value(&self, /* out, retval */ value: *mut LPWSTR) -> HRESULT;
3716
3717 /// Set the cookie value property.
3718 unsafe fn put_value(&self, /* in */ value: LPCWSTR) -> HRESULT;
3719
3720 /// The domain for which the cookie is valid.
3721 /// The default is the host that this cookie has been received from.
3722 /// Note that, for instance, ".bing.com", "bing.com", and "www.bing.com" are
3723 /// considered different domains.
3724 unsafe fn get_domain(&self, /* out, retval */ domain: *mut LPWSTR) -> HRESULT;
3725
3726 /// The path for which the cookie is valid. The default is "/", which means
3727 /// this cookie will be sent to all pages on the Domain.
3728 unsafe fn get_path(&self, /* out, retval */ path: *mut LPWSTR) -> HRESULT;
3729
3730 /// The expiration date and time for the cookie as the number of seconds since the UNIX epoch.
3731 /// The default is -1.0, which means cookies are session cookies by default.
3732 unsafe fn get_expires(&self, /* out, retval */ expires: *mut f64) -> HRESULT;
3733
3734 /// Set the Expires property. Cookies are session cookies and will not be
3735 /// persistent if Expires is set to -1.0. NaN, infinity, and any negative
3736 /// value set other than -1.0 is disallowed.
3737 unsafe fn put_expires(&self, /* in */ expires: f64) -> HRESULT;
3738
3739 /// Whether this cookie is http-only.
3740 /// True if a page script or other active content cannot access this
3741 /// cookie. The default is false.
3742 unsafe fn get_is_http_only(&self, /* out, retval */ is_http_only: *mut BOOL) -> HRESULT;
3743
3744 /// Set the IsHttpOnly property.
3745 unsafe fn put_is_http_only(&self, /* in */ is_http_only: BOOL) -> HRESULT;
3746
3747 /// SameSite status of the cookie which represents the enforcement mode of the cookie.
3748 /// The default is COREWEBVIEW2_COOKIE_SAME_SITE_KIND_LAX.
3749 unsafe fn get_same_site(
3750 &self,
3751 /* out, retval */ same_site: *mut CookieSameSiteKind,
3752 ) -> HRESULT;
3753
3754 /// Set the SameSite property.
3755 unsafe fn put_same_site(&self, /* in */ same_site: CookieSameSiteKind) -> HRESULT;
3756
3757 /// The security level of this cookie. True if the client is only to return
3758 /// the cookie in subsequent requests if those requests use HTTPS.
3759 /// The default is false.
3760 /// Note that cookie that requests COREWEBVIEW2_COOKIE_SAME_SITE_KIND_NONE but
3761 /// is not marked Secure will be rejected.
3762 unsafe fn get_is_secure(&self, /* out, retval */ is_secure: *mut BOOL) -> HRESULT;
3763
3764 /// Set the IsSecure property.
3765 unsafe fn put_is_secure(&self, /* in */ is_secure: BOOL) -> HRESULT;
3766
3767 /// Whether this is a session cookie. The default is false.
3768 unsafe fn get_is_session(&self, /* out, retval */ is_session: *mut BOOL) -> HRESULT;
3769}
3770
3771/// Creates, adds or updates, gets, or or view the cookies. The changes would
3772/// apply to the context of the user profile. That is, other WebViews under the
3773/// same user profile could be affected.
3774#[com_interface("177CD9E7-B6F5-451A-94A0-5D7A3A4C4141")]
3775pub trait ICoreWebView2CookieManager: IUnknown {
3776 /// Create a cookie object with a specified name, value, domain, and path.
3777 /// One can set other optional properties after cookie creation.
3778 /// This only creates a cookie object and it is not added to the cookie
3779 /// manager until you call AddOrUpdateCookie.
3780 /// Leading or trailing whitespace(s), empty string, and special characters
3781 /// are not allowed for name.
3782 /// See ICoreWebView2Cookie for more details.
3783 unsafe fn create_cookie(
3784 &self,
3785 /* in */ name: LPCWSTR,
3786 /* in */ value: LPCWSTR,
3787 /* in */ domain: LPCWSTR,
3788 /* in */ path: LPCWSTR,
3789 /* out, retval */ cookie: *mut *mut *mut ICoreWebView2CookieVTable,
3790 ) -> HRESULT;
3791
3792 /// Creates a cookie whose params matches those of the specified cookie.
3793 unsafe fn copy_cookie(
3794 &self,
3795 /* in */ cookie_param: *mut *mut ICoreWebView2CookieVTable,
3796 /* out, retval */ cookie: *mut *mut *mut ICoreWebView2CookieVTable,
3797 ) -> HRESULT;
3798
3799 /// Gets a list of cookies matching the specific URI.
3800 /// If uri is empty string or null, all cookies under the same profile are
3801 /// returned.
3802 /// You can modify the cookie objects by calling
3803 /// ICoreWebView2CookieManager::AddOrUpdateCookie, and the changes
3804 /// will be applied to the webview.
3805 /// \snippet ScenarioCookieManagement.cpp GetCookies
3806 unsafe fn get_cookies(
3807 &self,
3808 /* in */ uri: LPCWSTR,
3809 /* in */ handler: *mut *mut ICoreWebView2GetCookiesCompletedHandlerVTable,
3810 ) -> HRESULT;
3811
3812 /// Adds or updates a cookie with the given cookie data; may overwrite
3813 /// cookies with matching name, domain, and path if they exist.
3814 /// This method will fail if the domain of the given cookie is not specified.
3815 /// \snippet ScenarioCookieManagement.cpp AddOrUpdateCookie
3816 unsafe fn add_or_update_cookie(
3817 &self,
3818 /* in */ cookie: *mut *mut ICoreWebView2CookieVTable,
3819 ) -> HRESULT;
3820
3821 /// Deletes a cookie whose name and domain/path pair
3822 /// match those of the specified cookie.
3823 unsafe fn delete_cookie(
3824 &self,
3825 /* in */ cookie: *mut *mut ICoreWebView2CookieVTable,
3826 ) -> HRESULT;
3827
3828 /// Deletes cookies with matching name and uri.
3829 /// Cookie name is required.
3830 /// All cookies with the given name where domain
3831 /// and path match provided URI are deleted.
3832 unsafe fn delete_cookies(
3833 &self,
3834 /* in */ name: LPCWSTR,
3835 /* in */ uri: LPCWSTR,
3836 ) -> HRESULT;
3837
3838 /// Deletes cookies with matching name and domain/path pair.
3839 /// Cookie name is required.
3840 /// If domain is specified, deletes only cookies with the exact domain.
3841 /// If path is specified, deletes only cookies with the exact path.
3842 unsafe fn delete_cookies_with_domain_and_path(
3843 &self,
3844 /* in */ name: LPCWSTR,
3845 /* in */ domain: LPCWSTR,
3846 /* in */ path: LPCWSTR,
3847 ) -> HRESULT;
3848
3849 /// Deletes all cookies under the same profile.
3850 /// This could affect other WebViews under the same user profile.
3851 unsafe fn delete_all_cookies(&self) -> HRESULT;
3852}
3853
3854/// A list of cookie objects. See `ICoreWebView2Cookie`.
3855/// \snippet ScenarioCookieManagement.cpp GetCookies
3856#[com_interface("F7F6F714-5D2A-43C6-9503-346ECE02D186")]
3857pub trait ICoreWebView2CookieList: IUnknown {
3858 /// The number of cookies contained in the ICoreWebView2CookieList.
3859 unsafe fn get_count(&self, /* out, retval */ count: *mut u32) -> HRESULT;
3860
3861 /// Gets the cookie object at the given index.
3862 unsafe fn get_value_at_index(
3863 &self,
3864 /* in */ index: u32,
3865 /* out, retval */ cookie: *mut *mut *mut ICoreWebView2CookieVTable,
3866 ) -> HRESULT;
3867}
3868
3869/// Receives the result of the `GetCookies` method. The result is written to
3870/// the cookie list provided in the `GetCookies` method call.
3871#[com_interface("5A4F5069-5C15-47C3-8646-F4DE1C116670")]
3872pub trait ICoreWebView2GetCookiesCompletedHandler: IUnknown {
3873 /// Provides the completion status of the corresponding asynchronous method
3874 /// call.
3875 unsafe fn invoke(
3876 &self,
3877 result: HRESULT,
3878 cookie_list: *mut *mut ICoreWebView2CookieListVTable,
3879 ) -> HRESULT;
3880}
3881
3882/// Provides access to the certificate metadata
3883#[com_interface("e7188076-bcc3-11eb-8529-0242ac130003")]
3884pub trait ICoreWebView2ClientCertificate: IUnknown {
3885 /// Subject of the certificate.
3886 unsafe fn get_subject(&self, /* out, retval */ value: *mut LPWSTR) -> HRESULT;
3887
3888 /// Name of the certificate authority that issued the certificate.
3889 unsafe fn get_issuer(&self, /* out, retval */ value: *mut LPWSTR) -> HRESULT;
3890
3891 /// The valid start date and time for the certificate as the number of seconds since
3892 /// the UNIX epoch.
3893 unsafe fn get_valid_from(&self, /* out, retval */ value: *mut f64) -> HRESULT;
3894
3895 /// The valid expiration date and time for the certificate as the number of seconds since
3896 /// the UNIX epoch.
3897 unsafe fn get_valid_to(&self, /* out, retval */ value: *mut f64) -> HRESULT;
3898
3899 /// DER encoded serial number of the certificate.
3900 /// Read more about DER at [RFC 7468 DER]
3901 /// (https://tools.ietf.org/html/rfc7468#appendix-B).
3902 unsafe fn get_der_encoded_serial_number(
3903 &self,
3904 /* out, retval */ value: *mut LPWSTR,
3905 ) -> HRESULT;
3906
3907 /// Display name for a certificate.
3908 unsafe fn get_display_name(&self, /* out, retval */ value: *mut LPWSTR) -> HRESULT;
3909
3910 /// PEM encoded data for the certificate.
3911 /// Returns Base64 encoding of DER encoded certificate.
3912 /// Read more about PEM at [RFC 1421 Privacy Enhanced Mail]
3913 /// (https://tools.ietf.org/html/rfc1421).
3914 unsafe fn to_pem_encoding(
3915 &self,
3916 /* out, retval */ pem_encoded_data: *mut LPWSTR,
3917 ) -> HRESULT;
3918
3919 /// Collection of PEM encoded client certificate issuer chain.
3920 /// In this collection first element is the current certificate followed by
3921 /// intermediate1, intermediate2...intermediateN-1. Root certificate is the
3922 /// last element in collection.
3923 unsafe fn get_pem_encoded_issuer_certificate_chain(
3924 &self,
3925 /* out, retval */ value: *mut *mut *mut ICoreWebView2StringCollectionVTable,
3926 ) -> HRESULT;
3927
3928 /// Kind of a certificate (eg., smart card, pin, other).
3929 unsafe fn get_kind(&self, /* out, retval */ value: *mut ClientCertificateKind) -> HRESULT;
3930}
3931
3932/// A collection of client certificate object.
3933#[com_interface("ef5674d2-bcc3-11eb-8529-0242ac130003")]
3934pub trait ICoreWebView2ClientCertificateCollection: IUnknown {
3935 /// The number of client certificates contained in the
3936 /// ICoreWebView2ClientCertificateCollection.
3937 unsafe fn get_count(&self, /* out, retval */ value: *mut u32) -> HRESULT;
3938
3939 /// Gets the certificate object at the given index.
3940 unsafe fn get_value_at_index(
3941 &self,
3942 /* in */ index: u32,
3943 /* out, retval */ certificate: *mut *mut *mut ICoreWebView2ClientCertificateVTable,
3944 ) -> HRESULT;
3945}
3946
3947/// A collection of strings.
3948#[com_interface("f41f3f8a-bcc3-11eb-8529-0242ac130003")]
3949pub trait ICoreWebView2StringCollection: IUnknown {
3950 /// The number of strings contained in ICoreWebView2StringCollection.
3951 unsafe fn get_count(&self, /* out, retval */ value: *mut u32) -> HRESULT;
3952
3953 /// Gets the value at a given index.
3954 unsafe fn get_value_at_index(
3955 &self,
3956 /* in */ index: u32,
3957 /* out, retval */ value: *mut LPWSTR,
3958 ) -> HRESULT;
3959}
3960
3961/// An event handler for the `ClientCertificateRequested` event.
3962#[com_interface("d7175ba2-bcc3-11eb-8529-0242ac130003")]
3963pub trait ICoreWebView2ClientCertificateRequestedEventHandler: IUnknown {
3964 /// Provides the event args for the corresponding event.
3965 unsafe fn invoke(
3966 &self,
3967 /* in */ sender: *mut *mut ICoreWebView2VTable,
3968 /* in */ args: *mut *mut ICoreWebView2ClientCertificateRequestedEventArgsVTable,
3969 ) -> HRESULT;
3970}
3971
3972/// Event args for the `ClientCertificateRequested` event.
3973#[com_interface("bc59db28-bcc3-11eb-8529-0242ac130003")]
3974pub trait ICoreWebView2ClientCertificateRequestedEventArgs: IUnknown {
3975 /// Host name of the server that requested client certificate authentication.
3976 /// Normalization rules applied to the hostname are:
3977 /// * Convert to lowercase characters for ascii characters.
3978 /// * Punycode is used for representing non ascii characters.
3979 /// * Strip square brackets for IPV6 address.
3980 unsafe fn get_host(&self, /* out, retval */ value: *mut LPWSTR) -> HRESULT;
3981
3982 /// Port of the server that requested client certificate authentication.
3983 unsafe fn get_port(&self, /* out, retval */ value: *mut i32) -> HRESULT;
3984
3985 /// Returns true if the server that issued this request is an http proxy.
3986 /// Returns false if the server is the origin server.
3987 unsafe fn get_is_proxy(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;
3988
3989 /// Returns the `ICoreWebView2StringCollection`.
3990 /// The collection contains distinguished names of certificate authorities
3991 /// allowed by the server.
3992 unsafe fn get_allowed_certificate_authorities(
3993 &self,
3994 /* out, retval */ value: *mut *mut *mut ICoreWebView2StringCollectionVTable,
3995 ) -> HRESULT;
3996
3997 /// Returns the `ICoreWebView2ClientCertificateCollection` when client
3998 /// certificate authentication is requested. The collection contains mutually
3999 /// trusted CA certificates.
4000 unsafe fn get_mutually_trusted_certificates(
4001 &self,
4002 /* out, retval */
4003 value: *mut *mut *mut ICoreWebView2ClientCertificateCollectionVTable,
4004 ) -> HRESULT;
4005
4006 /// Returns the selected certificate.
4007 unsafe fn get_selected_certificate(
4008 &self,
4009 /* out, retval */ value: *mut *mut *mut ICoreWebView2ClientCertificateVTable,
4010 ) -> HRESULT;
4011
4012 /// Sets the certificate to respond to the server.
4013 unsafe fn put_selected_certificate(
4014 &self,
4015 /* in */ value: *mut *mut ICoreWebView2ClientCertificateVTable,
4016 ) -> HRESULT;
4017
4018 /// You�may�set�this�flag�to�cancel�the�certificate selection. If canceled,
4019 /// the request is aborted regardless of the `Handled` property. By default the
4020 /// value is `FALSE`.
4021 unsafe fn get_cancel(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;
4022
4023 ///�Sets�the�`Cancel`�property.
4024 unsafe fn put_cancel(&self, /* in */ value: BOOL) -> HRESULT;
4025
4026 /// You�may�set�this�flag�to�`TRUE` to respond to the server with or
4027 /// without a certificate. If this flag is `TRUE` with a `SelectedCertificate`
4028 /// it responds to the server with the selected certificate otherwise respond to the
4029 /// server without a certificate. By default the value of `Handled` and `Cancel` are `FALSE`
4030 /// and display default client certificate selection dialog prompt to allow the user to
4031 /// choose a certificate. The `SelectedCertificate` is ignored unless `Handled` is set `TRUE`.
4032 unsafe fn get_handled(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;
4033
4034 ///�Sets�the�`Handled`�property.
4035 unsafe fn put_handled(&self, /* in */ value: BOOL) -> HRESULT;
4036
4037 /// Returns an `ICoreWebView2Deferral` object. Use this operation to
4038 /// complete the event at a later time.
4039 unsafe fn get_deferral(
4040 &self,
4041 /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
4042 ) -> HRESULT;
4043}
4044
4045/// This mostly represents a combined win32
4046/// POINTER_INFO/POINTER_TOUCH_INFO/POINTER_PEN_INFO object. It takes fields
4047/// from all three and excludes some win32 specific data types like HWND and
4048/// HANDLE. Note, sourceDevice is taken out but we expect the PointerDeviceRect
4049/// and DisplayRect to cover the existing use cases of sourceDevice.
4050/// Another big difference is that any of the point or rect locations are
4051/// expected to be in WebView physical coordinates. That is, coordinates
4052/// relative to the WebView and no DPI scaling applied.
4053#[com_interface("e6995887-d10d-4f5d-9359-4ce46e4f96b9")]
4054pub trait ICoreWebView2PointerInfo: IUnknown {
4055 /// Get the PointerKind of the pointer event. This corresponds to the
4056 /// pointerKind property of the POINTER_INFO struct. The values are defined by
4057 /// the POINTER_INPUT_KIND enum in the Windows SDK (winuser.h). Supports
4058 /// PT_PEN and PT_TOUCH.
4059 unsafe fn get_pointer_kind(&self, /* out, retval */ pointer_kind: *mut DWORD) -> HRESULT;
4060
4061 /// Set the PointerKind of the pointer event. This corresponds to the
4062 /// pointerKind property of the POINTER_INFO struct. The values are defined by
4063 /// the POINTER_INPUT_KIND enum in the Windows SDK (winuser.h). Supports
4064 /// PT_PEN and PT_TOUCH.
4065 unsafe fn put_pointer_kind(&self, /* in */ pointer_kind: DWORD) -> HRESULT;
4066
4067 /// Get the PointerId of the pointer event. This corresponds to the pointerId
4068 /// property of the POINTER_INFO struct as defined in the Windows SDK
4069 /// (winuser.h).
4070 unsafe fn get_pointer_id(&self, /* out, retval */ pointer_id: *mut u32) -> HRESULT;
4071
4072 /// Set the PointerId of the pointer event. This corresponds to the pointerId
4073 /// property of the POINTER_INFO struct as defined in the Windows SDK
4074 /// (winuser.h).
4075 unsafe fn put_pointer_id(&self, /* in */ pointer_id: u32) -> HRESULT;
4076
4077 /// Get the FrameID of the pointer event. This corresponds to the frameId
4078 /// property of the POINTER_INFO struct as defined in the Windows SDK
4079 /// (winuser.h).
4080 unsafe fn get_frame_id(&self, /* out, retval */ frame_id: *mut u32) -> HRESULT;
4081
4082 /// Set the FrameID of the pointer event. This corresponds to the frameId
4083 /// property of the POINTER_INFO struct as defined in the Windows SDK
4084 /// (winuser.h).
4085 unsafe fn put_frame_id(&self, /* in */ frame_id: u32) -> HRESULT;
4086
4087 /// Get the PointerFlags of the pointer event. This corresponds to the
4088 /// pointerFlags property of the POINTER_INFO struct. The values are defined
4089 /// by the POINTER_FLAGS constants in the Windows SDK (winuser.h).
4090 unsafe fn get_pointer_flags(&self, /* out, retval */ pointer_flags: *mut u32) -> HRESULT;
4091
4092 /// Set the PointerFlags of the pointer event. This corresponds to the
4093 /// pointerFlags property of the POINTER_INFO struct. The values are defined
4094 /// by the POINTER_FLAGS constants in the Windows SDK (winuser.h).
4095 unsafe fn put_pointer_flags(&self, /* in */ pointer_flags: u32) -> HRESULT;
4096
4097 /// Get the PointerDeviceRect of the sourceDevice property of the
4098 /// POINTER_INFO struct as defined in the Windows SDK (winuser.h).
4099 unsafe fn get_pointer_device_rect(
4100 &self,
4101 /* out, retval */ pointer_device_rect: *mut RECT,
4102 ) -> HRESULT;
4103
4104 /// Set the PointerDeviceRect of the sourceDevice property of the
4105 /// POINTER_INFO struct as defined in the Windows SDK (winuser.h).
4106 unsafe fn put_pointer_device_rect(&self, /* in */ pointer_device_rect: RECT) -> HRESULT;
4107
4108 /// Get the DisplayRect of the sourceDevice property of the POINTER_INFO
4109 /// struct as defined in the Windows SDK (winuser.h).
4110 unsafe fn get_display_rect(&self, /* out, retval */ display_rect: *mut RECT) -> HRESULT;
4111
4112 /// Set the DisplayRect of the sourceDevice property of the POINTER_INFO
4113 /// struct as defined in the Windows SDK (winuser.h).
4114 unsafe fn put_display_rect(&self, /* in */ display_rect: RECT) -> HRESULT;
4115
4116 /// Get the PixelLocation of the pointer event. This corresponds to the
4117 /// ptPixelLocation property of the POINTER_INFO struct as defined in the
4118 /// Windows SDK (winuser.h).
4119 unsafe fn get_pixel_location(
4120 &self,
4121 /* out, retval */ pixel_location: *mut POINT,
4122 ) -> HRESULT;
4123
4124 /// Set the PixelLocation of the pointer event. This corresponds to the
4125 /// ptPixelLocation property of the POINTER_INFO struct as defined in the
4126 /// Windows SDK (winuser.h).
4127 unsafe fn put_pixel_location(&self, /* in */ pixel_location: POINT) -> HRESULT;
4128
4129 /// Get the HimetricLocation of the pointer event. This corresponds to the
4130 /// ptHimetricLocation property of the POINTER_INFO struct as defined in the
4131 /// Windows SDK (winuser.h).
4132 unsafe fn get_himetric_location(
4133 &self,
4134 /* out, retval */ himetric_location: *mut POINT,
4135 ) -> HRESULT;
4136
4137 /// Set the HimetricLocation of the pointer event. This corresponds to the
4138 /// ptHimetricLocation property of the POINTER_INFO struct as defined in the
4139 /// Windows SDK (winuser.h).
4140 unsafe fn put_himetric_location(&self, /* in */ himetric_location: POINT) -> HRESULT;
4141
4142 /// Get the PixelLocationRaw of the pointer event. This corresponds to the
4143 /// ptPixelLocationRaw property of the POINTER_INFO struct as defined in the
4144 /// Windows SDK (winuser.h).
4145 unsafe fn get_pixel_location_raw(
4146 &self,
4147 /* out, retval */ pixel_location_raw: *mut POINT,
4148 ) -> HRESULT;
4149
4150 /// Set the PixelLocationRaw of the pointer event. This corresponds to the
4151 /// ptPixelLocationRaw property of the POINTER_INFO struct as defined in the
4152 /// Windows SDK (winuser.h).
4153 unsafe fn put_pixel_location_raw(&self, /* in */ pixel_location_raw: POINT) -> HRESULT;
4154
4155 /// Get the HimetricLocationRaw of the pointer event. This corresponds to the
4156 /// ptHimetricLocationRaw property of the POINTER_INFO struct as defined in
4157 /// the Windows SDK (winuser.h).
4158 unsafe fn get_himetric_location_raw(
4159 &self,
4160 /* out, retval */ himetric_location_raw: *mut POINT,
4161 ) -> HRESULT;
4162
4163 /// Set the HimetricLocationRaw of the pointer event. This corresponds to the
4164 /// ptHimetricLocationRaw property of the POINTER_INFO struct as defined in
4165 /// the Windows SDK (winuser.h).
4166 unsafe fn put_himetric_location_raw(
4167 &self,
4168 /* in */ himetric_location_raw: POINT,
4169 ) -> HRESULT;
4170
4171 /// Get the Time of the pointer event. This corresponds to the dwTime property
4172 /// of the POINTER_INFO struct as defined in the Windows SDK (winuser.h).
4173 unsafe fn get_time(&self, /* out, retval */ time: *mut DWORD) -> HRESULT;
4174
4175 /// Set the Time of the pointer event. This corresponds to the dwTime property
4176 /// of the POINTER_INFO struct as defined in the Windows SDK (winuser.h).
4177 unsafe fn put_time(&self, /* in */ time: DWORD) -> HRESULT;
4178
4179 /// Get the HistoryCount of the pointer event. This corresponds to the
4180 /// historyCount property of the POINTER_INFO struct as defined in the Windows
4181 /// SDK (winuser.h).
4182 unsafe fn get_history_count(&self, /* out, retval */ history_count: *mut u32) -> HRESULT;
4183
4184 /// Set the HistoryCount of the pointer event. This corresponds to the
4185 /// historyCount property of the POINTER_INFO struct as defined in the Windows
4186 /// SDK (winuser.h).
4187 unsafe fn put_history_count(&self, /* in */ history_count: u32) -> HRESULT;
4188
4189 /// Get the InputData of the pointer event. This corresponds to the InputData
4190 /// property of the POINTER_INFO struct as defined in the Windows SDK
4191 /// (winuser.h).
4192 unsafe fn get_input_data(&self, /* out, retval */ input_data: *mut i32) -> HRESULT;
4193
4194 /// Set the InputData of the pointer event. This corresponds to the InputData
4195 /// property of the POINTER_INFO struct as defined in the Windows SDK
4196 /// (winuser.h).
4197 unsafe fn put_input_data(&self, /* in */ input_data: i32) -> HRESULT;
4198
4199 /// Get the KeyStates of the pointer event. This corresponds to the
4200 /// dwKeyStates property of the POINTER_INFO struct as defined in the Windows
4201 /// SDK (winuser.h).
4202 unsafe fn get_key_states(&self, /* out, retval */ key_states: *mut DWORD) -> HRESULT;
4203
4204 /// Set the KeyStates of the pointer event. This corresponds to the
4205 /// dwKeyStates property of the POINTER_INFO struct as defined in the Windows
4206 /// SDK (winuser.h).
4207 unsafe fn put_key_states(&self, /* in */ key_states: DWORD) -> HRESULT;
4208
4209 /// Get the PerformanceCount of the pointer event. This corresponds to the
4210 /// PerformanceCount property of the POINTER_INFO struct as defined in the
4211 /// Windows SDK (winuser.h).
4212 unsafe fn get_performance_count(
4213 &self,
4214 /* out, retval */ performance_count: *mut u64,
4215 ) -> HRESULT;
4216
4217 /// Set the PerformanceCount of the pointer event. This corresponds to the
4218 /// PerformanceCount property of the POINTER_INFO struct as defined in the
4219 /// Windows SDK (winuser.h).
4220 unsafe fn put_performance_count(&self, /* in */ performance_count: u64) -> HRESULT;
4221
4222 /// Get the ButtonChangeKind of the pointer event. This corresponds to the
4223 /// ButtonChangeKind property of the POINTER_INFO struct. The values are
4224 /// defined by the POINTER_BUTTON_CHANGE_KIND enum in the Windows SDK
4225 /// (winuser.h).
4226 unsafe fn get_button_change_kind(
4227 &self,
4228 /* out, retval */ button_change_kind: *mut i32,
4229 ) -> HRESULT;
4230
4231 /// Set the ButtonChangeKind of the pointer event. This corresponds to the
4232 /// ButtonChangeKind property of the POINTER_INFO struct. The values are
4233 /// defined by the POINTER_BUTTON_CHANGE_KIND enum in the Windows SDK
4234 /// (winuser.h).
4235 unsafe fn put_button_change_kind(&self, /* in */ button_change_kind: i32) -> HRESULT;
4236
4237 /// Get the PenFlags of the pointer event. This corresponds to the penFlags
4238 /// property of the POINTER_PEN_INFO struct. The values are defined by the
4239 /// PEN_FLAGS constants in the Windows SDK (winuser.h).
4240 unsafe fn get_pen_flags(&self, /* out, retval */ pen_flags: *mut u32) -> HRESULT;
4241
4242 /// Set the PenFlags of the pointer event. This corresponds to the penFlags
4243 /// property of the POINTER_PEN_INFO struct. The values are defined by the
4244 /// PEN_FLAGS constants in the Windows SDK (winuser.h).
4245 unsafe fn put_pen_flags(&self, /* in */ pen_flags: u32) -> HRESULT;
4246
4247 /// Get the PenMask of the pointer event. This corresponds to the penMask
4248 /// property of the POINTER_PEN_INFO struct. The values are defined by the
4249 /// PEN_MASK constants in the Windows SDK (winuser.h).
4250 unsafe fn get_pen_mask(&self, /* out, retval */ pen_mask: *mut u32) -> HRESULT;
4251
4252 /// Set the PenMask of the pointer event. This corresponds to the penMask
4253 /// property of the POINTER_PEN_INFO struct. The values are defined by the
4254 /// PEN_MASK constants in the Windows SDK (winuser.h).
4255 unsafe fn put_pen_mask(&self, /* in */ pen_mask: u32) -> HRESULT;
4256
4257 /// Get the PenPressure of the pointer event. This corresponds to the pressure
4258 /// property of the POINTER_PEN_INFO struct as defined in the Windows SDK
4259 /// (winuser.h).
4260 unsafe fn get_pen_pressure(&self, /* out, retval */ pen_pressure: *mut u32) -> HRESULT;
4261
4262 /// Set the PenPressure of the pointer event. This corresponds to the pressure
4263 /// property of the POINTER_PEN_INFO struct as defined in the Windows SDK
4264 /// (winuser.h).
4265 unsafe fn put_pen_pressure(&self, /* in */ pen_pressure: u32) -> HRESULT;
4266
4267 /// Get the PenRotation of the pointer event. This corresponds to the rotation
4268 /// property of the POINTER_PEN_INFO struct as defined in the Windows SDK
4269 /// (winuser.h).
4270 unsafe fn get_pen_rotation(&self, /* out, retval */ pen_rotation: *mut u32) -> HRESULT;
4271
4272 /// Set the PenRotation of the pointer event. This corresponds to the rotation
4273 /// property of the POINTER_PEN_INFO struct as defined in the Windows SDK
4274 /// (winuser.h).
4275 unsafe fn put_pen_rotation(&self, /* in */ pen_rotation: u32) -> HRESULT;
4276
4277 /// Get the PenTiltX of the pointer event. This corresponds to the tiltX
4278 /// property of the POINTER_PEN_INFO struct as defined in the Windows SDK
4279 /// (winuser.h).
4280 unsafe fn get_pen_tilt_x(&self, /* out, retval */ pen_tilt_x: *mut i32) -> HRESULT;
4281
4282 /// Set the PenTiltX of the pointer event. This corresponds to the tiltX
4283 /// property of the POINTER_PEN_INFO struct as defined in the Windows SDK
4284 /// (winuser.h).
4285 unsafe fn put_pen_tilt_x(&self, /* in */ pen_tilt_x: i32) -> HRESULT;
4286
4287 /// Get the PenTiltY of the pointer event. This corresponds to the tiltY
4288 /// property of the POINTER_PEN_INFO struct as defined in the Windows SDK
4289 /// (winuser.h).
4290 unsafe fn get_pen_tilt_y(&self, /* out, retval */ pen_tilt_y: *mut i32) -> HRESULT;
4291
4292 /// Set the PenTiltY of the pointer event. This corresponds to the tiltY
4293 /// property of the POINTER_PEN_INFO struct as defined in the Windows SDK
4294 /// (winuser.h).
4295 unsafe fn put_pen_tilt_y(&self, /* in */ pen_tilt_y: i32) -> HRESULT;
4296
4297 /// Get the TouchFlags of the pointer event. This corresponds to the
4298 /// touchFlags property of the POINTER_TOUCH_INFO struct. The values are
4299 /// defined by the TOUCH_FLAGS constants in the Windows SDK (winuser.h).
4300 unsafe fn get_touch_flags(&self, /* out, retval */ touch_flags: *mut u32) -> HRESULT;
4301
4302 /// Set the TouchFlags of the pointer event. This corresponds to the
4303 /// touchFlags property of the POINTER_TOUCH_INFO struct. The values are
4304 /// defined by the TOUCH_FLAGS constants in the Windows SDK (winuser.h).
4305 unsafe fn put_touch_flags(&self, /* in */ touch_flags: u32) -> HRESULT;
4306
4307 /// Get the TouchMask of the pointer event. This corresponds to the
4308 /// touchMask property of the POINTER_TOUCH_INFO struct. The values are
4309 /// defined by the TOUCH_MASK constants in the Windows SDK (winuser.h).
4310 unsafe fn get_touch_mask(&self, /* out, retval */ touch_mask: *mut u32) -> HRESULT;
4311
4312 /// Set the TouchMask of the pointer event. This corresponds to the
4313 /// touchMask property of the POINTER_TOUCH_INFO struct. The values are
4314 /// defined by the TOUCH_MASK constants in the Windows SDK (winuser.h).
4315 unsafe fn put_touch_mask(&self, /* in */ touch_mask: u32) -> HRESULT;
4316
4317 /// Get the TouchContact of the pointer event. This corresponds to the
4318 /// rcContact property of the POINTER_TOUCH_INFO struct as defined in the
4319 /// Windows SDK (winuser.h).
4320 unsafe fn get_touch_contact(&self, /* out, retval */ touch_contact: *mut RECT) -> HRESULT;
4321
4322 /// Set the TouchContact of the pointer event. This corresponds to the
4323 /// rcContact property of the POINTER_TOUCH_INFO struct as defined in the
4324 /// Windows SDK (winuser.h).
4325 unsafe fn put_touch_contact(&self, /* in */ touch_contact: RECT) -> HRESULT;
4326
4327 /// Get the TouchContactRaw of the pointer event. This corresponds to the
4328 /// rcContactRaw property of the POINTER_TOUCH_INFO struct as defined in the
4329 /// Windows SDK (winuser.h).
4330 unsafe fn get_touch_contact_raw(
4331 &self,
4332 /* out, retval */ touch_contact_raw: *mut RECT,
4333 ) -> HRESULT;
4334
4335 /// Set the TouchContactRaw of the pointer event. This corresponds to the
4336 /// rcContactRaw property of the POINTER_TOUCH_INFO struct as defined in the
4337 /// Windows SDK (winuser.h).
4338 unsafe fn put_touch_contact_raw(&self, /* in */ touch_contact_raw: RECT) -> HRESULT;
4339
4340 /// Get the TouchOrientation of the pointer event. This corresponds to the
4341 /// orientation property of the POINTER_TOUCH_INFO struct as defined in the
4342 /// Windows SDK (winuser.h).
4343 unsafe fn get_touch_orientation(
4344 &self,
4345 /* out, retval */ touch_orientation: *mut u32,
4346 ) -> HRESULT;
4347
4348 /// Set the TouchOrientation of the pointer event. This corresponds to the
4349 /// orientation property of the POINTER_TOUCH_INFO struct as defined in the
4350 /// Windows SDK (winuser.h).
4351 unsafe fn put_touch_orientation(&self, /* in */ touch_orientation: u32) -> HRESULT;
4352
4353 /// Get the TouchPressure of the pointer event. This corresponds to the
4354 /// pressure property of the POINTER_TOUCH_INFO struct as defined in the
4355 /// Windows SDK (winuser.h).
4356 unsafe fn get_touch_pressure(&self, /* out, retval */ touch_pressure: *mut u32) -> HRESULT;
4357
4358 /// Set the TouchPressure of the pointer event. This corresponds to the
4359 /// pressure property of the POINTER_TOUCH_INFO struct as defined in the
4360 /// Windows SDK (winuser.h).
4361 unsafe fn put_touch_pressure(&self, /* in */ touch_pressure: u32) -> HRESULT;
4362}
4363
4364/// The caller implements this interface to receive CursorChanged events. Use
4365/// the Cursor property to get the new cursor.
4366#[com_interface("9da43ccc-26e1-4dad-b56c-d8961c94c571")]
4367pub trait ICoreWebView2CursorChangedEventHandler: IUnknown {
4368 /// Called to provide the implementer with the event args for the
4369 /// corresponding event. There are no event args and the args
4370 /// parameter will be null.
4371 unsafe fn invoke(
4372 &self,
4373 /* in */ sender: *mut *mut ICoreWebView2CompositionControllerVTable,
4374 /* in */ args: *mut *mut IUnknownVTable,
4375 ) -> HRESULT;
4376}
4377
4378/// Receives `RasterizationScaleChanged` events. Use the `RasterizationScale`
4379/// property to get the modified scale.
4380#[com_interface("9c98c8b1-ac53-427e-a345-3049b5524bbe")]
4381pub trait ICoreWebView2RasterizationScaleChangedEventHandler: IUnknown {
4382 /// Called to provide the implementer with the event args for the
4383 /// corresponding event. There are no event args and the args
4384 /// parameter will be null.
4385 unsafe fn invoke(
4386 &self,
4387 /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
4388 /* in */ args: *mut *mut IUnknownVTable,
4389 ) -> HRESULT;
4390}
4391
4392/// Represents the WebView2 Environment. WebViews created from an environment
4393/// run on the browser process specified with environment parameters and
4394/// objects created from an environment should be used in the same
4395/// environment. Using it in different environments are not guaranteed to be
4396/// compatible and may fail.
4397#[com_interface("b96d755e-0319-4e92-a296-23436f46a1fc")]
4398pub trait ICoreWebView2Environment: IUnknown {
4399 /// Asynchronously create a new WebView.
4400 ///
4401 /// `parentWindow` is the `HWND` in which the WebView should be displayed and
4402 /// from which receive input. The WebView adds a child window to the
4403 /// provided window during WebView creation. Z-order and other things
4404 /// impacted by sibling window order are affected accordingly.
4405 ///
4406 /// It is recommended that the app set Application User Model ID for the
4407 /// process or the app window. If none is set, during WebView creation a
4408 /// generated Application User Model ID is set to root window of
4409 /// `parentWindow`.
4410 ///
4411 /// \snippet AppWindow.cpp CreateCoreWebView2Controller
4412 ///
4413 /// It is recommended that the app handles restart manager messages, to
4414 /// gracefully restart it in the case when the app is using the WebView2
4415 /// Runtime from a certain installation and that installation is being
4416 /// uninstalled. For example, if a user installs a version of the WebView2
4417 /// Runtime and opts to use another version of the WebView2 Runtime for
4418 /// testing the app, and then uninstalls the 1st version of the WebView2
4419 /// Runtime without closing the app, the app restarts to allow
4420 /// un-installation to succeed.
4421 ///
4422 /// \snippet AppWindow.cpp RestartManager
4423 ///
4424 /// When the app retries `CreateCoreWebView2Controller` upon failure, it is
4425 /// recommended that the app restarts from creating a new WebView2
4426 /// Environment. If an WebView2 Runtime update happens, the version
4427 /// associated with a WebView2 Environment may have been removed and causing
4428 /// the object to no longer work. Creating a new WebView2 Environment works
4429 /// since it uses the latest version.
4430 ///
4431 /// WebView creation fails if a running instance using the same user data
4432 /// folder exists, and the Environment objects have different
4433 /// `EnvironmentOptions`. For example, if a WebView was created with one
4434 /// language, an attempt to create a WebView with a different language using
4435 /// the same user data folder fails.
4436 unsafe fn create_core_web_view2_controller(
4437 &self,
4438 parent_window: HWND,
4439 handler: *mut *mut ICoreWebView2CreateCoreWebView2ControllerCompletedHandlerVTable,
4440 ) -> HRESULT;
4441
4442 /// Create a new web resource response object. The `headers` parameter is
4443 /// the raw response header string delimited by newline. It is also possible
4444 /// to create this object with null headers string and then use the
4445 /// `ICoreWebView2HttpResponseHeaders` to construct the headers line by line.
4446 /// For more information about other parameters, navigate to
4447 /// \[ICoreWebView2WebResourceResponse\]\[MicrosoftEdgeWebview2ReferenceWin32Icorewebview2webresourceresponse\].
4448 ///
4449 /// \snippet SettingsComponent.cpp WebResourceRequested0
4450 /// \snippet SettingsComponent.cpp WebResourceRequested1
4451 ///
4452 /// \[MicrosoftEdgeWebview2ReferenceWin32Icorewebview2webresourceresponse\]: /microsoft-edge/webview2/reference/win32/icorewebview2webresourceresponse "interface ICoreWebView2WebResourceResponse | Microsoft Docs"
4453 unsafe fn create_web_resource_response(
4454 &self,
4455 /* in */ content: *mut *mut IStreamVTable,
4456 /* in */ status_code: i32,
4457 /* in */ reason_phrase: LPCWSTR,
4458 /* in */ headers: LPCWSTR,
4459 /* out, retval */ response: *mut *mut *mut ICoreWebView2WebResourceResponseVTable,
4460 ) -> HRESULT;
4461
4462 /// The browser version info of the current `ICoreWebView2Environment`,
4463 /// including channel name if it is not the WebView2 Runtime. It matches the
4464 /// format of the `GetAvailableCoreWebView2BrowserVersionString` API.
4465 /// Channel names are `beta`, `dev`, and `canary`.
4466 ///
4467 /// \snippet AppWindow.cpp GetBrowserVersionString
4468 unsafe fn get_browser_version_string(
4469 &self,
4470 /* out, retval */ version_info: *mut LPWSTR,
4471 ) -> HRESULT;
4472
4473 /// Add an event handler for the `NewBrowserVersionAvailable` event.
4474 /// `NewBrowserVersionAvailable` runs when a newer version of the WebView2
4475 /// Runtime is installed and available using WebView2. To use the newer
4476 /// version of the browser you must create a new environment and WebView.
4477 /// The event only runs for new version from the same WebView2 Runtime from
4478 /// which the code is running. When not running with installed WebView2
4479 /// Runtime, no event is run.
4480 ///
4481 /// Because a user data folder is only able to be used by one browser
4482 /// process at a time, if you want to use the same user data folder in the
4483 /// WebView using the new version of the browser, you must close the
4484 /// environment and instance of WebView that are using the older version of
4485 /// the browser first. Or simply prompt the user to restart the app.
4486 ///
4487 /// \snippet AppWindow.cpp NewBrowserVersionAvailable
4488 unsafe fn add_new_browser_version_available(
4489 &self,
4490 /* in */
4491 event_handler: *mut *mut ICoreWebView2NewBrowserVersionAvailableEventHandlerVTable,
4492 /* out */ token: *mut EventRegistrationToken,
4493 ) -> HRESULT;
4494
4495 /// Remove an event handler previously added with `add_NewBrowserVersionAvailable`.
4496 unsafe fn remove_new_browser_version_available(
4497 &self,
4498 /* in */ token: EventRegistrationToken,
4499 ) -> HRESULT;
4500}
4501
4502/// A continuation of the ICoreWebView2Environment interface.
4503#[com_interface("41F3632B-5EF4-404F-AD82-2D606C5A9A21")]
4504pub trait ICoreWebView2Environment2: ICoreWebView2Environment {
4505 /// Create a new web resource request object.
4506 /// URI parameter must be absolute URI.
4507 /// The headers string is the raw request header string delimited by CRLF
4508 /// (optional in last header).
4509 /// It's also possible to create this object with null headers string
4510 /// and then use the ICoreWebView2HttpRequestHeaders to construct the headers
4511 /// line by line.
4512 /// For information on other parameters see ICoreWebView2WebResourceRequest.
4513 ///
4514 /// \snippet ScenarioNavigateWithWebResourceRequest.cpp NavigateWithWebResourceRequest
4515 unsafe fn create_web_resource_request(
4516 &self,
4517 /* in */ uri: LPCWSTR,
4518 /* in */ method: LPCWSTR,
4519 /* in */ post_data: *mut *mut IStreamVTable,
4520 /* in */ headers: LPCWSTR,
4521 /* out, retval */ request: *mut *mut *mut ICoreWebView2WebResourceRequestVTable,
4522 ) -> HRESULT;
4523}
4524
4525/// A continuation of the ICoreWebView2Environment2 interface.
4526#[com_interface("80a22ae3-be7c-4ce2-afe1-5a50056cdeeb")]
4527pub trait ICoreWebView2Environment3: ICoreWebView2Environment2 {
4528 /// Asynchronously create a new WebView for use with visual hosting.
4529 ///
4530 /// parentWindow is the HWND in which the app will connect the visual tree of
4531 /// the WebView. This will be the HWND that the app will receive pointer/
4532 /// mouse input meant for the WebView (and will need to use SendMouseInput/
4533 /// SendPointerInput to forward). If the app moves the WebView visual tree to
4534 /// underneath a different window, then it needs to call put_ParentWindow to
4535 /// update the new parent HWND of the visual tree.
4536 ///
4537 /// Use put_RootVisualTarget on the created CoreWebView2CompositionController to
4538 /// provide a visual to host the browser's visual tree.
4539 ///
4540 /// It is recommended that the application set Application User Model ID for
4541 /// the process or the application window. If none is set, during WebView
4542 /// creation a generated Application User Model ID is set to root window of
4543 /// parentWindow.
4544 /// \snippet AppWindow.cpp CreateCoreWebView2Controller
4545 ///
4546 /// It is recommended that the application handles restart manager messages
4547 /// so that it can be restarted gracefully in the case when the app is using
4548 /// Edge for WebView from a certain installation and that installation is
4549 /// being uninstalled. For example, if a user installs Edge from Dev channel
4550 /// and opts to use Edge from that channel for testing the app, and then
4551 /// uninstalls Edge from that channel without closing the app, the app will
4552 /// be restarted to allow uninstallation of the dev channel to succeed.
4553 /// \snippet AppWindow.cpp RestartManager
4554 unsafe fn create_core_web_view2_composition_controller(
4555 &self,
4556 parent_window: HWND,
4557 handler: *mut *mut ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandlerVTable,
4558 ) -> HRESULT;
4559
4560 /// Create an empty ICoreWebView2PointerInfo. The returned
4561 /// ICoreWebView2PointerInfo needs to be populated with all of the relevant
4562 /// info before calling SendPointerInput.
4563 unsafe fn create_core_web_view2_pointer_info(
4564 &self,
4565 /* out, retval */ pointer_info: *mut *mut *mut ICoreWebView2PointerInfoVTable,
4566 ) -> HRESULT;
4567}
4568
4569/// A continuation of the ICoreWebView2Environment3 interface.
4570#[com_interface("20944379-6dcf-41d6-a0a0-abc0fc50de0d")]
4571pub trait ICoreWebView2Environment4: ICoreWebView2Environment3 {
4572 /// Returns the UI Automation Provider for the
4573 /// ICoreWebView2CompositionController that corresponds with the given HWND.
4574 unsafe fn get_provider_for_hwnd(
4575 &self,
4576 /* in */ hwnd: HWND,
4577 /* out, retval */ provider: *mut *mut *mut IUnknownVTable,
4578 ) -> HRESULT;
4579}
4580
4581/// Options used to create WebView2 Environment. A default implementation is
4582/// provided in `WebView2EnvironmentOptions.h`.
4583///
4584/// \snippet AppWindow.cpp CreateCoreWebView2EnvironmentWithOptions
4585#[com_interface("2fde08a8-1e9a-4766-8c05-95a9ceb9d1c5")]
4586pub trait ICoreWebView2EnvironmentOptions: IUnknown {
4587 /// Changes the behavior of the WebView. The arguments are passed to the
4588 /// browser process as part of the command. For more information about
4589 /// using command-line switches with Chromium browser processes, navigate to
4590 /// \[Run Chromium with Flags\]\[ChromiumDevelopersHowTosRunWithFlags\].
4591 /// The value appended to a switch is appended to the browser process, for
4592 /// example, in `--edge-webview-switches=xxx` the value is `xxx`. If you
4593 /// specify a switch that is important to WebView functionality, it is
4594 /// ignored, for example, `--user-data-dir`. Specific features are disabled
4595 /// internally and blocked from being enabled. If a switch is specified
4596 /// multiple times, only the last instance is used.
4597 ///
4598 /// \> [!NOTE]\n\> A merge of the different values of the same switch is not attempted,
4599 /// except for disabled and enabled features. The features specified by
4600 /// `--enable-features` and `--disable-features` are merged with simple
4601 /// logic.\n\> * The features is the union of the specified features
4602 /// and built-in features. If a feature is disabled, it is removed from the
4603 /// enabled features list.
4604 ///
4605 /// If you specify command-line switches and use the
4606 /// `additionalBrowserArguments` parameter, the `--edge-webview-switches`
4607 /// value takes precedence and is processed last. If a switch fails to
4608 /// parse, the switched is ignored. The default state for the operation is
4609 /// to run the browser process with no extra flags.
4610 ///
4611 /// <!--TODO: replace https://aka.ms/RunChromiumWithFlags link with go link in the following line and delete this line. -->
4612 /// \[ChromiumDevelopersHowTosRunWithFlags\]: https://www.chromium.org/developers/how-tos/run-chromium-with-flags "Run Chromium with flags | The Chromium Projects"
4613 unsafe fn get_additional_browser_arguments(
4614 &self,
4615 /* out, retval */ value: *mut LPWSTR,
4616 ) -> HRESULT;
4617
4618 /// Sets the `AdditionalBrowserArguments` property.
4619 unsafe fn put_additional_browser_arguments(&self, /* in */ value: LPCWSTR) -> HRESULT;
4620
4621 /// The default display language for WebView. It applies to browser UI such as
4622 /// context menu and dialogs. It also applies to the `accept-languages` HTTP
4623 /// header that WebView sends to websites. It is in the format of
4624 /// `language[-country]` where `language` is the 2-letter code from
4625 /// <!--TODO: Update the link in the following line and delete this line. -->
4626 /// \[ISO 639\]\[ISO639LanguageCodesHtml\]
4627 /// and `country` is the
4628 /// 2-letter code from
4629 /// \[ISO 3166\]\[ISOStandard72482Html\].
4630 ///
4631 /// \[ISO639LanguageCodesHtml\]: https://www.iso.org/iso-639-language-codes.html "ISO 639 | ISO"
4632 ///
4633 /// \[ISOStandard72482Html\]: https://www.iso.org/standard/72482.html "ISO 3166-1:2020 | ISO"
4634 unsafe fn get_language(&self, /* out, retval */ value: *mut LPWSTR) -> HRESULT;
4635
4636 /// Sets the `Language` property.
4637 unsafe fn put_language(&self, /* in */ value: LPCWSTR) -> HRESULT;
4638
4639 /// Specifies the version of the WebView2 Runtime binaries required to be
4640 /// compatible with your app. This defaults to the WebView2 Runtime version
4641 /// that corresponds with the version of the SDK the app is using. The
4642 /// format of this value is the same as the format of the
4643 /// `BrowserVersionString` property and other `BrowserVersion` values. Only
4644 /// the version part of the `BrowserVersion` value is respected. The channel
4645 /// suffix, if it exists, is ignored. The version of the WebView2 Runtime
4646 /// binaries actually used may be different from the specified
4647 /// `TargetCompatibleBrowserVersion`. The binaries are only guaranteed to be
4648 /// compatible. Verify the actual version on the `BrowserVersionString`
4649 /// property on the `ICoreWebView2Environment`.
4650 unsafe fn get_target_compatible_browser_version(
4651 &self,
4652 /* out, retval */ value: *mut LPWSTR,
4653 ) -> HRESULT;
4654
4655 /// Sets the `TargetCompatibleBrowserVersion` property.
4656 unsafe fn put_target_compatible_browser_version(&self, /* in */ value: LPCWSTR) -> HRESULT;
4657
4658 /// The `AllowSingleSignOnUsingOSPrimaryAccount` property is used to enable
4659 /// single sign on with Azure Active Directory (AAD) and personal Microsoft
4660 /// Account (MSA) resources inside WebView. All AAD accounts, connected to
4661 /// Windows and shared for all apps, are supported. For MSA, SSO is only enabled
4662 /// for the account associated for Windows account login, if any.
4663 /// Default is disabled. Universal Windows Platform apps must also declare
4664 /// `enterpriseCloudSSO`
4665 /// \[Restricted capabilities\]\[WindowsUwpPackagingAppCapabilityDeclarationsRestrictedCapabilities\]
4666 /// for the single sign on (SSO) to work.
4667 ///
4668 /// \[WindowsUwpPackagingAppCapabilityDeclarationsRestrictedCapabilities\]: /windows/uwp/packaging/app-capability-declarations\#restricted-capabilities "Restricted capabilities - App capability declarations | Microsoft Docs"
4669 unsafe fn get_allow_single_sign_on_using_osprimary_account(
4670 &self,
4671 /* out, retval */ allow: *mut BOOL,
4672 ) -> HRESULT;
4673
4674 /// Sets the `AllowSingleSignOnUsingOSPrimaryAccount` property.
4675 unsafe fn put_allow_single_sign_on_using_osprimary_account(
4676 &self,
4677 /* in */ allow: BOOL,
4678 ) -> HRESULT;
4679}
4680
4681/// Receives the `WebView2Environment` created using
4682/// `CreateCoreWebView2Environment`.
4683#[com_interface("4e8a3389-c9d8-4bd2-b6b5-124fee6cc14d")]
4684pub trait ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler: IUnknown {
4685 /// Provides the completion status and result of the corresponding
4686 /// asynchronous method.
4687 unsafe fn invoke(
4688 &self,
4689 error_code: HRESULT,
4690 created_environment: *mut *mut ICoreWebView2EnvironmentVTable,
4691 ) -> HRESULT;
4692}
4693
4694/// A Receiver is created for a particular DevTools Protocol event and allows
4695/// you to subscribe and unsubscribe from that event. Obtained from the
4696/// WebView object using `GetDevToolsProtocolEventReceiver`.
4697#[com_interface("b32ca51a-8371-45e9-9317-af021d080367")]
4698pub trait ICoreWebView2DevToolsProtocolEventReceiver: IUnknown {
4699 /// Subscribe to a `DevToolsProtocol` event. The `Invoke` method of the
4700 /// `handler` runs whenever the corresponding `DevToolsProtocol` event runs.
4701 /// `Invoke` runs with an event args object containing the parameter object
4702 /// of the DevTools Protocol event as a JSON string.
4703 ///
4704 /// \snippet ScriptComponent.cpp DevToolsProtocolEventReceived
4705 unsafe fn add_dev_tools_protocol_event_received(
4706 &self,
4707 /* in */
4708 handler: *mut *mut ICoreWebView2DevToolsProtocolEventReceivedEventHandlerVTable,
4709 /* out */ token: *mut EventRegistrationToken,
4710 ) -> HRESULT;
4711
4712 /// Remove an event handler previously added with
4713 /// `add_DevToolsProtocolEventReceived`.
4714 unsafe fn remove_dev_tools_protocol_event_received(
4715 &self,
4716 /* in */ token: EventRegistrationToken,
4717 ) -> HRESULT;
4718}
4719
4720/// WebView2Frame provides direct access to the iframes information.
4721#[com_interface("f1131a5e-9ba9-11eb-a8b3-0242ac130003")]
4722pub trait ICoreWebView2Frame: IUnknown {
4723 /// The name of the iframe from the iframe html tag declaring it.
4724 /// Calling this method fails if it is called after the iframe is destroyed.
4725 unsafe fn get_name(&self, /* out, retval */ name: *mut LPWSTR) -> HRESULT;
4726
4727 /// Raised when the iframe changes its window.name property.
4728 unsafe fn add_name_changed(
4729 &self,
4730 /* in */ event_handler: *mut *mut ICoreWebView2FrameNameChangedEventHandlerVTable,
4731 /* out */ token: *mut EventRegistrationToken,
4732 ) -> HRESULT;
4733
4734 /// Remove an event handler previously added with add_NameChanged.
4735 unsafe fn remove_name_changed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
4736
4737 /// Add the provided host object to script running in the iframe with the
4738 /// specified name for the list of the specified origins. The host object
4739 /// will be accessible for this iframe only if the iframe's origin during
4740 /// access matches one of the origins which are passed. The provided origins
4741 /// will be normalized before comparing to the origin of the document.
4742 /// So the scheme name is made lower case, the host will be punycode decoded
4743 /// as appropriate, default port values will be removed, and so on.
4744 /// This means the origin's host may be punycode encoded or not and will match
4745 /// regardless. If list contains malformed origin the call will fail.
4746 /// The method can be called multiple times in a row without calling
4747 /// RemoveHostObjectFromScript for the same object name. It will replace
4748 /// the previous object with the new object and new list of origins.
4749 /// List of origins will be treated as following:
4750 /// 1. empty list - call will succeed and object will be added for the iframe
4751 /// but it will not be exposed to any origin;
4752 /// 2. list with origins - during access to host object from iframe the
4753 /// origin will be checked that it belongs to this list;
4754 /// 3. list with "*" element - host object will be available for iframe for
4755 /// all origins. We suggest not to use this feature without understanding
4756 /// security implications of giving access to host object from from iframes
4757 /// with unknown origins.
4758 /// Calling this method fails if it is called after the iframe is destroyed.
4759 /// \snippet ScenarioAddHostObject.cpp AddHostObjectToScriptWithOrigins
4760 /// For more information about host objects navigate to
4761 /// ICoreWebView2::AddHostObjectToScript.
4762 unsafe fn add_host_object_to_script_with_origins(
4763 &self,
4764 /* in */ name: LPCWSTR,
4765 /* in */ object: *mut VARIANT,
4766 /* in */ origins_count: u32,
4767 /* in, size_is(originsCount) */ origins: *mut LPCWSTR,
4768 ) -> HRESULT;
4769
4770 /// Remove the host object specified by the name so that it is no longer
4771 /// accessible from JavaScript code in the iframe. While new access
4772 /// attempts are denied, if the object is already obtained by JavaScript code
4773 /// in the iframe, the JavaScript code continues to have access to that
4774 /// object. Calling this method for a name that is already removed or was
4775 /// never added fails. If the iframe is destroyed this method will return fail
4776 /// also.
4777 unsafe fn remove_host_object_from_script(&self, /* in */ name: LPCWSTR) -> HRESULT;
4778
4779 /// The Destroyed event is raised when the iframe corresponding
4780 /// to this CoreWebView2Frame object is removed or the document
4781 /// containing that iframe is destroyed.
4782 unsafe fn add_destroyed(
4783 &self,
4784 /* in */ event_handler: *mut *mut ICoreWebView2FrameDestroyedEventHandlerVTable,
4785 /* out */ token: *mut EventRegistrationToken,
4786 ) -> HRESULT;
4787
4788 /// Remove an event handler previously added with add_Destroyed.
4789 unsafe fn remove_destroyed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
4790
4791 /// Check whether a frame is destroyed. Returns true during
4792 /// the Destroyed event.
4793 unsafe fn is_destroyed(&self, /* out, retval */ destroyed: *mut BOOL) -> HRESULT;
4794}
4795
4796/// Receives `FrameCreated` event.
4797#[com_interface("38059770-9baa-11eb-a8b3-0242ac130003")]
4798pub trait ICoreWebView2FrameCreatedEventHandler: IUnknown {
4799 /// Provides the result for the iframe created event.
4800 unsafe fn invoke(
4801 &self,
4802 /* in */ sender: *mut *mut ICoreWebView2VTable,
4803 /* in */ args: *mut *mut ICoreWebView2FrameCreatedEventArgsVTable,
4804 ) -> HRESULT;
4805}
4806
4807/// Receives `FrameNameChanged` event.
4808#[com_interface("435c7dc8-9baa-11eb-a8b3-0242ac130003")]
4809pub trait ICoreWebView2FrameNameChangedEventHandler: IUnknown {
4810 /// Provides the result for the iframe name changed event.
4811 /// No event args exist and the `args` parameter is set to `null`.
4812 unsafe fn invoke(
4813 &self,
4814 /* in */ sender: *mut *mut ICoreWebView2FrameVTable,
4815 /* in */ args: *mut *mut IUnknownVTable,
4816 ) -> HRESULT;
4817}
4818
4819/// Event args for the `FrameCreated` events.
4820#[com_interface("4d6e7b5e-9baa-11eb-a8b3-0242ac130003")]
4821pub trait ICoreWebView2FrameCreatedEventArgs: IUnknown {
4822 /// The frame which was created.
4823 unsafe fn get_frame(
4824 &self,
4825 /* out, retval */ frame: *mut *mut *mut ICoreWebView2FrameVTable,
4826 ) -> HRESULT;
4827}
4828
4829/// Receives `FrameDestroyed` event.
4830#[com_interface("59dd7b4c-9baa-11eb-a8b3-0242ac130003")]
4831pub trait ICoreWebView2FrameDestroyedEventHandler: IUnknown {
4832 /// Provides the result for the iframe destroyed event.
4833 /// No event args exist and the `args` parameter is set to `null`.
4834 unsafe fn invoke(
4835 &self,
4836 /* in */ sender: *mut *mut ICoreWebView2FrameVTable,
4837 /* in */ args: *mut *mut IUnknownVTable,
4838 ) -> HRESULT;
4839}
4840
4841/// Add an event handler for the `DownloadStarting` event.
4842#[com_interface("efedc989-c396-41ca-83f7-07f845a55724")]
4843pub trait ICoreWebView2DownloadStartingEventHandler: IUnknown {
4844 /// Provides the event args for the corresponding event.
4845 unsafe fn invoke(
4846 &self,
4847 /* in */ sender: *mut *mut ICoreWebView2VTable,
4848 /* in */ args: *mut *mut ICoreWebView2DownloadStartingEventArgsVTable,
4849 ) -> HRESULT;
4850}
4851
4852/// Event args for the `DownloadStarting` event.
4853#[com_interface("e99bbe21-43e9-4544-a732-282764eafa60")]
4854pub trait ICoreWebView2DownloadStartingEventArgs: IUnknown {
4855 /// Returns the `ICoreWebView2DownloadOperation` for the download that
4856 /// has started.
4857 unsafe fn get_download_operation(
4858 &self,
4859 /* out, retval */
4860 download_operation: *mut *mut *mut ICoreWebView2DownloadOperationVTable,
4861 ) -> HRESULT;
4862
4863 /// The host may set this flag to cancel the download. If canceled, the
4864 /// download save dialog is not displayed regardless of the
4865 /// `Handled` property.
4866 unsafe fn get_cancel(&self, /* out, retval */ cancel: *mut BOOL) -> HRESULT;
4867
4868 /// Sets the `Cancel` property.
4869 unsafe fn put_cancel(&self, /* in */ cancel: BOOL) -> HRESULT;
4870
4871 /// The path to the file. If setting the path, the host should ensure that it
4872 /// is an absolute path, including the file name, and that the path does not
4873 /// point to an existing file. If the path points to an existing file, the
4874 /// file will be overwritten. If the directory does not exist, it is created.
4875 unsafe fn get_result_file_path(
4876 &self,
4877 /* out, retval */ result_file_path: *mut LPWSTR,
4878 ) -> HRESULT;
4879
4880 /// Sets the `ResultFilePath` property.
4881 unsafe fn put_result_file_path(&self, /* in */ result_file_path: LPCWSTR) -> HRESULT;
4882
4883 /// The host may set this flag to `TRUE` to hide the default download dialog
4884 /// for this download. The download will progress as normal if it is not
4885 /// canceled, there will just be no default UI shown. By default the value is
4886 /// `FALSE` and the default download dialog is shown.
4887 unsafe fn get_handled(&self, /* out, retval */ handled: *mut BOOL) -> HRESULT;
4888
4889 /// Sets the `Handled` property.
4890 unsafe fn put_handled(&self, /* in */ handled: BOOL) -> HRESULT;
4891
4892 /// Returns an `ICoreWebView2Deferral` object. Use this operation to
4893 /// complete the event at a later time.
4894 unsafe fn get_deferral(
4895 &self,
4896 /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
4897 ) -> HRESULT;
4898}
4899
4900/// Implements the interface to receive `BytesReceivedChanged` event. Use the
4901/// `ICoreWebView2DownloadOperation.BytesReceived` property to get the received
4902/// bytes count.
4903#[com_interface("828e8ab6-d94c-4264-9cef-5217170d6251")]
4904pub trait ICoreWebView2BytesReceivedChangedEventHandler: IUnknown {
4905 /// Provides the event args for the corresponding event. No event args exist
4906 /// and the `args` parameter is set to `null`.
4907 unsafe fn invoke(
4908 &self,
4909 /* in */ sender: *mut *mut ICoreWebView2DownloadOperationVTable,
4910 /* in */ args: *mut *mut IUnknownVTable,
4911 ) -> HRESULT;
4912}
4913
4914/// Implements the interface to receive `EstimatedEndTimeChanged` event. Use the
4915/// `ICoreWebView2DownloadOperation.EstimatedEndTime` property to get the new
4916/// estimated end time.
4917#[com_interface("28f0d425-93fe-4e63-9f8d-2aeec6d3ba1e")]
4918pub trait ICoreWebView2EstimatedEndTimeChangedEventHandler: IUnknown {
4919 /// Provides the event args for the corresponding event. No event args exist
4920 /// and the `args` parameter is set to `null`.
4921 unsafe fn invoke(
4922 &self,
4923 /* in */ sender: *mut *mut ICoreWebView2DownloadOperationVTable,
4924 /* in */ args: *mut *mut IUnknownVTable,
4925 ) -> HRESULT;
4926}
4927
4928/// Implements the interface to receive `StateChanged` event. Use the
4929/// `ICoreWebView2DownloadOperation.State` property to get the current state,
4930/// which can be in progress, interrupted, or completed. Use the
4931/// `ICoreWebView2DownloadOperation.InterruptReason` property to get the
4932/// interrupt reason if the download is interrupted.
4933#[com_interface("81336594-7ede-4ba9-bf71-acf0a95b58dd")]
4934pub trait ICoreWebView2StateChangedEventHandler: IUnknown {
4935 /// Provides the event args for the corresponding event. No event args exist
4936 /// and the `args` parameter is set to `null`.
4937 unsafe fn invoke(
4938 &self,
4939 /* in */ sender: *mut *mut ICoreWebView2DownloadOperationVTable,
4940 /* in */ args: *mut *mut IUnknownVTable,
4941 ) -> HRESULT;
4942}
4943
4944/// Represents a download operation. Gives access to the download's metadata
4945/// and supports a user canceling, pausing, or resuming the download.
4946#[com_interface("3d6b6cf2-afe1-44c7-a995-c65117714336")]
4947pub trait ICoreWebView2DownloadOperation: IUnknown {
4948 /// Add an event handler for the `BytesReceivedChanged` event.
4949 ///
4950 /// \snippet ScenarioCustomDownloadExperience.cpp BytesReceivedChanged
4951 unsafe fn add_bytes_received_changed(
4952 &self,
4953 /* in */
4954 event_handler: *mut *mut ICoreWebView2BytesReceivedChangedEventHandlerVTable,
4955 /* out */ token: *mut EventRegistrationToken,
4956 ) -> HRESULT;
4957
4958 /// Remove an event handler previously added with `add_BytesReceivedChanged`.
4959 unsafe fn remove_bytes_received_changed(
4960 &self,
4961 /* in */ token: EventRegistrationToken,
4962 ) -> HRESULT;
4963
4964 /// Add an event handler for the `EstimatedEndTimeChanged` event.
4965 unsafe fn add_estimated_end_time_changed(
4966 &self,
4967 /* in */
4968 event_handler: *mut *mut ICoreWebView2EstimatedEndTimeChangedEventHandlerVTable,
4969 /* out */ token: *mut EventRegistrationToken,
4970 ) -> HRESULT;
4971
4972 /// Remove an event handler previously added with `add_EstimatedEndTimeChanged`.
4973 unsafe fn remove_estimated_end_time_changed(
4974 &self,
4975 /* in */ token: EventRegistrationToken,
4976 ) -> HRESULT;
4977
4978 /// Add an event handler for the `StateChanged` event.
4979 ///
4980 /// \snippet ScenarioCustomDownloadExperience.cpp StateChanged
4981 unsafe fn add_state_changed(
4982 &self,
4983 /* in */ event_handler: *mut *mut ICoreWebView2StateChangedEventHandlerVTable,
4984 /* out */ token: *mut EventRegistrationToken,
4985 ) -> HRESULT;
4986
4987 /// Remove an event handler previously added with `add_StateChanged`.
4988 unsafe fn remove_state_changed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;
4989
4990 /// The URI of the download.
4991 unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;
4992
4993 /// The Content-Disposition header value from the download's HTTP response.
4994 unsafe fn get_content_disposition(
4995 &self,
4996 /* out, retval */ content_disposition: *mut LPWSTR,
4997 ) -> HRESULT;
4998
4999 /// MIME type of the downloaded content.
5000 unsafe fn get_mime_type(&self, /* out, retval */ mime_type: *mut LPWSTR) -> HRESULT;
5001
5002 /// The expected size of the download in total number of bytes based on the
5003 /// HTTP Content-Length header. Returns -1 if the size is unknown.
5004 unsafe fn get_total_bytes_to_receive(
5005 &self,
5006 /* out, retval */ total_bytes_to_receive: *mut i64,
5007 ) -> HRESULT;
5008
5009 /// The number of bytes that have been written to the download file.
5010 unsafe fn get_bytes_received(&self, /* out, retval */ bytes_received: *mut i64) -> HRESULT;
5011
5012 /// The estimated end time in [ISO 8601 Date and Time Format](https://www.iso.org/iso-8601-date-and-time-format.html).
5013 unsafe fn get_estimated_end_time(
5014 &self,
5015 /* out, retval */ estimated_end_time: *mut LPWSTR,
5016 ) -> HRESULT;
5017
5018 /// The absolute path to the download file, including file name. Host can change
5019 /// this from `ICoreWebView2DownloadStartingEventArgs`.
5020 unsafe fn get_result_file_path(
5021 &self,
5022 /* out, retval */ result_file_path: *mut LPWSTR,
5023 ) -> HRESULT;
5024
5025 /// The state of the download. A download can be in progress, interrupted, or
5026 /// completed. See `COREWEBVIEW2_DOWNLOAD_STATE` for descriptions of states.
5027 unsafe fn get_state(
5028 &self,
5029 /* out, retval */ download_state: *mut DownloadState,
5030 ) -> HRESULT;
5031
5032 /// The reason why connection with file host was broken.
5033 unsafe fn get_interrupt_reason(
5034 &self,
5035 /* out, retval */ interrupt_reason: *mut DownloadInterruptReason,
5036 ) -> HRESULT;
5037
5038 /// Cancels the download. If canceled, the default download dialog shows
5039 /// that the download was canceled. Host should set the `Cancel` property from
5040 /// `ICoreWebView2SDownloadStartingEventArgs` if the download should be
5041 /// canceled without displaying the default download dialog.
5042 unsafe fn cancel(&self) -> HRESULT;
5043
5044 /// Pauses the download. If paused, the default download dialog shows that the
5045 /// download is paused. No effect if download is already paused. Pausing a
5046 /// download changes the state to `COREWEBVIEW2_DOWNLOAD_STATE_INTERRUPTED`
5047 /// with `InterruptReason` set to `COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_USER_PAUSED`.
5048 unsafe fn pause(&self) -> HRESULT;
5049
5050 /// Resumes a paused download. May also resume a download that was interrupted
5051 /// for another reason, if `CanResume` returns true. Resuming a download changes
5052 /// the state from `COREWEBVIEW2_DOWNLOAD_STATE_INTERRUPTED` to
5053 /// `COREWEBVIEW2_DOWNLOAD_STATE_IN_PROGRESS`.
5054 unsafe fn resume(&self) -> HRESULT;
5055
5056 /// Returns true if an interrupted download can be resumed. Downloads with
5057 /// the following interrupt reasons may automatically resume without you
5058 /// calling any methods:
5059 /// `COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE`,
5060 /// `COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH`,
5061 /// `COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT`.
5062 /// In these cases download progress may be restarted with `BytesReceived`
5063 /// reset to 0.
5064 unsafe fn get_can_resume(&self, /* out, retval */ can_resume: *mut BOOL) -> HRESULT;
5065}
5066
5067/// A continuation of the ICoreWebView2ProcessFailedEventArgs interface.
5068#[com_interface("4dab9422-46fa-4c3e-a5d2-41d2071d3680")]
5069pub trait ICoreWebView2ProcessFailedEventArgs2: ICoreWebView2ProcessFailedEventArgs {
5070 /// The reason for the process failure. The reason is always
5071 /// `COREWEBVIEW2_PROCESS_FAILED_REASON_UNEXPECTED` when `ProcessFailedKind`
5072 /// is `COREWEBVIEW2_PROCESS_FAILED_KIND_BROWSER_PROCESS_EXITED`, and
5073 /// `COREWEBVIEW2_PROCESS_FAILED_REASON_UNRESPONSIVE` when `ProcessFailedKind`
5074 /// is `COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_UNRESPONSIVE`.
5075 /// For other process failure kinds, the reason may be any of the reason
5076 /// values.
5077 unsafe fn get_reason(&self, /* out, retval */ reason: *mut ProcessFailedReason) -> HRESULT;
5078
5079 /// The exit code of the failing process, for telemetry purposes. The exit
5080 /// code is always `1` when `ProcessFailedKind` is
5081 /// `COREWEBVIEW2_PROCESS_FAILED_KIND_BROWSER_PROCESS_EXITED`, and
5082 /// `STILL_ACTIVE` (`259`) when `ProcessFailedKind` is
5083 /// `COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_UNRESPONSIVE`.
5084 unsafe fn get_exit_code(&self, /* out, retval */ exit_code: *mut i32) -> HRESULT;
5085
5086 /// Description of the process assigned by the WebView2 Runtime. This is a
5087 /// technical English term appropriate for logging or development purposes,
5088 /// and not localized for the end user. It applies to utility processes (for
5089 /// example, "Audio Service", "Video Capture") and plugin processes (for
5090 /// example, "Flash"). The returned `processDescription` is empty if the
5091 /// WebView2 Runtime did not assign a description to the process.
5092 unsafe fn get_process_description(
5093 &self,
5094 /* out, retval */ process_description: *mut LPWSTR,
5095 ) -> HRESULT;
5096
5097 /// The collection of `FrameInfo`s for frames in the `ICoreWebView2` that were
5098 /// being rendered by the failed process. The content in these frames is
5099 /// replaced with an error page.
5100 /// This is only available when `ProcessFailedKind` is
5101 /// `COREWEBVIEW2_PROCESS_FAILED_KIND_FRAME_RENDER_PROCESS_EXITED`;
5102 /// `frames` is `null` for all other process failure kinds, including the case
5103 /// in which the failed process was the renderer for the main frame and
5104 /// subframes within it, for which the failure kind is
5105 /// `COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_EXITED`.
5106 unsafe fn get_frame_infos_for_failed_process(
5107 &self,
5108 /* out, retval */ frames: *mut *mut *mut ICoreWebView2FrameInfoCollectionVTable,
5109 ) -> HRESULT;
5110}
5111
5112/// Collection of `FrameInfo`s (name and source). Used to list the affected
5113/// frames' info when a frame-only render process failure occurs in the
5114/// `ICoreWebView2`.
5115#[com_interface("8f834154-d38e-4d90-affb-6800a7272839")]
5116pub trait ICoreWebView2FrameInfoCollection: IUnknown {
5117 /// Gets an iterator over the collection of `FrameInfo`s.
5118 unsafe fn get_iterator(
5119 &self,
5120 /* out, retval */
5121 iterator: *mut *mut *mut ICoreWebView2FrameInfoCollectionIteratorVTable,
5122 ) -> HRESULT;
5123}
5124
5125/// Iterator for a collection of `FrameInfo`s. For more info, see
5126/// `ICoreWebView2ProcessFailedEventArgs2` and
5127/// `ICoreWebView2FrameInfoCollection`.
5128#[com_interface("1bf89e2d-1b2b-4629-b28f-05099b41bb03")]
5129pub trait ICoreWebView2FrameInfoCollectionIterator: IUnknown {
5130 /// `TRUE` when the iterator has not run out of `FrameInfo`s. If the
5131 /// collection over which the iterator is iterating is empty or if the
5132 /// iterator has gone past the end of the collection, then this is `FALSE`.
5133 unsafe fn get_has_current(&self, /* out, retval */ has_current: *mut BOOL) -> HRESULT;
5134
5135 /// Get the current `ICoreWebView2FrameInfo` of the iterator.
5136 unsafe fn get_current(
5137 &self,
5138 /* out, retval */ frame_info: *mut *mut *mut ICoreWebView2FrameInfoVTable,
5139 ) -> HRESULT;
5140
5141 /// Move the iterator to the next `FrameInfo` in the collection.
5142 unsafe fn move_next(&self, /* out, retval */ has_next: *mut BOOL) -> HRESULT;
5143}
5144
5145/// Provides a set of properties for a frame in the `ICoreWebView2`.
5146#[com_interface("da86b8a1-bdf3-4f11-9955-528cefa59727")]
5147pub trait ICoreWebView2FrameInfo: IUnknown {
5148 /// The name attribute of the frame, as in `<iframe name="frame-name" ...>`.
5149 /// The returned string is empty when the frame has no name attribute.
5150 unsafe fn get_name(&self, /* out, retval */ name: *mut LPWSTR) -> HRESULT;
5151
5152 /// The URI of the document in the frame.
5153 unsafe fn get_source(&self, /* out, retval */ source: *mut LPWSTR) -> HRESULT;
5154}
5155
5156/// This is the ICoreWebView2Interop interface.
5157/// Interop interface for the CoreWebView2 WinRT object to allow WinRT end
5158/// developers to be able to use COM interfaces as parameters for some methods.
5159#[com_interface("912b34a7-d10b-49c4-af18-7cb7e604e01a")]
5160pub trait ICoreWebView2Interop: IUnknown {
5161 /// Add the provided host object to script running in the WebView with the
5162 /// specified name.
5163 /// See the documentation for ICoreWebView2::AddHostObjectToScript for more
5164 /// information.
5165 unsafe fn add_host_object_to_script(
5166 &self,
5167 /* in */ name: LPCWSTR,
5168 /* in */ object: *mut VARIANT,
5169 ) -> HRESULT;
5170}
5171
5172/// This is the ICoreWebView2CompositionControllerInterop interface.
5173/// Interop interface for the CoreWebView2CompositionController WinRT object to
5174/// allow WinRT end developers to be able to use the COM interfaces as parameters
5175/// for some methods.
5176#[com_interface("8e9922ce-9c80-42e6-bad7-fcebf291a495")]
5177pub trait ICoreWebView2CompositionControllerInterop: IUnknown {
5178 /// Returns the UI Automation Provider for the WebView.
5179 unsafe fn get_uiaprovider(
5180 &self,
5181 /* out, retval */ provider: *mut *mut *mut IUnknownVTable,
5182 ) -> HRESULT;
5183
5184 /// The RootVisualTarget is a visual in the hosting app's visual tree. This
5185 /// visual is where the WebView will connect its visual tree. The app uses
5186 /// this visual to position the WebView within the app. The app still needs
5187 /// to use the Bounds property to size the WebView. The RootVisualTarget
5188 /// property can be an IDCompositionVisual or a
5189 /// Windows::UI::Composition::ContainerVisual. WebView will connect its visual
5190 /// tree to the provided visual before returning from the property setter. The
5191 /// app needs to commit on its device setting the RootVisualTarget property.
5192 /// The RootVisualTarget property supports being set to nullptr to disconnect
5193 /// the WebView from the app's visual tree.
5194 /// \snippet ViewComponent.cpp SetRootVisualTarget
5195 /// \snippet ViewComponent.cpp BuildDCompTree
5196 unsafe fn get_root_visual_target(
5197 &self,
5198 /* out, retval */ target: *mut *mut *mut IUnknownVTable,
5199 ) -> HRESULT;
5200
5201 /// Set the RootVisualTarget property.
5202 unsafe fn put_root_visual_target(
5203 &self,
5204 /* in */ target: *mut *mut IUnknownVTable,
5205 ) -> HRESULT;
5206}
5207
5208/// This is the ICoreWebView2EnvironmentInterop interface.
5209/// Interop interface for the CoreWebView2Environment WinRT object to allow
5210/// WinRT end developers to be able to use COM interfaces as parameters for some
5211/// methods.
5212#[com_interface("ee503a63-c1e2-4fbf-8a4d-824e95f8bb13")]
5213pub trait ICoreWebView2EnvironmentInterop: IUnknown {
5214 /// Returns the UI Automation Provider for the
5215 /// ICoreWebView2CompositionController that corresponds with the given HWND.
5216 unsafe fn get_provider_for_hwnd(
5217 &self,
5218 /* in */ hwnd: HWND,
5219 /* out, retval */ provider: *mut *mut *mut IUnknownVTable,
5220 ) -> HRESULT;
5221}