00001 /* 00002 * Copyright 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00021 00022 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_INSERT_GA_FILTER_H_ 00023 #define NET_INSTAWEB_REWRITER_PUBLIC_INSERT_GA_FILTER_H_ 00024 00025 #include "net/instaweb/rewriter/public/common_filter.h" 00026 #include "net/instaweb/util/public/basictypes.h" 00027 #include "net/instaweb/util/public/string.h" 00028 00029 namespace net_instaweb { 00030 00031 class HtmlCharactersNode; 00032 class HtmlElement; 00033 class RewriteDriver; 00034 class Statistics; 00035 class Variable; 00036 00037 extern const char kGASnippet[]; 00038 extern const char kGASpeedTracking[]; 00039 00042 class InsertGAFilter : public CommonFilter { 00043 public: 00044 explicit InsertGAFilter(RewriteDriver* rewrite_driver); 00045 virtual ~InsertGAFilter(); 00046 00048 static void Initialize(Statistics* stats); 00049 00050 virtual void StartDocumentImpl(); 00051 virtual void StartElementImpl(HtmlElement* element); 00052 virtual void EndElementImpl(HtmlElement* element); 00054 virtual void Characters(HtmlCharactersNode* characters); 00055 00056 virtual const char* Name() const { return "InsertGASnippet"; } 00057 00058 private: 00060 GoogleString ConstructFuriousSnippet() const; 00061 00063 GoogleString MakeFullFuriousSnippet() const; 00064 00066 void HandleEndHead(HtmlElement* head); 00067 00070 void HandleEndScript(HtmlElement* script); 00071 00074 void AddScriptNode(HtmlElement* parent, const GoogleString& text, 00075 HtmlElement** script_element) const; 00076 00079 bool FoundSnippetInBuffer() const; 00080 00082 Variable* inserted_ga_snippets_count_; 00083 00086 HtmlElement* script_element_; 00088 HtmlElement* added_snippet_element_; 00090 HtmlElement* added_furious_element_; 00091 00093 GoogleString ga_id_; 00094 00097 GoogleString buffer_; 00098 00100 bool found_snippet_; 00101 00103 bool increase_speed_tracking_; 00104 00105 DISALLOW_COPY_AND_ASSIGN(InsertGAFilter); 00106 }; 00107 00108 } 00109 00110 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_INSERT_GA_FILTER_H_