00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_SLOT_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_SLOT_H_
00021
00022 #include <set>
00023 #include <vector>
00024
00025 #include "net/instaweb/htmlparse/public/html_element.h"
00026 #include "net/instaweb/rewriter/public/resource.h"
00027 #include "net/instaweb/util/public/basictypes.h"
00028 #include "net/instaweb/util/public/ref_counted_ptr.h"
00029 #include "net/instaweb/util/public/string.h"
00030 #include "net/instaweb/util/public/vector_deque.h"
00031
00032 namespace net_instaweb {
00033
00034 class HtmlParse;
00035 class HtmlResourceSlot;
00036 class ResourceSlot;
00037 class RewriteContext;
00038
00039 typedef RefCountedPtr<ResourceSlot> ResourceSlotPtr;
00040 typedef RefCountedPtr<HtmlResourceSlot> HtmlResourceSlotPtr;
00041 typedef std::vector<ResourceSlotPtr> ResourceSlotVector;
00042
00049 class ResourceSlot : public RefCounted<ResourceSlot> {
00050 public:
00051 explicit ResourceSlot(const ResourcePtr& resource)
00052 : resource_(resource),
00053 disable_rendering_(false),
00054 should_delete_element_(false),
00055 was_optimized_(false) {
00056 }
00057
00058 ResourcePtr resource() const { return resource_; }
00059
00073 void SetResource(const ResourcePtr& resource);
00074
00078 void set_disable_rendering(bool x) { disable_rendering_ = x; }
00079 bool disable_rendering() const { return disable_rendering_; }
00080
00084 void set_should_delete_element(bool x) { should_delete_element_ = x; }
00085 bool should_delete_element() const { return should_delete_element_; }
00086
00091 bool was_optimized() const { return was_optimized_; }
00092
00094 void set_was_optimized(bool x) { was_optimized_ = x; }
00095
00098 virtual void Render() = 0;
00099
00103 virtual void Finished() {}
00104
00107 RewriteContext* LastContext() const;
00108
00110 void AddContext(RewriteContext* context) { contexts_.push_back(context); }
00111
00114 void DetachContext(RewriteContext* context);
00115
00118 virtual GoogleString LocationString() = 0;
00119
00120 protected:
00121 virtual ~ResourceSlot();
00122 REFCOUNT_FRIEND_DECLARATION(ResourceSlot);
00123
00124 private:
00125 ResourcePtr resource_;
00126 bool disable_rendering_;
00127 bool should_delete_element_;
00128 bool was_optimized_;
00129
00132 VectorDeque<RewriteContext*> contexts_;
00133
00134 DISALLOW_COPY_AND_ASSIGN(ResourceSlot);
00135 };
00136
00139 class FetchResourceSlot : public ResourceSlot {
00140 public:
00141 explicit FetchResourceSlot(const ResourcePtr& resource)
00142 : ResourceSlot(resource) {
00143 }
00144
00145 virtual void Render();
00146 virtual GoogleString LocationString();
00147
00148 protected:
00149 REFCOUNT_FRIEND_DECLARATION(FetchResourceSlot);
00150 virtual ~FetchResourceSlot();
00151
00152 private:
00153 DISALLOW_COPY_AND_ASSIGN(FetchResourceSlot);
00154 };
00155
00156 class HtmlResourceSlot : public ResourceSlot {
00157 public:
00158 HtmlResourceSlot(const ResourcePtr& resource,
00159 HtmlElement* element,
00160 HtmlElement::Attribute* attribute,
00161 HtmlParse* html_parse)
00162 : ResourceSlot(resource),
00163 element_(element),
00164 attribute_(attribute),
00165 html_parse_(html_parse),
00166 begin_line_number_(element->begin_line_number()),
00167 end_line_number_(element->end_line_number()) {
00168 }
00169
00170 HtmlElement* element() { return element_; }
00171 HtmlElement::Attribute* attribute() { return attribute_; }
00172
00173 virtual void Render();
00174 virtual GoogleString LocationString();
00175
00176 protected:
00177 REFCOUNT_FRIEND_DECLARATION(HtmlResourceSlot);
00178 virtual ~HtmlResourceSlot();
00179
00180 private:
00181 HtmlElement* element_;
00182 HtmlElement::Attribute* attribute_;
00183 HtmlParse* html_parse_;
00184
00185 int begin_line_number_;
00186 int end_line_number_;
00187
00188 DISALLOW_COPY_AND_ASSIGN(HtmlResourceSlot);
00189 };
00190
00191 class HtmlResourceSlotComparator {
00192 public:
00193 bool operator()(const HtmlResourceSlotPtr& p,
00194 const HtmlResourceSlotPtr& q) const;
00195 };
00196
00197 typedef std::set<HtmlResourceSlotPtr,
00198 HtmlResourceSlotComparator> HtmlResourceSlotSet;
00199
00200 }
00201
00202 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_SLOT_H_