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

Side by Side Diff: content/browser/download/download_request_handle.cc

Issue 1079163008: PlzNavigate: provide the FrameTreeNode ID to the network stack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-unittests
Patch Set: Rebase + addressed Nasko's comments Created 5 years, 7 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 "content/browser/download/download_request_handle.h" 5 #include "content/browser/download/download_request_handle.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
8 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/browser/frame_host/navigator.h"
11 #include "content/browser/frame_host/render_frame_host_impl.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h" 12 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 13 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/common/content_switches.h"
13 17
14 namespace content { 18 namespace content {
15 19
16 DownloadRequestHandle::~DownloadRequestHandle() { 20 DownloadRequestHandle::~DownloadRequestHandle() {
17 } 21 }
18 22
19 DownloadRequestHandle::DownloadRequestHandle() 23 DownloadRequestHandle::DownloadRequestHandle()
20 : child_id_(-1), 24 : child_id_(-1),
21 render_view_id_(-1), 25 render_view_id_(-1),
22 request_id_(-1) { 26 request_id_(-1),
27 frame_tree_node_id_(-1) {
23 } 28 }
24 29
25 DownloadRequestHandle::DownloadRequestHandle( 30 DownloadRequestHandle::DownloadRequestHandle(
26 const base::WeakPtr<DownloadResourceHandler>& handler, 31 const base::WeakPtr<DownloadResourceHandler>& handler,
27 int child_id, 32 int child_id,
28 int render_view_id, 33 int render_view_id,
29 int request_id) 34 int request_id,
35 int frame_tree_node_id)
30 : handler_(handler), 36 : handler_(handler),
31 child_id_(child_id), 37 child_id_(child_id),
32 render_view_id_(render_view_id), 38 render_view_id_(render_view_id),
33 request_id_(request_id) { 39 request_id_(request_id),
40 frame_tree_node_id_(frame_tree_node_id) {
34 DCHECK(handler_.get()); 41 DCHECK(handler_.get());
35 } 42 }
36 43
37 WebContents* DownloadRequestHandle::GetWebContents() const { 44 WebContents* DownloadRequestHandle::GetWebContents() const {
45 // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the
46 // WebContents.
47 // TODO(davidben): This logic should be abstracted within the ResourceLoader
48 // stack. https://crbug.com/376003
49 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
50 switches::kEnableBrowserSideNavigation)) {
51 FrameTreeNode* frame_tree_node =
52 FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
53 if (frame_tree_node) {
54 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
55 }
56 }
57
38 RenderViewHostImpl* render_view_host = 58 RenderViewHostImpl* render_view_host =
39 RenderViewHostImpl::FromID(child_id_, render_view_id_); 59 RenderViewHostImpl::FromID(child_id_, render_view_id_);
40 if (!render_view_host) 60 if (!render_view_host)
41 return NULL; 61 return nullptr;
42 62
43 return render_view_host->GetDelegate()->GetAsWebContents(); 63 return render_view_host->GetDelegate()->GetAsWebContents();
44 } 64 }
45 65
46 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { 66 DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
67 // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the
68 // DownloadManager.
69 // TODO(davidben): This logic should be abstracted within the ResourceLoader
70 // stack. https://crbug.com/376003
71 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
72 switches::kEnableBrowserSideNavigation)) {
73 FrameTreeNode* frame_tree_node =
74 FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
75 if (frame_tree_node) {
76 BrowserContext* context =
77 frame_tree_node->navigator()->GetController()->GetBrowserContext();
78 if (context)
79 return BrowserContext::GetDownloadManager(context);
80 }
81 }
82
47 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( 83 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(
48 child_id_, render_view_id_); 84 child_id_, render_view_id_);
49 if (rvh == NULL) 85 if (rvh == NULL)
50 return NULL; 86 return NULL;
51 RenderProcessHost* rph = rvh->GetProcess(); 87 RenderProcessHost* rph = rvh->GetProcess();
52 if (rph == NULL) 88 if (rph == NULL)
53 return NULL; 89 return NULL;
54 BrowserContext* context = rph->GetBrowserContext(); 90 BrowserContext* context = rph->GetBrowserContext();
55 if (context == NULL) 91 if (context == NULL)
56 return NULL; 92 return NULL;
(...skipping 23 matching lines...) Expand all
80 " child_id = %d" 116 " child_id = %d"
81 " render_view_id = %d" 117 " render_view_id = %d"
82 " request_id = %d" 118 " request_id = %d"
83 "}", 119 "}",
84 child_id_, 120 child_id_,
85 render_view_id_, 121 render_view_id_,
86 request_id_); 122 request_id_);
87 } 123 }
88 124
89 } // namespace content 125 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_request_handle.h ('k') | content/browser/download/download_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698