summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/xml/xsl_style_sheet.h
blob: 18da053f9c21b48b507c42f38a2af613a9382ddb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * This file is part of the XSL implementation.
 *
 * Copyright (C) 2004, 2006, 2008, 2012 Apple Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_XML_XSL_STYLE_SHEET_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_XML_XSL_STYLE_SHEET_H_

#include <libxml/tree.h>
#include <libxslt/transform.h>
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/core/css/style_sheet.h"
#include "third_party/blink/renderer/core/dom/processing_instruction.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"

namespace blink {

class XSLStyleSheet final : public StyleSheet {
 public:
  XSLStyleSheet(Node* parent_node,
                const String& original_url,
                const KURL& final_url,
                bool embedded);
  // Taking an arbitrary node is unsafe, because owner node pointer can become
  // stale. XSLTProcessor ensures that the stylesheet doesn't outlive its
  // parent, in part by not exposing it to JavaScript.
  XSLStyleSheet(Document* owner_document,
                Node* style_sheet_root_node,
                const String& original_url,
                const KURL& final_url,
                bool embedded);
  XSLStyleSheet(XSLStyleSheet* parent_style_sheet,
                const String& original_url,
                const KURL& final_url);
  ~XSLStyleSheet() override;

  bool ParseString(const String&);

  void CheckLoaded();

  Document* OwnerDocument();
  XSLStyleSheet* parentStyleSheet() const override {
    return parent_style_sheet_;
  }

  xmlDocPtr GetDocument();
  xsltStylesheetPtr CompileStyleSheet();
  xmlDocPtr LocateStylesheetSubResource(xmlDocPtr parent_doc,
                                        const xmlChar* uri);

  void ClearDocuments();

  void MarkAsProcessed();
  bool Processed() const { return processed_; }

  String type() const override { return "text/xml"; }
  bool disabled() const override { return is_disabled_; }
  void setDisabled(bool b) override { is_disabled_ = b; }
  Node* ownerNode() const override { return owner_node_; }
  String href() const override { return original_url_; }
  String title() const override { return g_empty_string; }

  void ClearOwnerNode() override { owner_node_ = nullptr; }
  KURL BaseURL() const override { return final_url_; }
  bool IsLoading() const override { return false; }

  void Trace(Visitor*) override;

 private:
  void LoadChildSheets();
  void LoadChildSheet(const String& href);

  Member<Node> owner_node_;
  String original_url_;
  KURL final_url_;
  bool is_disabled_;

  HeapVector<Member<XSLStyleSheet>> children_;

  bool embedded_;
  bool processed_;

  xmlDocPtr stylesheet_doc_;
  bool stylesheet_doc_taken_;
  bool compilation_failed_;

  Member<XSLStyleSheet> parent_style_sheet_;
  Member<Document> owner_document_;
};

template <>
struct DowncastTraits<XSLStyleSheet> {
  static bool AllowFrom(const StyleSheet& sheet) {
    return !sheet.IsCSSStyleSheet();
  }
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_XML_XSL_STYLE_SHEET_H_