| 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/loader/navigation_url_loader_impl_core.h" | 10 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| 9 #include "content/browser/loader/netlog_observer.h" | 11 #include "content/browser/loader/netlog_observer.h" |
| 10 #include "content/browser/loader/resource_request_info_impl.h" | 12 #include "content/browser/loader/resource_request_info_impl.h" |
| 11 #include "content/browser/resource_context_impl.h" | 13 #include "content/browser/resource_context_impl.h" |
| 12 #include "content/browser/streams/stream.h" | 14 #include "content/browser/streams/stream.h" |
| 13 #include "content/browser/streams/stream_context.h" | 15 #include "content/browser/streams/stream_context.h" |
| 16 #include "content/public/browser/navigation_data.h" |
| 14 #include "content/public/browser/resource_controller.h" | 17 #include "content/public/browser/resource_controller.h" |
| 18 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 15 #include "content/public/browser/stream_handle.h" | 19 #include "content/public/browser/stream_handle.h" |
| 16 #include "content/public/common/resource_response.h" | 20 #include "content/public/common/resource_response.h" |
| 17 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 18 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 19 | 23 |
| 20 namespace content { | 24 namespace content { |
| 21 | 25 |
| 22 NavigationResourceHandler::NavigationResourceHandler( | 26 NavigationResourceHandler::NavigationResourceHandler( |
| 23 net::URLRequest* request, | 27 net::URLRequest* request, |
| 24 NavigationURLLoaderImplCore* core) | 28 NavigationURLLoaderImplCore* core, |
| 29 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate) |
| 25 : ResourceHandler(request), | 30 : ResourceHandler(request), |
| 26 core_(core) { | 31 core_(core), |
| 32 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate) { |
| 27 core_->set_resource_handler(this); | 33 core_->set_resource_handler(this); |
| 28 writer_.set_immediate_mode(true); | 34 writer_.set_immediate_mode(true); |
| 29 } | 35 } |
| 30 | 36 |
| 31 NavigationResourceHandler::~NavigationResourceHandler() { | 37 NavigationResourceHandler::~NavigationResourceHandler() { |
| 32 if (core_) { | 38 if (core_) { |
| 33 core_->NotifyRequestFailed(false, net::ERR_ABORTED); | 39 core_->NotifyRequestFailed(false, net::ERR_ABORTED); |
| 34 DetachFromCore(); | 40 DetachFromCore(); |
| 35 } | 41 } |
| 36 } | 42 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // dispatched at the navigation layer. | 91 // dispatched at the navigation layer. |
| 86 if (info->IsDownload() || info->is_stream()) | 92 if (info->IsDownload() || info->is_stream()) |
| 87 return true; | 93 return true; |
| 88 | 94 |
| 89 StreamContext* stream_context = | 95 StreamContext* stream_context = |
| 90 GetStreamContextForResourceContext(info->GetContext()); | 96 GetStreamContextForResourceContext(info->GetContext()); |
| 91 writer_.InitializeStream(stream_context->registry(), | 97 writer_.InitializeStream(stream_context->registry(), |
| 92 request()->url().GetOrigin()); | 98 request()->url().GetOrigin()); |
| 93 | 99 |
| 94 NetLogObserver::PopulateResponseInfo(request(), response); | 100 NetLogObserver::PopulateResponseInfo(request(), response); |
| 95 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle()); | 101 |
| 102 std::unique_ptr<NavigationData> cloned_data; |
| 103 if (resource_dispatcher_host_delegate_) { |
| 104 // Ask the embedder for a NavigationData instance. |
| 105 NavigationData* navigation_data = |
| 106 resource_dispatcher_host_delegate_->GetNavigationData(request()); |
| 107 |
| 108 // Clone the embedder's NavigationData before moving it to the UI thread. |
| 109 if (navigation_data) |
| 110 cloned_data = navigation_data->Clone(); |
| 111 } |
| 112 |
| 113 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle(), |
| 114 std::move(cloned_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 |