Skip to content

Commit

Permalink
Update to WebView2 NuGet 1.0.1823.32
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadordf committed Jun 6, 2023
1 parent 25da452 commit ab710a8
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 14 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.1774.30](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.1823.32](https://www.nuget.org/packages/Microsoft.Web.WebView2) to embed a web browser.

WebView4Delphi was developed and tested on Delphi 11.3, Delphi XE2, Delphi 7 and Lazarus 2.2.6/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.
2 changes: 1 addition & 1 deletion packages/webview4delphi.lpk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Version Major="1" Release="1774" Build="30"/>
<Version Major="1" Release="1823" Build="32"/>
<Files Count="55">
<Item1>
<Filename Value="..\source\uWVBrowser.pas"/>
Expand Down
1 change: 1 addition & 0 deletions source/uWVBrowser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ TWVBrowser = class(TWVBrowserBase)
property OnGetCustomSchemes;
property OnGetNonDefaultPermissionSettingsCompleted;
property OnSetPermissionStateCompleted;
property OnLaunchingExternalUriScheme;
end;

{$IFDEF FPC}
Expand Down
112 changes: 112 additions & 0 deletions source/uWVBrowserBase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents)
FOnGetCustomSchemes : TOnGetCustomSchemesEvent;
FOnGetNonDefaultPermissionSettingsCompleted : TOnGetNonDefaultPermissionSettingsCompletedEvent;
FOnSetPermissionStateCompleted : TOnSetPermissionStateCompletedEvent;
FOnLaunchingExternalUriScheme : TOnLaunchingExternalUriSchemeEvent;

function GetBrowserProcessID : cardinal;
function GetBrowserVersionInfo : wvstring;
Expand Down Expand Up @@ -214,6 +215,9 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents)
function GetPreferredColorScheme : TWVPreferredColorScheme;
function GetPreferredTrackingPreventionLevel : TWVTrackingPreventionLevel;
function GetProfileCookieManager : ICoreWebView2CookieManager;
function GetProfileIsPasswordAutosaveEnabled : boolean;
function GetProfileIsGeneralAutofillEnabled : boolean;
function GetMemoryUsageTargetLevel : TWVMemoryUsageTargetLevel;

procedure SetBuiltInErrorPageEnabled(aValue: boolean);
procedure SetDefaultContextMenusEnabled(aValue: boolean);
Expand Down Expand Up @@ -253,6 +257,9 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents)
procedure SetDefaultDownloadFolderPath(const aValue : wvstring);
procedure SetPreferredColorScheme(const aValue : TWVPreferredColorScheme);
procedure SetPreferredTrackingPreventionLevel(const aValue : TWVTrackingPreventionLevel);
procedure SetProfileIsPasswordAutosaveEnabled(aValue : boolean);
procedure SetProfileIsGeneralAutofillEnabled(aValue : boolean);
procedure SetMemoryUsageTargetLevel(aValue : TWVMemoryUsageTargetLevel);

function CreateEnvironment : boolean;
function CreateCompositionController: boolean;
Expand Down Expand Up @@ -353,6 +360,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents)
function PrintToPdfStreamCompletedHandler_Invoke(errorCode: HResult; const pdfStream: IStream): HRESULT;
function GetNonDefaultPermissionSettingsCompletedHandler_Invoke(errorCode: HResult; const collectionView: ICoreWebView2PermissionSettingCollectionView): HRESULT;
function SetPermissionStateCompletedHandler_Invoke(errorCode: HResult): HRESULT;
function LaunchingExternalUriSchemeEventHandler_Invoke(const sender: ICoreWebView2; const args: ICoreWebView2LaunchingExternalUriSchemeEventArgs): HRESULT;

procedure doOnInitializationError(aErrorCode: HRESULT; const aErrorMessage: wvstring); virtual;
procedure doOnEnvironmentCompleted; virtual;
Expand Down Expand Up @@ -435,6 +443,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents)
procedure doOnGetCustomSchemes(var aSchemeRegistrations : TWVCustomSchemeRegistrationArray); virtual;
procedure doOnGetNonDefaultPermissionSettingsCompleted(errorCode: HResult; const collectionView: ICoreWebView2PermissionSettingCollectionView); virtual;
procedure doOnSetPermissionStateCompleted(errorCode: HResult); virtual;
procedure doOnLaunchingExternalUriSchemeEvent(const sender: ICoreWebView2; const args: ICoreWebView2LaunchingExternalUriSchemeEventArgs); virtual;

public
constructor Create(AOwner: TComponent); override;
Expand Down Expand Up @@ -618,6 +627,9 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents)
// ICoreWebView2_15
property FaviconURI : wvstring read GetFaviconURI;

// ICoreWebView2_19
property MemoryUsageTargetLevel : TWVMemoryUsageTargetLevel read GetMemoryUsageTargetLevel write SetMemoryUsageTargetLevel; // ICoreWebView2_19.Get_MemoryUsageTargetLevel

// ICoreWebView2Controller properties
property Bounds : TRect read GetBounds write SetBounds; // ICoreWebView2Controller.get_Bounds
property IsVisible : boolean read GetIsVisible write SetIsVisible; // ICoreWebView2Controller.get_IsVisible
Expand Down Expand Up @@ -695,6 +707,10 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents)
// ICoreWebView2Profile5 properties
property ProfileCookieManager : ICoreWebView2CookieManager read GetProfileCookieManager; // ICoreWebView2Profile5.get_CookieManager

// ICoreWebView2Profile6 properties
property ProfileIsPasswordAutosaveEnabled : boolean read GetProfileIsPasswordAutosaveEnabled write SetProfileIsPasswordAutosaveEnabled; // ICoreWebView2Profile6.Get_IsPasswordAutosaveEnabled
property ProfileIsGeneralAutofillEnabled : boolean read GetProfileIsGeneralAutofillEnabled write SetProfileIsGeneralAutofillEnabled; // ICoreWebView2Profile6.Get_IsGeneralAutofillEnabled

// ICoreWebView2Environment5 events
property OnBrowserProcessExited : TOnBrowserProcessExitedEvent read FOnBrowserProcessExited write FOnBrowserProcessExited;

Expand Down Expand Up @@ -829,6 +845,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents)
property OnGetCustomSchemes : TOnGetCustomSchemesEvent read FOnGetCustomSchemes write FOnGetCustomSchemes;
property OnGetNonDefaultPermissionSettingsCompleted : TOnGetNonDefaultPermissionSettingsCompletedEvent read FOnGetNonDefaultPermissionSettingsCompleted write FOnGetNonDefaultPermissionSettingsCompleted;
property OnSetPermissionStateCompleted : TOnSetPermissionStateCompletedEvent read FOnSetPermissionStateCompleted write FOnSetPermissionStateCompleted;
property OnLaunchingExternalUriScheme : TOnLaunchingExternalUriSchemeEvent read FOnLaunchingExternalUriScheme write FOnLaunchingExternalUriScheme;
end;

implementation
Expand Down Expand Up @@ -964,6 +981,9 @@ constructor TWVBrowserBase.Create(AOwner: TComponent);
FOnGetFaviconCompleted := nil;
FOnPrintToPdfStreamCompleted := nil;
FOnGetCustomSchemes := nil;
FOnGetNonDefaultPermissionSettingsCompleted := nil;
FOnSetPermissionStateCompleted := nil;
FOnLaunchingExternalUriScheme := nil;
end;

destructor TWVBrowserBase.Destroy;
Expand Down Expand Up @@ -1996,6 +2016,12 @@ procedure TWVBrowserBase.doOnSetPermissionStateCompleted(errorCode: HResult);
FOnSetPermissionStateCompleted(self, errorCode);
end;

procedure TWVBrowserBase.doOnLaunchingExternalUriSchemeEvent(const sender: ICoreWebView2; const args: ICoreWebView2LaunchingExternalUriSchemeEventArgs);
begin
if assigned(FOnLaunchingExternalUriScheme) then
FOnLaunchingExternalUriScheme(self, sender, args);
end;

