Page Speed Optimization Libraries
1.5.27.2
|
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/util/public/basictypes.h" 00023 #include "net/instaweb/htmlparse/public/empty_html_filter.h" 00024 #include "net/instaweb/rewriter/public/resource.h" 00025 #include "net/instaweb/rewriter/public/rewrite_driver.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 HtmlElement; 00032 class ServerContext; 00033 class ResponseHeaders; 00034 class RewriteOptions; 00035 00046 class CommonFilter : public EmptyHtmlFilter { 00047 public: 00048 explicit CommonFilter(RewriteDriver* driver); 00049 virtual ~CommonFilter(); 00050 00052 00054 const GoogleUrl& base_url() const; 00055 00058 const GoogleUrl& decoded_base_url() const; 00059 00060 HtmlElement* noscript_element() const { return noscript_element_; } 00061 00063 virtual void StartDocument(); 00064 virtual void StartElement(HtmlElement* element); 00065 virtual void EndElement(HtmlElement* element); 00066 00071 ResourcePtr CreateInputResource(const StringPiece& input_url); 00072 00077 bool BaseUrlIsValid() const; 00078 00079 RewriteDriver* driver() const { return driver_; } 00080 00085 bool DebugMode() const { return driver_->DebugMode(); } 00086 00099 static bool ExtractMetaTagDetails(const HtmlElement& element, 00100 const ResponseHeaders* headers, 00101 GoogleString* content, 00102 GoogleString* mime_type, 00103 GoogleString* charset); 00104 00109 virtual void LogFilterModifiedContent(); 00110 00111 protected: 00115 virtual void StartDocumentImpl() = 0; 00116 virtual void StartElementImpl(HtmlElement* element) = 0; 00117 virtual void EndElementImpl(HtmlElement* element) = 0; 00118 00121 virtual const char* LoggingId() { return Name(); } 00123 RewriteDriver* driver_; 00124 ServerContext* server_context_; 00125 const RewriteOptions* rewrite_options_; 00126 00127 private: 00128 HtmlElement* noscript_element_; 00129 bool seen_base_; 00130 00131 DISALLOW_COPY_AND_ASSIGN(CommonFilter); 00132 }; 00133 00134 } 00135 00136 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_COMMON_FILTER_H_