Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dedup_inlined_images_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 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_DEDUP_INLINED_IMAGES_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_DEDUP_INLINED_IMAGES_FILTER_H_
21 
23 #include "pagespeed/kernel/base/basictypes.h"
24 #include "pagespeed/kernel/base/string_util.h"
25 
26 namespace net_instaweb {
27 
28 class HtmlElement;
29 class RewriteDriver;
30 class Statistics;
31 class Variable;
32 
33 /*
34  * The Dedup Inlined Images filter replaces the second & subsequent occurences
35  * a repeated inlined image (data:image/... URL) with JavaScript that loads
36  * the image from the first occurence. This requires the first occurence to be
37  * tagged with a unique id; if it already has an id then that's used instead.
38  */
40  public:
41  static const unsigned int kMinimumImageCutoff;
42 
43  static const char kDiiInitializer[];
44 
46  static const char kCandidatesFound[];
47  static const char kCandidatesReplaced[];
48 
49  explicit DedupInlinedImagesFilter(RewriteDriver* driver);
50  virtual ~DedupInlinedImagesFilter();
51 
53  static void InitStats(Statistics* statistics);
54 
55  virtual void StartDocumentImpl();
56  virtual void EndDocument();
57  virtual void StartElementImpl(HtmlElement* element);
58  virtual void EndElementImpl(HtmlElement* element);
59  virtual void DetermineEnabled(GoogleString* disabled_reason);
60 
61  virtual const char* Name() const { return "DedupInlinedImages"; }
62 
63  private:
64  bool IsDedupCandidate(HtmlElement* element, StringPiece* src_iff_true);
65  void InsertOurScriptElement(HtmlElement* before);
66 
67  bool script_inserted_;
68  StringStringMap hash_to_id_map_;
69  int snippet_id_;
70 
72  Variable* num_dedup_inlined_images_candidates_found_;
74  Variable* num_dedup_inlined_images_candidates_replaced_;
75 
76  DISALLOW_COPY_AND_ASSIGN(DedupInlinedImagesFilter);
77 };
78 
79 }
80 
81 #endif
Definition: common_filter.h:48
static const char kDiiInitializer[]
public for the test harness only.
Definition: dedup_inlined_images_filter.h:43
static const char kCandidatesFound[]
Statistics' names.
Definition: dedup_inlined_images_filter.h:46
static void InitStats(Statistics *statistics)
May be called multiple times, if there are multiple statistics objects.
static const char kCandidatesReplaced[]
No. of those replaced with JS.
Definition: dedup_inlined_images_filter.h:47
static const unsigned int kMinimumImageCutoff
Dont dedup if smaller.
Definition: dedup_inlined_images_filter.h:41
Definition: rewrite_driver.h:98
Definition: dedup_inlined_images_filter.h:39