2
* Copyright 2011 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
// Author: nforman@google.com (Naomi Forman)
19
// This provides the MetaTagFilter class which converts meta tags in html with
22
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_META_TAG_FILTER_H_
23
#define NET_INSTAWEB_REWRITER_PUBLIC_META_TAG_FILTER_H_
25
#include "net/instaweb/rewriter/public/common_filter.h"
26
#include "net/instaweb/util/public/basictypes.h"
28
namespace net_instaweb {
31
class ResponseHeaders;
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
39
class MetaTagFilter : public CommonFilter {
41
explicit MetaTagFilter(RewriteDriver* rewrite_driver);
42
virtual ~MetaTagFilter();
44
static void InitStats(Statistics* stats);
46
virtual void StartDocumentImpl();
47
virtual void StartElementImpl(HtmlElement* element) {}
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);
59
virtual const char* Name() const { return "ConvertMetaTags"; }
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(
65
ResponseHeaders* response_headers);
68
ResponseHeaders* response_headers_;
70
// Stats on how many tags we moved.
71
Variable* converted_meta_tag_count_;
73
DISALLOW_COPY_AND_ASSIGN(MetaTagFilter);
76
} // namespace net_instaweb
78
#endif // NET_INSTAWEB_REWRITER_PUBLIC_META_TAG_FILTER_H_