Skip to content

Commit

Permalink
Update to WebView2 NuGet 1.0.1185.39
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadordf committed Apr 16, 2022
1 parent e9fbb95 commit b92dd8d
Show file tree
Hide file tree
Showing 35 changed files with 1,852 additions and 175 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.1150.38](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.1185.39](https://www.nuget.org/packages/Microsoft.Web.WebView2) to embed a web browser.

WebView4Delphi was developed and tested on Delphi 11.1, 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.
12 changes: 3 additions & 9 deletions demos/Delphi_VCL/KioskBrowser/uKioskBrowser.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object MainForm: TMainForm
Font.Name = 'Segoe UI'
Font.Style = []
WindowState = wsMaximized
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 15
Expand Down Expand Up @@ -52,16 +53,9 @@ object MainForm: TMainForm
OnNewWindowRequested = WVBrowser1NewWindowRequested
OnWebMessageReceived = WVBrowser1WebMessageReceived
OnAcceleratorKeyPressed = WVBrowser1AcceleratorKeyPressed
OnWidget0CompMsg = WVBrowser1Widget0CompMsg
OnContextMenuRequested = WVBrowser1ContextMenuRequested
OnCustomItemSelected = WVBrowser1CustomItemSelected
Left = 200
Top = 160
end
object PopupMenu1: TPopupMenu
Left = 392
Top = 160
object ExitMi: TMenuItem
Caption = 'Exit'
OnClick = ExitMiClick
end
end
end
78 changes: 53 additions & 25 deletions demos/Delphi_VCL/KioskBrowser/uKioskBrowser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ TMainForm = class(TForm)
WVWindowParent1: TWVWindowParent;
Timer1: TTimer;
WVBrowser1: TWVBrowser;
PopupMenu1: TPopupMenu;
ExitMi: TMenuItem;
TouchKeyboard1: TTouchKeyboard;

procedure FormShow(Sender: TObject);
procedure ExitMiClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);

