Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
split_html_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 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_SPLIT_HTML_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_FILTER_H_
21 
22 #include <vector>
23 
29 #include "net/instaweb/util/public/json.h"
30 #include "net/instaweb/util/public/json_writer.h"
31 #include "net/instaweb/util/public/null_writer.h"
35 
36 namespace net_instaweb {
37 
38 class HtmlElement;
39 class RewriteOptions;
40 class SplitHtmlConfig;
41 class SplitHtmlState;
42 class StaticAssetManager;
43 class Writer;
44 
47 
51  public:
52  static const char kSplitSuffixJsFormatString[];
53  static const char kSplitTwoChunkSuffixJsFormatString[];
54  static const char kLoadHiResImages[];
55  static const char kMetaReferer[];
56 
57  explicit SplitHtmlFilter(RewriteDriver* rewrite_driver);
58  virtual ~SplitHtmlFilter();
59 
60  virtual void DetermineEnabled(GoogleString* disabled_reason);
61 
62  virtual void StartDocument();
63  virtual void EndDocument();
64 
65  virtual void StartElement(HtmlElement* element);
66  virtual void EndElement(HtmlElement* element);
67 
68  static const GoogleString& GetBlinkJsUrl(
69  const RewriteOptions* options,
70  const StaticAssetManager* static_asset_manager);
71 
72  virtual const char* Name() const { return "SplitHtmlFilter"; }
73 
74  private:
75  const SplitHtmlConfig* config() const {
76  return driver()->split_html_config();
77  }
78  const StaticAssetManager* static_asset_manager() const {
79  return driver()->server_context()->static_asset_manager();
80  }
81 
82  void ServeNonCriticalPanelContents(const Json::Value& json);
83 
86  void MarkElementWithPanelId(HtmlElement* element,
87  const GoogleString& panel_id);
88 
90  GoogleString GetPanelIdForInstance(HtmlElement* element);
91 
93  GoogleString GenerateCriticalLineConfigString();
94 
97  void EndPanelInstance();
98 
100  void StartPanelInstance(HtmlElement* element);
101 
103  void InsertPanelStub(HtmlElement* element, const GoogleString& panel_id);
104 
106  void AppendJsonData(Json::Value* dictionary, const Json::Value& dict);
107 
108  void WriteString(const StringPiece& str);
109 
113  void InsertSplitInitScripts(HtmlElement* element);
114 
115  void InvokeBaseHtmlFilterStartDocument();
116 
117  void InvokeBaseHtmlFilterStartElement(HtmlElement* element);
118 
119  void InvokeBaseHtmlFilterEndElement(HtmlElement* element);
120 
121  void InvokeBaseHtmlFilterEndDocument();
122 
127  bool IsAllowedCrossDomainRequest(StringPiece cross_origin);
128 
129  scoped_ptr<SplitHtmlState> state_;
130  const RewriteOptions* options_;
131  std::vector<ElementJsonPair> element_json_stack_;
132  Json::FastWriter fast_writer_;
133  scoped_ptr<JsonWriter> json_writer_;
134  Writer* original_writer_;
135  NullWriter null_writer_;
136  StringPiece url_;
137  bool script_written_;
138  bool flush_head_enabled_;
139  bool disable_filter_;
140  bool inside_pagespeed_no_defer_script_;
141  bool serve_response_in_two_chunks_;
142  int last_script_index_before_panel_stub_;
143  bool panel_seen_;
144  ScriptTagScanner script_tag_scanner_;
145 
146  DISALLOW_COPY_AND_ASSIGN(SplitHtmlFilter);
147 };
148 
149 }
150 
151 #endif
Definition: static_asset_manager.h:44
Definition: split_html_config.h:50
Definition: rewrite_driver.h:98
Definition: script_tag_scanner.h:30
Definition: suppress_prehead_filter.h:41
Definition: split_html_filter.h:50
Definition: rewrite_options.h:81