Page Speed Optimization Libraries  1.13.35.1
 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 
40 
41 namespace Css {
42 
43 class Stylesheet;
44 
45 }
46 
47 namespace net_instaweb {
48 
50  public:
51  static const char kAddStylesFunction[];
52  static const char kAddStylesInvocation[];
53  static const char kNoscriptStylesClass[];
54 
55  explicit CriticalSelectorFilter(RewriteDriver* rewrite_driver);
56  virtual ~CriticalSelectorFilter();
57 
58  virtual const char* Name() const { return "CriticalSelectorFilter"; }
59  virtual const char* id() const { return "cl"; }
60 
67  const {
68  return driver()->options()->HasInlineUnauthorizedResourceType(
69  semantic_type::kStylesheet) ?
70  RewriteDriver::kInlineUnauthorizedResources :
71  RewriteDriver::kInlineOnlyAuthorizedResources;
72  }
73 
75  virtual bool IntendedForInlining() const { return true; }
76  ScriptUsage GetScriptUsage() const override { return kWillInjectScripts; }
77 
78  protected:
84  void Summarize(Css::Stylesheet* stylesheet,
85  GoogleString* out) const override;
86  void RenderSummary(int pos,
87  HtmlElement* element,
88  HtmlCharactersNode* char_node,
89  bool* is_element_deleted) override;
90  void WillNotRenderSummary(int pos,
91  HtmlElement* element,
92  HtmlCharactersNode* char_node) override;
93 
96  virtual GoogleString CacheKeySuffix() const;
97 
99  virtual void StartDocumentImpl();
100  virtual void EndDocument();
101  virtual void RenderDone();
102 
104  virtual void DetermineEnabled(GoogleString* disabled_reason);
105 
106  private:
107  class CssElement;
108  class CssStyleElement;
109  typedef std::vector<CssElement*> CssElementVector;
110 
111  void RememberFullCss(int pos,
112  HtmlElement* element,
113  HtmlCharactersNode* char_node);
114 
118  StringSet critical_selectors_;
119 
121  GoogleString cache_key_suffix_;
122 
126  CssElementVector css_elements_;
127 
129  bool saw_end_document_;
130 
132  bool any_rendered_;
133 
135  bool is_flush_script_added_;
136 
137 
138 };
139 
140 }
141 
142 #endif
Leaf node representing raw characters in HTML.
Definition: html_node.h:167
void RenderSummary(int pos, HtmlElement *element, HtmlCharactersNode *char_node, bool *is_element_deleted) override
Definition: critical_selector_filter.h:49
Definition: html_element.h:42
void WillNotRenderSummary(int pos, HtmlElement *element, HtmlCharactersNode *char_node) override
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: critical_selector_filter.h:66
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: critical_selector_filter.h:58
virtual bool IntendedForInlining() const
Selectors are inlined into the html.
Definition: critical_selector_filter.h:75
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
Definition: rewrite_driver.h:100
void Summarize(Css::Stylesheet *stylesheet, GoogleString *out) const override
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:137
ScriptUsage GetScriptUsage() const override
Definition: critical_selector_filter.h:76
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:496
virtual GoogleString CacheKeySuffix() const
Definition: css_summarizer_base.h:52