forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle_url_loader_throttle.cc
66 lines (56 loc) · 2.43 KB
/
google_url_loader_throttle.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/google_url_loader_throttle.h"
#include "chrome/common/net/safe_search_util.h"
#include "components/variations/net/variations_http_headers.h"
GoogleURLLoaderThrottle::GoogleURLLoaderThrottle(
bool is_off_the_record,
bool force_safe_search,
int32_t youtube_restrict,
const std::string& allowed_domains_for_apps,
const std::string& variation_ids_header)
: is_off_the_record_(is_off_the_record),
force_safe_search_(force_safe_search),
youtube_restrict_(youtube_restrict),
allowed_domains_for_apps_(allowed_domains_for_apps),
variation_ids_header_(variation_ids_header) {}
GoogleURLLoaderThrottle::~GoogleURLLoaderThrottle() {}
void GoogleURLLoaderThrottle::DetachFromCurrentSequence() {}
void GoogleURLLoaderThrottle::WillStartRequest(
network::ResourceRequest* request,
bool* defer) {
if (!is_off_the_record_ &&
variations::ShouldAppendVariationHeaders(request->url) &&
!variation_ids_header_.empty()) {
request->headers.SetHeaderIfMissing(variations::kClientDataHeader,
variation_ids_header_);
}
if (force_safe_search_) {
GURL new_url;
safe_search_util::ForceGoogleSafeSearch(request->url, &new_url);
if (!new_url.is_empty())
request->url = new_url;
}
static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0,
"OFF must be first");
if (youtube_restrict_ > safe_search_util::YOUTUBE_RESTRICT_OFF &&
youtube_restrict_ < safe_search_util::YOUTUBE_RESTRICT_COUNT) {
safe_search_util::ForceYouTubeRestrict(
request->url, &request->headers,
static_cast<safe_search_util::YouTubeRestrictMode>(youtube_restrict_));
}
if (!allowed_domains_for_apps_.empty() &&
request->url.DomainIs("google.com")) {
request->headers.SetHeader(safe_search_util::kGoogleAppsAllowedDomains,
allowed_domains_for_apps_);
}
}
void GoogleURLLoaderThrottle::WillRedirectRequest(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
bool* defer,
std::vector<std::string>* to_be_removed_headers) {
if (!variations::ShouldAppendVariationHeaders(redirect_info.new_url))
to_be_removed_headers->push_back(variations::kClientDataHeader);
}