Page Speed Optimization Libraries
1.7.30.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 const GoogleUrl& base_url, 00074 Css::Values* values, 00075 int value_index, 00076 CssFilter::Context* parent, 00077 Css::Declarations* decls, 00078 MessageHandler* handler); 00079 00081 OutputResourcePtr MakeOutput(); 00082 00084 void Reset(RewriteContext* context, const GoogleUrl& css_url, 00085 const StringPiece& css_text); 00086 00089 void RegisterOrReleaseContext(); 00090 00091 protected: 00092 virtual const UrlSegmentEncoder* encoder() const { return &encoder_; } 00093 virtual const char* Name() const { return "ImageCombine"; } 00094 virtual void StartDocumentImpl() {} 00095 virtual void StartElementImpl(HtmlElement* element) {} 00096 virtual void EndElementImpl(HtmlElement* element) {} 00097 00099 virtual const char* id() const { return RewriteOptions::kImageCombineId; } 00100 00101 private: 00102 class Combiner; 00103 class Context; 00104 00105 virtual RewriteContext* MakeRewriteContext(); 00106 Context* MakeNestedContext(RewriteContext* parent, const GoogleUrl& css_url, 00107 const StringPiece& css_text); 00108 bool GetDeclarationDimensions(Css::Declarations* declarations, 00109 int* width, int* height); 00110 void AddFilesReducedStat(int reduced); 00111 00112 Variable* image_file_count_reduction_; 00113 Context* context_; 00114 UrlMultipartEncoder encoder_; 00115 00116 DISALLOW_COPY_AND_ASSIGN(ImageCombineFilter); 00117 }; 00118 00119 } 00120 00121 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_COMBINE_FILTER_H_