~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/flush_early_content_writer_filter.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 */
16
 
// Author: nikhilmadan@google.com (Nikhil Madan)
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/htmlparse/public/html_writer_filter.h"
24
 
#include "net/instaweb/http/public/logging_proto.h"
25
 
#include "net/instaweb/http/public/logging_proto_impl.h"
26
 
#include "net/instaweb/http/public/semantic_type.h"
27
 
#include "net/instaweb/http/public/user_agent_matcher.h"
28
 
#include "net/instaweb/util/public/basictypes.h"
29
 
#include "net/instaweb/util/public/null_writer.h"
30
 
#include "net/instaweb/util/public/scoped_ptr.h"
31
 
#include "net/instaweb/util/public/string.h"
32
 
#include "net/instaweb/util/public/string_util.h"
33
 
 
34
 
namespace net_instaweb {
35
 
 
36
 
class GoogleUrl;
37
 
class HtmlCharactersNode;
38
 
class HtmlElement;
39
 
class RewriteDriver;
40
 
class TimedVariable;
41
 
class Writer;
42
 
 
43
 
struct ResourceInfo;
44
 
 
45
 
// FlushEarlyContentWriterFilter finds rewritten resources in the DOM and
46
 
// inserts HTML that makes the browser download them. Note that we set a
47
 
// NullWriter as the writer for this driver, and directly  write whatever we
48
 
// need to the original writer.
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 kPrefetchScriptTagHtml[];
56
 
  static const char kPrefetchLinkTagHtml[];
57
 
  static const char kFlushEarlyStyleTemplate[];
58
 
 
59
 
  explicit FlushEarlyContentWriterFilter(RewriteDriver* driver);
60
 
 
61
 
  virtual void StartDocument();
62
 
  virtual void EndDocument();
63
 
 
64
 
  virtual void StartElement(HtmlElement* element);
65
 
  virtual void EndElement(HtmlElement* element);
66
 
 
67
 
  virtual void Characters(HtmlCharactersNode* characters_node);
68
 
 
69
 
 protected:
70
 
  virtual void Clear();
71
 
 
72
 
 private:
73
 
  // Writes the string to original_writer_.
74
 
  void WriteToOriginalWriter(const GoogleString& in);
75
 
 
76
 
  // Check whether resource can be flushed or not.
77
 
  bool IsFlushable(const GoogleUrl& gurl,
78
 
                   const FlushEarlyResourceInfo::ResourceType& resource_type);
79
 
 
80
 
  // Flush the resource using kPrefetchImageTagHtml.
81
 
  void FlushResourceAsImage(StringPiece url);
82
 
 
83
 
  // Flush the resource and update time_consumed_ms_ based on time_to_download.
84
 
  void FlushResources(
85
 
      StringPiece url,
86
 
      int64 time_to_download,
87
 
      bool is_pagespeed_resource,
88
 
      semantic_type::Category category);
89
 
 
90
 
  void FlushDeferJavascriptEarly();
91
 
  void UpdateStats(int64 time_to_download, bool is_pagespeed_resource);
92
 
  GoogleString ComputeFlushEarlyCriticalCss(const GoogleString& style_id);
93
 
 
94
 
  // Returns the type of resource based on the url.
95
 
  FlushEarlyResourceInfo::ResourceType GetResourceType(
96
 
      const GoogleUrl& gurl, bool is_pagespeed_resource);
97
 
 
98
 
  RewriteDriver* driver_;
99
 
  TimedVariable* num_resources_flushed_early_;
100
 
  // Whether we need to insert a close script tag at EndDocument.
101
 
  bool in_body_;
102
 
  bool insert_close_script_;
103
 
  int num_resources_flushed_;
104
 
  NullWriter null_writer_;
105
 
  Writer* original_writer_;
106
 
  HtmlElement* current_element_;
107
 
  UserAgentMatcher::PrefetchMechanism prefetch_mechanism_;
108
 
  scoped_ptr<StringSet> private_cacheable_resources_;
109
 
  scoped_ptr<StringSet> public_cacheable_resources_;
110
 
  int64 time_consumed_ms_;
111
 
  int64 max_available_time_ms_;
112
 
  typedef std::list<ResourceInfo*> ResourceInfoList;
113
 
  ResourceInfoList js_resources_info_;
114
 
  bool defer_javascript_enabled_;
115
 
  bool split_html_enabled_;
116
 
  bool is_flushing_critical_style_element_;
117
 
  GoogleString css_output_content_;
118
 
  GoogleString flush_early_content_;
119
 
  bool flush_more_resources_early_if_time_permits_;
120
 
  bool stylesheets_flushed_;
121
 
 
122
 
  DISALLOW_COPY_AND_ASSIGN(FlushEarlyContentWriterFilter);
123
 
};
124
 
 
125
 
}  // namespace net_instaweb
126
 
 
127
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_