├── Images └── authentication.png ├── source ├── 5 │ ├── WebView2Loader.dll │ ├── Microsoft.Web.WebView2.Core.dll │ ├── Microsoft.Web.WebView2.Wpf.dll │ ├── Microsoft.Web.WebView2.WinForms.dll │ ├── runtimes │ │ ├── win-x64 │ │ │ └── native │ │ │ │ └── WebView2Loader.dll │ │ ├── win-x86 │ │ │ └── native │ │ │ │ └── WebView2Loader.dll │ │ └── win-arm64 │ │ │ └── native │ │ │ └── WebView2Loader.dll │ ├── Microsoft.Web.WebView2.WinForms.xml │ └── Microsoft.Web.WebView2.Wpf.xml └── 7 │ ├── WebView2Loader.dll │ ├── Microsoft.Web.WebView2.Core.dll │ ├── Microsoft.Web.WebView2.Wpf.dll │ ├── Microsoft.Web.WebView2.WinForms.dll │ ├── runtimes │ ├── win-x64 │ │ └── native │ │ │ └── WebView2Loader.dll │ ├── win-x86 │ │ └── native │ │ │ └── WebView2Loader.dll │ └── win-arm64 │ │ └── native │ │ └── WebView2Loader.dll │ └── Microsoft.Web.WebView2.WinForms.xml ├── README.md ├── LICENSE └── DestinyAPI.ps1 /Images/authentication.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/Images/authentication.png -------------------------------------------------------------------------------- /source/5/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/5/WebView2Loader.dll -------------------------------------------------------------------------------- /source/7/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/7/WebView2Loader.dll -------------------------------------------------------------------------------- /source/5/Microsoft.Web.WebView2.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/5/Microsoft.Web.WebView2.Core.dll -------------------------------------------------------------------------------- /source/5/Microsoft.Web.WebView2.Wpf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/5/Microsoft.Web.WebView2.Wpf.dll -------------------------------------------------------------------------------- /source/7/Microsoft.Web.WebView2.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/7/Microsoft.Web.WebView2.Core.dll -------------------------------------------------------------------------------- /source/7/Microsoft.Web.WebView2.Wpf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/7/Microsoft.Web.WebView2.Wpf.dll -------------------------------------------------------------------------------- /source/5/Microsoft.Web.WebView2.WinForms.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/5/Microsoft.Web.WebView2.WinForms.dll -------------------------------------------------------------------------------- /source/7/Microsoft.Web.WebView2.WinForms.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/7/Microsoft.Web.WebView2.WinForms.dll -------------------------------------------------------------------------------- /source/5/runtimes/win-x64/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/5/runtimes/win-x64/native/WebView2Loader.dll -------------------------------------------------------------------------------- /source/5/runtimes/win-x86/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/5/runtimes/win-x86/native/WebView2Loader.dll -------------------------------------------------------------------------------- /source/7/runtimes/win-x64/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/7/runtimes/win-x64/native/WebView2Loader.dll -------------------------------------------------------------------------------- /source/7/runtimes/win-x86/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/7/runtimes/win-x86/native/WebView2Loader.dll -------------------------------------------------------------------------------- /source/5/runtimes/win-arm64/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/5/runtimes/win-arm64/native/WebView2Loader.dll -------------------------------------------------------------------------------- /source/7/runtimes/win-arm64/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkasco/Destiny-API-PowerShell-Bootstrapper/HEAD/source/7/runtimes/win-arm64/native/WebView2Loader.dll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Destiny API PowerShell Bootstrapper 2 | This repo will help you quickly bootstrap initial authentication using the Bungie Destiny API. It uses WinForms with a modern webview2 control. 3 | 4 | ![Sample Pic](Images/authentication.png) 5 | 6 | Assumptions: 7 | - You are running the script with Windows PowerShell 5.1 or PowerShell 7 (Both assemblies have been provided, they vary due to WinForm differences between .NET Framework 4.x and .NET 7) 8 | - You have created a PRIVATE application at [https://www.bungie.net/en/Application](https://www.bungie.net/en/Application) 9 | - Capture the API Key, Client ID, and Client Secret 10 | - Set the redirect URI to "https://localhost.local" (The bootstrapper will handle capturing the auth code silently) 11 | 12 | *Note: If you'd like complete security peace at mind you can retrieve your own webview2 dlls if desired. I obtained mine by creating a basic winform application in Visual Studio and adding the **Microsoft.Web.WebView2** package via NuGet. Build then retrieve the required dlls.* 13 | 14 | Feel free to use as a jumpstart for your own projects. 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Nathan Kasco 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /DestinyAPI.ps1: -------------------------------------------------------------------------------- 1 | ################################################################# 2 | # Destiny API Bootstrapper # 3 | # Written By: Nathan Kasco # 4 | # Date: 3/26/2023 # 5 | ################################################################# 6 | 7 | param( 8 | [switch] 9 | $UseConfig #If desired, place JSON 1 level up from this folder in DestinyAPIConfig.json 10 | ) 11 | 12 | $ScriptPath = Split-Path $MyInvocation.MyCommand.Path 13 | 14 | #Configuration - Set variables here 15 | if(!($UseConfig)){ 16 | $env:BUNGIE_API_KEY = "" 17 | $clientId = "" 18 | $client_secret = "" 19 | $redirectUri = "https://localhost.local" #Override if desired, otherwise this must match what you configured for your app 20 | } else { 21 | $ConfigPath = "$ScriptPath\..\DestinyAPIConfig.json" 22 | $ConfigContent = Get-Content -Raw $ConfigPath 23 | $ConfigJSON = ConvertFrom-Json $ConfigContent 24 | $env:BUNGIE_API_KEY = $ConfigJSON.APIKey 25 | $clientId = $ConfigJSON.ClientID 26 | $client_secret = $ConfigJSON.ClientSecret 27 | $redirectUri = $ConfigJSON.RedirectURI 28 | } 29 | 30 | #TODO: Add logic to use a refresh token if one exists 31 | 32 | #Initialization 33 | try{ 34 | Write-Progress -Activity "Initializing..." 35 | Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop 36 | 37 | if($PSVersionTable.PSEdition -eq "Core"){ 38 | #Handle .NET 7 / PowerShell 7 39 | Add-Type -LiteralPath "$ScriptPath\source\7\Microsoft.Web.WebView2.WinForms.dll" -ErrorAction Stop 40 | Add-Type -LiteralPath "$ScriptPath\source\7\Microsoft.Web.WebView2.Core.dll" -ErrorAction Stop 41 | } else { 42 | #Handle .NET Framework / PowerShell 5.1 43 | Add-Type -LiteralPath "$ScriptPath\source\5\Microsoft.Web.WebView2.WinForms.dll" -ErrorAction Stop 44 | Add-Type -LiteralPath "$ScriptPath\source\5\Microsoft.Web.WebView2.Core.dll" -ErrorAction Stop 45 | } 46 | 47 | $authUrl = "https://www.bungie.net/en/OAuth/Authorize" 48 | $tokenUrl = "https://www.bungie.net/platform/app/oauth/token/" 49 | 50 | $authorizationUrl = "$($authUrl)?response_type=code&client_id=$clientId&state=1234&redirect_uri=$redirectUri" 51 | 52 | # Create a new form object 53 | $form = New-Object System.Windows.Forms.Form -ErrorAction Stop 54 | $form.Text = "Bungie.net Authorization" 55 | $form.Width = 800 56 | $form.Height = 600 57 | 58 | [Microsoft.Web.WebView2.WinForms.WebView2]$webview = New-Object 'Microsoft.Web.WebView2.WinForms.WebView2' 59 | $webview.CreationProperties = New-Object 'Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties' -ErrorAction Stop 60 | $webview.CreationProperties.UserDataFolder = "$ScriptPath\source\UserData" 61 | $webview.Dock = "Fill" 62 | $webview.source = $authorizationUrl 63 | 64 | #Since the redirect goes to localhost, close when it gets navigated there since there is nothing for the user to do 65 | $webview.Add_SourceChanged({ 66 | if($webview.source -match "localhost"){ 67 | $Form.close() | Out-Null 68 | } 69 | }) 70 | 71 | # Add the WebBrowser control to the form 72 | $form.Controls.Add($webview) 73 | 74 | $form.Add_Shown({$form.Activate()}) 75 | $form.ShowDialog() | Out-Null 76 | 77 | #Once the user closes the window the script will continue and find the auth code from the url source 78 | 79 | if($webview.source.query -match "code="){ 80 | $authorizationCode = $webview.source.query -replace "&state.*" -replace "\?code=" 81 | } else { 82 | Read-Host "Authentication failed, press enter to exit" 83 | Exit 1603 84 | } 85 | 86 | #Fetch an Access Token 87 | $tokenRequestParams = @{ 88 | grant_type = "authorization_code" 89 | code = $authorizationCode 90 | client_id = $clientId 91 | client_secret = $client_secret 92 | redirect_uri = $redirectUri 93 | } 94 | 95 | Write-Progress -Activity "Fetching auth token..." 96 | $tokenResponse = Invoke-RestMethod -Method Post -Uri $tokenUrl -Body $tokenRequestParams -ErrorAction Stop 97 | 98 | $accessToken = $tokenResponse.access_token 99 | $headers = @{ "Authorization" = "Bearer $accessToken"; "X-API-Key" = $env:BUNGIE_API_KEY } 100 | 101 | #IMPORTANT - AT THIS POINT YOU HAVE AN AUTH TOKEN, LISTED BELOW IS A SAMPLE OF HOW IT CAN BE USED 102 | 103 | #Get Bungie User Data 104 | $getUrl = "https://www.bungie.net/Platform/User/GetMembershipsForCurrentUser/" 105 | 106 | Write-Progress -Activity "Fetching profile data..." 107 | $userResponse = Invoke-RestMethod -Method Get -Uri $getUrl -Headers $headers -ErrorAction Stop 108 | $destinyMembershipId = $userResponse.Response.destinyMemberships[0].membershipId 109 | $membershipType = $userResponse.Response.destinyMemberships[0].membershipType 110 | 111 | $profileData = Invoke-RestMethod -Method Get -Uri "https://www.bungie.net/Platform/Destiny2/$membershipType/Profile/$destinyMembershipId/?components=100" -Headers $headers -ErrorAction Stop 112 | 113 | $profileData.response.profile.data 114 | Write-Progress -Activity " " -Completed 115 | } catch { 116 | Write-Error "An error occurred - $_" 117 | } 118 | Read-Host "Press enter to exit" -------------------------------------------------------------------------------- /source/5/Microsoft.Web.WebView2.WinForms.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.Web.WebView2.WinForms 5 | 6 | 7 | 8 | 9 | This class is a bundle of the most common parameters used to create and instances. 10 | Its main purpose is to be set to in order to customize the environment and/or controller used by a during implicit initialization. 11 | 12 | 13 | This class isn't intended to contain all possible environment or controller customization options. 14 | If you need complete control over the environment and/or controller used by a WebView2 control then you'll need to initialize the control explicitly by 15 | creating your own environment (with ) and/or controller options (with ) and passing them to 16 | *before* you set the property to anything. 17 | See the class documentation for an initialization overview. 18 | 19 | 20 | 21 | 22 | Creates a new instance of with default data for all properties. 23 | 24 | 25 | 26 | 27 | Gets or sets the value to pass as the browserExecutableFolder parameter of when creating an environment with this instance. 28 | 29 | 30 | 31 | 32 | Gets or sets the value to pass as the userDataFolder parameter of when creating an environment with this instance. 33 | 34 | 35 | 36 | 37 | Gets or sets the value to use for the Language property of the CoreWebView2EnvironmentOptions parameter passed to when creating an environment with this instance. 38 | 39 | 40 | 41 | 42 | Gets or sets the value to use for the ProfileName property of the CoreWebView2ControllerOptions parameter passed to CreateCoreWebView2ControllerWithOptionsAsync when creating an controller with this instance. 43 | 44 | 45 | 46 | 47 | Gets or sets the value to pass as the AdditionalBrowserArguments parameter of which is passed to when creating an environment with this instance. 48 | 49 | 50 | 51 | 52 | Gets or sets the value to use for the IsInPrivateModeEnabled property of the CoreWebView2ControllerOptions parameter passed to CreateCoreWebView2ControllerWithOptionsAsync when creating an controller with this instance. 53 | 54 | 55 | 56 | 57 | Create a using the current values of this instance's properties. 58 | 59 | A task which will provide the created environment on completion, or null if no environment-related options are set. 60 | 61 | As long as no other properties on this instance are changed, repeated calls to this method will return the same task/environment as earlier calls. 62 | If some other property is changed then the next call to this method will return a different task/environment. 63 | 64 | 65 | 66 | 67 | Creates a using the current values of this instance's properties. 68 | 69 | A object or null if no controller-related properties are set. 70 | Thrown if the parameter environment is null. 71 | 72 | 73 | 74 | Control to embed WebView2 in WinForms. 75 | 76 | 77 | 78 | 79 | Create a new WebView2 WinForms control. 80 | After construction the property is null. 81 | Call to initialize the underlying . 82 | 83 | 84 | This control is effectively a wrapper around the WebView2 COM API, which you can find documentation for here: https://aka.ms/webview2 85 | You can directly access the underlying ICoreWebView2 interface and all of its functionality by accessing the property. 86 | Some of the most common COM functionality is also accessible directly through wrapper methods/properties/events on the control. 87 | 88 | Upon creation, the control's CoreWebView2 property will be null. 89 | This is because creating the CoreWebView2 is an expensive operation which involves things like launching Edge browser processes. 90 | There are two ways to cause the CoreWebView2 to be created: 91 | 1) Call the method. This is referred to as explicit initialization. 92 | 2) Set the property. This is referred to as implicit initialization. 93 | Either option will start initialization in the background and return back to the caller without waiting for it to finish. 94 | To specify options regarding the initialization process, either pass your own to EnsureCoreWebView2Async or set the control's property prior to initialization. 95 | 96 | When initialization has finished (regardless of how it was triggered) then the following things will occur, in this order: 97 | 1) The control's event will be invoked. If you need to perform one time setup operations on the CoreWebView2 prior to its use then you should do so in a handler for that event. 98 | 2) If a Uri has been set to the property then the control will start navigating to it in the background (i.e. these steps will continue without waiting for the navigation to finish). 99 | 3) The Task returned from will complete. 100 | 101 | For more details about any of the methods/properties/events involved in the initialization process, see its specific documentation. 102 | 103 | Accelerator key presses (e.g. Ctrl+P) that occur within the control will 104 | fire standard key press events such as OnKeyDown. You can suppress the 105 | control's default implementation of an accelerator key press (e.g. 106 | printing, in the case of Ctrl+P) by setting the Handled property of its 107 | EventArgs to true. Also note that the underlying browser process is 108 | blocked while these handlers execute, so: 109 | 110 | 111 | You should avoid doing a lot of work in these handlers. 112 | 113 | 114 | Some of the WebView2 and CoreWebView2 APIs may throw errors if 115 | invoked within these handlers due to being unable to communicate with 116 | the browser process. 117 | 118 | 119 | If you need to do a lot of work and/or invoke WebView2 APIs in response to 120 | accelerator keys then consider kicking off a background task or queuing 121 | the work for later execution on the UI thread. 122 | 123 | 124 | 125 | 126 | Cleans up any resources being used. 127 | 128 | true if managed resources should be disposed; otherwise, false. 129 | 130 | 131 | 132 | Overrides the base OnPaint event to have custom actions 133 | in designer mode 134 | 135 | The graphics devices which is the source 136 | 137 | 138 | 139 | Overrides the base WndProc events to handle specific window messages. 140 | 141 | The Message object containing the HWND window message and parameters 142 | 143 | 144 | 145 | Gets or sets a bag of options which are used during initialization of the control's . 146 | This property cannot be modified (an exception will be thrown) after initialization of the control's CoreWebView2 has started. 147 | 148 | Thrown if initialization of the control's CoreWebView2 has already started. 149 | 150 | 151 | 152 | Explicitly trigger initialization of the control's . 153 | 154 | 155 | A pre-created that should be used to create the . 156 | Creating your own environment gives you control over several options that affect how the is initialized. 157 | If you pass null (the default value) then a default environment will be created and used automatically. 158 | 159 | 160 | A pre-created that should be used to create the . 161 | Creating your own controller options gives you control over several options that affect how the is initialized. 162 | If you pass a controllerOptions to this method then it will override any settings specified on the property. 163 | If you pass null (the default value) and no value has been set to then a default controllerOptions will be created and used automatically. 164 | 165 | 166 | A Task that represents the background initialization process. 167 | When the task completes then the property will be available for use (i.e. non-null). 168 | Note that the control's event will be invoked before the task completes 169 | or on exceptions. 170 | 171 | 172 | Unless previous initialization has already failed, calling this method additional times with the same parameter will have no effect (any specified environment is ignored) and return the same Task as the first call. 173 | Unless previous initialization has already failed, calling this method after initialization has been implicitly triggered by setting the property will have no effect if no environment is given 174 | and simply return a Task representing that initialization already in progress. 175 | Unless previous initialization has already failed, calling this method with a different environment after initialization has begun will result in an . For example, this can happen if you begin initialization 176 | by setting the property and then call this method with a new environment, if you begin initialization with and then call this method with a new 177 | environment, or if you begin initialization with one environment and then call this method with no environment specified. 178 | When this method is called after previous initialization has failed, it will trigger initialization of the control's again. 179 | Note that even though this method is asynchronous and returns a Task, it still must be called on the UI thread like most public functionality of most UI controls. 180 | 181 | The following summarizes the possible error values and a description of why these errors occur. 182 | 183 | 184 | Error Value 185 | Description 186 | 187 | 188 | HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) 189 | *\\Edge\\Application* path used in browserExecutableFolder. 190 | 191 | 192 | HRESULT_FROM_WIN32(ERROR_INVALID_STATE) 193 | Specified options do not match the options of the WebViews that are currently running in the shared browser process. 194 | 195 | 196 | HRESULT_FROM_WIN32(ERROR_INVALID_WINDOW_HANDLE) 197 | WebView2 Initialization failed due to an invalid host HWND parentWindow. 198 | 199 | 200 | HRESULT_FROM_WIN32(ERROR_DISK_FULL) 201 | WebView2 Initialization failed due to reaching the maximum number of installed runtime versions. 202 | 203 | 204 | HRESULT_FROM_WIN32(ERROR_PRODUCT_UNINSTALLED 205 | If the Webview depends upon an installed WebView2 Runtime version and it is uninstalled. 206 | 207 | 208 | HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) 209 | Could not find Edge installation. 210 | 211 | 212 | HRESULT_FROM_WIN32(ERROR_FILE_EXISTS) 213 | User data folder cannot be created because a file with the same name already exists. 214 | 215 | 216 | E_ACCESSDENIED 217 | Unable to create user data folder, Access Denied. 218 | 219 | 220 | E_FAIL 221 | Edge runtime unable to start. 222 | 223 | 224 | 225 | 226 | 227 | Thrown if this method is called with a different environment than when it was initialized. See Remarks for more info. 228 | 229 | 230 | Thrown if this instance of is already disposed, or if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 231 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 232 | 233 | 234 | 235 | 236 | Explicitly trigger initialization of the control's . 237 | 238 | 239 | A pre-created that should be used to create the . 240 | Creating your own environment gives you control over several options that affect how the is initialized. 241 | If you pass null then a default environment will be created and used automatically. 242 | 243 | 244 | A Task that represents the background initialization process. 245 | When the task completes then the property will be available for use (i.e. non-null). 246 | Note that the control's event will be invoked before the task completes 247 | or on exceptions. 248 | 249 | 250 | Unless previous initialization has already failed, calling this method additional times with the same parameter will have no effect (any specified environment is ignored) and return the same Task as the first call. 251 | Unless previous initialization has already failed, calling this method after initialization has been implicitly triggered by setting the property will have no effect if no environment is given 252 | and simply return a Task representing that initialization already in progress. 253 | Unless previous initialization has already failed, calling this method with a different environment after initialization has begun will result in an . For example, this can happen if you begin initialization 254 | by setting the property and then call this method with a new environment, if you begin initialization with and then call this method with a new 255 | environment, or if you begin initialization with one environment and then call this method with no environment specified. 256 | When this method is called after previous initialization has failed, it will trigger initialization of the control's again. 257 | Note that even though this method is asynchronous and returns a Task, it still must be called on the UI thread like most public functionality of most UI controls. 258 | 259 | 260 | Thrown if this method is called with a different environment than when it was initialized. See Remarks for more info. 261 | 262 | 263 | Thrown if this instance of is already disposed, or if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 264 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 265 | 266 | 267 | 268 | 269 | This is the private function which implements the actual background initialization task. 270 | Cannot be called if the control is already initialized or has been disposed. 271 | 272 | 273 | The environment to use to create the . 274 | If that is null then a default environment is created with and its default parameters. 275 | 276 | 277 | The controllerOptions to use to create the . 278 | If that is null then a default controllerOptions is created with its default parameters. 279 | 280 | A task representing the background initialization process. 281 | All the event handlers added here need to be removed in . 282 | 283 | 284 | 285 | Protected CreateParams property. Used to set custom window styles to the forms HWND. 286 | 287 | 288 | 289 | 290 | Protected VisibilityChanged handler. 291 | 292 | 293 | 294 | 295 | Protected SizeChanged handler. 296 | 297 | 298 | 299 | 300 | Protected Select method: override this to capture tab direction when WebView control is activated 301 | 302 | 303 | 304 | 305 | Protected OnGotFocus handler. 306 | 307 | 308 | 309 | 310 | Protected OnParentChanged handler. 311 | 312 | 313 | 314 | 315 | True if initialization finished successfully and the control is not disposed yet. 316 | 317 | 318 | 319 | 320 | Recursive retrieval of the parent control 321 | 322 | The control to get the parent for 323 | The root parent control 324 | 325 | 326 | 327 | The underlying CoreWebView2. Use this property to perform more operations on the WebView2 content than is exposed 328 | on the WebView2. This value is null until it is initialized and the object itself has undefined behaviour once the control is disposed. 329 | You can force the underlying CoreWebView2 to 330 | initialize via the method. 331 | 332 | Thrown if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 333 | 334 | 335 | 336 | The zoom factor for the WebView. 337 | 338 | 339 | 340 | 341 | Enable/disable external drop. 342 | 343 | 344 | 345 | 346 | The Source property is the URI of the top level document of the 347 | WebView2. Setting the Source is equivalent to calling . 348 | Setting the Source will trigger initialization of the , if not already initialized. 349 | The default value of Source is null, indicating that the is not yet initialized. 350 | 351 | Specified value is not an absolute . 352 | Specified value is null and the control is initialized. 353 | 354 | 355 | 356 | 357 | Returns true if the webview can navigate to a next page in the 358 | navigation history via the method. 359 | This is equivalent to the . 360 | If the underlying is not yet initialized, this property is false. 361 | 362 | 363 | 364 | 365 | 366 | Returns true if the webview can navigate to a previous page in the 367 | navigation history via the method. 368 | This is equivalent to the . 369 | If the underlying is not yet initialized, this property is false. 370 | 371 | 372 | 373 | 374 | 375 | The default background color for the WebView. 376 | 377 | 378 | 379 | 380 | Executes the provided script in the top level document of the . 381 | This is equivalent to . 382 | 383 | The underlying is not yet initialized. 384 | Thrown when browser process has unexpectedly and left this control in an invalid state. We are considering throwing a different type of exception for this case in the future. 385 | 386 | 387 | 388 | 389 | Reloads the top level document of the . 390 | This is equivalent to . 391 | 392 | The underlying is not yet initialized. 393 | Thrown when browser process has unexpectedly and left this control in an invalid state. We are considering throwing a different type of exception for this case in the future. 394 | 395 | 396 | 397 | 398 | Navigates to the next page in navigation history. 399 | This is equivalent to . 400 | If the underlying is not yet initialized, this method does nothing. 401 | 402 | 403 | 404 | 405 | 406 | Navigates to the previous page in navigation history. 407 | This is equivalent to . 408 | If the underlying is not yet initialized, this method does nothing. 409 | 410 | 411 | 412 | 413 | 414 | Renders the provided HTML as the top level document of the . 415 | This is equivalent to . 416 | 417 | The underlying is not yet initialized. 418 | Thrown when browser process has unexpectedly and left this control in an invalid state. We are considering throwing a different type of exception for this case in the future. 419 | The htmlContent parameter may not be larger than 2 MB (2 * 1024 * 1024 bytes) in total size. The origin of the new page is about:blank. 420 | 421 | 422 | 423 | 424 | Stops any in progress navigation in the . 425 | This is equivalent to . 426 | If the underlying is not yet initialized, this method does nothing. 427 | 428 | 429 | 430 | 431 | 432 | This event is triggered either 1) when the control's has finished being initialized (regardless of how it was triggered or whether it succeeded) but before it is used for anything 433 | OR 2) the initialization failed. 434 | You should handle this event if you need to perform one time setup operations on the CoreWebView2 which you want to affect all of its usages 435 | (e.g. adding event handlers, configuring settings, installing document creation scripts, adding host objects). 436 | 437 | 438 | This sender will be the WebView2 control, whose CoreWebView2 property will now be valid (i.e. non-null) for the first time 439 | if is true. 440 | Unlikely this event can fire second time (after reporting initialization success first) 441 | if the initialization is followed by navigation which fails. 442 | 443 | 444 | 445 | 446 | NavigationStarting dispatches before a new navigate starts for the top 447 | level document of the . 448 | This is equivalent to the event. 449 | 450 | 451 | 452 | 453 | 454 | NavigationCompleted dispatches after a navigate of the top level 455 | document completes rendering either successfully or not. 456 | This is equivalent to the event. 457 | 458 | 459 | 460 | 461 | 462 | WebMessageReceived dispatches after web content sends a message to the 463 | app host via chrome.webview.postMessage. 464 | This is equivalent to the event. 465 | 466 | 467 | 468 | 469 | 470 | SourceChanged dispatches after the property changes. This may happen 471 | during a navigation or if otherwise the script in the page changes the 472 | URI of the document. 473 | This is equivalent to the event. 474 | 475 | 476 | 477 | 478 | 479 | ContentLoading dispatches after a navigation begins to a new URI and the 480 | content of that URI begins to render. 481 | This is equivalent to the event. 482 | 483 | 484 | 485 | 486 | 487 | ZoomFactorChanged dispatches when the property changes. 488 | This is equivalent to the event. 489 | 490 | 491 | 492 | 493 | 494 | Required designer variable. 495 | 496 | 497 | 498 | 499 | Required method for Designer support - do not modify 500 | the contents of this method with the code editor. 501 | 502 | 503 | 504 | 505 | -------------------------------------------------------------------------------- /source/7/Microsoft.Web.WebView2.WinForms.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.Web.WebView2.WinForms 5 | 6 | 7 | 8 | 9 | This class is a bundle of the most common parameters used to create and instances. 10 | Its main purpose is to be set to in order to customize the environment and/or controller used by a during implicit initialization. 11 | 12 | 13 | This class isn't intended to contain all possible environment or controller customization options. 14 | If you need complete control over the environment and/or controller used by a WebView2 control then you'll need to initialize the control explicitly by 15 | creating your own environment (with ) and/or controller options (with ) and passing them to 16 | *before* you set the property to anything. 17 | See the class documentation for an initialization overview. 18 | 19 | 20 | 21 | 22 | Creates a new instance of with default data for all properties. 23 | 24 | 25 | 26 | 27 | Gets or sets the value to pass as the browserExecutableFolder parameter of when creating an environment with this instance. 28 | 29 | 30 | 31 | 32 | Gets or sets the value to pass as the userDataFolder parameter of when creating an environment with this instance. 33 | 34 | 35 | 36 | 37 | Gets or sets the value to use for the Language property of the CoreWebView2EnvironmentOptions parameter passed to when creating an environment with this instance. 38 | 39 | 40 | 41 | 42 | Gets or sets the value to use for the ProfileName property of the CoreWebView2ControllerOptions parameter passed to CreateCoreWebView2ControllerWithOptionsAsync when creating an controller with this instance. 43 | 44 | 45 | 46 | 47 | Gets or sets the value to pass as the AdditionalBrowserArguments parameter of which is passed to when creating an environment with this instance. 48 | 49 | 50 | 51 | 52 | Gets or sets the value to use for the IsInPrivateModeEnabled property of the CoreWebView2ControllerOptions parameter passed to CreateCoreWebView2ControllerWithOptionsAsync when creating an controller with this instance. 53 | 54 | 55 | 56 | 57 | Create a using the current values of this instance's properties. 58 | 59 | A task which will provide the created environment on completion, or null if no environment-related options are set. 60 | 61 | As long as no other properties on this instance are changed, repeated calls to this method will return the same task/environment as earlier calls. 62 | If some other property is changed then the next call to this method will return a different task/environment. 63 | 64 | 65 | 66 | 67 | Creates a using the current values of this instance's properties. 68 | 69 | A object or null if no controller-related properties are set. 70 | Thrown if the parameter environment is null. 71 | 72 | 73 | 74 | Control to embed WebView2 in WinForms. 75 | 76 | 77 | 78 | 79 | Create a new WebView2 WinForms control. 80 | After construction the property is null. 81 | Call to initialize the underlying . 82 | 83 | 84 | This control is effectively a wrapper around the WebView2 COM API, which you can find documentation for here: https://aka.ms/webview2 85 | You can directly access the underlying ICoreWebView2 interface and all of its functionality by accessing the property. 86 | Some of the most common COM functionality is also accessible directly through wrapper methods/properties/events on the control. 87 | 88 | Upon creation, the control's CoreWebView2 property will be null. 89 | This is because creating the CoreWebView2 is an expensive operation which involves things like launching Edge browser processes. 90 | There are two ways to cause the CoreWebView2 to be created: 91 | 1) Call the method. This is referred to as explicit initialization. 92 | 2) Set the property. This is referred to as implicit initialization. 93 | Either option will start initialization in the background and return back to the caller without waiting for it to finish. 94 | To specify options regarding the initialization process, either pass your own to EnsureCoreWebView2Async or set the control's property prior to initialization. 95 | 96 | When initialization has finished (regardless of how it was triggered) then the following things will occur, in this order: 97 | 1) The control's event will be invoked. If you need to perform one time setup operations on the CoreWebView2 prior to its use then you should do so in a handler for that event. 98 | 2) If a Uri has been set to the property then the control will start navigating to it in the background (i.e. these steps will continue without waiting for the navigation to finish). 99 | 3) The Task returned from will complete. 100 | 101 | For more details about any of the methods/properties/events involved in the initialization process, see its specific documentation. 102 | 103 | Accelerator key presses (e.g. Ctrl+P) that occur within the control will 104 | fire standard key press events such as OnKeyDown. You can suppress the 105 | control's default implementation of an accelerator key press (e.g. 106 | printing, in the case of Ctrl+P) by setting the Handled property of its 107 | EventArgs to true. Also note that the underlying browser process is 108 | blocked while these handlers execute, so: 109 | 110 | 111 | You should avoid doing a lot of work in these handlers. 112 | 113 | 114 | Some of the WebView2 and CoreWebView2 APIs may throw errors if 115 | invoked within these handlers due to being unable to communicate with 116 | the browser process. 117 | 118 | 119 | If you need to do a lot of work and/or invoke WebView2 APIs in response to 120 | accelerator keys then consider kicking off a background task or queuing 121 | the work for later execution on the UI thread. 122 | 123 | 124 | 125 | 126 | Cleans up any resources being used. 127 | 128 | true if managed resources should be disposed; otherwise, false. 129 | 130 | 131 | 132 | Overrides the base OnPaint event to have custom actions 133 | in designer mode 134 | 135 | The graphics devices which is the source 136 | 137 | 138 | 139 | Overrides the base WndProc events to handle specific window messages. 140 | 141 | The Message object containing the HWND window message and parameters 142 | 143 | 144 | 145 | Gets or sets a bag of options which are used during initialization of the control's . 146 | This property cannot be modified (an exception will be thrown) after initialization of the control's CoreWebView2 has started. 147 | 148 | Thrown if initialization of the control's CoreWebView2 has already started. 149 | 150 | 151 | 152 | Explicitly trigger initialization of the control's . 153 | 154 | 155 | A pre-created that should be used to create the . 156 | Creating your own environment gives you control over several options that affect how the is initialized. 157 | If you pass null (the default value) then a default environment will be created and used automatically. 158 | 159 | 160 | A pre-created that should be used to create the . 161 | Creating your own controller options gives you control over several options that affect how the is initialized. 162 | If you pass a controllerOptions to this method then it will override any settings specified on the property. 163 | If you pass null (the default value) and no value has been set to then a default controllerOptions will be created and used automatically. 164 | 165 | 166 | A Task that represents the background initialization process. 167 | When the task completes then the property will be available for use (i.e. non-null). 168 | Note that the control's event will be invoked before the task completes 169 | or on exceptions. 170 | 171 | 172 | Unless previous initialization has already failed, calling this method additional times with the same parameter will have no effect (any specified environment is ignored) and return the same Task as the first call. 173 | Unless previous initialization has already failed, calling this method after initialization has been implicitly triggered by setting the property will have no effect if no environment is given 174 | and simply return a Task representing that initialization already in progress. 175 | Unless previous initialization has already failed, calling this method with a different environment after initialization has begun will result in an . For example, this can happen if you begin initialization 176 | by setting the property and then call this method with a new environment, if you begin initialization with and then call this method with a new 177 | environment, or if you begin initialization with one environment and then call this method with no environment specified. 178 | When this method is called after previous initialization has failed, it will trigger initialization of the control's again. 179 | Note that even though this method is asynchronous and returns a Task, it still must be called on the UI thread like most public functionality of most UI controls. 180 | 181 | The following summarizes the possible error values and a description of why these errors occur. 182 | 183 | 184 | Error Value 185 | Description 186 | 187 | 188 | HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) 189 | *\\Edge\\Application* path used in browserExecutableFolder. 190 | 191 | 192 | HRESULT_FROM_WIN32(ERROR_INVALID_STATE) 193 | Specified options do not match the options of the WebViews that are currently running in the shared browser process. 194 | 195 | 196 | HRESULT_FROM_WIN32(ERROR_INVALID_WINDOW_HANDLE) 197 | WebView2 Initialization failed due to an invalid host HWND parentWindow. 198 | 199 | 200 | HRESULT_FROM_WIN32(ERROR_DISK_FULL) 201 | WebView2 Initialization failed due to reaching the maximum number of installed runtime versions. 202 | 203 | 204 | HRESULT_FROM_WIN32(ERROR_PRODUCT_UNINSTALLED 205 | If the Webview depends upon an installed WebView2 Runtime version and it is uninstalled. 206 | 207 | 208 | HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) 209 | Could not find Edge installation. 210 | 211 | 212 | HRESULT_FROM_WIN32(ERROR_FILE_EXISTS) 213 | User data folder cannot be created because a file with the same name already exists. 214 | 215 | 216 | E_ACCESSDENIED 217 | Unable to create user data folder, Access Denied. 218 | 219 | 220 | E_FAIL 221 | Edge runtime unable to start. 222 | 223 | 224 | 225 | 226 | 227 | Thrown if this method is called with a different environment than when it was initialized. See Remarks for more info. 228 | 229 | 230 | Thrown if this instance of is already disposed, or if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 231 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 232 | 233 | 234 | 235 | 236 | Explicitly trigger initialization of the control's . 237 | 238 | 239 | A pre-created that should be used to create the . 240 | Creating your own environment gives you control over several options that affect how the is initialized. 241 | If you pass null then a default environment will be created and used automatically. 242 | 243 | 244 | A Task that represents the background initialization process. 245 | When the task completes then the property will be available for use (i.e. non-null). 246 | Note that the control's event will be invoked before the task completes 247 | or on exceptions. 248 | 249 | 250 | Unless previous initialization has already failed, calling this method additional times with the same parameter will have no effect (any specified environment is ignored) and return the same Task as the first call. 251 | Unless previous initialization has already failed, calling this method after initialization has been implicitly triggered by setting the property will have no effect if no environment is given 252 | and simply return a Task representing that initialization already in progress. 253 | Unless previous initialization has already failed, calling this method with a different environment after initialization has begun will result in an . For example, this can happen if you begin initialization 254 | by setting the property and then call this method with a new environment, if you begin initialization with and then call this method with a new 255 | environment, or if you begin initialization with one environment and then call this method with no environment specified. 256 | When this method is called after previous initialization has failed, it will trigger initialization of the control's again. 257 | Note that even though this method is asynchronous and returns a Task, it still must be called on the UI thread like most public functionality of most UI controls. 258 | 259 | 260 | Thrown if this method is called with a different environment than when it was initialized. See Remarks for more info. 261 | 262 | 263 | Thrown if this instance of is already disposed, or if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 264 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 265 | 266 | 267 | 268 | 269 | This is the private function which implements the actual background initialization task. 270 | Cannot be called if the control is already initialized or has been disposed. 271 | 272 | 273 | The environment to use to create the . 274 | If that is null then a default environment is created with and its default parameters. 275 | 276 | 277 | The controllerOptions to use to create the . 278 | If that is null then a default controllerOptions is created with its default parameters. 279 | 280 | A task representing the background initialization process. 281 | All the event handlers added here need to be removed in . 282 | 283 | 284 | 285 | Protected CreateParams property. Used to set custom window styles to the forms HWND. 286 | 287 | 288 | 289 | 290 | Protected VisibilityChanged handler. 291 | 292 | 293 | 294 | 295 | Protected SizeChanged handler. 296 | 297 | 298 | 299 | 300 | Protected Select method: override this to capture tab direction when WebView control is activated 301 | 302 | 303 | 304 | 305 | Protected OnGotFocus handler. 306 | 307 | 308 | 309 | 310 | Protected OnParentChanged handler. 311 | 312 | 313 | 314 | 315 | True if initialization finished successfully and the control is not disposed yet. 316 | 317 | 318 | 319 | 320 | Recursive retrieval of the parent control 321 | 322 | The control to get the parent for 323 | The root parent control 324 | 325 | 326 | 327 | The underlying CoreWebView2. Use this property to perform more operations on the WebView2 content than is exposed 328 | on the WebView2. This value is null until it is initialized and the object itself has undefined behaviour once the control is disposed. 329 | You can force the underlying CoreWebView2 to 330 | initialize via the method. 331 | 332 | Thrown if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 333 | 334 | 335 | 336 | The zoom factor for the WebView. 337 | 338 | 339 | 340 | 341 | Enable/disable external drop. 342 | 343 | 344 | 345 | 346 | The Source property is the URI of the top level document of the 347 | WebView2. Setting the Source is equivalent to calling . 348 | Setting the Source will trigger initialization of the , if not already initialized. 349 | The default value of Source is null, indicating that the is not yet initialized. 350 | 351 | Specified value is not an absolute . 352 | Specified value is null and the control is initialized. 353 | 354 | 355 | 356 | 357 | Returns true if the webview can navigate to a next page in the 358 | navigation history via the method. 359 | This is equivalent to the . 360 | If the underlying is not yet initialized, this property is false. 361 | 362 | 363 | 364 | 365 | 366 | Returns true if the webview can navigate to a previous page in the 367 | navigation history via the method. 368 | This is equivalent to the . 369 | If the underlying is not yet initialized, this property is false. 370 | 371 | 372 | 373 | 374 | 375 | The default background color for the WebView. 376 | 377 | 378 | 379 | 380 | Executes the provided script in the top level document of the . 381 | This is equivalent to . 382 | 383 | The underlying is not yet initialized. 384 | Thrown when browser process has unexpectedly and left this control in an invalid state. We are considering throwing a different type of exception for this case in the future. 385 | 386 | 387 | 388 | 389 | Reloads the top level document of the . 390 | This is equivalent to . 391 | 392 | The underlying is not yet initialized. 393 | Thrown when browser process has unexpectedly and left this control in an invalid state. We are considering throwing a different type of exception for this case in the future. 394 | 395 | 396 | 397 | 398 | Navigates to the next page in navigation history. 399 | This is equivalent to . 400 | If the underlying is not yet initialized, this method does nothing. 401 | 402 | 403 | 404 | 405 | 406 | Navigates to the previous page in navigation history. 407 | This is equivalent to . 408 | If the underlying is not yet initialized, this method does nothing. 409 | 410 | 411 | 412 | 413 | 414 | Renders the provided HTML as the top level document of the . 415 | This is equivalent to . 416 | 417 | The underlying is not yet initialized. 418 | Thrown when browser process has unexpectedly and left this control in an invalid state. We are considering throwing a different type of exception for this case in the future. 419 | The htmlContent parameter may not be larger than 2 MB (2 * 1024 * 1024 bytes) in total size. The origin of the new page is about:blank. 420 | 421 | 422 | 423 | 424 | Stops any in progress navigation in the . 425 | This is equivalent to . 426 | If the underlying is not yet initialized, this method does nothing. 427 | 428 | 429 | 430 | 431 | 432 | This event is triggered either 1) when the control's has finished being initialized (regardless of how it was triggered or whether it succeeded) but before it is used for anything 433 | OR 2) the initialization failed. 434 | You should handle this event if you need to perform one time setup operations on the CoreWebView2 which you want to affect all of its usages 435 | (e.g. adding event handlers, configuring settings, installing document creation scripts, adding host objects). 436 | 437 | 438 | This sender will be the WebView2 control, whose CoreWebView2 property will now be valid (i.e. non-null) for the first time 439 | if is true. 440 | Unlikely this event can fire second time (after reporting initialization success first) 441 | if the initialization is followed by navigation which fails. 442 | 443 | 444 | 445 | 446 | NavigationStarting dispatches before a new navigate starts for the top 447 | level document of the . 448 | This is equivalent to the event. 449 | 450 | 451 | 452 | 453 | 454 | NavigationCompleted dispatches after a navigate of the top level 455 | document completes rendering either successfully or not. 456 | This is equivalent to the event. 457 | 458 | 459 | 460 | 461 | 462 | WebMessageReceived dispatches after web content sends a message to the 463 | app host via chrome.webview.postMessage. 464 | This is equivalent to the event. 465 | 466 | 467 | 468 | 469 | 470 | SourceChanged dispatches after the property changes. This may happen 471 | during a navigation or if otherwise the script in the page changes the 472 | URI of the document. 473 | This is equivalent to the event. 474 | 475 | 476 | 477 | 478 | 479 | ContentLoading dispatches after a navigation begins to a new URI and the 480 | content of that URI begins to render. 481 | This is equivalent to the event. 482 | 483 | 484 | 485 | 486 | 487 | ZoomFactorChanged dispatches when the property changes. 488 | This is equivalent to the event. 489 | 490 | 491 | 492 | 493 | 494 | Required designer variable. 495 | 496 | 497 | 498 | 499 | Required method for Designer support - do not modify 500 | the contents of this method with the code editor. 501 | 502 | 503 | 504 | 505 | -------------------------------------------------------------------------------- /source/5/Microsoft.Web.WebView2.Wpf.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.Web.WebView2.Wpf 5 | 6 | 7 | 8 | 9 | This class is a bundle of the most common parameters used to create and instances. 10 | Its main purpose is to be set to in order to customize the environment and/or controller used by a during implicit initialization. 11 | It is also a nice WPF integration utility which allows commonly used environment/controller parameters to be dependency properties and be created and used in markup. 12 | 13 | 14 | This class isn't intended to contain all possible environment or controller customization options. 15 | If you need complete control over the environment and/or controller used by a WebView2 control then you'll need to initialize the control explicitly by 16 | creating your own environment (with ) and/or controller options (with ) and passing them to 17 | *before* you set the property to anything. 18 | See the class documentation for an initialization overview. 19 | 20 | 21 | 22 | 23 | Creates a new instance of with default data for all properties. 24 | 25 | 26 | 27 | 28 | The WPF DependencyProperty which backs the property. 29 | 30 | 31 | 32 | 33 | Gets or sets the value to pass as the browserExecutableFolder parameter of when creating an environment with this instance. 34 | 35 | 36 | 37 | 38 | The WPF DependencyProperty which backs the property. 39 | 40 | 41 | 42 | 43 | Gets or sets the value to pass as the userDataFolder parameter of when creating an environment with this instance. 44 | 45 | 46 | 47 | 48 | The WPF DependencyProperty which backs the property. 49 | 50 | 51 | 52 | 53 | Gets or sets the value to use for the Language property of the CoreWebView2EnvironmentOptions parameter passed to when creating an environment with this instance. 54 | 55 | 56 | 57 | 58 | The WPF DependencyProperty which backs the property. 59 | 60 | 61 | 62 | 63 | Gets or sets the value to use for the AdditionalBrowserArguments property of the CoreWebView2EnvironmentOptions parameter passed to when creating an environment with this instance. 64 | 65 | 66 | 67 | 68 | The WPF DependencyProperty which backs the property. 69 | 70 | 71 | 72 | 73 | Gets or sets the value to use for the ProfileName property of the CoreWebView2ControllerOptions parameter passed to CreateCoreWebView2ControllerWithOptionsAsync when creating an controller with this instance. 74 | 75 | 76 | 77 | 78 | The WPF DependencyProperty which backs the property. 79 | 80 | 81 | 82 | 83 | Gets or sets the value to use for the IsInPrivateModeEnabled property of the CoreWebView2ControllerOptions parameter passed to CreateCoreWebView2ControllerWithOptionsAsync when creating an controller with this instance. 84 | 85 | 86 | 87 | 88 | Create a using the current values of this instance's properties. 89 | 90 | A task which will provide the created environment on completion, or null if no environment-related options are set. 91 | 92 | As long as no other properties on this instance are changed, repeated calls to this method will return the same task/environment as earlier calls. 93 | If some other property is changed then the next call to this method will return a different task/environment. 94 | 95 | 96 | 97 | 98 | Create a using the current values of this instance's properties. 99 | 100 | A object or null if no controller-related properties are set. 101 | Thrown if the parameter environment is null. 102 | 103 | 104 | 105 | Tracks the conditions which block implicit initialization and whether it has been requested or not. 106 | The analogy is a set of gates which are either open (implicit init allowed) or closed (will have to wait). 107 | All sub-gates must be open before implicit init can proceed. 108 | If implicit init is requested while the gate is open then it happens immediately. 109 | If it's requested while the gate is closed then it occurs when the gate becomes open. 110 | 111 | 112 | It should be reasonably straight-forward to expand this class in the future to: 113 | * add new sub-gates to further restrict when implicit initialization can occur 114 | * support storing and invoking multiple actions next time the gate is open instead of only one 115 | 116 | 117 | 118 | 119 | Tracks whether a sub-gate regarding / is open or closed. 120 | This sub-gate is only closed after calls to `BeginInit` and before an equal number of calls to `EndInit`. 121 | 122 | 123 | We don't want implicit initialization to occur in between those calls, 124 | because implicit initialization is a side effect of setting the Source property, 125 | and side effects of setting properties during that period are supposed to be delayed until `EndInit`. 126 | 127 | 128 | 129 | 130 | How many times has been called without being called. 131 | 132 | 133 | 134 | 135 | Tracks whether a sub-gate regarding is open or closed. 136 | This sub-gate is closed if `SynchronizationContext.Current == null`. 137 | 138 | 139 | Initialization won't work without a `SynchronizationContext` because otherwise an `await` might resume on a different thread. 140 | As far as I know so far this only occurs before an event loop as started on the running thread. 141 | Once there's an event loop running the `SynchronizationContext` ensures that `await`s resume in the same event loop (i.e. same thread). 142 | Although it's a rare corner case, it's possible to create a `Window` w/ `WebView2` before an app's event loop starts. 143 | This sub-gate handles that corner case. 144 | 145 | 146 | 147 | 148 | An action which will trigger initialization next time the gate is open (and only once). 149 | 150 | 151 | This basically tracks whether or not implicit initialization has been requested while the gate is closed. 152 | If this is non-null then it should be a delegate that calls . 153 | 154 | 155 | 156 | 157 | Closes the gate until is called an equal number of times. 158 | 159 | 160 | 161 | 162 | Opens the gate closed by after being called the same number of times. 163 | 164 | 165 | 166 | 167 | A handler that should be attached to an event which indicates that exists. 168 | The best one I know of right now is . 169 | When the handler is called, the gate will re-evaluate its state and potentially allow any pending initialization action. 170 | 171 | 172 | 173 | 174 | Run a given action when the gate is open. 175 | 176 | 177 | If the gate is currently open then the action runs immediately. 178 | Otherwise the action runs next time the gate is discovered to be open. 179 | The action is only ever run once; it will not run again a second/subsequent time the gate opens. 180 | If the gate is closed and another action is already pending then the new action *overwrites* the current one (i.e. the currently stored action will never run). 181 | To "forget" a currently stored action, pass `null`. 182 | 183 | Action to run when the gate is open, or null to clear a previously specified action. 184 | 185 | 186 | 187 | Examine our overall open/closed state and run any pending action if appropriate. 188 | 189 | 190 | 191 | 192 | A control to embed web content in a WPF application. 193 | 194 | 195 | This control is effectively a wrapper around the [WebView2 COM 196 | API](https://aka.ms/webview2). You can directly access the underlying 197 | ICoreWebView2 interface and all of its functionality by accessing the 198 | property. Some of the most common COM 199 | functionality is also accessible directly through wrapper 200 | methods/properties/events on the control. 201 | 202 | Upon creation, the control's property will be 203 | null. This is because creating the is an 204 | expensive operation which involves things like launching Edge browser 205 | processes. There are two ways to cause the to 206 | be created: 207 | 208 | 209 | Call the method. This is 210 | referred to as explicit initialization. 211 | 212 | 213 | Set the property (which could be done from 214 | markup, for example). This is referred to as implicit initialization. 215 | Either option will start initialization in the background and return 216 | back to the caller without waiting for it to finish. 217 | To specify options regarding the initialization process, either pass 218 | your own to or set the control's property prior to initialization. 221 | 222 | 223 | 224 | When initialization has finished (regardless of how it was triggered or 225 | whether it succeeded) then the following things will occur, in this 226 | order: 227 | 228 | 229 | The control's event 230 | will be invoked. If you need to perform one time setup operations on 231 | the prior to its use then you should 232 | do so in a handler for that event. 233 | 234 | 235 | If initialization was successful and a Uri has been set to the property then the control will start navigating to it in 237 | the background (i.e. these steps will continue without waiting for the 238 | navigation to finish). 239 | 240 | 241 | The Task returned from will 242 | complete. 243 | 244 | 245 | 246 | For more details about any of the methods/properties/events involved in 247 | the initialization process, see its specific documentation. 248 | 249 | Because the control's is a very heavyweight 250 | object (potentially responsible for multiple running processes and 251 | megabytes of disk space) the control implements to provide an explicit means to free it. 253 | Calling will release the 254 | and its underlying resources (except any that are also being used by other 255 | WebViews), and reset to null. After has been called the cannot be 257 | re-initialized, and any attempt to use functionality which requires it 258 | will throw an . 259 | 260 | Accelerator key presses (e.g. Ctrl+P) that occur within the control will 261 | fire standard key press events such as OnKeyDown. You can suppress the 262 | control's default implementation of an accelerator key press (e.g. 263 | printing, in the case of Ctrl+P) by setting the Handled property of its 264 | EventArgs to true. Also note that the underlying browser process is 265 | blocked while these handlers execute, so: 266 | 267 | 268 | You should avoid doing a lot of work in these handlers. 269 | 270 | 271 | Some of the WebView2 and CoreWebView2 APIs may throw errors if 272 | invoked within these handlers due to being unable to communicate with 273 | the browser process. 274 | 275 | 276 | If you need to do a lot of work and/or invoke WebView2 APIs in response to 277 | accelerator keys then consider kicking off a background task or queuing 278 | the work for later execution on the UI thread. 279 | 280 | Note that this control extends in order to embed 281 | windows which live outside of the WPF ecosystem. This has some 282 | implications regarding the control's input and output behavior as well as 283 | the functionality it "inherits" from and . 285 | See the and [WPF/Win32 286 | interop](https://docs.microsoft.com/dotnet/framework/wpf/advanced/wpf-and-win32-interoperation#hwnds-inside-wpf) 287 | documentation for more information. 288 | 289 | 290 | 291 | 292 | 293 | Creates a new instance of a WebView2 control. 294 | Note that the control's will be null until initialized. 295 | See the class documentation for an initialization overview. 296 | 297 | 298 | 299 | 300 | The WPF which backs the property. 301 | 302 | 303 | 304 | 305 | 306 | Gets or sets a bag of options which are used during initialization of the control's . 307 | Setting this property will not work after initialization of the control's has started (the old value will be retained). 308 | See the class documentation for an initialization overview. 309 | 310 | 311 | 312 | 313 | 314 | This is overridden from and is called to instruct us to create our HWND. 315 | 316 | The HWND that we should use as the parent of the one we create. 317 | The HWND that we created. 318 | 319 | 320 | 321 | 322 | This is overridden from and is called to instruct us to destroy our HWND. 323 | 324 | Our HWND that we need to destroy. 325 | 326 | 327 | 328 | 329 | This is overridden from and is called to provide us with Win32 messages that are sent to our hwnd. 330 | 331 | Window receiving the message (should always match our ). 332 | Indicates the message being received. See Win32 documentation for WM_* constant values. 333 | The "wParam" data being provided with the message. Meaning varies by message. 334 | The "lParam" data being provided with the message. Meaning varies by message. 335 | If true then the message will not be forwarded to any (more) handlers. 336 | Return value varies by message. 337 | 338 | 339 | 340 | 341 | Override for painting to draw 342 | 343 | The tools to handle the drawing via . 344 | 345 | 346 | 347 | Accesses the complete functionality of the underlying COM API. 348 | Returns null until initialization has completed. 349 | See the class documentation for an initialization overview. 350 | 351 | 352 | Thrown if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 353 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 354 | 355 | Thrown if has already been called on the control. 356 | 357 | 358 | 359 | 360 | 361 | This event is triggered either 362 | 1) when the control's has finished being initialized (regardless of how initialization was triggered) but before it is used for anything, or 363 | 2) if the initialization failed. 364 | You should handle this event if you need to perform one time setup operations on the which you want to affect all of its usages. 365 | (e.g. adding event handlers, configuring settings, installing document creation scripts, adding host objects). 366 | See the class documentation for an initialization overview. 367 | 368 | 369 | This sender will be the control, whose property will now be valid (i.e. non-null) for the first time 370 | if is true. 371 | Unlikely this event can fire second time (after reporting initialization success first) 372 | if the initialization is followed by navigation which fails. 373 | 374 | 375 | 376 | 377 | 378 | Explicitly triggers initialization of the control's . 379 | See the class documentation for an initialization overview. 380 | 381 | 382 | A pre-created that should be used to create the . 383 | Creating your own environment gives you control over several options that affect how the is initialized. 384 | If you pass an environment to this method then it will override any settings specified on the property. 385 | If you pass null (the default value) and no value has been set to then a default environment will be created and used automatically. 386 | 387 | 388 | A pre-created that should be used to create the . 389 | Creating your own controller options gives you control over several options that affect how the is initialized. 390 | If you pass a controllerOptions to this method then it will override any settings specified on the property. 391 | If you pass null (the default value) and no value has been set to then a default controllerOptions will be created and used automatically. 392 | 393 | 394 | A Task that represents the background initialization process. 395 | When the task completes then the property will be available for use (i.e. non-null). 396 | Note that the control's event will be invoked before the task completes. 397 | 398 | 399 | Unless previous initialization has already failed, calling this method additional times with the same parameter will have no effect (any specified environment is ignored) and return the same Task as the first call. 400 | Unless previous initialization has already failed, calling this method after initialization has been implicitly triggered by setting the property will have no effect if no environment is given 401 | and simply return a Task representing that initialization already in progress, unless previous initialization has already failed. 402 | Unless previous initialization has already failed, calling this method with a different environment after initialization has begun will result in an . For example, this can happen if you begin initialization 403 | by setting the property and then call this method with a new environment, if you begin initialization with and then call this method with a new 404 | environment, or if you begin initialization with one environment and then call this method with no environment specified. 405 | When this method is called after previous initialization has failed, it will trigger initialization of the control's again. 406 | Note that even though this method is asynchronous and returns a Task, it still must be called on the UI thread like most public functionality of most UI controls. 407 | 408 | The following summarizes the possible error values and a description of why these errors occur. 409 | 410 | 411 | Error Value 412 | Description 413 | 414 | 415 | HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) 416 | *\\Edge\\Application* path used in browserExecutableFolder. 417 | 418 | 419 | HRESULT_FROM_WIN32(ERROR_INVALID_STATE) 420 | Specified options do not match the options of the WebViews that are currently running in the shared browser process. 421 | 422 | 423 | HRESULT_FROM_WIN32(ERROR_INVALID_WINDOW_HANDLE) 424 | WebView2 Initialization failed due to an invalid host HWND parentWindow. 425 | 426 | 427 | HRESULT_FROM_WIN32(ERROR_DISK_FULL) 428 | WebView2 Initialization failed due to reaching the maximum number of installed runtime versions. 429 | 430 | 431 | HRESULT_FROM_WIN32(ERROR_PRODUCT_UNINSTALLED 432 | If the Webview depends upon an installed WebView2 Runtime version and it is uninstalled. 433 | 434 | 435 | HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) 436 | Could not find Edge installation. 437 | 438 | 439 | HRESULT_FROM_WIN32(ERROR_FILE_EXISTS) 440 | User data folder cannot be created because a file with the same name already exists. 441 | 442 | 443 | E_ACCESSDENIED 444 | Unable to create user data folder, Access Denied. 445 | 446 | 447 | E_FAIL 448 | Edge runtime unable to start. 449 | 450 | 451 | 452 | 453 | 454 | Thrown if this method is called with a different environment than when it was initialized. See Remarks for more info. 455 | 456 | 457 | Thrown if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 458 | May also be thrown if is null, which probably indicates that the application's event loop hasn't started yet. 459 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 460 | 461 | Thrown if has already been called on the control. 462 | 463 | 464 | 465 | 466 | 467 | Explicitly triggers initialization of the control's . 468 | See the class documentation for an initialization overview. 469 | 470 | 471 | A pre-created that should be used to create the . 472 | Creating your own environment gives you control over several options that affect how the is initialized. 473 | If you pass an environment to this method then it will override any settings specified on the property. 474 | If you pass null and no value has been set to then a default environment will be created and used automatically. 475 | 476 | 477 | A Task that represents the background initialization process. 478 | When the task completes then the property will be available for use (i.e. non-null). 479 | Note that the control's event will be invoked before the task completes. 480 | 481 | 482 | Unless previous initialization has already failed, calling this method additional times with the same parameter will have no effect (any specified environment is ignored) and return the same Task as the first call. 483 | Unless previous initialization has already failed, calling this method after initialization has been implicitly triggered by setting the property will have no effect if no environment is given 484 | and simply return a Task representing that initialization already in progress, unless previous initialization has already failed. 485 | Unless previous initialization has already failed, calling this method with a different environment after initialization has begun will result in an . For example, this can happen if you begin initialization 486 | by setting the property and then call this method with a new environment, if you begin initialization with and then call this method with a new 487 | environment, or if you begin initialization with one environment and then call this method with no environment specified. 488 | When this method is called after previous initialization has failed, it will trigger initialization of the control's again. 489 | Note that even though this method is asynchronous and returns a Task, it still must be called on the UI thread like most public functionality of most UI controls. 490 | 491 | 492 | Thrown if this method is called with a different environment than when it was initialized. See Remarks for more info. 493 | 494 | 495 | Thrown if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 496 | May also be thrown if is null, which probably indicates that the application's event loop hasn't started yet. 497 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 498 | 499 | Thrown if has already been called on the control. 500 | 501 | 502 | 503 | 504 | 505 | This is called by our base class according to the typical implementation of the pattern. 506 | We implement it by releasing all of our underlying COM resources, including our . 507 | 508 | True if a caller is explicitly calling Dispose, false if we're being finalized. 509 | 510 | 511 | 512 | This is an event handler for our CoreWebView2's ProcessFailedEvent 513 | 514 | 515 | 516 | 517 | This is a "gate" which controls whether or not implicit initialization can occur. 518 | If implicit initialization is triggered while the gate is closed, 519 | then the initialization should be delayed until the gate opens. 520 | When we want to trigger implicit initialization we route the call through this gate. 521 | If the gate is open then the initialization will proceed. 522 | If the gate is closed then it will remember to trigger the initialization when it opens. 523 | 524 | 525 | 526 | 527 | Implementation of the ISupportInitialize pattern. 528 | Prevents the control from implicitly initializing its until is called. 529 | Does *not* prevent explicit initialization of the CoreWebView2 (i.e. ). 530 | Mainly intended for use by interactive UI designers. 531 | 532 | 533 | Note that the "Initialize" in ISupportInitialize and the "Init" in BeginInit/EndInit mean 534 | something different and more general than this control's specific concept of initializing 535 | its CoreWebView2 (explicitly or implicitly). This ISupportInitialize pattern is a general 536 | way to set batches of properties on the control to their initial values without triggering 537 | any dependent side effects until all of the values are set (i.e. until EndInit is called). 538 | In the case of this control, a specific side effect to be avoided is triggering implicit 539 | initialization of the CoreWebView2 when setting the Source property. 540 | For example, normally if you set after you've already set Source, 541 | the data set to CreationProperties is ignored because implicit initialization has already started. 542 | However, if you set the two properties (in the same order) in between calls to BeginInit and 543 | EndInit then the implicit initialization of the CoreWebView2 is delayed until EndInit, so the data 544 | set to CreationProperties is still used even though it was set after Source. 545 | 546 | 547 | 548 | 549 | Implementation of the ISupportInitialize pattern. 550 | Invokes any functionality that has been delayed since the corresponding call to . 551 | Mainly intended for use by interactive UI designers. 552 | 553 | 554 | See the documentation of for more information. 555 | 556 | 557 | 558 | 559 | Updates one of our dependency properties to match a new value from the . 560 | It both sets the value and remembers (in _propertyChangingFromCore) that it came from the CoreWebView2 rather than the caller, 561 | allowing the property's "on changed" handler to alter its behavior based on where the new value came from. 562 | It's only intended to be called in a CoreWebView2 event handler that's informing us of a new property value. 563 | It's basically just a wrapper around the inherited SetCurrentValue which also maintains _propertyChangingFromCore. 564 | See the comments on for additional background info. 565 | One more thing worth explicitly stating is that it wraps SetCurrentValue rather than SetValue, 566 | in order to avoid overwriting any OneWay bindings that are set on the specified properties. 567 | Check the link https://stackoverflow.com/q/4230698 for more information about the difference between SetValue and SetCurrentValue. 568 | 569 | The property to change due to an equivalent change in the CoreWebView2. 570 | The new value from the CoreWebView2. 571 | 572 | 573 | 574 | Checks if a given property is currently being updated to match an equivalent change in the . 575 | This method should only be called from a property's "on changed" handler; it has no meaning at any other time. 576 | It is used to determine if the property is changing to match the CoreWebView2 or because the caller set it. 577 | Usually this is used in order to decide if the new value needs to be propagated down to the CoreWebView2. 578 | See the comments on for additional background info. 579 | 580 | The property to check. 581 | True if the property is changing to match the CoreWebView2, or false if the property was changed by the caller. 582 | 583 | 584 | 585 | Changes our controller's ParentWindow to the given HWND, along with any other necessary associated work. 586 | 587 | The new HWND to set as the controller's parent. IntPtr.Zero means that the controller will have no parent and the CoreWebView2 will be hidden. 588 | Whether or not to call as required. Defaults to true. If you pass false then you should call it yourself if required. 589 | 590 | Reparenting the controller isn't necessarily as simple as changing its ParentWindow property, 591 | and this method exists to ensure that any other work that needs to be done at the same time gets done. 592 | The reason that SyncControllerWithParentWindow isn't baked directly into this method is because 593 | sometimes we want to call the Sync functionality without necessarily reparenting (e.g. during initialization). 594 | 595 | 596 | 597 | 598 | Syncs visual/windowing information between the controller and its parent HWND. 599 | This should be called any time a new, non-null HWND is set as the controller's parent, 600 | including when the controller is first created. 601 | 602 | 603 | 604 | 605 | This is a handler for our base UIElement's IsVisibleChanged event. 606 | It's predictably fired whenever IsVisible changes, and IsVisible reflects the actual current visibility status of the control. 607 | We just need to pass this info through to our CoreWebView2Controller so it can save some effort when the control isn't visible. 608 | 609 | 610 | 611 | 612 | This is overridden from and called when our control's location has changed. 613 | The HwndHost takes care of updating the HWND we created. 614 | What we need to do is move our CoreWebView2 to match the new location. 615 | 616 | 617 | 618 | 619 | The WPF which backs the property. 620 | 621 | 622 | 623 | 624 | The top-level which the WebView is currently displaying (or will display once initialization of its is finished). 625 | Generally speaking, getting this property is equivalent to getting the property and setting this property (to a different value) is equivalent to calling the method. 626 | 627 | 628 | Getting this property before the has been initialized will retrieve the last Uri which was set to it, or null (the default) if none has been. 629 | Setting this property before the has been initialized will cause initialization to start in the background (if not already in progress), after which the will navigate to the specified . 630 | This property can never be set back to null or to a relative . 631 | See the class documentation for an initialization overview. 632 | 633 | Thrown if has already been called on the control. 634 | Thrown if the property is set to null. 635 | Thrown if the property is set to a relative (i.e. a whose property is false). 636 | 637 | 638 | 639 | 640 | This is a callback that WPF calls to validate a potential new Source value. 641 | 642 | 643 | True if the value is valid, false if it is not. 644 | If we return false then WPF should respond by throwing an . 645 | 646 | 647 | Note that we unfortunately can't treat null as invalid here because null is valid prior to initialization. 648 | 649 | 650 | 651 | 652 | This is a callback that WPF calls when the WPF Source property's value changes. 653 | This might have been triggered by either: 654 | 1) The caller set Source to programmatically trigger a navigation. 655 | 2) The CoreWebView changed its own source and we're just updating the dependency property to match. 656 | We use to distinguish the two cases. 657 | 658 | 659 | 660 | 661 | A wrapper around the . 662 | The only difference between this event and is the first parameter that's passed to handlers. 663 | Handlers of this event will receive the control, whereas handlers of will receive the instance. 664 | 665 | 666 | 667 | 668 | 669 | This is an event handler for our CoreWebView2's SourceChanged event. 670 | Unsurprisingly, it fires when the CoreWebView2's source URI has been changed. 671 | Note that there are two distinct triggers for this: 672 | 1) The CoreWebView2 was told to navigate programmatically (potentially by us, see SourcePropertyChanged). 673 | 2) The user interacted with the CoreWebView2, e.g. clicked a link. 674 | In either of the above cases, this event might trigger several times due to e.g. redirection. 675 | Aside from propagating to our own event, we just need to update our WPF Source property to match the CoreWebView2's. 676 | 677 | 678 | 679 | 680 | A wrapper around the . 681 | The only difference between this event and is the first parameter that's passed to handlers. 682 | Handlers of this event will receive the control, whereas handlers of will receive the instance. 683 | 684 | 685 | 686 | 687 | 688 | This is an event handler for our CoreWebView2's NavigationStarting event. 689 | We just need to propagate the event to WPF. 690 | 691 | 692 | 693 | 694 | A wrapper around the . 695 | The only difference between this event and is the first parameter that's passed to handlers. 696 | Handlers of this event will receive the control, whereas handlers of will receive the instance. 697 | 698 | 699 | 700 | 701 | 702 | This is an event handler for our CoreWebView2's NavigationCompleted event. 703 | We just need to propagate the event to WPF. 704 | 705 | 706 | 707 | 708 | This is an event handler for our CoreWebView2's HistoryChanged event. 709 | We're handling it in order to update our WPF CanGoBack and CanGoForward properties. 710 | 711 | 712 | 713 | 714 | The WPF which backs the property. 715 | 716 | 717 | 718 | 719 | Returns true if the WebView can navigate to a previous page in the navigation history. 720 | Wrapper around the property of . 721 | If isn't initialized yet then returns false. 722 | 723 | 724 | 725 | 726 | 727 | The WPF which backs the property. 728 | 729 | 730 | 731 | 732 | Returns true if the WebView can navigate to a next page in the navigation history. 733 | Wrapper around the property of . 734 | If isn't initialized yet then returns false. 735 | 736 | 737 | 738 | 739 | 740 | This is overridden from and is called to inform us that tabbing has caused the focus to move into our control/window. 741 | Since WPF can't manage the transition of focus to a non-WPF HWND, it delegates the transition to us here. 742 | So our job is just to place the focus in our external HWND. 743 | 744 | Information about how the focus is moving. 745 | true to indicate that we handled the navigation, or false to indicate that we didn't. 746 | 747 | 748 | 749 | This is overridden from and is called to inform us when we receive the keyboard focus. 750 | We handle this by passing the keyboard focus on to the underlying . 751 | We never want to land in a state where our window (this.Handle) actually has the keyboard focus. 752 | 753 | Arguments from the underlying GotKeyboardFocus event. 754 | 755 | Note that it's actually possible for us to receive keyboard focus without this method being called. 756 | One known case where that happens is when our parent window is deactivated while we have focus, then reactivated. 757 | We handle that case in . 758 | 759 | 760 | 761 | 762 | 763 | This is an event handler for our CoreWebView2Controller's MoveFocusRequested event. 764 | It fires when the CoreWebView2Controller has focus but wants to move it elsewhere in the app. 765 | E.g. this happens when the user tabs past the last item in the CoreWebView2 and focus needs to return to some other app control. 766 | So our job is just to tell WPF to move the focus on to the next control. 767 | Note that we don't propagate this event outward as a standard WPF routed event because we've implemented its purpose here. 768 | If users of the control want to track focus shifting in/out of the control, they should use standard WPF events. 769 | 770 | 771 | 772 | 773 | This is an event handler for our CoreWebView2Controller's GotFocus event. 774 | We just need to propagate the event to WPF. 775 | 776 | 777 | 778 | 779 | This is an event handler for our CoreWebView2Controller's LostFocus event. 780 | We just need to propagate the event to WPF. 781 | 782 | 783 | 784 | 785 | This is an event handler for our CoreWebView2Controller's AcceleratorKeyPressed event. 786 | This is called to inform us about key presses that are likely to have special behavior (e.g. esc, return, Function keys, letters with modifier keys). 787 | WPF can't detect this input because Windows sends it directly to the Win32 CoreWebView2Controller control. 788 | We implement this by generating standard WPF key input events, allowing callers to handle the input in the usual WPF way if they want. 789 | If nobody handles the WPF key events then we'll allow the default CoreWebView2Controller logic (if any) to handle it. 790 | Of the possible options, this implementation should provide the most flexibility to callers. 791 | 792 | 793 | 794 | 795 | This is overridden from and called to allow us to handle key press input. 796 | WPF should never actually call this in response to keyboard events because we're hosting a non-WPF window. 797 | When our window has focus Windows will send the input directly to it rather than to WPF's top-level window and input system. 798 | This override should only be called when we're explicitly forwarding accelerator key input from the CoreWebView2 to WPF (in CoreWebView2Controller_AcceleratorKeyPressed). 799 | Even then, this KeyDownEvent is only triggered because our PreviewKeyDownEvent implementation explicitly triggers it, matching WPF's usual system. 800 | So the process is: 801 | 802 | CoreWebView2Controller_AcceleratorKeyPressed 803 | PreviewKeyDownEvent 804 | KeyDownEvent 805 | OnKeyDown 806 | 807 | . 808 | 809 | 810 | 811 | 812 | See . 813 | 814 | 815 | 816 | 817 | This is the "Preview" (i.e. tunneling) version of , so it actually happens first. 818 | Like OnKeyDown, this will only ever be called if we're explicitly forwarding key presses from the CoreWebView2. 819 | In order to mimic WPF's standard input handling, when we receive this we turn around and fire off the standard bubbling KeyDownEvent. 820 | That way others in the WPF tree see the same standard pair of input events that WPF itself would have triggered if it were handling the key press. 821 | 822 | 823 | 824 | 825 | 826 | See . 827 | 828 | 829 | 830 | 831 | The WPF which backs the property. 832 | 833 | 834 | 835 | 836 | The zoom factor for the WebView. 837 | This property directly exposes , see its documentation for more info. 838 | Getting this property before the has been initialized will retrieve the last value which was set to it, or 1.0 (the default) if none has been. 839 | The most recent value set to this property before the CoreWebView2 has been initialized will be set on it after initialization. 840 | 841 | 842 | 843 | 844 | 845 | This is a callback that WPF calls when our WPF ZoomFactor property's value changes. 846 | This might have been triggered by either: 847 | 1) The caller set ZoomFactor to change the zoom of the CoreWebView2. 848 | 2) The CoreWebView2 changed its own ZoomFactor and we're just updating the dependency property to match. 849 | We use to distinguish the two cases. 850 | 851 | 852 | 853 | 854 | The event is raised when the property changes. 855 | This event directly exposes . 856 | 857 | 858 | 859 | 860 | 861 | 862 | This is an event handler for our CoreWebView2Controller's ZoomFactorChanged event. 863 | Unsurprisingly, it fires when the CoreWebView2Controller's ZoomFactor has been changed. 864 | Note that there are two distinct triggers for this: 865 | 1) The value was changed programmatically (potentially by us, see ZoomFactorPropertyChanged). 866 | 2) The user interacted with the CoreWebView2, e.g. CTRL + Mouse Wheel. 867 | Aside from propagating to our own event, we just need to update our WPF ZoomFactor property to match the CoreWebView2Controller's. 868 | 869 | 870 | 871 | 872 | The WPF which backs the property. 873 | 874 | 875 | 876 | 877 | The default background color for the WebView. 878 | This property directly exposes , see its documentation for more info. 879 | Getting this property before the has been initialized will retrieve the last value which was 880 | set to it, or Color.White (the default) if none has been. 881 | The most recent value set to this property before CoreWebView2Controller has been initialized will be set on it after initialization. 882 | 883 | 884 | 885 | 886 | This is a callback that WPF calls when our WPF DefaultBackgroundColor property's value changes. 887 | Since CoreWebView2Controller does not update this property itself, this is only triggered by the 888 | caller setting DefaultBackgroundColor. 889 | 890 | 891 | 892 | 893 | The WPF which backs the property. 894 | 895 | 896 | 897 | 898 | The AllowExternalDrop property for the WebView. 899 | This property directly exposes , see its documentation for more info. 900 | Getting this property before the has been initialized will retrieve the last value which was 901 | set to it, or true (the default) if none has been. 902 | The most recent value set to this property before CoreWebView2Controller has been initialized will be set on it after initialization. 903 | 904 | 905 | 906 | 907 | This is a callback that WPF calls when our WPF AllowExternalDrop property's value changes. 908 | Since CoreWebView2Controller does not update this property itself, this is only triggered by the 909 | caller setting AllowExternalDrop. 910 | 911 | 912 | 913 | 914 | The WPF which backs the property. 915 | 916 | 917 | 918 | 919 | The foreground color to be used in design mode. 920 | 921 | 922 | 923 | 924 | Navigates the WebView to the previous page in the navigation history. 925 | Equivalent to calling 926 | If hasn't been initialized yet then does nothing. 927 | 928 | 929 | Thrown if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 930 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 931 | 932 | Thrown if has already been called on the control. 933 | 934 | 935 | 936 | 937 | 938 | Navigates the WebView to the next page in the navigation history. 939 | Equivalent to calling . 940 | If hasn't been initialized yet then does nothing. 941 | 942 | 943 | Thrown if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 944 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 945 | 946 | Thrown if has already been called on the control. 947 | 948 | 949 | 950 | 951 | 952 | Reloads the current page. 953 | Equivalent to calling . 954 | 955 | 956 | Thrown if hasn't been initialized yet, or if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 957 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 958 | 959 | Thrown if has already been called on the control. 960 | 961 | 962 | 963 | 964 | 965 | Stops all navigations and pending resource fetches. 966 | Equivalent to calling . 967 | 968 | 969 | Thrown if hasn't been initialized yet, or if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 970 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 971 | 972 | Thrown if has already been called on the control. 973 | 974 | 975 | 976 | 977 | 978 | Initiates a navigation to htmlContent as source HTML of a new document. 979 | Equivalent to calling . 980 | 981 | 982 | Thrown if hasn't been initialized yet, or if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 983 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 984 | 985 | Thrown if has already been called on the control. 986 | The htmlContent parameter may not be larger than 2 MB (2 * 1024 * 1024 bytes) in total size. The origin of the new page is about:blank. 987 | 988 | 989 | 990 | 991 | 992 | A wrapper around the . 993 | The only difference between this event and is the first parameter that's passed to handlers. 994 | Handlers of this event will receive the control, whereas handlers of will receive the instance. 995 | 996 | 997 | 998 | 999 | 1000 | This is an event handler for our CoreWebView2's ContentLoading event. 1001 | We just need to propagate the event to WPF. 1002 | 1003 | 1004 | 1005 | 1006 | Executes JavaScript code from the javaScript parameter in the current top level document rendered in the WebView. 1007 | Equivalent to calling . 1008 | 1009 | 1010 | Thrown if hasn't been initialized yet, or if the calling thread isn't the thread which created this object (usually the UI thread). See for more info. 1011 | May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future. 1012 | 1013 | Thrown if has already been called on the control. 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | A wrapper around the . 1020 | The only difference between this event and is the first parameter that's passed to handlers. 1021 | Handlers of this event will receive the control, whereas handlers of will receive the instance. 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | This is an event handler for our CoreWebView2's WebMessageReceived event. 1028 | We just need to propagate the event to WPF. 1029 | 1030 | 1031 | 1032 | 1033 | True when we're in design mode and shouldn't create an underlying CoreWebView2. 1034 | 1035 | 1036 | 1037 | 1038 | --------------------------------------------------------------------------------