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

Side by Side Diff: chrome/browser/download/download_request_limiter.cc

Issue 1467563002: Use ResourceRequestInfo::GetWebContents in DownloadRequestLimiter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-contents-callback
Patch Set: Addressed comments Created 5 years 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 "chrome/browser/download/download_request_limiter.h" 5 #include "chrome/browser/download/download_request_limiter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 299
300 if (!create) 300 if (!create)
301 return NULL; 301 return NULL;
302 302
303 TabDownloadState* state = 303 TabDownloadState* state =
304 new TabDownloadState(this, web_contents, originating_web_contents); 304 new TabDownloadState(this, web_contents, originating_web_contents);
305 state_map_[web_contents] = state; 305 state_map_[web_contents] = state;
306 return state; 306 return state;
307 } 307 }
308 308
309 void DownloadRequestLimiter::CanDownload(int render_process_host_id, 309 void DownloadRequestLimiter::CanDownload(
310 int render_view_id, 310 const content::ResourceRequestInfo::WebContentsGetterOnUIThread&
311 const GURL& url, 311 web_contents_getter,
312 const std::string& request_method, 312 const GURL& url,
313 const Callback& callback) { 313 const std::string& request_method,
314 const Callback& callback) {
314 DCHECK_CURRENTLY_ON(BrowserThread::UI); 315 DCHECK_CURRENTLY_ON(BrowserThread::UI);
315 316
316 content::WebContents* originating_contents = 317 content::WebContents* originating_contents = web_contents_getter.Run();
317 tab_util::GetWebContentsByID(render_process_host_id, render_view_id);
318 if (!originating_contents) { 318 if (!originating_contents) {
319 // The WebContents was closed, don't allow the download. 319 // The WebContents was closed, don't allow the download.
320 callback.Run(false); 320 callback.Run(false);
321 return; 321 return;
322 } 322 }
323 323
324 if (!originating_contents->GetDelegate()) { 324 if (!originating_contents->GetDelegate()) {
325 callback.Run(false); 325 callback.Run(false);
326 return; 326 return;
327 } 327 }
328 328
329 // Note that because |originating_contents| might go away before 329 // Note that because |originating_contents| might go away before
330 // OnCanDownloadDecided is invoked, we look it up by |render_process_host_id| 330 // OnCanDownloadDecided is invoked, we look it up by |render_process_host_id|
331 // and |render_view_id|. 331 // and |render_view_id|.
332 base::Callback<void(bool)> can_download_callback = base::Bind( 332 base::Callback<void(bool)> can_download_callback = base::Bind(
333 &DownloadRequestLimiter::OnCanDownloadDecided, 333 &DownloadRequestLimiter::OnCanDownloadDecided, factory_.GetWeakPtr(),
334 factory_.GetWeakPtr(), 334 web_contents_getter, request_method, callback);
335 render_process_host_id,
336 render_view_id,
337 request_method,
338 callback);
339 335
340 originating_contents->GetDelegate()->CanDownload( 336 originating_contents->GetDelegate()->CanDownload(
341 url, 337 url,
342 request_method, 338 request_method,
343 can_download_callback); 339 can_download_callback);
344 } 340 }
345 341
346 void DownloadRequestLimiter::OnCanDownloadDecided( 342 void DownloadRequestLimiter::OnCanDownloadDecided(
347 int render_process_host_id, 343 const content::ResourceRequestInfo::WebContentsGetterOnUIThread&
348 int render_view_id, 344 web_contents_getter,
349 const std::string& request_method, 345 const std::string& request_method,
350 const Callback& orig_callback, bool allow) { 346 const Callback& orig_callback,
347 bool allow) {
351 DCHECK_CURRENTLY_ON(BrowserThread::UI); 348 DCHECK_CURRENTLY_ON(BrowserThread::UI);
352 content::WebContents* originating_contents = 349 content::WebContents* originating_contents = web_contents_getter.Run();
353 tab_util::GetWebContentsByID(render_process_host_id, render_view_id);
354 if (!originating_contents || !allow) { 350 if (!originating_contents || !allow) {
355 orig_callback.Run(false); 351 orig_callback.Run(false);
356 return; 352 return;
357 } 353 }
358 354
359 CanDownloadImpl(originating_contents, 355 CanDownloadImpl(originating_contents,
360 request_method, 356 request_method,
361 orig_callback); 357 orig_callback);
362 } 358 }
363 359
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 NOTREACHED(); 439 NOTREACHED();
444 } 440 }
445 } 441 }
446 442
447 void DownloadRequestLimiter::Remove(TabDownloadState* state, 443 void DownloadRequestLimiter::Remove(TabDownloadState* state,
448 content::WebContents* contents) { 444 content::WebContents* contents) {
449 DCHECK(ContainsKey(state_map_, contents)); 445 DCHECK(ContainsKey(state_map_, contents));
450 state_map_.erase(contents); 446 state_map_.erase(contents);
451 delete state; 447 delete state;
452 } 448 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698