Page Speed Optimization Libraries
1.7.30.2
|
00001 /* 00002 * Copyright 2013 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_FAKE_FILTER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_FAKE_FILTER_H_ 00021 00022 #include "net/instaweb/http/public/semantic_type.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/resource_slot.h" 00026 #include "net/instaweb/rewriter/public/rewrite_filter.h" 00027 #include "net/instaweb/rewriter/public/server_context.h" 00028 #include "net/instaweb/rewriter/public/single_rewrite_context.h" 00029 #include "net/instaweb/util/public/string.h" 00030 00031 namespace net_instaweb { 00032 00033 class HtmlElement; 00034 class ResourceContext; 00035 class RewriteContext; 00036 class RewriteDriver; 00037 struct ContentType; 00038 00043 class FakeFilter : public RewriteFilter { 00044 public: 00045 class Context : public SingleRewriteContext { 00046 public: 00047 Context(FakeFilter* filter, RewriteDriver* driver, RewriteContext* parent, 00048 ResourceContext* resource_context) 00049 : SingleRewriteContext(driver, parent, resource_context), 00050 filter_(filter) {} 00051 virtual ~Context(); 00052 00053 void RewriteSingle(const ResourcePtr& input, 00054 const OutputResourcePtr& output); 00055 00056 void DoRewriteSingle(const ResourcePtr input, OutputResourcePtr output); 00057 GoogleString UserAgentCacheKey( 00058 const ResourceContext* resource_context) const; 00059 00060 virtual const char* id() const { return filter_->id(); } 00061 virtual OutputResourceKind kind() const { return filter_->kind(); } 00062 00063 private: 00064 FakeFilter* filter_; 00065 }; 00066 00067 FakeFilter(const char* id, RewriteDriver* rewrite_driver, 00068 semantic_type::Category category) 00069 : RewriteFilter(rewrite_driver), 00070 id_(id), 00071 exceed_deadline_(false), 00072 enabled_(true), 00073 num_rewrites_(0), 00074 output_content_type_(NULL), 00075 num_calls_to_encode_user_agent_(0), 00076 category_(category) {} 00077 00078 virtual ~FakeFilter(); 00079 00080 virtual void StartDocumentImpl() {} 00081 virtual void EndElementImpl(HtmlElement* element) {} 00082 virtual void StartElementImpl(HtmlElement* element); 00083 virtual RewriteContext* MakeRewriteContext() { 00084 return new FakeFilter::Context(this, driver_, NULL, NULL); 00085 } 00086 virtual RewriteContext* MakeNestedRewriteContext(RewriteContext* parent, 00087 const ResourceSlotPtr& slot); 00088 int num_rewrites() const { return num_rewrites_; } 00089 int num_encode_user_agent() const { return num_calls_to_encode_user_agent_; } 00090 void ClearStats(); 00091 void set_enabled(bool x) { enabled_ = x; } 00092 bool enabled() { return enabled_; } 00093 bool exceed_deadline() { return exceed_deadline_; } 00094 void set_exceed_deadline(bool x) { exceed_deadline_ = x; } 00095 void IncRewrites() { ++num_rewrites_; } 00096 void set_output_content_type(const ContentType* type) { 00097 output_content_type_ = type; 00098 } 00099 const ContentType* output_content_type() { return output_content_type_; } 00100 virtual void EncodeUserAgentIntoResourceContext( 00101 ResourceContext* context) const; 00102 00103 protected: 00104 virtual const char* id() const { return id_; } 00105 virtual OutputResourceKind kind() const { return kRewrittenResource; } 00106 virtual const char* Name() const { return "MockFilter"; } 00107 virtual bool ComputeOnTheFly() const { return false; } 00108 00109 private: 00110 const char* id_; 00111 bool exceed_deadline_; 00112 bool enabled_; 00113 int num_rewrites_; 00114 const ContentType* output_content_type_; 00115 mutable int num_calls_to_encode_user_agent_; 00116 semantic_type::Category category_; 00117 }; 00118 00119 } 00120 00121 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_FAKE_FILTER_H_