~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/blink_util.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2012 Google Inc.
3
 
 *
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
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
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.
15
 
 */
16
 
 
17
 
// Author: gagansingh@google.com (Gagan Singh)
18
 
 
19
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_
20
 
#define NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_
21
 
 
22
 
#include <map>
23
 
#include <utility>
24
 
#include <vector>
25
 
 
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"
30
 
 
31
 
namespace net_instaweb {
32
 
 
33
 
class AsyncFetch;
34
 
class GoogleUrl;
35
 
class HtmlElement;
36
 
class Panel;
37
 
class PanelSet;
38
 
class ServerContext;
39
 
 
40
 
typedef std::map<GoogleString, const Panel*> PanelIdToSpecMap;
41
 
typedef std::multimap<GoogleString, std::pair<GoogleString, const int>,
42
 
        StringCompareInsensitive> AttributesToNonCacheableValuesMap;
43
 
 
44
 
namespace BlinkUtil {
45
 
 
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 ****-->";
64
 
 
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);
72
 
 
73
 
// Returns true if json has only miscellaneous(like 'contiguous')
74
 
// atributes.
75
 
bool IsJsonEmpty(const Json::Value& json);
76
 
 
77
 
// Clears the json array if all objects are empty.
78
 
void ClearArrayIfAllEmpty(Json::Value* json);
79
 
 
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);
84
 
 
85
 
// Escapes < and > with __psa_lt; and __psa_gt; respectively.
86
 
void EscapeString(GoogleString* str);
87
 
 
88
 
// TODO(rahulbansal): Move this function to net/instaweb/util/string_util
89
 
bool StripTrailingNewline(GoogleString* s);
90
 
 
91
 
// Populates the attributes to non cacheable values map.
92
 
void PopulateAttributeToNonCacheableValuesMap(
93
 
    const RewriteOptions* rewrite_options,
94
 
    const GoogleUrl& url,
95
 
    AttributesToNonCacheableValuesMap* attribute_non_cacheable_values_map,
96
 
    std::vector<int>* panel_number_num_instances);
97
 
 
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);
102
 
 
103
 
// Gets panel id for the given panel instance.
104
 
GoogleString GetPanelId(int panel_number, int instance_number);
105
 
}  // namespace BlinkUtil
106
 
 
107
 
}  // namespace net_instaweb
108
 
 
109
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_BLINK_UTIL_H_