| 37 | | completed = false; |
|---|
| 38 | | navigateCounter = 0; |
|---|
| 39 | | unfinishedDownloads = 0; |
|---|
| 40 | | internetExplorer = new SHDocVw.InternetExplorerClass(); |
|---|
| 41 | | internetExplorer.NavigateError += new DWebBrowserEvents2_NavigateErrorEventHandler(this.navigationError); |
|---|
| 42 | | internetExplorer.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.documentComplete); |
|---|
| 43 | | internetExplorer.DownloadBegin += new DWebBrowserEvents2_DownloadBeginEventHandler(this.downloadBegin); |
|---|
| 44 | | internetExplorer.DownloadComplete += new DWebBrowserEvents2_DownloadCompleteEventHandler(this.downloadComplete); |
|---|
| 45 | | internetExplorer.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.beforeNavigate); |
|---|
| 46 | | internetExplorer.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(this.navigateComplete); |
|---|
| | 29 | ieThread.SetApartmentState(ApartmentState.STA); |
|---|
| 91 | | |
|---|
| 92 | | /// <summary> |
|---|
| 93 | | /// This method is called when a Navigation Error event occurs |
|---|
| 94 | | /// </summary> |
|---|
| 95 | | /// <param name="pDisp"></param> |
|---|
| 96 | | /// <param name="URL">The URL that caused the Navigation Error</param> |
|---|
| 97 | | /// <param name="Frame"></param> |
|---|
| 98 | | /// <param name="StatusCode">Status code of the Navigation Error (ex. 404, 501)</param> |
|---|
| 99 | | /// <param name="Cancel"></param> |
|---|
| 100 | | private void navigationError(object pDisp, ref object URL, ref object Frame, ref object StatusCode, ref bool Cancel) |
|---|
| 101 | | { |
|---|
| 102 | | |
|---|
| 103 | | } |
|---|
| 104 | | |
|---|
| 105 | | /// <summary> |
|---|
| 106 | | /// This method is called when a Document Complete event occurs |
|---|
| 107 | | /// </summary> |
|---|
| 108 | | /// <param name="pDisp"></param> |
|---|
| 109 | | /// <param name="URL">URL of the completed document</param> |
|---|
| 110 | | private void documentComplete(object pDisp, ref object URL) |
|---|
| 111 | | { |
|---|
| 112 | | completed = true; |
|---|
| 113 | | } |
|---|
| 114 | | |
|---|
| 115 | | /// <summary> |
|---|
| 116 | | /// This method is called when a Download Begins event occurs |
|---|
| 117 | | /// Download Begins occurs every time the browser makes a valid |
|---|
| 118 | | /// request for content form a server. |
|---|
| 119 | | /// </summary> |
|---|
| 120 | | private void downloadBegin() |
|---|
| 121 | | { |
|---|
| 122 | | unfinishedDownloads++; |
|---|
| 123 | | } |
|---|
| 124 | | |
|---|
| 125 | | /// <summary> |
|---|
| 126 | | /// This method is called when a Download Complete event occurs |
|---|
| 127 | | /// Download Complete occurs everytime the content downloaded after |
|---|
| 128 | | /// a Download Begins is completed. |
|---|
| 129 | | /// </summary> |
|---|
| 130 | | private void downloadComplete() |
|---|
| 131 | | { |
|---|
| 132 | | unfinishedDownloads--; |
|---|
| 133 | | } |
|---|
| 134 | | |
|---|
| 135 | | /// <summary> |
|---|
| 136 | | /// This method is event that is triggered before a URL is navigated to |
|---|
| 137 | | /// A web page will usually make multiple requests to Navigate URLs |
|---|
| 138 | | /// </summary> |
|---|
| 139 | | /// <param name="pDisp"></param> |
|---|
| 140 | | /// <param name="URL">URL to be navigated to</param> |
|---|
| 141 | | /// <param name="Flags"></param> |
|---|
| 142 | | /// <param name="TargetFrameName"></param> |
|---|
| 143 | | /// <param name="PostData"></param> |
|---|
| 144 | | /// <param name="Headers"></param> |
|---|
| 145 | | /// <param name="Cancel"></param> |
|---|
| 146 | | private void beforeNavigate(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) |
|---|
| 147 | | { |
|---|
| 148 | | if(!((String)URL).Equals("about:blank")) |
|---|
| 149 | | { |
|---|
| 150 | | navigateCounter++; |
|---|
| 151 | | } |
|---|
| 152 | | completed = false; |
|---|
| 153 | | } |
|---|
| 154 | | |
|---|
| 155 | | /// <summary> |
|---|
| 156 | | /// A Navigation Complete event occurs when the browser has finished navigating to |
|---|
| 157 | | /// a URL. It seems that this event is not triggered for each beforeNavigate event. |
|---|
| 158 | | /// It also seems that this event can be triggered more than once for each beforeNavigate |
|---|
| 159 | | /// event. |
|---|
| 160 | | /// </summary> |
|---|
| 161 | | /// <param name="pDisp"></param> |
|---|
| 162 | | /// <param name="URL">URL of the completed navigation</param> |
|---|
| 163 | | private void navigateComplete(object pDisp, ref object URL) |
|---|
| 164 | | { |
|---|
| 165 | | navigateCounter--; |
|---|
| 166 | | } |
|---|