Page Speed Optimization Libraries
1.4.26.1
|
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 class UserAgentMatcher; 00040 00041 typedef std::map<GoogleString, const Panel*> PanelIdToSpecMap; 00042 typedef std::multimap<GoogleString, std::pair<GoogleString, const int>, 00043 StringCompareInsensitive> AttributesToNonCacheableValuesMap; 00044 00045 namespace BlinkUtil { 00046 00047 const char kContiguous[] = "contiguous"; 00048 const char kCritical[] = "critical"; 00049 const char kPanelId[] = "panel-id"; 00050 const char kImages[] = "images"; 00051 const char kInstanceHtml[] = "instance_html"; 00052 const char kStartBodyMarker[] = "<!--GooglePanel **** Start body ****-->"; 00053 const char kEndBodyTag[] = "</body>"; 00054 const char kLayoutMarker[] = "<!--GooglePanel **** Layout end ****-->"; 00055 const char kJsonCachePrefix[] = "json:"; 00057 const char kBlinkResponseCodePropertyName[] = "blink_last_response_code"; 00058 const char kXpath[] = "xpath"; 00060 const char kBlinkCohort[] = "blink"; 00061 const char kBlinkCriticalLineDataPropertyName[] = "blink_critical_line_data"; 00062 const char kCacheHtmlRewriterInfo[] = "cache_html"; 00063 const char kComputeVisibleTextFilterOutputEndMarker[] = 00064 "<!--GooglePanel **** Output end ****-->"; 00065 00067 bool IsUserAgentAllowedForBlink(AsyncFetch* async_fetch, 00068 const RewriteOptions* options, 00069 const char* user_agent, 00070 UserAgentMatcher* user_agent_matcher); 00071 00073 bool IsBlinkRequest(const GoogleUrl& url, 00074 AsyncFetch* async_fetch, 00075 const RewriteOptions* options, 00076 const char* user_agent, 00077 UserAgentMatcher* user_agent_matcher_, 00078 RewriteOptions::Filter filter); 00079 00081 bool ShouldApplyBlinkFlowCriticalLine( 00082 const ServerContext* manager, 00083 const RewriteOptions* options); 00084 00087 bool IsJsonEmpty(const Json::Value& json); 00088 00090 void ClearArrayIfAllEmpty(Json::Value* json); 00091 00094 bool ComputePanels(const PanelSet* panel_set_, 00095 PanelIdToSpecMap* panel_id_to_spec); 00096 00098 void EscapeString(GoogleString* str); 00099 00101 bool StripTrailingNewline(GoogleString* s); 00102 00104 void PopulateAttributeToNonCacheableValuesMap( 00105 const RewriteOptions* rewrite_options, 00106 const GoogleUrl& url, 00107 AttributesToNonCacheableValuesMap* attribute_non_cacheable_values_map, 00108 std::vector<int>* panel_number_num_instances); 00109 00111 int GetPanelNumberForNonCacheableElement( 00112 const AttributesToNonCacheableValuesMap& attribute_non_cacheable_values_map, 00113 const HtmlElement* element); 00114 00116 GoogleString GetPanelId(int panel_number, int instance_number); 00117 } 00118 00119 } 00120 00121 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_