48 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_GOOGLE_ANALYTICS_FILTER_H_
49 #define NET_INSTAWEB_REWRITER_PUBLIC_GOOGLE_ANALYTICS_FILTER_H_
53 #include "net/instaweb/htmlparse/public/empty_html_filter.h"
59 namespace net_instaweb {
61 class HtmlCharactersNode;
62 class HtmlCommentNode;
64 class HtmlIEDirectiveNode;
74 kGaJsScriptSrcLoad = 0,
79 HtmlCharactersNode* characters_node,
80 GoogleString::size_type pos,
81 GoogleString::size_type len,
84 HtmlElement* GetScriptElement()
const {
return script_element_; }
85 HtmlCharactersNode* GetScriptCharactersNode()
const {
86 return script_characters_node_;
88 Type GetType()
const {
return editor_type_; }
90 void NewContents(
const StringPiece &replacement,
91 GoogleString* contents)
const;
94 HtmlElement* script_element_;
95 HtmlCharactersNode* script_characters_node_;
97 GoogleString::size_type pos_;
98 GoogleString::size_type len_;
109 typedef StringPieceVector MethodVector;
112 Statistics* statistics);
117 Statistics* statistics,
118 MethodVector* glue_methods,
119 MethodVector* unhandled_methods);
121 static void InitStats(Statistics* statistics);
123 virtual void StartDocument();
124 virtual void EndDocument();
125 virtual void StartElement(HtmlElement* element);
126 virtual void EndElement(HtmlElement* element);
128 virtual void Flush();
131 virtual void Characters(HtmlCharactersNode* characters_node);
134 virtual void Comment(HtmlCommentNode* comment);
135 virtual void Cdata(HtmlCdataNode* cdata);
136 virtual void IEDirective(HtmlIEDirectiveNode* directive);
138 virtual const char* Name()
const {
return "GoogleAnalytics"; }
140 static const char kPageLoadCount[];
141 static const char kRewrittenCount[];
146 bool MatchSyncLoad(StringPiece contents,
147 GoogleString::size_type* pos,
148 GoogleString::size_type* len)
const;
149 bool MatchSyncInit(StringPiece contents,
150 GoogleString::size_type start_pos,
151 GoogleString::size_type* pos,
152 GoogleString::size_type* len)
const;
153 bool MatchUnhandledCalls(StringPiece contents,
154 GoogleString::size_type start_pos)
const;
155 void FindRewritableScripts();
156 void GetSyncToAsyncScript(GoogleString* buffer)
const;
157 bool RewriteAsAsync();
161 std::vector<ScriptEditor*> script_editors_;
163 scoped_ptr<MethodVector> glue_methods_;
164 scoped_ptr<MethodVector> unhandled_methods_;
166 HtmlParse* html_parse_;
167 HtmlElement* script_element_;
168 HtmlCharactersNode* script_characters_node_;
170 Variable* page_load_count_;
171 Variable* rewritten_count_;
Definition: google_analytics_filter.h:107
virtual void Characters(HtmlCharactersNode *characters_node)
Expected HTML Events in <script> elements.
Edit a substring in a script element.
Definition: google_analytics_filter.h:71
virtual void Comment(HtmlCommentNode *comment)
Unexpected HTML Events in <script> elements.