Page Speed Optimization Libraries  1.7.30.1
net/instaweb/rewriter/public/common_filter.h
Go to the documentation of this file.
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:
00050   explicit CommonFilter(RewriteDriver* driver);
00051   virtual ~CommonFilter();
00052 
00054 
00056   const GoogleUrl& base_url() const;
00057 
00060   const GoogleUrl& decoded_base_url() const;
00061 
00062   HtmlElement* noscript_element() const { return noscript_element_; }
00063 
00077   void InsertNodeAtBodyEnd(HtmlNode* data);
00078 
00080   virtual void StartDocument();
00081   virtual void StartElement(HtmlElement* element);
00082   virtual void EndElement(HtmlElement* element);
00083 
00087   virtual void Characters(HtmlCharactersNode* characters);
00088 
00093   ResourcePtr CreateInputResource(const StringPiece& input_url);
00094 
00099   bool BaseUrlIsValid() const;
00100 
00101   RewriteDriver* driver() const { return driver_; }
00102 
00107   bool DebugMode() const { return driver_->DebugMode(); }
00108 
00121   static bool ExtractMetaTagDetails(const HtmlElement& element,
00122                                     const ResponseHeaders* headers,
00123                                     GoogleString* content,
00124                                     GoogleString* mime_type,
00125                                     GoogleString* charset);
00126 
00131   virtual void LogFilterModifiedContent();
00132 
00133  protected:
00137   virtual void StartDocumentImpl() = 0;
00138   virtual void StartElementImpl(HtmlElement* element) = 0;
00139   virtual void EndElementImpl(HtmlElement* element) = 0;
00140 
00143   virtual const char* LoggingId() { return Name(); }
00145   RewriteDriver* driver_;
00146   ServerContext* server_context_;
00147   const RewriteOptions* rewrite_options_;
00148 
00149  private:
00150   HtmlElement* noscript_element_;
00151   HtmlElement* end_body_point_;
00152   bool seen_base_;
00153 
00154   DISALLOW_COPY_AND_ASSIGN(CommonFilter);
00155 };
00156 
00157 }  
00158 
00159 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_COMMON_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines