Page Speed Optimization Libraries
1.6.29.3
|
00001 /* 00002 * Copyright 2012 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_FILTER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_FILTER_H_ 00021 00022 #include <vector> 00023 00024 #include "net/instaweb/rewriter/public/script_tag_scanner.h" 00025 #include "net/instaweb/rewriter/public/suppress_prehead_filter.h" 00026 #include "net/instaweb/util/public/basictypes.h" 00027 #include "net/instaweb/util/public/json.h" 00028 #include "net/instaweb/util/public/json_writer.h" 00029 #include "net/instaweb/util/public/null_writer.h" 00030 #include "net/instaweb/util/public/scoped_ptr.h" 00031 #include "net/instaweb/util/public/string.h" 00032 #include "net/instaweb/util/public/string_util.h" 00033 00034 namespace net_instaweb { 00035 00036 class HtmlElement; 00037 class RewriteDriver; 00038 class RewriteOptions; 00039 class SplitHtmlConfig; 00040 class StaticAssetManager; 00041 class Writer; 00042 class XpathUnit; 00043 00046 00049 class SplitHtmlFilter : public SuppressPreheadFilter { 00050 public: 00051 static const char kSplitSuffixJsFormatString[]; 00052 static const char kSplitTwoChunkSuffixJsFormatString[]; 00053 static const char kLoadHiResImages[]; 00054 static const char kMetaReferer[]; 00055 00056 explicit SplitHtmlFilter(RewriteDriver* rewrite_driver); 00057 virtual ~SplitHtmlFilter(); 00058 00059 virtual void StartDocument(); 00060 virtual void EndDocument(); 00061 00062 virtual void StartElement(HtmlElement* element); 00063 virtual void EndElement(HtmlElement* element); 00064 00065 static const GoogleString& GetBlinkJsUrl( 00066 const RewriteOptions* options, 00067 StaticAssetManager* static_asset_manager); 00068 00069 virtual const char* Name() const { return "SplitHtmlFilter"; } 00070 00071 private: 00072 void ServeNonCriticalPanelContents(const Json::Value& json); 00073 00076 void MarkElementWithPanelId(HtmlElement* element, 00077 const GoogleString& panel_id); 00078 00080 GoogleString GetPanelIdForInstance(HtmlElement* element); 00081 00083 GoogleString MatchPanelIdForElement(HtmlElement* element); 00084 00086 GoogleString GenerateCriticalLineConfigString(); 00087 00090 bool IsElementSiblingOfCurrentPanel(HtmlElement* element); 00091 00093 bool IsElementParentOfCurrentPanel(HtmlElement* element); 00094 00097 void EndPanelInstance(); 00098 00100 void StartPanelInstance(HtmlElement* element); 00101 00103 void InsertPanelStub(HtmlElement* element, const GoogleString& panel_id); 00104 00107 bool IsEndMarkerForCurrentPanel(HtmlElement* element); 00108 00110 void AppendJsonData(Json::Value* dictionary, const Json::Value& dict); 00111 00112 void WriteString(const StringPiece& str); 00113 00117 void InsertSplitInitScripts(HtmlElement* element); 00118 00119 bool ElementMatchesXpath(const HtmlElement* element, 00120 const std::vector<XpathUnit>& xpath_units); 00121 00122 void InvokeBaseHtmlFilterStartDocument(); 00123 00124 void InvokeBaseHtmlFilterStartElement(HtmlElement* element); 00125 00126 void InvokeBaseHtmlFilterEndElement(HtmlElement* element); 00127 00128 void InvokeBaseHtmlFilterEndDocument(); 00129 00134 bool IsAllowedCrossDomainRequest(StringPiece cross_origin); 00135 00136 RewriteDriver* rewrite_driver_; 00137 scoped_ptr<SplitHtmlConfig> config_; 00138 const RewriteOptions* options_; 00139 std::vector<ElementJsonPair> element_json_stack_; 00140 std::vector<int> num_children_stack_; 00141 Json::FastWriter fast_writer_; 00142 scoped_ptr<JsonWriter> json_writer_; 00143 Writer* original_writer_; 00144 NullWriter null_writer_; 00145 GoogleString current_panel_id_; 00146 StringPiece url_; 00147 bool script_written_; 00148 bool flush_head_enabled_; 00149 bool disable_filter_; 00150 bool inside_pagespeed_no_defer_script_; 00151 bool serve_response_in_two_chunks_; 00152 int last_script_index_before_panel_stub_; 00153 bool panel_seen_; 00154 HtmlElement* current_panel_parent_element_; 00155 StaticAssetManager* static_asset_manager_; 00156 ScriptTagScanner script_tag_scanner_; 00157 00158 DISALLOW_COPY_AND_ASSIGN(SplitHtmlFilter); 00159 }; 00160 00161 } 00162 00163 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_FILTER_H_