Page Speed Optimization Libraries  1.7.30.2
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:
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   HtmlElement* noscript_element() const { return noscript_element_; }
00066 
00080   void InsertNodeAtBodyEnd(HtmlNode* data);
00081 
00083   virtual void StartDocument();
00084   virtual void StartElement(HtmlElement* element);
00085   virtual void EndElement(HtmlElement* element);
00086 
00090   virtual void Characters(HtmlCharactersNode* characters);
00091 
00096   ResourcePtr CreateInputResource(const StringPiece& input_url);
00097 
00100   void ResolveUrl(StringPiece input_url, GoogleUrl* out_url);
00101 
00106   bool BaseUrlIsValid() const;
00107 
00108   RewriteDriver* driver() const { return driver_; }
00109 
00114   bool DebugMode() const { return driver_->DebugMode(); }
00115 
00128   static bool ExtractMetaTagDetails(const HtmlElement& element,
00129                                     const ResponseHeaders* headers,
00130                                     GoogleString* content,
00131                                     GoogleString* mime_type,
00132                                     GoogleString* charset);
00133 
00138   virtual void LogFilterModifiedContent();
00139 
00143   virtual bool AllowUnauthorizedDomain() const { return false; }
00144 
00145  protected:
00149   virtual void StartDocumentImpl() = 0;
00150   virtual void StartElementImpl(HtmlElement* element) = 0;
00151   virtual void EndElementImpl(HtmlElement* element) = 0;
00152 
00155   virtual const char* LoggingId() { return Name(); }
00157   RewriteDriver* driver_;
00158   ServerContext* server_context_;
00159   const RewriteOptions* rewrite_options_;
00160 
00161  private:
00162   HtmlElement* noscript_element_;
00163   HtmlElement* end_body_point_;
00164   bool seen_base_;
00165 
00166   DISALLOW_COPY_AND_ASSIGN(CommonFilter);
00167 };
00168 
00169 }  
00170 
00171 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_COMMON_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines