Ejemplo n.º 1
0
        internal void Navigate(IIsolatedBrowser browser, string url)
        {
            var task = new NavigationTask()
            {
                Browser = browser, Url = url
            };

            if (_current == null)
            {
                StartTask(task);
            }
            else if (!_current.Browser.IsBusy)
            {
                Cleanup();
                StartTask(task);
            }
            else
            {
                // Check whether we already have a pending navigation for this browser.
                // If so, discard it since it's now irrelevant.  (It may also be impossible
                // if it was for a temporary file: see https://jira.sil.org/browse/BL-863.)
                for (int i = 0; i < _pending.Count; ++i)
                {
                    if (browser.Equals(_pending[i].Browser))
                    {
                        _pending.RemoveAt(i);
                        break;
                    }
                }
                _pending.Add(task);
            }
        }
Ejemplo n.º 2
0
 private void StartTask(NavigationTask task)
 {
     _current         = task;
     _startNavigation = DateTime.Now;
     _current.Browser.InstallEventHandlers();
     _current.Browser.Navigated += BrowserOnDocumentCompleted;
     Debug.Assert(_timer == null, "We should have cleaned up any old timer before starting a new task");
     _timer       = new Timer();
     _timer.Tick += (sender, args) =>
     {
         if (_current == null)
         {
             // We somehow got another tick after the need for the timer has passed. Get rid of it.
             CleanupTimer();
             return;
         }
         if (!_current.Browser.IsBusy)
         {
             // browser stopped being busy without notifying us! Pretend it did.
             BrowserOnDocumentCompleted(null, null);
         }
         if (DateTime.Now - _startNavigation > new TimeSpan(0, 0, 0, 2))
         {
             // Navigation is taking too long. Sometimes the main window stays busy forerver. Give up.
             // Enhance: may want to wait a bit longer if nothing is waiting...but remember idle tasks can still be frozen out.
             ForceDocumentCompleted();
         }
     };
     _timer.Interval = 100;
     _timer.Start();
     _current.Browser.Navigate(_current.Url);
 }
Ejemplo n.º 3
0
        private void Cleanup()
        {
            if (_current == null)
            {
                return;
            }

            CleanupTimer();
            _current.Browser.RemoveEventHandlers();
            _current.Browser.Navigated -= BrowserOnDocumentCompleted;
            _current = null;
        }
        internal void Navigate(IIsolatedBrowser browser, string url)
        {
            var task = new NavigationTask()
            {
                Browser = browser, Url = url
            };

            if (_current == null)
            {
                StartTask(task);
            }
            else if (!_current.Browser.IsBusy)
            {
                Cleanup();
                StartTask(task);
            }
            else
            {
                _pending.Add(task);
            }
        }
Ejemplo n.º 5
0
 private void StartTask(NavigationTask task)
 {
     _current = task;
     _startNavigation = DateTime.Now;
     _current.Browser.InstallEventHandlers();
     _current.Browser.Navigated += BrowserOnDocumentCompleted;
     Debug.Assert(_timer == null, "We should have cleaned up any old timer before starting a new task");
     _timer = new Timer();
     _timer.Tick += (sender, args) =>
     {
         if (_current == null)
         {
             // We somehow got another tick after the need for the timer has passed. Get rid of it.
             CleanupTimer();
             return;
         }
         if (!_current.Browser.IsBusy)
         {
             // browser stopped being busy without notifying us! Pretend it did.
             BrowserOnDocumentCompleted(null, null);
         }
         if (DateTime.Now - _startNavigation > new TimeSpan(0, 0, 0, 2))
         {
             // Navigation is taking too long. Sometimes the main window stays busy forerver. Give up.
             // Enhance: may want to wait a bit longer if nothing is waiting...but remember idle tasks can still be frozen out.
             ForceDocumentCompleted();
         }
     };
     _timer.Interval = 100;
     _timer.Start();
     _current.Browser.Navigate(_current.Url);
 }
Ejemplo n.º 6
0
        private void Cleanup()
        {
            if (_current == null) return;

            CleanupTimer();
            _current.Browser.RemoveEventHandlers();
            _current.Browser.Navigated -= BrowserOnDocumentCompleted;
            _current = null;
        }
Ejemplo n.º 7
0
 internal void Navigate(IIsolatedBrowser browser, string url)
 {
     var task = new NavigationTask() { Browser = browser, Url = url };
     if (_current == null)
     {
         StartTask(task);
     }
     else if (!_current.Browser.IsBusy)
     {
         Cleanup();
         StartTask(task);
     }
     else
     {
         // Check whether we already have a pending navigation for this browser.
         // If so, discard it since it's now irrelevant.  (It may also be impossible
         // if it was for a temporary file: see https://jira.sil.org/browse/BL-863.)
         for (int i = 0; i < _pending.Count; ++i)
         {
             if (browser.Equals(_pending[i].Browser))
             {
                 _pending.RemoveAt(i);
                 break;
             }
         }
         _pending.Add(task);
     }
 }