diff --git a/README.md b/README.md index 6cb5acb..1921a6e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bin32/WebView2Loader.dll b/bin32/WebView2Loader.dll index f697d8f..05fac9e 100644 Binary files a/bin32/WebView2Loader.dll and b/bin32/WebView2Loader.dll differ diff --git a/bin64/WebView2Loader.dll b/bin64/WebView2Loader.dll index 23ee281..2c79fb4 100644 Binary files a/bin64/WebView2Loader.dll and b/bin64/WebView2Loader.dll differ diff --git a/demos/Delphi_VCL/KioskBrowser/uKioskBrowser.dfm b/demos/Delphi_VCL/KioskBrowser/uKioskBrowser.dfm index 1494b63..0d33b25 100644 --- a/demos/Delphi_VCL/KioskBrowser/uKioskBrowser.dfm +++ b/demos/Delphi_VCL/KioskBrowser/uKioskBrowser.dfm @@ -12,6 +12,7 @@ object MainForm: TMainForm Font.Name = 'Segoe UI' Font.Style = [] WindowState = wsMaximized + OnCreate = FormCreate OnShow = FormShow PixelsPerInch = 96 TextHeight = 15 @@ -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 diff --git a/demos/Delphi_VCL/KioskBrowser/uKioskBrowser.pas b/demos/Delphi_VCL/KioskBrowser/uKioskBrowser.pas index b377f04..86d347d 100644 --- a/demos/Delphi_VCL/KioskBrowser/uKioskBrowser.pas +++ b/demos/Delphi_VCL/KioskBrowser/uKioskBrowser.pas @@ -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; @@ -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); @@ -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; @@ -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; diff --git a/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.dfm b/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.dfm index fa7e841..e832d37 100644 --- a/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.dfm +++ b/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.dfm @@ -239,6 +239,7 @@ object MiniBrowserFrm: TMiniBrowserFrm OnRetrieveTextCompleted = WVBrowser1RetrieveTextCompleted OnRetrieveMHTMLCompleted = WVBrowser1RetrieveMHTMLCompleted OnBasicAuthenticationRequested = WVBrowser1BasicAuthenticationRequested + OnStatusBarTextChanged = WVBrowser1StatusBarTextChanged Left = 48 Top = 64 end diff --git a/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas b/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas index a5039ab..be02316 100644 --- a/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas +++ b/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas @@ -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; @@ -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); diff --git a/demos/Lazarus/MiniBrowser/MiniBrowser.lps b/demos/Lazarus/MiniBrowser/MiniBrowser.lps index 96da0c4..5f86bc2 100644 --- a/demos/Lazarus/MiniBrowser/MiniBrowser.lps +++ b/demos/Lazarus/MiniBrowser/MiniBrowser.lps @@ -4,7 +4,7 @@ - + @@ -19,11 +19,11 @@ - - + + - + @@ -42,12 +42,11 @@ - + - @@ -214,15 +213,14 @@ - - - + + + - @@ -278,151 +276,157 @@ - + - - + - - - + + + - + + + + + + + + - + - + - + - + - + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + diff --git a/demos/Lazarus/MiniBrowser/uMiniBrowser.lfm b/demos/Lazarus/MiniBrowser/uMiniBrowser.lfm index f7a9e6a..dfd723d 100644 --- a/demos/Lazarus/MiniBrowser/uMiniBrowser.lfm +++ b/demos/Lazarus/MiniBrowser/uMiniBrowser.lfm @@ -1,7 +1,7 @@ object MiniBrowserFrm: TMiniBrowserFrm - Left = 389 + Left = 506 Height = 717 - Top = 123 + Top = 141 Width = 1119 Caption = 'MiniBrowser - Initializing...' ClientHeight = 717 @@ -196,6 +196,7 @@ object MiniBrowserFrm: TMiniBrowserFrm item Width = 1000 end> + SimplePanel = False end object WVWindowParent1: TWVWindowParent Left = 0 @@ -227,6 +228,7 @@ object MiniBrowserFrm: TMiniBrowserFrm OnRetrieveTextCompleted = WVBrowser1RetrieveTextCompleted OnRetrieveMHTMLCompleted = WVBrowser1RetrieveMHTMLCompleted OnBasicAuthenticationRequested = WVBrowser1BasicAuthenticationRequested + OnStatusBarTextChanged = WVBrowser1StatusBarTextChanged Left = 48 Top = 64 end diff --git a/demos/Lazarus/MiniBrowser/uMiniBrowser.pas b/demos/Lazarus/MiniBrowser/uMiniBrowser.pas index c8a8ffc..01b3652 100644 --- a/demos/Lazarus/MiniBrowser/uMiniBrowser.pas +++ b/demos/Lazarus/MiniBrowser/uMiniBrowser.pas @@ -110,6 +110,8 @@ TMiniBrowserFrm = class(TForm) procedure WVBrowser1DownloadStateChanged(Sender: TObject; const aDownloadOperation: ICoreWebView2DownloadOperation; aDownloadID : integer); procedure WVBrowser1BytesReceivedChanged(Sender: TObject; const aDownloadOperation: ICoreWebView2DownloadOperation; aDownloadID : integer); procedure WVBrowser1CapturePreviewCompleted(Sender: TObject; aErrorCode: HRESULT); + procedure WVBrowser1StatusBarTextChanged(Sender: TObject; + const aWebView: ICoreWebView2); procedure WVBrowser1WebResourceRequested(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2WebResourceRequestedEventArgs); procedure WVBrowser1WebResourceResponseReceived(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2WebResourceResponseReceivedEventArgs); @@ -458,6 +460,12 @@ procedure TMiniBrowserFrm.WVBrowser1CapturePreviewCompleted( FreeAndNil(FFileStream); end; +procedure TMiniBrowserFrm.WVBrowser1StatusBarTextChanged(Sender: TObject; + const aWebView: ICoreWebView2); +begin + StatusBar1.Panels[0].Text := UTF8Encode(WVBrowser1.StatusBarText); +end; + procedure TMiniBrowserFrm.UpdateDownloadInfo(aDownloadID : integer); var TempStatus : string; diff --git a/packages/WebView4DelphiVCLRTL.dpk b/packages/WebView4DelphiVCLRTL.dpk index 5725132..07d8e6a 100644 --- a/packages/WebView4DelphiVCLRTL.dpk +++ b/packages/WebView4DelphiVCLRTL.dpk @@ -76,6 +76,9 @@ contains uWVBrowserBase in '..\source\uWVBrowserBase.pas', uWVCoreWebView2ProcessInfoCollection in '..\source\uWVCoreWebView2ProcessInfoCollection.pas', uWVCoreWebView2ProcessInfo in '..\source\uWVCoreWebView2ProcessInfo.pas', - uWVCoreWebView2BasicAuthenticationResponse in '..\source\uWVCoreWebView2BasicAuthenticationResponse.pas'; + uWVCoreWebView2BasicAuthenticationResponse in '..\source\uWVCoreWebView2BasicAuthenticationResponse.pas', + uWVCoreWebView2ContextMenuItemCollection in '..\source\uWVCoreWebView2ContextMenuItemCollection.pas', + uWVCoreWebView2ContextMenuItem in '..\source\uWVCoreWebView2ContextMenuItem.pas', + uWVCoreWebView2ContextMenuTarget in '..\source\uWVCoreWebView2ContextMenuTarget.pas'; end. diff --git a/packages/WebView4DelphiVCLRTL.dproj b/packages/WebView4DelphiVCLRTL.dproj index 9e2d1cc..5234aca 100644 --- a/packages/WebView4DelphiVCLRTL.dproj +++ b/packages/WebView4DelphiVCLRTL.dproj @@ -140,6 +140,9 @@ + + + Base @@ -177,7 +180,7 @@ true - + WebView4DelphiVCLRTL.bpl true diff --git a/packages/webview4delphi.lpk b/packages/webview4delphi.lpk index 66925df..40614ef 100644 --- a/packages/webview4delphi.lpk +++ b/packages/webview4delphi.lpk @@ -12,8 +12,8 @@ - - + + @@ -192,6 +192,18 @@ + + + + + + + + + + + + diff --git a/packages/webview4delphi.pas b/packages/webview4delphi.pas index dd32885..73dadc6 100644 --- a/packages/webview4delphi.pas +++ b/packages/webview4delphi.pas @@ -28,7 +28,9 @@ interface uWVEvents, uWVInterfaces, uWVLibFunctions, uWVLoader, uWVMiscFunctions, uWVTypeLibrary, uWVTypes, uWVWinControl, uWVWindowParent, uWVCoreWebView2ProcessInfo, uWVCoreWebView2ProcessInfoCollection, - uWVCoreWebView2BasicAuthenticationResponse, LazarusPackageIntf; + uWVCoreWebView2BasicAuthenticationResponse, uWVCoreWebView2ContextMenuItem, + uWVCoreWebView2ContextMenuItemCollection, uWVCoreWebView2ContextMenuTarget, + LazarusPackageIntf; implementation diff --git a/source/uWVBrowser.pas b/source/uWVBrowser.pas index 1ea441d..9c57467 100644 --- a/source/uWVBrowser.pas +++ b/source/uWVBrowser.pas @@ -108,6 +108,10 @@ TWVBrowser = class(TWVBrowserBase) property OnFrameDOMContentLoaded; property OnFrameWebMessageReceived; property OnBasicAuthenticationRequested; + property OnContextMenuRequested; + property OnCustomItemSelected; + property OnStatusBarTextChanged; + property OnFramePermissionRequested; end; {$IFDEF FPC} diff --git a/source/uWVBrowserBase.pas b/source/uWVBrowserBase.pas index d2554cc..f70c431 100644 --- a/source/uWVBrowserBase.pas +++ b/source/uWVBrowserBase.pas @@ -40,6 +40,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) FLanguage : wvstring; FTargetCompatibleBrowserVersion : wvstring; FAllowSingleSignOnUsingOSPrimaryAccount : boolean; + FExclusiveUserDataFolderAccess : boolean; FIgnoreCertificateErrors : boolean; FZoomStep : byte; FOffline : boolean; @@ -130,6 +131,10 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) FOnFrameDOMContentLoaded : TOnFrameDOMContentLoadedEvent; FOnFrameWebMessageReceived : TOnFrameWebMessageReceivedEvent; FOnBasicAuthenticationRequested : TOnBasicAuthenticationRequestedEvent; + FOnContextMenuRequested : TOnContextMenuRequestedEvent; + FOnCustomItemSelected : TOnCustomItemSelectedEvent; + FOnStatusBarTextChanged : TOnStatusBarTextChangedEvent; + FOnFramePermissionRequested : TOnFramePermissionRequestedEvent; function GetBrowserProcessID : cardinal; function GetBrowserVersionInfo : wvstring; @@ -169,13 +174,15 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) function GetRootVisualTarget : IUnknown; function GetCursor : HCURSOR; function GetSystemCursorID : cardinal; - function GetUIAProvider : IUnknown; + function GetAutomationProvider : IUnknown; function GetProcessInfos : ICoreWebView2ProcessInfoCollection; function GetIsMuted : boolean; function GetIsDocumentPlayingAudio : boolean; function GetIsDefaultDownloadDialogOpen : boolean; function GetDefaultDownloadDialogCornerAlignment : TWVDefaultDownloadDialogCornerAlignment; function GetDefaultDownloadDialogMargin : TPoint; + function GetStatusBarText : wvstring; + function GetAllowExternalDrop : boolean; procedure SetBuiltInErrorPageEnabled(aValue: boolean); procedure SetDefaultContextMenusEnabled(aValue: boolean); @@ -208,6 +215,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) procedure SetIsMuted(aValue : boolean); procedure SetDefaultDownloadDialogCornerAlignment(aValue : TWVDefaultDownloadDialogCornerAlignment); procedure SetDefaultDownloadDialogMargin(aValue : TPoint); + procedure SetAllowExternalDrop(aValue : boolean); function CreateEnvironment : boolean; @@ -291,6 +299,10 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) function FrameDOMContentLoadedEventHandler_Invoke(const sender: ICoreWebView2Frame; const args: ICoreWebView2DOMContentLoadedEventArgs; aFrameID: integer): HRESULT; function FrameWebMessageReceivedEventHandler_Invoke(const sender: ICoreWebView2Frame; const args: ICoreWebView2WebMessageReceivedEventArgs; aFrameID: integer): HRESULT; function BasicAuthenticationRequestedEventHandler_Invoke(const sender: ICoreWebView2; const args: ICoreWebView2BasicAuthenticationRequestedEventArgs): HRESULT; + function ContextMenuRequestedEventHandler_Invoke(const sender: ICoreWebView2; const args: ICoreWebView2ContextMenuRequestedEventArgs): HRESULT; + function CustomItemSelectedEventHandler_Invoke(const sender: ICoreWebView2ContextMenuItem; const args: IUnknown): HRESULT; + function StatusBarTextChangedEventHandler_Invoke(const sender: ICoreWebView2; const args: IUnknown): HRESULT; + function FramePermissionRequestedEventHandler_Invoke(const sender: ICoreWebView2Frame; const args: ICoreWebView2PermissionRequestedEventArgs2; aFrameID: integer): HRESULT; procedure doOnInitializationError(aErrorCode: HRESULT; const aErrorMessage: wvstring); virtual; procedure doOnEnvironmentCompleted; virtual; @@ -360,6 +372,10 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) procedure doOnFrameDOMContentLoadedEvent(const sender: ICoreWebView2Frame; const args: ICoreWebView2DOMContentLoadedEventArgs; aFrameID: integer); virtual; procedure doOnFrameWebMessageReceivedEvent(const sender: ICoreWebView2Frame; const args: ICoreWebView2WebMessageReceivedEventArgs; aFrameID: integer); virtual; procedure doOnBasicAuthenticationRequestedEvent(const sender: ICoreWebView2; const args: ICoreWebView2BasicAuthenticationRequestedEventArgs); virtual; + procedure doOnContextMenuRequestedEvent(const sender: ICoreWebView2; const args: ICoreWebView2ContextMenuRequestedEventArgs); virtual; + procedure doOnCustomItemSelectedEvent(const sender: ICoreWebView2ContextMenuItem; const args: IUnknown); virtual; + procedure doOnStatusBarTextChangedEvent(const sender: ICoreWebView2; const args: IUnknown); virtual; + procedure doOnFramePermissionRequestedEvent(const sender: ICoreWebView2Frame; const args: ICoreWebView2PermissionRequestedEventArgs2; aFrameID: integer); virtual; public constructor Create(AOwner: TComponent); override; @@ -383,6 +399,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) function SubscribeToDevToolsProtocolEvent(const aEventName : wvstring; aEventID : integer = 0) : boolean; function CallDevToolsProtocolMethod(const aMethodName, aParametersAsJson : wvstring; aExecutionID : integer = 0) : boolean; + function CallDevToolsProtocolMethodForSession(const aSessionId, aMethodName, aParametersAsJson : wvstring; aExecutionID : integer = 0) : boolean; function SetFocus : boolean; function FocusNext : boolean; @@ -484,6 +501,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) property Language : wvstring read FLanguage write FLanguage; // ICoreWebView2EnvironmentOptions.get_Language property TargetCompatibleBrowserVersion : wvstring read FTargetCompatibleBrowserVersion write FTargetCompatibleBrowserVersion; // ICoreWebView2EnvironmentOptions.get_TargetCompatibleBrowserVersion property AllowSingleSignOnUsingOSPrimaryAccount : boolean read FAllowSingleSignOnUsingOSPrimaryAccount write FAllowSingleSignOnUsingOSPrimaryAccount; // ICoreWebView2EnvironmentOptions.get_AllowSingleSignOnUsingOSPrimaryAccount + property ExclusiveUserDataFolderAccess : boolean read FExclusiveUserDataFolderAccess write FExclusiveUserDataFolderAccess; // ICoreWebView2EnvironmentOptions2.Get_ExclusiveUserDataFolderAccess // ICoreWebView2Environment properties property BrowserVersionInfo : wvstring read GetBrowserVersionInfo; // ICoreWebView2Environment.get_BrowserVersionString @@ -511,6 +529,9 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) property DefaultDownloadDialogMargin : TPoint read GetDefaultDownloadDialogMargin write SetDefaultDownloadDialogMargin; // ICoreWebView2_9.get_DefaultDownloadDialogMargin property IsDefaultDownloadDialogOpen : boolean read GetIsDefaultDownloadDialogOpen; // ICoreWebView2_9.get_IsDefaultDownloadDialogOpen + // ICoreWebView2_12 + property StatusBarText : wvstring read GetStatusBarText; + // ICoreWebView2Controller properties property Bounds : TRect read GetBounds write SetBounds; // ICoreWebView2Controller.get_Bounds property IsVisible : boolean read GetIsVisible write SetIsVisible; // ICoreWebView2Controller.get_IsVisible @@ -525,6 +546,9 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) property RasterizationScale : double read GetRasterizationScale write SetRasterizationScale; // ICoreWebView2Controller3.get_RasterizationScale property ShouldDetectMonitorScaleChanges : boolean read GetShouldDetectMonitorScaleChanges write SetShouldDetectMonitorScaleChanges; // ICoreWebView2Controller3.get_ShouldDetectMonitorScaleChanges + // ICoreWebView2Controller4 properties + property AllowExternalDrop : boolean read GetAllowExternalDrop write SetAllowExternalDrop; + // ICoreWebView2Settings properties property DefaultContextMenusEnabled : boolean read GetDefaultContextMenusEnabled write SetDefaultContextMenusEnabled; // ICoreWebView2Settings.get_AreDefaultContextMenusEnabled property DefaultScriptDialogsEnabled : boolean read GetDefaultScriptDialogsEnabled write SetDefaultScriptDialogsEnabled; // ICoreWebView2Settings.get_AreDefaultScriptDialogsEnabled @@ -558,7 +582,7 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) property SystemCursorID : cardinal read GetSystemCursorID; // ICoreWebView2CompositionController.get_SystemCursorId // ICoreWebView2CompositionController2 properties - property UIAProvider : IUnknown read GetUIAProvider; // ICoreWebView2CompositionController2.get_UIAProvider + property AutomationProvider : IUnknown read GetAutomationProvider; // ICoreWebView2CompositionController2.get_UIAProvider // ICoreWebView2Environment8 properties property ProcessInfos : ICoreWebView2ProcessInfoCollection read GetProcessInfos; @@ -608,6 +632,12 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) // ICoreWebView2_10 events property OnBasicAuthenticationRequested : TOnBasicAuthenticationRequestedEvent read FOnBasicAuthenticationRequested write FOnBasicAuthenticationRequested; + // ICoreWebView2_11 events + property OnContextMenuRequested : TOnContextMenuRequestedEvent read FOnContextMenuRequested write FOnContextMenuRequested; + + // ICoreWebView2_12 events + property OnStatusBarTextChanged : TOnStatusBarTextChangedEvent read FOnStatusBarTextChanged write FOnStatusBarTextChanged; + // ICoreWebView2Controller events property OnAcceleratorKeyPressed : TOnAcceleratorKeyPressedEvent read FOnAcceleratorKeyPressed write FOnAcceleratorKeyPressed; property OnGotFocus : TNotifyEvent read FOnGotFocus write FOnGotFocus; @@ -637,9 +667,15 @@ TWVBrowserBase = class(TComponent, IWVBrowserEvents) property OnFrameDOMContentLoaded : TOnFrameDOMContentLoadedEvent read FOnFrameDOMContentLoaded write FOnFrameDOMContentLoaded; property OnFrameWebMessageReceived : TOnFrameWebMessageReceivedEvent read FOnFrameWebMessageReceived write FOnFrameWebMessageReceived; + // ICoreWebView2Frame3 events + property OnFramePermissionRequested : TOnFramePermissionRequestedEvent read FOnFramePermissionRequested write FOnFramePermissionRequested; + // ICoreWebView2DevToolsProtocolEventReceiver events property OnDevToolsProtocolEventReceived : TOnDevToolsProtocolEventReceivedEvent read FOnDevToolsProtocolEventReceived write FOnDevToolsProtocolEventReceived; + // ICoreWebView2ContextMenuItem events + property OnCustomItemSelected : TOnCustomItemSelectedEvent read FOnCustomItemSelected write FOnCustomItemSelected; + // Custom events property OnInitializationError : TOnInitializationErrorEvent read FOnInitializationError write FOnInitializationError; property OnEnvironmentCompleted : TNotifyEvent read FOnEnvironmentCompleted write FOnEnvironmentCompleted; @@ -692,6 +728,7 @@ constructor TWVBrowserBase.Create(AOwner: TComponent); FUseCompositionController := False; FTargetCompatibleBrowserVersion := LowestChromiumVersion; FAllowSingleSignOnUsingOSPrimaryAccount := False; + FExclusiveUserDataFolderAccess := False; FZoomStep := ZOOM_STEP_DEF; FOffline := False; FIsNavigating := False; @@ -781,6 +818,10 @@ constructor TWVBrowserBase.Create(AOwner: TComponent); FOnIsDocumentPlayingAudioChanged := nil; FOnIsDefaultDownloadDialogOpenChanged := nil; FOnBasicAuthenticationRequested := nil; + FOnContextMenuRequested := nil; + FOnCustomItemSelected := nil; + FOnStatusBarTextChanged := nil; + FOnFramePermissionRequested := nil; end; destructor TWVBrowserBase.Destroy; @@ -1700,6 +1741,35 @@ procedure TWVBrowserBase.doOnBasicAuthenticationRequestedEvent(const sender : IC FOnBasicAuthenticationRequested(self, sender, args); end; +procedure TWVBrowserBase.doOnContextMenuRequestedEvent(const sender : ICoreWebView2; + const args : ICoreWebView2ContextMenuRequestedEventArgs); +begin + if assigned(FOnContextMenuRequested) then + FOnContextMenuRequested(self, sender, args); +end; + +procedure TWVBrowserBase.doOnCustomItemSelectedEvent(const sender : ICoreWebView2ContextMenuItem; + const args : IUnknown); +begin + if assigned(FOnCustomItemSelected) then + FOnCustomItemSelected(self, sender); +end; + +procedure TWVBrowserBase.doOnStatusBarTextChangedEvent(const sender : ICoreWebView2; + const args : IUnknown); +begin + if assigned(FOnStatusBarTextChanged) then + FOnStatusBarTextChanged(self, sender); +end; + +procedure TWVBrowserBase.doOnFramePermissionRequestedEvent(const sender : ICoreWebView2Frame; + const args : ICoreWebView2PermissionRequestedEventArgs2; + aFrameID : integer); +begin + if assigned(FOnFramePermissionRequested) then + FOnFramePermissionRequested(self, sender, args, aFrameID); +end; + procedure TWVBrowserBase.doOnRetrieveMHTMLCompleted(aErrorCode: HRESULT; const aReturnObjectAsJson: wvstring); var TempMHTML : wvstring; @@ -1811,25 +1881,29 @@ function TWVBrowserBase.AddScriptToExecuteOnDocumentCreatedCompletedHandler_Invo doOnAddScriptToExecuteOnDocumentCreatedCompletedEvent(errorCode, wvstring(id)); end; -function TWVBrowserBase.IsMutedChangedEventHandler_Invoke(const sender: ICoreWebView2; const args: IUnknown): HRESULT; +function TWVBrowserBase.IsMutedChangedEventHandler_Invoke(const sender : ICoreWebView2; + const args : IUnknown): HRESULT; begin Result := S_OK; doOnIsMutedChanged(sender); end; -function TWVBrowserBase.IsDocumentPlayingAudioChangedEventHandler_Invoke(const sender: ICoreWebView2; const args: IUnknown): HRESULT; +function TWVBrowserBase.IsDocumentPlayingAudioChangedEventHandler_Invoke(const sender : ICoreWebView2; + const args : IUnknown): HRESULT; begin Result := S_OK; doOnIsDocumentPlayingAudioChanged(sender); end; -function TWVBrowserBase.IsDefaultDownloadDialogOpenChangedEventHandler_Invoke(const sender: ICoreWebView2; const args: IUnknown): HRESULT; +function TWVBrowserBase.IsDefaultDownloadDialogOpenChangedEventHandler_Invoke(const sender : ICoreWebView2; + const args : IUnknown): HRESULT; begin Result := S_OK; doOnIsDefaultDownloadDialogOpenChanged(sender); end; -function TWVBrowserBase.ProcessInfosChangedEventHandler_Invoke(const sender: ICoreWebView2Environment; const args: IUnknown): HRESULT; +function TWVBrowserBase.ProcessInfosChangedEventHandler_Invoke(const sender : ICoreWebView2Environment; + const args : IUnknown): HRESULT; begin Result := S_OK; doOnProcessInfosChangedEvent(sender); @@ -1882,6 +1956,35 @@ function TWVBrowserBase.BasicAuthenticationRequestedEventHandler_Invoke(const se doOnBasicAuthenticationRequestedEvent(sender, args); end; +function TWVBrowserBase.ContextMenuRequestedEventHandler_Invoke(const sender : ICoreWebView2; + const args : ICoreWebView2ContextMenuRequestedEventArgs): HRESULT; +begin + Result := S_OK; + doOnContextMenuRequestedEvent(sender, args); +end; + +function TWVBrowserBase.CustomItemSelectedEventHandler_Invoke(const sender : ICoreWebView2ContextMenuItem; + const args : IUnknown): HRESULT; +begin + Result := S_OK; + doOnCustomItemSelectedEvent(sender, args); +end; + +function TWVBrowserBase.StatusBarTextChangedEventHandler_Invoke(const sender : ICoreWebView2; + const args : IUnknown): HRESULT; +begin + Result := S_OK; + doOnStatusBarTextChangedEvent(sender, args); +end; + +function TWVBrowserBase.FramePermissionRequestedEventHandler_Invoke(const sender : ICoreWebView2Frame; + const args : ICoreWebView2PermissionRequestedEventArgs2; + aFrameID : integer): HRESULT; +begin + Result := S_OK; + doOnFramePermissionRequestedEvent(sender, args, aFrameID); +end; + function TWVBrowserBase.ExecuteScriptCompletedHandler_Invoke(errorCode: HRESULT; resultObjectAsJson: PWideChar; aExecutionID : integer): HRESULT; begin Result := S_OK; @@ -2081,10 +2184,10 @@ function TWVBrowserBase.GetSystemCursorID : cardinal; Result := 0; end; -function TWVBrowserBase.GetUIAProvider : IUnknown; +function TWVBrowserBase.GetAutomationProvider : IUnknown; begin if FUseCompositionController and Initialized then - Result := FCoreWebView2CompositionController.UIAProvider + Result := FCoreWebView2CompositionController.AutomationProvider else Result := nil; end; @@ -2115,6 +2218,14 @@ function TWVBrowserBase.GetIsDefaultDownloadDialogOpen : boolean; FCoreWebView2.IsDefaultDownloadDialogOpen; end; +function TWVBrowserBase.GetStatusBarText : wvstring; +begin + if Initialized then + Result := FCoreWebView2.StatusBarText + else + Result := ''; +end; + function TWVBrowserBase.GetDefaultDownloadDialogCornerAlignment : TWVDefaultDownloadDialogCornerAlignment; begin if Initialized then @@ -2284,6 +2395,12 @@ function TWVBrowserBase.GetShouldDetectMonitorScaleChanges : boolean; FCoreWebView2Controller.ShouldDetectMonitorScaleChanges; end; +function TWVBrowserBase.GetAllowExternalDrop : boolean; +begin + Result := Initialized and + FCoreWebView2Controller.AllowExternalDrop; +end; + function TWVBrowserBase.GetBoundsMode : TWVBoundsMode; begin if Initialized then @@ -2376,7 +2493,8 @@ function TWVBrowserBase.CreateEnvironment : boolean; TempOptions := TCoreWebView2EnvironmentOptions.Create(FAdditionalBrowserArguments, FLanguage, FTargetCompatibleBrowserVersion, - FAllowSingleSignOnUsingOSPrimaryAccount); + FAllowSingleSignOnUsingOSPrimaryAccount, + FExclusiveUserDataFolderAccess); TempHResult := CreateCoreWebView2EnvironmentWithOptions(PWideChar(FBrowserExecPath), PWideChar(FUserDataFolder), @@ -2464,6 +2582,12 @@ procedure TWVBrowserBase.SetShouldDetectMonitorScaleChanges(aValue : boolean); FCoreWebView2Controller.ShouldDetectMonitorScaleChanges := aValue; end; +procedure TWVBrowserBase.SetAllowExternalDrop(aValue : boolean); +begin + if Initialized then + FCoreWebView2Controller.AllowExternalDrop := aValue; +end; + procedure TWVBrowserBase.SetBoundsMode(aValue : TWVBoundsMode); begin if Initialized then @@ -2692,6 +2816,13 @@ function TWVBrowserBase.CallDevToolsProtocolMethod(const aMethodName, aParameter FCoreWebView2.CallDevToolsProtocolMethod(aMethodName, aParametersAsJson, aExecutionID, self); end; +// This function is asynchronous and it triggers the TWVBrowserBase.OnCallDevToolsProtocolMethodCompleted event when it finishes +function TWVBrowserBase.CallDevToolsProtocolMethodForSession(const aSessionId, aMethodName, aParametersAsJson : wvstring; aExecutionID : integer) : boolean; +begin + Result := Initialized and + FCoreWebView2.CallDevToolsProtocolMethodForSession(aSessionId, aMethodName, aParametersAsJson, aExecutionID, self); +end; + function TWVBrowserBase.AddHostObjectToScript(const aName : wvstring; const aObject : OleVariant): boolean; begin Result := Initialized and diff --git a/source/uWVCoreWebView2.pas b/source/uWVCoreWebView2.pas index fc2a806..a506997 100644 --- a/source/uWVCoreWebView2.pas +++ b/source/uWVCoreWebView2.pas @@ -25,6 +25,8 @@ TCoreWebView2 = class FBaseIntf8 : ICoreWebView2_8; FBaseIntf9 : ICoreWebView2_9; FBaseIntf10 : ICoreWebView2_10; + FBaseIntf11 : ICoreWebView2_11; + FBaseIntf12 : ICoreWebView2_12; FContainsFullScreenElementChangedToken : EventRegistrationToken; FContentLoadingToken : EventRegistrationToken; FDocumentTitleChangedToken : EventRegistrationToken; @@ -50,6 +52,8 @@ TCoreWebView2 = class FIsDocumentPlayingAudioChangedToken : EventRegistrationToken; FIsDefaultDownloadDialogOpenChangedToken : EventRegistrationToken; FBasicAuthenticationRequestedToken : EventRegistrationToken; + FContextMenuRequestedToken : EventRegistrationToken; + FStatusBarTextChangedToken : EventRegistrationToken; FDevToolsEventNames : TStringList; FDevToolsEventTokens : array of EventRegistrationToken; @@ -70,6 +74,7 @@ TCoreWebView2 = class function GetIsDefaultDownloadDialogOpen : boolean; function GetDefaultDownloadDialogCornerAlignment : TWVDefaultDownloadDialogCornerAlignment; function GetDefaultDownloadDialogMargin : TPoint; + function GetStatusBarText : wvstring; procedure SetIsMuted(aValue : boolean); procedure SetDefaultDownloadDialogCornerAlignment(aValue : TWVDefaultDownloadDialogCornerAlignment); @@ -105,6 +110,8 @@ TCoreWebView2 = class function AddIsDocumentPlayingAudioChangedEvent(const aBrowserComponent : TComponent) : boolean; function AddIsDefaultDownloadDialogOpenChangedEvent(const aBrowserComponent : TComponent) : boolean; function AddBasicAuthenticationRequestedEvent(const aBrowserComponent : TComponent) : boolean; + function AddContextMenuRequestedEvent(const aBrowserComponent : TComponent) : boolean; + function AddStatusBarTextChangedEvent(const aBrowserComponent : TComponent) : boolean; public constructor Create(const aBaseIntf : ICoreWebView2); reintroduce; @@ -131,6 +138,7 @@ TCoreWebView2 = class function PostWebMessageAsJson(const aWebMessageAsJson : wvstring) : boolean; function PostWebMessageAsString(const aWebMessageAsString : wvstring) : boolean; function CallDevToolsProtocolMethod(const aMethodName, aParametersAsJson : wvstring; aExecutionID : integer; const aBrowserComponent : TComponent) : boolean; + function CallDevToolsProtocolMethodForSession(const aSessionId, aMethodName, aParametersAsJson : wvstring; aExecutionID : integer; const aBrowserComponent : TComponent) : boolean; function AddWebResourceRequestedFilter(const URI : wvstring; ResourceContext: TWVWebResourceContext) : boolean; function RemoveWebResourceRequestedFilter(const URI : wvstring; ResourceContext: TWVWebResourceContext) : boolean; function AddHostObjectToScript(const aName : wvstring; const aObject : OleVariant): boolean; @@ -157,6 +165,7 @@ TCoreWebView2 = class property IsDefaultDownloadDialogOpen : boolean read GetIsDefaultDownloadDialogOpen; property DefaultDownloadDialogCornerAlignment : TWVDefaultDownloadDialogCornerAlignment read GetDefaultDownloadDialogCornerAlignment write SetDefaultDownloadDialogCornerAlignment; property DefaultDownloadDialogMargin : TPoint read GetDefaultDownloadDialogMargin write SetDefaultDownloadDialogMargin; + property StatusBarText : wvstring read GetStatusBarText; end; implementation @@ -173,15 +182,17 @@ constructor TCoreWebView2.Create(const aBaseIntf : ICoreWebView2); FBaseIntf := aBaseIntf; if Initialized and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_2, FBaseIntf2)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_3, FBaseIntf3)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_4, FBaseIntf4)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_5, FBaseIntf5)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_6, FBaseIntf6)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_7, FBaseIntf7)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_8, FBaseIntf8)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_9, FBaseIntf9)) then - FBaseIntf.QueryInterface(IID_ICoreWebView2_10, FBaseIntf10); + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_2, FBaseIntf2)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_3, FBaseIntf3)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_4, FBaseIntf4)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_5, FBaseIntf5)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_6, FBaseIntf6)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_7, FBaseIntf7)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_8, FBaseIntf8)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_9, FBaseIntf9)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_10, FBaseIntf10)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2_11, FBaseIntf11)) then + FBaseIntf.QueryInterface(IID_ICoreWebView2_12, FBaseIntf12); end; destructor TCoreWebView2.Destroy; @@ -223,6 +234,8 @@ procedure TCoreWebView2.InitializeFields; FBaseIntf8 := nil; FBaseIntf9 := nil; FBaseIntf10 := nil; + FBaseIntf11 := nil; + FBaseIntf12 := nil; FDevToolsEventTokens := nil; FDevToolsEventNames := nil; @@ -256,6 +269,8 @@ procedure TCoreWebView2.InitializeTokens; FIsDocumentPlayingAudioChangedToken.value := 0; FIsDefaultDownloadDialogOpenChangedToken.value := 0; FBasicAuthenticationRequestedToken.value := 0; + FContextMenuRequestedToken.value := 0; + FStatusBarTextChangedToken.value := 0; end; function TCoreWebView2.GetInitialized : boolean; @@ -335,12 +350,10 @@ procedure TCoreWebView2.RemoveAllEvents; FBaseIntf4.remove_DownloadStarting(FDownloadStartingToken); end; - if assigned(FBaseIntf5) then - begin - // Access violation when we try to remove this event - //if (FClientCertificateRequestedToken.value <> 0) then - // FBaseIntf5.remove_ClientCertificateRequested(FClientCertificateRequestedToken); - end; +// Access violation when we try to remove this event +// if assigned(FBaseIntf5) and +// (FClientCertificateRequestedToken.value <> 0) then +// FBaseIntf5.remove_ClientCertificateRequested(FClientCertificateRequestedToken); if assigned(FBaseIntf8) then begin @@ -359,6 +372,14 @@ procedure TCoreWebView2.RemoveAllEvents; (FBasicAuthenticationRequestedToken.Value <> 0) then FBaseIntf10.remove_BasicAuthenticationRequested(FBasicAuthenticationRequestedToken); + if assigned(FBaseIntf11) and + (FContextMenuRequestedToken.Value <> 0) then + FBaseIntf11.remove_ContextMenuRequested(FContextMenuRequestedToken); + + if assigned(FBaseIntf12) and + (FStatusBarTextChangedToken.Value <> 0) then + FBaseIntf12.remove_StatusBarTextChanged(FStatusBarTextChangedToken); + UnsubscribeAllDevToolsProtocolEvents; end; except @@ -745,6 +766,36 @@ function TCoreWebView2.AddBasicAuthenticationRequestedEvent(const aBrowserCompon end; end; +function TCoreWebView2.AddContextMenuRequestedEvent(const aBrowserComponent : TComponent) : boolean; +var + TempHandler : ICoreWebView2ContextMenuRequestedEventHandler; +begin + Result := False; + + if assigned(FBaseIntf11) and (FContextMenuRequestedToken.value = 0) then + try + TempHandler := TCoreWebView2ContextMenuRequestedEventHandler.Create(TWVBrowserBase(aBrowserComponent)); + Result := succeeded(FBaseIntf11.add_ContextMenuRequested(TempHandler, FContextMenuRequestedToken)); + finally + TempHandler := nil; + end; +end; + +function TCoreWebView2.AddStatusBarTextChangedEvent(const aBrowserComponent : TComponent) : boolean; +var + TempHandler : ICoreWebView2StatusBarTextChangedEventHandler; +begin + Result := False; + + if assigned(FBaseIntf12) and (FStatusBarTextChangedToken.value = 0) then + try + TempHandler := TCoreWebView2StatusBarTextChangedEventHandler.Create(TWVBrowserBase(aBrowserComponent)); + Result := succeeded(FBaseIntf12.add_StatusBarTextChanged(TempHandler, FStatusBarTextChangedToken)); + finally + TempHandler := nil; + end; +end; + function TCoreWebView2.AddAllBrowserEvents(const aBrowserComponent : TComponent) : boolean; begin Result := AddNavigationStartingEvent(aBrowserComponent) and @@ -771,7 +822,9 @@ function TCoreWebView2.AddAllBrowserEvents(const aBrowserComponent : TComponent) AddIsMutedChangedEvent(aBrowserComponent) and AddIsDocumentPlayingAudioChangedEvent(aBrowserComponent) and AddIsDefaultDownloadDialogOpenChangedEvent(aBrowserComponent) and - AddBasicAuthenticationRequestedEvent(aBrowserComponent); + AddBasicAuthenticationRequestedEvent(aBrowserComponent) and + AddContextMenuRequestedEvent(aBrowserComponent) and + AddStatusBarTextChangedEvent(aBrowserComponent); end; function TCoreWebView2.AddWebResourceRequestedFilter(const URI : wvstring; @@ -1012,6 +1065,21 @@ function TCoreWebView2.CallDevToolsProtocolMethod(const aMethodName, aParameters end; end; +function TCoreWebView2.CallDevToolsProtocolMethodForSession(const aSessionId, aMethodName, aParametersAsJson : wvstring; aExecutionID : integer; const aBrowserComponent : TComponent) : boolean; +var + TempHandler : ICoreWebView2CallDevToolsProtocolMethodCompletedHandler; +begin + Result := False; + + if assigned(FBaseIntf11) then + try + TempHandler := TCoreWebView2CallDevToolsProtocolMethodCompletedHandler.Create(TWVBrowserBase(aBrowserComponent), aExecutionID); + Result := succeeded(FBaseIntf11.CallDevToolsProtocolMethodForSession(PWideChar(aSessionId), PWideChar(aMethodName), PWideChar(aParametersAsJson), TempHandler)); + finally + TempHandler := nil; + end; +end; + function TCoreWebView2.AddHostObjectToScript(const aName : wvstring; const aObject : OleVariant) : boolean; begin Result := Initialized and @@ -1221,6 +1289,21 @@ function TCoreWebView2.GetDefaultDownloadDialogMargin : TPoint; Result := point(0, 0); end; +function TCoreWebView2.GetStatusBarText : wvstring; +var + TempString : PWideChar; +begin + Result := ''; + TempString := nil; + + if assigned(FBaseIntf12) and + succeeded(FBaseIntf12.Get_StatusBarText(TempString)) then + begin + Result := TempString; + CoTaskMemFree(TempString); + end; +end; + procedure TCoreWebView2.SetIsMuted(aValue : boolean); begin if assigned(FBaseIntf8) then diff --git a/source/uWVCoreWebView2Args.pas b/source/uWVCoreWebView2Args.pas index 63c1d39..6a62fd5 100644 --- a/source/uWVCoreWebView2Args.pas +++ b/source/uWVCoreWebView2Args.pas @@ -5,6 +5,11 @@ interface uses + {$IFDEF FPC} + Types, ActiveX, + {$ELSE} + System.Types, Winapi.ActiveX, + {$ENDIF} uWVTypeLibrary, uWVTypes; type @@ -64,10 +69,12 @@ TCoreWebView2ContentLoadingEventArgs = class TCoreWebView2DevToolsProtocolEventReceivedEventArgs = class protected - FBaseIntf : ICoreWebView2DevToolsProtocolEventReceivedEventArgs; + FBaseIntf : ICoreWebView2DevToolsProtocolEventReceivedEventArgs; + FBaseIntf2 : ICoreWebView2DevToolsProtocolEventReceivedEventArgs2; function GetInitialized : boolean; function GetParameterObjectAsJson : wvstring; + function GetSessionId : wvstring; public constructor Create(const aArgs: ICoreWebView2DevToolsProtocolEventReceivedEventArgs); reintroduce; @@ -76,6 +83,7 @@ TCoreWebView2DevToolsProtocolEventReceivedEventArgs = class property Initialized : boolean read GetInitialized; property BaseIntf : ICoreWebView2DevToolsProtocolEventReceivedEventArgs read FBaseIntf; property ParameterObjectAsJson : wvstring read GetParameterObjectAsJson; + property SessionId : wvstring read GetSessionId; end; TCoreWebView2MoveFocusRequestedEventArgs = class @@ -186,7 +194,8 @@ TCoreWebView2NewWindowRequestedEventArgs = class TCoreWebView2PermissionRequestedEventArgs = class protected - FBaseIntf : ICoreWebView2PermissionRequestedEventArgs; + FBaseIntf : ICoreWebView2PermissionRequestedEventArgs; + FBaseIntf2 : ICoreWebView2PermissionRequestedEventArgs2; function GetInitialized : boolean; function GetURI : wvstring; @@ -194,11 +203,14 @@ TCoreWebView2PermissionRequestedEventArgs = class function GetIsUserInitiated : boolean; function GetState : TWVPermissionState; function GetDeferral : ICoreWebView2Deferral; + function GetHandled : boolean; procedure SetState(aValue : TWVPermissionState); + procedure SetHandled(avalue : boolean); public - constructor Create(const aArgs: ICoreWebView2PermissionRequestedEventArgs); reintroduce; + constructor Create(const aArgs: ICoreWebView2PermissionRequestedEventArgs); reintroduce; overload; + constructor Create(const aArgs: ICoreWebView2PermissionRequestedEventArgs2); reintroduce; overload; destructor Destroy; override; property Initialized : boolean read GetInitialized; @@ -208,6 +220,7 @@ TCoreWebView2PermissionRequestedEventArgs = class property PermissionKind : TWVPermissionKind read GetPermissionKind; property IsUserInitiated : boolean read GetIsUserInitiated; property Deferral : ICoreWebView2Deferral read GetDeferral; + property Handled : boolean read GetHandled write SetHandled; end; TCoreWebView2ProcessFailedEventArgs = class @@ -480,15 +493,38 @@ TCoreWebView2BasicAuthenticationRequestedEventArgs = class property Deferral : ICoreWebView2Deferral read GetDeferral; end; + TCoreWebView2ContextMenuRequestedEventArgs = class + protected + FBaseIntf : ICoreWebView2ContextMenuRequestedEventArgs; + + function GetInitialized : boolean; + function GetMenuItems : ICoreWebView2ContextMenuItemCollection; + function GetContextMenuTarget : ICoreWebView2ContextMenuTarget; + function GetLocation : TPoint; + function GetSelectedCommandId : Integer; + function GetDeferral : ICoreWebView2Deferral; + function GetHandled : boolean; + + procedure SetSelectedCommandId(aValue: Integer); + procedure SetHandled(aValue : boolean); + + public + constructor Create(const aArgs: ICoreWebView2ContextMenuRequestedEventArgs); reintroduce; + destructor Destroy; override; + + property Initialized : boolean read GetInitialized; + property BaseIntf : ICoreWebView2ContextMenuRequestedEventArgs read FBaseIntf; + property MenuItems : ICoreWebView2ContextMenuItemCollection read GetMenuItems; + property ContextMenuTarget : ICoreWebView2ContextMenuTarget read GetContextMenuTarget; + property Location : TPoint read GetLocation; + property SelectedCommandId : integer read GetSelectedCommandId write SetSelectedCommandId; + property Handled : boolean read GetHandled write SetHandled; + property Deferral : ICoreWebView2Deferral read GetDeferral; + end; + implementation -uses - {$IFDEF FPC} - ActiveX; - {$ELSE} - Winapi.ActiveX; - {$ENDIF} // TCoreWebView2AcceleratorKeyPressedEventArgs @@ -661,6 +697,9 @@ constructor TCoreWebView2DevToolsProtocolEventReceivedEventArgs.Create(const aAr inherited Create; FBaseIntf := aArgs; + + if Initialized then + FBaseIntf.QueryInterface(ICoreWebView2DevToolsProtocolEventReceivedEventArgs2, FBaseIntf2); end; destructor TCoreWebView2DevToolsProtocolEventReceivedEventArgs.Destroy; @@ -679,13 +718,28 @@ function TCoreWebView2DevToolsProtocolEventReceivedEventArgs.GetParameterObjectA var TempString : PWideChar; begin - if Initialized and succeeded(FBaseIntf.Get_ParameterObjectAsJson(TempString)) then + Result := ''; + + if Initialized and + succeeded(FBaseIntf.Get_ParameterObjectAsJson(TempString)) then begin Result := TempString; CoTaskMemFree(TempString); - end - else - Result := ''; + end; +end; + +function TCoreWebView2DevToolsProtocolEventReceivedEventArgs.GetSessionId : wvstring; +var + TempString : PWideChar; +begin + Result := ''; + + if assigned(FBaseIntf2) and + succeeded(FBaseIntf2.Get_sessionId(TempString)) then + begin + Result := TempString; + CoTaskMemFree(TempString); + end; end; @@ -1047,6 +1101,17 @@ constructor TCoreWebView2PermissionRequestedEventArgs.Create(const aArgs: ICoreW inherited Create; FBaseIntf := aArgs; + + if Initialized then + FBaseIntf.QueryInterface(ICoreWebView2PermissionRequestedEventArgs2, FBaseIntf2); +end; + +constructor TCoreWebView2PermissionRequestedEventArgs.Create(const aArgs: ICoreWebView2PermissionRequestedEventArgs2); +begin + inherited Create; + + aArgs.QueryInterface(ICoreWebView2PermissionRequestedEventArgs, FBaseIntf); + FBaseIntf2 := aArgs; end; destructor TCoreWebView2PermissionRequestedEventArgs.Destroy; @@ -1121,12 +1186,27 @@ function TCoreWebView2PermissionRequestedEventArgs.GetDeferral : ICoreWebView2De Result := TempDeferral; end; +function TCoreWebView2PermissionRequestedEventArgs.GetHandled : boolean; +var + TempResult : integer; +begin + Result := assigned(FBaseIntf2) and + succeeded(FBaseIntf2.Get_Handled(TempResult)) and + (TempResult <> 0); +end; + procedure TCoreWebView2PermissionRequestedEventArgs.SetState(aValue : TWVPermissionState); begin if Initialized then FBaseIntf.Set_State(aValue); end; +procedure TCoreWebView2PermissionRequestedEventArgs.SetHandled(avalue : boolean); +begin + if assigned(FBaseIntf2) then + FBaseIntf2.Set_Handled(ord(aValue)); +end; + // TCoreWebView2ProcessFailedEventArgs @@ -2001,4 +2081,113 @@ procedure TCoreWebView2BasicAuthenticationRequestedEventArgs.SetCancel(aValue : FBaseIntf.Set_Cancel(ord(aValue)); end; + +// TCoreWebView2ContextMenuRequestedEventArgs + +constructor TCoreWebView2ContextMenuRequestedEventArgs.Create(const aArgs: ICoreWebView2ContextMenuRequestedEventArgs); +begin + inherited Create; + + FBaseIntf := aArgs; +end; + +destructor TCoreWebView2ContextMenuRequestedEventArgs.Destroy; +begin + FBaseIntf := nil; + + inherited Destroy; +end; + +function TCoreWebView2ContextMenuRequestedEventArgs.GetInitialized : boolean; +begin + Result := assigned(FBaseIntf); +end; + +function TCoreWebView2ContextMenuRequestedEventArgs.GetMenuItems : ICoreWebView2ContextMenuItemCollection; +var + TempResult : ICoreWebView2ContextMenuItemCollection; +begin + Result := nil; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_MenuItems(TempResult)) and + (TempResult <> nil) then + Result := TempResult; +end; + +function TCoreWebView2ContextMenuRequestedEventArgs.GetContextMenuTarget : ICoreWebView2ContextMenuTarget; +var + TempResult : ICoreWebView2ContextMenuTarget; +begin + Result := nil; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_ContextMenuTarget(TempResult)) and + (TempResult <> nil) then + Result := TempResult; +end; + +function TCoreWebView2ContextMenuRequestedEventArgs.GetLocation : TPoint; +var + TempResult : tagPOINT; +begin + Result.x := low(integer); + Result.y := low(integer); + + if Initialized and + succeeded(FBaseIntf.Get_Location(TempResult)) then + begin + Result.x := TempResult.x; + Result.y := TempResult.y; + end; +end; + +function TCoreWebView2ContextMenuRequestedEventArgs.GetSelectedCommandId : Integer; +var + TempResult : integer; +begin + Result := -1; + TempResult := -1; + + if Initialized and + succeeded(FBaseIntf.Get_SelectedCommandId(TempResult)) then + Result := TempResult; +end; + +function TCoreWebView2ContextMenuRequestedEventArgs.GetHandled : boolean; +var + TempInt : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_Handled(TempInt)) and + (TempInt <> 0); +end; + +function TCoreWebView2ContextMenuRequestedEventArgs.GetDeferral : ICoreWebView2Deferral; +var + TempResult : ICoreWebView2Deferral; +begin + Result := nil; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.GetDeferral(TempResult)) and + (TempResult <> nil) then + Result := TempResult; +end; + +procedure TCoreWebView2ContextMenuRequestedEventArgs.SetSelectedCommandId(aValue: Integer); +begin + if Initialized then + FBaseIntf.Set_SelectedCommandId(aValue); +end; + +procedure TCoreWebView2ContextMenuRequestedEventArgs.SetHandled(aValue : boolean); +begin + if Initialized then + FBaseIntf.Set_Handled(ord(aValue)); +end; + end. diff --git a/source/uWVCoreWebView2CompositionController.pas b/source/uWVCoreWebView2CompositionController.pas index 42976c9..a206187 100644 --- a/source/uWVCoreWebView2CompositionController.pas +++ b/source/uWVCoreWebView2CompositionController.pas @@ -23,7 +23,7 @@ TCoreWebView2CompositionController = class function GetRootVisualTarget : IUnknown; function GetCursor : HCURSOR; function GetSystemCursorID : cardinal; - function GetUIAProvider : IUnknown; + function GetAutomationProvider : IUnknown; procedure SetRootVisualTarget(const aValue : IUnknown); @@ -45,7 +45,7 @@ TCoreWebView2CompositionController = class property RootVisualTarget : IUnknown read GetRootVisualTarget write SetRootVisualTarget; property Cursor : HCURSOR read GetCursor; property SystemCursorID : cardinal read GetSystemCursorID; - property UIAProvider : IUnknown read GetUIAProvider; + property AutomationProvider : IUnknown read GetAutomationProvider; end; implementation @@ -128,7 +128,7 @@ function TCoreWebView2CompositionController.GetSystemCursorID : cardinal; Result := 0; end; -function TCoreWebView2CompositionController.GetUIAProvider : IUnknown; +function TCoreWebView2CompositionController.GetAutomationProvider : IUnknown; var TempResult : IUnknown; begin @@ -136,7 +136,7 @@ function TCoreWebView2CompositionController.GetUIAProvider : IUnknown; TempResult := nil; if assigned(FBaseIntf2) and - succeeded(FBaseIntf2.Get_UIAProvider(TempResult)) and + succeeded(FBaseIntf2.Get_AutomationProvider(TempResult)) and assigned(TempResult) then Result := TempResult; end; diff --git a/source/uWVCoreWebView2ContextMenuItem.pas b/source/uWVCoreWebView2ContextMenuItem.pas new file mode 100644 index 0000000..a3f25bd --- /dev/null +++ b/source/uWVCoreWebView2ContextMenuItem.pas @@ -0,0 +1,223 @@ +unit uWVCoreWebView2ContextMenuItem; + +{$IFDEF FPC}{$MODE Delphi}{$ENDIF} + +{$I webview2.inc} + +interface + +uses + {$IFDEF FPC} + Classes, ActiveX, + {$ELSE} + System.Classes, Winapi.ActiveX, + {$ENDIF} + uWVTypeLibrary, uWVTypes; + +type + TCoreWebView2ContextMenuItem = class + protected + FBaseIntf : ICoreWebView2ContextMenuItem; + + function GetInitialized : boolean; + function GetName : wvstring; + function GetLabel : wvstring; + function GetCommandId : integer; + function GetShortcutKeyDescription : wvstring; + function GetIcon : IStream; + function GetKind : TWVMenuItemKind; + function GetIsEnabled : boolean; + function GetIsChecked : boolean; + function GetChildren : ICoreWebView2ContextMenuItemCollection; + + procedure SetIsEnabled(aValue : boolean); + procedure SetIsChecked(aValue : boolean); + + public + constructor Create(const aBaseIntf : ICoreWebView2ContextMenuItem); reintroduce; + destructor Destroy; override; + function AddCustomItemSelectedEvent(const aBrowserComponent : TComponent) : boolean; + + property Initialized : boolean read GetInitialized; + property BaseIntf : ICoreWebView2ContextMenuItem read FBaseIntf write FBaseIntf; + property Name : wvstring read GetName; + property Label_ : wvstring read GetLabel; + property CommandId : integer read GetCommandId; + property ShortcutKeyDescription : wvstring read GetShortcutKeyDescription; + property Icon : IStream read GetIcon; + property Kind : TWVMenuItemKind read GetKind; + property IsEnabled : boolean read GetIsEnabled write SetIsEnabled; + property IsChecked : boolean read GetIsChecked write SetIsChecked; + property Children : ICoreWebView2ContextMenuItemCollection read GetChildren; + end; + +implementation + +uses + uWVBrowserBase, uWVCoreWebView2Delegates, uWVMiscFunctions; + +constructor TCoreWebView2ContextMenuItem.Create(const aBaseIntf: ICoreWebView2ContextMenuItem); +begin + inherited Create; + + FBaseIntf := aBaseIntf; +end; + +destructor TCoreWebView2ContextMenuItem.Destroy; +begin + FBaseIntf := nil; + + inherited Destroy; +end; + +function TCoreWebView2ContextMenuItem.GetInitialized : boolean; +begin + Result := assigned(FBaseIntf); +end; + +function TCoreWebView2ContextMenuItem.GetName : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_name(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +function TCoreWebView2ContextMenuItem.GetLabel : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_Label_(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +function TCoreWebView2ContextMenuItem.GetCommandId : integer; +var + TempResult : integer; +begin + Result := -1; + + if Initialized and + succeeded(FBaseIntf.Get_CommandId(TempResult)) then + Result := TempResult; +end; + +function TCoreWebView2ContextMenuItem.GetShortcutKeyDescription : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_ShortcutKeyDescription(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +function TCoreWebView2ContextMenuItem.GetIcon : IStream; +var + TempResult : IStream; +begin + Result := nil; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_Icon(TempResult)) and + assigned(TempResult) then + Result := TempResult; +end; + +function TCoreWebView2ContextMenuItem.GetKind : TWVMenuItemKind; +var + TempResult : COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND; +begin + Result := 0; + + if Initialized and + succeeded(FBaseIntf.Get_Kind(TempResult)) then + Result := TempResult; +end; + +function TCoreWebView2ContextMenuItem.GetIsEnabled : boolean; +var + TempResult : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_IsEnabled(TempResult)) and + (TempResult <> 0); +end; + +function TCoreWebView2ContextMenuItem.GetIsChecked : boolean; +var + TempResult : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_IsChecked(TempResult)) and + (TempResult <> 0); +end; + +function TCoreWebView2ContextMenuItem.GetChildren : ICoreWebView2ContextMenuItemCollection; +var + TempResult : ICoreWebView2ContextMenuItemCollection; +begin + Result := nil; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_Children(TempResult)) and + assigned(TempResult) then + Result := TempResult; +end; + +procedure TCoreWebView2ContextMenuItem.SetIsEnabled(aValue : boolean); +begin + if Initialized then + FBaseIntf.Set_IsEnabled(ord(aValue)); +end; + +procedure TCoreWebView2ContextMenuItem.SetIsChecked(aValue : boolean); +begin + if Initialized then + FBaseIntf.Set_IsChecked(ord(aValue)); +end; + +function TCoreWebView2ContextMenuItem.AddCustomItemSelectedEvent(const aBrowserComponent : TComponent) : boolean; +var + TempHandler : ICoreWebView2CustomItemSelectedEventHandler; + TempToken : EventRegistrationToken; +begin + Result := False; + + if Initialized then + try + TempHandler := TCoreWebView2CustomItemSelectedEventHandler.Create(TWVBrowserBase(aBrowserComponent)); + TempToken.value := 0; + Result := succeeded(FBaseIntf.add_CustomItemSelected(TempHandler, TempToken)); + finally + TempHandler := nil; + end; +end; + + +end. + diff --git a/source/uWVCoreWebView2ContextMenuItemCollection.pas b/source/uWVCoreWebView2ContextMenuItemCollection.pas new file mode 100644 index 0000000..b43d77d --- /dev/null +++ b/source/uWVCoreWebView2ContextMenuItemCollection.pas @@ -0,0 +1,167 @@ +unit uWVCoreWebView2ContextMenuItemCollection; + +{$IFDEF FPC}{$MODE Delphi}{$ENDIF} + +interface + +uses + uWVTypeLibrary, uWVTypes; + +type + TCoreWebView2ContextMenuItemCollection = class + protected + FBaseIntf : ICoreWebView2ContextMenuItemCollection; + + function GetInitialized : boolean; + function GetCount : cardinal; + function GetValueAtIndex(index : cardinal) : ICoreWebView2ContextMenuItem; + + public + constructor Create(const aBaseIntf : ICoreWebView2ContextMenuItemCollection); reintroduce; + destructor Destroy; override; + function RemoveValueAtIndex(index: cardinal): boolean; + function InsertValueAtIndex(index: cardinal; const aValue: ICoreWebView2ContextMenuItem): boolean; + procedure RemoveAllMenuItems; + procedure RemoveMenuItem(aCommandId : integer); overload; + procedure RemoveMenuItem(const aLabel : wvstring); overload; + + property Initialized : boolean read GetInitialized; + property BaseIntf : ICoreWebView2ContextMenuItemCollection read FBaseIntf; + property Count : cardinal read GetCount; + property Items[idx : cardinal] : ICoreWebView2ContextMenuItem read GetValueAtIndex; + end; + +implementation + +uses + {$IFDEF FPC} + SysUtils, ActiveX, + {$ELSE} + System.SysUtils, Winapi.ActiveX, + {$ENDIF} + uWVCoreWebView2ContextMenuItem; + +constructor TCoreWebView2ContextMenuItemCollection.Create(const aBaseIntf: ICoreWebView2ContextMenuItemCollection); +begin + inherited Create; + + FBaseIntf := aBaseIntf; +end; + +destructor TCoreWebView2ContextMenuItemCollection.Destroy; +begin + FBaseIntf := nil; + + inherited Destroy; +end; + +function TCoreWebView2ContextMenuItemCollection.GetInitialized : boolean; +begin + Result := assigned(FBaseIntf); +end; + +function TCoreWebView2ContextMenuItemCollection.GetCount : cardinal; +var + TempResult : SYSUINT; +begin + Result := 0; + TempResult := 0; + + if Initialized and + succeeded(FBaseIntf.Get_Count(TempResult)) then + Result := TempResult; +end; + +function TCoreWebView2ContextMenuItemCollection.GetValueAtIndex(index : cardinal) : ICoreWebView2ContextMenuItem; +var + TempResult : ICoreWebView2ContextMenuItem; +begin + Result := nil; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.GetValueAtIndex(index, TempResult)) and + (TempResult <> nil) then + Result := TempResult; +end; + +function TCoreWebView2ContextMenuItemCollection.RemoveValueAtIndex(index: cardinal): boolean; +begin + Result := Initialized and + succeeded(FBaseIntf.RemoveValueAtIndex(index)); +end; + +function TCoreWebView2ContextMenuItemCollection.InsertValueAtIndex(index: cardinal; const aValue: ICoreWebView2ContextMenuItem): boolean; +begin + Result := Initialized and + succeeded(FBaseIntf.InsertValueAtIndex(index, aValue)); +end; + +procedure TCoreWebView2ContextMenuItemCollection.RemoveAllMenuItems; +var + i : cardinal; +begin + if (Count > 0) then + for i := pred(Count) downto 0 do + RemoveValueAtIndex(i); +end; + +procedure TCoreWebView2ContextMenuItemCollection.RemoveMenuItem(aCommandId : integer); +var + TempItem : TCoreWebView2ContextMenuItem; + i : cardinal; +begin + TempItem := nil; + + try + if (Count > 0) then + for i := pred(Count) downto 0 do + begin + if assigned(TempItem) then + TempItem.BaseIntf := Items[i] + else + TempItem := TCoreWebView2ContextMenuItem.Create(Items[i]); + + if (TempItem.Kind = COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_COMMAND) and + (TempItem.CommandId = aCommandId) then + begin + RemoveValueAtIndex(i); + break; + end; + end; + finally + if assigned(TempItem) then + FreeAndNil(TempItem); + end; +end; + +procedure TCoreWebView2ContextMenuItemCollection.RemoveMenuItem(const aLabel : wvstring); +var + TempItem : TCoreWebView2ContextMenuItem; + i : cardinal; +begin + TempItem := nil; + + try + if (Count > 0) then + for i := pred(Count) downto 0 do + begin + if assigned(TempItem) then + TempItem.BaseIntf := Items[i] + else + TempItem := TCoreWebView2ContextMenuItem.Create(Items[i]); + + if (TempItem.Kind = COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_COMMAND) and + (TempItem.Label_ = aLabel) then + begin + RemoveValueAtIndex(i); + break; + end; + end; + finally + if assigned(TempItem) then + FreeAndNil(TempItem); + end; +end; + +end. diff --git a/source/uWVCoreWebView2ContextMenuTarget.pas b/source/uWVCoreWebView2ContextMenuTarget.pas new file mode 100644 index 0000000..e1fcba6 --- /dev/null +++ b/source/uWVCoreWebView2ContextMenuTarget.pas @@ -0,0 +1,241 @@ +unit uWVCoreWebView2ContextMenuTarget; + +{$IFDEF FPC}{$MODE Delphi}{$ENDIF} + +interface + +uses + uWVTypeLibrary, uWVTypes; + +type + TCoreWebView2ContextMenuTarget = class + protected + FBaseIntf : ICoreWebView2ContextMenuTarget; + + function GetInitialized : boolean; + function GetKind : TWVMenuTargetKind; + function GetIsEditable : boolean; + function GetIsRequestedForMainFrame : boolean; + function GetPageUri : wvstring; + function GetFrameUri : wvstring; + function GetHasLinkUri : boolean; + function GetLinkUri : wvstring; + function GetHasLinkText : boolean; + function GetLinkText : wvstring; + function GetHasSourceUri : boolean; + function GetSourceUri : wvstring; + function GetHasSelection : boolean; + function GetSelectionText : wvstring; + + public + constructor Create(const aBaseIntf : ICoreWebView2ContextMenuTarget); reintroduce; + destructor Destroy; override; + + property Initialized : boolean read GetInitialized; + property BaseIntf : ICoreWebView2ContextMenuTarget read FBaseIntf; + property Kind : TWVMenuTargetKind read GetKind; + property IsEditable : boolean read GetIsEditable; + property IsRequestedForMainFrame : boolean read GetIsRequestedForMainFrame; + property PageUri : wvstring read GetPageUri; + property FrameUri : wvstring read GetFrameUri; + property HasLinkUri : boolean read GetHasLinkUri; + property LinkUri : wvstring read GetLinkUri; + property HasLinkText : boolean read GetHasLinkText; + property LinkText : wvstring read GetLinkText; + property HasSourceUri : boolean read GetHasSourceUri; + property SourceUri : wvstring read GetSourceUri; + property HasSelection : boolean read GetHasSelection; + property SelectionText : wvstring read GetSelectionText; + end; + +implementation + +uses + {$IFDEF FPC} + ActiveX; + {$ELSE} + Winapi.ActiveX; + {$ENDIF} + +constructor TCoreWebView2ContextMenuTarget.Create(const aBaseIntf: ICoreWebView2ContextMenuTarget); +begin + inherited Create; + + FBaseIntf := aBaseIntf; +end; + +destructor TCoreWebView2ContextMenuTarget.Destroy; +begin + FBaseIntf := nil; + + inherited Destroy; +end; + +function TCoreWebView2ContextMenuTarget.GetInitialized : boolean; +begin + Result := assigned(FBaseIntf); +end; + +function TCoreWebView2ContextMenuTarget.GetKind : TWVMenuTargetKind; +var + TempResult : COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND; +begin + if Initialized and + succeeded(FBaseIntf.Get_Kind(TempResult)) then + Result := TempResult + else + Result := 0; +end; + +function TCoreWebView2ContextMenuTarget.GetIsEditable : boolean; +var + TempResult : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_IsEditable(TempResult)) and + (TempResult <> 0); +end; + +function TCoreWebView2ContextMenuTarget.GetIsRequestedForMainFrame : boolean; +var + TempResult : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_IsRequestedForMainFrame(TempResult)) and + (TempResult <> 0); +end; + +function TCoreWebView2ContextMenuTarget.GetPageUri : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_PageUri(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +function TCoreWebView2ContextMenuTarget.GetFrameUri : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_FrameUri(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +function TCoreWebView2ContextMenuTarget.GetHasLinkUri : boolean; +var + TempResult : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_HasLinkUri(TempResult)) and + (TempResult <> 0); +end; + +function TCoreWebView2ContextMenuTarget.GetLinkUri : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_LinkUri(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +function TCoreWebView2ContextMenuTarget.GetHasLinkText : boolean; +var + TempResult : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_HasLinkText(TempResult)) and + (TempResult <> 0); +end; + +function TCoreWebView2ContextMenuTarget.GetLinkText : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_LinkText(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +function TCoreWebView2ContextMenuTarget.GetHasSourceUri : boolean; +var + TempResult : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_HasSourceUri(TempResult)) and + (TempResult <> 0); +end; + +function TCoreWebView2ContextMenuTarget.GetSourceUri : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_SourceUri(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +function TCoreWebView2ContextMenuTarget.GetHasSelection : boolean; +var + TempResult : integer; +begin + Result := Initialized and + succeeded(FBaseIntf.Get_HasSelection(TempResult)) and + (TempResult <> 0); +end; + +function TCoreWebView2ContextMenuTarget.GetSelectionText : wvstring; +var + TempResult : PWideChar; +begin + Result := ''; + TempResult := nil; + + if Initialized and + succeeded(FBaseIntf.Get_SelectionText(TempResult)) and + (TempResult <> nil) then + begin + Result := TempResult; + CoTaskMemFree(TempResult); + end; +end; + +end. + diff --git a/source/uWVCoreWebView2Controller.pas b/source/uWVCoreWebView2Controller.pas index 500b59b..8c94fb2 100644 --- a/source/uWVCoreWebView2Controller.pas +++ b/source/uWVCoreWebView2Controller.pas @@ -18,6 +18,7 @@ TCoreWebView2Controller = class FBaseIntf : ICoreWebView2Controller; FBaseIntf2 : ICoreWebView2Controller2; FBaseIntf3 : ICoreWebView2Controller3; + FBaseIntf4 : ICoreWebView2Controller4; FAcceleratorKeyPressedToken : EventRegistrationToken; FGotFocusToken : EventRegistrationToken; FLostFocusToken : EventRegistrationToken; @@ -35,6 +36,7 @@ TCoreWebView2Controller = class function GetShouldDetectMonitorScaleChanges : boolean; function GetBoundsMode : TWVBoundsMode; function GetCoreWebView2 : ICoreWebView2; + function GetAllowExternalDrop : boolean; procedure SetZoomFactor(const aValue : double); procedure SetIsVisible(const aValue : boolean); @@ -44,6 +46,7 @@ TCoreWebView2Controller = class procedure SetRasterizationScale(const aValue : double); procedure SetShouldDetectMonitorScaleChanges(aValue : boolean); procedure SetBoundsMode(aValue : TWVBoundsMode); + procedure SetAllowExternalDrop(aValue : boolean); procedure InitializeFields; procedure InitializeTokens; @@ -76,6 +79,7 @@ TCoreWebView2Controller = class property ShouldDetectMonitorScaleChanges : boolean read GetShouldDetectMonitorScaleChanges write SetShouldDetectMonitorScaleChanges; property BoundsMode : TWVBoundsMode read GetBoundsMode write SetBoundsMode; property CoreWebView2 : ICoreWebView2 read GetCoreWebView2; + property AllowExternalDrop : boolean read GetAllowExternalDrop write SetAllowExternalDrop; end; implementation @@ -92,8 +96,9 @@ constructor TCoreWebView2Controller.Create(const aBaseIntf : ICoreWebView2Contro FBaseIntf := aBaseIntf; if Initialized and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Controller2, FBaseIntf2)) then - FBaseIntf.QueryInterface(IID_ICoreWebView2Controller3, FBaseIntf3); + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Controller2, FBaseIntf2)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Controller3, FBaseIntf3)) then + FBaseIntf.QueryInterface(IID_ICoreWebView2Controller4, FBaseIntf4); end; destructor TCoreWebView2Controller.Destroy; @@ -112,6 +117,7 @@ procedure TCoreWebView2Controller.InitializeFields; FBaseIntf := nil; FBaseIntf2 := nil; FBaseIntf3 := nil; + FBaseIntf4 := nil; InitializeTokens; end; @@ -282,6 +288,15 @@ function TCoreWebView2Controller.GetCoreWebView2 : ICoreWebView2; Result := TempResult; end; +function TCoreWebView2Controller.GetAllowExternalDrop : boolean; +var + TempResult : integer; +begin + Result := assigned(FBaseIntf4) and + succeeded(FBaseIntf4.Get_AllowExternalDrop(TempResult)) and + (TempResult <> 0); +end; + function TCoreWebView2Controller.SetBoundsAndZoomFactor(aBounds: TRect; const aZoomFactor: double) : boolean; begin Result := Initialized and @@ -346,6 +361,12 @@ procedure TCoreWebView2Controller.SetBoundsMode(aValue : TWVBoundsMode); FBaseIntf3.Set_BoundsMode(aValue); end; +procedure TCoreWebView2Controller.SetAllowExternalDrop(aValue : boolean); +begin + if assigned(FBaseIntf4) then + FBaseIntf4.Set_AllowExternalDrop(ord(aValue)); +end; + function TCoreWebView2Controller.GetIsVisible : boolean; var TempResult : integer; diff --git a/source/uWVCoreWebView2Delegates.pas b/source/uWVCoreWebView2Delegates.pas index 0b730a5..95d0765 100644 --- a/source/uWVCoreWebView2Delegates.pas +++ b/source/uWVCoreWebView2Delegates.pas @@ -668,6 +668,51 @@ TCoreWebView2BasicAuthenticationRequestedEventHandler = class(TInterfacedObjec destructor Destroy; override; end; + TCoreWebView2ContextMenuRequestedEventHandler = class(TInterfacedObject, ICoreWebView2ContextMenuRequestedEventHandler) + protected + FEvents : Pointer; + + function Invoke(const sender: ICoreWebView2; const args: ICoreWebView2ContextMenuRequestedEventArgs): HResult; stdcall; + + public + constructor Create(const aEvents: IWVBrowserEvents); reintroduce; + destructor Destroy; override; + end; + + TCoreWebView2CustomItemSelectedEventHandler = class(TInterfacedObject, ICoreWebView2CustomItemSelectedEventHandler) + protected + FEvents : Pointer; + + function Invoke(const sender: ICoreWebView2ContextMenuItem; const args: IUnknown): HResult; stdcall; + + public + constructor Create(const aEvents: IWVBrowserEvents); reintroduce; + destructor Destroy; override; + end; + + TCoreWebView2StatusBarTextChangedEventHandler = class(TInterfacedObject, ICoreWebView2StatusBarTextChangedEventHandler) + protected + FEvents : Pointer; + + function Invoke(const sender: ICoreWebView2; const args: IUnknown): HResult; stdcall; + + public + constructor Create(const aEvents: IWVBrowserEvents); reintroduce; + destructor Destroy; override; + end; + + TCoreWebView2FramePermissionRequestedEventHandler = class(TInterfacedObject, ICoreWebView2FramePermissionRequestedEventHandler) + protected + FEvents : Pointer; + FFrameID : integer; + + function Invoke(const sender: ICoreWebView2Frame; const args: ICoreWebView2PermissionRequestedEventArgs2): HResult; stdcall; + + public + constructor Create(const aEvents: IWVBrowserEvents; aFrameID : integer); reintroduce; + destructor Destroy; override; + end; + implementation @@ -2165,4 +2210,108 @@ function TCoreWebView2BasicAuthenticationRequestedEventHandler.Invoke(const send end; +// TCoreWebView2ContextMenuRequestedEventHandler + +constructor TCoreWebView2ContextMenuRequestedEventHandler.Create(const aEvents: IWVBrowserEvents); +begin + inherited Create; + + FEvents := Pointer(aEvents); +end; + +destructor TCoreWebView2ContextMenuRequestedEventHandler.Destroy; +begin + FEvents := nil; + + inherited Destroy; +end; + +function TCoreWebView2ContextMenuRequestedEventHandler.Invoke(const sender : ICoreWebView2; + const args : ICoreWebView2ContextMenuRequestedEventArgs): HResult; stdcall; +begin + if (FEvents <> nil) then + Result := IWVBrowserEvents(FEvents).ContextMenuRequestedEventHandler_Invoke(sender, args) + else + Result := E_FAIL; +end; + + +// TCoreWebView2CustomItemSelectedEventHandler + +constructor TCoreWebView2CustomItemSelectedEventHandler.Create(const aEvents: IWVBrowserEvents); +begin + inherited Create; + + FEvents := Pointer(aEvents); +end; + +destructor TCoreWebView2CustomItemSelectedEventHandler.Destroy; +begin + FEvents := nil; + + inherited Destroy; +end; + +function TCoreWebView2CustomItemSelectedEventHandler.Invoke(const sender : ICoreWebView2ContextMenuItem; + const args : IUnknown): HResult; stdcall; +begin + if (FEvents <> nil) then + Result := IWVBrowserEvents(FEvents).CustomItemSelectedEventHandler_Invoke(sender, args) + else + Result := E_FAIL; +end; + + +// TCoreWebView2StatusBarTextChangedEventHandler + +constructor TCoreWebView2StatusBarTextChangedEventHandler.Create(const aEvents: IWVBrowserEvents); +begin + inherited Create; + + FEvents := Pointer(aEvents); +end; + +destructor TCoreWebView2StatusBarTextChangedEventHandler.Destroy; +begin + FEvents := nil; + + inherited Destroy; +end; + +function TCoreWebView2StatusBarTextChangedEventHandler.Invoke(const sender: ICoreWebView2; const args: IUnknown): HResult; stdcall; +begin + if (FEvents <> nil) then + Result := IWVBrowserEvents(FEvents).StatusBarTextChangedEventHandler_Invoke(sender, args) + else + Result := E_FAIL; +end; + + +// TCoreWebView2FramePermissionRequestedEventHandler + +constructor TCoreWebView2FramePermissionRequestedEventHandler.Create(const aEvents: IWVBrowserEvents; aFrameID : integer); +begin + inherited Create; + + FEvents := Pointer(aEvents); + FFrameID := aFrameID; +end; + +destructor TCoreWebView2FramePermissionRequestedEventHandler.Destroy; +begin + FEvents := nil; + + inherited Destroy; +end; + +function TCoreWebView2FramePermissionRequestedEventHandler.Invoke(const sender : ICoreWebView2Frame; + const args : ICoreWebView2PermissionRequestedEventArgs2): HResult; stdcall; +begin + if (FEvents <> nil) then + Result := IWVBrowserEvents(FEvents).FramePermissionRequestedEventHandler_Invoke(sender, args, FFrameID) + else + Result := E_FAIL; +end; + + end. diff --git a/source/uWVCoreWebView2Environment.pas b/source/uWVCoreWebView2Environment.pas index 2c0d8a0..93893ee 100644 --- a/source/uWVCoreWebView2Environment.pas +++ b/source/uWVCoreWebView2Environment.pas @@ -23,6 +23,7 @@ TCoreWebView2Environment = class FBaseIntf6 : ICoreWebView2Environment6; FBaseIntf7 : ICoreWebView2Environment7; FBaseIntf8 : ICoreWebView2Environment8; + FBaseIntf9 : ICoreWebView2Environment9; FNewBrowserVersionAvailableEventToken : EventRegistrationToken; FBrowserProcessExitedEventToken : EventRegistrationToken; FProcessInfosChangedEventToken : EventRegistrationToken; @@ -53,8 +54,9 @@ TCoreWebView2Environment = class function CreateWebResourceRequest(const aURI, aMethod : wvstring; const aPostData : IStream; const aHeaders : wvstring; var aRequest : ICoreWebView2WebResourceRequest): boolean; function CreateCoreWebView2CompositionController(aParentWindow : THandle; const aBrowserEvents : IWVBrowserEvents; var aResult: HRESULT) : boolean; function CreateCoreWebView2PointerInfo(var aPointerInfo : ICoreWebView2PointerInfo) : boolean; - function GetProviderForHwnd(aHandle : THandle; var aProvider : IUnknown) : boolean; + function GetAutomationProviderForWindow(aHandle : THandle; var aProvider : IUnknown) : boolean; function CreatePrintSettings(var aPrintSettings : ICoreWebView2PrintSettings) : boolean; + function CreateContextMenuItem(const aLabel : wvstring; const aIconStream : IStream; aKind : TWVMenuItemKind; var aMenuItem : ICoreWebView2ContextMenuItem) : boolean; property Initialized : boolean read GetInitialized; property BaseIntf : ICoreWebView2Environment read FBaseIntf; @@ -83,8 +85,9 @@ constructor TCoreWebView2Environment.Create(const aBaseIntf : ICoreWebView2Envir succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Environment4, FBaseIntf4)) and succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Environment5, FBaseIntf5)) and succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Environment6, FBaseIntf6)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Environment7, FBaseIntf7)) then - FBaseIntf.QueryInterface(IID_ICoreWebView2Environment8, FBaseIntf8); + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Environment7, FBaseIntf7)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Environment8, FBaseIntf8)) then + FBaseIntf.QueryInterface(IID_ICoreWebView2Environment9, FBaseIntf9); end; destructor TCoreWebView2Environment.Destroy; @@ -107,6 +110,7 @@ procedure TCoreWebView2Environment.InitializeFields; FBaseIntf6 := nil; FBaseIntf7 := nil; FBaseIntf8 := nil; + FBaseIntf9 := nil; InitializeTokens; end; @@ -320,11 +324,11 @@ function TCoreWebView2Environment.CreateCoreWebView2PointerInfo(var aPointerInfo succeeded(FBaseIntf3.CreateCoreWebView2PointerInfo(aPointerInfo)); end; -function TCoreWebView2Environment.GetProviderForHwnd(aHandle : THandle; var aProvider: IUnknown) : boolean; +function TCoreWebView2Environment.GetAutomationProviderForWindow(aHandle : THandle; var aProvider: IUnknown) : boolean; begin aProvider := nil; Result := assigned(FBaseIntf4) and - succeeded(FBaseIntf4.GetProviderForHwnd(aHandle, aProvider)); + succeeded(FBaseIntf4.GetAutomationProviderForWindow(aHandle, aProvider)); end; function TCoreWebView2Environment.CreatePrintSettings(var aPrintSettings: ICoreWebView2PrintSettings): boolean; @@ -335,6 +339,17 @@ function TCoreWebView2Environment.CreatePrintSettings(var aPrintSettings: ICoreW assigned(aPrintSettings); end; +function TCoreWebView2Environment.CreateContextMenuItem(const aLabel : wvstring; + const aIconStream : IStream; + aKind : TWVMenuItemKind; + var aMenuItem : ICoreWebView2ContextMenuItem) : boolean; +begin + aMenuItem := nil; + Result := assigned(FBaseIntf9) and + succeeded(FBaseIntf9.CreateContextMenuItem(PWideChar(aLabel), aIconStream, aKind, aMenuItem)) and + assigned(aMenuItem); +end; + function TCoreWebView2Environment.GetUserDataFolder : wvstring; var TempString : PWideChar; diff --git a/source/uWVCoreWebView2EnvironmentOptions.pas b/source/uWVCoreWebView2EnvironmentOptions.pas index 619d49f..3cfdec6 100644 --- a/source/uWVCoreWebView2EnvironmentOptions.pas +++ b/source/uWVCoreWebView2EnvironmentOptions.pas @@ -13,13 +13,15 @@ interface uWVTypeLibrary, uWVTypes; type - TCoreWebView2EnvironmentOptions = class(TInterfacedObject, ICoreWebView2EnvironmentOptions) + TCoreWebView2EnvironmentOptions = class(TInterfacedObject, ICoreWebView2EnvironmentOptions, ICoreWebView2EnvironmentOptions2) protected FAdditionalBrowserArguments : wvstring; FLanguage : wvstring; FTargetCompatibleBrowserVersion : wvstring; FAllowSingleSignOnUsingOSPrimaryAccount : boolean; + FExclusiveUserDataFolderAccess : boolean; + // ICoreWebView2EnvironmentOptions function Get_AdditionalBrowserArguments(out value: PWideChar): HResult; stdcall; function Set_AdditionalBrowserArguments(value: PWideChar): HResult; stdcall; function Get_Language(out value: PWideChar): HResult; stdcall; @@ -29,8 +31,12 @@ TCoreWebView2EnvironmentOptions = class(TInterfacedObject, ICoreWebView2Enviro function Get_AllowSingleSignOnUsingOSPrimaryAccount(out allow: Integer): HResult; stdcall; function Set_AllowSingleSignOnUsingOSPrimaryAccount(allow: Integer): HResult; stdcall; + // ICoreWebView2EnvironmentOptions2 + function Get_ExclusiveUserDataFolderAccess(out value: Integer): HResult; stdcall; + function Set_ExclusiveUserDataFolderAccess(value: Integer): HResult; stdcall; + public - constructor Create(const aAdditionalBrowserArguments, aLanguage, aTargetCompatibleBrowserVersion : wvstring; aAllowSingleSignOnUsingOSPrimaryAccount : boolean); + constructor Create(const aAdditionalBrowserArguments, aLanguage, aTargetCompatibleBrowserVersion : wvstring; aAllowSingleSignOnUsingOSPrimaryAccount, aExclusiveUserDataFolderAccess : boolean); destructor Destroy; override; end; @@ -42,7 +48,8 @@ implementation constructor TCoreWebView2EnvironmentOptions.Create(const aAdditionalBrowserArguments : wvstring; const aLanguage : wvstring; const aTargetCompatibleBrowserVersion : wvstring; - aAllowSingleSignOnUsingOSPrimaryAccount : boolean); + aAllowSingleSignOnUsingOSPrimaryAccount : boolean; + aExclusiveUserDataFolderAccess : boolean); begin inherited Create; @@ -50,6 +57,7 @@ constructor TCoreWebView2EnvironmentOptions.Create(const aAdditionalBrowserArgum FLanguage := aLanguage; FTargetCompatibleBrowserVersion := aTargetCompatibleBrowserVersion; FAllowSingleSignOnUsingOSPrimaryAccount := aAllowSingleSignOnUsingOSPrimaryAccount; + FExclusiveUserDataFolderAccess := aExclusiveUserDataFolderAccess; end; destructor TCoreWebView2EnvironmentOptions.Destroy; @@ -126,4 +134,16 @@ function TCoreWebView2EnvironmentOptions.Set_AllowSingleSignOnUsingOSPrimaryAcco FAllowSingleSignOnUsingOSPrimaryAccount := (allow <> 0); end; +function TCoreWebView2EnvironmentOptions.Get_ExclusiveUserDataFolderAccess(out value: Integer): HResult; stdcall; +begin + Result := S_OK; + value := ord(FExclusiveUserDataFolderAccess); +end; + +function TCoreWebView2EnvironmentOptions.Set_ExclusiveUserDataFolderAccess(value: Integer): HResult; stdcall; +begin + Result := S_OK; + FExclusiveUserDataFolderAccess := (value <> 0); +end; + end. diff --git a/source/uWVCoreWebView2Frame.pas b/source/uWVCoreWebView2Frame.pas index e458c9d..f395d72 100644 --- a/source/uWVCoreWebView2Frame.pas +++ b/source/uWVCoreWebView2Frame.pas @@ -17,6 +17,7 @@ TCoreWebView2Frame = class protected FBaseIntf : ICoreWebView2Frame; FBaseIntf2 : ICoreWebView2Frame2; + FBaseIntf3 : ICoreWebView2Frame3; FNameChangedToken : EventRegistrationToken; FDestroyedToken : EventRegistrationToken; FFrameNavigationStartingToken : EventRegistrationToken; @@ -24,6 +25,7 @@ TCoreWebView2Frame = class FFrameContentLoadingToken : EventRegistrationToken; FFrameDOMContentLoadedToken : EventRegistrationToken; FFrameWebMessageReceivedToken : EventRegistrationToken; + FPermissionRequestedToken : EventRegistrationToken; FFrameID : integer; function GetInitialized : boolean; @@ -41,6 +43,7 @@ TCoreWebView2Frame = class function AddFrameContentLoadingEvent(const aBrowserComponent : TComponent) : boolean; function AddFrameDOMContentLoadedEvent(const aBrowserComponent : TComponent) : boolean; function AddFrameWebMessageReceivedEvent(const aBrowserComponent : TComponent) : boolean; + function AddPermissionRequestedEvent(const aBrowserComponent : TComponent) : boolean; public constructor Create(const aBaseIntf : ICoreWebView2Frame; aFrameID : integer); reintroduce; @@ -73,8 +76,9 @@ constructor TCoreWebView2Frame.Create(const aBaseIntf: ICoreWebView2Frame; aFram FBaseIntf := aBaseIntf; FFrameID := aFrameID; - if Initialized then - FBaseIntf.QueryInterface(ICoreWebView2Frame2, FBaseIntf2); + if Initialized and + succeeded(FBaseIntf.QueryInterface(ICoreWebView2Frame2, FBaseIntf2)) then + FBaseIntf.QueryInterface(ICoreWebView2Frame3, FBaseIntf3); end; destructor TCoreWebView2Frame.Destroy; @@ -91,6 +95,7 @@ procedure TCoreWebView2Frame.InitializeFields; begin FBaseIntf := nil; FBaseIntf2 := nil; + FBaseIntf3 := nil; FFrameID := 0; InitializeTokens; @@ -105,6 +110,7 @@ procedure TCoreWebView2Frame.InitializeTokens; FFrameContentLoadingToken.value := 0; FFrameDOMContentLoadedToken.value := 0; FFrameWebMessageReceivedToken.value := 0; + FPermissionRequestedToken.value := 0; end; procedure TCoreWebView2Frame.RemoveAllEvents; @@ -135,14 +141,24 @@ procedure TCoreWebView2Frame.RemoveAllEvents; FBaseIntf2.remove_WebMessageReceived(FFrameWebMessageReceivedToken); end; + if assigned(FBaseIntf3) and + (FPermissionRequestedToken.value <> 0) then + FBaseIntf3.remove_PermissionRequested(FPermissionRequestedToken); + InitializeTokens; end; end; function TCoreWebView2Frame.AddAllBrowserEvents(const aBrowserComponent : TComponent) : boolean; begin - Result := AddFrameNameChangedEvent(aBrowserComponent) and - AddFrameDestroyedEvent(aBrowserComponent); + Result := AddFrameNameChangedEvent(aBrowserComponent) and + AddFrameDestroyedEvent(aBrowserComponent) and + AddFrameNavigationStartingEvent(aBrowserComponent) and + AddFrameNavigationCompletedEvent(aBrowserComponent) and + AddFrameContentLoadingEvent(aBrowserComponent) and + AddFrameDOMContentLoadedEvent(aBrowserComponent) and + AddFrameWebMessageReceivedEvent(aBrowserComponent) and + AddPermissionRequestedEvent(aBrowserComponent); end; function TCoreWebView2Frame.AddFrameNameChangedEvent(const aBrowserComponent : TComponent) : boolean; @@ -250,6 +266,21 @@ function TCoreWebView2Frame.AddFrameWebMessageReceivedEvent(const aBrowserCompon end; end; +function TCoreWebView2Frame.AddPermissionRequestedEvent(const aBrowserComponent : TComponent) : boolean; +var + TempHandler : ICoreWebView2FramePermissionRequestedEventHandler; +begin + Result := False; + + if assigned(FBaseIntf3) and (FPermissionRequestedToken.value = 0) then + try + TempHandler := TCoreWebView2FramePermissionRequestedEventHandler.Create(TWVBrowserBase(aBrowserComponent), FFrameID); + Result := succeeded(FBaseIntf3.add_PermissionRequested(TempHandler, FPermissionRequestedToken)); + finally + TempHandler := nil; + end; +end; + function TCoreWebView2Frame.GetInitialized : boolean; begin Result := assigned(FBaseIntf); diff --git a/source/uWVCoreWebView2Settings.pas b/source/uWVCoreWebView2Settings.pas index b504956..b08324f 100644 --- a/source/uWVCoreWebView2Settings.pas +++ b/source/uWVCoreWebView2Settings.pas @@ -16,6 +16,7 @@ TCoreWebView2Settings = class FBaseIntf4 : ICoreWebView2Settings4; FBaseIntf5 : ICoreWebView2Settings5; FBaseIntf6 : ICoreWebView2Settings6; + FBaseIntf7 : ICoreWebView2Settings7; function GetInitialized : boolean; function GetIsBuiltInErrorPageEnabled : boolean; @@ -33,6 +34,7 @@ TCoreWebView2Settings = class function GetIsGeneralAutofillEnabled : boolean; function GetIsPinchZoomEnabled : boolean; function GetIsSwipeNavigationEnabled : boolean; + function GetHiddenPdfToolbarItems : TWVPDFToolbarItems; procedure SetIsBuiltInErrorPageEnabled(aValue : boolean); procedure SetAreDefaultContextMenusEnabled(aValue : boolean); @@ -49,6 +51,7 @@ TCoreWebView2Settings = class procedure SetIsGeneralAutofillEnabled(aValue : boolean); procedure SetIsPinchZoomEnabled(aValue : boolean); procedure SetIsSwipeNavigationEnabled(aValue : boolean); + procedure SetHiddenPdfToolbarItems(aValue : TWVPDFToolbarItems); procedure InitializeFields; @@ -73,6 +76,7 @@ TCoreWebView2Settings = class property IsGeneralAutofillEnabled : boolean read GetIsGeneralAutofillEnabled write SetIsGeneralAutofillEnabled; property IsPinchZoomEnabled : boolean read GetIsPinchZoomEnabled write SetIsPinchZoomEnabled; property IsSwipeNavigationEnabled : boolean read GetIsSwipeNavigationEnabled write SetIsSwipeNavigationEnabled; + property HiddenPdfToolbarItems : TWVPDFToolbarItems read GetHiddenPdfToolbarItems write SetHiddenPdfToolbarItems; end; implementation @@ -97,8 +101,9 @@ constructor TCoreWebView2Settings.Create(const aBaseIntf : ICoreWebView2Settings succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Settings2, FBaseIntf2)) and succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Settings3, FBaseIntf3)) and succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Settings4, FBaseIntf4)) and - succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Settings5, FBaseIntf5)) then - FBaseIntf.QueryInterface(IID_ICoreWebView2Settings6, FBaseIntf6); + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Settings5, FBaseIntf5)) and + succeeded(FBaseIntf.QueryInterface(IID_ICoreWebView2Settings6, FBaseIntf6)) then + FBaseIntf.QueryInterface(IID_ICoreWebView2Settings7, FBaseIntf7); end; destructor TCoreWebView2Settings.Destroy; @@ -116,6 +121,7 @@ procedure TCoreWebView2Settings.InitializeFields; FBaseIntf4 := nil; FBaseIntf5 := nil; FBaseIntf6 := nil; + FBaseIntf7 := nil; end; function TCoreWebView2Settings.GetInitialized : boolean; @@ -266,6 +272,17 @@ function TCoreWebView2Settings.GetIsSwipeNavigationEnabled : boolean; (TempResult <> 0); end; +function TCoreWebView2Settings.GetHiddenPdfToolbarItems : TWVPDFToolbarItems; +var + TempResult : COREWEBVIEW2_PDF_TOOLBAR_ITEMS; +begin + if assigned(FBaseIntf7) and + succeeded(FBaseIntf7.Get_HiddenPdfToolbarItems(TempResult)) then + Result := TempResult + else + Result := 0; +end; + procedure TCoreWebView2Settings.SetIsBuiltInErrorPageEnabled(aValue : boolean); begin if Initialized then @@ -356,4 +373,10 @@ procedure TCoreWebView2Settings.SetIsSwipeNavigationEnabled(aValue : boolean); FBaseIntf6.Set_IsSwipeNavigationEnabled(ord(aValue)); end; +procedure TCoreWebView2Settings.SetHiddenPdfToolbarItems(aValue : TWVPDFToolbarItems); +begin + if assigned(FBaseIntf7) then + FBaseIntf7.Set_HiddenPdfToolbarItems(aValue); +end; + end. diff --git a/source/uWVEvents.pas b/source/uWVEvents.pas index 5adc87a..adc8ced 100644 --- a/source/uWVEvents.pas +++ b/source/uWVEvents.pas @@ -73,6 +73,10 @@ interface TOnFrameDOMContentLoadedEvent = procedure(Sender: TObject; const aFrame: ICoreWebView2Frame; const aArgs: ICoreWebView2DOMContentLoadedEventArgs; aFrameID: integer) of object; TOnFrameWebMessageReceivedEvent = procedure(Sender: TObject; const aFrame: ICoreWebView2Frame; const aArgs: ICoreWebView2WebMessageReceivedEventArgs; aFrameID: integer) of object; TOnBasicAuthenticationRequestedEvent = procedure(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2BasicAuthenticationRequestedEventArgs) of object; + TOnContextMenuRequestedEvent = procedure(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2ContextMenuRequestedEventArgs) of object; + TOnCustomItemSelectedEvent = procedure(Sender: TObject; const aMenuItem: ICoreWebView2ContextMenuItem) of object; + TOnStatusBarTextChangedEvent = procedure(Sender: TObject; const aWebView: ICoreWebView2) of object; + TOnFramePermissionRequestedEvent = procedure(Sender: TObject; const aFrame: ICoreWebView2Frame; const aArgs: ICoreWebView2PermissionRequestedEventArgs2; aFrameID: integer) of object; // Custom events TOnCompMsgEvent = procedure(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean) of object; diff --git a/source/uWVFMXBrowser.pas b/source/uWVFMXBrowser.pas index e4d0c3b..43b218d 100644 --- a/source/uWVFMXBrowser.pas +++ b/source/uWVFMXBrowser.pas @@ -106,6 +106,10 @@ TWVFMXBrowser = class(TWVBrowserBase) property OnFrameDOMContentLoaded; property OnFrameWebMessageReceived; property OnBasicAuthenticationRequested; + property OnContextMenuRequested; + property OnCustomItemSelected; + property OnStatusBarTextChanged; + property OnFramePermissionRequested; end; implementation diff --git a/source/uWVInterfaces.pas b/source/uWVInterfaces.pas index b954ee3..d276854 100644 --- a/source/uWVInterfaces.pas +++ b/source/uWVInterfaces.pas @@ -199,6 +199,18 @@ interface // ICoreWebView2BasicAuthenticationRequestedEventHandler function BasicAuthenticationRequestedEventHandler_Invoke(const sender: ICoreWebView2; const args: ICoreWebView2BasicAuthenticationRequestedEventArgs): HResult; + + // ICoreWebView2ContextMenuRequestedEventHandler + function ContextMenuRequestedEventHandler_Invoke(const sender: ICoreWebView2; const args: ICoreWebView2ContextMenuRequestedEventArgs): HResult; + + // ICoreWebView2CustomItemSelectedEventHandler + function CustomItemSelectedEventHandler_Invoke(const sender: ICoreWebView2ContextMenuItem; const args: IUnknown): HResult; + + // ICoreWebView2StatusBarTextChangedEventHandler + function StatusBarTextChangedEventHandler_Invoke(const sender: ICoreWebView2; const args: IUnknown): HResult; + + // ICoreWebView2FramePermissionRequestedEventHandler + function FramePermissionRequestedEventHandler_Invoke(const sender: ICoreWebView2Frame; const args: ICoreWebView2PermissionRequestedEventArgs2; aFrameID: integer): HResult; end; implementation diff --git a/source/uWVLoader.pas b/source/uWVLoader.pas index 185d0a7..5beed51 100644 --- a/source/uWVLoader.pas +++ b/source/uWVLoader.pas @@ -44,6 +44,7 @@ TWVLoader = class(TComponent, IWVLoaderEvents) FLanguage : wvstring; FTargetCompatibleBrowserVersion : wvstring; FAllowSingleSignOnUsingOSPrimaryAccount : boolean; + FExclusiveUserDataFolderAccess : boolean; // Fields used to set command line switches FEnableGPU : boolean; @@ -146,6 +147,7 @@ TWVLoader = class(TComponent, IWVLoaderEvents) property Language : wvstring read FLanguage write FLanguage; // ICoreWebView2EnvironmentOptions.get_Language property TargetCompatibleBrowserVersion : wvstring read FTargetCompatibleBrowserVersion write FTargetCompatibleBrowserVersion; // ICoreWebView2EnvironmentOptions.get_TargetCompatibleBrowserVersion property AllowSingleSignOnUsingOSPrimaryAccount : boolean read FAllowSingleSignOnUsingOSPrimaryAccount write FAllowSingleSignOnUsingOSPrimaryAccount; // ICoreWebView2EnvironmentOptions.get_AllowSingleSignOnUsingOSPrimaryAccount + property ExclusiveUserDataFolderAccess : boolean read FExclusiveUserDataFolderAccess write FExclusiveUserDataFolderAccess; // ICoreWebView2EnvironmentOptions2.Get_ExclusiveUserDataFolderAccess // Properties used to set command line switches property EnableGPU : boolean read FEnableGPU write FEnableGPU; // --enable-gpu-plugin @@ -261,6 +263,7 @@ constructor TWVLoader.Create(AOwner: TComponent); FLanguage := ''; FTargetCompatibleBrowserVersion := LowestChromiumVersion; FAllowSingleSignOnUsingOSPrimaryAccount := False; + FExclusiveUserDataFolderAccess := False; // Fields used to set command line switches FEnableGPU := True; @@ -1031,7 +1034,8 @@ function TWVLoader.CreateEnvironment : boolean; TempOptions := TCoreWebView2EnvironmentOptions.Create(CustomCommandLineSwitches, FLanguage, FTargetCompatibleBrowserVersion, - FAllowSingleSignOnUsingOSPrimaryAccount); + FAllowSingleSignOnUsingOSPrimaryAccount, + FExclusiveUserDataFolderAccess); TempHResult := CreateCoreWebView2EnvironmentWithOptions(PWideChar(FBrowserExecPath), PWideChar(FUserDataFolder), diff --git a/source/uWVTypeLibrary.pas b/source/uWVTypeLibrary.pas index 928e502..f5934f7 100644 --- a/source/uWVTypeLibrary.pas +++ b/source/uWVTypeLibrary.pas @@ -28,10 +28,10 @@ // ************************************************************************ // // $Rev: 98336 $ -// File generated on 11/03/2022 15:10:52 from Type Library described below. +// File generated on 13/04/2022 10:14:53 from Type Library described below. // ************************************************************************ // -// Type Lib: Z:\microsoft.web.webview2.1.0.1150.38.nupkg_FILES\WebView2.tlb (1) +// Type Lib: T:\microsoft.web.webview2.1.0.1185.39.nupkg_FILES\WebView2.tlb (1) // LIBID: {26D34152-879F-4065-BEA2-3DAA2CFADFB8} // LCID: 0 // Helpfile: @@ -43,6 +43,8 @@ // Hint: Parameter 'object' of ICoreWebView2.AddHostObjectToScript changed to 'object_' // Hint: Symbol 'type' renamed to 'type_' // Hint: Parameter 'object' of ICoreWebView2Frame.AddHostObjectToScriptWithOrigins changed to 'object_' +// Hint: Member 'Label' of 'ICoreWebView2ContextMenuItem' changed to 'Label_' +// Hint: Parameter 'Label' of ICoreWebView2Environment9.CreateContextMenuItem changed to 'Label_' // ************************************************************************ // {$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. {$WARN SYMBOL_PLATFORM OFF} @@ -169,6 +171,15 @@ interface IID_ICoreWebView2BasicAuthenticationRequestedEventHandler: TGUID = '{58B4D6C2-18D4-497E-B39B-9A96533FA278}'; IID_ICoreWebView2BasicAuthenticationRequestedEventArgs: TGUID = '{EF05516F-D897-4F9E-B672-D8E2307A3FB0}'; IID_ICoreWebView2BasicAuthenticationResponse: TGUID = '{07023F7D-2D77-4D67-9040-6E7D428C6A40}'; + IID_ICoreWebView2_11: TGUID = '{0BE78E56-C193-4051-B943-23B460C08BDB}'; + IID_ICoreWebView2ContextMenuRequestedEventHandler: TGUID = '{04D3FE1D-AB87-42FB-A898-DA241D35B63C}'; + IID_ICoreWebView2ContextMenuRequestedEventArgs: TGUID = '{A1D309EE-C03F-11EB-8529-0242AC130003}'; + IID_ICoreWebView2ContextMenuItemCollection: TGUID = '{F562A2F5-C415-45CF-B909-D4B7C1E276D3}'; + IID_ICoreWebView2ContextMenuItem: TGUID = '{7AED49E3-A93F-497A-811C-749C6B6B6C65}'; + IID_ICoreWebView2CustomItemSelectedEventHandler: TGUID = '{49E1D0BC-FE9E-4481-B7C2-32324AA21998}'; + IID_ICoreWebView2ContextMenuTarget: TGUID = '{B8611D99-EED6-4F3F-902C-A198502AD472}'; + IID_ICoreWebView2_12: TGUID = '{35D69927-BCFA-4566-9349-6B3E0D154CAC}'; + IID_ICoreWebView2StatusBarTextChangedEventHandler: TGUID = '{A5E3B0D0-10DF-4156-BFAD-3B43867ACAC6}'; IID_ICoreWebView2BrowserProcessExitedEventArgs: TGUID = '{1F00663F-AF8C-4782-9CDD-DD01C52E34CB}'; IID_ICoreWebView2BrowserProcessExitedEventHandler: TGUID = '{FA504257-A216-4911-A860-FE8825712861}'; IID_ICoreWebView2CompositionController: TGUID = '{3DF9B733-B9AE-4A15-86B4-EB9EE9826469}'; @@ -178,8 +189,10 @@ interface IID_ICoreWebView2Controller2: TGUID = '{C979903E-D4CA-4228-92EB-47EE3FA96EAB}'; IID_ICoreWebView2Controller3: TGUID = '{F9614724-5D2B-41DC-AEF7-73D62B51543B}'; IID_ICoreWebView2RasterizationScaleChangedEventHandler: TGUID = '{9C98C8B1-AC53-427E-A345-3049B5524BBE}'; + IID_ICoreWebView2Controller4: TGUID = '{97D418D5-A426-4E49-A151-E1A10F327D9E}'; IID_ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler: TGUID = '{02FAB84B-1428-4FB7-AD45-1B2E64736184}'; IID_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler: TGUID = '{4E8A3389-C9D8-4BD2-B6B5-124FEE6CC14D}'; + IID_ICoreWebView2DevToolsProtocolEventReceivedEventArgs2: TGUID = '{2DC4959D-1494-4393-95BA-BEA4CB9EBD1B}'; IID_ICoreWebView2Environment2: TGUID = '{41F3632B-5EF4-404F-AD82-2D606C5A9A21}'; IID_ICoreWebView2Environment3: TGUID = '{80A22AE3-BE7C-4CE2-AFE1-5A50056CDEEB}'; IID_ICoreWebView2Environment4: TGUID = '{20944379-6DCF-41D6-A0A0-ABC0FC50DE0D}'; @@ -190,13 +203,18 @@ interface IID_ICoreWebView2ProcessInfosChangedEventHandler: TGUID = '{F4AF0C39-44B9-40E9-8B11-0484CFB9E0A1}'; IID_ICoreWebView2ProcessInfoCollection: TGUID = '{402B99CD-A0CC-4FA5-B7A5-51D86A1D2339}'; IID_ICoreWebView2ProcessInfo: TGUID = '{84FA7612-3F3D-4FBF-889D-FAD000492D72}'; + IID_ICoreWebView2Environment9: TGUID = '{F06F41BF-4B5A-49D8-B9F6-FA16CD29F274}'; IID_ICoreWebView2EnvironmentOptions: TGUID = '{2FDE08A8-1E9A-4766-8C05-95A9CEB9D1C5}'; + IID_ICoreWebView2EnvironmentOptions2: TGUID = '{FF85C98A-1BA7-4A6B-90C8-2B752C89E9E2}'; IID_ICoreWebView2Frame2: TGUID = '{7A6A5834-D185-4DBF-B63F-4A9BC43107D4}'; IID_ICoreWebView2FrameNavigationStartingEventHandler: TGUID = '{E79908BF-2D5D-4968-83DB-263FEA2C1DA3}'; IID_ICoreWebView2FrameContentLoadingEventHandler: TGUID = '{0D6156F2-D332-49A7-9E03-7D8F2FEEEE54}'; IID_ICoreWebView2FrameNavigationCompletedEventHandler: TGUID = '{609302AD-0E36-4F9A-A210-6A45272842A9}'; IID_ICoreWebView2FrameDOMContentLoadedEventHandler: TGUID = '{38D9520D-340F-4D1E-A775-43FCE9753683}'; IID_ICoreWebView2FrameWebMessageReceivedEventHandler: TGUID = '{E371E005-6D1D-4517-934B-A8F1629C62A5}'; + IID_ICoreWebView2Frame3: TGUID = '{B50D82CC-CC28-481D-9614-CB048895E6A0}'; + IID_ICoreWebView2FramePermissionRequestedEventHandler: TGUID = '{845D0EDD-8BD8-429B-9915-4821789F23E9}'; + IID_ICoreWebView2PermissionRequestedEventArgs2: TGUID = '{74D7127F-9DE6-4200-8734-42D6FB4FF741}'; IID_ICoreWebView2FrameInfo: TGUID = '{DA86B8A1-BDF3-4F11-9955-528CEFA59727}'; IID_ICoreWebView2FrameInfoCollection: TGUID = '{8F834154-D38E-4D90-AFFB-6800A7272839}'; IID_ICoreWebView2FrameInfoCollectionIterator: TGUID = '{1BF89E2D-1B2B-4629-B28F-05099B41BB03}'; @@ -208,6 +226,7 @@ interface IID_ICoreWebView2Settings4: TGUID = '{CB56846C-4168-4D53-B04F-03B6D6796FF2}'; IID_ICoreWebView2Settings5: TGUID = '{183E7052-1D03-43A0-AB99-98E043B66B39}'; IID_ICoreWebView2Settings6: TGUID = '{11CB3ACD-9BC8-43B8-83BF-F40753714F87}'; + IID_ICoreWebView2Settings7: TGUID = '{488DC902-35EF-42D2-BC7D-94B65C4BC49C}'; // *********************************************************************// // Declaration of Enumerations defined in Type Library @@ -409,6 +428,26 @@ interface COREWEBVIEW2_DEFAULT_DOWNLOAD_DIALOG_CORNER_ALIGNMENT_BOTTOM_LEFT = $00000002; COREWEBVIEW2_DEFAULT_DOWNLOAD_DIALOG_CORNER_ALIGNMENT_BOTTOM_RIGHT = $00000003; +// Constants for enum COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND +type + COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND = TOleEnum; +const + COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_COMMAND = $00000000; + COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_CHECK_BOX = $00000001; + COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_RADIO = $00000002; + COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_SEPARATOR = $00000003; + COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_SUBMENU = $00000004; + +// Constants for enum COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND +type + COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND = TOleEnum; +const + COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND_PAGE = $00000000; + COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND_IMAGE = $00000001; + COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND_SELECTED_TEXT = $00000002; + COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND_AUDIO = $00000003; + COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND_VIDEO = $00000004; + // Constants for enum COREWEBVIEW2_BROWSER_PROCESS_EXIT_KIND type COREWEBVIEW2_BROWSER_PROCESS_EXIT_KIND = TOleEnum; @@ -491,6 +530,15 @@ interface COREWEBVIEW2_PROCESS_FAILED_REASON_LAUNCH_FAILED = $00000004; COREWEBVIEW2_PROCESS_FAILED_REASON_OUT_OF_MEMORY = $00000005; +// Constants for enum COREWEBVIEW2_PDF_TOOLBAR_ITEMS +type + COREWEBVIEW2_PDF_TOOLBAR_ITEMS = TOleEnum; +const + COREWEBVIEW2_PDF_TOOLBAR_ITEMS_NONE = $00000000; + COREWEBVIEW2_PDF_TOOLBAR_ITEMS_SAVE = $00000001; + COREWEBVIEW2_PDF_TOOLBAR_ITEMS_PRINT = $00000002; + COREWEBVIEW2_PDF_TOOLBAR_ITEMS_SAVE_AS = $00000004; + type // *********************************************************************// @@ -590,6 +638,15 @@ interface ICoreWebView2BasicAuthenticationRequestedEventHandler = interface; ICoreWebView2BasicAuthenticationRequestedEventArgs = interface; ICoreWebView2BasicAuthenticationResponse = interface; + ICoreWebView2_11 = interface; + ICoreWebView2ContextMenuRequestedEventHandler = interface; + ICoreWebView2ContextMenuRequestedEventArgs = interface; + ICoreWebView2ContextMenuItemCollection = interface; + ICoreWebView2ContextMenuItem = interface; + ICoreWebView2CustomItemSelectedEventHandler = interface; + ICoreWebView2ContextMenuTarget = interface; + ICoreWebView2_12 = interface; + ICoreWebView2StatusBarTextChangedEventHandler = interface; ICoreWebView2BrowserProcessExitedEventArgs = interface; ICoreWebView2BrowserProcessExitedEventHandler = interface; ICoreWebView2CompositionController = interface; @@ -599,8 +656,10 @@ interface ICoreWebView2Controller2 = interface; ICoreWebView2Controller3 = interface; ICoreWebView2RasterizationScaleChangedEventHandler = interface; + ICoreWebView2Controller4 = interface; ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler = interface; ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = interface; + ICoreWebView2DevToolsProtocolEventReceivedEventArgs2 = interface; ICoreWebView2Environment2 = interface; ICoreWebView2Environment3 = interface; ICoreWebView2Environment4 = interface; @@ -611,13 +670,18 @@ interface ICoreWebView2ProcessInfosChangedEventHandler = interface; ICoreWebView2ProcessInfoCollection = interface; ICoreWebView2ProcessInfo = interface; + ICoreWebView2Environment9 = interface; ICoreWebView2EnvironmentOptions = interface; + ICoreWebView2EnvironmentOptions2 = interface; ICoreWebView2Frame2 = interface; ICoreWebView2FrameNavigationStartingEventHandler = interface; ICoreWebView2FrameContentLoadingEventHandler = interface; ICoreWebView2FrameNavigationCompletedEventHandler = interface; ICoreWebView2FrameDOMContentLoadedEventHandler = interface; ICoreWebView2FrameWebMessageReceivedEventHandler = interface; + ICoreWebView2Frame3 = interface; + ICoreWebView2FramePermissionRequestedEventHandler = interface; + ICoreWebView2PermissionRequestedEventArgs2 = interface; ICoreWebView2FrameInfo = interface; ICoreWebView2FrameInfoCollection = interface; ICoreWebView2FrameInfoCollectionIterator = interface; @@ -629,6 +693,7 @@ interface ICoreWebView2Settings4 = interface; ICoreWebView2Settings5 = interface; ICoreWebView2Settings6 = interface; + ICoreWebView2Settings7 = interface; // *********************************************************************// // Declaration of structures, unions and aliases. @@ -2051,6 +2116,140 @@ COREWEBVIEW2_COLOR = record function Set_Password(Password: PWideChar): HResult; stdcall; end; +// *********************************************************************// +// Interface: ICoreWebView2_11 +// Flags: (0) +// GUID: {0BE78E56-C193-4051-B943-23B460C08BDB} +// *********************************************************************// + ICoreWebView2_11 = interface(ICoreWebView2_10) + ['{0BE78E56-C193-4051-B943-23B460C08BDB}'] + function CallDevToolsProtocolMethodForSession(sessionId: PWideChar; methodName: PWideChar; + parametersAsJson: PWideChar; + const handler: ICoreWebView2CallDevToolsProtocolMethodCompletedHandler): HResult; stdcall; + function add_ContextMenuRequested(const eventHandler: ICoreWebView2ContextMenuRequestedEventHandler; + out token: EventRegistrationToken): HResult; stdcall; + function remove_ContextMenuRequested(token: EventRegistrationToken): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2ContextMenuRequestedEventHandler +// Flags: (0) +// GUID: {04D3FE1D-AB87-42FB-A898-DA241D35B63C} +// *********************************************************************// + ICoreWebView2ContextMenuRequestedEventHandler = interface(IUnknown) + ['{04D3FE1D-AB87-42FB-A898-DA241D35B63C}'] + function Invoke(const sender: ICoreWebView2; + const args: ICoreWebView2ContextMenuRequestedEventArgs): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2ContextMenuRequestedEventArgs +// Flags: (0) +// GUID: {A1D309EE-C03F-11EB-8529-0242AC130003} +// *********************************************************************// + ICoreWebView2ContextMenuRequestedEventArgs = interface(IUnknown) + ['{A1D309EE-C03F-11EB-8529-0242AC130003}'] + function Get_MenuItems(out value: ICoreWebView2ContextMenuItemCollection): HResult; stdcall; + function Get_ContextMenuTarget(out value: ICoreWebView2ContextMenuTarget): HResult; stdcall; + function Get_Location(out value: tagPOINT): HResult; stdcall; + function Set_SelectedCommandId(value: SYSINT): HResult; stdcall; + function Get_SelectedCommandId(out value: SYSINT): HResult; stdcall; + function Set_Handled(value: Integer): HResult; stdcall; + function Get_Handled(out value: Integer): HResult; stdcall; + function GetDeferral(out deferral: ICoreWebView2Deferral): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2ContextMenuItemCollection +// Flags: (0) +// GUID: {F562A2F5-C415-45CF-B909-D4B7C1E276D3} +// *********************************************************************// + ICoreWebView2ContextMenuItemCollection = interface(IUnknown) + ['{F562A2F5-C415-45CF-B909-D4B7C1E276D3}'] + function Get_Count(out value: SYSUINT): HResult; stdcall; + function GetValueAtIndex(index: SYSUINT; out value: ICoreWebView2ContextMenuItem): HResult; stdcall; + function RemoveValueAtIndex(index: SYSUINT): HResult; stdcall; + function InsertValueAtIndex(index: SYSUINT; const value: ICoreWebView2ContextMenuItem): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2ContextMenuItem +// Flags: (0) +// GUID: {7AED49E3-A93F-497A-811C-749C6B6B6C65} +// *********************************************************************// + ICoreWebView2ContextMenuItem = interface(IUnknown) + ['{7AED49E3-A93F-497A-811C-749C6B6B6C65}'] + function Get_name(out value: PWideChar): HResult; stdcall; + function Get_Label_(out value: PWideChar): HResult; stdcall; + function Get_CommandId(out value: SYSINT): HResult; stdcall; + function Get_ShortcutKeyDescription(out value: PWideChar): HResult; stdcall; + function Get_Icon(out value: IStream): HResult; stdcall; + function Get_Kind(out value: COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND): HResult; stdcall; + function Set_IsEnabled(value: Integer): HResult; stdcall; + function Get_IsEnabled(out value: Integer): HResult; stdcall; + function Set_IsChecked(value: Integer): HResult; stdcall; + function Get_IsChecked(out value: Integer): HResult; stdcall; + function Get_Children(out value: ICoreWebView2ContextMenuItemCollection): HResult; stdcall; + function add_CustomItemSelected(const eventHandler: ICoreWebView2CustomItemSelectedEventHandler; + out token: EventRegistrationToken): HResult; stdcall; + function remove_CustomItemSelected(token: EventRegistrationToken): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2CustomItemSelectedEventHandler +// Flags: (0) +// GUID: {49E1D0BC-FE9E-4481-B7C2-32324AA21998} +// *********************************************************************// + ICoreWebView2CustomItemSelectedEventHandler = interface(IUnknown) + ['{49E1D0BC-FE9E-4481-B7C2-32324AA21998}'] + function Invoke(const sender: ICoreWebView2ContextMenuItem; const args: IUnknown): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2ContextMenuTarget +// Flags: (0) +// GUID: {B8611D99-EED6-4F3F-902C-A198502AD472} +// *********************************************************************// + ICoreWebView2ContextMenuTarget = interface(IUnknown) + ['{B8611D99-EED6-4F3F-902C-A198502AD472}'] + function Get_Kind(out value: COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND): HResult; stdcall; + function Get_IsEditable(out value: Integer): HResult; stdcall; + function Get_IsRequestedForMainFrame(out value: Integer): HResult; stdcall; + function Get_PageUri(out value: PWideChar): HResult; stdcall; + function Get_FrameUri(out value: PWideChar): HResult; stdcall; + function Get_HasLinkUri(out value: Integer): HResult; stdcall; + function Get_LinkUri(out value: PWideChar): HResult; stdcall; + function Get_HasLinkText(out value: Integer): HResult; stdcall; + function Get_LinkText(out value: PWideChar): HResult; stdcall; + function Get_HasSourceUri(out value: Integer): HResult; stdcall; + function Get_SourceUri(out value: PWideChar): HResult; stdcall; + function Get_HasSelection(out value: Integer): HResult; stdcall; + function Get_SelectionText(out value: PWideChar): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2_12 +// Flags: (0) +// GUID: {35D69927-BCFA-4566-9349-6B3E0D154CAC} +// *********************************************************************// + ICoreWebView2_12 = interface(ICoreWebView2_11) + ['{35D69927-BCFA-4566-9349-6B3E0D154CAC}'] + function add_StatusBarTextChanged(const eventHandler: ICoreWebView2StatusBarTextChangedEventHandler; + out token: EventRegistrationToken): HResult; stdcall; + function remove_StatusBarTextChanged(token: EventRegistrationToken): HResult; stdcall; + function Get_StatusBarText(out value: PWideChar): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2StatusBarTextChangedEventHandler +// Flags: (0) +// GUID: {A5E3B0D0-10DF-4156-BFAD-3B43867ACAC6} +// *********************************************************************// + ICoreWebView2StatusBarTextChangedEventHandler = interface(IUnknown) + ['{A5E3B0D0-10DF-4156-BFAD-3B43867ACAC6}'] + function Invoke(const sender: ICoreWebView2; const args: IUnknown): HResult; stdcall; + end; + // *********************************************************************// // Interface: ICoreWebView2BrowserProcessExitedEventArgs // Flags: (0) @@ -2177,7 +2376,7 @@ COREWEBVIEW2_COLOR = record // *********************************************************************// ICoreWebView2CompositionController2 = interface(ICoreWebView2CompositionController) ['{0B6A3D24-49CB-4806-BA20-B5E0734A7B26}'] - function Get_UIAProvider(out provider: IUnknown): HResult; stdcall; + function Get_AutomationProvider(out provider: IUnknown): HResult; stdcall; end; // *********************************************************************// @@ -2219,6 +2418,17 @@ COREWEBVIEW2_COLOR = record function Invoke(const sender: ICoreWebView2Controller; const args: IUnknown): HResult; stdcall; end; +// *********************************************************************// +// Interface: ICoreWebView2Controller4 +// Flags: (0) +// GUID: {97D418D5-A426-4E49-A151-E1A10F327D9E} +// *********************************************************************// + ICoreWebView2Controller4 = interface(ICoreWebView2Controller3) + ['{97D418D5-A426-4E49-A151-E1A10F327D9E}'] + function Get_AllowExternalDrop(out value: Integer): HResult; stdcall; + function Set_AllowExternalDrop(value: Integer): HResult; stdcall; + end; + // *********************************************************************// // Interface: ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler // Flags: (0) @@ -2239,6 +2449,16 @@ COREWEBVIEW2_COLOR = record function Invoke(errorCode: HResult; const createdEnvironment: ICoreWebView2Environment): HResult; stdcall; end; +// *********************************************************************// +// Interface: ICoreWebView2DevToolsProtocolEventReceivedEventArgs2 +// Flags: (0) +// GUID: {2DC4959D-1494-4393-95BA-BEA4CB9EBD1B} +// *********************************************************************// + ICoreWebView2DevToolsProtocolEventReceivedEventArgs2 = interface(ICoreWebView2DevToolsProtocolEventReceivedEventArgs) + ['{2DC4959D-1494-4393-95BA-BEA4CB9EBD1B}'] + function Get_sessionId(out sessionId: PWideChar): HResult; stdcall; + end; + // *********************************************************************// // Interface: ICoreWebView2Environment2 // Flags: (0) @@ -2271,8 +2491,8 @@ COREWEBVIEW2_COLOR = record // *********************************************************************// ICoreWebView2Environment4 = interface(ICoreWebView2Environment3) ['{20944379-6DCF-41D6-A0A0-ABC0FC50DE0D}'] - // function GetProviderForHwnd(var hwnd: _RemotableHandle; out provider: IUnknown): HResult; stdcall; var hwnd: _RemotableHandle -> aHWND: HWND ************** WEBVIEW4DELPHI ************** - function GetProviderForHwnd(aHWND: HWND; out provider: IUnknown): HResult; stdcall; + // function GetAutomationProviderForWindow(var hwnd: _RemotableHandle; out provider: IUnknown): HResult; stdcall; var hwnd: _RemotableHandle -> aHWND: HWND ************** WEBVIEW4DELPHI ************** + function GetAutomationProviderForWindow(aHWND: HWND; out provider: IUnknown): HResult; stdcall; end; // *********************************************************************// @@ -2352,6 +2572,18 @@ COREWEBVIEW2_COLOR = record function Get_Kind(out Kind: COREWEBVIEW2_PROCESS_KIND): HResult; stdcall; end; +// *********************************************************************// +// Interface: ICoreWebView2Environment9 +// Flags: (0) +// GUID: {F06F41BF-4B5A-49D8-B9F6-FA16CD29F274} +// *********************************************************************// + ICoreWebView2Environment9 = interface(ICoreWebView2Environment8) + ['{F06F41BF-4B5A-49D8-B9F6-FA16CD29F274}'] + function CreateContextMenuItem(Label_: PWideChar; const iconStream: IStream; + Kind: COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND; + out item: ICoreWebView2ContextMenuItem): HResult; stdcall; + end; + // *********************************************************************// // Interface: ICoreWebView2EnvironmentOptions // Flags: (0) @@ -2369,6 +2601,17 @@ COREWEBVIEW2_COLOR = record function Set_AllowSingleSignOnUsingOSPrimaryAccount(allow: Integer): HResult; stdcall; end; +// *********************************************************************// +// Interface: ICoreWebView2EnvironmentOptions2 +// Flags: (0) +// GUID: {FF85C98A-1BA7-4A6B-90C8-2B752C89E9E2} +// *********************************************************************// + ICoreWebView2EnvironmentOptions2 = interface(IUnknown) + ['{FF85C98A-1BA7-4A6B-90C8-2B752C89E9E2}'] + function Get_ExclusiveUserDataFolderAccess(out value: Integer): HResult; stdcall; + function Set_ExclusiveUserDataFolderAccess(value: Integer): HResult; stdcall; + end; + // *********************************************************************// // Interface: ICoreWebView2Frame2 // Flags: (0) @@ -2452,6 +2695,40 @@ COREWEBVIEW2_COLOR = record const args: ICoreWebView2WebMessageReceivedEventArgs): HResult; stdcall; end; +// *********************************************************************// +// Interface: ICoreWebView2Frame3 +// Flags: (0) +// GUID: {B50D82CC-CC28-481D-9614-CB048895E6A0} +// *********************************************************************// + ICoreWebView2Frame3 = interface(ICoreWebView2Frame2) + ['{B50D82CC-CC28-481D-9614-CB048895E6A0}'] + function add_PermissionRequested(const handler: ICoreWebView2FramePermissionRequestedEventHandler; + out token: EventRegistrationToken): HResult; stdcall; + function remove_PermissionRequested(token: EventRegistrationToken): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2FramePermissionRequestedEventHandler +// Flags: (0) +// GUID: {845D0EDD-8BD8-429B-9915-4821789F23E9} +// *********************************************************************// + ICoreWebView2FramePermissionRequestedEventHandler = interface(IUnknown) + ['{845D0EDD-8BD8-429B-9915-4821789F23E9}'] + function Invoke(const sender: ICoreWebView2Frame; + const args: ICoreWebView2PermissionRequestedEventArgs2): HResult; stdcall; + end; + +// *********************************************************************// +// Interface: ICoreWebView2PermissionRequestedEventArgs2 +// Flags: (0) +// GUID: {74D7127F-9DE6-4200-8734-42D6FB4FF741} +// *********************************************************************// + ICoreWebView2PermissionRequestedEventArgs2 = interface(ICoreWebView2PermissionRequestedEventArgs) + ['{74D7127F-9DE6-4200-8734-42D6FB4FF741}'] + function Get_Handled(out Handled: Integer): HResult; stdcall; + function Set_Handled(Handled: Integer): HResult; stdcall; + end; + // *********************************************************************// // Interface: ICoreWebView2FrameInfo // Flags: (0) @@ -2576,6 +2853,17 @@ COREWEBVIEW2_COLOR = record function Set_IsSwipeNavigationEnabled(enabled: Integer): HResult; stdcall; end; +// *********************************************************************// +// Interface: ICoreWebView2Settings7 +// Flags: (0) +// GUID: {488DC902-35EF-42D2-BC7D-94B65C4BC49C} +// *********************************************************************// + ICoreWebView2Settings7 = interface(ICoreWebView2Settings6) + ['{488DC902-35EF-42D2-BC7D-94B65C4BC49C}'] + function Get_HiddenPdfToolbarItems(out hidden_pdf_toolbar_items: COREWEBVIEW2_PDF_TOOLBAR_ITEMS): HResult; stdcall; + function Set_HiddenPdfToolbarItems(hidden_pdf_toolbar_items: COREWEBVIEW2_PDF_TOOLBAR_ITEMS): HResult; stdcall; + end; + implementation uses diff --git a/source/uWVTypes.pas b/source/uWVTypes.pas index 407e8cd..ff2cfd1 100644 --- a/source/uWVTypes.pas +++ b/source/uWVTypes.pas @@ -43,6 +43,9 @@ interface TWVColor = type COREWEBVIEW2_COLOR; TWVDefaultDownloadDialogCornerAlignment = type COREWEBVIEW2_DEFAULT_DOWNLOAD_DIALOG_CORNER_ALIGNMENT; TWVProcessKind = type COREWEBVIEW2_PROCESS_KIND; + TWVMenuItemKind = type COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND; + TWVMenuTargetKind = type COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND; + TWVPDFToolbarItems = type COREWEBVIEW2_PDF_TOOLBAR_ITEMS; TWV2LoaderStatus = (wvlsCreated, wvlsLoading, diff --git a/update_WebView4Delphi.json b/update_WebView4Delphi.json index 46a9b45..72d120f 100644 --- a/update_WebView4Delphi.json +++ b/update_WebView4Delphi.json @@ -2,9 +2,9 @@ "UpdateLazPackages" : [ { "ForceNotify" : true, - "InternalVersion" : 50, + "InternalVersion" : 51, "Name" : "webview4delphi.lpk", - "Version" : "1.0.1150.38" + "Version" : "1.0.1185.39" } ], "UpdatePackageData" : {