Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
association_transformer.h
Go to the documentation of this file.
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 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_ASSOCIATION_TRANSFORMER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_ASSOCIATION_TRANSFORMER_H_
21 
22 #include <map>
23 
31 
32 namespace net_instaweb {
33 
34 class GoogleUrl;
35 class HtmlElement;
36 class MessageHandler;
37 class RewriteOptions;
38 
44  public:
54  const RewriteOptions* options,
55  CssTagScanner::Transformer* backup_transformer,
56  MessageHandler* handler)
57  : base_url_(base_url), options_(options),
58  backup_transformer_(backup_transformer), handler_(handler) {}
59  virtual ~AssociationTransformer();
60 
64  StringStringMap* map() { return &map_; }
65 
70  virtual TransformStatus Transform(GoogleString* str);
71 
72  private:
74  StringStringMap map_;
75 
77  const GoogleUrl* base_url_;
78  const RewriteOptions* options_;
79 
82  CssTagScanner::Transformer* backup_transformer_;
83 
84  MessageHandler* handler_;
85 
86  FRIEND_TEST(AssociationTransformerTest, TransformsCorrectly);
87 
88 
89 };
90 
96 class AssociationSlot : public ResourceSlot {
97  public:
100  StringStringMap* map, const StringPiece& key)
101  : ResourceSlot(resource), map_(map) {
102  key.CopyToString(&key_);
103  }
104  virtual ~AssociationSlot();
105 
106  virtual HtmlElement* element() const { return NULL; }
107 
110  virtual void Render() {
112  if (!resource()->is_authorized_domain()) {
113  return;
114  }
115  if (!disable_rendering() && !preserve_urls()) {
116  (*map_)[key_] = resource()->url();
117  }
118  }
119 
120  virtual bool DirectSetUrl(const StringPiece& url) {
122  if (!resource()->is_authorized_domain()) {
123  return false;
124  }
125  url.CopyToString(&((*map_)[key_]));
126  return true;
127  }
128 
129  virtual GoogleString LocationString() const {
132  return "Inside CSS";
133  }
134 
135  private:
136  StringStringMap* map_;
137  GoogleString key_;
138 
139 
140 };
141 
142 }
143 
144 #endif
class GoogleUrl
Definition: google_url.h:58
Definition: css_tag_scanner.h:39
virtual TransformStatus Transform(GoogleString *str)
AssociationTransformer(const GoogleUrl *base_url, const RewriteOptions *options, CssTagScanner::Transformer *backup_transformer, MessageHandler *handler)
Definition: association_transformer.h:53
AssociationSlot(ResourcePtr resource, StringStringMap *map, const StringPiece &key)
Note: map must outlive AssociationSlot.
Definition: association_transformer.h:99
virtual void Render()
Definition: association_transformer.h:110
Definition: resource_slot.h:54
Definition: html_element.h:42
Definition: association_transformer.h:96
virtual GoogleString url() const =0
Gets the absolute URL of the resource.
virtual bool DirectSetUrl(const StringPiece &url)
Definition: association_transformer.h:120
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual GoogleString LocationString() const
Definition: association_transformer.h:129
Definition: message_handler.h:39
virtual HtmlElement * element() const
Return HTML element associated with slot, or NULL if none (CSS, IPRO)
Definition: association_transformer.h:106
Definition: association_transformer.h:43
Definition: rewrite_options.h:84
StringStringMap * map()
Definition: association_transformer.h:64