Page Speed Optimization Libraries
1.8.31.3
|
00001 /* 00002 * Copyright 2010 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_COMMON_FILTER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_COMMON_FILTER_H_ 00021 00022 #include "net/instaweb/htmlparse/public/empty_html_filter.h" 00023 #include "net/instaweb/rewriter/public/resource.h" 00024 #include "net/instaweb/rewriter/public/rewrite_driver.h" 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/string.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 00029 namespace net_instaweb { 00030 class GoogleUrl; 00031 class HtmlCharactersNode; 00032 class HtmlElement; 00033 class HtmlNode; 00034 class ResponseHeaders; 00035 class RewriteOptions; 00036 class ServerContext; 00037 00048 class CommonFilter : public EmptyHtmlFilter { 00049 public: 00051 static const char kCreateResourceFailedDebugMsg[]; 00052 00053 explicit CommonFilter(RewriteDriver* driver); 00054 virtual ~CommonFilter(); 00055 00057 00059 const GoogleUrl& base_url() const; 00060 00063 const GoogleUrl& decoded_base_url() const; 00064 00065 RewriteDriver* driver() const { return driver_; } 00066 HtmlElement* noscript_element() const { return noscript_element_; } 00067 00081 void InsertNodeAtBodyEnd(HtmlNode* data); 00082 00084 virtual void StartDocument(); 00085 virtual void StartElement(HtmlElement* element); 00086 virtual void EndElement(HtmlElement* element); 00087 00091 virtual void Characters(HtmlCharactersNode* characters); 00092 00097 ResourcePtr CreateInputResource(const StringPiece& input_url); 00098 00101 void ResolveUrl(StringPiece input_url, GoogleUrl* out_url); 00102 00107 bool BaseUrlIsValid() const; 00108 00113 bool DebugMode() const { return driver_->DebugMode(); } 00114 00127 static bool ExtractMetaTagDetails(const HtmlElement& element, 00128 const ResponseHeaders* headers, 00129 GoogleString* content, 00130 GoogleString* mime_type, 00131 GoogleString* charset); 00132 00137 bool CanAddPagespeedOnloadToImage(const HtmlElement&); 00138 00143 virtual void LogFilterModifiedContent(); 00144 00148 virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() 00149 const { return RewriteDriver::kInlineOnlyAuthorizedResources; } 00150 00154 virtual bool IntendedForInlining() const { return false; } 00155 00156 protected: 00157 ServerContext* server_context() const { return server_context_; } 00158 const RewriteOptions* rewrite_options() { return rewrite_options_; } 00159 00163 virtual void StartDocumentImpl() = 0; 00164 virtual void StartElementImpl(HtmlElement* element) = 0; 00165 virtual void EndElementImpl(HtmlElement* element) = 0; 00166 00169 virtual const char* LoggingId() { return Name(); } 00170 00171 private: 00173 RewriteDriver* driver_; 00174 ServerContext* server_context_; 00175 const RewriteOptions* rewrite_options_; 00176 HtmlElement* noscript_element_; 00178 HtmlElement* end_body_point_; 00179 bool seen_base_; 00180 00181 DISALLOW_COPY_AND_ASSIGN(CommonFilter); 00182 }; 00183 00184 } 00185 00186 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_COMMON_FILTER_H_