Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
critical_css_beacon_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 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_CSS_BEACON_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_CSS_BEACON_FILTER_H_
21 
32 
33 namespace Css {
34 
35 class Ruleset;
36 class Stylesheet;
37 
38 }
39 
40 namespace net_instaweb {
41 
42 class Statistics;
43 class Variable;
44 
51  public:
52  static const char kInitializePageSpeedJs[];
53 
55  static const char kCriticalCssBeaconAddedCount[];
56  static const char kCriticalCssNoBeaconDueToMissingData[];
57  static const char kCriticalCssSkippedDueToCharset[];
58 
59  explicit CriticalCssBeaconFilter(RewriteDriver* driver);
60  virtual ~CriticalCssBeaconFilter();
61 
62  static void InitStats(Statistics* statistics);
63 
64  virtual const char* Name() const { return "CriticalCssBeacon"; }
65  virtual const char* id() const { return "cb"; }
66 
72  const {
73  return driver()->options()->HasInlineUnauthorizedResourceType(
74  semantic_type::kStylesheet) ?
75  RewriteDriver::kInlineUnauthorizedResources :
76  RewriteDriver::kInlineOnlyAuthorizedResources;
77  }
78 
80  virtual bool IntendedForInlining() const { return true; }
81  ScriptUsage GetScriptUsage() const override { return kWillInjectScripts; }
82 
83  protected:
84  virtual bool MustSummarize(HtmlElement* element) const;
85  virtual void Summarize(Css::Stylesheet* stylesheet,
86  GoogleString* out) const;
87  virtual void SummariesDone();
88 
89  virtual void DetermineEnabled(GoogleString* disabled_reason);
90 
91  private:
92  static void FindSelectorsFromRuleset(const Css::Ruleset& ruleset,
93  StringSet* selectors);
95  static void FindSelectorsFromStylesheet(const Css::Stylesheet& css,
96  StringSet* selectors);
97 
99  void AppendSelectorsInitJs(GoogleString* script, const StringSet& selectors);
100 
102  void AppendBeaconInitJs(const BeaconMetadata& metadata, GoogleString* script);
103 
105  Variable* critical_css_beacon_added_count_;
108  Variable* critical_css_no_beacon_due_to_missing_data_;
111  Variable* critical_css_skipped_due_to_charset_;
112 
113 
114 };
115 
116 }
117 
118 #endif
virtual bool MustSummarize(HtmlElement *element) const
Definition: statistics.h:43
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: critical_css_beacon_filter.h:64
virtual void DetermineEnabled(GoogleString *disabled_reason)
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
virtual void Summarize(Css::Stylesheet *stylesheet, GoogleString *out) const
virtual bool IntendedForInlining() const
Selectors are inlined into javascript.
Definition: critical_css_beacon_filter.h:80
Definition: html_element.h:42
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: critical_css_beacon_filter.h:71
Definition: critical_finder_support_util.h:78
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
Definition: critical_css_beacon_filter.h:50
Definition: rewrite_driver.h:100
static const char kCriticalCssBeaconAddedCount[]
Statistics:
Definition: critical_css_beacon_filter.h:55
ScriptUsage GetScriptUsage() const override
Definition: critical_css_beacon_filter.h:81
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:137
const RewriteOptions * options() const
Return the options used for this RewriteDriver.
Definition: rewrite_driver.h:496
Definition: css_summarizer_base.h:52