Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: content/renderer/previews_state_helper.cc

Issue 2910783002: Adds Lo-Fi fallback support for new Data Reduction Proxy protocol. (Closed)
Patch Set: Added support for legacy Lo-Fi path (without Lite-Page enabled). Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/previews_state_helper.h"
6
7 #include "base/strings/string_split.h"
8
9 namespace content {
10
11 // Chrome Proxy Previews header and directives.
12 const char kChromeProxyHeader[] = "chrome-proxy";
13 const char kChromeProxyContentTransformHeader[] =
14 "chrome-proxy-content-transform";
15 const char kChromeProxyPagePoliciesDirective[] = "page-policies";
16 const char kChromeProxyEmptyImageDirective[] = "empty-image";
17 const char kChromeProxyLitePageDirective[] = "lite-page";
18
19 PreviewsState UpdatePreviewsStateFromMainFrameResponse(
20 PreviewsState original_state,
21 const blink::WebURLResponse& web_url_response) {
22 // First check if no previews were enabled for this request.
23 if (original_state == PREVIEWS_UNSPECIFIED)
24 return original_state;
25
26 // Next handle legacy path where Lite Page not enabled but Lo-Fi is enabled.
27 if (!(original_state & SERVER_LITE_PAGE_ON) &&
28 (original_state & SERVER_LOFI_ON)) {
sclittle 2017/06/01 00:59:29 I don't think this is quite right. If Server LoFi
dougarnett 2017/06/01 20:53:11 Adding an early return above if neither server pre
29 return original_state;
30 }
31
32 PreviewsState updated_state = original_state;
33
34 // Clear the Lite Page bit if Lite Page transformation did not occur.
sclittle 2017/06/01 00:59:29 Looking at the code here, it looks like if the DRP
dougarnett 2017/06/01 20:53:11 Let's discuss. It depends on when this method is c
dougarnett 2017/06/01 22:05:10 Done.
35 if (web_url_response
36 .HttpHeaderField(
37 blink::WebString::FromUTF8(kChromeProxyContentTransformHeader))
38 .Utf8() != kChromeProxyLitePageDirective) {
39 updated_state &= ~(SERVER_LITE_PAGE_ON);
40 }
41
42 // Determine whether to keep or clear Lo-Fi bits. We need to receive the
43 // empty-image policy directive and have SERVER_LOFI_ON in order to retain
44 // Lo-Fi bits.
45 if (!(updated_state & SERVER_LOFI_ON)) {
46 // Server Lo-Fi not enabled so ensure Client Lo-Fi off for this request.
sclittle 2017/06/01 00:59:29 Client LoFi shouldn't be dependent on Server LoFi
dougarnett 2017/06/01 20:53:11 No, that was not my understanding. I thought that
47 updated_state &= ~(CLIENT_LOFI_ON);
48 } else {
49 // Keep/clear Lo-Fi bits based on having empty-image policy directive.
50 bool has_empty_page_directive = false;
51 std::string chrome_proxy_value =
52 web_url_response
53 .HttpHeaderField(blink::WebString::FromUTF8(kChromeProxyHeader))
54 .Utf8();
55 size_t page_policies_pos =
sclittle 2017/06/01 00:59:29 Could you separate this string searching into a he
dougarnett 2017/06/01 20:53:11 Done.
56 chrome_proxy_value.find(kChromeProxyPagePoliciesDirective);
sclittle 2017/06/01 00:59:29 Could you just use base::SplitStringPiece here to
dougarnett 2017/06/01 20:53:11 Done.
57 if (page_policies_pos != std::string::npos) {
58 size_t end_pos =
59 chrome_proxy_value.find_first_of(" ,", page_policies_pos);
60 std::string page_policies_value = chrome_proxy_value.substr(
sclittle 2017/06/01 00:59:29 nit: Don't make an unnecessary copy of the std::st
dougarnett 2017/06/01 20:53:11 Done.
61 page_policies_pos + strlen(kChromeProxyPagePoliciesDirective) + 1,
sclittle 2017/06/01 00:59:29 nit: you can use arraysize or sizeof instead of st
dougarnett 2017/06/01 20:53:11 Done.
62 end_pos);
sclittle 2017/06/01 00:59:29 string::substr takes in a total number of characte
dougarnett 2017/06/01 20:53:11 Acknowledged.
63 for (const auto& policy :
64 base::SplitString(page_policies_value, "|", base::TRIM_WHITESPACE,
sclittle 2017/06/01 00:59:29 nit: use base::SplitStringPiece, not base::SplitSt
dougarnett 2017/06/01 20:53:11 Done.
65 base::SPLIT_WANT_NONEMPTY)) {
66 if (policy == kChromeProxyEmptyImageDirective) {
sclittle 2017/06/01 00:59:29 Use case-insensitive comparison, e.g. base::LowerC
dougarnett 2017/06/01 20:53:11 Done.
67 has_empty_page_directive = true;
68 break;
69 }
70 }
71 }
72 if (!has_empty_page_directive) {
73 updated_state &= ~(SERVER_LOFI_ON | CLIENT_LOFI_ON);
74 }
75 }
76
77 return updated_state;
78 }
79
80 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/previews_state_helper.h ('k') | content/renderer/previews_state_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698