~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/url_left_trim_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 2010 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: jmaessen@google.com (Jan Maessen)
18
 
 
19
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_URL_LEFT_TRIM_FILTER_H_
20
 
#define NET_INSTAWEB_REWRITER_PUBLIC_URL_LEFT_TRIM_FILTER_H_
21
 
 
22
 
#include "net/instaweb/htmlparse/public/html_element.h"
23
 
#include "net/instaweb/rewriter/public/common_filter.h"
24
 
#include "net/instaweb/util/public/basictypes.h"
25
 
#include "net/instaweb/util/public/string.h"
26
 
#include "net/instaweb/util/public/string_util.h"
27
 
 
28
 
namespace net_instaweb {
29
 
class GoogleUrl;
30
 
class MessageHandler;
31
 
class RewriteDriver;
32
 
class Statistics;
33
 
class Variable;
34
 
 
35
 
// Filter that trims redundant information from the left end of each url.
36
 
//
37
 
// For example: if the page's base URL is http://www.example.com/foo/bar.html
38
 
// then the following URLs can be trimmed:
39
 
//   http://www.example.com/foo/bar/other.html -> bar/other.html
40
 
//   http://www.example.com/another.html -> /another.html
41
 
//   http://www.example.org/index.html -> //www.example.org/index.html
42
 
//
43
 
// TODO(jmaessen): Do we care to introduce ../ in order to relativize more urls?
44
 
// For example, if base URL is http://www.example.com/foo/bar/index.html
45
 
// we could convert: http://www.example.com/foo/other.html -> ../other.html
46
 
// rather than -> /foo/other.html.
47
 
class UrlLeftTrimFilter : public CommonFilter {
48
 
 public:
49
 
  UrlLeftTrimFilter(RewriteDriver* rewrite_driver, Statistics* stats);
50
 
  virtual ~UrlLeftTrimFilter();
51
 
 
52
 
  static void InitStats(Statistics* statistics);
53
 
  virtual void StartDocumentImpl() {}
54
 
  virtual void StartElementImpl(HtmlElement* element);
55
 
  virtual void EndElementImpl(HtmlElement* element) {}
56
 
 
57
 
  virtual const char* Name() const { return "UrlLeftTrim"; }
58
 
 
59
 
  // Trim 'url_to_trim' relative to 'base_url' returning the result in
60
 
  // 'trimmed_url'. Returns true if we succeeded at trimming the URL.
61
 
  //
62
 
  // This is static and requires the base_url explicitly, so that it can be
63
 
  // called from other places (like the CSS filter).
64
 
  static bool Trim(const GoogleUrl& base_url, const StringPiece& url_to_trim,
65
 
                   GoogleString* trimmed_url, MessageHandler* handler);
66
 
 
67
 
 private:
68
 
  void TrimAttribute(HtmlElement::Attribute* attr);
69
 
  void ClearBaseUrl();
70
 
 
71
 
  friend class UrlLeftTrimFilterTest;
72
 
 
73
 
  // Stats on how much trimming we've done.
74
 
  Variable* trim_count_;
75
 
  Variable* trim_saved_bytes_;
76
 
 
77
 
  DISALLOW_COPY_AND_ASSIGN(UrlLeftTrimFilter);
78
 
};
79
 
 
80
 
}  // namespace net_instaweb
81
 
 
82
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_URL_LEFT_TRIM_FILTER_H_