Пример #1
0
        public override INode Clone(Boolean deep = true)
        {
            var node = new HtmlScriptElement(Owner, Prefix, _parserInserted, _started);

            node._forceAsync = _forceAsync;
            CopyProperties(this, node, deep);
            CopyAttributes(this, node);
            return(node);
        }
Пример #2
0
        public override INode Clone(Boolean deep = true)
        {
            var node = new HtmlScriptElement(Owner, Prefix, _parserInserted, _started)
            {
                _forceAsync = _forceAsync
            };

            CloneElement(node, deep);
            return(node);
        }
Пример #3
0
        /// <summary>
        /// See 8.2.5.4.4 The "in head" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void InHead(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Html))
                    {
                        InBody(token);
                        return;
                    }
                    else if (tagName.Is(TagNames.Meta))
                    {
                        var element = new HtmlMetaElement(_document);
                        AddElement(element, token.AsTag(), true);
                        var encoding = element.GetEncoding();
                        CloseCurrentNode();

                        if (encoding != null)
                        {
                            try
                            {
                                _document.Source.CurrentEncoding = encoding;
                            }
                            catch (NotSupportedException)
                            {
                                Restart();
                            }
                        }

                        return;
                    }
                    else if (TagNames.AllHeadBase.Contains(tagName))
                    {
                        AddElement(token.AsTag(), true);
                        CloseCurrentNode();
                        return;
                    }
                    else if (tagName.Is(TagNames.Title))
                    {
                        RCDataAlgorithm(token.AsTag());
                        return;
                    }
                    else if (tagName.IsOneOf(TagNames.Style, TagNames.NoFrames) || (_options.IsScripting && tagName.Is(TagNames.NoScript)))
                    {
                        RawtextAlgorithm(token.AsTag());
                        return;
                    }
                    else if (tagName.Is(TagNames.NoScript))
                    {
                        AddElement(token.AsTag());
                        _currentMode = HtmlTreeMode.InHeadNoScript;
                        return;
                    }
                    else if (tagName.Is(TagNames.Script))
                    {
                        var script = new HtmlScriptElement(_document, parserInserted: true, started: IsFragmentCase);
                        AddElement(script, token.AsTag());
                        _tokenizer.State = HtmlParseMode.Script;
                        _previousMode = _currentMode;
                        _currentMode = HtmlTreeMode.Text;
                        return;
                    }
                    else if (tagName.Is(TagNames.Head))
                    {
                        RaiseErrorOccurred(HtmlParseError.HeadTagMisplaced, token);
                        return;
                    }
                    else if (tagName.Is(TagNames.Template))
                    {
                        AddElement(new HtmlTemplateElement(_document), token.AsTag());
                        _formattingElements.AddScopeMarker();
                        _frameset = false;
                        _currentMode = HtmlTreeMode.InTemplate;
                        _templateModes.Push(HtmlTreeMode.InTemplate);
                        return;
                    }

                    break;
                }
                case HtmlTokenType.EndTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Head))
                    {
                        CloseCurrentNode();

                        _currentMode = HtmlTreeMode.AfterHead;
                        _waiting = _document.WaitForReady();
                        return;
                    }
                    else if (tagName.Is(TagNames.Template))
                    {
                        if (TagCurrentlyOpen(TagNames.Template))
                        {
                            GenerateImpliedEndTags();

                            if (!CurrentNode.LocalName.Is(TagNames.Template))
                                RaiseErrorOccurred(HtmlParseError.TagClosingMismatch, token);

                            CloseTemplate();
                        }
                        else
                            RaiseErrorOccurred(HtmlParseError.TagInappropriate, token);

                        return;
                    }
                    else if (!tagName.IsOneOf(TagNames.Html, TagNames.Body, TagNames.Br))
                    {
                        RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
                        return;
                    }

                    break;
                }
            }

            CloseCurrentNode();
            _currentMode = HtmlTreeMode.AfterHead;
            AfterHead(token);
        }
Пример #4
0
 /// <summary>
 /// Runs the current script element, if there is one.
 /// </summary>
 /// <returns>The task waiting for the document to be ready.</returns>
 async Task RunScript(HtmlScriptElement script)
 {
     await _document.WaitForReady().ConfigureAwait(false);
     script.Run();
 }
Пример #5
0
        /// <summary>
        /// Runs a script given by the current node.
        /// </summary>
        void HandleScript(HtmlScriptElement script)
        {
            //Disable scripting for HTML fragments (security reasons)
            if (script != null && !IsFragmentCase)
            {
                _document.PerformMicrotaskCheckpoint();
                _document.ProvideStableState();
                CloseCurrentNode();
                _currentMode = _previousMode;

                if (script.Prepare(_document))
                {
                    _waiting = RunScript(script);
                }
            }
        }
Пример #6
0
 /// <summary>
 /// Adds a script to the queue of scripts to be run.
 /// </summary>
 /// <param name="script"></param>
 internal void AddScript(HtmlScriptElement script)
 {
     _loadingScripts.Enqueue(script);
 }
Пример #7
0
 internal static ScriptRequestProcessor Create(HtmlScriptElement script)
 {
     var document = script.Owner;
     var loader = document.Loader;
     return new ScriptRequestProcessor(script, document, loader);
 }
Пример #8
0
 private ScriptRequestProcessor(HtmlScriptElement script, Document document, IResourceLoader loader)
 {
     _script = script;
     _document = document;
     _loader = loader;
 }
Пример #9
0
 /// <summary>
 /// Runs the current script element, if there is one.
 /// </summary>
 /// <returns>The task waiting for the document to be ready.</returns>
 private async Task RunScript(HtmlScriptElement script)
 {
     await _document.WaitForReadyAsync().ConfigureAwait(false);
     await script.RunAsync(CancellationToken.None).ConfigureAwait(false);
 }
Пример #10
0
 public override INode Clone(Boolean deep = true)
 {
     var node = new HtmlScriptElement(Owner, Prefix, _parserInserted, _started)
     {
         _forceAsync = _forceAsync
     };
     CloneElement(node, deep);
     return node;
 }