Page Speed Optimization Libraries
1.4.26.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_IMAGE_COMBINE_FILTER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_COMBINE_FILTER_H_ 00021 00022 #include "net/instaweb/rewriter/public/css_filter.h" 00023 #include "net/instaweb/rewriter/public/server_context.h" 00024 #include "net/instaweb/rewriter/public/rewrite_filter.h" 00025 #include "net/instaweb/rewriter/public/rewrite_options.h" 00026 #include "net/instaweb/util/public/basictypes.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 #include "net/instaweb/util/public/url_multipart_encoder.h" 00029 00030 namespace Css { 00031 00032 class Declarations; 00033 class Values; 00034 00035 } 00036 00037 namespace net_instaweb { 00038 00039 class GoogleUrl; 00040 class HtmlElement; 00041 class MessageHandler; 00042 class RewriteContext; 00043 class RewriteDriver; 00044 class Statistics; 00045 class UrlSegmentEncoder; 00046 class Variable; 00047 00048 /* 00049 * The ImageCombineFilter combines multiple images into a single image 00050 * (a process called "spriting". This reduces the total number of 00051 * round-trips, and reduces bytes downloaded by consolidating image 00052 * headers and improving compression. 00053 * 00054 * Right now this is only used on CSS background-images, so it doesn't 00055 * need to be in the HTML filter chain. In the future it will rewrite 00056 * img tags as well. 00057 */ 00058 class ImageCombineFilter : public RewriteFilter { 00059 public: 00060 explicit ImageCombineFilter(RewriteDriver* rewrite_driver); 00061 virtual ~ImageCombineFilter(); 00062 00063 static void InitStats(Statistics* statistics); 00064 00072 void AddCssBackgroundContext(const GoogleUrl& original_url, 00073 Css::Values* values, 00074 int value_index, 00075 CssFilter::Context* parent, 00076 Css::Declarations* decls, 00077 MessageHandler* handler); 00078 00080 OutputResourcePtr MakeOutput(); 00081 00083 void Reset(RewriteContext* context, const GoogleUrl& css_url, 00084 const StringPiece& css_text); 00085 00088 void RegisterOrReleaseContext(); 00089 00090 protected: 00091 virtual const UrlSegmentEncoder* encoder() const { return &encoder_; } 00092 virtual const char* Name() const { return "ImageCombine"; } 00093 virtual void StartDocumentImpl() {} 00094 virtual void StartElementImpl(HtmlElement* element) {} 00095 virtual void EndElementImpl(HtmlElement* element) {} 00096 00098 virtual const char* id() const { return RewriteOptions::kImageCombineId; } 00099 00100 private: 00101 class Combiner; 00102 class Context; 00103 00104 virtual RewriteContext* MakeRewriteContext(); 00105 Context* MakeNestedContext(RewriteContext* parent, const GoogleUrl& css_url, 00106 const StringPiece& css_text); 00107 bool GetDeclarationDimensions(Css::Declarations* declarations, 00108 int* width, int* height); 00109 void AddFilesReducedStat(int reduced); 00110 00111 Variable* image_file_count_reduction_; 00112 Context* context_; 00113 UrlMultipartEncoder encoder_; 00114 00115 DISALLOW_COPY_AND_ASSIGN(ImageCombineFilter); 00116 }; 00117 00118 } 00119 00120 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_COMBINE_FILTER_H_