Page Speed Optimization Libraries  1.7.30.1
net/instaweb/rewriter/public/critical_selector_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 
00024 
00025 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
00026 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
00027 
00028 #include <vector>
00029 
00030 #include "net/instaweb/rewriter/public/css_summarizer_base.h"
00031 #include "net/instaweb/util/public/basictypes.h"
00032 #include "net/instaweb/util/public/string.h"
00033 #include "net/instaweb/util/public/string_util.h"
00034 
00035 namespace Css {
00036 
00037 class Stylesheet;
00038 
00039 }  
00040 
00041 namespace net_instaweb {
00042 
00043 class HtmlCharactersNode;
00044 class HtmlElement;
00045 class RewriteDriver;
00046 
00047 class CriticalSelectorFilter : public CssSummarizerBase {
00048  public:
00049   static const char kAddStylesFunction[];
00050   static const char kAddStylesInvocation[];
00051   static const char kApplyFlushEarlyCss[];
00052   static const char kInvokeFlushEarlyCssTemplate[];
00053   static const char kMoveScriptId[];
00054   static const char kNoscriptStylesClass[];
00055 
00056   explicit CriticalSelectorFilter(RewriteDriver* rewrite_driver);
00057   virtual ~CriticalSelectorFilter();
00058 
00059   virtual const char* Name() const { return "CriticalSelectorFilter"; }
00060   virtual const char* id() const { return "cl"; }
00061 
00062  protected:
00068   virtual void Summarize(Css::Stylesheet* stylesheet,
00069                          GoogleString* out) const;
00070   virtual void RenderSummary(int pos,
00071                              HtmlElement* element,
00072                              HtmlCharactersNode* char_node,
00073                              bool* is_element_deleted);
00074   virtual void WillNotRenderSummary(int pos,
00075                                     HtmlElement* element,
00076                                     HtmlCharactersNode* char_node,
00077                                     bool* is_element_deleted);
00078 
00081   virtual GoogleString CacheKeySuffix() const;
00082 
00084   virtual void StartDocumentImpl();
00085   virtual void EndDocument();
00086   virtual void RenderDone();
00087 
00089   virtual void DetermineEnabled();
00090 
00091  private:
00092   class CssElement;
00093   class CssStyleElement;
00094   typedef std::vector<CssElement*> CssElementVector;
00095 
00096   void RememberFullCss(int pos,
00097                        HtmlElement* element,
00098                        HtmlCharactersNode* char_node);
00099 
00100   bool IsCssFlushedEarly(const GoogleString& url) const;
00101   void ApplyCssFlushedEarly(HtmlElement* element,
00102                             const GoogleString& style_id,
00103                             const char* media);
00104 
00108   StringSet critical_selectors_;
00109 
00111   GoogleString cache_key_suffix_;
00112 
00116   CssElementVector css_elements_;
00117 
00119   bool saw_end_document_;
00120 
00122   bool any_rendered_;
00123 
00125   bool is_flush_script_added_;
00126 
00127   DISALLOW_COPY_AND_ASSIGN(CriticalSelectorFilter);
00128 };
00129 
00130 }  
00131 
00132 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines