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

Side by Side Diff: android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc

Issue 2814593002: WebView: add {set,get}SafeBrowsingEnabled per WebView (Closed)
Patch Set: Add comment about getSafeBrowsingEnabled() Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h" 5 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "android_webview/browser/aw_browser_context.h" 10 #include "android_webview/browser/aw_browser_context.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // From content::ResourceThrottle 122 // From content::ResourceThrottle
123 void WillStartRequest(bool* defer) override; 123 void WillStartRequest(bool* defer) override;
124 void WillRedirectRequest(const net::RedirectInfo& redirect_info, 124 void WillRedirectRequest(const net::RedirectInfo& redirect_info,
125 bool* defer) override; 125 bool* defer) override;
126 const char* GetNameForLogging() const override; 126 const char* GetNameForLogging() const override;
127 127
128 void OnIoThreadClientReady(int new_render_process_id, 128 void OnIoThreadClientReady(int new_render_process_id,
129 int new_render_frame_id); 129 int new_render_frame_id);
130 bool MaybeBlockRequest(); 130 bool MaybeBlockRequest();
131 bool ShouldBlockRequest(); 131 bool ShouldBlockRequest();
132 bool GetSafeBrowsingEnabled();
132 int render_process_id() const { return render_process_id_; } 133 int render_process_id() const { return render_process_id_; }
133 int render_frame_id() const { return render_frame_id_; } 134 int render_frame_id() const { return render_frame_id_; }
134 135
135 private: 136 private:
136 std::unique_ptr<AwContentsIoThreadClient> GetIoThreadClient() const; 137 std::unique_ptr<AwContentsIoThreadClient> GetIoThreadClient() const;
137 138
138 int render_process_id_; 139 int render_process_id_;
139 int render_frame_id_; 140 int render_frame_id_;
140 net::URLRequest* request_; 141 net::URLRequest* request_;
141 }; 142 };
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 210 }
210 211
211 bool IoThreadClientThrottle::MaybeBlockRequest() { 212 bool IoThreadClientThrottle::MaybeBlockRequest() {
212 if (ShouldBlockRequest()) { 213 if (ShouldBlockRequest()) {
213 CancelWithError(net::ERR_ACCESS_DENIED); 214 CancelWithError(net::ERR_ACCESS_DENIED);
214 return true; 215 return true;
215 } 216 }
216 return false; 217 return false;
217 } 218 }
218 219
220 bool IoThreadClientThrottle::GetSafeBrowsingEnabled() {
221 std::unique_ptr<AwContentsIoThreadClient> io_client = GetIoThreadClient();
222 if (!io_client)
223 return false;
224 return io_client->GetSafeBrowsingEnabled();
225 }
226
219 bool IoThreadClientThrottle::ShouldBlockRequest() { 227 bool IoThreadClientThrottle::ShouldBlockRequest() {
220 std::unique_ptr<AwContentsIoThreadClient> io_client = GetIoThreadClient(); 228 std::unique_ptr<AwContentsIoThreadClient> io_client = GetIoThreadClient();
221 if (!io_client) 229 if (!io_client)
222 return false; 230 return false;
223 231
224 // Part of implementation of WebSettings.allowContentAccess. 232 // Part of implementation of WebSettings.allowContentAccess.
225 if (request_->url().SchemeIs(url::kContentScheme) && 233 if (request_->url().SchemeIs(url::kContentScheme) &&
226 io_client->ShouldBlockContentUrls()) { 234 io_client->ShouldBlockContentUrls()) {
227 return true; 235 return true;
228 } 236 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 net::URLRequest* request, 284 net::URLRequest* request,
277 content::ResourceContext* resource_context, 285 content::ResourceContext* resource_context,
278 content::AppCacheService* appcache_service, 286 content::AppCacheService* appcache_service,
279 ResourceType resource_type, 287 ResourceType resource_type,
280 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) { 288 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) {
281 AddExtraHeadersIfNeeded(request, resource_context); 289 AddExtraHeadersIfNeeded(request, resource_context);
282 290
283 const content::ResourceRequestInfo* request_info = 291 const content::ResourceRequestInfo* request_info =
284 content::ResourceRequestInfo::ForRequest(request); 292 content::ResourceRequestInfo::ForRequest(request);
285 293
286 if (AwSafeBrowsingConfigHelper::GetSafeBrowsingEnabled()) { 294 std::unique_ptr<IoThreadClientThrottle> ioThreadThrottle =
295 base::MakeUnique<IoThreadClientThrottle>(request_info->GetChildID(),
296 request_info->GetRenderFrameID(),
297 request);
298
299 if (ioThreadThrottle->GetSafeBrowsingEnabled()) {
287 content::ResourceThrottle* throttle = 300 content::ResourceThrottle* throttle =
288 AwSafeBrowsingResourceThrottle::MaybeCreate( 301 AwSafeBrowsingResourceThrottle::MaybeCreate(
289 request, resource_type, 302 request, resource_type,
290 AwBrowserContext::GetDefault()->GetSafeBrowsingDBManager(), 303 AwBrowserContext::GetDefault()->GetSafeBrowsingDBManager(),
291 AwBrowserContext::GetDefault()->GetSafeBrowsingUIManager()); 304 AwBrowserContext::GetDefault()->GetSafeBrowsingUIManager());
292 if (throttle == nullptr) { 305 if (throttle == nullptr) {
293 // Should not happen 306 // Should not happen
294 DLOG(WARNING) << "Failed creating safebrowsing throttle"; 307 DLOG(WARNING) << "Failed creating safebrowsing throttle";
295 } else { 308 } else {
296 throttles->push_back(base::WrapUnique(throttle)); 309 throttles->push_back(base::WrapUnique(throttle));
297 } 310 }
298 } 311 }
299 312
300 // We always push the throttles here. Checking the existence of io_client 313 // We always push the throttles here. Checking the existence of io_client
301 // is racy when a popup window is created. That is because RequestBeginning 314 // is racy when a popup window is created. That is because RequestBeginning
302 // is called whether or not requests are blocked via BlockRequestForRoute() 315 // is called whether or not requests are blocked via BlockRequestForRoute()
303 // however io_client may or may not be ready at the time depending on whether 316 // however io_client may or may not be ready at the time depending on whether
304 // webcontents is created. 317 // webcontents is created.
305 throttles->push_back(base::MakeUnique<IoThreadClientThrottle>( 318 throttles->push_back(std::move(ioThreadThrottle));
306 request_info->GetChildID(), request_info->GetRenderFrameID(), request));
307 319
308 bool is_main_frame = resource_type == content::RESOURCE_TYPE_MAIN_FRAME; 320 bool is_main_frame = resource_type == content::RESOURCE_TYPE_MAIN_FRAME;
309 if (!is_main_frame) 321 if (!is_main_frame)
310 InterceptNavigationDelegate::UpdateUserGestureCarryoverInfo(request); 322 InterceptNavigationDelegate::UpdateUserGestureCarryoverInfo(request);
311 throttles->push_back( 323 throttles->push_back(
312 base::MakeUnique<web_restrictions::WebRestrictionsResourceThrottle>( 324 base::MakeUnique<web_restrictions::WebRestrictionsResourceThrottle>(
313 AwBrowserContext::GetDefault()->GetWebRestrictionProvider(), 325 AwBrowserContext::GetDefault()->GetWebRestrictionProvider(),
314 request->url(), is_main_frame)); 326 request->url(), is_main_frame));
315 } 327 }
316 328
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 net::HttpRequestHeaders headers; 514 net::HttpRequestHeaders headers;
503 headers.AddHeadersFromString(extra_headers); 515 headers.AddHeadersFromString(extra_headers);
504 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { 516 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) {
505 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); 517 request->SetExtraRequestHeaderByName(it.name(), it.value(), false);
506 } 518 }
507 } 519 }
508 } 520 }
509 } 521 }
510 522
511 } // namespace android_webview 523 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698