Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
css_tag_scanner.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_TAG_SCANNER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_TAG_SCANNER_H_
21 
27 
28 namespace net_instaweb {
29 
30 class MessageHandler;
31 class RewriteOptions;
32 class ServerContext;
33 class Writer;
34 
36  public:
39  class Transformer {
40  public:
41  virtual ~Transformer();
42 
43  enum TransformStatus { kSuccess, kNoChange, kFailure };
50  virtual TransformStatus Transform(GoogleString* str) = 0;
51  };
52 
53  static const char kStylesheet[];
54  static const char kAlternate[];
55  static const char kUriValue[];
56 
61  CssTagScanner(Transformer* transformer, MessageHandler* handler);
62 
68  static bool ParseCssElement(HtmlElement* element,
70  const char** media,
71  StringPieceVector* nonstandard_attributes);
72 
75  static bool ParseCssElement(HtmlElement* element,
77  const char** media) {
78  return ParseCssElement(element, href, media,
79  NULL );
80  }
81 
85  enum InputPortion {
86  kInputIncludesEnd,
87  kInputDoesNotIncludeEnd
88  };
89 
94  static bool TransformUrls(
95  StringPiece contents, Writer* writer, Transformer* transformer,
96  MessageHandler* handler);
97 
104  StringPiece contents, InputPortion input_portion, Writer* writer);
105 
108  GoogleString RetainedForReparse() const { return reparse_; }
109 
112  static bool HasImport(const StringPiece& contents, MessageHandler* handler);
113 
115  static bool HasUrl(const StringPiece& contents);
116 
119  static bool IsStylesheetOrAlternate(const StringPiece& attribute_value);
120 
122  static bool IsAlternateStylesheet(const StringPiece& attribute_value);
123 
124  private:
125  enum UrlKind {
126  kNone,
127  kImport,
128  kUrl
129  };
130 
131  void SerializeUrlUse(UrlKind kind, const GoogleString& url,
132  bool is_quoted, bool have_term_quote, char quote,
133  bool have_term_paren,
134  Writer* writer, bool* ok);
135 
136  Transformer* transformer_;
137  MessageHandler* handler_;
138  GoogleString reparse_;
139 
140 
141 };
142 
148  public:
149  RewriteDomainTransformer(const GoogleUrl* old_base_url,
150  const GoogleUrl* new_base_url,
151  const ServerContext* server_context,
152  const RewriteOptions* options,
153  MessageHandler* handler);
154  virtual ~RewriteDomainTransformer();
155 
156  virtual TransformStatus Transform(GoogleString* str);
157 
158  void set_trim_urls(bool x) { trim_urls_ = x; }
159 
160  private:
161  const GoogleUrl* old_base_url_;
162  const GoogleUrl* new_base_url_;
163 
164  const ServerContext* server_context_;
165  const RewriteOptions* options_;
166  MessageHandler* handler_;
167 
168  bool trim_urls_;
169 
170 
171 };
172 
173 
174 }
175 
176 #endif
class GoogleUrl
Definition: google_url.h:58
Definition: css_tag_scanner.h:39
Definition: html_element.h:66
static bool HasUrl(const StringPiece &contents)
Detemines whether this CSS contains a URI value (aka URL).
static bool IsAlternateStylesheet(const StringPiece &attribute_value)
Does this rel attribute value represent an alternate stylesheet?
Definition: css_tag_scanner.h:147
static bool TransformUrls(StringPiece contents, Writer *writer, Transformer *transformer, MessageHandler *handler)
static bool IsStylesheetOrAlternate(const StringPiece &attribute_value)
GoogleString RetainedForReparse() const
Definition: css_tag_scanner.h:108
Definition: html_element.h:42
InputPortion
Definition: css_tag_scanner.h:85
static bool ParseCssElement(HtmlElement *element, HtmlElement::Attribute **href, const char **media)
Definition: css_tag_scanner.h:75
CssTagScanner(Transformer *transformer, MessageHandler *handler)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual TransformStatus Transform(GoogleString *str)
static bool HasImport(const StringPiece &contents, MessageHandler *handler)
static bool ParseCssElement(HtmlElement *element, HtmlElement::Attribute **href, const char **media, StringPieceVector *nonstandard_attributes)
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: server_context.h:99
Definition: css_tag_scanner.h:35
bool TransformUrlsStreaming(StringPiece contents, InputPortion input_portion, Writer *writer)
Definition: message_handler.h:39
Definition: rewrite_options.h:84
virtual TransformStatus Transform(GoogleString *str)=0