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 00070 00071 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DELAY_IMAGES_FILTER_H_ 00072 #define NET_INSTAWEB_REWRITER_PUBLIC_DELAY_IMAGES_FILTER_H_ 00073 00074 #include "net/instaweb/htmlparse/public/empty_html_filter.h" 00075 #include "net/instaweb/rewriter/public/resource_tag_scanner.h" 00076 #include "net/instaweb/util/public/basictypes.h" 00077 #include "net/instaweb/util/public/string_util.h" 00078 00079 namespace net_instaweb { 00080 00081 class HtmlElement; 00082 class ImageTagScanner; 00083 class RewriteDriver; 00084 class StaticJavascriptManager; 00085 class Statistics; 00086 00087 class DelayImagesFilter : public EmptyHtmlFilter { 00088 public: 00089 static const char kDelayImagesSuffix[]; 00090 00091 static const char kDelayImagesInlineSuffix[]; 00092 00093 explicit DelayImagesFilter(RewriteDriver* driver); 00094 virtual ~DelayImagesFilter(); 00095 00096 virtual void StartDocument(); 00097 virtual void EndDocument(); 00098 virtual void EndElement(HtmlElement* element); 00099 00100 virtual const char* Name() const { return "DelayImages"; } 00101 00102 static void Initialize(Statistics* statistics); 00103 static void Terminate(); 00104 00105 private: 00108 void InsertDelayImagesJS(HtmlElement* element); 00109 00112 void InsertDelayImagesInlineJS(HtmlElement* element); 00113 00114 RewriteDriver* driver_; 00115 StaticJavascriptManager* static_js_manager_; 00116 scoped_ptr<const ImageTagScanner> tag_scanner_; 00117 00121 bool low_res_map_inserted_; 00122 int num_low_res_inlined_images_; 00123 StringStringMap low_res_data_map_; 00124 00128 bool insert_low_res_images_inplace_; 00129 00130 DISALLOW_COPY_AND_ASSIGN(DelayImagesFilter); 00131 }; 00132 00133 } 00134 00135 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_DELAY_IMAGES_FILTER_H_