Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
simple_text_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_SIMPLE_TEXT_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_SIMPLE_TEXT_FILTER_H_
21 
32 
33 namespace net_instaweb {
34 
35 class RewriteContext;
36 class RewriteDriver;
37 
47  public:
48  class Rewriter : public RefCounted<Rewriter> {
49  public:
50  Rewriter() {}
51  virtual bool RewriteText(const StringPiece& url,
52  const StringPiece& in,
53  GoogleString* out,
54  ServerContext* server_context) = 0;
55  virtual HtmlElement::Attribute* FindResourceAttribute(
56  HtmlElement* element) = 0;
57 
58  virtual OutputResourceKind kind() const = 0;
59  virtual const char* id() const = 0;
60  virtual const char* name() const = 0;
61 
63  virtual bool OptimizationOnly() const { return true; }
64 
65  protected:
66  REFCOUNT_FRIEND_DECLARATION(Rewriter);
67  virtual ~Rewriter();
68 
69  private:
70 
71  };
72 
73  typedef RefCountedPtr<Rewriter> RewriterPtr;
74 
75  class Context : public SingleRewriteContext {
76  public:
77  Context(const RewriterPtr& rewriter, RewriteDriver* driver,
79  virtual ~Context();
80  virtual void RewriteSingle(
81  const ResourcePtr& input, const OutputResourcePtr& output);
82 
83  protected:
84  virtual const char* id() const { return rewriter_->id(); }
85  virtual OutputResourceKind kind() const { return rewriter_->kind(); }
86  virtual bool OptimizationOnly() const {
87  return rewriter_->OptimizationOnly();
88  }
89  bool PolicyPermitsRendering() const override {
90  return true;
91  }
92 
93  private:
94  RewriterPtr rewriter_;
95 
96 
97  };
98 
99  SimpleTextFilter(Rewriter* rewriter, RewriteDriver* driver);
100  virtual ~SimpleTextFilter();
101 
102  virtual void StartDocumentImpl() {}
103  virtual void EndElementImpl(HtmlElement* element) {}
104  virtual void StartElementImpl(HtmlElement* element);
105 
106  virtual RewriteContext* MakeRewriteContext();
107  virtual RewriteContext* MakeNestedRewriteContext(
108  RewriteContext* parent, const ResourceSlotPtr& slot);
109 
110  protected:
111  virtual const char* id() const { return rewriter_->id(); }
112  virtual const char* Name() const { return rewriter_->name(); }
113  virtual bool ComputeOnTheFly() const {
114  return rewriter_->kind() == kOnTheFlyResource;
115  }
116 
117  private:
118  RewriterPtr rewriter_;
119 
120 
121 };
122 
123 }
124 
125 #endif
RewriteContext * parent()
Allows a nested rewriter to walk up its parent hierarchy.
Definition: rewrite_context.h:280
Definition: html_element.h:66
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: simple_text_filter.h:112
virtual bool OptimizationOnly() const
Definition: simple_text_filter.h:86
virtual bool OptimizationOnly() const
See RewriteContext::OptimizationOnly()
Definition: simple_text_filter.h:63
Definition: ref_counted_ptr.h:41
Definition: output_resource_kind.h:28
Definition: simple_text_filter.h:75
Definition: html_element.h:42
Definition: simple_text_filter.h:46
virtual bool ComputeOnTheFly() const
Definition: simple_text_filter.h:113
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual RewriteContext * MakeRewriteContext()
virtual OutputResourceKind kind() const
Definition: simple_text_filter.h:85
bool PolicyPermitsRendering() const override
Definition: simple_text_filter.h:89
Definition: rewrite_filter.h:35
Definition: rewrite_driver.h:100
Definition: server_context.h:99
Definition: rewrite_context.h:155
Definition: single_rewrite_context.h:36
virtual RewriteContext * MakeNestedRewriteContext(RewriteContext *parent, const ResourceSlotPtr &slot)
virtual void RewriteSingle(const ResourcePtr &input, const OutputResourcePtr &output)
Subclasses of SingleRewriteContext must override this:
Definition: simple_text_filter.h:48
virtual void StartDocumentImpl()
Definition: simple_text_filter.h:102
virtual const char * id() const
Returns the filter ID.
Definition: simple_text_filter.h:84
OutputResourceKind
Definition: output_resource_kind.h:26