procedure TWVBrowserBase.doOnRetrieveMHTMLCompleted( aErrorCode : HRESULT;
const aReturnObjectAsJson : wvstring);
var
Expand Down Expand Up @@ -2290,6 +2316,12 @@ function TWVBrowserBase.SetPermissionStateCompletedHandler_Invoke(errorCode: HRe
doOnSetPermissionStateCompleted(errorCode);
end;

function TWVBrowserBase.LaunchingExternalUriSchemeEventHandler_Invoke(const sender: ICoreWebView2; const args: ICoreWebView2LaunchingExternalUriSchemeEventArgs): HRESULT;
begin
Result := S_OK;
doOnLaunchingExternalUriSchemeEvent(sender, args);
end;

function TWVBrowserBase.ExecuteScriptCompletedHandler_Invoke(errorCode: HRESULT; resultObjectAsJson: PWideChar; aExecutionID : integer): HRESULT;
begin
Result := S_OK;
Expand Down Expand Up @@ -2857,6 +2889,14 @@ function TWVBrowserBase.GetFaviconURI : wvstring;
Result := '';
end;

function TWVBrowserBase.GetMemoryUsageTargetLevel : TWVMemoryUsageTargetLevel;
begin
if Initialized then
Result := FCoreWebView2.MemoryUsageTargetLevel
else
Result := COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_NORMAL;
end;

function TWVBrowserBase.GetScreenScale : single;
begin
if (GlobalWebView2Loader <> nil) then
Expand Down Expand Up @@ -4495,6 +4535,40 @@ function TWVBrowserBase.GetProfileCookieManager : ICoreWebView2CookieManager;
end;
end;

function TWVBrowserBase.GetProfileIsPasswordAutosaveEnabled : boolean;
var
TempProfile : TCoreWebView2Profile;
begin
Result := False;
TempProfile := nil;

if Initialized then
try
TempProfile := TCoreWebView2Profile.Create(FCoreWebView2.Profile);
Result := TempProfile.IsPasswordAutosaveEnabled;
finally
if assigned(TempProfile) then
FreeAndNil(TempProfile);
end;
end;

function TWVBrowserBase.GetProfileIsGeneralAutofillEnabled : boolean;
var
TempProfile : TCoreWebView2Profile;
begin
Result := False;
TempProfile := nil;

if Initialized then
try
TempProfile := TCoreWebView2Profile.Create(FCoreWebView2.Profile);
Result := TempProfile.IsGeneralAutofillEnabled;
finally
if assigned(TempProfile) then
FreeAndNil(TempProfile);
end;
end;

procedure TWVBrowserBase.SetPreferredTrackingPreventionLevel(const aValue : TWVTrackingPreventionLevel);
var
TempProfile : TCoreWebView2Profile;
Expand All @@ -4511,6 +4585,44 @@ procedure TWVBrowserBase.SetPreferredTrackingPreventionLevel(const aValue : TWVT
end;
end;

procedure TWVBrowserBase.SetProfileIsPasswordAutosaveEnabled(aValue : boolean);
var
TempProfile : TCoreWebView2Profile;
begin
TempProfile := nil;

if Initialized then
try
TempProfile := TCoreWebView2Profile.Create(FCoreWebView2.Profile);
TempProfile.IsPasswordAutosaveEnabled := aValue;
finally
if assigned(TempProfile) then
FreeAndNil(TempProfile);
end;
end;

procedure TWVBrowserBase.SetProfileIsGeneralAutofillEnabled(aValue : boolean);
var
TempProfile : TCoreWebView2Profile;
begin
TempProfile := nil;

if Initialized then
try
TempProfile := TCoreWebView2Profile.Create(FCoreWebView2.Profile);
TempProfile.IsGeneralAutofillEnabled := aValue;
finally
if assigned(TempProfile) then
FreeAndNil(TempProfile);
end;
end;

procedure TWVBrowserBase.SetMemoryUsageTargetLevel(aValue : TWVMemoryUsageTargetLevel);
begin
if Initialized then
FCoreWebView2.MemoryUsageTargetLevel := aValue;
end;

function TWVBrowserBase.CreateSharedBuffer(aSize : Largeuint; var aSharedBuffer : ICoreWebView2SharedBuffer) : boolean;
begin
Result := Initialized and
Expand Down
55 changes: 52 additions & 3 deletions source/uWVCoreWebView2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ TCoreWebView2 = class
FBaseIntf15 : ICoreWebView2_15;
FBaseIntf16 : ICoreWebView2_16;
FBaseIntf17 : ICoreWebView2_17;
FBaseIntf18 : ICoreWebView2_18;
FBaseIntf19 : ICoreWebView2_19;
FContainsFullScreenElementChangedToken : EventRegistrationToken;
FContentLoadingToken : EventRegistrationToken;
FDocumentTitleChangedToken : EventRegistrationToken;
Expand Down Expand Up @@ -63,6 +65,7 @@ TCoreWebView2 = class
FStatusBarTextChangedToken : EventRegistrationToken;
FServerCertificateErrorDetectedToken : EventRegistrationToken;
FFaviconChangedToken : EventRegistrationToken;
FLaunchingExternalUriSchemeToken : EventRegistrationToken;

FDevToolsEventNames : TStringList;
FDevToolsEventTokens : array of EventRegistrationToken;
Expand All @@ -86,10 +89,12 @@ TCoreWebView2 = class
function GetStatusBarText : wvstring;
function GetProfile : ICoreWebView2Profile;
function GetFaviconURI : wvstring;
function GetMemoryUsageTargetLevel : TWVMemoryUsageTargetLevel;

procedure SetIsMuted(aValue : boolean);
procedure SetDefaultDownloadDialogCornerAlignment(aValue : TWVDefaultDownloadDialogCornerAlignment);
procedure SetDefaultDownloadDialogMargin(aValue : TPoint);
procedure SetMemoryUsageTargetLevel(aValue : TWVMemoryUsageTargetLevel);

procedure InitializeFields;
procedure InitializeTokens;
Expand Down Expand Up @@ -125,6 +130,7 @@ TCoreWebView2 = class
function AddStatusBarTextChangedEvent(const aBrowserComponent : TComponent) : boolean;
function AddServerCertificateErrorDetectedEvent(const aBrowserComponent : TComponent) : boolean;
function AddFaviconChanged(const aBrowserComponent : TComponent) : boolean;
function AddLaunchingExternalUriScheme(const aBrowserComponent : TComponent) : boolean;

public
constructor Create(const aBaseIntf : ICoreWebView2); reintroduce;
Expand Down Expand Up @@ -187,6 +193,7 @@ TCoreWebView2 = class
property StatusBarText : wvstring read GetStatusBarText;
property Profile : ICoreWebView2Profile read GetProfile;
property FaviconURI : wvstring read GetFaviconURI;
property MemoryUsageTargetLevel : TWVMemoryUsageTargetLevel read GetMemoryUsageTargetLevel write SetMemoryUsageTargetLevel;
end;

implementation
Expand Down Expand Up @@ -217,8 +224,10 @@ constructor TCoreWebView2.Create(const aBaseIntf : ICoreWebView2);
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_13, FBaseIntf13) and
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_14, FBaseIntf14) and
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_15, FBaseIntf15) and
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_16, FBaseIntf16) then
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_17, FBaseIntf17);
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_16, FBaseIntf16) and
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_17, FBaseIntf17) and
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_18, FBaseIntf18) then
LoggedQueryInterface(FBaseIntf, IID_ICoreWebView2_19, FBaseIntf19);
end;

