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 #ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_NAVIGATION_BODY_LOADER_H_
6 #define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_NAVIGATION_BODY_LOADER_H_
7 
8 #include <memory>
9 
10 #include "base/containers/span.h"
11 #include "base/optional.h"
12 #include "base/time/time.h"
13 #include "mojo/public/cpp/base/big_buffer.h"
14 #include "third_party/blink/public/platform/web_url_error.h"
15 #include "third_party/blink/public/platform/web_url_loader.h"
16 
17 namespace blink {
18 
19 // This class is used to load the body of main resource during navigation.
20 // It is provided by the client which commits a navigation.
21 // See WebNavigationParams for more details.
22 class BLINK_EXPORT WebNavigationBodyLoader {
23  public:
24   class Client {
25    public:
~Client()26     virtual ~Client() {}
27 
28     // Notifies about code cache if available. This method will
29     // be called zero or one time.
30     virtual void BodyCodeCacheReceived(mojo_base::BigBuffer data) = 0;
31 
32     // Notifies about more data available. Called multiple times.
33     // If main resource is empty, can be not called at all.
34     virtual void BodyDataReceived(base::span<const char> data) = 0;
35 
36     // Called once at the end. If something went wrong, |error| will be set.
37     // No more calls are issued after this one.
38     virtual void BodyLoadingFinished(
39         base::TimeTicks completion_time,
40         int64_t total_encoded_data_length,
41         int64_t total_encoded_body_length,
42         int64_t total_decoded_body_length,
43         bool should_report_corb_blocking,
44         const base::Optional<WebURLError>& error) = 0;
45   };
46 
47   // It should be safe to destroy WebNavigationBodyLoader at any moment,
48   // including from inside any client notification.
~WebNavigationBodyLoader()49   virtual ~WebNavigationBodyLoader() {}
50 
51   // While deferred, data will be read on the renderer side but will not invoke
52   // any web-exposed behavior such as dispatching messages or handling
53   // redirects. This method can be called multiple times at any moment.
54   virtual void SetDefersLoading(WebURLLoader::DeferType defers) = 0;
55 
56   // Starts loading the body. Client must be non-null, and will receive
57   // the body, code cache and final result.
58   virtual void StartLoadingBody(Client*, bool use_isolated_code_cache) = 0;
59 };
60 
61 }  // namespace blink
62 
63 #endif  // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_NAVIGATION_BODY_LOADER_H_
64