Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends 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 
26 #include "pagespeed/kernel/base/basictypes.h"
27 #include "pagespeed/kernel/base/string.h"
28 #include "pagespeed/kernel/base/string_util.h"
29 #include "pagespeed/kernel/html/empty_html_filter.h"
30 #include "pagespeed/kernel/html/html_element.h"
31 #include "pagespeed/kernel/html/html_node.h"
32 #include "pagespeed/kernel/http/google_url.h"
33 #include "pagespeed/kernel/http/response_headers.h"
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, bool* is_authorized);
101 
106  ResourcePtr CreateInputResourceOrInsertDebugComment(StringPiece input_url,
107  HtmlElement* element);
108 
111  void ResolveUrl(StringPiece input_url, GoogleUrl* out_url);
112 
117  bool BaseUrlIsValid() const;
118 
123  bool DebugMode() const { return driver_->DebugMode(); }
124 
137  static bool ExtractMetaTagDetails(const HtmlElement& element,
138  const ResponseHeaders* headers,
139  GoogleString* content,
140  GoogleString* mime_type,
141  GoogleString* charset);
142 
147  bool CanAddPagespeedOnloadToImage(const HtmlElement&);
148 
153  virtual void LogFilterModifiedContent();
154 
159  const { return RewriteDriver::kInlineOnlyAuthorizedResources; }
160 
164  virtual bool IntendedForInlining() const { return false; }
165 
168  void AddJsToElement(StringPiece js, HtmlElement* script);
169 
170  protected:
171  ServerContext* server_context() const { return server_context_; }
172  const RewriteOptions* rewrite_options() { return rewrite_options_; }
173 
177  virtual void StartDocumentImpl() = 0;
178  virtual void StartElementImpl(HtmlElement* element) = 0;
179  virtual void EndElementImpl(HtmlElement* element) = 0;
180 
183  virtual const char* LoggingId() { return Name(); }
184 
185  private:
187  RewriteDriver* driver_;
188  ServerContext* server_context_;
189  const RewriteOptions* rewrite_options_;
190  HtmlElement* noscript_element_;
192  HtmlElement* end_body_point_;
193  bool seen_base_;
194 
195 
196 };
197 
198 }
199 
200 #endif
ResourcePtr CreateInputResourceOrInsertDebugComment(StringPiece input_url, HtmlElement *element)
Definition: common_filter.h:47
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: common_filter.h:158
virtual void StartDocumentImpl()=0
bool DebugMode() const
Definition: common_filter.h:123
void AddJsToElement(StringPiece js, HtmlElement *script)
void InsertNodeAtBodyEnd(HtmlNode *data)
virtual const char * LoggingId()
Definition: common_filter.h:183
bool CanAddPagespeedOnloadToImage(const HtmlElement &)
bool DebugMode() const
Definition: rewrite_driver.h:1123
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:100
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: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:164
ResourcePtr CreateInputResource(StringPiece input_url, bool *is_authorized)
Definition: rewrite_options.h:84
static bool ExtractMetaTagDetails(const HtmlElement &element, const ResponseHeaders *headers, GoogleString *content, GoogleString *mime_type, GoogleString *charset)