Skip to content

Commit

Permalink
Update to WebView2 NuGet 1.0.1150.38
Browse files Browse the repository at this point in the history
Renamed the "aWebView" parameter to "aFrame" in TWVBrowserBase.OnFrameNavigationStarting, TWVBrowserBase.OnFrameNavigationCompleted,
TWVBrowserBase.OnFrameContentLoading,
TWVBrowserBase.OnFrameDOMContentLoaded and
TWVBrowserBase.OnFrameWebMessageReceived
  • Loading branch information
salvadordf committed Mar 11, 2022
1 parent c48d2d9 commit 2b6fe85
Show file tree
Hide file tree
Showing 36 changed files with 1,552 additions and 414 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WebView4Delphi is an open source project created by Salvador Díaz Fau to embed

WebView4Delphi only supports Windows. If you need to embed a web browser in Linux, Windows or MacOS consider using [CEF4Delphi](https://github.com/salvadordf/CEF4Delphi) instead.

WebView4Delphi uses the [Microsoft Edge WebView2 Runtime](https://docs.microsoft.com/en-us/microsoft-edge/webview2/) and [Microsoft.Web.WebView2 NuGet package version 1.0.1108.44](https://www.nuget.org/packages/Microsoft.Web.WebView2) to embed a web browser.
WebView4Delphi uses the [Microsoft Edge WebView2 Runtime](https://docs.microsoft.com/en-us/microsoft-edge/webview2/) and [Microsoft.Web.WebView2 NuGet package version 1.0.1150.38](https://www.nuget.org/packages/Microsoft.Web.WebView2) to embed a web browser.

WebView4Delphi was developed and tested on Delphi 11.0, Delphi XE3 and Lazarus 2.2.0/FPC 3.2.2.

Expand Down
Binary file modified bin32/WebView2Loader.dll
Binary file not shown.
Binary file modified bin64/WebView2Loader.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion demos/Delphi_VCL/MiniBrowser/MiniBrowser.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ program MiniBrowser;
uses
Vcl.Forms,
uMiniBrowser in 'uMiniBrowser.pas' {MiniBrowserFrm},
uTextViewerForm in 'uTextViewerForm.pas' {TextViewerFrm};
uTextViewerForm in 'uTextViewerForm.pas' {TextViewerFrm},
uBasicUserAuthForm in 'uBasicUserAuthForm.pas' {TBasicUserAuthForm};

{$R *.res}

Expand Down
8 changes: 6 additions & 2 deletions demos/Delphi_VCL/MiniBrowser/MiniBrowser.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
<Form>TextViewerFrm</Form>
<FormType>dfm</FormType>
</DCCReference>
<DCCReference Include="uBasicUserAuthForm.pas">
<Form>TBasicUserAuthForm</Form>
<FormType>dfm</FormType>
</DCCReference>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
Expand All @@ -163,7 +167,7 @@
</Source>
</Delphi.Personality>
<Deployment Version="3">
<DeployFile LocalName="..\..\bin32\MiniBrowser.exe" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="..\..\..\bin32\MiniBrowser.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>MiniBrowser.exe</RemoteName>
<Overwrite>true</Overwrite>
Expand Down Expand Up @@ -972,8 +976,8 @@
<ProjectRoot Platform="OSX64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Android64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
Expand Down
110 changes: 110 additions & 0 deletions demos/Delphi_VCL/MiniBrowser/uBasicUserAuthForm.dfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
object TBasicUserAuthForm: TTBasicUserAuthForm
Left = 0
Top = 0
BorderIcons = [biSystemMenu]
BorderStyle = bsSingle
Caption = 'User authentication'
ClientHeight = 195
ClientWidth = 537
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Segoe UI'
Font.Style = []
Position = poScreenCenter
OnClose = FormClose
OnDestroy = FormDestroy
OnShow = FormShow
PixelsPerInch = 96
DesignSize = (
537
195)
TextHeight = 15
object InfoLbl: TLabel
Left = 40
Top = 16
Width = 308
Height = 15
Caption = 'Type your username and password for the following page :'
end
object UsernameLbl: TLabel
Left = 40
Top = 72
Width = 53
Height = 15
Caption = 'Username'
end
object PasswordLbl: TLabel
Left = 40
Top = 120
Width = 50
Height = 15
Caption = 'Password'
end
object URILbl: TLabel
Left = 40
Top = 37
Width = 3
Height = 15
end
object ButtonPnl: TPanel
Left = 0
Top = 160
Width = 537
Height = 35
Align = alBottom
BevelOuter = bvNone
Padding.Left = 40
Padding.Top = 5
Padding.Right = 40
Padding.Bottom = 5
TabOrder = 2
ExplicitWidth = 432
object OkBtn: TButton
Left = 40
Top = 5
Width = 120
Height = 25
Align = alLeft
Caption = 'Ok'
Enabled = False
ModalResult = 1
TabOrder = 0
OnClick = OkBtnClick
ExplicitHeight = 31
end
object CancelBtn: TButton
Left = 377
Top = 5
Width = 120
Height = 25
Align = alRight
Caption = 'Cancel'
ModalResult = 2
TabOrder = 1
OnClick = CancelBtnClick
ExplicitLeft = 317
ExplicitHeight = 31
end
end
object UsernameEdt: TEdit
Left = 120
Top = 69
Width = 377
Height = 23
Anchors = [akLeft, akTop, akRight]
TabOrder = 0
OnChange = UsernameEdtChange
end
object PasswordEdt: TEdit
Left = 120
Top = 117
Width = 377
Height = 23
Anchors = [akLeft, akTop, akRight]
PasswordChar = '*'
TabOrder = 1
OnChange = UsernameEdtChange
end
end
97 changes: 97 additions & 0 deletions demos/Delphi_VCL/MiniBrowser/uBasicUserAuthForm.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
unit uBasicUserAuthForm;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
uWVTypeLibrary, uWVCoreWebView2Args, uWVCoreWebView2Deferral;

type
TTBasicUserAuthForm = class(TForm)
ButtonPnl: TPanel;
OkBtn: TButton;
CancelBtn: TButton;
InfoLbl: TLabel;
UsernameLbl: TLabel;
PasswordLbl: TLabel;
UsernameEdt: TEdit;
PasswordEdt: TEdit;
URILbl: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure OkBtnClick(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure UsernameEdtChange(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FArgs : TCoreWebView2BasicAuthenticationRequestedEventArgs;
FDeferral : TCoreWebView2Deferral;
FOkPressed : boolean;
public
constructor Create(AOwner: TComponent; const aArgs : ICoreWebView2BasicAuthenticationRequestedEventArgs); reintroduce;
end;

implementation

{$R *.dfm}

uses
uWVCoreWebView2BasicAuthenticationResponse;

procedure TTBasicUserAuthForm.CancelBtnClick(Sender: TObject);
begin
close;
end;

constructor TTBasicUserAuthForm.Create(AOwner: TComponent; const aArgs : ICoreWebView2BasicAuthenticationRequestedEventArgs);
begin
inherited Create(AOwner);

FArgs := TCoreWebView2BasicAuthenticationRequestedEventArgs.Create(aArgs);
FDeferral := TCoreWebView2Deferral.Create(FArgs.Deferral);
FOkPressed := False;
end;

procedure TTBasicUserAuthForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if not(FOkPressed) then
FArgs.Cancel := True;

Action := TCloseAction.caFree;
end;

procedure TTBasicUserAuthForm.FormDestroy(Sender: TObject);
begin
if assigned(FDeferral) then
FreeAndNil(FDeferral);

if assigned(FArgs) then
FreeAndNil(FArgs);
end;

procedure TTBasicUserAuthForm.FormShow(Sender: TObject);
begin
URILbl.Caption := FArgs.URI;
end;

procedure TTBasicUserAuthForm.OkBtnClick(Sender: TObject);
var
TempResponse : TCoreWebView2BasicAuthenticationResponse;
begin
FOkPressed := True;

TempResponse := TCoreWebView2BasicAuthenticationResponse.Create(FArgs.Response);
TempResponse.Username := UsernameEdt.Text;
TempResponse.Password := PasswordEdt.Text;
TempResponse.Free;

close;
end;

procedure TTBasicUserAuthForm.UsernameEdtChange(Sender: TObject);
begin
OkBtn.Enabled := (length(UsernameEdt.Text) > 0) and (length(PasswordEdt.Text) > 0);
end;

end.
2 changes: 2 additions & 0 deletions demos/Delphi_VCL/MiniBrowser/uMiniBrowser.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ object MiniBrowserFrm: TMiniBrowserFrm
'https://html5demos.com/drag/'
'https://frames-per-second.appspot.com/'
'https://badssl.com/'
'https://www.httpwatch.com/httpgallery/authentication/'
'edge://flags/'
'edge://gpu/'
'edge://about/')
Expand Down Expand Up @@ -237,6 +238,7 @@ object MiniBrowserFrm: TMiniBrowserFrm
OnRetrieveHTMLCompleted = WVBrowser1RetrieveHTMLCompleted
OnRetrieveTextCompleted = WVBrowser1RetrieveTextCompleted
OnRetrieveMHTMLCompleted = WVBrowser1RetrieveMHTMLCompleted
OnBasicAuthenticationRequested = WVBrowser1BasicAuthenticationRequested
Left = 48
Top = 64
end
Expand Down
24 changes: 23 additions & 1 deletion demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ interface
WinApi.TlHelp32, Winapi.PsAPI,
uWVBrowser, uWVWinControl, uWVWindowParent, uWVTypes, uWVConstants, uWVTypeLibrary,
uWVLibFunctions, uWVLoader, uWVInterfaces, uWVCoreWebView2Args, uWVCoreWebView2DownloadOperation,
uWVBrowserBase;
uWVBrowserBase, uBasicUserAuthForm;

const
PWV_SHOWUSERAUTH = WM_APP + $A50;

type
TMiniBrowserFrm = class(TForm)
Expand Down Expand Up @@ -102,6 +105,7 @@ TMiniBrowserFrm = class(TForm)
procedure WVBrowser1RetrieveHTMLCompleted(Sender: TObject; aResult: Boolean; const aHTML: wvstring);
procedure WVBrowser1RetrieveTextCompleted(Sender: TObject; aResult: Boolean; const aText: wvstring);
procedure WVBrowser1RetrieveMHTMLCompleted(Sender: TObject; aResult: Boolean; const aMHTML: wvstring);
procedure WVBrowser1BasicAuthenticationRequested(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2BasicAuthenticationRequestedEventArgs);

protected
FDownloadOperation : TCoreWebView2DownloadOperation;
Expand All @@ -110,6 +114,7 @@ TMiniBrowserFrm = class(TForm)
FBlockImages : boolean;
FGetHeaders : boolean;
FHeaders : TStringList;
FUserAuthFrm : TTBasicUserAuthForm;

procedure UpdateNavButtons(aIsNavigating : boolean);
procedure UpdateDownloadInfo(aDownloadID : integer);
Expand All @@ -121,6 +126,7 @@ TMiniBrowserFrm = class(TForm)

procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
procedure ShowUserAuthMsg(var aMessage : TMessage); message PWV_SHOWUSERAUTH;
public
{ Public declarations }
end;
Expand Down Expand Up @@ -287,6 +293,7 @@ procedure TMiniBrowserFrm.FormCreate(Sender: TObject);
FGetHeaders := True;
FHeaders := TStringList.Create;
FFileStream := nil;
FUserAuthFrm := nil;
FBlockImages := False;
FDownloadIDGen := 0;
FDownloadOperation := nil;
Expand Down Expand Up @@ -437,6 +444,16 @@ procedure TMiniBrowserFrm.WVBrowser1AfterCreated(Sender: TObject);
WVBrowser1.AddWebResourceRequestedFilter('*', COREWEBVIEW2_WEB_RESOURCE_CONTEXT_MEDIA);
end;

procedure TMiniBrowserFrm.WVBrowser1BasicAuthenticationRequested(
Sender: TObject; const aWebView: ICoreWebView2;
const aArgs: ICoreWebView2BasicAuthenticationRequestedEventArgs);
begin
FUserAuthFrm := TTBasicUserAuthForm.Create(self, aArgs);
// Modal forms and dialogs must be shown outside WebView events
// https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/threading-model
PostMessage(Handle, PWV_SHOWUSERAUTH, 0, 0);
end;

procedure TMiniBrowserFrm.WVBrowser1BytesReceivedChanged(Sender: TObject;
const aDownloadOperation: ICoreWebView2DownloadOperation; aDownloadID : integer);
begin
Expand Down Expand Up @@ -732,6 +749,11 @@ procedure TMiniBrowserFrm.WMMoving(var aMessage : TMessage);
WVBrowser1.NotifyParentWindowPositionChanged;
end;

procedure TMiniBrowserFrm.ShowUserAuthMsg(var aMessage : TMessage);
begin
FUserAuthFrm.ShowModal;
end;

initialization
GlobalWebView2Loader := TWVLoader.Create(nil);
GlobalWebView2Loader.UserDataFolder := ExtractFileDir(Application.ExeName) + '\CustomCache';
Expand Down
Loading

0 comments on commit 2b6fe85

Please sign in to comment.