2
* Copyright 2012 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: gagansingh@google.com (Gagan Singh)
19
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_
20
#define NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_
26
#include "net/instaweb/rewriter/public/rewrite_options.h"
27
#include "net/instaweb/util/public/json.h"
28
#include "net/instaweb/util/public/string.h"
29
#include "net/instaweb/util/public/string_util.h"
31
namespace net_instaweb {
40
typedef std::map<GoogleString, const Panel*> PanelIdToSpecMap;
41
typedef std::multimap<GoogleString, std::pair<GoogleString, const int>,
42
StringCompareInsensitive> AttributesToNonCacheableValuesMap;
46
const char kContiguous[] = "contiguous";
47
const char kCritical[] = "critical";
48
const char kPanelId[] = "panel-id";
49
const char kImages[] = "images";
50
const char kInstanceHtml[] = "instance_html";
51
const char kStartBodyMarker[] = "<!--GooglePanel **** Start body ****-->";
52
const char kEndBodyTag[] = "</body>";
53
const char kLayoutMarker[] = "<!--GooglePanel **** Layout end ****-->";
54
const char kJsonCachePrefix[] = "json:";
55
// TODO(mmohabey): Use RewriteDriver::kStatusCodePropertyName here.
56
const char kBlinkResponseCodePropertyName[] = "blink_last_response_code";
57
const char kXpath[] = "xpath";
58
// TODO(rahulbansal): Use these constants everywhere in the code from here.
59
const char kBlinkCohort[] = "blink";
60
const char kBlinkCriticalLineDataPropertyName[] = "blink_critical_line_data";
61
const char kCacheHtmlRewriterInfo[] = "cache_html";
62
const char kComputeVisibleTextFilterOutputEndMarker[] =
63
"<!--GooglePanel **** Output end ****-->";
65
// Checks whether the request for 'url' is a valid blink request.
66
bool IsBlinkRequest(const GoogleUrl& url,
67
AsyncFetch* async_fetch,
68
const RewriteOptions* options,
69
const char* user_agent,
70
const ServerContext* server_context,
71
RewriteOptions::Filter filter);
73
// Returns true if json has only miscellaneous(like 'contiguous')
75
bool IsJsonEmpty(const Json::Value& json);
77
// Clears the json array if all objects are empty.
78
void ClearArrayIfAllEmpty(Json::Value* json);
80
// Computes panel id to specification map and returns if any non cacheable
81
// panels are present.
82
bool ComputePanels(const PanelSet* panel_set_,
83
PanelIdToSpecMap* panel_id_to_spec);
85
// Escapes < and > with __psa_lt; and __psa_gt; respectively.
86
void EscapeString(GoogleString* str);
88
// TODO(rahulbansal): Move this function to net/instaweb/util/string_util
89
bool StripTrailingNewline(GoogleString* s);
91
// Populates the attributes to non cacheable values map.
92
void PopulateAttributeToNonCacheableValuesMap(
93
const RewriteOptions* rewrite_options,
95
AttributesToNonCacheableValuesMap* attribute_non_cacheable_values_map,
96
std::vector<int>* panel_number_num_instances);
98
// Returns panel number for non cacheable element. If cacheable returns -1.
99
int GetPanelNumberForNonCacheableElement(
100
const AttributesToNonCacheableValuesMap& attribute_non_cacheable_values_map,
101
const HtmlElement* element);
103
// Gets panel id for the given panel instance.
104
GoogleString GetPanelId(int panel_number, int instance_number);
105
} // namespace BlinkUtil
107
} // namespace net_instaweb
109
#endif // NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_