00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_
00021
00022 #include <map>
00023 #include <utility>
00024 #include <vector>
00025
00026 #include "net/instaweb/util/public/json.h"
00027 #include "net/instaweb/util/public/string.h"
00028 #include "net/instaweb/util/public/string_util.h"
00029
00030 namespace net_instaweb {
00031
00032 class GoogleUrl;
00033 class HtmlElement;
00034 class Layout;
00035 class Panel;
00036 class PanelSet;
00037 class PublisherConfig;
00038 class RequestHeaders;
00039 class ResourceManager;
00040 class RewriteOptions;
00041 class UserAgentMatcher;
00042
00043 typedef std::map<GoogleString, const Panel*> PanelIdToSpecMap;
00044 typedef std::multimap<GoogleString, std::pair<GoogleString, const int> >
00045 AttributesToNonCacheableValuesMap;
00046
00047 namespace BlinkUtil {
00048
00049 const char kContiguous[] = "contiguous";
00050 const char kCritical[] = "critical";
00051 const char kPanelId[] = "panel-id";
00052 const char kImages[] = "images";
00053 const char kInstanceHtml[] = "instance_html";
00054 const char kStartBodyMarker[] = "<!--GooglePanel **** Start body ****-->";
00055 const char kEndBodyTag[] = "</body>";
00056 const char kLayoutMarker[] = "<!--GooglePanel **** Layout end ****-->";
00057 const char kJsonCachePrefix[] = "json:";
00058 const char kBlinkResponseCodePropertyName[] = "blink_last_response_code";
00059
00061 bool IsBlinkRequest(const GoogleUrl& url,
00062 const RequestHeaders* request_headers,
00063 const RewriteOptions* options,
00064 const char* user_agent,
00065 const UserAgentMatcher& user_agent_matcher_);
00066
00068 bool ShouldApplyBlinkFlowCriticalLine(
00069 const ResourceManager* manager,
00070 const RewriteOptions* options);
00071
00073 const Layout* ExtractBlinkLayout(const GoogleUrl& url, RewriteOptions* options,
00074 const StringPiece& user_agent);
00075
00077 const Layout* FindLayout(const PublisherConfig& config,
00078 const GoogleUrl& request_url);
00079
00082 void SplitCritical(const Json::Value& complete_json,
00083 const PanelIdToSpecMap& panel_id_to_spec,
00084 GoogleString* critical_json_str,
00085 GoogleString* non_critical_json_str,
00086 GoogleString* pushed_images_str);
00087
00090 void SplitCriticalArray(const Json::Value& complete_json,
00091 const PanelIdToSpecMap& panel_id_to_spec,
00092 Json::Value* critical_json,
00093 Json::Value* non_cacheable_json,
00094 Json::Value* non_critical_json,
00095 bool panel_valid,
00096 int num_critical_instances,
00097 Json::Value* pushed_images);
00100 void SplitCriticalObj(const Json::Value& json_obj,
00101 const PanelIdToSpecMap& panel_id_to_spec,
00102 Json::Value* critical_obj,
00103 Json::Value* non_cacheable_obj,
00104 Json::Value* non_critical_obj,
00105 bool panel_cacheable,
00106 Json::Value* pushed_images);
00109 bool IsJsonEmpty(const Json::Value& json);
00110
00112 void ClearArrayIfAllEmpty(Json::Value* json);
00113
00115 void DeleteImagesFromJson(Json::Value* json);
00116
00119 bool ComputePanels(const PanelSet* panel_set_,
00120 PanelIdToSpecMap* panel_id_to_spec);
00121
00123 void EscapeString(GoogleString* str);
00124
00126 bool StripTrailingNewline(GoogleString* s);
00127
00129 StringPiece GetNonCacheableElements(
00130 const GoogleString& atf_non_cacheable_elements, const GoogleUrl& url);
00131
00133 void PopulateAttributeToNonCacheableValuesMap(
00134 const GoogleString& atf_non_cacheable_elements,
00135 const GoogleUrl& url,
00136 AttributesToNonCacheableValuesMap* attribute_non_cacheable_values_map,
00137 std::vector<int>* panel_number_num_instances);
00138
00140 int GetPanelNumberForNonCacheableElement(
00141 const AttributesToNonCacheableValuesMap&
00142 attribute_non_cacheable_values_map,
00143 const HtmlElement* element);
00144
00146 GoogleString GetPanelId(int panel_number, int instance_number);
00147 }
00148
00149 }
00150
00151 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_