Page Speed Optimization Libraries
1.7.30.3
|
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 00018 00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_SIMPLE_TEXT_FILTER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_SIMPLE_TEXT_FILTER_H_ 00021 00022 #include "net/instaweb/htmlparse/public/html_element.h" 00023 #include "net/instaweb/rewriter/public/output_resource_kind.h" 00024 #include "net/instaweb/rewriter/public/resource.h" 00025 #include "net/instaweb/rewriter/public/server_context.h" 00026 #include "net/instaweb/rewriter/public/resource_slot.h" 00027 #include "net/instaweb/rewriter/public/rewrite_filter.h" 00028 #include "net/instaweb/rewriter/public/single_rewrite_context.h" 00029 #include "net/instaweb/util/public/basictypes.h" 00030 #include "net/instaweb/util/public/string.h" 00031 #include "net/instaweb/util/public/string_util.h" 00032 00033 namespace net_instaweb { 00034 00035 class RewriteContext; 00036 class RewriteDriver; 00037 00046 class SimpleTextFilter : public RewriteFilter { 00047 public: 00048 class Rewriter : public RefCounted<Rewriter> { 00049 public: 00050 Rewriter() {} 00051 virtual bool RewriteText(const StringPiece& url, 00052 const StringPiece& in, 00053 GoogleString* out, 00054 ServerContext* server_context) = 0; 00055 virtual HtmlElement::Attribute* FindResourceAttribute( 00056 HtmlElement* element) = 0; 00057 00058 virtual OutputResourceKind kind() const = 0; 00059 virtual const char* id() const = 0; 00060 virtual const char* name() const = 0; 00061 00063 virtual bool OptimizationOnly() const { return true; } 00064 00065 protected: 00066 REFCOUNT_FRIEND_DECLARATION(Rewriter); 00067 virtual ~Rewriter(); 00068 00069 private: 00070 DISALLOW_COPY_AND_ASSIGN(Rewriter); 00071 }; 00072 00073 typedef RefCountedPtr<Rewriter> RewriterPtr; 00074 00075 class Context : public SingleRewriteContext { 00076 public: 00077 Context(const RewriterPtr& rewriter, RewriteDriver* driver, 00078 RewriteContext* parent); 00079 virtual ~Context(); 00080 virtual void RewriteSingle( 00081 const ResourcePtr& input, const OutputResourcePtr& output); 00082 00083 protected: 00084 virtual const char* id() const { return rewriter_->id(); } 00085 virtual OutputResourceKind kind() const { return rewriter_->kind(); } 00086 virtual bool OptimizationOnly() const { 00087 return rewriter_->OptimizationOnly(); 00088 } 00089 00090 private: 00091 RewriterPtr rewriter_; 00092 00093 DISALLOW_COPY_AND_ASSIGN(Context); 00094 }; 00095 00096 SimpleTextFilter(Rewriter* rewriter, RewriteDriver* driver); 00097 virtual ~SimpleTextFilter(); 00098 00099 virtual void StartDocumentImpl() {} 00100 virtual void EndElementImpl(HtmlElement* element) {} 00101 virtual void StartElementImpl(HtmlElement* element); 00102 00103 virtual RewriteContext* MakeRewriteContext(); 00104 virtual RewriteContext* MakeNestedRewriteContext( 00105 RewriteContext* parent, const ResourceSlotPtr& slot); 00106 00107 protected: 00108 virtual const char* id() const { return rewriter_->id(); } 00109 virtual const char* Name() const { return rewriter_->name(); } 00110 virtual bool ComputeOnTheFly() const { 00111 return rewriter_->kind() == kOnTheFlyResource; 00112 } 00113 00114 private: 00115 RewriterPtr rewriter_; 00116 00117 DISALLOW_COPY_AND_ASSIGN(SimpleTextFilter); 00118 }; 00119 00120 } 00121 00122 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_SIMPLE_TEXT_FILTER_H_