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: morlovich@google.com (Maksim Orlovich)
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).
23
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_
24
#define NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_
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"
36
namespace Css { class Values; }
38
namespace net_instaweb {
43
// A place storing a rewritable URL inside a CSS AST.
44
class CssResourceSlot : public ResourceSlot {
46
virtual void Render();
47
virtual void Finished();
48
virtual GoogleString LocationString();
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_; }
55
virtual bool DirectSetUrl(const StringPiece& url);
56
virtual bool CanDirectSetUrl() { return true; }
59
CssResourceSlot(const ResourcePtr& resource,
60
const GoogleUrl& trim_url, const RewriteOptions* options,
61
Css::Values* values, size_t value_index);
63
REFCOUNT_FRIEND_DECLARATION(CssResourceSlot);
64
virtual ~CssResourceSlot();
67
friend class CssResourceSlotFactory;
72
UrlRelativity url_relativity_;
74
const RewriteOptions* options_;
76
DISALLOW_COPY_AND_ASSIGN(CssResourceSlot);
79
typedef RefCountedPtr<CssResourceSlot> CssResourceSlotPtr;
81
// Helper factory that makes sure we get a single CSS object for given value
82
// slot in the CSS AST.
83
class CssResourceSlotFactory {
85
CssResourceSlotFactory() {}
86
~CssResourceSlotFactory();
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);
97
class SlotComparator {
99
bool operator()(const CssResourceSlotPtr& p,
100
const CssResourceSlotPtr& q) const;
102
typedef std::set<CssResourceSlotPtr, SlotComparator> SlotSet;
105
DISALLOW_COPY_AND_ASSIGN(CssResourceSlotFactory);
108
} // namespace net_instaweb
110
#endif // NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_