Page Speed Optimization Libraries
1.3.25.1
|
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 "net/instaweb/rewriter/public/resource.h" 00030 #include "net/instaweb/rewriter/public/resource_slot.h" 00031 #include "net/instaweb/util/public/basictypes.h" 00032 #include "net/instaweb/util/public/scoped_ptr.h" 00033 #include "net/instaweb/util/public/string.h" 00034 #include "net/instaweb/util/public/string_util.h" 00035 00036 namespace Css { class Values; } 00037 00038 namespace net_instaweb { 00039 00040 class GoogleUrl; 00041 00043 class CssResourceSlot : public ResourceSlot { 00044 public: 00045 virtual void Render(); 00046 virtual void Finished(); 00047 virtual GoogleString LocationString(); 00048 00049 Css::Values* values() const { return values_; } 00050 size_t value_index() const { return value_index_; } 00051 00053 void EnableTrim(const GoogleUrl& base_url); 00054 00055 virtual void DirectSetUrl(const StringPiece& url); 00056 virtual bool CanDirectSetUrl() { return true; } 00057 00058 protected: 00059 CssResourceSlot(const ResourcePtr& resource, Css::Values* values, 00060 size_t value_index) 00061 : ResourceSlot(resource), 00062 values_(values), 00063 value_index_(value_index) { 00064 } 00065 00066 REFCOUNT_FRIEND_DECLARATION(CssResourceSlot); 00067 virtual ~CssResourceSlot(); 00068 00069 private: 00070 friend class CssResourceSlotFactory; 00071 00072 Css::Values* values_; 00073 size_t value_index_; 00074 scoped_ptr<GoogleUrl> trim_base_; 00075 00076 DISALLOW_COPY_AND_ASSIGN(CssResourceSlot); 00077 }; 00078 00079 typedef RefCountedPtr<CssResourceSlot> CssResourceSlotPtr; 00080 00083 class CssResourceSlotFactory { 00084 public: 00085 CssResourceSlotFactory() {} 00086 ~CssResourceSlotFactory(); 00087 00090 CssResourceSlotPtr GetSlot(const ResourcePtr& resource, 00091 Css::Values* values, size_t value_index); 00092 CssResourceSlotPtr UniquifySlot(CssResourceSlotPtr slot); 00093 00094 private: 00095 class SlotComparator { 00096 public: 00097 bool operator()(const CssResourceSlotPtr& p, 00098 const CssResourceSlotPtr& q) const; 00099 }; 00100 typedef std::set<CssResourceSlotPtr, SlotComparator> SlotSet; 00101 00102 SlotSet slots_; 00103 DISALLOW_COPY_AND_ASSIGN(CssResourceSlotFactory); 00104 }; 00105 00106 } 00107 00108 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_RESOURCE_SLOT_H_