2
* Copyright 2013 Google Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
// Authors: mmohabey@google.com (Megha Mohabey)
18
// rahulbansal@google.com (Rahul Bansal)
20
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_
21
#define NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_
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"
35
namespace net_instaweb {
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 {
45
explicit CacheHtmlFilter(RewriteDriver* rewrite_driver);
46
virtual ~CacheHtmlFilter();
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);
54
virtual const char* Name() const { return "CacheHtmlFilter"; }
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);
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_;
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_;
75
std::vector<int> num_children_stack_;
77
DISALLOW_COPY_AND_ASSIGN(CacheHtmlFilter);
80
} // namespace net_instaweb
82
#endif // NET_INSTAWEB_REWRITER_PUBLIC_CACHE_HTML_FILTER_H_