destructor TCoreWebView2.Destroy;
Expand Down Expand Up @@ -267,6 +276,8 @@ procedure TCoreWebView2.InitializeFields;
FBaseIntf15 := nil;
FBaseIntf16 := nil;
FBaseIntf17 := nil;
FBaseIntf18 := nil;
FBaseIntf19 := nil;
FDevToolsEventTokens := nil;
FDevToolsEventNames := nil;

Expand Down Expand Up @@ -304,6 +315,7 @@ procedure TCoreWebView2.InitializeTokens;
FStatusBarTextChangedToken.value := 0;
FServerCertificateErrorDetectedToken.value := 0;
FFaviconChangedToken.value := 0;
FLaunchingExternalUriSchemeToken.value := 0;
end;

function TCoreWebView2.GetInitialized : boolean;
Expand Down Expand Up @@ -422,6 +434,10 @@ procedure TCoreWebView2.RemoveAllEvents;
(FFaviconChangedToken.Value <> 0) then
FBaseIntf15.remove_FaviconChanged(FFaviconChangedToken);

if assigned(FBaseIntf18) and
(FLaunchingExternalUriSchemeToken.Value <> 0) then
FBaseIntf18.remove_LaunchingExternalUriScheme(FLaunchingExternalUriSchemeToken);

