Page Speed Optimization Libraries
1.7.30.3
|
00001 /* 00002 * Copyright 2013 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 00019 00020 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_ 00021 #define NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_ 00022 00023 #include <vector> 00024 00025 #include "net/instaweb/htmlparse/public/html_writer_filter.h" 00026 #include "net/instaweb/rewriter/cache_html_info.pb.h" 00027 #include "net/instaweb/rewriter/public/blink_util.h" 00028 #include "net/instaweb/util/public/basictypes.h" 00029 #include "net/instaweb/util/public/property_cache.h" 00030 #include "net/instaweb/util/public/string.h" 00031 #include "net/instaweb/util/public/string_util.h" 00032 #include "net/instaweb/util/public/string_writer.h" 00033 #include "net/instaweb/util/public/json.h" 00034 00035 namespace net_instaweb { 00036 00037 class HtmlElement; 00038 class RewriteDriver; 00039 class RewriteOptions; 00040 00043 class CacheHtmlFilter : public HtmlWriterFilter { 00044 public: 00045 explicit CacheHtmlFilter(RewriteDriver* rewrite_driver); 00046 virtual ~CacheHtmlFilter(); 00047 00048 virtual void StartDocument(); 00049 virtual void StartElement(HtmlElement* element); 00050 virtual void EndElement(HtmlElement* element); 00051 virtual void EndDocument(); 00052 void WriteString(StringPiece str); 00053 virtual void Flush(); 00054 virtual const char* Name() const { return "CacheHtmlFilter"; } 00055 00056 private: 00057 void SendCookies(); 00058 void SendNonCacheableObject(const Json::Value& json); 00062 GoogleString GetXpathOfCurrentElement(HtmlElement* element); 00063 00064 RewriteDriver* rewrite_driver_; 00065 const RewriteOptions* rewrite_options_; 00066 AttributesToNonCacheableValuesMap attribute_non_cacheable_values_map_; 00067 std::vector<int> panel_number_num_instances_; 00068 GoogleString buffer_; 00069 StringWriter string_writer_; 00070 const HtmlElement* current_non_cacheable_element_; 00071 GoogleString current_panel_id_; 00072 const PropertyCache::Cohort* cohort_; 00073 CacheHtmlInfo cache_html_info_; 00074 bool abort_filter_; 00075 std::vector<int> num_children_stack_; 00076 00077 DISALLOW_COPY_AND_ASSIGN(CacheHtmlFilter); 00078 }; 00079 00080 } 00081 00082 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_