Page Speed Optimization Libraries
1.2.24.1
|
00001 /* 00002 * Copyright 2012 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 00018 00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_BLINK_FILTER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_BLINK_FILTER_H_ 00021 00022 #include <vector> 00023 00024 #include "net/instaweb/htmlparse/public/html_writer_filter.h" 00025 #include "net/instaweb/rewriter/blink_critical_line_data.pb.h" 00026 #include "net/instaweb/rewriter/public/blink_util.h" 00027 #include "net/instaweb/util/public/basictypes.h" 00028 #include "net/instaweb/util/public/property_cache.h" 00029 #include "net/instaweb/util/public/string.h" 00030 #include "net/instaweb/util/public/string_util.h" 00031 #include "net/instaweb/util/public/string_writer.h" 00032 #include "net/instaweb/util/public/json.h" 00033 00034 namespace net_instaweb { 00035 00036 class HtmlElement; 00037 class RewriteDriver; 00038 class RewriteOptions; 00039 00042 class BlinkFilter : public HtmlWriterFilter { 00043 public: 00045 static const char kBlinkCriticalLineDataPropertyName[]; 00046 static const char kBlinkCohort[]; 00047 static const char kRefreshPageJs[]; 00048 00049 explicit BlinkFilter(RewriteDriver* rewrite_driver); 00050 virtual ~BlinkFilter(); 00051 00052 void StartDocument(); 00053 void StartElement(HtmlElement* element); 00054 void EndElement(HtmlElement* element); 00055 void EndDocument(); 00056 void WriteString(StringPiece str); 00057 void Flush(); 00058 virtual const char* Name() const { return "BlinkFilter"; } 00059 00060 private: 00061 void SendCookies(); 00062 void SendNonCriticalJson(GoogleString* str); 00063 void ServeNonCriticalPanelContents(); 00064 void SendNonCacheableObject(const Json::Value& json); 00065 void ObtainBlinkCriticalLineData(); 00066 void HandleLastModifiedChange(); 00070 GoogleString GetXpathOfCurrentElement(HtmlElement* element); 00071 00072 RewriteDriver* rewrite_driver_; 00073 const RewriteOptions* rewrite_options_; 00074 AttributesToNonCacheableValuesMap attribute_non_cacheable_values_map_; 00075 std::vector<int> panel_number_num_instances_; 00076 GoogleString buffer_; 00077 StringWriter string_writer_; 00078 const HtmlElement* current_non_cacheable_element_; 00079 GoogleString current_panel_id_; 00080 const PropertyCache::Cohort* cohort_; 00081 BlinkCriticalLineData blink_critical_line_data_; 00082 bool abort_filter_; 00083 std::vector<int> num_children_stack_; 00084 00085 DISALLOW_COPY_AND_ASSIGN(BlinkFilter); 00086 }; 00087 00088 } 00089 00090 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_BLINK_FILTER_H_