Page Speed Optimization Libraries  1.13.35.1
 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 
34 
35 namespace net_instaweb {
36 
47 class CommonFilter : public EmptyHtmlFilter {
48  public:
50  static const char kCreateResourceFailedDebugMsg[];
51 
52  explicit CommonFilter(RewriteDriver* driver);
53  virtual ~CommonFilter();
54 
56 
58  const GoogleUrl& base_url() const;
59 
62  const GoogleUrl& decoded_base_url() const;
63 
64  RewriteDriver* driver() const { return driver_; }
65  HtmlElement* noscript_element() const { return noscript_element_; }
66 
80  void InsertNodeAtBodyEnd(HtmlNode* data);
81 
83  virtual void StartDocument();
84  virtual void StartElement(HtmlElement* element);
85  virtual void EndElement(HtmlElement* element);
86 
90  virtual void Characters(HtmlCharactersNode* characters);
91 
100  ResourcePtr CreateInputResource(StringPiece input_url,
102  bool* is_authorized);
103 
109  StringPiece input_url, RewriteDriver::InputRole role,
110  HtmlElement* element);
111 
114  void ResolveUrl(StringPiece input_url, GoogleUrl* out_url);
115 
116  bool IsRelativeUrlLoadPermittedByCsp(StringPiece url, CspDirective role);
117 
122  bool BaseUrlIsValid() const;
123 
128  bool DebugMode() const { return driver_->DebugMode(); }
129 
142  static bool ExtractMetaTagDetails(const HtmlElement& element,
143  const ResponseHeaders* headers,
144  GoogleString* content,
145  GoogleString* mime_type,
146  GoogleString* charset);
147 
153 
158  virtual void LogFilterModifiedContent();
159 
164  const { return RewriteDriver::kInlineOnlyAuthorizedResources; }
165 
169  virtual bool IntendedForInlining() const { return false; }
170 
173  void AddJsToElement(StringPiece js, HtmlElement* script);
174 
175  protected:
176  ServerContext* server_context() const { return server_context_; }
177  const RewriteOptions* rewrite_options() { return rewrite_options_; }
178 
182  virtual void StartDocumentImpl() = 0;
183  virtual void StartElementImpl(HtmlElement* element) = 0;
184  virtual void EndElementImpl(HtmlElement* element) = 0;
185 
188  virtual const char* LoggingId() { return Name(); }
189 
190  private:
192  RewriteDriver* driver_;
193  ServerContext* server_context_;
194  const RewriteOptions* rewrite_options_;
195  HtmlElement* noscript_element_;
197  HtmlElement* end_body_point_;
198  bool seen_base_;
199 
200 
201 };
202 
203 }
204 
205 #endif
class GoogleUrl
Definition: google_url.h:58
Definition: common_filter.h:47
virtual void StartElement(HtmlElement *element)
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: common_filter.h:163
virtual void StartDocumentImpl()=0
bool DebugMode() const
Definition: common_filter.h:128
void AddJsToElement(StringPiece js, HtmlElement *script)
Definition: empty_html_filter.h:37
void InsertNodeAtBodyEnd(HtmlNode *data)
virtual const char * LoggingId()
Definition: common_filter.h:188
ResourcePtr CreateInputResourceOrInsertDebugComment(StringPiece input_url, RewriteDriver::InputRole role, HtmlElement *element)
bool CanAddPagespeedOnloadToImage(const HtmlElement &)
bool DebugMode() const
Definition: rewrite_driver.h:1137
Definition: html_element.h:42
Read/write API for HTTP response headers.
Definition: response_headers.h:37
CspDirective
Definition: csp_directive.h:37
virtual void Characters(HtmlCharactersNode *characters)
InputRole
Definition: rewrite_driver.h:611
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual void LogFilterModifiedContent()
bool BaseUrlIsValid() const
void ResolveUrl(StringPiece input_url, GoogleUrl *out_url)
Definition: rewrite_driver.h:100
Definition: server_context.h:99
static const char kCreateResourceFailedDebugMsg[]
Debug message to be inserted when resource creation fails.
Definition: common_filter.h:50
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:137
const GoogleUrl & decoded_base_url() const
virtual void StartDocument()
Note: Don't overload these methods, overload the implementers instead!
virtual const char * Name() const =0
The name of this filter – used for logging and debugging.
const GoogleUrl & base_url() const
Getters.
virtual bool IntendedForInlining() const
Definition: common_filter.h:169
Definition: rewrite_options.h:84
static bool ExtractMetaTagDetails(const HtmlElement &element, const ResponseHeaders *headers, GoogleString *content, GoogleString *mime_type, GoogleString *charset)
ResourcePtr CreateInputResource(StringPiece input_url, RewriteDriver::InputRole role, bool *is_authorized)