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/util/public/string.h" 00026 #include "net/instaweb/util/public/string_util.h" 00027 00028 namespace net_instaweb { 00029 class GoogleUrl; 00030 class HtmlElement; 00031 class ResourceManager; 00032 class ResponseHeaders; 00033 class RewriteDriver; 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() { return driver_; } 00080 00093 static bool ExtractMetaTagDetails(const HtmlElement& element, 00094 const ResponseHeaders* headers, 00095 GoogleString* content, 00096 GoogleString* mime_type, 00097 GoogleString* charset); 00098 00099 protected: 00103 virtual void StartDocumentImpl() = 0; 00104 virtual void StartElementImpl(HtmlElement* element) = 0; 00105 virtual void EndElementImpl(HtmlElement* element) = 0; 00106 00108 RewriteDriver* driver_; 00109 ResourceManager* resource_manager_; 00110 const RewriteOptions* rewrite_options_; 00111 00112 private: 00113 HtmlElement* noscript_element_; 00114 bool seen_base_; 00115 00116 DISALLOW_COPY_AND_ASSIGN(CommonFilter); 00117 }; 00118 00119 } 00120 00121 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_COMMON_FILTER_H_