|
| 1 | +<!-- USAGE |
| 2 | + * Fill in each of the sections (like Background) below |
| 3 | + * Wrap code with `single line of code` or ```code block``` |
| 4 | + * Before submitting, delete all <!-- TEMPLATE marked comments in this file, |
| 5 | + and the following quote banner: |
| 6 | +--> |
| 7 | +# Background |
| 8 | +The browser has a Status bar that displays text when hovering over a link, or performing some activity. Currently, |
| 9 | +developers are able to opt in to disable showing the status bar through the browser |
| 10 | +settings. |
| 11 | + |
| 12 | +Developers would also like to be able to opt in to intercept the text which would |
| 13 | +normally be displayed by the Status bar, and show it using their own custom UI. |
| 14 | +# Description |
| 15 | +We propose a new event for WebView2 that would allow developers to |
| 16 | +listen for Status bar updates which are triggered by activity on the WebView, and then handle those updates however they want in their applications. |
| 17 | + |
| 18 | +Developers will be able to register an event handler for changes to the status bar text. |
| 19 | +# Examples |
| 20 | +## Win32 C++ Registering a listener for status bar text changes |
| 21 | +``` |
| 22 | +CHECK_FAILURE(m_webView->add_StatusBarTextChanged( |
| 23 | + Microsoft::WRL::Callback<ICoreWebView2StatusBarTextChangedEventHandler>( |
| 24 | + [this](ICoreWebView2* sender, ICoreWebView2StatusBarTextChangedEventArgs* args) -> HRESULT |
| 25 | + { |
| 26 | +
|
| 27 | + Microsoft::WRL::ComPtr<ICoreWebView2_5> webview5; |
| 28 | + CHECK_FAILURE(sender->QueryInterface(IID_PPV_ARGS(&webview5))); |
| 29 | + |
| 30 | + wil::unique_cotaskmem_string value; |
| 31 | + CHECK_FAILURE(webview5->get_StatusBarText(&value)); |
| 32 | + |
| 33 | + if (wcslen(value) != 0) |
| 34 | + { |
| 35 | +
|
| 36 | + m_statusBar.show(value); |
| 37 | + } else { |
| 38 | + |
| 39 | + m_statusBar.hide(); |
| 40 | + } |
| 41 | +
|
| 42 | + return S_OK; |
| 43 | + } |
| 44 | +).Get(), |
| 45 | +&m_statusBarTextChangedToken)); |
| 46 | +``` |
| 47 | +## .NET / WinRT Registering a listener for status bar text changes |
| 48 | +``` |
| 49 | +webView.CoreWebView2.StatusBarTextChanged += (CoreWebView2 sender, Object arg) => |
| 50 | +{ |
| 51 | + string value = sender.StatusBarText; |
| 52 | + // Handle status bar text in value |
| 53 | + if (value.Length != 0) { |
| 54 | + statusBar.show(value); |
| 55 | + } else { |
| 56 | + statusBar.hide(); |
| 57 | + } |
| 58 | +
|
| 59 | +}; |
| 60 | +``` |
| 61 | +# API Notes |
| 62 | +See [API Details](#api-details) Section below for API reference |
| 63 | +# API Details |
| 64 | +## Win32 C++ |
| 65 | +``` |
| 66 | +/// Interface for the status bar text changed event handler |
| 67 | +[uuid(85c8b75a-ceac-11eb-b8bc-0242ac130003), object, pointer_default(unique)] |
| 68 | +interface ICoreWebView2StatusBarTextChangedEventHandler : IUnknown { |
| 69 | + /// Called to provide the implementer with the event args for the |
| 70 | + /// corresponding event. |
| 71 | + HRESULT Invoke( |
| 72 | + [in] ICoreWebView2* sender, |
| 73 | + [in] ICoreWebView2StatusBarTextChangedEventArgs* args); |
| 74 | +} |
| 75 | +
|
| 76 | +/// Interface for status bar text change event args |
| 77 | +[uuid(2B9CAB1C-BE29-4FC8-BFDD-20AF170ACA7F), object, pointer_default(unique)] |
| 78 | +interface ICoreWebView2StatusBarTextChangedEventArgs : IUnknown { |
| 79 | +
|
| 80 | +} |
| 81 | +
|
| 82 | +[uuid(b2c01782-ceaf-11eb-b8bc-0242ac130003), object, pointer_default(unique)] |
| 83 | +interface ICoreWebView2_5 : ICoreWebView2_4 { |
| 84 | + /// Add an event handler for the `StatusBarTextChanged` event. |
| 85 | + /// `StatusBarTextChanged` runs when the WebView statusbar content changes |
| 86 | + /// status bar |
| 87 | + HRESULT add_StatusBarTextChanged( |
| 88 | + [in] ICoreWebView2StatusBarTextChangedEventHandler* eventHandler, |
| 89 | + [out] EventRegistrationToken* token); |
| 90 | +
|
| 91 | + /// Removing the event handler for `StatusBarTextChanged` event |
| 92 | + HRESULT remove_StatusBarTextChanged( |
| 93 | + [in] EventRegistrationToken token); |
| 94 | +
|
| 95 | + /// used to access the current value of the status bar text |
| 96 | + [propget] HRESULT StatusBarText([out, retval] LPWSTR* value); |
| 97 | +} |
| 98 | +``` |
| 99 | +## .Net/ WinRT |
| 100 | +``` |
| 101 | +namespace Microsoft.Web.WebView2.Core { |
| 102 | +
|
| 103 | +/// Interface for the status bar text changed event handler |
| 104 | + runtimeclass CoreWebView2 { |
| 105 | + event Windows.Foundation.TypedEventHandler<CoreWebView2, CoreWebView2StatusBarTextChangedEventArgs> StatusBarTextChanged; |
| 106 | + string StatusBarText {get;}; |
| 107 | + } |
| 108 | +} |
| 109 | +``` |
| 110 | +# Appendix |
| 111 | +<!-- TEMPLATE |
| 112 | + Anything else that you want to write down for posterity, but |
| 113 | + that isn't necessary to understand the purpose and usage of the API. |
| 114 | + For example, implementation details or links to other resources. |
| 115 | +--> |
| 116 | +See here for more details about the Status bar: <a href="https://www.computerhope.com/jargon/s/statusbar.htm">Here</a> |
0 commit comments