Page Speed Optimization Libraries
1.5.27.2
|
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 */ 00017 00018 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_ 00019 #define NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_ 00020 00021 #include <list> 00022 00023 #include "net/instaweb/htmlparse/public/html_writer_filter.h" 00024 #include "net/instaweb/http/public/logging_proto.h" 00025 #include "net/instaweb/http/public/logging_proto_impl.h" 00026 #include "net/instaweb/http/public/semantic_type.h" 00027 #include "net/instaweb/http/public/user_agent_matcher.h" 00028 #include "net/instaweb/util/public/basictypes.h" 00029 #include "net/instaweb/util/public/null_writer.h" 00030 #include "net/instaweb/util/public/scoped_ptr.h" 00031 #include "net/instaweb/util/public/string.h" 00032 #include "net/instaweb/util/public/string_util.h" 00033 00034 namespace net_instaweb { 00035 00036 class GoogleUrl; 00037 class HtmlCharactersNode; 00038 class HtmlElement; 00039 class RewriteDriver; 00040 class TimedVariable; 00041 class Writer; 00042 00043 struct ResourceInfo; 00044 00049 class FlushEarlyContentWriterFilter : public HtmlWriterFilter { 00050 public: 00051 static const char kPrefetchLinkRelSubresourceHtml[]; 00052 static const char kPrefetchImageTagHtml[]; 00053 static const char kPrefetchStartTimeScript[]; 00054 static const char kNumResourcesFlushedEarly[]; 00055 static const char kPrefetchScriptTagHtml[]; 00056 static const char kPrefetchLinkTagHtml[]; 00057 static const char kInlineCriticalCssLinkTemplate[]; 00058 static const char kDisableLinkTag[]; 00059 00060 explicit FlushEarlyContentWriterFilter(RewriteDriver* driver); 00061 00062 virtual void StartDocument(); 00063 virtual void EndDocument(); 00064 00065 virtual void StartElement(HtmlElement* element); 00066 virtual void EndElement(HtmlElement* element); 00067 00068 virtual void Characters(HtmlCharactersNode* characters_node); 00069 00070 protected: 00071 virtual void Clear(); 00072 00073 private: 00075 void WriteToOriginalWriter(const GoogleString& in); 00076 00078 bool IsFlushable(const GoogleUrl& gurl, 00079 const FlushEarlyResourceInfo::ResourceType& resource_type); 00080 00082 void FlushResources( 00083 StringPiece url, 00084 int64 time_to_download, 00085 bool is_pagespeed_resource, 00086 semantic_type::Category category); 00087 00088 void FlushDeferJavascriptEarly(); 00089 void UpdateStats(int64 time_to_download, bool is_pagespeed_resource); 00090 GoogleString ComputeFlushEarlyCriticalCss(const GoogleString& style_id); 00091 00093 FlushEarlyResourceInfo::ResourceType GetResourceType( 00094 const GoogleUrl& gurl, bool is_pagespeed_resource); 00095 00096 RewriteDriver* driver_; 00097 TimedVariable* num_resources_flushed_early_; 00099 bool in_body_; 00100 bool insert_close_script_; 00101 int num_resources_flushed_; 00102 NullWriter null_writer_; 00103 Writer* original_writer_; 00104 HtmlElement* current_element_; 00105 UserAgentMatcher::PrefetchMechanism prefetch_mechanism_; 00106 scoped_ptr<StringSet> private_cacheable_resources_; 00107 scoped_ptr<StringSet> public_cacheable_resources_; 00108 int64 time_consumed_ms_; 00109 int64 max_available_time_ms_; 00110 typedef std::list<ResourceInfo*> ResourceInfoList; 00111 ResourceInfoList js_resources_info_; 00112 bool defer_javascript_enabled_; 00113 bool split_html_enabled_; 00114 bool is_flushing_critical_style_element_; 00115 GoogleString css_output_content_; 00116 GoogleString flush_early_content_; 00117 bool flush_more_resources_early_if_time_permits_; 00118 00119 DISALLOW_COPY_AND_ASSIGN(FlushEarlyContentWriterFilter); 00120 }; 00121 00122 } 00123 00124 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_