Page Speed Optimization Libraries  1.7.30.3
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 
00067   virtual bool AllowUnauthorizedDomain() const { return true; }
00068 
00069  protected:
00075   virtual void Summarize(Css::Stylesheet* stylesheet,
00076                          GoogleString* out) const;
00077   virtual void RenderSummary(int pos,
00078                              HtmlElement* element,
00079                              HtmlCharactersNode* char_node,
00080                              bool* is_element_deleted);
00081   virtual void WillNotRenderSummary(int pos,
00082                                     HtmlElement* element,
00083                                     HtmlCharactersNode* char_node,
00084                                     bool* is_element_deleted);
00085 
00088   virtual GoogleString CacheKeySuffix() const;
00089 
00091   virtual void StartDocumentImpl();
00092   virtual void EndDocument();
00093   virtual void RenderDone();
00094 
00096   virtual void DetermineEnabled();
00097 
00098  private:
00099   class CssElement;
00100   class CssStyleElement;
00101   typedef std::vector<CssElement*> CssElementVector;
00102 
00103   void RememberFullCss(int pos,
00104                        HtmlElement* element,
00105                        HtmlCharactersNode* char_node);
00106 
00107   bool IsCssFlushedEarly(const GoogleString& url) const;
00108   void ApplyCssFlushedEarly(HtmlElement* element,
00109                             const GoogleString& style_id,
00110                             const char* media);
00111 
00115   StringSet critical_selectors_;
00116 
00118   GoogleString cache_key_suffix_;
00119 
00123   CssElementVector css_elements_;
00124 
00126   bool saw_end_document_;
00127 
00129   bool any_rendered_;
00130 
00132   bool is_flush_script_added_;
00133 
00134   DISALLOW_COPY_AND_ASSIGN(CriticalSelectorFilter);
00135 };
00136 
00137 }  
00138 
00139 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines