Page Speed Optimization Libraries
1.2.24.1
|
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/public/string.h" 00024 00025 namespace net_instaweb { 00026 00027 class HtmlElement; 00028 class RewriteDriver; 00029 class RewriteOptions; 00030 class StaticJavascriptManager; 00031 class Statistics; 00032 00074 class LazyloadImagesFilter : public CommonFilter { 00075 public: 00076 static const char* kImageLazyloadCode; 00077 static const char* kBlankImageSrc; 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 bool ShouldApply(RewriteDriver* driver); 00093 static GoogleString GetLazyloadJsSnippet( 00094 const RewriteOptions* options, 00095 StaticJavascriptManager* static_js_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(const RewriteOptions* options); 00108 00110 void InsertLazyloadJsCode(HtmlElement* element); 00111 00114 void InsertOverrideAttributesScript(HtmlElement* element, 00115 bool is_before_script); 00116 00118 GoogleString blank_image_url_; 00121 HtmlElement* skip_rewrite_; 00123 bool main_script_inserted_; 00125 bool abort_rewrite_; 00128 bool abort_script_inserted_; 00131 int num_images_lazily_loaded_; 00132 }; 00133 00134 } 00135 00136 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_