Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
css_summarizer_base.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 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_SUMMARIZER_BASE_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_SUMMARIZER_BASE_H_
21 
22 #include <vector>
23 
31 
32 namespace Css {
33 
34 class Stylesheet;
35 
36 }
37 
38 namespace net_instaweb {
39 
40 class AbstractMutex;
41 class HtmlCharactersNode;
42 class RewriteContext;
43 class RewriteDriver;
44 class Statistics;
45 class Variable;
46 
53  public:
54  static const char kNumCssUsedForCriticalCssComputation[];
55  static const char kNumCssNotUsedForCriticalCssComputation[];
56 
57  explicit CssSummarizerBase(RewriteDriver* driver);
58  virtual ~CssSummarizerBase();
59 
60  static void InitStats(Statistics* statistics);
61 
62  protected:
63  enum SummaryState {
66 
69 
72 
76 
79 
82  };
83 
84  struct SummaryInfo {
85  SummaryInfo()
87  is_external(false),
88  is_inside_noscript(false) {}
89 
93 
96 
100 
103 
106 
109 
112 
115  };
116 
119  virtual GoogleString CacheKeySuffix() const;
120 
125  virtual bool MustSummarize(HtmlElement* element) const {
126  return true;
127  }
128 
136  virtual void Summarize(Css::Stylesheet* stylesheet,
137  GoogleString* out) const = 0;
138 
155  virtual void RenderSummary(int pos,
156  HtmlElement* element,
157  HtmlCharactersNode* char_node,
158  bool* is_element_deleted);
159 
167  virtual void WillNotRenderSummary(int pos,
168  HtmlElement* element,
169  HtmlCharactersNode* char_node);
170 
185  virtual void SummariesDone();
186 
191  int NumStyles() const { return static_cast<int>(summaries_.size()); }
192 
198  const SummaryInfo& GetSummaryForStyle(int pos) const {
199  return summaries_.at(pos);
200  }
201 
204  virtual void StartDocumentImpl();
205  virtual void EndDocument();
206  virtual void StartElementImpl(HtmlElement* element);
207  virtual void Characters(HtmlCharactersNode* characters);
208  virtual void EndElementImpl(HtmlElement* element);
209  virtual void RenderDone();
210 
212 
213  private:
214  class Context;
215 
217  void Clear();
218 
221  void ReportSummariesDone();
222 
225  void StartInlineRewrite(HtmlElement* style, HtmlCharactersNode* text);
226 
229  void StartExternalRewrite(HtmlElement* link, HtmlElement::Attribute* src,
230  StringPiece rel);
231 
237  Context* CreateContextAndSummaryInfo(const HtmlElement* element,
238  bool external,
239  const ResourceSlotPtr& slot,
240  const GoogleString& location,
241  StringPiece base_for_resources,
242  StringPiece rel);
243 
244  ResourceSlotPtr MakeSlotForInlineCss(HtmlCharactersNode* char_node);
245 
247  std::vector<SummaryInfo> summaries_;
248 
249  scoped_ptr<AbstractMutex> progress_lock_;
250  int outstanding_rewrites_;
251  bool saw_end_of_document_;
252  std::vector<int> canceled_summaries_;
256 
257  HtmlElement* style_element_;
258 
259  Variable* num_css_used_for_critical_css_computation_;
260  Variable* num_css_not_used_for_critical_css_computation_;
261 
262 
263 };
264 
265 }
266 
267 #endif
Definition: html_element.h:66
GoogleString location
Definition: css_summarizer_base.h:99
Definition: statistics.h:43
const SummaryInfo & GetSummaryForStyle(int pos) const
Definition: css_summarizer_base.h:198
Leaf node representing raw characters in HTML.
Definition: html_node.h:167
Slot got removed by an another optimization.
Definition: css_summarizer_base.h:81
virtual GoogleString CacheKeySuffix() const
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
CSS parse error we can't recover from.
Definition: css_summarizer_base.h:71
Definition: html_element.h:42
virtual void Summarize(Css::Stylesheet *stylesheet, GoogleString *out) const =0
Definition: ref_counted_ptr.h:69
Definition: css_summarizer_base.h:84
Fetch result unusable, either error or not cacheable.
Definition: css_summarizer_base.h:78
bool is_inside_noscript
True if the style was included inside a noscript section.
Definition: css_summarizer_base.h:114
Definition: scoped_ptr.h:30
Computation/Fetches ongoing, we don't have a result yet.
Definition: css_summarizer_base.h:68
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
GoogleString rel
If it's an external stylesheet, the value of the rel attribute.
Definition: css_summarizer_base.h:108
All OK!
Definition: css_summarizer_base.h:65
bool is_external
True if it's a <link rel=stylesheet href=>, false for <style>
Definition: css_summarizer_base.h:111
Definition: rewrite_filter.h:35
SummaryState state
State of computation of 'data'.
Definition: css_summarizer_base.h:95
Definition: rewrite_driver.h:100
int NumStyles() const
Definition: css_summarizer_base.h:191
Definition: rewrite_context.h:155
SummaryState
Definition: css_summarizer_base.h:63
virtual void Characters(HtmlCharactersNode *characters)
virtual void WillNotRenderSummary(int pos, HtmlElement *element, HtmlCharactersNode *char_node)
virtual void RenderSummary(int pos, HtmlElement *element, HtmlCharactersNode *char_node, bool *is_element_deleted)
GoogleString media_from_html
CSS media there were applied to the resource by the HTML.
Definition: css_summarizer_base.h:105
GoogleString base
Base to use for resolving links in the CSS resource.
Definition: css_summarizer_base.h:102
virtual bool MustSummarize(HtmlElement *element) const
Definition: css_summarizer_base.h:125
virtual RewriteContext * MakeRewriteContext()
GoogleString data
Definition: css_summarizer_base.h:92
Definition: css_summarizer_base.h:52