예제 #1
0
        /// <summary>Handle navigation events</summary>
        private void HandleNavigating(object sender, WebBrowserNavigatingEventArgs args)
        {
            // Ignore recursive calls (and navigation events that happen after
            // this method returns but are due to the assignment of DocumentStream)
            if (m_rdr_content || args.Url == AboutBlankUrl)
            {
                return;
            }
            using (Scope.Create(() => m_rdr_content = true, () => m_rdr_content = false))
            {
                var idx = UrlHistory.Position + 1;

                // Add the selected URL to the history
                if (idx == UrlHistory.Count)
                {
                    // Resolve the URL to content
                    var a = new ResolveContentEventArgs(args.Url);
                    OnResolveContent(a);

                    // Add to the history
                    UrlHistory.Add(new Visit(a.Url, a.Content));
                }
                else if (!m_fwd_or_back || args.Url != UrlHistory[idx].Url)
                {
                    // Resolve the URL to content
                    var a = new ResolveContentEventArgs(args.Url);
                    OnResolveContent(a);

                    // Set the current visit and remove the future history
                    UrlHistory[idx] = new Visit(a.Url, a.Content);
                    m_url_history.RemoveToEnd(idx + 1);
                }

                UrlHistory.Position = idx;

                // Display the content
                var content = UrlHistory.Current.Content;
                if (content != null)
                {
                    // Setting DocumentStream is considered a navigation (to about:blank)
                    // This may or may not result in a recursive call to this method
                    m_wb.DocumentStream = new MemoryStream(Encoding.UTF8.GetBytes(content));
                    args.Cancel         = true;
                }
                m_fwd_or_back = false;
            }

            System.Diagnostics.Debug.WriteLine($"{UrlHistory.Position} : {string.Join("->", UrlHistory.Select(x => x.Url.ToString()))}");
        }
예제 #2
0
 protected virtual void OnResolveContent(ResolveContentEventArgs args)
 {
     ResolveContent?.Invoke(this, args);
 }