Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
flush_early_content_writer_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
17 
18 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_
19 #define NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_
20 
21 #include <list>
22 
23 #include "net/instaweb/http/public/logging_proto.h"
24 #include "net/instaweb/http/public/logging_proto_impl.h"
25 #include "pagespeed/kernel/base/basictypes.h"
26 #include "pagespeed/kernel/base/null_writer.h"
27 #include "pagespeed/kernel/base/scoped_ptr.h"
28 #include "pagespeed/kernel/base/string.h"
29 #include "pagespeed/kernel/base/string_util.h"
30 #include "pagespeed/kernel/base/writer.h"
31 #include "pagespeed/kernel/html/html_element.h"
32 #include "pagespeed/kernel/html/html_node.h"
33 #include "pagespeed/kernel/html/html_writer_filter.h"
34 #include "pagespeed/kernel/http/semantic_type.h"
35 #include "pagespeed/kernel/http/user_agent_matcher.h"
36 
37 namespace net_instaweb {
38 
39 class GoogleUrl;
40 class RewriteDriver;
41 class TimedVariable;
42 
43 struct ResourceInfo;
44 
49 class FlushEarlyContentWriterFilter : public HtmlWriterFilter {
50  public:
51  static const char kDisableLinkTag[];
52  static const char kPrefetchImageTagHtml[];
53  static const char kPrefetchStartTimeScript[];
54  static const char kNumResourcesFlushedEarly[];
55  static const char kLinkRelPrefetchTagHtml[];
56  static const char kPrefetchScriptTagHtml[];
57  static const char kPrefetchLinkTagHtml[];
58  static const char kFlushEarlyStyleTemplate[];
59 
61 
62  virtual void StartDocument();
63  virtual void EndDocument();
64 
65  virtual void StartElement(HtmlElement* element);
66  virtual void EndElement(HtmlElement* element);
67 
68  virtual void Characters(HtmlCharactersNode* characters_node);
69  virtual bool CanInjectScript() const { return true; }
70 
71  protected:
72  virtual void Clear();
73 
74  private:
76  void WriteToOriginalWriter(const GoogleString& in);
77 
79  bool IsFlushable(const GoogleUrl& gurl,
80  const FlushEarlyResourceInfo::ResourceType& resource_type);
81 
83  void FlushResourceAsImage(StringPiece url);
84 
85  void FlushResourceWithHtmlTemplate(const char* templ, StringPiece url);
86 
88  void FlushResources(
89  StringPiece url,
90  int64 time_to_download,
91  bool is_pagespeed_resource,
92  semantic_type::Category category);
93 
94  void FlushDeferJavascriptEarly();
95  void UpdateStats(int64 time_to_download, bool is_pagespeed_resource);
96  GoogleString ComputeFlushEarlyCriticalCss(const GoogleString& style_id);
97 
99  FlushEarlyResourceInfo::ResourceType GetResourceType(
100  const GoogleUrl& gurl, bool is_pagespeed_resource);
101 
102  RewriteDriver* driver_;
103  TimedVariable* num_resources_flushed_early_;
105  bool in_body_;
106  bool insert_close_script_;
107  int num_resources_flushed_;
108  NullWriter null_writer_;
109  Writer* original_writer_;
110  HtmlElement* current_element_;
111  UserAgentMatcher::PrefetchMechanism prefetch_mechanism_;
112  scoped_ptr<StringSet> private_cacheable_resources_;
113  scoped_ptr<StringSet> public_cacheable_resources_;
114  int64 time_consumed_ms_;
115  int64 max_available_time_ms_;
116  typedef std::list<ResourceInfo*> ResourceInfoList;
117  ResourceInfoList js_resources_info_;
118  bool defer_javascript_enabled_;
119  bool is_flushing_critical_style_element_;
120  GoogleString css_output_content_;
121  GoogleString flush_early_content_;
122  bool flush_more_resources_early_if_time_permits_;
123  bool stylesheets_flushed_;
124 
125 
126 };
127 
128 }
129 
130 #endif
Definition: rewrite_driver.h:98
Definition: flush_early_content_writer_filter.h:49