Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
critical_selector_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
24 
25 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
26 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
27 
28 #include <vector>
29 
33 #include "pagespeed/kernel/base/basictypes.h"
34 #include "pagespeed/kernel/base/string.h"
35 #include "pagespeed/kernel/base/string_util.h"
36 #include "pagespeed/kernel/http/semantic_type.h"
37 
38 namespace Css {
39 
40 class Stylesheet;
41 
42 }
43 
44 namespace net_instaweb {
45 
46 class HtmlCharactersNode;
47 class HtmlElement;
48 
50  public:
51  static const char kAddStylesFunction[];
52  static const char kAddStylesInvocation[];
53  static const char kApplyFlushEarlyCss[];
54  static const char kInvokeFlushEarlyCssTemplate[];
55  static const char kMoveScriptId[];
56  static const char kNoscriptStylesClass[];
57 
58  explicit CriticalSelectorFilter(RewriteDriver* rewrite_driver);
59  virtual ~CriticalSelectorFilter();
60 
61  virtual const char* Name() const { return "CriticalSelectorFilter"; }
62  virtual const char* id() const { return "cl"; }
63 
70  const {
71  return driver()->options()->HasInlineUnauthorizedResourceType(
72  semantic_type::kStylesheet) ?
73  RewriteDriver::kInlineUnauthorizedResources :
74  RewriteDriver::kInlineOnlyAuthorizedResources;
75  }
76 
78  virtual bool IntendedForInlining() const { return true; }
79 
80  protected:
86  virtual void Summarize(Css::Stylesheet* stylesheet,
87  GoogleString* out) const;
88  virtual void RenderSummary(int pos,
89  HtmlElement* element,
90  HtmlCharactersNode* char_node,
91  bool* is_element_deleted);
92  virtual void WillNotRenderSummary(int pos,
93  HtmlElement* element,
94  HtmlCharactersNode* char_node,
95  bool* is_element_deleted);
96 
99  virtual GoogleString CacheKeySuffix() const;
100 
102  virtual void StartDocumentImpl();
103  virtual void EndDocument();
104  virtual void RenderDone();
105 
107  virtual void DetermineEnabled(GoogleString* disabled_reason);
108 
109  private:
110  class CssElement;
111  class CssStyleElement;
112  typedef std::vector<CssElement*> CssElementVector;
113 
114  void RememberFullCss(int pos,
115  HtmlElement* element,
116  HtmlCharactersNode* char_node);
117 
118  bool IsCssFlushedEarly(const GoogleString& url) const;
119  void ApplyCssFlushedEarly(HtmlElement* element,
120  const GoogleString& style_id,
121  const char* media);
122 
126  StringSet critical_selectors_;
127 
129  GoogleString cache_key_suffix_;
130 
134  CssElementVector css_elements_;
135 
137  bool saw_end_document_;
138 
140  bool any_rendered_;
141 
143  bool is_flush_script_added_;
144 
145  DISALLOW_COPY_AND_ASSIGN(CriticalSelectorFilter);
146 };
147 
148 }
149 
150 #endif
virtual void RenderSummary(int pos, HtmlElement *element, HtmlCharactersNode *char_node, bool *is_element_deleted)
virtual void WillNotRenderSummary(int pos, HtmlElement *element, HtmlCharactersNode *char_node, bool *is_element_deleted)
Definition: critical_selector_filter.h:49
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: critical_selector_filter.h:69
virtual bool IntendedForInlining() const
Selectors are inlined into the html.
Definition: critical_selector_filter.h:78
virtual void Summarize(Css::Stylesheet *stylesheet, GoogleString *out) const
Definition: rewrite_driver.h:98
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:135
virtual void StartDocumentImpl()
Parser callbacks.
virtual void DetermineEnabled(GoogleString *disabled_reason)
Filter control API.
const RewriteOptions * options() const
Return the options used for this RewriteDriver.
Definition: rewrite_driver.h:478
virtual GoogleString CacheKeySuffix() const
Definition: css_summarizer_base.h:52