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, |
| 25 : ResourceHandler(request), | 30 ResourceDispatcherHostImpl* rdh) |
| 26 core_(core) { | 31 : ResourceHandler(request), core_(core), rdh_(rdh) { |
| 27 core_->set_resource_handler(this); | 32 core_->set_resource_handler(this); |
| 28 writer_.set_immediate_mode(true); | 33 writer_.set_immediate_mode(true); |
| 29 } | 34 } |
| 30 | 35 |
| 31 NavigationResourceHandler::~NavigationResourceHandler() { | 36 NavigationResourceHandler::~NavigationResourceHandler() { |
| 32 if (core_) { | 37 if (core_) { |
| 33 core_->NotifyRequestFailed(false, net::ERR_ABORTED); | 38 core_->NotifyRequestFailed(false, net::ERR_ABORTED); |
| 34 DetachFromCore(); | 39 DetachFromCore(); |
| 35 } | 40 } |
| 36 } | 41 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 // dispatched at the navigation layer. | 90 // dispatched at the navigation layer. |
| 86 if (info->IsDownload() || info->is_stream()) | 91 if (info->IsDownload() || info->is_stream()) |
| 87 return true; | 92 return true; |
| 88 | 93 |
| 89 StreamContext* stream_context = | 94 StreamContext* stream_context = |
| 90 GetStreamContextForResourceContext(info->GetContext()); | 95 GetStreamContextForResourceContext(info->GetContext()); |
| 91 writer_.InitializeStream(stream_context->registry(), | 96 writer_.InitializeStream(stream_context->registry(), |
| 92 request()->url().GetOrigin()); | 97 request()->url().GetOrigin()); |
| 93 | 98 |
| 94 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); | 99 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); |
| 95 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle()); | 100 |
| 101 // Ask the embedder for a NavigationData instance. | |
| 102 std::unique_ptr<NavigationData> navigation_data(nullptr); | |
|
bengr
2016/04/29 21:14:22
I'm not sure about Chromium style, but you can do:
RyanSturm
2016/05/02 19:52:21
Done.
| |
| 103 if (rdh_ && rdh_->delegate()) | |
| 104 navigation_data = rdh_->delegate()->GetNavigationData(request()); | |
| 105 // Clone the embedder NavigationData before moving it to the UI thread. | |
|
bengr
2016/04/29 21:14:22
embedder -> embedder's
RyanSturm
2016/05/02 19:52:21
Done.
| |
| 106 std::unique_ptr<NavigationData> clone_data( | |
| 107 navigation_data.get() ? navigation_data->Clone() : nullptr); | |
| 108 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle(), | |
| 109 std::move(clone_data)); | |
| 96 *defer = true; | 110 *defer = true; |
| 111 | |
| 97 return true; | 112 return true; |
| 98 } | 113 } |
| 99 | 114 |
| 100 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 115 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { |
| 101 return true; | 116 return true; |
| 102 } | 117 } |
| 103 | 118 |
| 104 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url, | 119 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url, |
| 105 bool* defer) { | 120 bool* defer) { |
| 106 return true; | 121 return true; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 NOTREACHED(); | 158 NOTREACHED(); |
| 144 } | 159 } |
| 145 | 160 |
| 146 void NavigationResourceHandler::DetachFromCore() { | 161 void NavigationResourceHandler::DetachFromCore() { |
| 147 DCHECK(core_); | 162 DCHECK(core_); |
| 148 core_->set_resource_handler(nullptr); | 163 core_->set_resource_handler(nullptr); |
| 149 core_ = nullptr; | 164 core_ = nullptr; |
| 150 } | 165 } |
| 151 | 166 |
| 152 } // namespace content | 167 } // namespace content |
| OLD | NEW |