Skip to content

Commit d301c54

Browse files
authored
Added more details on certain edge case scenarios
Updated the comments in the docs so updated comments here.
1 parent f2b8e60 commit d301c54

1 file changed

Lines changed: 47 additions & 32 deletions

File tree

specs/GetFavicon.md

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Background
2-
A Favicon is an asset which is a part of a webpage, and typically displayed on each tab. Developers would
3-
like to have an API which allows them to retrieve the Favicon of a webpage, if it has one, as well as get an update whenever
4-
the favicon has changed.
2+
A Favicon is an asset which is a part of a webpage, and typically displayed on each tab. Developers would
3+
like to have an API which allows them to retrieve the Favicon of a webpage, if it has been set, as well as get an update whenever the favicon has changed.
54

65
# Description
76
We propose a new Webview2 event which would allow developers access the current Favicon of a page,
8-
as well as be notified when the favicon changes.
7+
as well as be notified when the favicon changes. This means when a page first loads, it would fire
8+
the Favicon change event as the icon has inialized to null. DOM or Javascript may change the Favicon,
9+
causing the event to fire again.
910

1011
# Examples
1112
## Win32 C++ Registering a listener for favicon changes
@@ -53,52 +54,66 @@ webView.CoreWebView2.FaviconChanged += (CoreWebView2 sender, Object arg) =>
5354
};
5455
```
5556
# API Notes
56-
If a Web page does not have a Favicon, then the event is not fired.
57+
If a Web page does not have a Favicon, then the event is only fires when the
58+
page is navigated to. The Favicon would be an empty image and Uri. The
59+
user is expected to handle this scenario.
5760
See [API Details](#api-details) Section below for API reference
5861
# API Details
5962
## Win32 C++
6063
```cpp
61-
/// Interface for the Favicon changed event handler
62-
[uuid(A0CDE626-8E5E-4EE2-9766-58F3696978FE), object, pointer_default(unique)]
63-
interface ICoreWebView2FaviconChangedEventHandler : IUnknown {
64-
/// Called to provide the implementer with the event args for the
65-
/// corresponding event.
64+
/// This interface is a handler for when the `Favicon` is changed.
65+
/// The sender is the embedded_browser which handle the change and the
66+
/// second argument is null.
67+
/// For more information see `add_FaviconChanged`.
68+
[uuid(2913DA94-833D-4DE0-8DCA-900FC524A1A4), object, pointer_default(unique)]
69+
interface ICoreWebView2ExperimentalFaviconChangedEventHandler : IUnknown {
70+
/// Called to notify the favicon changed.
6671
HRESULT Invoke(
6772
[in] ICoreWebView2* sender,
6873
[in] IUnknown* args);
6974
}
7075

71-
[uuid(93ACC5AD-DC22-419E-9A3F-75D96A1538E4), object, pointer_default(unique)]
72-
interface ICoreWebView2GetFaviconCompletedHandler : IUnknown {
73-
/// Called to provide the implementer with the completion information of CoreWebView2.GetFaviconAsync.
74-
/// corresponding event.
76+
/// This interface is a handler for the completion of the copying for the`imageStream`.
77+
/// The 'error_code` is E_NOT_SET if the there is no image. Otherwise error_code
78+
/// is the result from the image write operation.
79+
/// For more details, see the `GetFavicon` API.
80+
[uuid(A2508329-7DA8-49D7-8C05-FA125E4AEE8D), object, pointer_default(unique)]
81+
interface ICoreWebView2ExperimentalGetFaviconCompletedHandler : IUnknown {
82+
/// Called to notify the favicon has been retrieved.
7583
HRESULT Invoke([in] HRESULT error_code);
7684
}
7785

86+
/// This is the ICoreWebView2 Experimental Favicon interface.
87+
/// It has the capability to fire an event for the changing of the
88+
/// Favicon. When a new page loads event would fire due to Favicon not being set.
89+
/// The event would also set the Favicon when the set by DOM or Javascript.
7890
[uuid(DC838C64-F64B-4DC7-98EC-0992108E2157), object, pointer_default(unique)]
7991
interface ICoreWebView2_10 : ICoreWebView2_9 {
80-
/// Add an event handler for the `FaviconChanged` event.
81-
/// `FaviconChanged` is raised when the favicon of the top-level document of the WebView2 changes.
82-
HRESULT add_FaviconChanged(
83-
[in] ICoreWebView2FaviconChangedEventHandler* eventHandler,
92+
/// Add an event handler for the `FaviconChanged` event.
93+
HRESULT add_FaviconChanged(
94+
[in] ICoreWebView2ExperimentalFaviconChangedEventHandler* eventHandler,
8495
[out] EventRegistrationToken* token);
8596

86-
/// Remove an event handler from the `FaviconChanged` event.
87-
HRESULT remove_FaviconChanged(
88-
[in] EventRegistrationToken token);
89-
90-
/// Async function for getting the actual image data of the favicon
91-
HRESULT GetFaviconAsync(
97+
/// Remove the event handler for `FaviconChanged` event.
98+
HRESULT remove_FaviconChanged(
99+
[in] EventRegistrationToken token);
100+
101+
/// Get the current Uri of the favicon.
102+
/// If value is null, the `HRESULT` `E_POINTER`, otherwise it is `S_OK`.
103+
/// If a page has no favicon then value is an empty string.
104+
[propget] HRESULT FaviconUri([out, retval] LPWSTR* value);
105+
106+
/// Async function for getting the actual image data of the favicon.
107+
/// If the `imageStream` is null, the `HRESULT` will be `E_POINTER`, otherwise
108+
/// it is `S_OK`.
109+
/// The image is copied to the `imageStream` object and when complete,
110+
/// it will execute the `eventHandler` if it was set.
111+
HRESULT GetFavicon(
92112
[in] COREWEBVIEW2_FAVICON_IMAGE_FORMAT format,
93-
[in] IStream * imageStream,
94-
[in] ICoreWebView2GetFaviconCompletedHandler* eventHandler
95-
);
96-
97-
/// Used to access the current value of the favicon's URI.
98-
/// If a page has no favicon then this returns a nullptr.
99-
[propget] HRESULT FaviconUri([out, retval] LPWSTR* value);
100-
113+
[in] IStream* imageStream,
114+
[in] ICoreWebView2ExperimentalGetFaviconCompletedHandler* eventHandler);
101115
}
116+
102117
[v1_enum]
103118
typedef enum COREWEBVIEW2_FAVICON_IMAGE_FORMAT {
104119
/// Indicates that CoreWebView2.GetFaviconAsync should return the favicon in PNG format.

0 commit comments

Comments
 (0)