UnsubscribeAllDevToolsProtocolEvents;
end;
except
Expand Down Expand Up @@ -868,6 +884,21 @@ function TCoreWebView2.AddFaviconChanged(const aBrowserComponent : TComponent) :
end;
end;

function TCoreWebView2.AddLaunchingExternalUriScheme(const aBrowserComponent : TComponent) : boolean;
var
TempHandler : ICoreWebView2LaunchingExternalUriSchemeEventHandler;
begin
Result := False;

if assigned(FBaseIntf18) and (FLaunchingExternalUriSchemeToken.value = 0) then
try
TempHandler := TCoreWebView2LaunchingExternalUriSchemeEventHandler.Create(TWVBrowserBase(aBrowserComponent));
Result := succeeded(FBaseIntf18.add_LaunchingExternalUriScheme(TempHandler, FLaunchingExternalUriSchemeToken));
finally
TempHandler := nil;
end;
end;

function TCoreWebView2.AddAllBrowserEvents(const aBrowserComponent : TComponent) : boolean;
begin
Result := AddNavigationStartingEvent(aBrowserComponent) and
Expand Down Expand Up @@ -898,7 +929,8 @@ function TCoreWebView2.AddAllBrowserEvents(const aBrowserComponent : TComponent)
AddContextMenuRequestedEvent(aBrowserComponent) and
AddStatusBarTextChangedEvent(aBrowserComponent) and
AddServerCertificateErrorDetectedEvent(aBrowserComponent) and
AddFaviconChanged(aBrowserComponent);
AddFaviconChanged(aBrowserComponent) and
AddLaunchingExternalUriScheme(aBrowserComponent);
end;

function TCoreWebView2.AddWebResourceRequestedFilter(const URI : wvstring;
Expand Down Expand Up @@ -1464,6 +1496,17 @@ function TCoreWebView2.GetFaviconURI : wvstring;
end;
end;

function TCoreWebView2.GetMemoryUsageTargetLevel : TWVMemoryUsageTargetLevel;
var
TempResult : COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL;
begin
if assigned(FBaseIntf19) and
succeeded(FBaseIntf19.Get_MemoryUsageTargetLevel(TempResult)) then
Result := TempResult
else
Result := COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_NORMAL;
end;

procedure TCoreWebView2.SetIsMuted(aValue : boolean);
begin
if assigned(FBaseIntf8) then
Expand All @@ -1482,4 +1525,10 @@ procedure TCoreWebView2.SetDefaultDownloadDialogMargin(aValue : TPoint);
FBaseIntf9.Set_DefaultDownloadDialogMargin(tagPOINT(aValue));
end;

procedure TCoreWebView2.SetMemoryUsageTargetLevel(aValue : TWVMemoryUsageTargetLevel);
begin
if assigned(FBaseIntf19) then
FBaseIntf19.Set_MemoryUsageTargetLevel(aValue);
end;

end.
Loading

0 comments on commit ab710a8

Please sign in to comment.