Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
css_inline_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 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_INLINE_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_INLINE_FILTER_H_
21 
22 #include <cstddef>
23 
24 #include "net/instaweb/rewriter/cached_result.pb.h"
35 
36 namespace net_instaweb {
37 
38 class Statistics;
39 class Variable;
40 
42 class CssInlineFilter : public CommonFilter {
43  public:
44  static const char kNumCssInlined[];
45 
46  explicit CssInlineFilter(RewriteDriver* driver);
47  virtual ~CssInlineFilter();
48 
49  virtual void StartDocumentImpl();
50  virtual void StartElementImpl(HtmlElement* element);
51  virtual void EndElementImpl(HtmlElement* element);
52  virtual const char* Name() const { return "InlineCss"; }
57  const {
58  return driver()->options()->HasInlineUnauthorizedResourceType(
59  semantic_type::kStylesheet) ?
60  RewriteDriver::kInlineUnauthorizedResources :
61  RewriteDriver::kInlineOnlyAuthorizedResources;
62  }
63  virtual bool IntendedForInlining() const { return true; }
64 
65  static void InitStats(Statistics* statistics);
66  static bool HasClosingStyleTag(StringPiece contents);
67 
68  protected:
71  void set_id(const char* id) { id_ = id; }
72 
75  virtual ResourcePtr CreateResource(const char* url, bool* is_authorized);
76 
77  void set_size_threshold_bytes(size_t size) { size_threshold_bytes_ = size; }
78 
79  private:
80  class Context;
81  friend class Context;
82 
83  bool ShouldInline(const ResourcePtr& resource,
84  const StringPiece& attrs_attribute,
85  GoogleString* reason) const;
86  void RenderInline(const ResourcePtr& resource, const CachedResult& cached,
87  const GoogleUrl& base_url, const StringPiece& text,
88  HtmlElement* element);
89 
90  const char* id_;
91  size_t size_threshold_bytes_;
92 
93  GoogleString domain_;
94 
95  Variable* num_css_inlined_;
96  bool in_body_;
97 
98 
99 };
100 
101 }
102 
103 #endif
Definition: common_filter.h:47
virtual bool IntendedForInlining() const
Definition: css_inline_filter.h:63
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Definition: html_element.h:42
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: css_inline_filter.h:52
virtual void StartDocumentImpl()
void set_id(const char *id)
Definition: css_inline_filter.h:71
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: rewrite_driver.h:100
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:137
Inline small CSS files.
Definition: css_inline_filter.h:42
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: css_inline_filter.h:56
virtual ResourcePtr CreateResource(const char *url, bool *is_authorized)
const GoogleUrl & base_url() const
Getters.
const RewriteOptions * options() const
Return the options used for this RewriteDriver.
Definition: rewrite_driver.h:496