Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
mobilize_rewrite_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 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_MOBILIZE_REWRITE_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_MOBILIZE_REWRITE_FILTER_H_
21 
26 #include "pagespeed/kernel/base/basictypes.h"
27 #include "pagespeed/kernel/base/statistics.h"
28 #include "pagespeed/kernel/base/string.h"
29 #include "pagespeed/kernel/base/string_util.h"
30 #include "pagespeed/kernel/html/html_element.h"
31 #include "pagespeed/kernel/html/html_filter.h"
32 #include "pagespeed/kernel/http/user_agent_matcher.h"
33 
34 namespace net_instaweb {
35 
74  public:
75  static const char kPagesMobilized[];
76 
77  explicit MobilizeRewriteFilter(RewriteDriver* rewrite_driver);
78  virtual ~MobilizeRewriteFilter();
79 
80  static void InitStats(Statistics* statistics);
81 
83  static bool IsApplicableFor(RewriteDriver* driver);
84  static bool IsApplicableFor(const RewriteOptions* options,
85  const char* user_agent,
86  const UserAgentMatcher* matcher);
87  virtual void DetermineEnabled(GoogleString* disabled_reason);
88  virtual void StartDocumentImpl();
89  virtual void EndDocument();
90  virtual void RenderDone();
91  virtual void StartElementImpl(HtmlElement* element);
92  virtual void EndElementImpl(HtmlElement* element);
93  virtual const char* Name() const { return "MobilizeRewrite"; }
94  ScriptUsage GetScriptUsage() const override { return kWillInjectScripts; }
95 
96  private:
97  void AppendStylesheet(StringPiece css_file_name,
98  StaticAssetEnum::StaticAsset asset,
99  HtmlElement* element);
100  void AddStyle(HtmlElement* element);
101 
102  GoogleString GetMobJsInitScript();
103 
104  int body_element_depth_;
105  bool added_viewport_;
106  bool added_style_;
107  bool added_spacer_;
108  bool saw_end_document_;
109 
112  Variable* num_pages_mobilized_;
113 
116 
117 
118 };
119 
120 }
121 
122 #endif
Definition: common_filter.h:47
Definition: rewrite_driver.h:98
static bool IsApplicableFor(RewriteDriver *driver)
True if options or request UA suggest we will actually do mobilization.
Definition: mobilize_rewrite_filter.h:73
Definition: rewrite_options.h:84
friend class MobilizeRewriteFilterTest
Used for overriding default behavior in testing.
Definition: mobilize_rewrite_filter.h:115