Page Speed Optimization Libraries
1.8.31.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_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/rewriter/public/rewrite_options.h" 00027 #include "net/instaweb/util/public/json.h" 00028 #include "net/instaweb/util/public/string.h" 00029 #include "net/instaweb/util/public/string_util.h" 00030 00031 namespace net_instaweb { 00032 00033 class AsyncFetch; 00034 class GoogleUrl; 00035 class HtmlElement; 00036 class Panel; 00037 class PanelSet; 00038 class ServerContext; 00039 00040 typedef std::map<GoogleString, const Panel*> PanelIdToSpecMap; 00041 typedef std::multimap<GoogleString, std::pair<GoogleString, const int>, 00042 StringCompareInsensitive> AttributesToNonCacheableValuesMap; 00043 00044 namespace BlinkUtil { 00045 00046 const char kContiguous[] = "contiguous"; 00047 const char kCritical[] = "critical"; 00048 const char kPanelId[] = "panel-id"; 00049 const char kImages[] = "images"; 00050 const char kInstanceHtml[] = "instance_html"; 00051 const char kStartBodyMarker[] = "<!--GooglePanel **** Start body ****-->"; 00052 const char kEndBodyTag[] = "</body>"; 00053 const char kLayoutMarker[] = "<!--GooglePanel **** Layout end ****-->"; 00054 const char kJsonCachePrefix[] = "json:"; 00056 const char kBlinkResponseCodePropertyName[] = "blink_last_response_code"; 00057 const char kXpath[] = "xpath"; 00059 const char kBlinkCohort[] = "blink"; 00060 const char kBlinkCriticalLineDataPropertyName[] = "blink_critical_line_data"; 00061 const char kCacheHtmlRewriterInfo[] = "cache_html"; 00062 const char kComputeVisibleTextFilterOutputEndMarker[] = 00063 "<!--GooglePanel **** Output end ****-->"; 00064 00066 bool IsBlinkRequest(const GoogleUrl& url, 00067 AsyncFetch* async_fetch, 00068 const RewriteOptions* options, 00069 const char* user_agent, 00070 const ServerContext* server_context, 00071 RewriteOptions::Filter filter); 00072 00075 bool IsJsonEmpty(const Json::Value& json); 00076 00078 void ClearArrayIfAllEmpty(Json::Value* json); 00079 00082 bool ComputePanels(const PanelSet* panel_set_, 00083 PanelIdToSpecMap* panel_id_to_spec); 00084 00086 void EscapeString(GoogleString* str); 00087 00089 bool StripTrailingNewline(GoogleString* s); 00090 00092 void PopulateAttributeToNonCacheableValuesMap( 00093 const RewriteOptions* rewrite_options, 00094 const GoogleUrl& url, 00095 AttributesToNonCacheableValuesMap* attribute_non_cacheable_values_map, 00096 std::vector<int>* panel_number_num_instances); 00097 00099 int GetPanelNumberForNonCacheableElement( 00100 const AttributesToNonCacheableValuesMap& attribute_non_cacheable_values_map, 00101 const HtmlElement* element); 00102 00104 GoogleString GetPanelId(int panel_number, int instance_number); 00105 } 00106 00107 } 00108 00109 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_