internal void FrameStoppedLoading(string frameId)
        {
            if (!Frames.TryGetValue(frameId, out var frame))
            {
                return;
            }

            bool hasDOMContentLoaded = frame.FiredLifecycleEvents.Contains(WaitUntilNavigation.DOMContentLoaded);
            bool hasLoad             = frame.FiredLifecycleEvents.Contains(WaitUntilNavigation.Load);

            frame.FiredLifecycleEvents.Add(WaitUntilNavigation.DOMContentLoaded);
            frame.FiredLifecycleEvents.Add(WaitUntilNavigation.Load);

            foreach (var watcher in LifecycleWatchers.ToArray())
            {
                watcher?.OnLifecycleEvent(frame);
            }

            if (frame == MainFrame && !hasDOMContentLoaded)
            {
                _page.OnDOMContentLoaded();
            }

            if (frame == MainFrame && !hasLoad)
            {
                _page.OnLoad();
            }
        }
        internal void RequestFailed(Request request, bool canceled)
        {
            InflightRequestFinished(request);
            var frame = request.Frame;

            if (!string.IsNullOrEmpty(request.DocumentId) && frame != null)
            {
                if (frame.LastDocumentId != request.DocumentId)
                {
                    string errorText = request.Failure;
                    if (canceled)
                    {
                        errorText += "; maybe frame was detached?";
                    }

                    foreach (var watcher in LifecycleWatchers.ToArray())
                    {
                        watcher?.OnAbortedNewDocumentNavigation(frame, request.DocumentId, errorText);
                    }
                }
            }

            if (!request.IsFavicon)
            {
                _page.OnRequestFailed(request);
            }
        }
        internal void FrameCommittedNewDocumentNavigation(string frameId, string url, string name, string documentId, bool initial)
        {
            Frames.TryGetValue(frameId, out var frame);

            if (frame == null)
            {
                return;
            }

            while (frame.ChildFrames.Count > 0)
            {
                RemoveFramesRecursively(frame.ChildFrames[0]);
            }

            frame.Url            = url;
            frame.Name           = name;
            frame.LastDocumentId = documentId;
            ClearFrameLifecycle(frame);
            ClearWebSockets(frame);

            if (!initial)
            {
                foreach (var watcher in LifecycleWatchers.ToArray())
                {
                    watcher?.OnCommittedNewDocumentNavigation(frame);
                }

                _page.OnFrameNavigated(frame);
            }
        }
        internal void FrameCommittedSameDocumentNavigation(string frameId, string url)
        {
            if (!Frames.TryGetValue(frameId, out var frame))
            {
                return;
            }

            frame.Url = url;
            foreach (var watcher in LifecycleWatchers.ToArray())
            {
                watcher?.OnNavigatedWithinDocument(frame);
            }

            _page.OnFrameNavigated(frame);
        }
        private void RemoveFramesRecursively(Frame frame)
        {
            while (frame.ChildFrames.Count > 0)
            {
                RemoveFramesRecursively(frame.ChildFrames[0]);
            }

            frame.OnDetached();
            Frames.TryRemove(frame.Id, out _);
            foreach (var watcher in LifecycleWatchers.ToArray())
            {
                watcher?.OnFrameDetached(frame);
            }

            _page.OnFrameDetached(frame);
        }
        internal void RequestStarted(Request request)
        {
            InflightRequestStarted(request);
            var frame = request.Frame;

            if (!string.IsNullOrEmpty(request.DocumentId) && frame != null && request.RedirectChain.Count == 0)
            {
                foreach (var watcher in LifecycleWatchers.ToArray())
                {
                    watcher?.OnNavigationRequest(frame, request);
                }
            }

            if (!request.IsFavicon)
            {
                _page.OnRequest(request);
            }
        }
        internal void FrameLifecycleEvent(string frameId, WaitUntilNavigation name)
        {
            if (!Frames.TryGetValue(frameId, out var frame))
            {
                return;
            }

            frame.FiredLifecycleEvents.Add(name);

            foreach (var watcher in LifecycleWatchers.ToArray())
            {
                watcher?.OnLifecycleEvent(frame);
            }

            if (frame == MainFrame && name == WaitUntilNavigation.Load)
            {
                _page.OnLoad();
            }

            if (frame == MainFrame && name == WaitUntilNavigation.DOMContentLoaded)
            {
                _page.OnDOMContentLoaded();
            }
        }
Esempio n. 8
0
        internal void FrameLifecycleEvent(string frameId, string e)
        {
            if (!Frames.TryGetValue(frameId, out var frame))
            {
                return;
            }

            frame.FiredLifecycleEvents.Add(e);

            foreach (var watcher in LifecycleWatchers.ToArray())
            {
                watcher.OnLifecycleEvent(frame);
            }

            if (frame == MainFrame && e == "load")
            {
                _page.OnLoad();
            }

            if (frame == MainFrame && e == "domcontentloaded")
            {
                _page.OnDOMContentLoaded();
            }
        }