~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/insert_dns_prefetch_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 2012 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
 
// Author: bharathbhushan@google.com (Bharath Bhushan)
17
 
 
18
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_INSERT_DNS_PREFETCH_FILTER_H_
19
 
#define NET_INSTAWEB_REWRITER_PUBLIC_INSERT_DNS_PREFETCH_FILTER_H_
20
 
 
21
 
#include "net/instaweb/htmlparse/public/html_element.h"
22
 
#include "net/instaweb/rewriter/public/common_filter.h"
23
 
#include "net/instaweb/util/public/basictypes.h"
24
 
#include "net/instaweb/util/public/string_util.h"  // for StringSet, etc
25
 
 
26
 
namespace net_instaweb {
27
 
 
28
 
class FlushEarlyInfo;
29
 
class RewriteDriver;
30
 
 
31
 
// Injects <link rel="dns-prefetch" href="//www.example.com"> tags in the HEAD
32
 
// to enable the browser to do DNS prefetching.
33
 
class InsertDnsPrefetchFilter : public CommonFilter {
34
 
 public:
35
 
  explicit InsertDnsPrefetchFilter(RewriteDriver* driver);
36
 
  virtual ~InsertDnsPrefetchFilter();
37
 
 
38
 
  virtual void StartDocumentImpl();
39
 
  virtual void EndDocument();
40
 
  virtual void StartElementImpl(HtmlElement* element);
41
 
  virtual void EndElementImpl(HtmlElement* element);
42
 
 
43
 
  virtual const char* Name() const { return "InsertDnsPrefetchFilter"; }
44
 
  // Override DetermineEnabled to enable writing of the property cache DOM
45
 
  // cohort in the RewriteDriver.
46
 
  virtual void DetermineEnabled(GoogleString* disabled_reason);
47
 
  virtual const char* id() const { return "idp"; }
48
 
 
49
 
 private:
50
 
  void Clear();
51
 
 
52
 
  // Add a domain found in the page to the list of domains for which DNS
53
 
  // prefetch tags can be inserted.
54
 
  void MarkAlreadyInHead(HtmlElement::Attribute* urlattr);
55
 
 
56
 
  // Returns true if the list of domains for DNS prefetch tags is "stable".
57
 
  // Refer to the implementation for details about stability. This filter will
58
 
  // insert the tags into the HEAD once the list is stable.
59
 
  bool IsDomainListStable(const FlushEarlyInfo& flush_early_info) const;
60
 
  void DebugPrint(const char* msg);
61
 
 
62
 
  // This flag is useful if multiple HEADs are present. This filter inserts the
63
 
  // DNS prefetch tags only in the first HEAD.
64
 
  bool dns_prefetch_inserted_;
65
 
 
66
 
  // This flag indicates if we are currently processing elements in HEAD.
67
 
  bool in_head_;
68
 
 
69
 
  // The set of domains that we should not insert DNS prefetch tags for. This
70
 
  // includes the current domain we are rewriting, and resource links in HEAD.
71
 
  StringSet domains_to_ignore_;
72
 
 
73
 
  // The set of domains seen in resource links in BODY and not already seen in
74
 
  // HEAD.
75
 
  StringSet domains_in_body_;
76
 
 
77
 
  // The list of domains for which DNS prefetch tags can be inserted, in the
78
 
  // order they were seen in BODY.
79
 
  StringVector dns_prefetch_domains_;
80
 
 
81
 
  // Whether this user agent supports dns prefetch filter.
82
 
  bool user_agent_supports_dns_prefetch_;
83
 
 
84
 
  DISALLOW_COPY_AND_ASSIGN(InsertDnsPrefetchFilter);
85
 
};
86
 
 
87
 
}  // namespace net_instaweb
88
 
 
89
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_INSERT_DNS_PREFETCH_FILTER_H_