Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resource_slot.h
Go to the documentation of this file.
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 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_SLOT_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_SLOT_H_
21 
22 #include <memory>
23 #include <set>
24 #include <vector>
25 
26 #include "net/instaweb/rewriter/input_info.pb.h"
35 
36 namespace net_instaweb {
37 
38 class HtmlResourceSlot;
39 class ResourceSlot;
40 class RewriteContext;
41 class RewriteDriver;
42 class RewriteOptions;
43 
44 typedef RefCountedPtr<ResourceSlot> ResourceSlotPtr;
45 typedef RefCountedPtr<HtmlResourceSlot> HtmlResourceSlotPtr;
46 typedef std::vector<ResourceSlotPtr> ResourceSlotVector;
47 
54 class ResourceSlot : public RefCounted<ResourceSlot> {
55  public:
56  explicit ResourceSlot(const ResourcePtr& resource)
57  : resource_(resource),
58  preserve_urls_(false),
59  disable_rendering_(false),
60  should_delete_element_(false),
61  disable_further_processing_(false),
62  was_optimized_(false),
63  need_aggregate_input_info_(false) {
64  }
65 
66  ResourcePtr resource() const { return resource_; }
68  virtual HtmlElement* element() const = 0;
69 
83  void SetResource(const ResourcePtr& resource);
84 
87  void set_preserve_urls(bool x) { preserve_urls_ = x; }
88  bool preserve_urls() const { return preserve_urls_; }
89 
93  void set_disable_rendering(bool x) { disable_rendering_ = x; }
94  bool disable_rendering() const { return disable_rendering_; }
95 
103  should_delete_element_ = true;
104  disable_further_processing_ = true;
105  }
106  bool should_delete_element() const { return should_delete_element_; }
107 
114  bool was_optimized() const { return was_optimized_; }
115 
117  void set_was_optimized(bool x) { was_optimized_ = x; }
118 
127  disable_further_processing_ = x;
128  }
129 
130  bool disable_further_processing() const {
131  return disable_further_processing_;
132  }
133 
137  need_aggregate_input_info_ = x;
138  }
139 
140  bool need_aggregate_input_info() const {
141  return need_aggregate_input_info_;
142  }
143 
144  void ReportInput(const InputInfo& input);
145 
147  const std::vector<InputInfo>* inputs() const { return inputs_.get(); }
148 
154  virtual void Render() = 0;
155 
159  virtual void Finished() {}
160 
171  virtual bool DirectSetUrl(const StringPiece& url);
172 
175  virtual bool CanDirectSetUrl() { return false; }
176 
179  RewriteContext* LastContext() const;
180 
182  void AddContext(RewriteContext* context) { contexts_.push_back(context); }
183 
186  void DetachContext(RewriteContext* context);
187 
190  virtual GoogleString LocationString() const = 0;
191 
196  StringPiece url,
197  UrlRelativity url_relativity,
198  const GoogleUrl& base_url);
199 
200  protected:
201  virtual ~ResourceSlot();
202  REFCOUNT_FRIEND_DECLARATION(ResourceSlot);
203 
204  private:
205  ResourcePtr resource_;
206  std::unique_ptr<std::vector<InputInfo>> inputs_;
207  bool preserve_urls_;
208  bool disable_rendering_;
209  bool should_delete_element_;
210  bool disable_further_processing_;
211  bool was_optimized_;
212  bool need_aggregate_input_info_;
213 
217 
218 
219 };
220 
224  public:
225  NullResourceSlot(const ResourcePtr& resource, StringPiece location);
226  virtual HtmlElement* element() const { return NULL; }
227  virtual void Render() {}
228  virtual GoogleString LocationString() const { return location_; }
229 
230  protected:
231  REFCOUNT_FRIEND_DECLARATION(NullResourceSlot);
232  virtual ~NullResourceSlot();
233 
234  private:
235  GoogleString location_;
236 
237 
238 };
239 
243  public:
244  explicit FetchResourceSlot(const ResourcePtr& resource)
245  : ResourceSlot(resource) {
246  }
247  virtual HtmlElement* element() const { return NULL; }
248  virtual void Render();
249  virtual GoogleString LocationString() const;
250 
251  protected:
252  REFCOUNT_FRIEND_DECLARATION(FetchResourceSlot);
253  virtual ~FetchResourceSlot();
254 
255  private:
256 
257 };
258 
260  public:
261  HtmlResourceSlot(const ResourcePtr& resource,
263  HtmlElement::Attribute* attribute,
264  RewriteDriver* driver);
265 
266  virtual HtmlElement* element() const { return element_; }
267  HtmlElement::Attribute* attribute() const { return attribute_; }
268 
269  virtual void Render();
270  virtual GoogleString LocationString() const;
271  virtual bool DirectSetUrl(const StringPiece& url);
272  virtual bool CanDirectSetUrl() { return true; }
273 
276  UrlRelativity url_relativity() const { return url_relativity_; }
277 
278  protected:
279  REFCOUNT_FRIEND_DECLARATION(HtmlResourceSlot);
280  virtual ~HtmlResourceSlot();
281 
282  private:
283  HtmlElement* element_;
284  HtmlElement::Attribute* attribute_;
285  RewriteDriver* driver_;
286  UrlRelativity url_relativity_;
287 
288  int begin_line_number_;
289  int end_line_number_;
290 
291 
292 };
293 
295  public:
296  bool operator()(const HtmlResourceSlotPtr& p,
297  const HtmlResourceSlotPtr& q) const;
298 };
299 
300 typedef std::set<HtmlResourceSlotPtr,
301  HtmlResourceSlotComparator> HtmlResourceSlotSet;
302 
303 }
304 
305 #endif
virtual void Finished()
Definition: resource_slot.h:159
class GoogleUrl
Definition: google_url.h:58
Definition: html_element.h:66
void set_disable_rendering(bool x)
Definition: resource_slot.h:93
bool was_optimized() const
Definition: resource_slot.h:114
Definition: vector_deque.h:47
virtual GoogleString LocationString() const
Definition: resource_slot.h:228
virtual HtmlElement * element() const
Return HTML element associated with slot, or NULL if none (CSS, IPRO)
Definition: resource_slot.h:226
void SetResource(const ResourcePtr &resource)
virtual void Render()=0
Definition: ref_counted_ptr.h:41
static GoogleString RelativizeOrPassthrough(const RewriteOptions *options, StringPiece url, UrlRelativity url_relativity, const GoogleUrl &base_url)
Definition: resource_slot.h:54
virtual GoogleString LocationString() const
Definition: html_element.h:42
virtual bool DirectSetUrl(const StringPiece &url)
void set_need_aggregate_input_info(bool x)
Definition: resource_slot.h:136
virtual bool CanDirectSetUrl()
Definition: resource_slot.h:175
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: resource_slot.h:259
virtual HtmlElement * element() const
Return HTML element associated with slot, or NULL if none (CSS, IPRO)
Definition: resource_slot.h:266
void RequestDeleteElement()
Definition: resource_slot.h:102
virtual HtmlElement * element() const
Return HTML element associated with slot, or NULL if none (CSS, IPRO)
Definition: resource_slot.h:247
virtual GoogleString LocationString() const
void set_disable_further_processing(bool x)
Definition: resource_slot.h:126
UrlRelativity url_relativity() const
Definition: resource_slot.h:276
Definition: resource_slot.h:242
Definition: rewrite_driver.h:100
UrlRelativity
namespace url
Definition: google_url.h:51
RewriteContext * LastContext() const
void AddContext(RewriteContext *context)
Adds a new context to this slot.
Definition: resource_slot.h:182
Definition: resource_slot.h:223
virtual bool DirectSetUrl(const StringPiece &url)
Definition: rewrite_context.h:155
virtual GoogleString LocationString() const =0
virtual bool CanDirectSetUrl()
Definition: resource_slot.h:272
Definition: resource_slot.h:294
virtual void Render()
Definition: resource_slot.h:227
const std::vector< InputInfo > * inputs() const
may be nullptr.
Definition: resource_slot.h:147
Definition: rewrite_options.h:84
void DetachContext(RewriteContext *context)
virtual HtmlElement * element() const =0
Return HTML element associated with slot, or NULL if none (CSS, IPRO)
void set_was_optimized(bool x)
Marks the slot as having been optimized.
Definition: resource_slot.h:117
void set_preserve_urls(bool x)
Definition: resource_slot.h:87