~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/css_resource_slot.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: morlovich@google.com (Maksim Orlovich)
18
 
//
19
 
// Contains CssResourceSlot (for representing locations in CSS AST during async
20
 
// rewrites) and CssResourceSlotFactory (for getting the same slot object for
21
 
// the same location).
22
 
 
23
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_
24
 
#define NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_
25
 
 
26
 
#include <cstddef>
27
 
#include <set>
28
 
 
29
 
#include "net/instaweb/rewriter/public/resource.h"
30
 
#include "net/instaweb/rewriter/public/resource_slot.h"
31
 
#include "net/instaweb/util/public/basictypes.h"
32
 
#include "net/instaweb/util/public/string.h"
33
 
#include "net/instaweb/util/public/string_util.h"
34
 
#include "pagespeed/kernel/http/google_url.h"
35
 
 
36
 
namespace Css { class Values; }
37
 
 
38
 
namespace net_instaweb {
39
 
 
40
 
class HtmlElement;
41
 
class RewriteOptions;
42
 
 
43
 
// A place storing a rewritable URL inside a CSS AST.
44
 
class CssResourceSlot : public ResourceSlot {
45
 
 public:
46
 
  virtual void Render();
47
 
  virtual void Finished();
48
 
  virtual GoogleString LocationString();
49
 
 
50
 
  virtual HtmlElement* element() const { return NULL; }
51
 
  Css::Values* values() const { return values_; }
52
 
  size_t value_index() const { return value_index_; }
53
 
  UrlRelativity url_relativity() const { return url_relativity_; }
54
 
 
55
 
  virtual bool DirectSetUrl(const StringPiece& url);
56
 
  virtual bool CanDirectSetUrl() { return true; }
57
 
 
58
 
 protected:
59
 
  CssResourceSlot(const ResourcePtr& resource,
60
 
                  const GoogleUrl& trim_url, const RewriteOptions* options,
61
 
                  Css::Values* values, size_t value_index);
62
 
 
63
 
  REFCOUNT_FRIEND_DECLARATION(CssResourceSlot);
64
 
  virtual ~CssResourceSlot();
65
 
 
66
 
 private:
67
 
  friend class CssResourceSlotFactory;
68
 
 
69
 
  Css::Values* values_;
70
 
  size_t value_index_;
71
 
 
72
 
  UrlRelativity url_relativity_;
73
 
  GoogleUrl trim_url_;
74
 
  const RewriteOptions* options_;
75
 
 
76
 
  DISALLOW_COPY_AND_ASSIGN(CssResourceSlot);
77
 
};
78
 
 
79
 
typedef RefCountedPtr<CssResourceSlot> CssResourceSlotPtr;
80
 
 
81
 
// Helper factory that makes sure we get a single CSS object for given value
82
 
// slot in the CSS AST.
83
 
class CssResourceSlotFactory {
84
 
 public:
85
 
  CssResourceSlotFactory() {}
86
 
  ~CssResourceSlotFactory();
87
 
 
88
 
  // Warning: this is only safe if the declaration containing this property is
89
 
  // not modified while this exists.
90
 
  CssResourceSlotPtr GetSlot(const ResourcePtr& resource,
91
 
                             const GoogleUrl& trim_url,
92
 
                             const RewriteOptions* options,
93
 
                             Css::Values* values, size_t value_index);
94
 
  CssResourceSlotPtr UniquifySlot(CssResourceSlotPtr slot);
95
 
 
96
 
 private:
97
 
  class SlotComparator {
98
 
   public:
99
 
    bool operator()(const CssResourceSlotPtr& p,
100
 
                    const CssResourceSlotPtr& q) const;
101
 
  };
102
 
  typedef std::set<CssResourceSlotPtr, SlotComparator> SlotSet;
103
 
 
104
 
  SlotSet slots_;
105
 
  DISALLOW_COPY_AND_ASSIGN(CssResourceSlotFactory);
106
 
};
107
 
 
108
 
}  // namespace net_instaweb
109
 
 
110
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_