chromium/third_party/blink/renderer/core/html/parser/html_tree_builder.cc

/*
 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
 * Copyright (C) 2011, 2014 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GOOGLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/core/html/parser/html_tree_builder.h"

#include <memory>

#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_fragment.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/html/forms/html_form_control_element.h"
#include "third_party/blink/renderer/core/html/forms/html_form_element.h"
#include "third_party/blink/renderer/core/html/forms/html_text_area_element.h"
#include "third_party/blink/renderer/core/html/html_template_element.h"
#include "third_party/blink/renderer/core/html/parser/atomic_html_token.h"
#include "third_party/blink/renderer/core/html/parser/html_document_parser.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/html/parser/html_stack_item.h"
#include "third_party/blink/renderer/core/html/parser/html_token.h"
#include "third_party/blink/renderer/core/html/parser/html_tokenizer.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/mathml_names.h"
#include "third_party/blink/renderer/core/svg_names.h"
#include "third_party/blink/renderer/core/xlink_names.h"
#include "third_party/blink/renderer/core/xml_names.h"
#include "third_party/blink/renderer/core/xmlns_names.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/runtime_call_stats.h"
#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/text/platform_locale.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
#include "third_party/blink/renderer/platform/wtf/text/character_visitor.h"
#include "third_party/blink/renderer/platform/wtf/text/string_buffer.h"

namespace blink {

HTMLTag;

namespace {

inline bool IsHTMLSpaceOrReplacementCharacter(UChar character) {}
}  // namespace

static TextPosition UninitializedPositionValue1() {}

static inline bool IsAllWhitespace(const StringView& string_view) {}

static inline bool IsAllWhitespaceOrReplacementCharacters(
    const StringView& string_view) {}

// The following macros are used in switch statements for some common types.
// They are defined so that they can look like a normal case statement, e.g.:
//   case FOO_CASES:

// Disable formatting as it mangles these macros.
// clang-format off

#define CAPTION_COL_OR_COLGROUP_CASES

#define NUMBERED_HEADER_CASES

#define TABLE_BODY_CONTEXT_CASES

#define TABLE_CELL_CONTEXT_CASES

// clang-format on

static bool IsTableBodyContextTag(HTMLTag tag) {}

// http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#formatting
class HTMLTreeBuilder::CharacterTokenBuffer {};

HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser,
                                 Document& document,
                                 ParserContentPolicy parser_content_policy,
                                 const HTMLParserOptions& options,
                                 bool include_shadow_roots,
                                 DocumentFragment* for_fragment,
                                 Element* fragment_context_element)
    :{}
HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser,
                                 Document& document,
                                 ParserContentPolicy parser_content_policy,
                                 const HTMLParserOptions& options,
                                 bool include_shadow_roots)
    :{}
HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser,
                                 DocumentFragment* fragment,
                                 Element* context_element,
                                 ParserContentPolicy parser_content_policy,
                                 const HTMLParserOptions& options,
                                 bool include_shadow_roots)
    :{}

HTMLTreeBuilder::~HTMLTreeBuilder() = default;

void HTMLTreeBuilder::FragmentParsingContext::Init(DocumentFragment* fragment,
                                                   Element* context_element) {}

void HTMLTreeBuilder::FragmentParsingContext::Trace(Visitor* visitor) const {}

void HTMLTreeBuilder::Trace(Visitor* visitor) const {}

void HTMLTreeBuilder::Detach() {}

Element* HTMLTreeBuilder::TakeScriptToProcess(
    TextPosition& script_start_position) {}

void HTMLTreeBuilder::ConstructTree(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessToken(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessDoctypeToken(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessFakeStartTag(HTMLTag tag,
                                          const Vector<Attribute>& attributes) {}

void HTMLTreeBuilder::ProcessFakeEndTag(HTMLTag tag) {}

void HTMLTreeBuilder::ProcessFakeEndTag(const HTMLStackItem& stack_item) {}

void HTMLTreeBuilder::ProcessFakePEndTagIfPInButtonScope() {}

namespace {

bool IsLi(const HTMLStackItem* item) {}

bool IsDdOrDt(const HTMLStackItem* item) {}

}  // namespace

template <bool shouldClose(const HTMLStackItem*)>
void HTMLTreeBuilder::ProcessCloseWhenNestedTag(AtomicHTMLToken* token) {}

namespace {
PrefixedNameToQualifiedNameMap;

template <typename TableQualifiedName>
void MapLoweredLocalNameToName(PrefixedNameToQualifiedNameMap* map,
                               const TableQualifiedName* const* names,
                               size_t length) {}

void AddManualLocalName(PrefixedNameToQualifiedNameMap* map, const char* name) {}

// "Any other start tag" bullet in
// https://html.spec.whatwg.org/C/#parsing-main-inforeign
void AdjustSVGTagNameCase(AtomicHTMLToken* token) {}

template <std::unique_ptr<const QualifiedName* []> getAttrs(),
          unsigned length,
          bool forSVG>
void AdjustAttributes(AtomicHTMLToken* token) {}

// https://html.spec.whatwg.org/C/#adjust-svg-attributes
void AdjustSVGAttributes(AtomicHTMLToken* token) {}

// https://html.spec.whatwg.org/C/#adjust-mathml-attributes
void AdjustMathMLAttributes(AtomicHTMLToken* token) {}

void AddNamesWithPrefix(PrefixedNameToQualifiedNameMap* map,
                        const AtomicString& prefix,
                        const QualifiedName* const* names,
                        size_t length) {}

void AdjustForeignAttributes(AtomicHTMLToken* token) {}

}  // namespace

void HTMLTreeBuilder::ProcessStartTagForInBody(AtomicHTMLToken* token) {}

namespace {
String DeclarativeShadowRootModeFromToken(AtomicHTMLToken* token,
                                          const Document& document,
                                          bool include_shadow_roots) {}
}  // namespace

void HTMLTreeBuilder::ProcessTemplateStartTag(AtomicHTMLToken* token) {}

bool HTMLTreeBuilder::ProcessTemplateEndTag(AtomicHTMLToken* token) {}

bool HTMLTreeBuilder::ProcessEndOfFileForInTemplateContents(
    AtomicHTMLToken* token) {}

bool HTMLTreeBuilder::ProcessColgroupEndTagForInColumnGroup() {}

// http://www.whatwg.org/specs/web-apps/current-work/#adjusted-current-node
HTMLStackItem* HTMLTreeBuilder::AdjustedCurrentStackItem() const {}

// http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#close-the-cell
void HTMLTreeBuilder::CloseTheCell() {}

void HTMLTreeBuilder::ProcessStartTagForInTable(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessStartTag(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessHtmlStartTagForInBody(AtomicHTMLToken* token) {}

bool HTMLTreeBuilder::ProcessBodyEndTagForInBody(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessAnyOtherEndTagForInBody(AtomicHTMLToken* token) {}

// http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#parsing-main-inbody
void HTMLTreeBuilder::CallTheAdoptionAgency(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ResetInsertionModeAppropriately() {}

void HTMLTreeBuilder::ProcessEndTagForInTableBody(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessEndTagForInRow(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessEndTagForInCell(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessEndTagForInBody(AtomicHTMLToken* token) {}

bool HTMLTreeBuilder::ProcessCaptionEndTagForInCaption() {}

bool HTMLTreeBuilder::ProcessTrEndTagForInRow() {}

bool HTMLTreeBuilder::ProcessTableEndTagForInTable() {}

void HTMLTreeBuilder::ProcessEndTagForInTable(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessEndTag(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessComment(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessDOMPart(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessCharacter(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessCharacterBuffer(CharacterTokenBuffer& buffer) {}

void HTMLTreeBuilder::ProcessCharacterBufferForInBody(
    CharacterTokenBuffer& buffer) {}

void HTMLTreeBuilder::ProcessEndOfFile(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::DefaultForInitial() {}

void HTMLTreeBuilder::DefaultForBeforeHTML() {}

void HTMLTreeBuilder::DefaultForBeforeHead() {}

void HTMLTreeBuilder::DefaultForInHead() {}

void HTMLTreeBuilder::DefaultForInHeadNoscript() {}

void HTMLTreeBuilder::DefaultForAfterHead() {}

void HTMLTreeBuilder::DefaultForInTableText() {}

bool HTMLTreeBuilder::ProcessStartTagForInHead(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessGenericRCDATAStartTag(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessGenericRawTextStartTag(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessScriptStartTag(AtomicHTMLToken* token) {}

// http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#tree-construction
bool HTMLTreeBuilder::ShouldProcessTokenInForeignContent(
    AtomicHTMLToken* token) {}

void HTMLTreeBuilder::ProcessTokenInForeignContent(AtomicHTMLToken* token) {}

void HTMLTreeBuilder::Finished() {}

void HTMLTreeBuilder::ParseError(AtomicHTMLToken*) {}

#ifndef NDEBUG
const char* HTMLTreeBuilder::ToString(HTMLTreeBuilder::InsertionMode mode) {}
#endif

}  // namespace blink