00001 /* 00002 * Copyright 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00022 00023 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_ 00024 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_ 00025 00026 #include <cstddef> 00027 #include <set> 00028 00029 #include "base/scoped_ptr.h" 00030 #include "net/instaweb/rewriter/public/resource.h" 00031 #include "net/instaweb/rewriter/public/resource_slot.h" 00032 #include "net/instaweb/util/public/basictypes.h" 00033 #include "net/instaweb/util/public/ref_counted_ptr.h" 00034 #include "net/instaweb/util/public/string.h" 00035 #include "net/instaweb/util/public/string_util.h" 00036 00037 namespace Css { class Values; } 00038 00039 namespace net_instaweb { 00040 00041 class GoogleUrl; 00042 00044 class CssResourceSlot : public ResourceSlot { 00045 public: 00046 virtual void Render(); 00047 virtual void Finished(); 00048 virtual GoogleString LocationString(); 00049 00050 Css::Values* values() const { return values_; } 00051 size_t value_index() const { return value_index_; } 00052 00054 void EnableTrim(const GoogleUrl& base_url); 00055 00058 void UpdateUrlInCss(const StringPiece& url); 00059 00060 protected: 00061 CssResourceSlot(const ResourcePtr& resource, Css::Values* values, 00062 size_t value_index) 00063 : ResourceSlot(resource), 00064 values_(values), 00065 value_index_(value_index) { 00066 } 00067 00068 REFCOUNT_FRIEND_DECLARATION(CssResourceSlot); 00069 virtual ~CssResourceSlot(); 00070 00071 private: 00072 friend class CssResourceSlotFactory; 00073 00074 Css::Values* values_; 00075 size_t value_index_; 00076 scoped_ptr<GoogleUrl> trim_base_; 00077 00078 DISALLOW_COPY_AND_ASSIGN(CssResourceSlot); 00079 }; 00080 00081 typedef RefCountedPtr<CssResourceSlot> CssResourceSlotPtr; 00082 00085 class CssResourceSlotFactory { 00086 public: 00087 CssResourceSlotFactory() {} 00088 ~CssResourceSlotFactory(); 00089 00092 CssResourceSlotPtr GetSlot(const ResourcePtr& resource, 00093 Css::Values* values, size_t value_index); 00094 CssResourceSlotPtr UniquifySlot(CssResourceSlotPtr slot); 00095 00096 private: 00097 class SlotComparator { 00098 public: 00099 bool operator()(const CssResourceSlotPtr& p, 00100 const CssResourceSlotPtr& q) const; 00101 }; 00102 typedef std::set<CssResourceSlotPtr, SlotComparator> SlotSet; 00103 00104 SlotSet slots_; 00105 DISALLOW_COPY_AND_ASSIGN(CssResourceSlotFactory); 00106 }; 00107 00108 } 00109 00110 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_