Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends 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/html/html_element.h"
37 #include "pagespeed/kernel/html/html_filter.h"
38 #include "pagespeed/kernel/html/html_node.h"
39 #include "pagespeed/kernel/http/semantic_type.h"
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 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  ScriptUsage GetScriptUsage() const override { return kWillInjectScripts; }
80 
81  protected:
87  virtual void Summarize(Css::Stylesheet* stylesheet,
88  GoogleString* out) const;
89  virtual void RenderSummary(int pos,
90  HtmlElement* element,
91  HtmlCharactersNode* char_node,
92  bool* is_element_deleted);
93  virtual void WillNotRenderSummary(int pos,
94  HtmlElement* element,
95  HtmlCharactersNode* char_node,
96  bool* is_element_deleted);
97 
100  virtual GoogleString CacheKeySuffix() const;
101 
103  virtual void StartDocumentImpl();
104  virtual void EndDocument();
105  virtual void RenderDone();
106 
108  virtual void DetermineEnabled(GoogleString* disabled_reason);
109 
110  private:
111  class CssElement;
112  class CssStyleElement;
113  typedef std::vector<CssElement*> CssElementVector;
114 
115  void RememberFullCss(int pos,
116  HtmlElement* element,
117  HtmlCharactersNode* char_node);
118 
119  bool IsCssFlushedEarly(const GoogleString& url) const;
120  void ApplyCssFlushedEarly(HtmlElement* element,
121  const GoogleString& style_id,
122  const char* media);
123 
127  StringSet critical_selectors_;
128 
130  GoogleString cache_key_suffix_;
131 
135  CssElementVector css_elements_;
136 
138  bool saw_end_document_;
139 
141  bool any_rendered_;
142 
144  bool is_flush_script_added_;
145 
146 
147 };
148 
149 }
150 
151 #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:490
virtual GoogleString CacheKeySuffix() const
Definition: css_summarizer_base.h:52