Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
image_combine_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_COMBINE_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_COMBINE_FILTER_H_
21 
29 
30 namespace Css {
31 
32 class Declarations;
33 class Values;
34 
35 }
36 
37 namespace net_instaweb {
38 
39 class GoogleUrl;
40 class HtmlElement;
41 class MessageHandler;
42 class RewriteContext;
43 class RewriteDriver;
44 class Statistics;
45 class UrlSegmentEncoder;
46 class Variable;
47 
48 /*
49  * The ImageCombineFilter combines multiple images into a single image
50  * (a process called "spriting". This reduces the total number of
51  * round-trips, and reduces bytes downloaded by consolidating image
52  * headers and improving compression.
53  *
54  * Right now this is only used on CSS background-images, so it doesn't
55  * need to be in the HTML filter chain. In the future it will rewrite
56  * img tags as well.
57  */
59  public:
60  explicit ImageCombineFilter(RewriteDriver* rewrite_driver);
61  virtual ~ImageCombineFilter();
62 
63  static void InitStats(Statistics* statistics);
64 
75  bool AddCssBackgroundContext(const GoogleUrl& original_url,
76  const GoogleUrl& base_url,
77  Css::Values* values,
78  int value_index,
79  CssFilter::Context* parent,
80  Css::Declarations* decls,
81  bool* is_authorized,
82  MessageHandler* handler);
83 
86 
88  void Reset(RewriteContext* context, const GoogleUrl& css_url,
89  const StringPiece& css_text);
90 
94 
95  protected:
96  virtual const UrlSegmentEncoder* encoder() const { return &encoder_; }
97  virtual const char* Name() const { return "ImageCombine"; }
98  virtual void StartDocumentImpl() {}
99  virtual void StartElementImpl(HtmlElement* element) {}
100  virtual void EndElementImpl(HtmlElement* element) {}
101 
103  virtual const char* id() const { return RewriteOptions::kImageCombineId; }
104 
105  private:
106  class Combiner;
107  class Context;
108 
109  virtual RewriteContext* MakeRewriteContext();
110  Context* MakeNestedContext(RewriteContext* parent, const GoogleUrl& css_url,
111  const StringPiece& css_text);
112  bool GetDeclarationDimensions(Css::Declarations* declarations,
113  int* width, int* height);
114  void AddFilesReducedStat(int reduced);
115 
116  Variable* image_file_count_reduction_;
117  Context* context_;
118  UrlMultipartEncoder encoder_;
119 
120 
121 };
122 
123 }
124 
125 #endif
class GoogleUrl
Definition: google_url.h:58
void Reset(RewriteContext *context, const GoogleUrl &css_url, const StringPiece &css_text)
Creates a new context for doing spriting, but does not register it.
Context used by CssFilter under async flow.
Definition: css_filter.h:251
Definition: url_multipart_encoder.h:45
virtual const char * id() const
Image rewriting was originally, but is no longer, a single CSS.
Definition: image_combine_filter.h:103
virtual void StartDocumentImpl()
Definition: image_combine_filter.h:98
bool AddCssBackgroundContext(const GoogleUrl &original_url, const GoogleUrl &base_url, Css::Values *values, int value_index, CssFilter::Context *parent, Css::Declarations *decls, bool *is_authorized, MessageHandler *handler)
Definition: statistics.h:43
virtual const UrlSegmentEncoder * encoder() const
Definition: image_combine_filter.h:96
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Definition: html_element.h:42
Definition: rewrite_filter.h:35
Definition: rewrite_driver.h:100
OutputResourcePtr MakeOutput()
Create the combination with the current combiner.
Definition: rewrite_context.h:155
Definition: url_segment_encoder.h:33
Definition: message_handler.h:39
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: image_combine_filter.h:97
Definition: image_combine_filter.h:58
const GoogleUrl & base_url() const
Getters.