Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
make_show_ads_async_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  */
17 
18 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_MAKE_SHOW_ADS_ASYNC_FILTER_H_
19 #define NET_INSTAWEB_REWRITER_PUBLIC_MAKE_SHOW_ADS_ASYNC_FILTER_H_
20 
22 #include "pagespeed/kernel/base/string.h"
23 #include "pagespeed/opt/ads/show_ads_snippet_parser.h"
24 #include "pagespeed/kernel/base/basictypes.h"
25 
26 namespace net_instaweb {
27 
28 class HtmlCharactersNode;
29 class HtmlElement;
30 class RewriteDriver;
31 class Statistics;
32 class Variable;
33 
37  public:
38  static const char kShowAdsSnippetsConverted[];
39  static const char kShowAdsSnippetsNotConverted[];
40  static const char kShowAdsApiReplacedForAsync[];
41 
42  explicit MakeShowAdsAsyncFilter(RewriteDriver* rewrite_driver);
43  virtual ~MakeShowAdsAsyncFilter();
44 
45  static void InitStats(Statistics* statistics);
46 
48  virtual void StartDocumentImpl();
49  virtual void StartElementImpl(HtmlElement* element);
50  virtual void EndElementImpl(HtmlElement* element);
51 
53  virtual const char* Name() const {
54  return "MakeShowAdsAsyncFilter";
55  }
56  virtual void Characters(HtmlCharactersNode* characters);
57 
58  private:
66  bool IsApplicableShowAds(
67  const GoogleString& content,
68  ShowAdsSnippetParser::AttributeMap* parsed_attributes) const;
69 
73  void ReplaceShowAdsWithAdsByGoogleElement(
74  const ShowAdsSnippetParser::AttributeMap& parsed_attributes,
75  HtmlElement* show_ads_elment);
76  void ReplaceShowAdsApiCallWithAdsByGoogleApiCall(
77  HtmlElement* show_ads_elment);
78 
80  HtmlElement* current_script_element_;
82  GoogleString current_script_element_contents_;
83 
112  bool has_ads_by_google_js_;
118  int32 num_pending_show_ads_api_call_replacements_;
119 
120  ShowAdsSnippetParser show_ads_snippet_parser_;
121 
123  Variable* show_ads_snippets_converted_count_;
124  Variable* show_ads_snippets_not_converted_count_;
125  Variable* show_ads_api_replaced_for_async_;
126 
127  DISALLOW_COPY_AND_ASSIGN(MakeShowAdsAsyncFilter);
128 };
129 
130 }
131 
132 #endif
Definition: common_filter.h:48
virtual const char * Name() const
Overrides HtmlFilter.
Definition: make_show_ads_async_filter.h:53
virtual void StartDocumentImpl()
Overrides CommonFilter.
Definition: rewrite_driver.h:98
virtual void Characters(HtmlCharactersNode *characters)
Definition: make_show_ads_async_filter.h:36