Page Speed Optimization Libraries  1.3.25.1
net/instaweb/rewriter/public/critical_css_filter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2013 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 
00029 
00030 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_CSS_FILTER_H_
00031 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_CSS_FILTER_H_
00032 
00033 #include <vector>
00034 
00035 #include "net/instaweb/htmlparse/public/empty_html_filter.h"
00036 #include "net/instaweb/rewriter/public/css_tag_scanner.h"
00037 #include "net/instaweb/util/public/basictypes.h"
00038 #include "net/instaweb/util/public/scoped_ptr.h"
00039 #include "net/instaweb/util/public/string_util.h"
00040 
00041 namespace net_instaweb {
00042 
00043 class CriticalCssFinder;
00044 class HtmlCharactersNode;
00045 class HtmlElement;
00046 class RewriteDriver;
00047 
00048 class CriticalCssFilter : public EmptyHtmlFilter {
00049  public:
00050   explicit CriticalCssFilter(RewriteDriver* rewrite_driver,
00051                              CriticalCssFinder* finder);
00052   virtual ~CriticalCssFilter();
00053 
00055   virtual void StartDocument();
00056   virtual void EndDocument();
00057   virtual void StartElement(HtmlElement* element);
00058   virtual void Characters(HtmlCharactersNode* characters);
00059   virtual void EndElement(HtmlElement* element);
00060   virtual const char* Name() const { return "CriticalCss"; }
00061 
00062  private:
00067   StringPiece GetRules(StringPiece decoded_url) const;
00068 
00069   RewriteDriver* driver_;
00070   CssTagScanner css_tag_scanner_;
00071   CriticalCssFinder* finder_;
00072 
00074   scoped_ptr<StringStringMap> critical_css_map_;
00075 
00076   class CssElement;
00077   class CssStyleElement;
00078   typedef std::vector<CssElement*> CssElementVector;
00079   CssElementVector css_elements_;
00080   CssStyleElement* current_style_element_;
00081   bool has_critical_css_match_;
00082 
00083   DISALLOW_COPY_AND_ASSIGN(CriticalCssFilter);
00084 };
00085 
00086 }  
00087 
00088 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_CSS_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines