Page Speed Optimization Libraries
1.2.24.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/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 AsyncFetch; 00033 class GoogleUrl; 00034 class HtmlElement; 00035 class Panel; 00036 class PanelSet; 00037 class ServerContext; 00038 class RewriteOptions; 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 kComputeVisibleTextFilterOutputEndMarker[] = 00063 "<!--GooglePanel **** Output end ****-->"; 00064 00066 bool IsUserAgentAllowedForBlink(AsyncFetch* async_fetch, 00067 const RewriteOptions* options, 00068 const char* user_agent, 00069 const UserAgentMatcher& user_agent_matcher); 00070 00072 bool IsBlinkRequest(const GoogleUrl& url, 00073 AsyncFetch* async_fetch, 00074 const RewriteOptions* options, 00075 const char* user_agent, 00076 const UserAgentMatcher& user_agent_matcher_); 00077 00079 bool ShouldApplyBlinkFlowCriticalLine( 00080 const ServerContext* manager, 00081 const RewriteOptions* options); 00082 00085 bool IsJsonEmpty(const Json::Value& json); 00086 00088 void ClearArrayIfAllEmpty(Json::Value* json); 00089 00092 bool ComputePanels(const PanelSet* panel_set_, 00093 PanelIdToSpecMap* panel_id_to_spec); 00094 00096 void EscapeString(GoogleString* str); 00097 00099 bool StripTrailingNewline(GoogleString* s); 00100 00102 void PopulateAttributeToNonCacheableValuesMap( 00103 const RewriteOptions* rewrite_options, 00104 const GoogleUrl& url, 00105 AttributesToNonCacheableValuesMap* attribute_non_cacheable_values_map, 00106 std::vector<int>* panel_number_num_instances); 00107 00109 int GetPanelNumberForNonCacheableElement( 00110 const AttributesToNonCacheableValuesMap& attribute_non_cacheable_values_map, 00111 const HtmlElement* element); 00112 00114 GoogleString GetPanelId(int panel_number, int instance_number); 00115 } 00116 00117 } 00118 00119 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_