Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
common_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_COMMON_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_COMMON_FILTER_H_
21 
24 #include "pagespeed/kernel/base/basictypes.h"
25 #include "pagespeed/kernel/base/string.h"
26 #include "pagespeed/kernel/base/string_util.h"
27 #include "pagespeed/kernel/html/empty_html_filter.h"
28 
29 namespace net_instaweb {
30 class GoogleUrl;
31 class HtmlCharactersNode;
32 class HtmlElement;
33 class HtmlNode;
34 class ResponseHeaders;
35 class RewriteOptions;
36 class ServerContext;
37 
48 class CommonFilter : public EmptyHtmlFilter {
49  public:
51  static const char kCreateResourceFailedDebugMsg[];
52 
53  explicit CommonFilter(RewriteDriver* driver);
54  virtual ~CommonFilter();
55 
57 
59  const GoogleUrl& base_url() const;
60 
63  const GoogleUrl& decoded_base_url() const;
64 
65  RewriteDriver* driver() const { return driver_; }
66  HtmlElement* noscript_element() const { return noscript_element_; }
67 
81  void InsertNodeAtBodyEnd(HtmlNode* data);
82 
84  virtual void StartDocument();
85  virtual void StartElement(HtmlElement* element);
86  virtual void EndElement(HtmlElement* element);
87 
91  virtual void Characters(HtmlCharactersNode* characters);
92 
101  ResourcePtr CreateInputResource(StringPiece input_url, bool* is_authorized);
102 
107  ResourcePtr CreateInputResourceOrInsertDebugComment(StringPiece input_url,
108  HtmlElement* element);
109 
112  void ResolveUrl(StringPiece input_url, GoogleUrl* out_url);
113 
118  bool BaseUrlIsValid() const;
119 
124  bool DebugMode() const { return driver_->DebugMode(); }
125 
138  static bool ExtractMetaTagDetails(const HtmlElement& element,
139  const ResponseHeaders* headers,
140  GoogleString* content,
141  GoogleString* mime_type,
142  GoogleString* charset);
143 
148  bool CanAddPagespeedOnloadToImage(const HtmlElement&);
149 
154  virtual void LogFilterModifiedContent();
155 
160  const { return RewriteDriver::kInlineOnlyAuthorizedResources; }
161 
165  virtual bool IntendedForInlining() const { return false; }
166 
167  protected:
168  ServerContext* server_context() const { return server_context_; }
169  const RewriteOptions* rewrite_options() { return rewrite_options_; }
170 
174  virtual void StartDocumentImpl() = 0;
175  virtual void StartElementImpl(HtmlElement* element) = 0;
176  virtual void EndElementImpl(HtmlElement* element) = 0;
177 
180  virtual const char* LoggingId() { return Name(); }
181 
182  private:
184  RewriteDriver* driver_;
185  ServerContext* server_context_;
186  const RewriteOptions* rewrite_options_;
187  HtmlElement* noscript_element_;
189  HtmlElement* end_body_point_;
190  bool seen_base_;
191 
192  DISALLOW_COPY_AND_ASSIGN(CommonFilter);
193 };
194 
195 }
196 
197 #endif
ResourcePtr CreateInputResourceOrInsertDebugComment(StringPiece input_url, HtmlElement *element)
Definition: common_filter.h:48
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: common_filter.h:159
virtual void StartDocumentImpl()=0
bool DebugMode() const
Definition: common_filter.h:124
void InsertNodeAtBodyEnd(HtmlNode *data)
virtual const char * LoggingId()
Definition: common_filter.h:180
bool CanAddPagespeedOnloadToImage(const HtmlElement &)
bool DebugMode() const
Definition: rewrite_driver.h:1070
virtual void Characters(HtmlCharactersNode *characters)
virtual void LogFilterModifiedContent()
bool BaseUrlIsValid() const
void ResolveUrl(StringPiece input_url, GoogleUrl *out_url)
Definition: rewrite_driver.h:98
Definition: server_context.h:101
static const char kCreateResourceFailedDebugMsg[]
Debug message to be inserted when resource creation fails.
Definition: common_filter.h:51
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:135
const GoogleUrl & decoded_base_url() const
virtual void StartDocument()
Note: Don't overload these methods, overload the implementers instead!
const GoogleUrl & base_url() const
Getters.
virtual bool IntendedForInlining() const
Definition: common_filter.h:165
ResourcePtr CreateInputResource(StringPiece input_url, bool *is_authorized)
Definition: rewrite_options.h:83
static bool ExtractMetaTagDetails(const HtmlElement &element, const ResponseHeaders *headers, GoogleString *content, GoogleString *mime_type, GoogleString *charset)