Page Speed Optimization Libraries  1.7.30.1
net/instaweb/rewriter/public/lazyload_images_filter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_
00021 
00022 #include "net/instaweb/rewriter/public/common_filter.h"
00023 #include "net/instaweb/util/enums.pb.h"
00024 #include "net/instaweb/util/public/string.h"
00025 
00026 namespace net_instaweb {
00027 
00028 class HtmlElement;
00029 class RewriteDriver;
00030 class RewriteOptions;
00031 class StaticAssetManager;
00032 class Statistics;
00033 
00075 class LazyloadImagesFilter : public CommonFilter {
00076  public:
00077   static const char* kImageLazyloadCode;
00078   static const char* kImageOnloadCode;
00079   static const char* kLoadAllImages;
00080   static const char* kOverrideAttributeFunctions;
00081   static const char* kIsLazyloadScriptInsertedPropertyName;
00082 
00083   explicit LazyloadImagesFilter(RewriteDriver* driver);
00084   virtual ~LazyloadImagesFilter();
00085 
00086   virtual const char* Name() const { return "Lazyload Images"; }
00087 
00088   static void InitStats(Statistics* statistics);
00089   static void Terminate();
00090 
00092   static RewriterHtmlApplication::Status ShouldApply(RewriteDriver* driver);
00093   static GoogleString GetLazyloadJsSnippet(
00094       const RewriteOptions* options,
00095       StaticAssetManager* static_asset_manager);
00096 
00097  private:
00098   virtual void StartDocumentImpl();
00099   virtual void EndDocument();
00100   virtual void StartElementImpl(HtmlElement* element);
00101   virtual void EndElementImpl(HtmlElement* element);
00102   virtual void DetermineEnabled();
00103 
00105   void Clear();
00106 
00107   static GoogleString GetBlankImageSrc(
00108       const RewriteOptions* options,
00109       const StaticAssetManager* static_asset_manager);
00110 
00112   void InsertLazyloadJsCode(HtmlElement* element);
00113 
00116   void InsertOverrideAttributesScript(HtmlElement* element,
00117                                       bool is_before_script);
00118 
00120   GoogleString blank_image_url_;
00123   HtmlElement* skip_rewrite_;
00125   bool main_script_inserted_;
00127   bool abort_rewrite_;
00130   bool abort_script_inserted_;
00133   int num_images_lazily_loaded_;
00134 };
00135 
00136 }  
00137 
00138 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines