~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/meta_tag_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 2011 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: nforman@google.com (Naomi Forman)
18
 
//
19
 
// This provides the MetaTagFilter class which converts meta tags in html with
20
 
// response headers.
21
 
 
22
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_META_TAG_FILTER_H_
23
 
#define NET_INSTAWEB_REWRITER_PUBLIC_META_TAG_FILTER_H_
24
 
 
25
 
#include "net/instaweb/rewriter/public/common_filter.h"
26
 
#include "net/instaweb/util/public/basictypes.h"
27
 
 
28
 
namespace net_instaweb {
29
 
 
30
 
class HtmlElement;
31
 
class ResponseHeaders;
32
 
class RewriteDriver;
33
 
class Statistics;
34
 
class Variable;
35
 
 
36
 
// This class is the implementation of convert_meta_tags filter, which removes
37
 
// meta tags from the html and replaces them with a corresponding
38
 
// response header.
39
 
class MetaTagFilter : public CommonFilter {
40
 
 public:
41
 
  explicit MetaTagFilter(RewriteDriver* rewrite_driver);
42
 
  virtual ~MetaTagFilter();
43
 
 
44
 
  static void InitStats(Statistics* stats);
45
 
 
46
 
  virtual void StartDocumentImpl();
47
 
  virtual void StartElementImpl(HtmlElement* element) {}
48
 
 
49
 
  // Rewrite tags in the following form:
50
 
  // <meta http-equiv="Content-Type" content="text/html" >
51
 
  // into response headers.
52
 
  // In theory we could delete the tag, but since it is somewhat
53
 
  // "dangerous" to mutate the html (in case a script is looking for something),
54
 
  // we leave the tag in there.  As long as the tags and the headers match,
55
 
  // there should not be a performance hit.
56
 
  virtual void EndElementImpl(HtmlElement* element);
57
 
  virtual void Flush();
58
 
 
59
 
  virtual const char* Name() const { return "ConvertMetaTags"; }
60
 
 
61
 
  // Utility function to extract the mime type and/or charset from a meta tag
62
 
  // and update the response_headers if they are not set already.
63
 
  static bool ExtractAndUpdateMetaTagDetails(
64
 
      HtmlElement* element,
65
 
      ResponseHeaders* response_headers);
66
 
 
67
 
 private:
68
 
  ResponseHeaders* response_headers_;
69
 
 
70
 
  // Stats on how many tags we moved.
71
 
  Variable* converted_meta_tag_count_;
72
 
 
73
 
  DISALLOW_COPY_AND_ASSIGN(MetaTagFilter);
74
 
};
75
 
 
76
 
}  // namespace net_instaweb
77
 
 
78
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_META_TAG_FILTER_H_