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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_resource_throttle.cc

Issue 1808653003: Move the supervised user error page to a component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h" 5 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/sparse_histogram.h" 8 #include "base/metrics/sparse_histogram.h"
9 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" 9 #include "chrome/browser/supervised_user/supervised_user_interstitial.h"
10 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h" 10 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
(...skipping 30 matching lines...) Expand all
41 41
42 static_assert(kHistogramPageTransitionMaxKnownValue < 42 static_assert(kHistogramPageTransitionMaxKnownValue <
43 kHistogramPageTransitionFallbackValue, 43 kHistogramPageTransitionFallbackValue,
44 "HistogramPageTransition MaxKnownValue must be < FallbackValue"); 44 "HistogramPageTransition MaxKnownValue must be < FallbackValue");
45 static_assert(FILTERING_BEHAVIOR_MAX * kHistogramFilteringBehaviorSpacing + 45 static_assert(FILTERING_BEHAVIOR_MAX * kHistogramFilteringBehaviorSpacing +
46 kHistogramPageTransitionFallbackValue < kHistogramMax, 46 kHistogramPageTransitionFallbackValue < kHistogramMax,
47 "Invalid HistogramMax value"); 47 "Invalid HistogramMax value");
48 48
49 int GetHistogramValueForFilteringBehavior( 49 int GetHistogramValueForFilteringBehavior(
50 SupervisedUserURLFilter::FilteringBehavior behavior, 50 SupervisedUserURLFilter::FilteringBehavior behavior,
51 SupervisedUserURLFilter::FilteringBehaviorReason reason, 51 supervised_user_error_page::FilteringBehaviorReason reason,
52 bool uncertain) { 52 bool uncertain) {
53 switch (behavior) { 53 switch (behavior) {
54 case SupervisedUserURLFilter::ALLOW: 54 case SupervisedUserURLFilter::ALLOW:
55 case SupervisedUserURLFilter::WARN: 55 case SupervisedUserURLFilter::WARN:
56 return uncertain ? FILTERING_BEHAVIOR_ALLOW_UNCERTAIN 56 return uncertain ? FILTERING_BEHAVIOR_ALLOW_UNCERTAIN
57 : FILTERING_BEHAVIOR_ALLOW; 57 : FILTERING_BEHAVIOR_ALLOW;
58 case SupervisedUserURLFilter::BLOCK: 58 case SupervisedUserURLFilter::BLOCK:
59 switch (reason) { 59 switch (reason) {
60 case SupervisedUserURLFilter::BLACKLIST: 60 case supervised_user_error_page::BLACKLIST:
61 return FILTERING_BEHAVIOR_BLOCK_BLACKLIST; 61 return FILTERING_BEHAVIOR_BLOCK_BLACKLIST;
62 case SupervisedUserURLFilter::ASYNC_CHECKER: 62 case supervised_user_error_page::ASYNC_CHECKER:
63 return FILTERING_BEHAVIOR_BLOCK_SAFESITES; 63 return FILTERING_BEHAVIOR_BLOCK_SAFESITES;
64 case SupervisedUserURLFilter::WHITELIST: 64 case supervised_user_error_page::WHITELIST:
65 NOTREACHED(); 65 NOTREACHED();
66 break; 66 break;
67 case SupervisedUserURLFilter::MANUAL: 67 case supervised_user_error_page::MANUAL:
68 return FILTERING_BEHAVIOR_BLOCK_MANUAL; 68 return FILTERING_BEHAVIOR_BLOCK_MANUAL;
69 case SupervisedUserURLFilter::DEFAULT: 69 case supervised_user_error_page::DEFAULT:
70 return FILTERING_BEHAVIOR_BLOCK_DEFAULT; 70 return FILTERING_BEHAVIOR_BLOCK_DEFAULT;
71 } 71 }
72 case SupervisedUserURLFilter::INVALID: 72 case SupervisedUserURLFilter::INVALID:
73 NOTREACHED(); 73 NOTREACHED();
74 } 74 }
75 return 0; 75 return 0;
76 } 76 }
77 77
78 int GetHistogramValueForTransitionType(ui::PageTransition transition_type) { 78 int GetHistogramValueForTransitionType(ui::PageTransition transition_type) {
79 int value = 79 int value =
80 static_cast<int>(ui::PageTransitionStripQualifier(transition_type)); 80 static_cast<int>(ui::PageTransitionStripQualifier(transition_type));
81 if (0 <= value && value <= kHistogramPageTransitionMaxKnownValue) 81 if (0 <= value && value <= kHistogramPageTransitionMaxKnownValue)
82 return value; 82 return value;
83 NOTREACHED(); 83 NOTREACHED();
84 return kHistogramPageTransitionFallbackValue; 84 return kHistogramPageTransitionFallbackValue;
85 } 85 }
86 86
87 void RecordFilterResultEvent( 87 void RecordFilterResultEvent(
88 bool safesites_histogram, 88 bool safesites_histogram,
89 SupervisedUserURLFilter::FilteringBehavior behavior, 89 SupervisedUserURLFilter::FilteringBehavior behavior,
90 SupervisedUserURLFilter::FilteringBehaviorReason reason, 90 supervised_user_error_page::FilteringBehaviorReason reason,
91 bool uncertain, 91 bool uncertain,
92 ui::PageTransition transition_type) { 92 ui::PageTransition transition_type) {
93 int value = 93 int value =
94 GetHistogramValueForFilteringBehavior(behavior, reason, uncertain) * 94 GetHistogramValueForFilteringBehavior(behavior, reason, uncertain) *
95 kHistogramFilteringBehaviorSpacing + 95 kHistogramFilteringBehaviorSpacing +
96 GetHistogramValueForTransitionType(transition_type); 96 GetHistogramValueForTransitionType(transition_type);
97 DCHECK_LT(value, kHistogramMax); 97 DCHECK_LT(value, kHistogramMax);
98 // Note: We can't pass in the histogram name as a parameter to this function 98 // Note: We can't pass in the histogram name as a parameter to this function
99 // because of how the macro works (look up the histogram on the first 99 // because of how the macro works (look up the histogram on the first
100 // invocation and cache it in a static variable). 100 // invocation and cache it in a static variable).
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 DCHECK_EQ(got_result, behavior_ != SupervisedUserURLFilter::INVALID); 135 DCHECK_EQ(got_result, behavior_ != SupervisedUserURLFilter::INVALID);
136 // If we got a "not blocked" result synchronously, don't defer. 136 // If we got a "not blocked" result synchronously, don't defer.
137 *defer = deferred_ = !got_result || 137 *defer = deferred_ = !got_result ||
138 (behavior_ == SupervisedUserURLFilter::BLOCK); 138 (behavior_ == SupervisedUserURLFilter::BLOCK);
139 if (got_result) 139 if (got_result)
140 behavior_ = SupervisedUserURLFilter::INVALID; 140 behavior_ = SupervisedUserURLFilter::INVALID;
141 } 141 }
142 142
143 void SupervisedUserResourceThrottle::ShowInterstitial( 143 void SupervisedUserResourceThrottle::ShowInterstitial(
144 const GURL& url, 144 const GURL& url,
145 SupervisedUserURLFilter::FilteringBehaviorReason reason) { 145 supervised_user_error_page::FilteringBehaviorReason reason) {
146 const content::ResourceRequestInfo* info = 146 const content::ResourceRequestInfo* info =
147 content::ResourceRequestInfo::ForRequest(request_); 147 content::ResourceRequestInfo::ForRequest(request_);
148 BrowserThread::PostTask( 148 BrowserThread::PostTask(
149 BrowserThread::UI, FROM_HERE, 149 BrowserThread::UI, FROM_HERE,
150 base::Bind( 150 base::Bind(
151 &SupervisedUserNavigationObserver::OnRequestBlocked, 151 &SupervisedUserNavigationObserver::OnRequestBlocked,
152 info->GetWebContentsGetterForRequest(), url, reason, 152 info->GetWebContentsGetterForRequest(), url, reason,
153 base::Bind(&SupervisedUserResourceThrottle::OnInterstitialResult, 153 base::Bind(&SupervisedUserResourceThrottle::OnInterstitialResult,
154 weak_ptr_factory_.GetWeakPtr()))); 154 weak_ptr_factory_.GetWeakPtr())));
155 } 155 }
156 156
157 void SupervisedUserResourceThrottle::WillStartRequest(bool* defer) { 157 void SupervisedUserResourceThrottle::WillStartRequest(bool* defer) {
158 ShowInterstitialIfNeeded(false, request_->url(), defer); 158 ShowInterstitialIfNeeded(false, request_->url(), defer);
159 } 159 }
160 160
161 void SupervisedUserResourceThrottle::WillRedirectRequest( 161 void SupervisedUserResourceThrottle::WillRedirectRequest(
162 const net::RedirectInfo& redirect_info, 162 const net::RedirectInfo& redirect_info,
163 bool* defer) { 163 bool* defer) {
164 ShowInterstitialIfNeeded(true, redirect_info.new_url, defer); 164 ShowInterstitialIfNeeded(true, redirect_info.new_url, defer);
165 } 165 }
166 166
167 const char* SupervisedUserResourceThrottle::GetNameForLogging() const { 167 const char* SupervisedUserResourceThrottle::GetNameForLogging() const {
168 return "SupervisedUserResourceThrottle"; 168 return "SupervisedUserResourceThrottle";
169 } 169 }
170 170
171 void SupervisedUserResourceThrottle::OnCheckDone( 171 void SupervisedUserResourceThrottle::OnCheckDone(
172 const GURL& url, 172 const GURL& url,
173 SupervisedUserURLFilter::FilteringBehavior behavior, 173 SupervisedUserURLFilter::FilteringBehavior behavior,
174 SupervisedUserURLFilter::FilteringBehaviorReason reason, 174 supervised_user_error_page::FilteringBehaviorReason reason,
175 bool uncertain) { 175 bool uncertain) {
176 DCHECK_EQ(SupervisedUserURLFilter::INVALID, behavior_); 176 DCHECK_EQ(SupervisedUserURLFilter::INVALID, behavior_);
177 // If we got a result synchronously, pass it back to ShowInterstitialIfNeeded. 177 // If we got a result synchronously, pass it back to ShowInterstitialIfNeeded.
178 if (!deferred_) 178 if (!deferred_)
179 behavior_ = behavior; 179 behavior_ = behavior;
180 180
181 ui::PageTransition transition = 181 ui::PageTransition transition =
182 content::ResourceRequestInfo::ForRequest(request_)->GetPageTransition(); 182 content::ResourceRequestInfo::ForRequest(request_)->GetPageTransition();
183 183
184 RecordFilterResultEvent(false, behavior, reason, uncertain, transition); 184 RecordFilterResultEvent(false, behavior, reason, uncertain, transition);
185 185
186 // If both the static blacklist and the async checker are enabled, also record 186 // If both the static blacklist and the async checker are enabled, also record
187 // SafeSites-only UMA events. 187 // SafeSites-only UMA events.
188 if (url_filter_->HasBlacklist() && url_filter_->HasAsyncURLChecker() && 188 if (url_filter_->HasBlacklist() && url_filter_->HasAsyncURLChecker() &&
189 (reason == SupervisedUserURLFilter::ASYNC_CHECKER || 189 (reason == supervised_user_error_page::ASYNC_CHECKER ||
190 reason == SupervisedUserURLFilter::BLACKLIST)) { 190 reason == supervised_user_error_page::BLACKLIST)) {
191 RecordFilterResultEvent(true, behavior, reason, uncertain, transition); 191 RecordFilterResultEvent(true, behavior, reason, uncertain, transition);
192 } 192 }
193 193
194 if (behavior == SupervisedUserURLFilter::BLOCK) 194 if (behavior == SupervisedUserURLFilter::BLOCK)
195 ShowInterstitial(url, reason); 195 ShowInterstitial(url, reason);
196 else if (deferred_) 196 else if (deferred_)
197 controller()->Resume(); 197 controller()->Resume();
198 } 198 }
199 199
200 void SupervisedUserResourceThrottle::OnInterstitialResult( 200 void SupervisedUserResourceThrottle::OnInterstitialResult(
201 bool continue_request) { 201 bool continue_request) {
202 if (continue_request) 202 if (continue_request)
203 controller()->Resume(); 203 controller()->Resume();
204 else 204 else
205 controller()->Cancel(); 205 controller()->Cancel();
206 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698