~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/cache_html_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
 
// Authors: mmohabey@google.com (Megha Mohabey)
18
 
//          rahulbansal@google.com (Rahul Bansal)
19
 
 
20
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_
21
 
#define NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_
22
 
 
23
 
#include <vector>
24
 
 
25
 
#include "net/instaweb/htmlparse/public/html_writer_filter.h"
26
 
#include "net/instaweb/rewriter/cache_html_info.pb.h"
27
 
#include "net/instaweb/rewriter/public/blink_util.h"
28
 
#include "net/instaweb/util/public/basictypes.h"
29
 
#include "net/instaweb/util/public/property_cache.h"
30
 
#include "net/instaweb/util/public/string.h"
31
 
#include "net/instaweb/util/public/string_util.h"
32
 
#include "net/instaweb/util/public/string_writer.h"
33
 
#include "net/instaweb/util/public/json.h"
34
 
 
35
 
namespace net_instaweb {
36
 
 
37
 
class HtmlElement;
38
 
class RewriteDriver;
39
 
class RewriteOptions;
40
 
 
41
 
// This class extracts the non cacheable panels and sends it to the client.
42
 
// TODO(mmohabey): Integrate with SplitFilter and send non critical JSON too.
43
 
class CacheHtmlFilter : public HtmlWriterFilter {
44
 
 public:
45
 
  explicit CacheHtmlFilter(RewriteDriver* rewrite_driver);
46
 
  virtual ~CacheHtmlFilter();
47
 
 
48
 
  virtual void StartDocument();
49
 
  virtual void StartElement(HtmlElement* element);
50
 
  virtual void EndElement(HtmlElement* element);
51
 
  virtual void EndDocument();
52
 
  void WriteString(StringPiece str);
53
 
  virtual void Flush();
54
 
  virtual const char* Name() const { return "CacheHtmlFilter"; }
55
 
 
56
 
 private:
57
 
  void SendCookies();
58
 
  void SendNonCacheableObject(const Json::Value& json);
59
 
  // Produces a custom xpath relative to the body or relative to the nearest
60
 
  // ancestor with an id (if there is one). Xpath comprises of the tag name
61
 
  // and the id (if it exists) or the position of the elements.
62
 
  GoogleString GetXpathOfCurrentElement(HtmlElement* element);
63
 
 
64
 
  RewriteDriver* rewrite_driver_;  // We do not own this.
65
 
  const RewriteOptions* rewrite_options_;  // We do not own this.
66
 
  AttributesToNonCacheableValuesMap attribute_non_cacheable_values_map_;
67
 
  std::vector<int> panel_number_num_instances_;
68
 
  GoogleString buffer_;
69
 
  StringWriter string_writer_;
70
 
  const HtmlElement* current_non_cacheable_element_;  // We do not own this.
71
 
  GoogleString current_panel_id_;
72
 
  const PropertyCache::Cohort* cohort_;  // We do not own this.
73
 
  CacheHtmlInfo cache_html_info_;
74
 
  bool abort_filter_;
75
 
  std::vector<int> num_children_stack_;
76
 
 
77
 
  DISALLOW_COPY_AND_ASSIGN(CacheHtmlFilter);
78
 
};
79
 
 
80
 
}  // namespace net_instaweb
81
 
 
82
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_