Page Speed Optimization Libraries
1.7.30.4
|
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/string.h" 00033 #include "net/instaweb/util/public/string_util.h" 00034 #include "pagespeed/kernel/http/google_url.h" 00035 00036 namespace Css { class Values; } 00037 00038 namespace net_instaweb { 00039 00040 class RewriteOptions; 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 UrlRelativity url_relativity() const { return url_relativity_; } 00052 00053 virtual bool DirectSetUrl(const StringPiece& url); 00054 virtual bool CanDirectSetUrl() { return true; } 00055 00056 protected: 00057 CssResourceSlot(const ResourcePtr& resource, 00058 const GoogleUrl& trim_url, const RewriteOptions* options, 00059 Css::Values* values, size_t value_index); 00060 00061 REFCOUNT_FRIEND_DECLARATION(CssResourceSlot); 00062 virtual ~CssResourceSlot(); 00063 00064 private: 00065 friend class CssResourceSlotFactory; 00066 00067 Css::Values* values_; 00068 size_t value_index_; 00069 00070 UrlRelativity url_relativity_; 00071 GoogleUrl trim_url_; 00072 const RewriteOptions* options_; 00073 00074 DISALLOW_COPY_AND_ASSIGN(CssResourceSlot); 00075 }; 00076 00077 typedef RefCountedPtr<CssResourceSlot> CssResourceSlotPtr; 00078 00081 class CssResourceSlotFactory { 00082 public: 00083 CssResourceSlotFactory() {} 00084 ~CssResourceSlotFactory(); 00085 00088 CssResourceSlotPtr GetSlot(const ResourcePtr& resource, 00089 const GoogleUrl& trim_url, 00090 const RewriteOptions* options, 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_