Page Speed Optimization Libraries  1.6.29.3
net/instaweb/rewriter/public/split_html_helper_filter.h
Go to the documentation of this file.
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_HELPER_FILTER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_HELPER_FILTER_H_
00021 
00022 #include <vector>
00023 
00024 #include "net/instaweb/rewriter/public/common_filter.h"
00025 #include "net/instaweb/rewriter/public/script_tag_scanner.h"
00026 #include "net/instaweb/util/public/basictypes.h"
00027 #include "net/instaweb/util/public/json.h"
00028 #include "net/instaweb/util/public/scoped_ptr.h"
00029 #include "net/instaweb/util/public/string.h"
00030 #include "pagespeed/kernel/base/json_writer.h"
00031 
00032 namespace net_instaweb {
00033 
00034 class HtmlElement;
00035 class RewriteDriver;
00036 class SplitHtmlConfig;
00037 class XpathUnit;
00038 
00049 class SplitHtmlHelperFilter : public CommonFilter {
00050  public:
00051   explicit SplitHtmlHelperFilter(RewriteDriver* rewrite_driver);
00052   virtual ~SplitHtmlHelperFilter();
00053 
00054   virtual void StartDocumentImpl();
00055   virtual void EndDocument();
00056 
00057   virtual void StartElementImpl(HtmlElement* element);
00058   virtual void EndElementImpl(HtmlElement* element);
00059 
00060   virtual const char* Name() const { return "SplitHtmlHelperFilter"; }
00061 
00062  private:
00064   GoogleString MatchPanelIdForElement(HtmlElement* element);
00065 
00067   bool IsElementParentOfCurrentPanel(HtmlElement* element);
00068 
00071   void EndPanelInstance();
00072 
00074   void StartPanelInstance(HtmlElement* element, const GoogleString& panelid);
00075 
00078   bool IsEndMarkerForCurrentPanel(HtmlElement* element);
00079 
00081   void AppendJsonData(Json::Value* dictionary, const Json::Value& dict);
00082 
00083   bool ElementMatchesXpath(const HtmlElement* element,
00084                            const std::vector<XpathUnit>& xpath_units);
00085 
00086   scoped_ptr<SplitHtmlConfig> config_;
00087   std::vector<ElementJsonPair> element_json_stack_;
00088   std::vector<int> num_children_stack_;
00089   GoogleString current_panel_id_;
00090   bool disable_filter_;
00091   bool inside_pagespeed_no_defer_script_;
00092   HtmlElement* current_panel_parent_element_;
00093   ScriptTagScanner script_tag_scanner_;
00094 
00095   DISALLOW_COPY_AND_ASSIGN(SplitHtmlHelperFilter);
00096 };
00097 
00098 }  
00099 
00100 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_HELPER_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines