Page Speed Optimization Libraries
1.7.30.1
|
00001 /* 00002 * Copyright 2013 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_CONFIG_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_CONFIG_H_ 00021 00022 #include <map> 00023 #include <vector> 00024 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/string.h" 00027 00028 namespace net_instaweb { 00029 00030 class CriticalLineInfo; 00031 class HtmlElement; 00032 class Panel; 00033 class RewriteDriver; 00034 00035 struct XpathUnit { 00036 XpathUnit() : child_number(0) {} 00037 00038 GoogleString tag_name; 00039 GoogleString attribute_value; 00040 int child_number; 00041 }; 00042 00043 typedef std::map<GoogleString, const Panel*> PanelIdToSpecMap; 00044 typedef std::vector<XpathUnit> XpathUnits; 00046 typedef std::map<GoogleString, XpathUnits*> XpathMap; 00047 00050 class SplitHtmlConfig { 00051 public: 00055 explicit SplitHtmlConfig(RewriteDriver* driver); 00056 ~SplitHtmlConfig(); 00057 00059 static void Initialize(); 00060 static void Terminate(); 00061 00062 const CriticalLineInfo* critical_line_info() const { 00063 return critical_line_info_; 00064 } 00065 00066 const XpathMap* xpath_map() const { 00067 return &xpath_map_; 00068 } 00069 00070 const PanelIdToSpecMap* panel_id_to_spec() const { 00071 return &panel_id_to_spec_; 00072 } 00073 00074 const RewriteDriver* driver() const { return driver_; } 00075 00076 private: 00078 RewriteDriver* driver_; 00079 00080 const CriticalLineInfo* critical_line_info_; 00081 00083 XpathMap xpath_map_; 00084 00086 PanelIdToSpecMap panel_id_to_spec_; 00087 00088 DISALLOW_COPY_AND_ASSIGN(SplitHtmlConfig); 00089 }; 00090 00092 class SplitHtmlState { 00093 public: 00094 explicit SplitHtmlState(const SplitHtmlConfig* config); 00095 ~SplitHtmlState(); 00096 00097 std::vector<int>* num_children_stack() { return &num_children_stack_; } 00098 00099 bool ElementMatchesXpath( 00100 const HtmlElement* element, 00101 const std::vector<XpathUnit>& xpath_units) const; 00102 00104 GoogleString MatchPanelIdForElement(HtmlElement* element) const; 00105 00108 bool IsElementSiblingOfCurrentPanel(HtmlElement* element) const; 00109 00111 bool IsElementParentOfCurrentPanel(HtmlElement* element) const; 00112 00115 bool IsEndMarkerForCurrentPanel(HtmlElement* element) const; 00116 00117 const HtmlElement* current_panel_parent_element() const { 00118 return current_panel_parent_element_; 00119 } 00120 00121 void set_current_panel_parent_element(HtmlElement* element) { 00122 current_panel_parent_element_ = element; 00123 } 00124 00125 const GoogleString& current_panel_id() const { 00126 return current_panel_id_; 00127 } 00128 00129 void set_current_panel_id(const GoogleString& panel_id) { 00130 current_panel_id_ = panel_id; 00131 } 00132 00133 void UpdateNumChildrenStack(const HtmlElement* element); 00134 00135 private: 00137 const SplitHtmlConfig* config_; 00138 00140 std::vector<int> num_children_stack_; 00141 00143 HtmlElement* current_panel_parent_element_; 00144 00145 GoogleString current_panel_id_; 00146 00147 DISALLOW_COPY_AND_ASSIGN(SplitHtmlState); 00148 }; 00149 00150 } 00151 00152 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_CONFIG_H_