{ The contents of this file are subject to the Mozilla Public License  }
{ Version 1.1 (the "License"); you may not use this file except in     }
{ compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/                                          }
{                                                                      }
{ Software distributed under the License is distributed on an "AS IS"  }
{ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  }
{ the License for the specific language governing rights and           }
{ limitations under the License.                                       }
{                                                                      }
{ The Original Code is ShDocVwEvents.pas.                              }
{                                                                      }
{**********************************************************************}
{                                                                      }
{ This unit contains the event handler classes required for connecting }
{ to events generated by an IWebBrowser2 interface automatically. This }
{ code was initially created by Binh Ly's EventSinkImp utility, and    }
{ was cleaned up for use specifically as an IWebBrowser event handler  }
{ by Ashley Godfrey.                                                   }
{                                                                      }
{ Unit owner: Ashley Godfrey.                                          }
{ Last modified: April 23, 2004.                                       }
{ Updates available from http://www.evocorp.com                        }
{                                                                      }
{**********************************************************************}

unit ShDocVwEvents;
interface
uses
  Windows, ActiveX, Classes, ComObj, OleCtrls, StdVcl, ShDocVw;

type
  TStatusTextChangeEvent = procedure(Sender: TObject;
    const Text: WideString) of object;
  TProgressChangeEvent = procedure(Sender: TObject;
    Progress: Integer; ProgressMax: Integer) of object;
  TCommandStateChangeEvent = procedure(Sender: TObject;
    Command: Integer; Enable: WordBool) of object;
  TDownloadBeginEvent = procedure(Sender: TObject) of object;
  TDownloadCompleteEvent = procedure(Sender: TObject) of object;
  TTitleChangeEvent = procedure(Sender: TObject;
    const Text: WideString) of object;
  TPropertyChangeEvent = procedure(Sender: TObject;
    const szProperty: WideString) of object;
  TBeforeNavigate2Event = procedure(Sender: TObject; const pDisp: IDispatch;
    var URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
    var Cancel: WordBool) of object;
  TNewWindow2Event = procedure(Sender: TObject;
    var ppDisp: IDispatch; var Cancel: WordBool) of object;
  TNavigateComplete2Event = procedure(Sender: TObject;
    const pDisp: IDispatch; var URL: OleVariant) of object;
  TDocumentCompleteEvent = procedure(Sender: TObject;
    const pDisp: IDispatch; var URL: OleVariant) of object;
  TOnQuitEvent = procedure(Sender: TObject) of object;
  TOnVisibleEvent = procedure(Sender: TObject; Visible: WordBool) of object;
  TOnToolBarEvent = procedure(Sender: TObject; ToolBar: WordBool) of object;
  TOnMenuBarEvent = procedure(Sender: TObject; MenuBar: WordBool) of object;
  TOnStatusBarEvent = procedure(Sender: TObject;
    StatusBar: WordBool) of object;
  TOnFullScreenEvent = procedure(Sender: TObject;
    FullScreen: WordBool) of object;
  TOnTheaterModeEvent = procedure(Sender: TObject;
    TheaterMode: WordBool) of object;
  TWindowSetResizableEvent = procedure(Sender: TObject;
    Resizable: WordBool) of object;
  TWindowSetLeftEvent = procedure(Sender: TObject; Left: Integer) of object;
  TWindowSetTopEvent = procedure(Sender: TObject; Top: Integer) of object;
  TWindowSetWidthEvent = procedure(Sender: TObject; Width: Integer) of object;
  TWindowSetHeightEvent = procedure(Sender: TObject;
    Height: Integer) of object;
  TWindowClosingEvent = procedure(Sender: TObject; IsChildWindow: WordBool;
    var Cancel: WordBool) of object;
  TClientToHostWindowEvent = procedure(Sender: TObject;
    var CX, CY: Integer) of object;
  TSetSecureLockIconEvent = procedure(Sender: TObject;
    SecureLockIcon: Integer) of object;
  TFileDownloadEvent = procedure(Sender: TObject;
    var Cancel: WordBool) of object;
  TNavigateErrorEvent = procedure(Sender: TObject; const pDisp: IDispatch;
    var URL, Frame, StatusCode: OleVariant; var Cancel: WordBool) of object;
  TPrintTemplateInstantiationEvent = procedure(Sender: TObject;
    const pDisp: IDispatch) of object;
  TPrintTemplateTeardownEvent = procedure(Sender: TObject;
    const pDisp: IDispatch) of object;
  TUpdatePageStatusEvent = procedure(Sender: TObject; const pDisp: IDispatch;
    var nPage: OleVariant; var fDone: OleVariant) of object;
  TPrivacyImpactedStateChangeEvent = procedure(Sender: TObject;
    bImpacted: WordBool) of object;

  TWebBrowserEvents = class(TObject, IUnknown, IDispatch)
  private
    FCookie: integer;
    FCP: IConnectionPoint;
    FWebBrowser: IWebBrowser2;
    // Events
    FBeforeNavigate2: TBeforeNavigate2Event;
    FClientToHostWindow: TClientToHostWindowEvent;
    FCommandStateChange: TCommandStateChangeEvent;
    FDocumentComplete: TDocumentCompleteEvent;
    FDownloadBegin: TDownloadBeginEvent;
    FDownloadComplete: TDownloadCompleteEvent;
    FFileDownload: TFileDownloadEvent;
    FNavigateComplete2: TNavigateComplete2Event;
    FNavigateError: TNavigateErrorEvent;
    FNewWindow2: TNewWindow2Event;
    FOnFullScreen: TOnFullScreenEvent;
    FOnMenuBar: TOnMenuBarEvent;
    FOnQuit: TOnQuitEvent;
    FOnStatusBar: TOnStatusBarEvent;
    FOnTheaterMode: TOnTheaterModeEvent;
    FOnToolBar: TOnToolBarEvent;
    FOnVisible: TOnVisibleEvent;
    FPrintTemplateInstantiation: TPrintTemplateInstantiationEvent;
    FPrintTemplateTeardown: TPrintTemplateTeardownEvent;
    FPrivacyImpactedStateChange: TPrivacyImpactedStateChangeEvent;
    FProgressChange: TProgressChangeEvent;
    FPropertyChange: TPropertyChangeEvent;
    FSetSecureLockIcon: TSetSecureLockIconEvent;
    FStatusTextChange: TStatusTextChangeEvent;
    FTitleChange: TTitleChangeEvent;
    FUpdatePageStatus: TUpdatePageStatusEvent;
    FWindowClosing: TWindowClosingEvent;
    FWindowSetHeight: TWindowSetHeightEvent;
    FWindowSetLeft: TWindowSetLeftEvent;
    FWindowSetResizable: TWindowSetResizableEvent;
    FWindowSetTop: TWindowSetTopEvent;
    FWindowSetWidth: TWindowSetWidthEvent;
  protected
    // IUnknown
    function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
    // IDispatch
    function GetIDsOfNames(const IID: TGUID; Names: Pointer;
      NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; virtual; stdcall;
    function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; virtual; stdcall;
    function GetTypeInfoCount(out Count: Integer): HResult; virtual; stdcall;
    function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
      Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; virtual; stdcall;
    // TWebBrowserEvents Invoke Mechanics
    function DoInvoke (DispID: Integer; const IID: TGUID; LocaleID: Integer;
      Flags: Word; var dps: TDispParams; pDispIds: PDispIdList;
      VarResult, ExcepInfo, ArgErr: Pointer): HResult; virtual;
    // TWebBrowserEvents Events
    procedure DoBeforeNavigate2(const pDisp: IDispatch;
      var URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
      var Cancel: WordBool); safecall;
    procedure DoClientToHostWindow(var CX: Integer; var CY: Integer); safecall;
    procedure DoCommandStateChange(Command: Integer;
      Enable: WordBool); safecall;
    procedure DoDocumentComplete(const pDisp: IDispatch;
      var URL: OleVariant); safecall;
    procedure DoDownloadBegin; safecall;
    procedure DoDownloadComplete; safecall;
    procedure DoFileDownload(var Cancel: WordBool); safecall;
    procedure DoNavigateComplete2(const pDisp: IDispatch;
      var URL: OleVariant); safecall;
    procedure DoNavigateError(const pDisp: IDispatch;
      var URL, Frame, StatusCode: OleVariant; var Cancel: WordBool); safecall;
    procedure DoNewWindow2(var ppDisp: IDispatch;
      var Cancel: WordBool); safecall;
    procedure DoOnFullScreen(FullScreen: WordBool); safecall;
    procedure DoOnMenuBar(MenuBar: WordBool); safecall;
    procedure DoOnQuit; safecall;
    procedure DoOnStatusBar(StatusBar: WordBool); safecall;
    procedure DoOnTheaterMode(TheaterMode: WordBool); safecall;
    procedure DoOnToolBar(ToolBar: WordBool); safecall;
    procedure DoOnVisible(Visible: WordBool); safecall;
    procedure DoPrintTemplateInstantiation(const pDisp: IDispatch); safecall;
    procedure DoPrintTemplateTeardown(const pDisp: IDispatch); safecall;
    procedure DoPrivacyImpactedStateChange(bImpacted: WordBool); safecall;
    procedure DoProgressChange(Progress: Integer;
      ProgressMax: Integer); safecall;
    procedure DoPropertyChange(const szProperty: WideString); safecall;
    procedure DoSetSecureLockIcon(SecureLockIcon: Integer); safecall;
    procedure DoStatusTextChange(const Text: WideString); safecall;
    procedure DoTitleChange(const Text: WideString); safecall;
    procedure DoUpdatePageStatus(const pDisp: IDispatch;
      var nPage, fDone: OleVariant); safecall;
    procedure DoWindowClosing(IsChildWindow: WordBool;
      var Cancel: WordBool); safecall;
    procedure DoWindowSetHeight(Height: Integer); safecall;
    procedure DoWindowSetLeft(Left: Integer); safecall;
    procedure DoWindowSetResizable(Resizable: WordBool); safecall;
    procedure DoWindowSetTop(Top: Integer); safecall;
    procedure DoWindowSetWidth(Width: Integer); safecall;
  public
    procedure Connect(const WebBrowser: IWebBrowser2); virtual;
    destructor Destroy; override;
    procedure Disconnect; virtual;

    property WebBrowser: IWebBrowser2 read FWebBrowser;
  published
    property BeforeNavigate2: TBeforeNavigate2Event
      read FBeforeNavigate2 write FBeforeNavigate2;
    property ClientToHostWindow: TClientToHostWindowEvent
      read FClientToHostWindow write FClientToHostWindow;
    property CommandStateChange: TCommandStateChangeEvent
      read FCommandStateChange write FCommandStateChange;
    property DocumentComplete: TDocumentCompleteEvent
      read FDocumentComplete write FDocumentComplete;
    property DownloadBegin: TDownloadBeginEvent
      read FDownloadBegin write FDownloadBegin;
    property DownloadComplete: TDownloadCompleteEvent
      read FDownloadComplete write FDownloadComplete;
    property FileDownload: TFileDownloadEvent
      read FFileDownload write FFileDownload;
    property NavigateComplete2: TNavigateComplete2Event
      read FNavigateComplete2 write FNavigateComplete2;
    property NavigateError: TNavigateErrorEvent
      read FNavigateError write FNavigateError;
    property NewWindow2: TNewWindow2Event
      read FNewWindow2 write FNewWindow2;
    property OnFullScreen: TOnFullScreenEvent
      read FOnFullScreen write FOnFullScreen;
    property OnMenuBar: TOnMenuBarEvent
      read FOnMenuBar write FOnMenuBar;
    property OnQuit: TOnQuitEvent
      read FOnQuit write FOnQuit;
    property OnStatusBar: TOnStatusBarEvent
      read FOnStatusBar write FOnStatusBar;
    property OnTheaterMode: TOnTheaterModeEvent
      read FOnTheaterMode write FOnTheaterMode;
    property OnToolBar: TOnToolBarEvent
      read FOnToolBar write FOnToolBar;
    property OnVisible: TOnVisibleEvent
      read FOnVisible write FOnVisible;
    property PrintTemplateInstantiation: TPrintTemplateInstantiationEvent
      read FPrintTemplateInstantiation write FPrintTemplateInstantiation;
    property PrintTemplateTeardown: TPrintTemplateTeardownEvent
      read FPrintTemplateTeardown write FPrintTemplateTeardown;
    property PrivacyImpactedStateChange: TPrivacyImpactedStateChangeEvent
      read FPrivacyImpactedStateChange write FPrivacyImpactedStateChange;
    property ProgressChange: TProgressChangeEvent
      read FProgressChange write FProgressChange;
    property PropertyChange: TPropertyChangeEvent
      read FPropertyChange write FPropertyChange;
    property SetSecureLockIcon: TSetSecureLockIconEvent
      read FSetSecureLockIcon write FSetSecureLockIcon;
    property StatusTextChange: TStatusTextChangeEvent
      read FStatusTextChange write FStatusTextChange;
    property TitleChange: TTitleChangeEvent
      read FTitleChange write FTitleChange;
    property UpdatePageStatus: TUpdatePageStatusEvent
      read FUpdatePageStatus write FUpdatePageStatus;
    property WindowClosing: TWindowClosingEvent
      read FWindowClosing write FWindowClosing;
    property WindowSetHeight: TWindowSetHeightEvent
      read FWindowSetHeight write FWindowSetHeight;
    property WindowSetLeft: TWindowSetLeftEvent
      read FWindowSetLeft write FWindowSetLeft;
    property WindowSetResizable: TWindowSetResizableEvent
      read FWindowSetResizable write FWindowSetResizable;
    property WindowSetTop: TWindowSetTopEvent
      read FWindowSetTop write FWindowSetTop;
    property WindowSetWidth: TWindowSetWidthEvent
      read FWindowSetWidth write FWindowSetWidth;
  end;

implementation
uses
  SysUtils;

procedure BuildPositionalDispIds(pDispIds: PDispIdList; const dps: TDispParams);
var i: integer;
begin
  Assert (pDispIds <> nil);

  { by default, directly arrange in reverse order }
  for i := 0 to dps.cArgs - 1 do
    pDispIds^ [i] := dps.cArgs - 1 - i;

  { check for named args }
  if (dps.cNamedArgs <= 0) then
    Exit;

  { parse named args }
  for i := 0 to dps.cNamedArgs - 1 do
    pDispIds^ [dps.rgdispidNamedArgs^ [i]] := i;
end;

{ TWebBrowserEvents }

function TWebBrowserEvents.GetIDsOfNames(const IID: TGUID; Names: Pointer;
  NameCount, LocaleID: Integer; DispIDs: Pointer): HResult;
begin
  Result := E_NOTIMPL;
end;

function TWebBrowserEvents.GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult;
begin
  Result := E_NOTIMPL;
  pointer (TypeInfo) := nil;
end;

function TWebBrowserEvents.GetTypeInfoCount(out Count: Integer): HResult;
begin
  Result := E_NOTIMPL;
  Count := 0;
end;

function TWebBrowserEvents.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
  Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult;
var
  dps: TDispParams absolute Params;
  bHasParams: boolean;
  pDispIds: PDispIdList;
  iDispIdsSize: integer;
begin
  { validity checks }
  if (Flags AND DISPATCH_METHOD = 0) then
    raise Exception.Create (
      Format ('%s only supports sinking of method calls!', [ClassName]
    ));

  { build pDispIds array. this maybe a bit of overhead but it allows us to
    sink named-argument calls such as Excel's AppEvents, etc!
  }
  pDispIds := nil;
  iDispIdsSize := 0;
  bHasParams := (dps.cArgs > 0);
  if (bHasParams) then
  begin
    iDispIdsSize := dps.cArgs * SizeOf (TDispId);
    GetMem (pDispIds, iDispIdsSize);
  end;  { if }

  try
    { rearrange dispids properly }
    if (bHasParams) then BuildPositionalDispIds (pDispIds, dps);
    Result := DoInvoke (DispId, IID, LocaleID, Flags, dps, pDispIds, VarResult, ExcepInfo, ArgErr);
  finally
    { free pDispIds array }
    if (bHasParams) then FreeMem (pDispIds, iDispIdsSize);
  end;  { finally }
end;

function TWebBrowserEvents.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
  if (GetInterface (IID, Obj)) then
  begin
    Result := S_OK;
    Exit;
  end
  else
    if (IsEqualIID (IID, DWebBrowserEvents2)) then
      if (GetInterface (IDispatch, Obj)) then
      begin
        Result := S_OK;
        Exit;
      end;
  Result := E_NOINTERFACE;
  pointer (Obj) := nil;
end;

function TWebBrowserEvents._AddRef: Integer;
begin
  Result := 2;
end;

function TWebBrowserEvents._Release: Integer;
begin
  Result := 1;
end;

destructor TWebBrowserEvents.Destroy;
begin
  Disconnect;
  inherited;
end;

procedure TWebBrowserEvents.Connect(const WebBrowser: IWebBrowser2);
var pcpc: IConnectionPointContainer;
begin
  Assert(WebBrowser <> nil);
  Disconnect;
  try
    OleCheck(WebBrowser.QueryInterface(IConnectionPointContainer, pcpc));
    OleCheck(pcpc.FindConnectionPoint(DWebBrowserEvents2, FCP));
    OleCheck(FCP.Advise(Self, FCookie));
    FWebBrowser := WebBrowser;
  except
    raise Exception.Create (Format ('Unable to connect %s.'#13'%s',
      [ClassName, Exception (ExceptObject).Message]
    ));
  end;  { finally }
end;

procedure TWebBrowserEvents.Disconnect;
begin
  if (FWebBrowser = nil) then Exit;
  try
    OleCheck(FCP.Unadvise(FCookie));
    FCP := nil;
    FWebBrowser := nil;
  except
    pointer(FCP) := nil;
    pointer(FWebBrowser) := nil;
  end;  
end;

function TWebBrowserEvents.DoInvoke (DispID: Integer; const IID: TGUID; LocaleID: Integer;
  Flags: Word; var dps: TDispParams; pDispIds: PDispIdList;
  VarResult, ExcepInfo, ArgErr: Pointer): HResult;
type
  POleVariant = ^OleVariant;
begin
  Result := DISP_E_MEMBERNOTFOUND;

  case DispId of
    102: begin
           DoStatusTextChange (dps.rgvarg^ [pDispIds^ [0]].bstrval);
           Result := S_OK;
         end;
    108: begin
           DoProgressChange (dps.rgvarg^ [pDispIds^ [0]].lval, dps.rgvarg^ [pDispIds^ [1]].lval);
           Result := S_OK;
         end;
    105: begin
           DoCommandStateChange (dps.rgvarg^ [pDispIds^ [0]].lval, dps.rgvarg^ [pDispIds^ [1]].vbool);
           Result := S_OK;
         end;
    106: begin
           DoDownloadBegin ();
           Result := S_OK;
         end;
    104: begin
           DoDownloadComplete ();
           Result := S_OK;
         end;
    113: begin
           DoTitleChange (dps.rgvarg^ [pDispIds^ [0]].bstrval);
           Result := S_OK;
         end;
    112: begin
           DoPropertyChange (dps.rgvarg^ [pDispIds^ [0]].bstrval);
           Result := S_OK;
         end;
    250: begin
           DoBeforeNavigate2 (IDispatch (dps.rgvarg^ [pDispIds^ [0]].dispval), POleVariant (dps.rgvarg^ [pDispIds^ [1]].pvarval)^, POleVariant (dps.rgvarg^ [pDispIds^ [2]].pvarval)^, POleVariant (dps.rgvarg^ [pDispIds^ [3]].pvarval)^, POleVariant (dps.rgvarg^ [pDispIds^ [4]].pvarval)^, POleVariant (dps.rgvarg^ [pDispIds^ [5]].pvarval)^, dps.rgvarg^ [pDispIds^ [6]].pbool^);
           Result := S_OK;
         end;
    251: begin
           DoNewWindow2 (IDispatch (dps.rgvarg^ [pDispIds^ [0]].pdispval^), dps.rgvarg^ [pDispIds^ [1]].pbool^);
           Result := S_OK;
         end;
    252: begin
           DoNavigateComplete2 (IDispatch (dps.rgvarg^ [pDispIds^ [0]].dispval), POleVariant (dps.rgvarg^ [pDispIds^ [1]].pvarval)^);
           Result := S_OK;
         end;
    259: begin
           DoDocumentComplete (IDispatch (dps.rgvarg^ [pDispIds^ [0]].dispval), POleVariant (dps.rgvarg^ [pDispIds^ [1]].pvarval)^);
           Result := S_OK;
         end;
    253: begin
           DoOnQuit ();
           Result := S_OK;
         end;
    254: begin
           DoOnVisible (dps.rgvarg^ [pDispIds^ [0]].vbool);
           Result := S_OK;
         end;
    255: begin
           DoOnToolBar (dps.rgvarg^ [pDispIds^ [0]].vbool);
           Result := S_OK;
         end;
    256: begin
           DoOnMenuBar (dps.rgvarg^ [pDispIds^ [0]].vbool);
           Result := S_OK;
         end;
    257: begin
           DoOnStatusBar (dps.rgvarg^ [pDispIds^ [0]].vbool);
           Result := S_OK;
         end;
    258: begin
           DoOnFullScreen (dps.rgvarg^ [pDispIds^ [0]].vbool);
           Result := S_OK;
         end;
    260: begin
           DoOnTheaterMode (dps.rgvarg^ [pDispIds^ [0]].vbool);
           Result := S_OK;
         end;
    262: begin
           DoWindowSetResizable (dps.rgvarg^ [pDispIds^ [0]].vbool);
           Result := S_OK;
         end;
    264: begin
           DoWindowSetLeft (dps.rgvarg^ [pDispIds^ [0]].lval);
           Result := S_OK;
         end;
    265: begin
           DoWindowSetTop (dps.rgvarg^ [pDispIds^ [0]].lval);
           Result := S_OK;
         end;
    266: begin
           DoWindowSetWidth (dps.rgvarg^ [pDispIds^ [0]].lval);
           Result := S_OK;
         end;
    267: begin
           DoWindowSetHeight (dps.rgvarg^ [pDispIds^ [0]].lval);
           Result := S_OK;
         end;
    263: begin
           DoWindowClosing (dps.rgvarg^ [pDispIds^ [0]].vbool, dps.rgvarg^ [pDispIds^ [1]].pbool^);
           Result := S_OK;
         end;
    268: begin
           DoClientToHostWindow (dps.rgvarg^ [pDispIds^ [0]].plval^, dps.rgvarg^ [pDispIds^ [1]].plval^);
           Result := S_OK;
         end;
    269: begin
           DoSetSecureLockIcon (dps.rgvarg^ [pDispIds^ [0]].lval);
           Result := S_OK;
         end;
    270: begin
           DoFileDownload (dps.rgvarg^ [pDispIds^ [0]].pbool^);
           Result := S_OK;
         end;
    271: begin
           DoNavigateError (IDispatch (dps.rgvarg^ [pDispIds^ [0]].dispval), POleVariant (dps.rgvarg^ [pDispIds^ [1]].pvarval)^, POleVariant (dps.rgvarg^ [pDispIds^ [2]].pvarval)^, POleVariant (dps.rgvarg^ [pDispIds^ [3]].pvarval)^, dps.rgvarg^ [pDispIds^ [4]].pbool^);
           Result := S_OK;
         end;
    225: begin
           DoPrintTemplateInstantiation (IDispatch (dps.rgvarg^ [pDispIds^ [0]].dispval));
           Result := S_OK;
         end;
    226: begin
           DoPrintTemplateTeardown (IDispatch (dps.rgvarg^ [pDispIds^ [0]].dispval));
           Result := S_OK;
         end;
    227: begin
           DoUpdatePageStatus (IDispatch (dps.rgvarg^ [pDispIds^ [0]].dispval), POleVariant (dps.rgvarg^ [pDispIds^ [1]].pvarval)^, POleVariant (dps.rgvarg^ [pDispIds^ [2]].pvarval)^);
           Result := S_OK;
         end;
    272: begin
           DoPrivacyImpactedStateChange (dps.rgvarg^ [pDispIds^ [0]].vbool);
           Result := S_OK;
         end;
  end;
end;

procedure TWebBrowserEvents.DoStatusTextChange(const Text: WideString);
begin
  if not Assigned (StatusTextChange) then System.Exit;
  StatusTextChange (Self, Text);
end;

procedure TWebBrowserEvents.DoProgressChange(Progress: Integer; ProgressMax: Integer);
begin
  if not Assigned (ProgressChange) then System.Exit;
  ProgressChange (Self, Progress, ProgressMax);
end;

procedure TWebBrowserEvents.DoCommandStateChange(Command: Integer; Enable: WordBool);
begin
  if not Assigned (CommandStateChange) then System.Exit;
  CommandStateChange (Self, Command, Enable);
end;

procedure TWebBrowserEvents.DoDownloadBegin;
begin
  if not Assigned (DownloadBegin) then System.Exit;
  DownloadBegin (Self);
end;

procedure TWebBrowserEvents.DoDownloadComplete;
begin
  if not Assigned (DownloadComplete) then System.Exit;
  DownloadComplete (Self);
end;

procedure TWebBrowserEvents.DoTitleChange(const Text: WideString);
begin
  if not Assigned (TitleChange) then System.Exit;
  TitleChange (Self, Text);
end;

procedure TWebBrowserEvents.DoPropertyChange(const szProperty: WideString);
begin
  if not Assigned (PropertyChange) then System.Exit;
  PropertyChange (Self, szProperty);
end;

procedure TWebBrowserEvents.DoBeforeNavigate2(const pDisp: IDispatch; var URL: OleVariant; var Flags: OleVariant; var TargetFrameName: OleVariant; var PostData: OleVariant; var Headers: OleVariant; var Cancel: WordBool);
begin
  if not Assigned (BeforeNavigate2) then System.Exit;
  BeforeNavigate2 (Self, pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel);
end;

procedure TWebBrowserEvents.DoNewWindow2(var ppDisp: IDispatch; var Cancel: WordBool);
var
  pppDisp: IDispatch;
begin
  if not Assigned (NewWindow2) then System.Exit;
  if (ppDisp <> nil) then pppDisp := ppDisp as IDispatch else pppDisp := nil;
  NewWindow2 (Self, pppDisp, Cancel);
  ppDisp := pppDisp;
end;

procedure TWebBrowserEvents.DoNavigateComplete2(const pDisp: IDispatch; var URL: OleVariant);
begin
  if not Assigned (NavigateComplete2) then System.Exit;
  NavigateComplete2 (Self, pDisp, URL);
end;

procedure TWebBrowserEvents.DoDocumentComplete(const pDisp: IDispatch; var URL: OleVariant);
begin
  if not Assigned (DocumentComplete) then System.Exit;
  DocumentComplete (Self, pDisp, URL);
end;

procedure TWebBrowserEvents.DoOnQuit;
begin
  if not Assigned (OnQuit) then System.Exit;
  OnQuit (Self);
end;

procedure TWebBrowserEvents.DoOnVisible(Visible: WordBool);
begin
  if not Assigned (OnVisible) then System.Exit;
  OnVisible (Self, Visible);
end;

procedure TWebBrowserEvents.DoOnToolBar(ToolBar: WordBool);
begin
  if not Assigned (OnToolBar) then System.Exit;
  OnToolBar (Self, ToolBar);
end;

procedure TWebBrowserEvents.DoOnMenuBar(MenuBar: WordBool);
begin
  if not Assigned (OnMenuBar) then System.Exit;
  OnMenuBar (Self, MenuBar);
end;

procedure TWebBrowserEvents.DoOnStatusBar(StatusBar: WordBool);
begin
  if not Assigned (OnStatusBar) then System.Exit;
  OnStatusBar (Self, StatusBar);
end;

procedure TWebBrowserEvents.DoOnFullScreen(FullScreen: WordBool);
begin
  if not Assigned (OnFullScreen) then System.Exit;
  OnFullScreen (Self, FullScreen);
end;

procedure TWebBrowserEvents.DoOnTheaterMode(TheaterMode: WordBool);
begin
  if not Assigned (OnTheaterMode) then System.Exit;
  OnTheaterMode (Self, TheaterMode);
end;

procedure TWebBrowserEvents.DoWindowSetResizable(Resizable: WordBool);
begin
  if not Assigned (WindowSetResizable) then System.Exit;
  WindowSetResizable (Self, Resizable);
end;

procedure TWebBrowserEvents.DoWindowSetLeft(Left: Integer);
begin
  if not Assigned (WindowSetLeft) then System.Exit;
  WindowSetLeft (Self, Left);
end;

procedure TWebBrowserEvents.DoWindowSetTop(Top: Integer);
begin
  if not Assigned (WindowSetTop) then System.Exit;
  WindowSetTop (Self, Top);
end;

procedure TWebBrowserEvents.DoWindowSetWidth(Width: Integer);
begin
  if not Assigned (WindowSetWidth) then System.Exit;
  WindowSetWidth (Self, Width);
end;

procedure TWebBrowserEvents.DoWindowSetHeight(Height: Integer);
begin
  if not Assigned (WindowSetHeight) then System.Exit;
  WindowSetHeight (Self, Height);
end;

procedure TWebBrowserEvents.DoWindowClosing(IsChildWindow: WordBool; var Cancel: WordBool);
begin
  if not Assigned (WindowClosing) then System.Exit;
  WindowClosing (Self, IsChildWindow, Cancel);
end;

procedure TWebBrowserEvents.DoClientToHostWindow(var CX: Integer; var CY: Integer);
begin
  if not Assigned (ClientToHostWindow) then System.Exit;
  ClientToHostWindow (Self, CX, CY);
end;

procedure TWebBrowserEvents.DoSetSecureLockIcon(SecureLockIcon: Integer);
begin
  if not Assigned (SetSecureLockIcon) then System.Exit;
  SetSecureLockIcon (Self, SecureLockIcon);
end;

procedure TWebBrowserEvents.DoFileDownload(var Cancel: WordBool);
begin
  if not Assigned (FileDownload) then System.Exit;
  FileDownload (Self, Cancel);
end;

procedure TWebBrowserEvents.DoNavigateError(const pDisp: IDispatch; var URL: OleVariant; var Frame: OleVariant; var StatusCode: OleVariant; var Cancel: WordBool);
begin
  if not Assigned (NavigateError) then System.Exit;
  NavigateError (Self, pDisp, URL, Frame, StatusCode, Cancel);
end;

procedure TWebBrowserEvents.DoPrintTemplateInstantiation(const pDisp: IDispatch);
begin
  if not Assigned (PrintTemplateInstantiation) then System.Exit;
  PrintTemplateInstantiation (Self, pDisp);
end;

procedure TWebBrowserEvents.DoPrintTemplateTeardown(const pDisp: IDispatch);
begin
  if not Assigned (PrintTemplateTeardown) then System.Exit;
  PrintTemplateTeardown (Self, pDisp);
end;

procedure TWebBrowserEvents.DoUpdatePageStatus(const pDisp: IDispatch; var nPage: OleVariant; var fDone: OleVariant);
begin
  if not Assigned (UpdatePageStatus) then System.Exit;
  UpdatePageStatus (Self, pDisp, nPage, fDone);
end;

procedure TWebBrowserEvents.DoPrivacyImpactedStateChange(bImpacted: WordBool);
begin
  if not Assigned (PrivacyImpactedStateChange) then System.Exit;
  PrivacyImpactedStateChange (Self, bImpacted);
end;

end.
