Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
delay_images_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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 
70 
71 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DELAY_IMAGES_FILTER_H_
72 #define NET_INSTAWEB_REWRITER_PUBLIC_DELAY_IMAGES_FILTER_H_
73 
75 #include "pagespeed/kernel/base/basictypes.h"
76 #include "pagespeed/kernel/base/string_util.h"
77 
78 namespace net_instaweb {
79 
80 class HtmlElement;
81 class RewriteDriver;
82 class StaticAssetManager;
83 class Statistics;
84 
86  public:
87  static const char kDelayImagesSuffix[];
88  static const char kDelayImagesInlineSuffix[];
89  static const char kImageOnloadCode[];
90  static const char kImageOnloadJsSnippet[];
91 
92  explicit DelayImagesFilter(RewriteDriver* driver);
93  virtual ~DelayImagesFilter();
94 
95  virtual void StartDocumentImpl();
96  virtual void StartElementImpl(HtmlElement* element) { }
97  virtual void EndElementImpl(HtmlElement* element);
98 
99  virtual void EndDocument();
100 
101  virtual const char* Name() const { return "DelayImages"; }
102 
103  virtual void DetermineEnabled(GoogleString* disabled_reason);
104 
105  static void InitStats(Statistics* statistics);
106  static void Terminate();
107 
108  private:
111  void MaybeAddImageOnloadJsSnippet(HtmlElement* element);
112 
114  void InsertLowResImagesAndJs(HtmlElement* element, bool insert_after_element);
115 
117  void InsertHighResJs(HtmlElement* element);
118 
121  bool ShouldRewriteInplace() const;
122 
123  RewriteDriver* driver_;
124  StaticAssetManager* static_asset_manager_;
125 
126  int num_low_res_inlined_images_;
127  StringStringMap low_res_data_map_;
128 
132  bool insert_low_res_images_inplace_;
133 
138  bool lazyload_highres_images_;
139 
140  bool is_script_inserted_;
141 
142  bool added_image_onload_js_;
143 
144  DISALLOW_COPY_AND_ASSIGN(DelayImagesFilter);
145 };
146 
147 }
148 
149 #endif
Definition: common_filter.h:48
Definition: static_asset_manager.h:44
Definition: rewrite_driver.h:98
Definition: delay_images_filter.h:85