chromium/third_party/blink/renderer/core/inspector/inspector_style_sheet.cc

/*
 * Copyright (C) 2010, Google 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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.
 */

#include "third_party/blink/renderer/core/inspector/inspector_style_sheet.h"

#include <algorithm>
#include <memory>

#include "third_party/blink/renderer/core/css/css_container_rule.h"
#include "third_party/blink/renderer/core/css/css_font_palette_values_rule.h"
#include "third_party/blink/renderer/core/css/css_grouping_rule.h"
#include "third_party/blink/renderer/core/css/css_import_rule.h"
#include "third_party/blink/renderer/core/css/css_keyframe_rule.h"
#include "third_party/blink/renderer/core/css/css_keyframes_rule.h"
#include "third_party/blink/renderer/core/css/css_layer_block_rule.h"
#include "third_party/blink/renderer/core/css/css_media_rule.h"
#include "third_party/blink/renderer/core/css/css_nested_declarations_rule.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/css/css_property_rule.h"
#include "third_party/blink/renderer/core/css/css_property_value_set.h"
#include "third_party/blink/renderer/core/css/css_rule_list.h"
#include "third_party/blink/renderer/core/css/css_scope_rule.h"
#include "third_party/blink/renderer/core/css/css_style_rule.h"
#include "third_party/blink/renderer/core/css/css_style_sheet.h"
#include "third_party/blink/renderer/core/css/css_supports_rule.h"
#include "third_party/blink/renderer/core/css/parser/css_at_rule_id.h"
#include "third_party/blink/renderer/core/css/parser/css_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_local_context.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_observer.h"
#include "third_party/blink/renderer/core/css/parser/css_tokenizer.h"
#include "third_party/blink/renderer/core/css/properties/css_parsing_utils.h"
#include "third_party/blink/renderer/core/css/properties/longhands/custom_property.h"
#include "third_party/blink/renderer/core/css/properties/shorthand.h"
#include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/css/resolver/style_cascade.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/css/style_rule.h"
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/execution_context/security_context.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/html_style_element.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/inspector_audits_issue.h"
#include "third_party/blink/renderer/core/inspector/inspector_css_agent.h"
#include "third_party/blink/renderer/core/inspector/inspector_network_agent.h"
#include "third_party/blink/renderer/core/inspector/inspector_resource_container.h"
#include "third_party/blink/renderer/core/inspector/inspector_style_resolver.h"
#include "third_party/blink/renderer/core/inspector/protocol/css.h"
#include "third_party/blink/renderer/core/svg/svg_style_element.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_regexp.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/text_position.h"
#include "third_party/blink/renderer/platform/wtf/wtf_size_t.h"

Array;

namespace blink {

namespace {

static const CSSParserContext* ParserContextForDocument(
    const Document* document) {}

String FindMagicComment(const String& content, const String& name) {}

void GetClassNamesFromRule(CSSStyleRule* rule, HashSet<String>& unique_names) {}

class StyleSheetHandler final : public CSSParserObserver {};

void StyleSheetHandler::StartRuleHeader(StyleRule::RuleType type,
                                        unsigned offset) {}

template <typename CharacterType>
inline void StyleSheetHandler::SetRuleHeaderEnd(
    const base::span<const CharacterType> data_start,
    unsigned list_end_offset) {}

void StyleSheetHandler::EndRuleHeader(unsigned offset) {}

void StyleSheetHandler::ObserveSelector(unsigned start_offset,
                                        unsigned end_offset) {}

void StyleSheetHandler::StartRuleBody(unsigned offset) {}

void StyleSheetHandler::EndRuleBody(unsigned offset) {}

void StyleSheetHandler::AddNewRuleToSourceTree(CSSRuleSourceData* rule) {}

void StyleSheetHandler::RemoveLastRuleFromSourceTree() {}

CSSRuleSourceData* StyleSheetHandler::PopRuleData() {}

wtf_size_t FindColonIndex(const String& property_string) {}

void StyleSheetHandler::ObserveProperty(unsigned start_offset,
                                        unsigned end_offset,
                                        bool is_important,
                                        bool is_parsed) {}

void StyleSheetHandler::ObserveComment(unsigned start_offset,
                                       unsigned end_offset) {}

static OrdinalNumber AddOrdinalNumbers(OrdinalNumber a, OrdinalNumber b) {}

TextPosition StyleSheetHandler::GetTextPosition(unsigned start_offset) {}

void StyleSheetHandler::ObserveErroneousAtRule(
    unsigned start_offset,
    CSSAtRuleID id,
    const Vector<CSSPropertyID, 2>& invalid_properties) {}

void StyleSheetHandler::ObserveNestedDeclarations(unsigned insert_rule_index) {}

static CSSPropertySourceData* GetPropertySourceData(
    CSSRuleSourceData& source_data,
    StringView propertyName) {}

static std::pair<const char*, const char*> GetPropertyNameAndIssueReason(
    CSSPropertyID invalid_property) {}

void StyleSheetHandler::ReportPropertyRuleFailure(
    unsigned start_offset,
    CSSPropertyID invalid_property) {}

bool VerifyRuleText(Document* document, const String& rule_text) {}

bool VerifyStyleText(Document* document,
                     const String& text,
                     StyleRule::RuleType rule_type = StyleRule::kStyle) {}

bool VerifyNestedDeclarations(Document* document, const String& rule_text) {}

bool VerifyPropertyNameText(Document* document, const String& name_text) {}

bool VerifyKeyframeKeyText(Document* document, const String& key_text) {}

bool VerifySelectorText(Document* document, const String& selector_text) {}

bool VerifyMediaText(Document* document, const String& media_text) {}

bool VerifyContainerQueryText(Document* document,
                              const String& container_query_text) {}

bool VerifySupportsText(Document* document, const String& supports_text) {}

bool VerifyScopeText(Document* document, const String& scope_text) {}

void FlattenSourceData(const CSSRuleSourceDataList& data_list,
                       CSSRuleSourceDataList* result) {}

CSSRuleList* AsCSSRuleList(CSSRule* rule) {}

template <typename RuleList>
void CollectFlatRules(RuleList rule_list, CSSRuleVector* result) {}

// Warning: it does not always produce valid CSS.
// Use the rule's cssText method if you need to expose CSS externally.
String CanonicalCSSText(CSSRule* rule) {}

}  // namespace

enum MediaListSource {};

std::unique_ptr<protocol::CSS::SourceRange>
InspectorStyleSheetBase::BuildSourceRangeObject(const SourceRange& range) {}

InspectorStyle::InspectorStyle(CSSStyleDeclaration* style,
                               CSSRuleSourceData* source_data,
                               InspectorStyleSheetBase* parent_style_sheet)
    :{}

std::unique_ptr<protocol::CSS::CSSStyle> InspectorStyle::BuildObjectForStyle(
    Element* element,
    PseudoId pseudo_id,
    const AtomicString& pseudo_argument) {}

bool InspectorStyle::StyleText(String* result) {}

bool InspectorStyle::TextForRange(const SourceRange& range, String* result) {}

void InspectorStyle::PopulateAllProperties(
    Vector<CSSPropertySourceData>& result) {}

bool InspectorStyle::CheckRegisteredPropertySyntaxWithVarSubstitution(
    Element* element,
    const CSSPropertySourceData& property,
    PseudoId pseudo_id,
    const AtomicString& pseudo_argument) const {}

std::unique_ptr<protocol::CSS::CSSStyle> InspectorStyle::StyleWithProperties(
    Element* element,
    PseudoId pseudo_id,
    const AtomicString& pseudo_argument) {}

String InspectorStyle::ShorthandValue(const String& shorthand_property) {}

std::unique_ptr<protocol::Array<protocol::CSS::CSSProperty>>
InspectorStyle::LonghandProperties(
    const CSSPropertySourceData& property_entry) {}

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

InspectorStyleSheetBase::InspectorStyleSheetBase(Listener* listener, String id)
    :{}

void InspectorStyleSheetBase::OnStyleSheetTextChanged() {}

std::unique_ptr<protocol::CSS::CSSStyle>
InspectorStyleSheetBase::BuildObjectForStyle(
    CSSStyleDeclaration* style,
    Element* element,
    PseudoId pseudo_id,
    const AtomicString& pseudo_argument) {}

const LineEndings* InspectorStyleSheetBase::GetLineEndings() {}

const LineEndings* StyleSheetHandler::GetLineEndings() {}

void InspectorStyleSheetBase::ResetLineEndings() {}

bool InspectorStyleSheetBase::LineNumberAndColumnToOffset(
    unsigned line_number,
    unsigned column_number,
    unsigned* offset) {}

InspectorStyleSheet::InspectorStyleSheet(
    InspectorNetworkAgent* network_agent,
    CSSStyleSheet* page_style_sheet,
    const String& origin,
    const String& document_url,
    InspectorStyleSheetBase::Listener* listener,
    InspectorResourceContainer* resource_container)
    :{}

InspectorStyleSheet::~InspectorStyleSheet() = default;

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

static String StyleSheetURL(CSSStyleSheet* page_style_sheet) {}

String InspectorStyleSheet::FinalURL() {}

bool InspectorStyleSheet::SetText(const String& text,
                                  ExceptionState& exception_state) {}

void InspectorStyleSheet::CSSOMStyleSheetTextReplaced(const String& text) {}

CSSStyleRule* InspectorStyleSheet::SetRuleSelector(
    const SourceRange& range,
    const String& text,
    SourceRange* new_range,
    String* old_text,
    ExceptionState& exception_state) {}

CSSPropertyRule* InspectorStyleSheet::SetPropertyName(
    const SourceRange& range,
    const String& text,
    SourceRange* new_range,
    String* old_text,
    ExceptionState& exception_state) {}

CSSKeyframeRule* InspectorStyleSheet::SetKeyframeKey(
    const SourceRange& range,
    const String& text,
    SourceRange* new_range,
    String* old_text,
    ExceptionState& exception_state) {}

CSSRule* InspectorStyleSheet::SetStyleText(const SourceRange& range,
                                           const String& text,
                                           SourceRange* new_range,
                                           String* old_text,
                                           ExceptionState& exception_state) {}

CSSMediaRule* InspectorStyleSheet::SetMediaRuleText(
    const SourceRange& range,
    const String& text,
    SourceRange* new_range,
    String* old_text,
    ExceptionState& exception_state) {}

CSSContainerRule* InspectorStyleSheet::SetContainerRuleText(
    const SourceRange& range,
    const String& text,
    SourceRange* new_range,
    String* old_text,
    ExceptionState& exception_state) {}

CSSSupportsRule* InspectorStyleSheet::SetSupportsRuleText(
    const SourceRange& range,
    const String& text,
    SourceRange* new_range,
    String* old_text,
    ExceptionState& exception_state) {}

CSSScopeRule* InspectorStyleSheet::SetScopeRuleText(
    const SourceRange& range,
    const String& text,
    SourceRange* new_range,
    String* old_text,
    ExceptionState& exception_state) {}

CSSRuleSourceData* InspectorStyleSheet::RuleSourceDataAfterSourceRange(
    const SourceRange& source_range) {}

CSSStyleRule* InspectorStyleSheet::InsertCSSOMRuleInStyleSheet(
    CSSRule* insert_before,
    const String& rule_text,
    ExceptionState& exception_state) {}

CSSStyleRule* InspectorStyleSheet::InsertCSSOMRuleInMediaRule(
    CSSMediaRule* media_rule,
    CSSRule* insert_before,
    const String& rule_text,
    ExceptionState& exception_state) {}

CSSStyleRule* InspectorStyleSheet::InsertCSSOMRuleBySourceRange(
    const SourceRange& source_range,
    const String& rule_text,
    ExceptionState& exception_state) {}

CSSStyleRule* InspectorStyleSheet::AddRule(const String& rule_text,
                                           const SourceRange& location,
                                           SourceRange* added_range,
                                           ExceptionState& exception_state) {}

bool InspectorStyleSheet::DeleteRule(const SourceRange& range,
                                     ExceptionState& exception_state) {}

std::unique_ptr<protocol::Array<String>>
InspectorStyleSheet::CollectClassNames() {}

void InspectorStyleSheet::ReplaceText(const SourceRange& range,
                                      const String& text,
                                      SourceRange* new_range,
                                      String* old_text) {}

void InspectorStyleSheet::ParseText(const String& text) {}

// The stylesheet text might be out of sync with `page_style_sheet_` rules.
// This method checks if a rule is present in the source text using
// `SourceDataForRule` and produces a new text with all rules merged into the
// original text. For example, if the source text is
//
//   /* comment */ .rule1 {} .rule3 {}
//
// and the page_style_sheet_ contains
//
//   .rule0 {} .rule1 {} .rule2 {} .rule3 {} .rule4 {}
//
// The result should be
//
//   .rule0 {} /* comment */ .rule1 {} .rule2 {} .rule3 {} .rule4 {}
//
// Note that page_style_sheet_ does not maintain comments and original
// formatting.
String InspectorStyleSheet::MergeCSSOMRulesWithText(const String& text) {}

void InspectorStyleSheet::InnerSetText(const String& text,
                                       bool mark_as_locally_modified) {}

namespace {

TextPosition TextPositionFromOffsetAndLineEndingsRelativeToStartPosition(
    unsigned offset,
    const Vector<unsigned>& line_endings,
    const TextPosition& start_position) {}

}  // namespace

std::unique_ptr<protocol::CSS::CSSStyleSheetHeader>
InspectorStyleSheet::BuildObjectForStyleSheetInfo() {}

std::unique_ptr<protocol::Array<protocol::CSS::Value>>
InspectorStyleSheet::SelectorsFromSource(CSSRuleSourceData* source_data,
                                         const String& sheet_text,
                                         CSSStyleRule* rule) {}

std::unique_ptr<protocol::CSS::SelectorList>
InspectorStyleSheet::BuildObjectForSelectorList(CSSStyleRule* rule) {}

static bool CanBind(const String& origin) {}

std::unique_ptr<protocol::CSS::CSSRule>
InspectorStyleSheet::BuildObjectForRuleWithoutAncestorData(
    CSSStyleRule* rule,
    Element* element,
    PseudoId pseudo_id,
    const AtomicString& pseudo_argument) {}

std::unique_ptr<protocol::CSS::RuleUsage>
InspectorStyleSheet::BuildObjectForRuleUsage(CSSRule* rule, bool was_used) {}

std::unique_ptr<protocol::CSS::CSSPositionTryRule>
InspectorStyleSheet::BuildObjectForPositionTryRule(
    CSSPositionTryRule* position_try_rule,
    bool active) {}

std::unique_ptr<protocol::CSS::CSSFontPaletteValuesRule>
InspectorStyleSheet::BuildObjectForFontPaletteValuesRule(
    CSSFontPaletteValuesRule* values_rule) {}

std::unique_ptr<protocol::CSS::CSSPropertyRule>
InspectorStyleSheet::BuildObjectForPropertyRule(
    CSSPropertyRule* property_rule) {}

std::unique_ptr<protocol::CSS::CSSKeyframeRule>
InspectorStyleSheet::BuildObjectForKeyframeRule(CSSKeyframeRule* keyframe_rule,
                                                Element* element) {}

bool InspectorStyleSheet::GetText(String* result) {}

std::unique_ptr<protocol::CSS::SourceRange>
InspectorStyleSheet::RuleHeaderSourceRange(CSSRule* rule) {}

std::unique_ptr<protocol::CSS::SourceRange>
InspectorStyleSheet::MediaQueryExpValueSourceRange(
    CSSRule* rule,
    wtf_size_t media_query_index,
    wtf_size_t media_query_exp_index) {}

InspectorStyle* InspectorStyleSheet::GetInspectorStyle(
    CSSStyleDeclaration* style) {}

String InspectorStyleSheet::SourceURL() {}

String InspectorStyleSheet::Url() {}

bool InspectorStyleSheet::HasSourceURL() {}

bool InspectorStyleSheet::StartsAtZero() {}

String InspectorStyleSheet::SourceMapURL() {}

const Document* InspectorStyleSheet::GetDocument() {}

CSSRuleSourceData* InspectorStyleSheet::FindRuleByHeaderRange(
    const SourceRange& source_range) {}

CSSRuleSourceData* InspectorStyleSheet::FindRuleByBodyRange(
    const SourceRange& source_range) {}

CSSRule* InspectorStyleSheet::RuleForSourceData(
    CSSRuleSourceData* source_data) {}

CSSRuleSourceData* InspectorStyleSheet::SourceDataForRule(CSSRule* rule) {}

void InspectorStyleSheet::RemapSourceDataToCSSOMIfNecessary() {}

void InspectorStyleSheet::MapSourceDataToCSSOM() {}

const CSSRuleVector& InspectorStyleSheet::FlatRules() {}

bool InspectorStyleSheet::ResourceStyleSheetText(String* result,
                                                 bool* loadingFailed) {}

Element* InspectorStyleSheet::OwnerStyleElement() {}

String InspectorStyleSheet::CollectStyleSheetRules() {}

bool InspectorStyleSheet::CSSOMStyleSheetText(String* result) {}

void InspectorStyleSheet::Reset() {}

void InspectorStyleSheet::SyncTextIfNeeded() {}

void InspectorStyleSheet::UpdateText() {}

bool InspectorStyleSheet::IsMutable() const {}

bool InspectorStyleSheet::InlineStyleSheetText(String* out) {}

bool InspectorStyleSheet::InspectorStyleSheetText(String* result) {}

InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(
    Element* element,
    Listener* listener)
    :{}

void InspectorStyleSheetForInlineStyle::DidModifyElementAttribute() {}

bool InspectorStyleSheetForInlineStyle::SetText(
    const String& text,
    ExceptionState& exception_state) {}

bool InspectorStyleSheetForInlineStyle::GetText(String* result) {}

InspectorStyle* InspectorStyleSheetForInlineStyle::GetInspectorStyle(
    CSSStyleDeclaration* style) {}

CSSRuleSourceData* InspectorStyleSheetForInlineStyle::RuleSourceData() {}

CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::InlineStyle() {}

const String& InspectorStyleSheetForInlineStyle::ElementStyleText() {}

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

const Document* InspectorStyleSheetForInlineStyle::GetDocument() {}

}  // namespace blink