Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lazyload_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 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_
21 
23 #include "net/instaweb/util/enums.pb.h"
25 
26 namespace net_instaweb {
27 
28 class HtmlElement;
29 class RewriteDriver;
30 class RewriteOptions;
31 class StaticAssetManager;
32 class Statistics;
33 
76  public:
77  static const char* kImageLazyloadCode;
78  static const char* kImageOnloadCode;
79  static const char* kLoadAllImages;
80  static const char* kOverrideAttributeFunctions;
81  static const char* kIsLazyloadScriptInsertedPropertyName;
82 
83  explicit LazyloadImagesFilter(RewriteDriver* driver);
84  virtual ~LazyloadImagesFilter();
85 
86  virtual const char* Name() const { return "Lazyload Images"; }
87 
88  static void InitStats(Statistics* statistics);
89  static void Terminate();
90 
92  static RewriterHtmlApplication::Status ShouldApply(RewriteDriver* driver);
93  static GoogleString GetLazyloadJsSnippet(
94  const RewriteOptions* options,
95  StaticAssetManager* static_asset_manager);
96 
97  private:
98  virtual void StartDocumentImpl();
99  virtual void EndDocument();
100  virtual void StartElementImpl(HtmlElement* element);
101  virtual void EndElementImpl(HtmlElement* element);
102  virtual void DetermineEnabled(GoogleString* disabled_reason);
103 
105  void Clear();
106 
107  static GoogleString GetBlankImageSrc(
108  const RewriteOptions* options,
109  const StaticAssetManager* static_asset_manager);
110 
112  void InsertLazyloadJsCode(HtmlElement* element);
113 
116  void InsertOverrideAttributesScript(HtmlElement* element,
117  bool is_before_script);
118 
120  GoogleString blank_image_url_;
123  HtmlElement* skip_rewrite_;
125  bool main_script_inserted_;
127  bool abort_rewrite_;
130  bool abort_script_inserted_;
133  int num_images_lazily_loaded_;
134 };
135 
136 }
137 
138 #endif
Definition: common_filter.h:48
Definition: static_asset_manager.h:44
Definition: rewrite_driver.h:98
Definition: lazyload_images_filter.h:75
Definition: rewrite_options.h:81
static RewriterHtmlApplication::Status ShouldApply(RewriteDriver *driver)
Lazyload filter will be no op for the request if ShouldApply returns false.