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

Side by Side Diff: content/browser/loader/navigation_resource_handler.cc

Issue 648813002: PlzNavigate: Add first version of NavigationURLLoader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plz-navigate-prepare
Patch Set: rebase, rework Core ownership story Created 6 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/loader/navigation_resource_handler.h"
6
7 #include "base/logging.h"
8 #include "content/browser/devtools/devtools_netlog_observer.h"
9 #include "content/browser/loader/navigation_url_loader_core.h"
10 #include "content/browser/loader/resource_request_info_impl.h"
11 #include "content/browser/resource_context_impl.h"
12 #include "content/browser/streams/stream.h"
13 #include "content/browser/streams/stream_context.h"
14 #include "content/public/browser/resource_controller.h"
15 #include "content/public/browser/stream_handle.h"
16 #include "content/public/common/resource_response.h"
17 #include "net/base/net_errors.h"
18 #include "net/url_request/url_request.h"
19
20 namespace content {
21
22 NavigationResourceHandler::NavigationResourceHandler(
23 net::URLRequest* request,
24 NavigationURLLoaderCore* core)
25 : ResourceHandler(request),
26 core_(core) {
27 core_->set_resource_handler(this);
28 }
29
30 NavigationResourceHandler::~NavigationResourceHandler() {
31 if (core_) {
32 core_->NotifyRequestFailed(net::ERR_ABORTED);
mmenke 2014/10/22 15:32:58 Can we end up here without an OnResponseCompleted
davidben 2014/10/22 20:58:03 If the ResourceLoader is uncleanly torn down, it c
33 core_->set_resource_handler(nullptr);
34 core_ = nullptr;
mmenke 2014/10/22 15:32:58 I don't think this gets us anything.
davidben 2014/10/22 20:58:03 Moved into helper method.
35 }
36 }
37
38 void NavigationResourceHandler::Cancel() {
39 controller()->Cancel();
40 core_ = nullptr;
41 }
42
43 void NavigationResourceHandler::FollowRedirect() {
44 controller()->Resume();
45 }
46
47 void NavigationResourceHandler::SetController(ResourceController* controller) {
48 writer_.set_controller(controller);
49 ResourceHandler::SetController(controller);
50 }
51
52 bool NavigationResourceHandler::OnUploadProgress(uint64 position,
53 uint64 size) {
54 return true;
55 }
56
57 bool NavigationResourceHandler::OnRequestRedirected(
58 const net::RedirectInfo& redirect_info,
59 ResourceResponse* response,
60 bool* defer) {
61 if (!core_)
mmenke 2014/10/22 15:32:58 Can this happen? We would have cancelled it by th
davidben 2014/10/22 20:58:04 I'm never clear on what can happen with all our as
62 return false;
63
64 // TODO(davidben): Perform a CSP check here, and anything else that would have
65 // been done renderer-side.
66 DevToolsNetLogObserver::PopulateResponseInfo(request(), response);
67 core_->NotifyRequestRedirected(redirect_info, response);
68 *defer = true;
69 return true;
70 }
71
72 bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response,
73 bool* defer) {
74 if (!core_)
75 return false;
76
77 ResourceRequestInfoImpl* info = GetRequestInfo();
78
79 // If the BufferedResourceHandler intercepted this request and converted it
80 // into a download, it will still call OnResponseStarted and immediately
81 // cancel. Ignore the call; OnReadCompleted will happen shortly.
82 //
83 // TODO(davidben): Move the dispatch out of BufferedResourceHandler. Perhaps
84 // all the way to the UI thread. Downloads, user certificates, etc., should be
85 // dispatched at the navigation layer.
86 if (info->IsDownload() || info->is_stream())
87 return true;
88
89 StreamContext* stream_context =
90 GetStreamContextForResourceContext(info->GetContext());
91 writer_.InitializeStream(stream_context->registry(),
92 request()->url().GetOrigin());
93
94 // Detach from the loader; at this point, the request is now owned by the
95 // StreamHandle.
96 DevToolsNetLogObserver::PopulateResponseInfo(request(), response);
97 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle());
98 core_->set_resource_handler(nullptr);
99 core_ = nullptr;
100 return true;
101 }
102
103 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) {
104 return true;
105 }
106
107 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url,
108 bool* defer) {
109 return true;
110 }
111
112 bool NavigationResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
113 int* buf_size,
114 int min_size) {
115 writer_.OnWillRead(buf, buf_size, min_size);
116 return true;
117 }
118
119 bool NavigationResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
120 writer_.OnReadCompleted(bytes_read, defer);
121 return true;
122 }
123
124 void NavigationResourceHandler::OnResponseCompleted(
125 const net::URLRequestStatus& status,
126 const std::string& security_info,
127 bool* defer) {
128 // If the request has already committed, close the stream and leave it as-is.
129 //
130 // TODO(davidben): Is the final status of a navigation request meaningful?
131 // Perhaps we should eventually extend the streams interface to push the
132 // status down. (If there was an error partway through loading the top-level.)
mmenke 2014/10/22 15:32:58 Do we currently replace committed partially loaded
davidben 2014/10/22 20:58:04 No, but it apparently isn't a no-op as far as Blin
133 if (writer_.stream()) {
134 writer_.Finalize();
mmenke 2014/10/22 15:32:58 Telling WebKit a blob is happily completed on erro
davidben 2014/10/22 20:58:04 Left a TODO and filed https://crbug.com/426162
135 return;
136 }
137
138 if (core_) {
139 DCHECK_NE(net::OK, status.error());
140 core_->NotifyRequestFailed(status.error());
141 core_->set_resource_handler(nullptr);
142 core_ = nullptr;
mmenke 2014/10/22 15:32:58 Are the last two lines needed? We end up destroyi
davidben 2014/10/22 20:58:04 If we don't detach at this point, then the destruc
143 }
144 }
145
146 void NavigationResourceHandler::OnDataDownloaded(int bytes_downloaded) {
147 NOTREACHED();
148 }
149
150 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698