Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/browser/loader/navigation_resource_handler.h" | 5 #include "content/browser/loader/navigation_resource_handler.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "content/browser/devtools/devtools_netlog_observer.h" | 10 #include "content/browser/devtools/devtools_netlog_observer.h" |
| 9 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 11 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| 12 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
| 10 #include "content/browser/loader/resource_request_info_impl.h" | 13 #include "content/browser/loader/resource_request_info_impl.h" |
| 11 #include "content/browser/resource_context_impl.h" | 14 #include "content/browser/resource_context_impl.h" |
| 12 #include "content/browser/streams/stream.h" | 15 #include "content/browser/streams/stream.h" |
| 13 #include "content/browser/streams/stream_context.h" | 16 #include "content/browser/streams/stream_context.h" |
| 17 #include "content/public/browser/navigation_data.h" | |
| 14 #include "content/public/browser/resource_controller.h" | 18 #include "content/public/browser/resource_controller.h" |
| 19 #include "content/public/browser/resource_dispatcher_host_delegate.h" | |
| 15 #include "content/public/browser/stream_handle.h" | 20 #include "content/public/browser/stream_handle.h" |
| 16 #include "content/public/common/resource_response.h" | 21 #include "content/public/common/resource_response.h" |
| 17 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 18 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 19 | 24 |
| 20 namespace content { | 25 namespace content { |
| 21 | 26 |
| 22 NavigationResourceHandler::NavigationResourceHandler( | 27 NavigationResourceHandler::NavigationResourceHandler( |
| 23 net::URLRequest* request, | 28 net::URLRequest* request, |
| 24 NavigationURLLoaderImplCore* core) | 29 NavigationURLLoaderImplCore* core, |
| 30 ResourceDispatcherHostImpl* resource_dispatcher_host) | |
| 25 : ResourceHandler(request), | 31 : ResourceHandler(request), |
| 26 core_(core) { | 32 core_(core), |
| 33 resource_dispatcher_host_(resource_dispatcher_host) { | |
| 27 core_->set_resource_handler(this); | 34 core_->set_resource_handler(this); |
| 28 writer_.set_immediate_mode(true); | 35 writer_.set_immediate_mode(true); |
| 29 } | 36 } |
| 30 | 37 |
| 31 NavigationResourceHandler::~NavigationResourceHandler() { | 38 NavigationResourceHandler::~NavigationResourceHandler() { |
| 32 if (core_) { | 39 if (core_) { |
| 33 core_->NotifyRequestFailed(false, net::ERR_ABORTED); | 40 core_->NotifyRequestFailed(false, net::ERR_ABORTED); |
| 34 DetachFromCore(); | 41 DetachFromCore(); |
| 35 } | 42 } |
| 36 } | 43 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 // dispatched at the navigation layer. | 92 // dispatched at the navigation layer. |
| 86 if (info->IsDownload() || info->is_stream()) | 93 if (info->IsDownload() || info->is_stream()) |
| 87 return true; | 94 return true; |
| 88 | 95 |
| 89 StreamContext* stream_context = | 96 StreamContext* stream_context = |
| 90 GetStreamContextForResourceContext(info->GetContext()); | 97 GetStreamContextForResourceContext(info->GetContext()); |
| 91 writer_.InitializeStream(stream_context->registry(), | 98 writer_.InitializeStream(stream_context->registry(), |
| 92 request()->url().GetOrigin()); | 99 request()->url().GetOrigin()); |
| 93 | 100 |
| 94 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); | 101 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); |
| 95 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle()); | 102 |
| 103 // Ask the embedder for a NavigationData instance. | |
| 104 std::unique_ptr<NavigationData> navigation_data; | |
| 105 std::unique_ptr<NavigationData> clone_data; | |
|
nasko
2016/05/02 22:02:49
nit: cloned_data
RyanSturm
2016/05/02 23:02:56
Done.
| |
| 106 if (resource_dispatcher_host_ && resource_dispatcher_host_->delegate()) { | |
| 107 navigation_data = | |
| 108 resource_dispatcher_host_->delegate()->GetNavigationData(request()); | |
| 109 if (navigation_data) | |
| 110 clone_data = navigation_data->Clone(); | |
| 111 } | |
| 112 | |
| 113 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle(), | |
| 114 std::move(clone_data)); | |
| 96 *defer = true; | 115 *defer = true; |
| 116 | |
| 97 return true; | 117 return true; |
| 98 } | 118 } |
| 99 | 119 |
| 100 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 120 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { |
| 101 return true; | 121 return true; |
| 102 } | 122 } |
| 103 | 123 |
| 104 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url, | 124 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url, |
| 105 bool* defer) { | 125 bool* defer) { |
| 106 return true; | 126 return true; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 NOTREACHED(); | 163 NOTREACHED(); |
| 144 } | 164 } |
| 145 | 165 |
| 146 void NavigationResourceHandler::DetachFromCore() { | 166 void NavigationResourceHandler::DetachFromCore() { |
| 147 DCHECK(core_); | 167 DCHECK(core_); |
| 148 core_->set_resource_handler(nullptr); | 168 core_->set_resource_handler(nullptr); |
| 149 core_ = nullptr; | 169 core_ = nullptr; |
| 150 } | 170 } |
| 151 | 171 |
| 152 } // namespace content | 172 } // namespace content |
| OLD | NEW |