~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/html/html_filter.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2010 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
 
 
17
 
// Author: jmarantz@google.com (Joshua Marantz)
18
 
 
19
 
#ifndef PAGESPEED_KERNEL_HTML_HTML_FILTER_H_
20
 
#define PAGESPEED_KERNEL_HTML_HTML_FILTER_H_
21
 
 
22
 
#include "pagespeed/kernel/base/string.h"
23
 
 
24
 
namespace net_instaweb {
25
 
 
26
 
class HtmlCdataNode;
27
 
class HtmlCharactersNode;
28
 
class HtmlCommentNode;
29
 
class HtmlDirectiveNode;
30
 
class HtmlElement;
31
 
class HtmlIEDirectiveNode;
32
 
 
33
 
// Base-class used to register for HTML Parser Callbacks.  Derive from this
34
 
// class and register with HtmlParse::AddFilter to use the HTML Parser.
35
 
class HtmlFilter {
36
 
 public:
37
 
  HtmlFilter();
38
 
  virtual ~HtmlFilter();
39
 
 
40
 
  // Starts a new document.  Filters should clear their state in this function,
41
 
  // as the same Filter instance may be used for multiple HTML documents.
42
 
  virtual void StartDocument() = 0;
43
 
  // Note: EndDocument will be called imediately before the last Flush call.
44
 
  virtual void EndDocument() = 0;
45
 
 
46
 
  // When an HTML element is encountered during parsing, each filter's
47
 
  // StartElement method is called.  The HtmlElement lives for the entire
48
 
  // duration of the document.
49
 
  //
50
 
  // TODO(jmarantz): consider passing handles rather than pointers and
51
 
  // reference-counting them instead to save memory on long documents.
52
 
  virtual void StartElement(HtmlElement* element) = 0;
53
 
  virtual void EndElement(HtmlElement* element) = 0;
54
 
 
55
 
  // Called for CDATA blocks (e.g. <![CDATA[foobar]]>)
56
 
  virtual void Cdata(HtmlCdataNode* cdata) = 0;
57
 
 
58
 
  // Called for HTML comments that aren't IE directives (e.g. <!--foobar-->).
59
 
  virtual void Comment(HtmlCommentNode* comment) = 0;
60
 
 
61
 
  // Called for an IE directive; typically used for CSS styling.
62
 
  // See http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx
63
 
  //
64
 
  // TODO(mdsteele): Should we try to maintain the nested structure of
65
 
  // the conditionals, in the same way that we maintain nesting of elements?
66
 
  virtual void IEDirective(HtmlIEDirectiveNode* directive) = 0;
67
 
 
68
 
  // Called for raw characters between tags.
69
 
  virtual void Characters(HtmlCharactersNode* characters) = 0;
70
 
 
71
 
  // Called for HTML directives (e.g. <!doctype foobar>).
72
 
  virtual void Directive(HtmlDirectiveNode* directive) = 0;
73
 
 
74
 
  // Notifies the Filter that a flush is occurring.  A filter that's
75
 
  // generating streamed output should flush at this time.  A filter
76
 
  // that's mutating elements can mutate any element seen since the
77
 
  // most recent flush; once an element is flushed it is already on
78
 
  // the wire to its destination and it's too late to mutate.  Flush
79
 
  // is initiated by an application calling HttpParse::Flush().
80
 
  //
81
 
  // Flush() is called after all other handlers during a HttpParse::Flush(),
82
 
  // except RenderDone(), which (if in use) happens after Flush().
83
 
  virtual void Flush() = 0;
84
 
 
85
 
  // Notifies a filter that an asynchronous rewrite & render computation
86
 
  // phase has finished. This is not used by HtmlParse itself, but only by
87
 
  // RewriteDriver for pre-render filters. Happens after the corresponding
88
 
  // flush, for every flush window. Default implementation does nothing.
89
 
  // TODO(morlovich): Push this down into CommonFilter and convert all the
90
 
  // pre-render filters to inherit off it.
91
 
  virtual void RenderDone();
92
 
 
93
 
  // Invoked by rewrite driver where all filters should determine whether
94
 
  // they are enabled for this request. The re-writer my optionally set
95
 
  // disabled_reason to explain why it disabled itself, which will appear
96
 
  // in the debug output.
97
 
  virtual void DetermineEnabled(GoogleString* disabled_reason) = 0;
98
 
 
99
 
  // Intended to be called from DetermineEnabled implementations in filters.
100
 
  // Returns whether a filter is enabled.
101
 
  bool is_enabled() const { return is_enabled_; }
102
 
 
103
 
  // The name of this filter -- used for logging and debugging.
104
 
  virtual const char* Name() const = 0;
105
 
 
106
 
 protected:
107
 
  void set_is_enabled(bool is_enabled) { is_enabled_ = is_enabled; }
108
 
 
109
 
 private:
110
 
  bool is_enabled_;
111
 
};
112
 
 
113
 
}  // namespace net_instaweb
114
 
 
115
 
#endif  // PAGESPEED_KERNEL_HTML_HTML_FILTER_H_