procedure WVBrowser1AfterCreated(Sender: TObject);
procedure WVBrowser1InitializationError(Sender: TObject; aErrorCode: HRESULT; const aErrorMessage: wvstring);
procedure WVBrowser1Widget0CompMsg(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
procedure WVBrowser1WebMessageReceived(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2WebMessageReceivedEventArgs);
procedure WVBrowser1AcceleratorKeyPressed(Sender: TObject; const aController: ICoreWebView2Controller; const aArgs: ICoreWebView2AcceleratorKeyPressedEventArgs);
procedure WVBrowser1NewWindowRequested(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2NewWindowRequestedEventArgs);
procedure WVBrowser1ContextMenuRequested(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2ContextMenuRequestedEventArgs);
procedure WVBrowser1CustomItemSelected(Sender: TObject; const aMenuItem: ICoreWebView2ContextMenuItem);

protected
FExitCommandID : integer;

// It's necessary to handle these messages to call NotifyParentWindowPositionChanged or some page elements will be misaligned.
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
Expand Down Expand Up @@ -67,9 +68,12 @@ implementation
// uWVLoader.pas. All browsers should be already destroyed before GlobalWebView2Loader
// is destroyed.

procedure TMainForm.ExitMiClick(Sender: TObject);
uses
uWVCoreWebView2ContextMenuItemCollection, uWVCoreWebView2ContextMenuItem;

procedure TMainForm.FormCreate(Sender: TObject);
begin
Close;
FExitCommandID := 0;
end;

procedure TMainForm.FormShow(Sender: TObject);
Expand Down Expand Up @@ -107,9 +111,50 @@ procedure TMainForm.WVBrowser1AfterCreated(Sender: TObject);

// Set the virtual host to map local files to any URL with a customhost.test domain
WVBrowser1.SetVirtualHostNameToFolderMapping('customhost.test', '..\assets', COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_ALLOW);
end;

// This demo disables the default context menu to show a custom TPopupMenu
WVBrowser1.DefaultContextMenusEnabled := False;
procedure TMainForm.WVBrowser1ContextMenuRequested(Sender: TObject;
const aWebView: ICoreWebView2;
const aArgs: ICoreWebView2ContextMenuRequestedEventArgs);
var
TempArgs : TCoreWebView2ContextMenuRequestedEventArgs;
TempCollection : TCoreWebView2ContextMenuItemCollection;
TempMenuItemItf : ICoreWebView2ContextMenuItem;
TempMenuItem : TCoreWebView2ContextMenuItem;
begin
TempArgs := TCoreWebView2ContextMenuRequestedEventArgs.Create(aArgs);
TempCollection := TCoreWebView2ContextMenuItemCollection.Create(TempArgs.MenuItems);
TempMenuItem := nil;

try
TempCollection.RemoveAllMenuItems;

if WVBrowser1.CoreWebView2Environment.CreateContextMenuItem('Exit', nil, COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_COMMAND, TempMenuItemItf) then
try
TempMenuItem := TCoreWebView2ContextMenuItem.Create(TempMenuItemItf);
FExitCommandID := TempMenuItem.CommandId;
TempMenuItem.AddCustomItemSelectedEvent(WVBrowser1);
TempCollection.InsertValueAtIndex(0, TempMenuItemItf);
finally
FreeAndNil(TempMenuItem);
end;
finally
FreeAndNil(TempCollection);
FreeAndNil(TempArgs);
end;
end;

procedure TMainForm.WVBrowser1CustomItemSelected(Sender: TObject;
const aMenuItem: ICoreWebView2ContextMenuItem);
var
TempMenuItem : TCoreWebView2ContextMenuItem;
begin
TempMenuItem := TCoreWebView2ContextMenuItem.Create(aMenuItem);

if (TempMenuItem.CommandId = FExitCommandID) then
PostMessage(Handle, WM_CLOSE, 0, 0);

FreeAndNil(TempMenuItem);
end;

procedure TMainForm.WVBrowser1InitializationError(Sender: TObject;
Expand Down Expand Up @@ -144,23 +189,6 @@ procedure TMainForm.WVBrowser1WebMessageReceived(Sender: TObject;
TempArgs.Free;
end;

procedure TMainForm.WVBrowser1Widget0CompMsg(Sender: TObject;
var aMessage: TMessage; var aHandled: Boolean);
var
TempPoint: TPoint;
begin
// We intercept this message to get the mouse coordinates and show our custom TPopupMenu.
// This demo the popup menu only has one option to exit.
if (aMessage.Msg = WM_PARENTNOTIFY) and (aMessage.WParam = WM_RBUTTONDOWN) then
begin
TempPoint.x := aMessage.lParam and $FFFF;
TempPoint.y := (aMessage.lParam and $FFFF0000) shr 16;
TempPoint := WVWindowParent1.ClientToScreen(TempPoint);

PopupMenu1.Popup(TempPoint.x, TempPoint.y);
end;
end;

procedure TMainForm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
Expand Down
1 change: 1 addition & 0 deletions demos/Delphi_VCL/MiniBrowser/uMiniBrowser.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ object MiniBrowserFrm: TMiniBrowserFrm
OnRetrieveTextCompleted = WVBrowser1RetrieveTextCompleted
OnRetrieveMHTMLCompleted = WVBrowser1RetrieveMHTMLCompleted
OnBasicAuthenticationRequested = WVBrowser1BasicAuthenticationRequested
OnStatusBarTextChanged = WVBrowser1StatusBarTextChanged
Left = 48
Top = 64
end
Expand Down
8 changes: 8 additions & 0 deletions demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ TMiniBrowserFrm = class(TForm)
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);
procedure WVBrowser1StatusBarTextChanged(Sender: TObject;
const aWebView: ICoreWebView2);

protected
FDownloadOperation : TCoreWebView2DownloadOperation;
Expand Down Expand Up @@ -634,6 +636,12 @@ procedure TMiniBrowserFrm.WVBrowser1SourceChanged(Sender: TObject; const aWebVie
URLCbx.Text := WVBrowser1.Source;
end;

procedure TMiniBrowserFrm.WVBrowser1StatusBarTextChanged(Sender: TObject;
const aWebView: ICoreWebView2);
begin
StatusBar1.Panels[0].Text := WVBrowser1.StatusBarText;
end;

procedure TMiniBrowserFrm.WVBrowser1WebResourceRequested(Sender: TObject;
const aWebView: ICoreWebView2;
const aArgs: ICoreWebView2WebResourceRequestedEventArgs);
Expand Down
Loading

0 comments on commit b92dd8d

Please sign in to comment.