Page Speed Optimization Libraries  1.13.35.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 
28 #include "pagespeed/opt/logging/enums.pb.h"
29 
30 namespace net_instaweb {
31 
32 class StaticAssetManager;
33 class Statistics;
34 
77  public:
78  static const char* kImageLazyloadCode;
79  static const char* kImageOnloadCode;
80  static const char* kLoadAllImages;
81  static const char* kOverrideAttributeFunctions;
82  static const char* kIsLazyloadScriptInsertedPropertyName;
83 
84  explicit LazyloadImagesFilter(RewriteDriver* driver);
85  virtual ~LazyloadImagesFilter();
86 
87  virtual const char* Name() const { return "Lazyload Images"; }
88  ScriptUsage GetScriptUsage() const override { return kWillInjectScripts; }
89 
90  static void InitStats(Statistics* statistics);
91  static void Terminate();
92 
94  static RewriterHtmlApplication::Status ShouldApply(RewriteDriver* driver);
95  static GoogleString GetLazyloadJsSnippet(
96  const RewriteOptions* options,
97  StaticAssetManager* static_asset_manager);
98 
99  private:
100  virtual void StartDocumentImpl();
101  virtual void EndDocument();
102  virtual void StartElementImpl(HtmlElement* element);
103  virtual void EndElementImpl(HtmlElement* element);
104  virtual void DetermineEnabled(GoogleString* disabled_reason);
105 
107  void Clear();
108 
109  static GoogleString GetBlankImageSrc(
110  const RewriteOptions* options,
111  const StaticAssetManager* static_asset_manager);
112 
114  void InsertLazyloadJsCode(HtmlElement* element);
115 
118  void InsertOverrideAttributesScript(HtmlElement* element,
119  bool is_before_script);
120 
122  GoogleString blank_image_url_;
125  HtmlElement* skip_rewrite_;
127  HtmlElement* head_element_;
129  bool main_script_inserted_;
131  bool abort_rewrite_;
134  bool abort_script_inserted_;
137  int num_images_lazily_loaded_;
138 };
139 
140 }
141 
142 #endif
Definition: common_filter.h:47
Definition: static_asset_manager.h:48
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Definition: html_element.h:42
ScriptUsage GetScriptUsage() const override
Definition: lazyload_images_filter.h:88
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
Definition: rewrite_driver.h:100
Definition: lazyload_images_filter.h:76
Definition: rewrite_options.h:84
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: lazyload_images_filter.h:87
static RewriterHtmlApplication::Status ShouldApply(RewriteDriver *driver)
Lazyload filter will be no op for the request if ShouldApply returns false.