Page Speed Optimization Libraries  1.13.35.1
 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 
29 
30 namespace net_instaweb {
31 
32 class Statistics;
33 class Variable;
34 
35 /*
36  * The Dedup Inlined Images filter replaces the second & subsequent occurences
37  * a repeated inlined image (data:image/... URL) with JavaScript that loads
38  * the image from the first occurence. This requires the first occurence to be
39  * tagged with a unique id; if it already has an id then that's used instead.
40  */
42  public:
43  static const unsigned int kMinimumImageCutoff;
44 
45  static const char kDiiInitializer[];
46 
48  static const char kCandidatesFound[];
49  static const char kCandidatesReplaced[];
50 
51  explicit DedupInlinedImagesFilter(RewriteDriver* driver);
52  virtual ~DedupInlinedImagesFilter();
53 
55  static void InitStats(Statistics* statistics);
56 
57  virtual void StartDocumentImpl();
58  virtual void EndDocument();
59  virtual void StartElementImpl(HtmlElement* element);
60  virtual void EndElementImpl(HtmlElement* element);
61  virtual void DetermineEnabled(GoogleString* disabled_reason);
62 
63  virtual const char* Name() const { return "DedupInlinedImages"; }
64  ScriptUsage GetScriptUsage() const override { return kWillInjectScripts; }
65 
66  private:
67  bool IsDedupCandidate(HtmlElement* element, StringPiece* src_iff_true);
68  void InsertOurScriptElement(HtmlElement* before);
69 
70  bool script_inserted_;
71  StringStringMap hash_to_id_map_;
72  int snippet_id_;
73 
75  Variable* num_dedup_inlined_images_candidates_found_;
77  Variable* num_dedup_inlined_images_candidates_replaced_;
78 
79 
80 };
81 
82 }
83 
84 #endif
virtual void DetermineEnabled(GoogleString *disabled_reason)
Definition: common_filter.h:47
Definition: statistics.h:43
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
static const char kDiiInitializer[]
public for the test harness only.
Definition: dedup_inlined_images_filter.h:45
Definition: html_element.h:42
static const char kCandidatesFound[]
Statistics' names.
Definition: dedup_inlined_images_filter.h:48
static void InitStats(Statistics *statistics)
May be called multiple times, if there are multiple statistics objects.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
ScriptUsage GetScriptUsage() const override
Definition: dedup_inlined_images_filter.h:64
static const char kCandidatesReplaced[]
No. of those replaced with JS.
Definition: dedup_inlined_images_filter.h:49
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
static const unsigned int kMinimumImageCutoff
Dont dedup if smaller.
Definition: dedup_inlined_images_filter.h:43
Definition: rewrite_driver.h:100
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: dedup_inlined_images_filter.h:63
Definition: dedup_inlined_images_filter.h:41