1 // Copyright 2019 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/cached_navigation_url_loader.h"
6 
7 #include "base/task/post_task.h"
8 #include "content/browser/frame_host/navigation_request_info.h"
9 #include "content/browser/loader/navigation_url_loader_delegate.h"
10 #include "content/browser/loader/navigation_url_loader_impl.h"
11 #include "content/browser/navigation_subresource_loader_params.h"
12 #include "content/public/browser/browser_task_traits.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/global_request_id.h"
15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/web_contents.h"
17 
18 namespace content {
19 
CachedNavigationURLLoader(std::unique_ptr<NavigationRequestInfo> request_info,NavigationURLLoaderDelegate * delegate)20 CachedNavigationURLLoader::CachedNavigationURLLoader(
21     std::unique_ptr<NavigationRequestInfo> request_info,
22     NavigationURLLoaderDelegate* delegate)
23     : request_info_(std::move(request_info)), delegate_(delegate) {
24   // Respond with a fake response. We use PostTask here to mimic the flow of
25   // a normal navigation.
26   //
27   // Normal navigations never call OnResponseStarted on the same message loop
28   // iteration that the NavigationURLLoader is created, because they have to
29   // make a network request.
30   base::PostTask(FROM_HERE, {BrowserThread::UI},
31                  base::BindOnce(&CachedNavigationURLLoader::OnResponseStarted,
32                                 weak_factory_.GetWeakPtr()));
33 }
34 
OnResponseStarted()35 void CachedNavigationURLLoader::OnResponseStarted() {
36   GlobalRequestID global_id = GlobalRequestID::MakeBrowserInitiated();
37 
38   delegate_->OnResponseStarted(
39       /*url_loader_client_endpoints=*/nullptr,
40       network::mojom::URLResponseHead::New(),
41       /*response_body=*/mojo::ScopedDataPipeConsumerHandle(), global_id,
42       /*is_download=*/false, NavigationDownloadPolicy(), base::nullopt);
43 }
~CachedNavigationURLLoader()44 CachedNavigationURLLoader::~CachedNavigationURLLoader() {}
45 
46 // static
Create(std::unique_ptr<NavigationRequestInfo> request_info,NavigationURLLoaderDelegate * delegate)47 std::unique_ptr<NavigationURLLoader> CachedNavigationURLLoader::Create(
48     std::unique_ptr<NavigationRequestInfo> request_info,
49     NavigationURLLoaderDelegate* delegate) {
50   return std::make_unique<CachedNavigationURLLoader>(std::move(request_info),
51                                                      delegate);
52 }
53 
FollowRedirect(const std::vector<std::string> & removed_headers,const net::HttpRequestHeaders & modified_headers,PreviewsState new_previews_state)54 void CachedNavigationURLLoader::FollowRedirect(
55     const std::vector<std::string>& removed_headers,
56     const net::HttpRequestHeaders& modified_headers,
57     PreviewsState new_previews_state) {
58   NOTREACHED();
59 }
60 }  // namespace content
61