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 */ 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/semantic_type.h" 00025 #include "net/instaweb/http/public/user_agent_matcher.h" 00026 #include "net/instaweb/util/public/basictypes.h" 00027 #include "net/instaweb/util/public/null_writer.h" 00028 #include "net/instaweb/util/public/scoped_ptr.h" 00029 #include "net/instaweb/util/public/string.h" 00030 #include "net/instaweb/util/public/string_util.h" 00031 00032 namespace net_instaweb { 00033 00034 class GoogleUrl; 00035 class HtmlElement; 00036 class RewriteDriver; 00037 class TimedVariable; 00038 class Writer; 00039 00040 struct ResourceInfo; 00041 00046 class FlushEarlyContentWriterFilter : public HtmlWriterFilter { 00047 public: 00048 static const char kPrefetchLinkRelSubresourceHtml[]; 00049 static const char kPrefetchImageTagHtml[]; 00050 static const char kPrefetchStartTimeScript[]; 00051 static const char kNumResourcesFlushedEarly[]; 00052 static const char kPrefetchScriptTagHtml[]; 00053 static const char kPrefetchLinkTagHtml[]; 00054 00055 explicit FlushEarlyContentWriterFilter(RewriteDriver* driver); 00056 00057 virtual void StartDocument(); 00058 virtual void EndDocument(); 00059 00060 virtual void StartElement(HtmlElement* element); 00061 virtual void EndElement(HtmlElement* element); 00062 00063 protected: 00064 virtual void Clear(); 00065 00066 private: 00068 void WriteToOriginalWriter(const GoogleString& in); 00069 00071 bool IsFlushable(const GoogleUrl& gurl, bool is_pagespeed_resource); 00072 00074 void FlushResources( 00075 StringPiece url, 00076 int64 time_to_download, 00077 bool is_pagespeed_resource, 00078 semantic_type::Category category); 00079 00080 RewriteDriver* driver_; 00081 TimedVariable* num_resources_flushed_early_; 00083 bool in_body_; 00084 bool insert_close_script_; 00085 int num_resources_flushed_; 00086 NullWriter null_writer_; 00087 Writer* original_writer_; 00088 HtmlElement* current_element_; 00089 UserAgentMatcher::PrefetchMechanism prefetch_mechanism_; 00090 scoped_ptr<StringSet> private_cacheable_resources_; 00091 int64 time_consumed_ms_; 00092 int64 max_available_time_ms_; 00093 typedef std::list<ResourceInfo*> ResourceInfoList; 00094 ResourceInfoList js_resources_info_; 00095 bool defer_javascript_enabled_; 00096 GoogleString flush_early_content_; 00097 00098 DISALLOW_COPY_AND_ASSIGN(FlushEarlyContentWriterFilter); 00099 }; 00100 00101 } 00102 00103 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_