~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/critical_images_beacon_filter.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
// Author: jud@google.com (Jud Porter)
18
 
 
19
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_IMAGES_BEACON_FILTER_H_
20
 
#define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_IMAGES_BEACON_FILTER_H_
21
 
 
22
 
#include "net/instaweb/rewriter/public/common_filter.h"
23
 
#include "net/instaweb/rewriter/public/critical_finder_support_util.h"
24
 
#include "net/instaweb/util/public/basictypes.h"
25
 
#include "pagespeed/kernel/base/string_util.h"
26
 
 
27
 
namespace net_instaweb {
28
 
 
29
 
class HtmlElement;
30
 
class RewriteDriver;
31
 
class Statistics;
32
 
class Variable;
33
 
 
34
 
// Inject javascript for detecting above the fold images after the page has
35
 
// loaded. Also adds pagespeed_url_hash attributes that the beacon sends
36
 
// back to the server. This allows the beacon to work despite image URL
37
 
// rewriting or inlining.
38
 
class CriticalImagesBeaconFilter : public CommonFilter {
39
 
 public:
40
 
  static const char* kImageOnloadCode;
41
 
  // Counters.
42
 
  static const char kCriticalImagesBeaconAddedCount[];
43
 
 
44
 
  explicit CriticalImagesBeaconFilter(RewriteDriver* driver);
45
 
  virtual ~CriticalImagesBeaconFilter();
46
 
 
47
 
  virtual void DetermineEnabled(GoogleString* disabled_reason);
48
 
 
49
 
  static void InitStats(Statistics* statistics);
50
 
 
51
 
  virtual void StartDocumentImpl() { }
52
 
  virtual void EndDocument();
53
 
  virtual void StartElementImpl(HtmlElement* element) { }
54
 
  virtual void EndElementImpl(HtmlElement* element);
55
 
  virtual const char* Name() const { return "CriticalImagesBeacon"; }
56
 
 
57
 
  // Returns true if this filter is going to inject a beacon. Filters that need
58
 
  // to disabled when beaconing run, like the rendered_image_dimensions filter,
59
 
  // can check this function.
60
 
  static bool ShouldApply(RewriteDriver* rewrite_driver);
61
 
 
62
 
 private:
63
 
  // Clear all state associated with filter.
64
 
  void Clear();
65
 
 
66
 
  // Adds the beaconing javascript just before the current element if it has
67
 
  // not already been added and insert_beacon_js_ is true.
68
 
  void MaybeAddBeaconJavascript(HtmlElement* element);
69
 
 
70
 
  BeaconMetadata beacon_metadata_;
71
 
  StringSet image_url_hashes_;
72
 
  bool insert_beacon_js_;
73
 
  // The total number of times the beacon is added.
74
 
  Variable* critical_images_beacon_added_count_;
75
 
 
76
 
  bool added_beacon_js_;
77
 
 
78
 
  DISALLOW_COPY_AND_ASSIGN(CriticalImagesBeaconFilter);
79
 
};
80
 
 
81
 
}  // namespace net_instaweb
82
 
 
83
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_IMAGES_BEACON_FILTER_H_