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

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 integration test the excercises page-polices fallback 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 {
megjablon 2017/06/05 23:47:58 move the anonymous namespace inside content namesp
dougarnett 2017/06/06 16:49:46 Done.
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 bool HasEmptyPageDirective(const blink::WebURLResponse& web_url_response) {
megjablon 2017/06/05 23:47:59 s/HasEmptyPageDirective/HasEmptyImageDirective/?
dougarnett 2017/06/06 16:49:46 Yuck! Thanks!
20 std::string chrome_proxy_value =
megjablon 2017/06/05 23:47:59 #include <string>
dougarnett 2017/06/06 16:49:46 Done.
21 web_url_response
22 .HttpHeaderField(blink::WebString::FromUTF8(kChromeProxyHeader))
megjablon 2017/06/05 23:47:58 #include "third_party/WebKit/public/platform/WebSt
dougarnett 2017/06/06 16:49:46 Done.
23 .Utf8();
24 for (const auto& directive :
25 base::SplitStringPiece(chrome_proxy_value, ",", base::TRIM_WHITESPACE,
26 base::SPLIT_WANT_NONEMPTY)) {
27 if (!base::StartsWith(directive, kChromeProxyPagePoliciesDirective,
megjablon 2017/06/05 23:47:58 #include "base/strings/string_util.cc"
dougarnett 2017/06/06 16:49:46 Done.
28 base::CompareCase::INSENSITIVE_ASCII)) {
29 continue;
30 }
31
32 // Check policy directive for empty-image entry.
33 base::StringPiece page_policies_value = base::StringPiece(directive).substr(
megjablon 2017/06/05 23:47:59 #include "base/strings/string_piece.h"
dougarnett 2017/06/06 16:49:46 Done.
34 arraysize(kChromeProxyPagePoliciesDirective));
megjablon 2017/06/05 23:47:58 #include "src/base/macros.h"
dougarnett 2017/06/06 16:49:46 Done.
35 for (const auto& policy :
36 base::SplitStringPiece(page_policies_value, "|", base::TRIM_WHITESPACE,
37 base::SPLIT_WANT_NONEMPTY)) {
38 if (base::LowerCaseEqualsASCII(policy, kChromeProxyEmptyImageDirective)) {
39 return true;
40 }
41 }
42 }
43 return false;
44 }
45
46 } // namespace
47
48 namespace content {
49
50 PreviewsState UpdatePreviewsStateFromMainFrameResponse(
51 PreviewsState original_state,
52 const blink::WebURLResponse& web_url_response) {
53 // Only update the state if there was a server preview requested.
54 if (!(original_state & SERVER_LITE_PAGE_ON) &&
55 !(original_state & SERVER_LOFI_ON))
56 return original_state;
megjablon 2017/06/05 23:47:58 if statement is more than two lines, add braces.
dougarnett 2017/06/06 16:49:46 Done.
57
58 // Next handle legacy path where Lite Page not enabled but Lo-Fi is enabled.
59 if (!(original_state & SERVER_LITE_PAGE_ON) &&
60 (original_state & SERVER_LOFI_ON)) {
megjablon 2017/06/05 23:47:58 Just want to make sure, in the updated protocol ca
dougarnett 2017/06/06 16:49:46 We don't want to since SERVER_LITE_PAGE_ON => acce
61 return original_state;
62 }
63
64 // At this point, we have a proxy main frame response for which we want
megjablon 2017/06/05 23:47:58 Don't use we.
dougarnett 2017/06/06 16:49:46 Done.
65 // to update the PreviewsState from what was enabled/accepted by the client
66 // to what the client should actually do based on the server response.
67
68 PreviewsState updated_state = original_state;
69
70 // Clear the Lite Page bit if Lite Page transformation did not occur.
71 if (web_url_response
72 .HttpHeaderField(
73 blink::WebString::FromUTF8(kChromeProxyContentTransformHeader))
74 .Utf8() != kChromeProxyLitePageDirective) {
75 updated_state &= ~(SERVER_LITE_PAGE_ON);
76 }
77
78 // Determine whether to keep or clear Lo-Fi bits. We need to receive the
79 // empty-image policy directive and have SERVER_LOFI_ON in order to retain
80 // Lo-Fi bits.
81 if (!(updated_state & SERVER_LOFI_ON)) {
megjablon 2017/06/05 23:47:59 Even though it's the same, I'd use original_state
dougarnett 2017/06/06 16:49:46 Done.
82 // Server Lo-Fi not enabled so ensure Client Lo-Fi off for this request.
83 updated_state &= ~(CLIENT_LOFI_ON);
84 } else if (!HasEmptyPageDirective(web_url_response)) {
85 updated_state &= ~(SERVER_LOFI_ON | CLIENT_LOFI_ON);
86 }
87
megjablon 2017/06/05 23:47:58 Can we check here if we cleared all the bits and i
dougarnett 2017/06/06 16:49:46 Done.
88 return updated_state;
89 }
90
91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698